コード例 #1
0
def test_colorscheme(config_stub, value, webengine_version, expected):
    versions = version.WebEngineVersions.from_pyqt(webengine_version)
    if value is not None:
        config_stub.val.colors.webpage.preferred_color_scheme = value

    darkmode_settings = darkmode.settings(versions=versions, special_flags=[])
    assert darkmode_settings['blink-settings'] == expected
コード例 #2
0
def _qtwebengine_args(
    namespace: argparse.Namespace,
    special_flags: Sequence[str],
) -> Iterator[str]:
    """Get the QtWebEngine arguments to use based on the config."""
    versions = version.qtwebengine_versions(avoid_init=True)

    qt_514_ver = utils.VersionNumber(5, 14)
    qt_515_ver = utils.VersionNumber(5, 15)
    if qt_514_ver <= versions.webengine < qt_515_ver:
        # WORKAROUND for https://bugreports.qt.io/browse/QTBUG-82105
        yield '--disable-shared-workers'

    # WORKAROUND equivalent to
    # https://codereview.qt-project.org/c/qt/qtwebengine/+/256786
    # also see:
    # https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/265753
    if versions.webengine >= utils.VersionNumber(5, 12, 3):
        if 'stack' in namespace.debug_flags:
            # Only actually available in Qt 5.12.5, but let's save another
            # check, as passing the option won't hurt.
            yield '--enable-in-process-stack-traces'
    else:
        if 'stack' not in namespace.debug_flags:
            yield '--disable-in-process-stack-traces'

    lang_override = _get_lang_override(
        webengine_version=versions.webengine,
        locale_name=QLocale().bcp47Name(),
    )
    if lang_override is not None:
        yield f'--lang={lang_override}'

    if 'chromium' in namespace.debug_flags:
        yield '--enable-logging'
        yield '--v=1'

    if 'wait-renderer-process' in namespace.debug_flags:
        yield '--renderer-startup-dialog'

    from qutebrowser.browser.webengine import darkmode
    darkmode_settings = darkmode.settings(
        versions=versions,
        special_flags=special_flags,
    )
    for switch_name, values in darkmode_settings.items():
        # If we need to use other switches (say, --enable-features), we might need to
        # refactor this so values still get combined with existing ones.
        assert switch_name in ['dark-mode-settings',
                               'blink-settings'], switch_name
        yield f'--{switch_name}=' + ','.join(f'{k}={v}' for k, v in values)

    enabled_features, disabled_features = _qtwebengine_features(
        versions, special_flags)
    if enabled_features:
        yield _ENABLE_FEATURES + ','.join(enabled_features)
    if disabled_features:
        yield _DISABLE_FEATURES + ','.join(disabled_features)

    yield from _qtwebengine_settings_args(versions)
コード例 #3
0
def test_basics(config_stub, monkeypatch, settings, expected):
    for k, v in settings.items():
        config_stub.set_obj('colors.webpage.darkmode.' + k, v)
    monkeypatch.setattr(darkmode, '_variant',
                        lambda: darkmode.Variant.qt_515_2)

    if expected:
        expected.append(('forceDarkModeImagePolicy', '2'))

    assert list(darkmode.settings()) == expected
コード例 #4
0
def test_pass_through_existing_settings(config_stub, flag, expected):
    config_stub.val.colors.webpage.darkmode.enabled = True
    versions = version.WebEngineVersions.from_pyqt('5.15.1')
    settings = darkmode.settings(versions=versions, special_flags=[flag])

    dark_mode_expected = [
        ('darkModeEnabled', 'true'),
        ('darkModeImagePolicy', '2'),
    ]
    assert settings['blink-settings'] == expected + dark_mode_expected
コード例 #5
0
def test_basics(config_stub, settings, expected):
    for k, v in settings.items():
        config_stub.set_obj('colors.webpage.darkmode.' + k, v)

    if expected:
        expected.append(('darkModeImagePolicy', '2'))

    # Using Qt 5.15.1 because it has the least special cases.
    versions = version.WebEngineVersions.from_pyqt('5.15.1')
    darkmode_settings = darkmode.settings(versions=versions, special_flags=[])
    assert darkmode_settings['blink-settings'] == expected
