From fd429fd3a59b2f1b693bdc68d177e63c3254b822 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 28 Jan 2021 15:56:14 +0100 Subject: Add a warning if QTWEBENGINE_CHROMIUM_FLAGS is set See #6065 (cherry picked from commit 38fec3726fc0aa518a3637574f7e3e0029df41d4) --- qutebrowser/config/qtargs.py | 11 ++++++++++- tests/unit/config/test_qtargs.py | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/qutebrowser/config/qtargs.py b/qutebrowser/config/qtargs.py index 6058931b3..415a76f25 100644 --- a/qutebrowser/config/qtargs.py +++ b/qutebrowser/config/qtargs.py @@ -26,7 +26,7 @@ from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple from qutebrowser.config import config from qutebrowser.misc import objects -from qutebrowser.utils import usertypes, qtutils, utils +from qutebrowser.utils import usertypes, qtutils, utils, log _ENABLE_FEATURES = '--enable-features=' @@ -266,6 +266,15 @@ def init_envvars() -> None: os.environ['QT_QUICK_BACKEND'] = 'software' elif software_rendering == 'chromium': os.environ['QT_WEBENGINE_DISABLE_NOUVEAU_WORKAROUND'] = '1' + + qtwe_flags_var = 'QTWEBENGINE_CHROMIUM_FLAGS' + qtwe_flags = os.environ.get(qtwe_flags_var) + if qtwe_flags is not None: + log.init.warning( + f"You have {qtwe_flags_var}={qtwe_flags!r} set in your environment. " + "This is currently unsupported and interferes with qutebrowser's own " + "flag handling (including workarounds for certain crashes). " + "Consider using the qt.args qutebrowser setting instead.") else: assert objects.backend == usertypes.Backend.QtWebKit, objects.backend diff --git a/tests/unit/config/test_qtargs.py b/tests/unit/config/test_qtargs.py index f560f7275..be27274e5 100644 --- a/tests/unit/config/test_qtargs.py +++ b/tests/unit/config/test_qtargs.py @@ -18,6 +18,7 @@ import sys import os +import logging import pytest @@ -552,3 +553,29 @@ class TestEnvVars: monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebKit) qtargs.init_envvars() + + @pytest.mark.parametrize('backend, value, expected', [ + (usertypes.Backend.QtWebKit, None, None), + (usertypes.Backend.QtWebKit, '--test', None), + + (usertypes.Backend.QtWebEngine, None, None), + (usertypes.Backend.QtWebEngine, '', "''"), + (usertypes.Backend.QtWebEngine, '--xyz', "'--xyz'"), + ]) + def test_qtwe_flags_warning(self, monkeypatch, config_stub, caplog, + backend, value, expected): + monkeypatch.setattr(qtargs.objects, 'backend', backend) + if value is None: + monkeypatch.delenv('QTWEBENGINE_CHROMIUM_FLAGS', raising=False) + else: + monkeypatch.setenv('QTWEBENGINE_CHROMIUM_FLAGS', value) + + with caplog.at_level(logging.WARNING): + qtargs.init_envvars() + + if expected is None: + assert not caplog.messages + else: + assert len(caplog.messages) == 1 + msg = caplog.messages[0] + assert msg.startswith(f'You have QTWEBENGINE_CHROMIUM_FLAGS={expected} set') -- cgit v1.2.3-54-g00ecf