From cf070d48f2de931bb4c00f37a1b8077ba69956a4 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 5 Sep 2016 12:16:58 +0200 Subject: [PATCH] WebEngine: Disable createWindow for Qt < 5.7.1 Fixes #1911. The bugfix is backported in my qt5-webengine-debug package, and QUTE_QTBUG54419_PATCHED can be set to force qutebrowser to use createWindow. --- pytest.ini | 1 + qutebrowser/browser/webengine/webview.py | 13 ++++++++++++- qutebrowser/misc/crashdialog.py | 2 +- tests/end2end/conftest.py | 6 ++++++ tests/end2end/features/hints.feature | 5 +++++ tests/end2end/features/javascript.feature | 1 + tests/end2end/features/misc.feature | 1 + tests/unit/misc/test_crashdialog.py | 1 + tox.ini | 2 +- 9 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pytest.ini b/pytest.ini index eda54aa56..b8232c733 100644 --- a/pytest.ini +++ b/pytest.ini @@ -18,6 +18,7 @@ markers = qtwebengine_todo: Features still missing with QtWebEngine qtwebengine_skip: Tests not applicable with QtWebEngine qtwebkit_skip: Tests not applicable with QtWebKit + qtwebengine_createWindow: Tests using createWindow with QtWebEngine (QTBUG-54419) qt_log_level_fail = WARNING qt_log_ignore = ^SpellCheck: .* diff --git a/qutebrowser/browser/webengine/webview.py b/qutebrowser/browser/webengine/webview.py index 9ba128c15..af1b5c0c3 100644 --- a/qutebrowser/browser/webengine/webview.py +++ b/qutebrowser/browser/webengine/webview.py @@ -19,6 +19,7 @@ """The main browser widget for QtWebEngine.""" +import os from PyQt5.QtCore import pyqtSignal, QUrl # pylint: disable=no-name-in-module,import-error,useless-suppression @@ -26,7 +27,7 @@ from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage # pylint: enable=no-name-in-module,import-error,useless-suppression from qutebrowser.config import config -from qutebrowser.utils import log, debug, usertypes, objreg +from qutebrowser.utils import log, debug, usertypes, objreg, qtutils, message class WebEngineView(QWebEngineView): @@ -63,6 +64,16 @@ class WebEngineView(QWebEngineView): Return: The new QWebEngineView object. """ + # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-54419 + vercheck = qtutils.version_check + qtbug_54419_fixed = ((vercheck('5.6.2') and not vercheck('5.7.0')) or + qtutils.version_check('5.7.1') or + os.environ.get('QUTE_QTBUG54419_PATCHED', '')) + if not qtbug_54419_fixed: + message.error(self._win_id, "Qt 5.6.2/5.7.1 or newer is required " + "to open new tabs via JS!") + return None + debug_type = debug.qenum_key(QWebEnginePage, wintype) log.webview.debug("createWindow with type {}".format(debug_type)) background = False diff --git a/qutebrowser/misc/crashdialog.py b/qutebrowser/misc/crashdialog.py index d22415b7b..8d44da041 100644 --- a/qutebrowser/misc/crashdialog.py +++ b/qutebrowser/misc/crashdialog.py @@ -99,7 +99,7 @@ def get_fatal_crash_dialog(debug, data): def _get_environment_vars(): """Gather environment variables for the crash info.""" masks = ('DESKTOP_SESSION', 'DE', 'QT_*', 'PYTHON*', 'LC_*', 'LANG', - 'XDG_*') + 'XDG_*', 'QUTE_*') info = [] for key, value in os.environ.items(): for m in masks: diff --git a/tests/end2end/conftest.py b/tests/end2end/conftest.py index c18f92a11..a8a40d824 100644 --- a/tests/end2end/conftest.py +++ b/tests/end2end/conftest.py @@ -132,6 +132,10 @@ if not getattr(sys, 'frozen', False): def pytest_collection_modifyitems(config, items): """Apply @qtwebengine_* markers.""" webengine = config.getoption('--qute-bdd-webengine') + vercheck = qtutils.version_check + qtbug_54419_fixed = ((vercheck('5.6.2') and not vercheck('5.7.0')) or + qtutils.version_check('5.7.1') or + os.environ.get('QUTE_QTBUG54419_PATCHED', '')) markers = { 'qtwebengine_todo': ('QtWebEngine TODO', pytest.mark.xfail, webengine), @@ -139,6 +143,8 @@ def pytest_collection_modifyitems(config, items): webengine), 'qtwebkit_skip': ('Skipped with QtWebKit', pytest.mark.skipif, not webengine), + 'qtwebengine_createWindow': ('Skipped because of QTBUG-54419', + pytest.mark.skipif, not qtbug_54419_fixed) } for item in items: diff --git a/tests/end2end/features/hints.feature b/tests/end2end/features/hints.feature index 420ec12d1..f100b5c10 100644 --- a/tests/end2end/features/hints.feature +++ b/tests/end2end/features/hints.feature @@ -19,6 +19,7 @@ Feature: Using hints ### Opening in current or new tab + @qtwebengine_createWindow Scenario: Following a hint and force to open in current tab. When I open data/hints/link_blank.html And I hint with args "links current" and follow a @@ -26,6 +27,7 @@ Feature: Using hints Then the following tabs should be open: - data/hello.txt (active) + @qtwebengine_createWindow Scenario: Following a hint and allow to open in new tab. When I open data/hints/link_blank.html And I hint with args "links normal" and follow a @@ -34,6 +36,7 @@ Feature: Using hints - data/hints/link_blank.html - data/hello.txt (active) + @qtwebengine_createWindow Scenario: Following a hint to link with sub-element and force to open in current tab. When I open data/hints/link_span.html And I run :tab-close @@ -151,11 +154,13 @@ Feature: Using hints And I hint wht args "links normal" and follow a Then "navigation request: url http://localhost:*/data/hello2.txt, type NavigationTypeLinkClicked, *" should be logged + @qtwebengine_createWindow Scenario: Opening a link inside a specific iframe When I open data/hints/iframe_target.html And I hint with args "links normal" and follow a Then "navigation request: url http://localhost:*/data/hello.txt, type NavigationTypeLinkClicked, *" should be logged + @qtwebengine_createWindow Scenario: Opening a link with specific target frame in a new tab When I open data/hints/iframe_target.html And I hint with args "links tab" and follow a diff --git a/tests/end2end/features/javascript.feature b/tests/end2end/features/javascript.feature index a29c33373..b2273cb1d 100644 --- a/tests/end2end/features/javascript.feature +++ b/tests/end2end/features/javascript.feature @@ -20,6 +20,7 @@ Feature: Javascript stuff Then "Requested to close * which does not exist!" should be logged @qtwebkit_skip + @qtwebengine_createWindow Scenario: Closing a JS window twice (issue 906) - qtwebengine When I open about:blank And I open data/javascript/issue906.html in a new tab diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 9ae612f87..a7fc0bf80 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -551,6 +551,7 @@ Feature: Various utility commands. Then the page should not be scrolled And the error "prompt-accept: This command is only allowed in prompt/yesno mode." should be shown + @qtwebengine_createWindow Scenario: :repeat-command with mode-switching command Given I open data/hints/link_blank.html And I run :tab-only diff --git a/tests/unit/misc/test_crashdialog.py b/tests/unit/misc/test_crashdialog.py index 6f38cd50c..dd2ebd35e 100644 --- a/tests/unit/misc/test_crashdialog.py +++ b/tests/unit/misc/test_crashdialog.py @@ -76,6 +76,7 @@ def test_parse_fatal_stacktrace(text, typ, func): "QT_IM_MODULE = fcitx" ), ({'LANGUAGE': 'foo', 'LANG': 'en_US.UTF-8'}, "LANG = en_US.UTF-8"), + ({'FOO': 'bar', 'QUTE_BLAH': '1'}, "QUTE_BLAH = 1"), ], ids=lambda e: e[1]) def test_get_environment_vars(monkeypatch, env, expected): """Test for crashdialog._get_environment_vars.""" diff --git a/tox.ini b/tox.ini index f6a6b88cd..5c49ecce4 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ skipsdist = true setenv = QT_QPA_PLATFORM_PLUGIN_PATH={envdir}/Lib/site-packages/PyQt5/plugins/platforms PYTEST_QT_API=pyqt5 -passenv = PYTHON DISPLAY XAUTHORITY HOME USERNAME USER CI TRAVIS XDG_* +passenv = PYTHON DISPLAY XAUTHORITY HOME USERNAME USER CI TRAVIS XDG_* QUTE_* deps = -r{toxinidir}/misc/requirements/requirements-pip.txt -r{toxinidir}/requirements.txt