コード例 #6
0
def test_qt_version_differences(config_stub, qversion, expected):
    settings = {
        'enabled': True,
        'algorithm': 'brightness-rgb',
        'grayscale.all': True,
    }
    for k, v in settings.items():
        config_stub.set_obj('colors.webpage.darkmode.' + k, v)

    versions = version.WebEngineVersions.from_pyqt(qversion)
    darkmode_settings = darkmode.settings(versions=versions, special_flags=[])
    assert darkmode_settings == expected
コード例 #7
0
def test_customization(config_stub, monkeypatch, setting, value, exp_key, exp_val):
    config_stub.val.colors.webpage.darkmode.enabled = True
    config_stub.set_obj('colors.webpage.darkmode.' + setting, value)
    monkeypatch.setattr(darkmode, '_variant', lambda: darkmode.Variant.qt_515_2)

    expected = []
    expected.append(('forceDarkModeEnabled', 'true'))
    if exp_key != 'ImagePolicy':
        expected.append(('forceDarkModeImagePolicy', '2'))
    expected.append(('forceDarkMode' + exp_key, exp_val))

    assert list(darkmode.settings()) == expected
コード例 #8
0
def test_qt_version_differences(config_stub, monkeypatch, qversion, expected):
    versions = version.WebEngineVersions.from_pyqt(qversion)
    monkeypatch.setattr(version, 'qtwebengine_versions', lambda avoid_init: versions)

    settings = {
        'enabled': True,
        'algorithm': 'brightness-rgb',
        'grayscale.all': True,
    }
    for k, v in settings.items():
        config_stub.set_obj('colors.webpage.darkmode.' + k, v)

    assert list(darkmode.settings()) == expected
コード例 #9
0
def test_customization(config_stub, setting, value, exp_key, exp_val):
    config_stub.val.colors.webpage.darkmode.enabled = True
    config_stub.set_obj('colors.webpage.darkmode.' + setting, value)

    expected = []
    expected.append(('darkModeEnabled', 'true'))
    if exp_key != 'ImagePolicy':
        expected.append(('darkModeImagePolicy', '2'))
    expected.append(('darkMode' + exp_key, exp_val))

    versions = version.WebEngineVersions.from_pyqt('5.15.1')
    darkmode_settings = darkmode.settings(versions=versions, special_flags=[])
    assert darkmode_settings['blink-settings'] == expected
コード例 #10
0
def _qtwebengine_args(
    namespace: argparse.Namespace,
    feature_flags: Sequence[str],
) -> Iterator[str]:
    """Get the QtWebEngine arguments to use based on the config."""
    is_qt_514 = (qtutils.version_check('5.14', compiled=False)
                 and not qtutils.version_check('5.15', compiled=False))

    if not qtutils.version_check('5.11', compiled=False) or is_qt_514:
        # WORKAROUND equivalent to
        # https://codereview.qt-project.org/#/c/217932/
        # Needed for Qt < 5.9.5 and < 5.10.1
        #
        # For Qt 5,14, WORKAROUND for
        # https://bugreports.qt.io/browse/QTBUG-82105
        yield '--disable-shared-workers'

    # WORKAROUND equivalent to
    # https://codereview.qt-project.org/c/qt/qtwebengine/+/256786
    # also see:
    # https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/265753
    if qtutils.version_check('5.12.3', compiled=False):
        if 'stack' in namespace.debug_flags:
            # Only actually available in Qt 5.12.5, but let's save another
            # check, as passing the option won't hurt.
            yield '--enable-in-process-stack-traces'
    else:
        if 'stack' not in namespace.debug_flags:
            yield '--disable-in-process-stack-traces'

    if 'chromium' in namespace.debug_flags:
        yield '--enable-logging'
        yield '--v=1'

    if 'wait-renderer-process' in namespace.debug_flags:
        yield '--renderer-startup-dialog'

    from qutebrowser.browser.webengine import darkmode
    blink_settings = list(darkmode.settings())
    if blink_settings:
        yield '--blink-settings=' + ','.join('{}={}'.format(k, v)
                                             for k, v in blink_settings)

    enabled_features = list(_qtwebengine_enabled_features(feature_flags))
    if enabled_features:
        yield '--enable-features=' + ','.join(enabled_features)

    yield from _qtwebengine_settings_args()
