moving MAX_WORLD_ID to qtutils, changing test names, fixing linter errors, changing error type to WebTabError
This commit is contained in:
parent
8ef3d90b1a
commit
abea603119
@ -41,8 +41,6 @@ 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:
|
||||
|
||||
@ -2089,8 +2087,8 @@ class CommandDispatcher:
|
||||
widget = self._current_widget()
|
||||
try:
|
||||
widget.run_js_async(js_code, callback=jseval_cb, world=world)
|
||||
except OverflowError:
|
||||
raise cmdexc.CommandError("World ID should be between 0 and " + str(MAX_WORLD_ID))
|
||||
except browsertab.WebTabError as e:
|
||||
raise cmdexc.CommandError(str(e))
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
def fake_key(self, keystring, global_=False):
|
||||
|
@ -47,10 +47,6 @@ 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
|
||||
@ -952,11 +948,14 @@ class _WebEngineScripts(QObject):
|
||||
new_script = QWebEngineScript()
|
||||
try:
|
||||
world = int(script.jsworld)
|
||||
if not 0 <= world <= MAX_WORLD_ID:
|
||||
if not 0 <= world <= qtutils.MAX_WORLD_ID:
|
||||
log.greasemonkey.error(
|
||||
"script {} has invalid value for '@qute-js-world'"
|
||||
": {}, should be between 0 and "
|
||||
"{}".format(script.name, script.jsworld, MAX_WORLD_ID))
|
||||
": {}, should be between 0 and {}"
|
||||
.format(
|
||||
script.name,
|
||||
script.jsworld,
|
||||
qtutils.MAX_WORLD_ID))
|
||||
continue
|
||||
except ValueError:
|
||||
try:
|
||||
@ -1075,8 +1074,10 @@ 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
|
||||
if not 0 <= world_id <= qtutils.MAX_WORLD_ID:
|
||||
raise browsertab.WebTabError(
|
||||
"World ID should be between 0 and {}"
|
||||
.format(qtutils.MAX_WORLD_ID))
|
||||
else:
|
||||
world_id = _JS_WORLD_MAP[world]
|
||||
|
||||
|
@ -24,6 +24,7 @@ Module attributes:
|
||||
value.
|
||||
MINVALS: A dictionary of C/Qt types (as string) mapped to their minimum
|
||||
value.
|
||||
MAX_WORLD_ID: The highest World ID allowed in this version of QtWebEngine
|
||||
"""
|
||||
|
||||
|
||||
@ -98,6 +99,10 @@ def version_check(version, exact=False, compiled=True):
|
||||
return result
|
||||
|
||||
|
||||
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-69904
|
||||
MAX_WORLD_ID = 256 if version_check('5.11.2') else 11
|
||||
|
||||
|
||||
def is_new_qtwebkit():
|
||||
"""Check if the given version is a new QtWebKit."""
|
||||
assert qWebKitVersion is not None
|
||||
|
@ -119,22 +119,22 @@ Feature: Various utility commands.
|
||||
And "No output or error" should be logged
|
||||
|
||||
@qtwebkit_skip @qt>=5.11.2
|
||||
Scenario: :jseval using too high of a world id
|
||||
Scenario: :jseval using too high of a world id in Qt versions bigger than 5.11.2
|
||||
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
|
||||
Scenario: :jseval using too high of a world id in Qt versions smaller than 5.11.2
|
||||
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
|
||||
Scenario: :jseval using a negative world id in Qt versions bigger than 5.11.2
|
||||
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
|
||||
Scenario: :jseval using a negative world id in Qt versions smaller than 5.11.2
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user