From 922c8c86c47651cee1c228f35f7837ce4ea1b404 Mon Sep 17 00:00:00 2001 From: Ted Morse Date: Sun, 29 Nov 2020 10:58:27 -0800 Subject: Only apply blink-settings on Qt 15.5.2 Turns out Qt 5.15.{0,1} also needs `--force-dark-mode`. This commit fixes it to only use the blink-setting on Qt 5.15.2 and up. It also parameterizes the tests better to test that the settings work on their respective Qt versions. (cherry picked from commit 1f67527662a076aa0a3caf5348f9ba6b663f4a0e) --- qutebrowser/config/qtargs.py | 12 +++++++----- tests/helpers/utils.py | 3 --- tests/unit/config/test_qtargs.py | 29 ++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/qutebrowser/config/qtargs.py b/qutebrowser/config/qtargs.py index b42484a08..0afea7196 100644 --- a/qutebrowser/config/qtargs.py +++ b/qutebrowser/config/qtargs.py @@ -79,8 +79,10 @@ def _darkmode_prefix() -> str: def _darkmode_settings() -> typing.Iterator[typing.Tuple[str, str]]: """Get necessary blink settings to configure dark mode for QtWebEngine.""" - if (qtutils.version_check('5.15', compiled=False) and + if (qtutils.version_check('5.15.2', compiled=False) and config.val.colors.webpage.prefers_color_scheme_dark): + # In future versions of 'blink', (> Qt 5.15.2) the enumeration has + # changed and this will need to be set to '0' instead. yield "preferredColorScheme", "1" if not config.val.colors.webpage.darkmode.enabled: @@ -335,10 +337,10 @@ def _qtwebengine_settings_args() -> typing.Iterator[str]: } if (qtutils.version_check('5.14', compiled=False) and - not qtutils.version_check('5.15', compiled=False)): - # In Qt 5.14, `--force-dark-mode` is used to set the preferred - # colorscheme. In Qt 5.15, this is handled by a blink-setting - # instead. + not qtutils.version_check('5.15.2', compiled=False)): + # In Qt 5.14 to 5.15.1, `--force-dark-mode` is used to set the + # preferred colorscheme. In Qt 5.15.2, this is handled by a + # blink-setting instead. settings['colors.webpage.prefers_color_scheme_dark'] = { True: '--force-dark-mode', False: None, diff --git a/tests/helpers/utils.py b/tests/helpers/utils.py index 64779dfc6..46787391d 100644 --- a/tests/helpers/utils.py +++ b/tests/helpers/utils.py @@ -52,9 +52,6 @@ qt514 = pytest.mark.skipif( skip_qt511 = pytest.mark.skipif( qtutils.version_check('5.11'), reason="Needs Qt 5.10 or earlier") -qt515 = pytest.mark.skipif( - not qtutils.version_check('5.15'), reason="Needs Qt 5.15 or newer") - class PartialCompareOutcome: diff --git a/tests/unit/config/test_qtargs.py b/tests/unit/config/test_qtargs.py index 644765a58..782444da6 100644 --- a/tests/unit/config/test_qtargs.py +++ b/tests/unit/config/test_qtargs.py @@ -320,10 +320,14 @@ class TestQtArgs: @pytest.mark.parametrize('dark, qt_version, added', [ (True, "5.13", False), (True, "5.14", True), - (True, "5.15", False), + (True, "5.15.0", True), + (True, "5.15.1", True), + (True, "5.15.2", False), (False, "5.13", False), (False, "5.14", False), - (False, "5.15", False), + (False, "5.15.0", False), + (False, "5.15.1", False), + (False, "5.15.2", False), ]) @utils.qt514 def test_prefers_color_scheme_dark(self, config_stub, monkeypatch, parser, @@ -591,17 +595,24 @@ class TestDarkMode: assert opt.restart, name assert opt.raw_backends == backends, name - @pytest.mark.parametrize('enabled, expected', [ + @pytest.mark.parametrize('qversion, enabled, expected', [ # Disabled or nothing set - (False, []), + ("5.14", False, []), + ("5.15.0", False, []), + ("5.15.1", False, []), + ("5.15.2", False, []), # Enabled in configuration - (True, [("preferredColorScheme", "1")]), + ("5.14", True, []), + ("5.15.0", True, []), + ("5.15.1", True, []), + ("5.15.2", True, [("preferredColorScheme", "1")]), ]) - @utils.qt515 - def test_colorscheme(self, config_stub, monkeypatch, enabled, expected): - config_stub.set_obj('colors.webpage.prefers_color_scheme_dark', enabled) - assert list(qtargs._darkmode_settings()) == expected + @utils.qt514 + def test_colorscheme(self, config_stub, monkeypatch, qversion, enabled, expected): + monkeypatch.setattr(qtargs.qtutils, 'qVersion', lambda: qversion) + config_stub.val.colors.webpage.prefers_color_scheme_dark = enabled + assert list(qtargs._dark_mode_settings()) == expected class TestEnvVars: -- cgit v1.2.3-54-g00ecf