From abea603119f3cbda81bf4b4be34e6df2bfbf76b3 Mon Sep 17 00:00:00 2001 From: Jesko Date: Sat, 18 Aug 2018 14:19:05 +0200 Subject: [PATCH] moving MAX_WORLD_ID to qtutils, changing test names, fixing linter errors, changing error type to WebTabError --- qutebrowser/browser/commands.py | 6 ++---- qutebrowser/browser/webengine/webenginetab.py | 19 ++++++++++--------- qutebrowser/utils/qtutils.py | 5 +++++ tests/end2end/features/misc.feature | 8 ++++---- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index ae5e38e22..838862038 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -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): diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 7a096dd8f..85c3879d4 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -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] diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index 8a42fb073..1f87d1a90 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -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 diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index ac3788d8e..6893e143a 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -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