1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2017-2020 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
import logging
import pytest
QtWebEngineWidgets = pytest.importorskip('PyQt5.QtWebEngineWidgets')
from qutebrowser.browser.webengine import webenginesettings
from qutebrowser.utils import usertypes
@pytest.fixture
def global_settings(monkeypatch, default_profile):
wrapper = webenginesettings._SettingsWrapper()
settings = webenginesettings.WebEngineSettings(wrapper)
settings.init_settings()
monkeypatch.setattr(webenginesettings, 'global_settings', settings)
@pytest.fixture
def default_profile(monkeypatch):
"""A profile to use which is set as default_profile.
Note we use a "private" profile here to avoid actually storing data during tests.
"""
profile = QtWebEngineWidgets.QWebEngineProfile()
profile.setter = webenginesettings.ProfileSetter(profile)
monkeypatch.setattr(profile, 'isOffTheRecord', lambda: False)
monkeypatch.setattr(webenginesettings, 'default_profile', profile)
return profile
@pytest.fixture
def private_profile(monkeypatch):
"""A profile to use which is set as private_profile."""
profile = QtWebEngineWidgets.QWebEngineProfile()
profile.setter = webenginesettings.ProfileSetter(profile)
monkeypatch.setattr(webenginesettings, 'private_profile', profile)
return profile
def test_big_cache_size(config_stub, default_profile):
"""Make sure a too big cache size is handled correctly."""
config_stub.val.content.cache.size = 2 ** 63 - 1
default_profile.setter.set_http_cache_size()
assert default_profile.httpCacheMaximumSize() == 2 ** 31 - 1
def test_non_existing_dict(config_stub, monkeypatch, message_mock, caplog,
global_settings):
monkeypatch.setattr(webenginesettings.spell, 'local_filename',
lambda _code: None)
config_stub.val.spellcheck.languages = ['af-ZA']
with caplog.at_level(logging.WARNING):
webenginesettings._update_settings('spellcheck.languages')
msg = message_mock.getmsg(usertypes.MessageLevel.warning)
expected = ("Language af-ZA is not installed - see scripts/dictcli.py in "
"qutebrowser's sources")
assert msg.text == expected
def test_existing_dict(config_stub, monkeypatch, global_settings,
default_profile, private_profile):
monkeypatch.setattr(webenginesettings.spell, 'local_filename',
lambda _code: 'en-US-8-0')
config_stub.val.spellcheck.languages = ['en-US']
webenginesettings._update_settings('spellcheck.languages')
for profile in [default_profile, private_profile]:
assert profile.isSpellCheckEnabled()
assert profile.spellCheckLanguages() == ['en-US-8-0']
def test_spell_check_disabled(config_stub, monkeypatch, global_settings,
default_profile, private_profile):
config_stub.val.spellcheck.languages = []
webenginesettings._update_settings('spellcheck.languages')
for profile in [default_profile, private_profile]:
assert not profile.isSpellCheckEnabled()
def test_parsed_user_agent(qapp):
webenginesettings.init_user_agent()
parsed = webenginesettings.parsed_user_agent
assert parsed.upstream_browser_key == 'Chrome'
assert parsed.qt_key == 'QtWebEngine'
|