diff options
author | Árni Dagur <agudmundsson@fc-md.umd.edu> | 2020-08-03 01:50:09 +0000 |
---|---|---|
committer | Árni Dagur <arni@dagur.eu> | 2020-12-19 20:24:06 +0000 |
commit | 68b9960a67158dceb7a50f4152074abf9696046b (patch) | |
tree | f52599e81a4b807dcf5f517bcdd177efd916386d /tests/helpers | |
parent | 36831af853e7df59c55f07005ded015b47c5e4e1 (diff) | |
parent | c04ab823a84b974fd26f5bbb1f9e6a6a175c038a (diff) | |
download | qutebrowser-68b9960a67158dceb7a50f4152074abf9696046b.tar.gz qutebrowser-68b9960a67158dceb7a50f4152074abf9696046b.zip |
Merge branch 'master' into more-sophisticated-adblock
Diffstat (limited to 'tests/helpers')
-rw-r--r-- | tests/helpers/fixtures.py | 35 | ||||
-rw-r--r-- | tests/helpers/stubs.py | 3 | ||||
-rw-r--r-- | tests/helpers/utils.py | 90 |
3 files changed, 123 insertions, 5 deletions
diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index 60a4f02ba..b62a488ce 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -208,9 +208,11 @@ def web_tab_setup(qtbot, tab_registry, session_manager_stub, @pytest.fixture def webkit_tab(web_tab_setup, qtbot, cookiejar_and_cache, mode_manager, - widget_container, download_stub, webpage): + widget_container, download_stub, webpage, monkeypatch): webkittab = pytest.importorskip('qutebrowser.browser.webkit.webkittab') + monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit) + tab = webkittab.WebKitTab(win_id=0, mode_manager=mode_manager, private=False) widget_container.set_widget(tab) @@ -225,6 +227,8 @@ def webkit_tab(web_tab_setup, qtbot, cookiejar_and_cache, mode_manager, def webengine_tab(web_tab_setup, qtbot, redirect_webengine_data, tabbed_browser_stubs, mode_manager, widget_container, monkeypatch): + monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebEngine) + tabwidget = tabbed_browser_stubs[0].widget tabwidget.current_index = 0 tabwidget.index_of = 0 @@ -442,9 +446,10 @@ def webengineview(qtbot, monkeypatch, web_tab_setup): @pytest.fixture -def webpage(qnam): +def webpage(qnam, monkeypatch): """Get a new QWebPage object.""" QtWebKitWidgets = pytest.importorskip('PyQt5.QtWebKitWidgets') + monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit) class WebPageStub(QtWebKitWidgets.QWebPage): @@ -466,10 +471,9 @@ def webpage(qnam): @pytest.fixture -def webview(qtbot, webpage, monkeypatch): +def webview(qtbot, webpage): """Get a new QWebView object.""" QtWebKitWidgets = pytest.importorskip('PyQt5.QtWebKitWidgets') - monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebKit) view = QtWebKitWidgets.QWebView() qtbot.add_widget(view) @@ -676,3 +680,26 @@ def web_history(fake_save_manager, tmpdir, init_sql, config_stub, stubs, web_history = history.WebHistory(stubs.FakeHistoryProgress()) monkeypatch.setattr(history, 'web_history', web_history) return web_history + + +@pytest.fixture +def blue_widget(qtbot): + widget = QWidget() + widget.setStyleSheet('background-color: blue;') + qtbot.add_widget(widget) + return widget + + +@pytest.fixture +def red_widget(qtbot): + widget = QWidget() + widget.setStyleSheet('background-color: red;') + qtbot.add_widget(widget) + return widget + + +@pytest.fixture +def state_config(data_tmpdir, monkeypatch): + state = configfiles.StateConfig() + monkeypatch.setattr(configfiles, 'state', state) + return state diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index bc8044461..f9223c3ca 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -481,9 +481,10 @@ class TabbedBrowserStub(QObject): def __init__(self, parent=None): super().__init__(parent) self.widget = TabWidgetStub() - self.shutting_down = False + self.is_shutting_down = False self.loaded_url = None self.cur_url = None + self.undo_stack = None def on_tab_close_requested(self, idx): del self.widget.tabs[idx] diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index dd30d9921..41fb4f100 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -26,9 +26,17 @@ import pprint import os.path import contextlib import pathlib +import importlib.util +import importlib.machinery import pytest +from PyQt5.QtCore import qVersion +try: + from PyQt5.QtWebEngine import PYQT_WEBENGINE_VERSION_STR +except ImportError: + PYQT_WEBENGINE_VERSION_STR = None + from qutebrowser.utils import qtutils, log ON_CI = 'CI' in os.environ @@ -123,6 +131,24 @@ def _partial_compare_eq(val1, val2, *, indent): return PartialCompareOutcome("{!r} != {!r}".format(val1, val2)) +def gha_group_begin(name): + """Get a string to begin a GitHub Actions group. + + Should only be called on CI. + """ + assert ON_CI + return '::group::' + name + + +def gha_group_end(): + """Get a string to end a GitHub Actions group. + + Should only be called on CI. + """ + assert ON_CI + return '::endgroup::' + + def partial_compare(val1, val2, *, indent=0): """Do a partial comparison between the given values. @@ -132,6 +158,9 @@ def partial_compare(val1, val2, *, indent=0): This happens recursively. """ + if ON_CI and indent == 0: + print(gha_group_begin('Comparison')) + print_i("Comparing", indent) print_i(pprint.pformat(val1), indent + 1) print_i("|---- to ----", indent) @@ -163,6 +192,10 @@ def partial_compare(val1, val2, *, indent=0): print_i("|======= Comparing via ==", indent) outcome = _partial_compare_eq(val1, val2, indent=indent) print_i("---> {}".format(outcome), indent) + + if ON_CI and indent == 0: + print(gha_group_end()) + return outcome @@ -227,3 +260,60 @@ def easylist_txt(): def easyprivacy_txt(): return _decompress_gzip_datafile("easyprivacy.txt.gz") + + +def seccomp_args(qt_flag): + """Get necessary flags to disable the seccomp BPF sandbox. + + This is needed for some QtWebEngine setups, with older Qt versions but + newer kernels. + + Args: + qt_flag: Add a '--qt-flag' argument. + """ + affected_versions = set() + for base, patch_range in [ + ## seccomp-bpf failure in syscall 0281 + ## https://github.com/qutebrowser/qutebrowser/issues/3163 + # 5.7.1 + ('5.7', [1]), + + ## seccomp-bpf failure in syscall 0281 (clock_nanosleep) + ## https://bugreports.qt.io/browse/QTBUG-81313 + # 5.11.0 to 5.11.3 (inclusive) + ('5.11', range(0, 4)), + # 5.12.0 to 5.12.7 (inclusive) + ('5.12', range(0, 8)), + # 5.13.0 to 5.13.2 (inclusive) + ('5.13', range(0, 3)), + # 5.14.0 + ('5.14', [0]), + ]: + for patch in patch_range: + affected_versions.add('{}.{}'.format(base, patch)) + + version = (PYQT_WEBENGINE_VERSION_STR + if PYQT_WEBENGINE_VERSION_STR is not None + else qVersion()) + if version in affected_versions: + disable_arg = 'disable-seccomp-filter-sandbox' + return ['--qt-flag', disable_arg] if qt_flag else ['--' + disable_arg] + + return [] + + +def import_userscript(name): + """Import a userscript via importlib. + + This is needed because userscripts don't have a .py extension and violate + Python's module naming convention. + """ + repo_root = pathlib.Path(__file__).resolve().parents[2] + script_path = repo_root / 'misc' / 'userscripts' / name + module_name = name.replace('-', '_') + loader = importlib.machinery.SourceFileLoader( + module_name, str(script_path)) + spec = importlib.util.spec_from_loader(module_name, loader) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module |