adding tests and improving error messages

This commit is contained in:
Jesko 2018-08-16 12:29:27 +02:00 committed by Jimmy
parent 0c38cbcbdd
commit ee9b1f4950
3 changed files with 32 additions and 3 deletions

View File

@ -41,6 +41,8 @@ from qutebrowser.misc import editor, guiprocess
from qutebrowser.completion.models import urlmodel, miscmodels
from qutebrowser.mainwindow import mainwindow
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-69904
MAX_WORLD_ID = 256 if qtutils.version_check('5.11.2') else 11
class CommandDispatcher:
@ -2088,7 +2090,7 @@ class CommandDispatcher:
try:
widget.run_js_async(js_code, callback=jseval_cb, world=world)
except OverflowError:
raise cmdexc.CommandError("World Id not in valid range")
raise cmdexc.CommandError("World ID should be between 0 and " + str(MAX_WORLD_ID))
@cmdutils.register(instance='command-dispatcher', scope='window')
def fake_key(self, keystring, global_=False):

View File

@ -47,6 +47,10 @@ from qutebrowser.qt import sip
_qute_scheme_handler = None
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-69904
MAX_WORLD_ID = 256 if qtutils.version_check('5.11.2') else 11
def init():
"""Initialize QtWebEngine-specific modules."""
# For some reason we need to keep a reference, otherwise the scheme handler
@ -948,10 +952,11 @@ class _WebEngineScripts(QObject):
new_script = QWebEngineScript()
try:
world = int(script.jsworld)
if not 0 <= world <= 11:
if not 0 <= world <= MAX_WORLD_ID:
log.greasemonkey.error(
"script {} has invalid value for '@qute-js-world'"
": {}".format(script.name, script.jsworld))
": {}, should be between 0 and "
"{}".format(script.name, script.jsworld, MAX_WORLD_ID))
continue
except ValueError:
try:
@ -1070,6 +1075,8 @@ class WebEngineTab(browsertab.AbstractTab):
world_id = QWebEngineScript.ApplicationWorld
elif isinstance(world, int):
world_id = world
if not 0 <= world_id <= MAX_WORLD_ID:
raise OverflowError
else:
world_id = _JS_WORLD_MAP[world]

View File

@ -118,6 +118,26 @@ Feature: Various utility commands.
Then the javascript message "Hello from the page!" should be logged
And "No output or error" should be logged
@qtwebkit_skip @qt>=5.11.2
Scenario: :jseval using too high of a world id
When I run :jseval --world=257 console.log("Hello from JS!");
Then the error "World ID should be between 0 and 256" should be shown
@qtwebkit_skip @qt<5.11.2
Scenario: :jseval using too high of a world id
When I run :jseval --world=12 console.log("Hello from JS!");
Then the error "World ID should be between 0 and 11" should be shown
@qtwebkit_skip @qt>=5.11.2
Scenario: :jseval using a negative world id
When I run :jseval --world=-1 console.log("Hello from JS!");
Then the error "World ID should be between 0 and 256" should be shown
@qtwebkit_skip @qt<5.11.2
Scenario: :jseval using a negative world id
When I run :jseval --world=-1 console.log("Hello from JS!");
Then the error "World ID should be between 0 and 11" should be shown
Scenario: :jseval --file using a file that exists as js-code
When I run :jseval --file (testdata)/misc/jseval_file.js
Then the javascript message "Hello from JS!" should be logged