diff options
author | toofar <toofar@spalge.com> | 2023-05-21 15:32:32 +1200 |
---|---|---|
committer | toofar <toofar@spalge.com> | 2023-05-21 15:32:32 +1200 |
commit | 8f89499cd5dcd5ff9db1e39e5677cb381eb28407 (patch) | |
tree | a8ac5ffd42e96c361e7f50c16066ff56913f78cf | |
parent | 025757a9c1784c96a9abcbadce8febe301cf41e1 (diff) | |
download | qutebrowser-feat/7662_scripts_on_profile.tar.gz qutebrowser-feat/7662_scripts_on_profile.zip |
Set up custom profile for webengine_tab fixturefeat/7662_scripts_on_profile
Make sure webenginesettings.default_profile is set before creating a
webengine tab. The webengine_tab fixture is used in the web_tab and
tabbed_browser fixtures.
Previously when `WebEngineView.__init__()` ran default_profile was set
to None which was causing the tabs to be created pointing to the Qt
default profile. Which was working fine until I moved the common JS
scripts used for hint mode etc up to the profile, now they just weren't
getting run.
Unfortunately using a fully set up default profile was too tricky for
me. The stuff in webenginesettings around setting up the default profile
is written specifically for setting up global stuff when the real
application. Apart from init_profile() depending on a bunch of other
global singletons (more to set up) the user agent setting is hard to
work with. There is an assert in `_init_default_profile()` if the global
user agent string is already set. If you bypass the global user agent
string then websettings chokes on it not being set (websettings is
called from webenginesettings).
That's probably all possible to unpick, just need to go through the
codepaths noting down what the regiments for the application path are
and what needs to be operable for tests. We will probably make it a bit
better when moving more towards containers anyway.
Alternatively we could have a session/request scope autouse=True fixture
to set up all the real global stuff. That might be benefitial to make
the tests faster anyway. Going through the full profile setup stuff for
every test might make them a bit slower.
A couple of the caret tests are still failing. Not sure why.
-rw-r--r-- | tests/helpers/fixtures.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/helpers/fixtures.py b/tests/helpers/fixtures.py index d4744c67d..5b0010411 100644 --- a/tests/helpers/fixtures.py +++ b/tests/helpers/fixtures.py @@ -40,6 +40,7 @@ import py.path from qutebrowser.qt.core import QSize, Qt from qutebrowser.qt.widgets import QWidget, QHBoxLayout, QVBoxLayout from qutebrowser.qt.network import QNetworkCookieJar +from qutebrowser.qt.webenginecore import QWebEngineProfile # TODO: will this break on webkit? import helpers.stubs as stubsmod import qutebrowser @@ -230,9 +231,36 @@ def webkit_tab(web_tab_setup, qtbot, cookiejar_and_cache, mode_manager, @pytest.fixture +def default_profile(testdata_scheme, monkeypatch): + """Make sure the qutebrowser default profile is set. + + This profile is not currently fully set up the same as the real one would + be. + webenginesettings._init_default_profile() does more setup, for example + setting cache and data dirs, but that method can't be called multiple + times which makes it hard to use in a fixture. Maybe we should make that + method re-runnable or pull out the non-global stuff when called with an + existing profile. + + There is a similar fixture in + tests/unit/browser/webengine/test_webenginesettings.py which we should + look at merging into this. + """ + webenginesettings = pytest.importorskip( + 'qutebrowser.browser.webengine.webenginesettings') + + profile = QWebEngineProfile() + _qute_scheme_handler.install(profile) + + webenginesettings._init_scripts_for_profile(profile) + + monkeypatch.setattr(webenginesettings, 'default_profile', profile) + + +@pytest.fixture def webengine_tab(web_tab_setup, qtbot, redirect_webengine_data, tabbed_browser_stubs, mode_manager, widget_container, - monkeypatch): + monkeypatch, default_profile): monkeypatch.setattr(objects, 'backend', usertypes.Backend.QtWebEngine) tabwidget = tabbed_browser_stubs[0].widget |