コード例 #11
0
ファイル: test_darkmode.py プロジェクト: psvenk/qutebrowser
def test_broken_smart_images_policy(config_stub, caplog):
    config_stub.val.colors.webpage.darkmode.enabled = True
    config_stub.val.colors.webpage.darkmode.policy.images = 'smart'
    versions = version.WebEngineVersions.from_pyqt('5.15.0')

    with caplog.at_level(logging.WARNING):
        darkmode_settings = darkmode.settings(versions=versions, special_flags=[])

    assert caplog.messages[-1] == (
        'Ignoring colors.webpage.darkmode.policy.images = smart because of '
        'Qt 5.15.0 bug')

    expected = [
        [('darkModeEnabled', 'true')],  # Qt 5.15
        [('darkMode', '4')],  # Qt 5.14
    ]
    assert darkmode_settings['blink-settings'] in expected
コード例 #12
0
def test_broken_smart_images_policy(config_stub, monkeypatch, caplog):
    config_stub.val.colors.webpage.darkmode.enabled = True
    config_stub.val.colors.webpage.darkmode.policy.images = 'smart'
    monkeypatch.setattr(darkmode, 'PYQT_WEBENGINE_VERSION', 0x050f00)

    with caplog.at_level(logging.WARNING):
        settings = list(darkmode.settings())

    assert caplog.messages[-1] == (
        'Ignoring colors.webpage.darkmode.policy.images = smart because of '
        'Qt 5.15.0 bug')

    expected = [
        [('darkModeEnabled', 'true')],  # Qt 5.15
        [('darkMode', '4')],  # Qt 5.14
    ]
    assert settings in expected
コード例 #13
0
def test_broken_smart_images_policy(config_stub, monkeypatch, caplog):
    config_stub.val.colors.webpage.darkmode.enabled = True
    config_stub.val.colors.webpage.darkmode.policy.images = 'smart'
    versions = version.WebEngineVersions.from_pyqt('5.15.0')
    monkeypatch.setattr(version, 'qtwebengine_versions', lambda avoid_init: versions)

    with caplog.at_level(logging.WARNING):
        settings = list(darkmode.settings())

    assert caplog.messages[-1] == (
        'Ignoring colors.webpage.darkmode.policy.images = smart because of '
        'Qt 5.15.0 bug')

    expected = [
        [('darkModeEnabled', 'true')],  # Qt 5.15
        [('darkMode', '4')],  # Qt 5.14
    ]
    assert settings in expected
コード例 #14
0
def test_qt_version_differences(config_stub, monkeypatch, qversion, expected):
    monkeypatch.setattr(darkmode.qtutils, 'qVersion', lambda: qversion)

    major, minor, patch = [int(part) for part in qversion.split('.')]
    hexversion = major << 16 | minor << 8 | patch
    if major > 5 or minor >= 13:
        # Added in Qt 5.13
        monkeypatch.setattr(darkmode, 'PYQT_WEBENGINE_VERSION', hexversion)

    settings = {
        'enabled': True,
        'algorithm': 'brightness-rgb',
        'grayscale.all': True,
    }
    for k, v in settings.items():
        config_stub.set_obj('colors.webpage.darkmode.' + k, v)

    assert list(darkmode.settings()) == expected
コード例 #15
0
def test_colorscheme(config_stub, monkeypatch, webengine_version, enabled, expected):
    versions = version.WebEngineVersions.from_pyqt(webengine_version)
    monkeypatch.setattr(version, 'qtwebengine_versions', lambda avoid_init: versions)
    config_stub.val.colors.webpage.prefers_color_scheme_dark = enabled
    assert list(darkmode.settings()) == expected
コード例 #16
0
def test_colorscheme_gentoo_workaround(config_stub, gentoo_versions):
    config_stub.val.colors.webpage.preferred_color_scheme = "dark"
    darkmode_settings = darkmode.settings(versions=gentoo_versions,
                                          special_flags=[])
    assert darkmode_settings['blink-settings'] == [("preferredColorScheme",
                                                    "0")]
コード例 #17
0
def test_colorscheme(config_stub, monkeypatch, qversion, enabled, expected):
    monkeypatch.setattr(darkmode.qtutils, 'qVersion', lambda: qversion)
    config_stub.val.colors.webpage.prefers_color_scheme_dark = enabled
    assert list(darkmode.settings()) == expected
コード例 #18
0
def test_colorscheme_gentoo_workaround(config_stub, gentoo_version_patch):
    config_stub.val.colors.webpage.prefers_color_scheme_dark = True
    assert list(darkmode.settings()) == [("preferredColorScheme", "0")]