diff options
author | Ander Punnar <ander@kvlt.ee> | 2021-06-01 20:36:56 +0300 |
---|---|---|
committer | Ander Punnar <ander@kvlt.ee> | 2021-06-01 20:36:56 +0300 |
commit | 00a394506f149b600c9869a63dd37e847fe17cfe (patch) | |
tree | 58c1ba094a79fa537abada91426cf2f01610c9c2 /tests | |
parent | 4e47af21586aad3846c2458dc0c8243e9d6eb792 (diff) | |
parent | b34988055071522e72c73b0f3a0bd3a6b59c6b9a (diff) | |
download | qutebrowser-00a394506f149b600c9869a63dd37e847fe17cfe.tar.gz qutebrowser-00a394506f149b600c9869a63dd37e847fe17cfe.zip |
Merge remote-tracking branch 'origin/master' into 4nd3r/hostblock_subdomains
Diffstat (limited to 'tests')
-rw-r--r-- | tests/end2end/data/downloads/mhtml/complex/complex.html | 2 | ||||
-rw-r--r-- | tests/end2end/data/downloads/mhtml/complex/complex.mht | 2 | ||||
-rw-r--r-- | tests/end2end/fixtures/testprocess.py | 5 | ||||
-rw-r--r-- | tests/end2end/test_invocations.py | 100 | ||||
-rw-r--r-- | tests/unit/config/test_configtypes.py | 5 | ||||
-rw-r--r-- | tests/unit/config/test_configutils.py | 4 | ||||
-rw-r--r-- | tests/unit/misc/test_editor.py | 11 |
7 files changed, 104 insertions, 25 deletions
diff --git a/tests/end2end/data/downloads/mhtml/complex/complex.html b/tests/end2end/data/downloads/mhtml/complex/complex.html index b298aa37c..d44e9be0f 100644 --- a/tests/end2end/data/downloads/mhtml/complex/complex.html +++ b/tests/end2end/data/downloads/mhtml/complex/complex.html @@ -91,7 +91,7 @@ <div class="dyk"> ...the IRC channel for qutebrowser is <code>#qutebrowser</code> on - irc.freenode.net + irc.libera.chat </div> <div class="dyk"> diff --git a/tests/end2end/data/downloads/mhtml/complex/complex.mht b/tests/end2end/data/downloads/mhtml/complex/complex.mht index 0467da22f..a458f4dcb 100644 --- a/tests/end2end/data/downloads/mhtml/complex/complex.mht +++ b/tests/end2end/data/downloads/mhtml/complex/complex.mht @@ -108,7 +108,7 @@ aster/doc/contributing.asciidoc"> =20
<div class=3D"dyk">
...the IRC channel for qutebrowser is <code>#qutebrowser</code> on
- irc.freenode.net
+ irc.libera.chat
</div>
=20
<div class=3D"dyk">
diff --git a/tests/end2end/fixtures/testprocess.py b/tests/end2end/fixtures/testprocess.py index 33b154e9a..96e700390 100644 --- a/tests/end2end/fixtures/testprocess.py +++ b/tests/end2end/fixtures/testprocess.py @@ -25,7 +25,7 @@ import warnings import dataclasses import pytest -import pytestqt.plugin +import pytestqt.wait_signal from PyQt5.QtCore import (pyqtSlot, pyqtSignal, QProcess, QObject, QElapsedTimer, QProcessEnvironment) from PyQt5.QtTest import QSignalSpy @@ -198,8 +198,7 @@ class Process(QObject): Should be used in a contextmanager. """ - blocker = pytestqt.plugin.SignalBlocker(timeout=timeout, - raising=raising) + blocker = pytestqt.wait_signal.SignalBlocker(timeout=timeout, raising=raising) blocker.connect(signal) return blocker diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index 1ce22b7ea..97c04eb0d 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -26,6 +26,7 @@ import logging import importlib import re import json +import platform import pytest from PyQt5.QtCore import QProcess, QPoint @@ -39,6 +40,14 @@ ascii_locale = pytest.mark.skipif(sys.hexversion >= 0x03070000, "locale with LC_ALL=C") +# For some reason (some floating point rounding differences?), color values are +# slightly different (and wrong!) on ARM machines. We adjust our expected values +# accordingly, since we don't really care about the exact value, we just want to +# know that the underlying Chromium is respecting our preferences. +# FIXME what to do about 32-bit ARM? +IS_ARM = platform.machine() == 'aarch64' + + def _base_args(config): """Get the arguments to pass with every invocation.""" args = ['--debug', '--json-logging', '--no-err-windows'] @@ -55,7 +64,16 @@ def _base_args(config): @pytest.fixture -def temp_basedir_env(tmp_path, short_tmpdir): +def runtime_tmpdir(short_tmpdir): + """A directory suitable for XDG_RUNTIME_DIR.""" + runtime_dir = short_tmpdir / 'rt' + runtime_dir.ensure(dir=True) + runtime_dir.chmod(0o700) + return runtime_dir + + +@pytest.fixture +def temp_basedir_env(tmp_path, runtime_tmpdir): """Return a dict of environment variables that fakes --temp-basedir. We can't run --basedir or --temp-basedir for some tests, so we mess with @@ -63,12 +81,8 @@ def temp_basedir_env(tmp_path, short_tmpdir): """ data_dir = tmp_path / 'data' config_dir = tmp_path / 'config' - runtime_dir = short_tmpdir / 'rt' cache_dir = tmp_path / 'cache' - runtime_dir.ensure(dir=True) - runtime_dir.chmod(0o700) - lines = [ '[general]', 'quickstart-done = 1', @@ -83,7 +97,7 @@ def temp_basedir_env(tmp_path, short_tmpdir): env = { 'XDG_DATA_HOME': str(data_dir), 'XDG_CONFIG_HOME': str(config_dir), - 'XDG_RUNTIME_DIR': str(runtime_dir), + 'XDG_RUNTIME_DIR': str(runtime_tmpdir), 'XDG_CACHE_HOME': str(cache_dir), } return env @@ -512,7 +526,8 @@ def test_preferred_colorscheme_with_dark_mode( # No workaround known. expected_text = 'Light preference detected.' # light website color, inverted by darkmode - expected_color = testutils.Color(127, 127, 127) + expected_color = (testutils.Color(123, 125, 123) if IS_ARM + else testutils.Color(127, 127, 127)) xfail = "Chromium bug 1177973" elif qtwe_version == utils.VersionNumber(5, 15, 2): # Our workaround breaks when dark mode is enabled... @@ -524,7 +539,8 @@ def test_preferred_colorscheme_with_dark_mode( # Qt 5.14 and 5.15.0/.1 work correctly. # Hopefully, so does Qt 6.x in the future? expected_text = 'Dark preference detected.' - expected_color = testutils.Color(34, 34, 34) # dark website color + expected_color = (testutils.Color(33, 32, 33) if IS_ARM + else testutils.Color(34, 34, 34)) # dark website color xfail = False pos = QPoint(0, 0) @@ -625,30 +641,51 @@ def test_cookies_store(quteproc_new, request, short_tmpdir, store): quteproc_new.wait_for_quit() +# The 'colors' dictionaries in the parametrize decorator below have (QtWebEngine +# version, CPU architecture) as keys. Either of those (or both) can be None to +# say "on all other Qt versions" or "on all other CPU architectures". @pytest.mark.parametrize('filename, algorithm, colors', [ ( 'blank', 'lightness-cielab', { - '5.15': testutils.Color(18, 18, 18), - '5.14': testutils.Color(27, 27, 27), - None: testutils.Color(0, 0, 0), + ('5.15', None): testutils.Color(18, 18, 18), + ('5.15', 'aarch64'): testutils.Color(16, 16, 16), + ('5.14', None): testutils.Color(27, 27, 27), + ('5.14', 'aarch64'): testutils.Color(24, 24, 24), + (None, None): testutils.Color(0, 0, 0), } ), - ('blank', 'lightness-hsl', {None: testutils.Color(0, 0, 0)}), - ('blank', 'brightness-rgb', {None: testutils.Color(0, 0, 0)}), + ('blank', 'lightness-hsl', {(None, None): testutils.Color(0, 0, 0)}), + ('blank', 'brightness-rgb', {(None, None): testutils.Color(0, 0, 0)}), ( 'yellow', 'lightness-cielab', { - '5.15': testutils.Color(35, 34, 0), - '5.14': testutils.Color(35, 34, 0), - None: testutils.Color(204, 204, 0), + ('5.15', None): testutils.Color(35, 34, 0), + ('5.15', 'aarch64'): testutils.Color(33, 32, 0), + ('5.14', None): testutils.Color(35, 34, 0), + ('5.14', 'aarch64'): testutils.Color(33, 32, 0), + (None, None): testutils.Color(204, 204, 0), + } + ), + ( + 'yellow', + 'lightness-hsl', + { + (None, None): testutils.Color(204, 204, 0), + (None, 'aarch64'): testutils.Color(206, 207, 0), + }, + ), + ( + 'yellow', + 'brightness-rgb', + { + (None, None): testutils.Color(0, 0, 204), + (None, 'aarch64'): testutils.Color(0, 0, 206), } ), - ('yellow', 'lightness-hsl', {None: testutils.Color(204, 204, 0)}), - ('yellow', 'brightness-rgb', {None: testutils.Color(0, 0, 204)}), ]) def test_dark_mode(webengine_versions, quteproc_new, request, filename, algorithm, colors): @@ -664,7 +701,17 @@ def test_dark_mode(webengine_versions, quteproc_new, request, ver = webengine_versions.webengine minor_version = str(ver.strip_patch()) - expected = colors.get(minor_version, colors[None]) + + arch = platform.machine() + for key in [ + (minor_version, arch), + (minor_version, None), + (None, arch), + (None, None), + ]: + if key in colors: + expected = colors[key] + break quteproc_new.open_path(f'data/darkmode/{filename}.html') @@ -691,9 +738,11 @@ def test_dark_mode_mathml(quteproc_new, request, qtbot): quteproc_new.wait_for_js('Image loaded') # First make sure loading finished by looking outside of the image + expected = testutils.Color(0, 0, 206) if IS_ARM else testutils.Color(0, 0, 204) + quteproc_new.get_screenshot( probe_pos=QPoint(105, 0), - probe_color=testutils.Color(0, 0, 204), + probe_color=expected, ) # Then get the actual formula color, probing again in case it's not displayed yet... @@ -743,3 +792,14 @@ def test_unavailable_backend(request, quteproc_new): message=('*qutebrowser tried to start with the Qt* backend but failed ' 'because * could not be imported.*')) line.expected = True + + +def test_json_logging_without_debug(request, quteproc_new, runtime_tmpdir): + args = _base_args(request.config) + ['--temp-basedir', ':quit'] + args.remove('--debug') + args.remove('about:blank') # interfers with :quit at the end + + quteproc_new.exit_expected = True + quteproc_new.start(args, env={'XDG_RUNTIME_DIR': str(runtime_tmpdir)}) + assert not quteproc_new.is_running() + assert not quteproc_new.captured_log diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 3e1d15099..66b152937 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -1839,6 +1839,11 @@ class TestFormatString: with pytest.raises(configexc.ValidationError): typ.to_py(val) + def test_invalid_encoding(self, klass): + typ = klass(fields=[], encoding='ascii') + with pytest.raises(configexc.ValidationError): + typ.to_py('fooäbar') + @pytest.mark.parametrize('value', [ None, ['one', 'two'], diff --git a/tests/unit/config/test_configutils.py b/tests/unit/config/test_configutils.py index 725a38c28..e7ce15aff 100644 --- a/tests/unit/config/test_configutils.py +++ b/tests/unit/config/test_configutils.py @@ -382,5 +382,9 @@ class TestFontFamilies: if info.family() == fallback_family: return + if info.family() == 'Noto Sans Mono': + # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-94090 + return + # If we didn't fall back, we should've gotten a fixed-pitch font. assert info.fixedPitch(), info.family() diff --git a/tests/unit/misc/test_editor.py b/tests/unit/misc/test_editor.py index cd21308f8..8e5597a0e 100644 --- a/tests/unit/misc/test_editor.py +++ b/tests/unit/misc/test_editor.py @@ -148,6 +148,17 @@ class TestFileHandling: assert msg.text.startswith("Failed to create initial file: ") assert editor._proc is None + def test_encode_error(self, message_mock, editor, caplog, config_stub): + """Test file handling when the initial text can't be encoded.""" + config_stub.val.editor.encoding = 'ascii' + + with caplog.at_level(logging.ERROR): + editor.edit("fooäbar") + + msg = message_mock.getmsg(usertypes.MessageLevel.error) + assert msg.text.startswith("Failed to create initial file: ") + assert editor._proc is None + def test_double_edit(self, editor): editor.edit("") with pytest.raises(ValueError): |