예제 #1
0
    def test_overlay_features_flag(self, config_stub, monkeypatch, parser,
                                   via_commandline, overlay, passed_features,
                                   expected_features):
        """If enable-features is already specified, we should combine both."""
        monkeypatch.setattr(qtargs.objects, 'backend',
                            usertypes.Backend.QtWebEngine)
        monkeypatch.setattr(qtargs.qtutils, 'version_check',
                            lambda version, exact=False, compiled=True:
                            True)
        monkeypatch.setattr(qtargs.utils, 'is_mac', False)
        # Avoid WebRTC pipewire feature
        monkeypatch.setattr(qtargs.utils, 'is_linux', False)

        stripped_prefix = 'enable-features='
        config_flag = stripped_prefix + passed_features

        config_stub.val.scrolling.bar = 'overlay' if overlay else 'never'
        config_stub.val.qt.args = ([] if via_commandline else [config_flag])

        parsed = parser.parse_args(['--qt-flag', config_flag]
                                   if via_commandline else [])
        args = qtargs.qt_args(parsed)

        prefix = '--' + stripped_prefix
        overlay_flag = prefix + 'OverlayScrollbar'
        combined_flag = prefix + expected_features
        assert len([arg for arg in args if arg.startswith(prefix)]) == 1
        assert combined_flag in args
        assert overlay_flag not in args
예제 #2
0
 def test_shared_workers(self, config_stub, monkeypatch, parser, backend,
                         expected):
     monkeypatch.setattr(qtargs.qtutils, 'qVersion', lambda: '5.14.0')
     monkeypatch.setattr(qtargs.objects, 'backend', backend)
     parsed = parser.parse_args([])
     args = qtargs.qt_args(parsed)
     assert ('--disable-shared-workers' in args) == expected
예제 #3
0
    def __init__(self, args):
        """Constructor.

        Args:
            Argument namespace from argparse.
        """
        self._last_focus_object = None

        qt_args = qtargs.qt_args(args)
        log.init.debug("Commandline args: {}".format(sys.argv[1:]))
        log.init.debug("Parsed: {}".format(args))
        log.init.debug("Qt arguments: {}".format(qt_args[1:]))
        super().__init__(qt_args)

        objects.args = args

        log.init.debug("Initializing application...")

        self.launch_time = datetime.datetime.now()
        self.focusObjectChanged.connect(  # type: ignore[attr-defined]
            self.on_focus_object_changed)

        self.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
        self.setAttribute(Qt.AA_MacDontSwapCtrlAndMeta, True)

        self.new_window.connect(self._on_new_window)
예제 #4
0
 def test_shared_workers(self, config_stub, version_patcher, monkeypatch, parser,
                         qt_version, backend, expected):
     version_patcher(qt_version)
     monkeypatch.setattr(qtargs.objects, 'backend', backend)
     parsed = parser.parse_args([])
     args = qtargs.qt_args(parsed)
     assert ('--disable-shared-workers' in args) == expected
예제 #5
0
 def test_with_settings(self, config_stub, parser):
     parsed = parser.parse_args(['--qt-flag', 'foo'])
     config_stub.val.qt.args = ['bar']
     args = qtargs.qt_args(parsed)
     assert args[0] == sys.argv[0]
     for arg in ['--foo', '--bar']:
         assert arg in args
예제 #6
0
 def test_disable_gpu(self, config, added, config_stub, monkeypatch,
                      parser):
     monkeypatch.setattr(qtargs.objects, 'backend',
                         usertypes.Backend.QtWebEngine)
     config_stub.val.qt.force_software_rendering = config
     parsed = parser.parse_args([])
     args = qtargs.qt_args(parsed)
     assert ('--disable-gpu' in args) == added
예제 #7
0
    def test_chromium_debug(self, monkeypatch, parser, flags, added):
        monkeypatch.setattr(qtargs.objects, 'backend',
                            usertypes.Backend.QtWebEngine)
        parsed = parser.parse_args(flags)
        args = qtargs.qt_args(parsed)

        for arg in ['--enable-logging', '--v=1']:
            assert (arg in args) == added
예제 #8
0
    def test_media_keys(self, config_stub, parser, enabled):
        config_stub.val.input.media_keys = enabled

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        assert ('--disable-features=HardwareMediaKeyHandling'
                in args) != enabled
예제 #9
0
    def test_canvas_reading(self, config_stub, monkeypatch, parser,
                            canvas_reading, added):
        monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebEngine)

        config_stub.val.content.canvas_reading = canvas_reading
        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)
        assert ('--disable-reading-from-canvas' in args) == added
예제 #10
0
 def test_shared_workers(self, config_stub, monkeypatch, parser, backend,
                         expected):
     monkeypatch.setattr(qtargs.qtutils,
                         'version_check',
                         lambda version, compiled=False: False)
     monkeypatch.setattr(qtargs.objects, 'backend', backend)
     parsed = parser.parse_args([])
     args = qtargs.qt_args(parsed)
     assert ('--disable-shared-workers' in args) == expected
예제 #11
0
    def test_qt_args(self, monkeypatch, config_stub, args, expected, parser):
        """Test commandline with no Qt arguments given."""
        # Avoid scrollbar overlay argument
        config_stub.val.scrolling.bar = 'never'
        # Avoid WebRTC pipewire feature
        monkeypatch.setattr(qtargs.utils, 'is_linux', False)

        parsed = parser.parse_args(args)
        assert qtargs.qt_args(parsed) == expected
예제 #12
0
 def test_qt_both(self, config_stub, parser):
     """Test commandline with a Qt argument and flag."""
     args = parser.parse_args(['--qt-arg', 'stylesheet', 'foobar',
                               '--qt-flag', 'reverse'])
     qt_args = qtargs.qt_args(args)
     assert qt_args[0] == sys.argv[0]
     assert '--reverse' in qt_args
     assert '--stylesheet' in qt_args
     assert 'foobar' in qt_args
예제 #13
0
    def test_preferred_color_scheme(
            self, config_stub, version_patcher, parser, value, qt_version, added):
        version_patcher(qt_version)

        config_stub.val.colors.webpage.preferred_color_scheme = value

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        assert ('--force-dark-mode' in args) == added
예제 #14
0
    def test_overlay_scrollbar(self, config_stub, monkeypatch, parser, bar,
                               is_mac, added):
        monkeypatch.setattr(qtargs.utils, 'is_mac', is_mac)

        config_stub.val.scrolling.bar = bar

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        assert ('--enable-features=OverlayScrollbar' in args) == added
예제 #15
0
    def test_low_end_device_mode(self, config_stub, parser,
                                 low_end_device_mode, arg):
        config_stub.val.qt.low_end_device_mode = low_end_device_mode
        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        if arg is None:
            assert '--enable-low-end-device-mode' not in args
            assert '--disable-low-end-device-mode' not in args
        else:
            assert arg in args
예제 #16
0
    def test_chromium_flags(self, monkeypatch, parser, flags, args):
        parsed = parser.parse_args(flags)
        args = qtargs.qt_args(parsed)

        if args:
            for arg in args:
                assert arg in args
        else:
            assert '--enable-logging' not in args
            assert '--v=1' not in args
            assert '--renderer-startup-dialog' not in args
예제 #17
0
    def test_webrtc(self, config_stub, monkeypatch, parser, policy, arg):
        monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebEngine)
        config_stub.val.content.webrtc_ip_handling_policy = policy

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        if arg is None:
            assert not any(a.startswith('--force-webrtc-ip-handling-policy=')
                           for a in args)
        else:
            assert arg in args
예제 #18
0
    def test_chromium_flags(self, monkeypatch, parser, flags, args):
        monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebEngine)
        parsed = parser.parse_args(flags)
        args = qtargs.qt_args(parsed)

        if args:
            for arg in args:
                assert arg in args
        else:
            assert '--enable-logging' not in args
            assert '--v=1' not in args
            assert '--renderer-startup-dialog' not in args
예제 #19
0
    def test_autoplay(self, config_stub, monkeypatch, parser, new_version,
                      autoplay, added):
        monkeypatch.setattr(qtargs.objects, 'backend',
                            usertypes.Backend.QtWebEngine)
        config_stub.val.content.autoplay = autoplay
        monkeypatch.setattr(qtargs.qtutils,
                            'version_check',
                            lambda version, compiled=False: new_version)

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)
        assert ('--autoplay-policy=user-gesture-required' in args) == added
예제 #20
0
    def test_process_model(self, config_stub, parser, process_model, added):
        config_stub.val.qt.process_model = process_model
        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        if added:
            assert '--' + process_model in args
        else:
            assert '--process-per-site' not in args
            assert '--single-process' not in args
            assert '--process-per-site-instance' not in args
            assert '--process-per-tab' not in args
예제 #21
0
    def test_webrtc(self, config_stub, monkeypatch, parser, policy, arg):
        config_stub.val.content.webrtc_ip_handling_policy = policy

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        if arg is None:
            assert not any(
                a.startswith('--force-webrtc-ip-handling-policy=')
                for a in args)
        else:
            assert arg in args
예제 #22
0
    def test_blink_settings_passthrough(self, parser, config_stub):
        config_stub.val.colors.webpage.darkmode.enabled = True

        flag = qtargs._BLINK_SETTINGS + 'foo=bar'
        parsed = parser.parse_args(['--qt-flag', flag.lstrip('-')])
        args = qtargs.qt_args(parsed)

        blink_settings_args = [
            arg for arg in args if arg.startswith(qtargs._BLINK_SETTINGS)
        ]
        assert len(blink_settings_args) == 1
        assert blink_settings_args[0].startswith('--blink-settings=foo=bar,')
예제 #23
0
    def test_prefers_color_scheme_dark(self, config_stub, monkeypatch, parser,
                                       dark, qt_version, added):
        monkeypatch.setattr(qtargs.objects, 'backend',
                            usertypes.Backend.QtWebEngine)
        monkeypatch.setattr(qtargs.qtutils, 'qVersion', lambda: qt_version)

        config_stub.val.colors.webpage.prefers_color_scheme_dark = dark

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        assert ('--force-dark-mode' in args) == added
예제 #24
0
    def test_installedapp_workaround(self, parser, version_patcher, qt_version, has_workaround):
        version_patcher(qt_version)

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)
        disable_features_args = [
            arg for arg in args
            if arg.startswith(qtargs._DISABLE_FEATURES)
        ]

        expected = ['--disable-features=InstalledApp'] if has_workaround else []
        assert disable_features_args == expected
예제 #25
0
    def test_referer(self, config_stub, monkeypatch, parser, referer, arg):
        monkeypatch.setattr(qtargs.objects, 'backend',
                            usertypes.Backend.QtWebEngine)

        config_stub.val.content.headers.referer = referer
        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        if arg is None:
            assert '--no-referrers' not in args
            assert '--reduced-referrer-granularity' not in args
        else:
            assert arg in args
예제 #26
0
    def test_blink_settings(self, config_stub, monkeypatch, parser):
        monkeypatch.setattr(qtargs.objects, 'backend',
                            usertypes.Backend.QtWebEngine)
        monkeypatch.setattr(qtargs.qtutils,
                            'version_check',
                            lambda version, exact=False, compiled=True: True)

        config_stub.val.colors.webpage.darkmode.enabled = True

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        assert '--blink-settings=darkModeEnabled=true' in args
예제 #27
0
    def test_overlay_scrollbar(self, config_stub, monkeypatch, parser,
                               bar, is_mac, added):
        monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebEngine)
        monkeypatch.setattr(qtargs.utils, 'is_mac', is_mac)
        # Avoid WebRTC pipewire feature
        monkeypatch.setattr(qtargs.utils, 'is_linux', False)

        config_stub.val.scrolling.bar = bar

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        assert ('--enable-features=OverlayScrollbar' in args) == added
예제 #28
0
    def test_dark_mode_settings(self, config_stub, monkeypatch, parser,
                                variant, expected):
        from qutebrowser.browser.webengine import darkmode
        monkeypatch.setattr(darkmode, '_variant',
                            lambda _versions: darkmode.Variant[variant])

        config_stub.val.colors.webpage.darkmode.enabled = True

        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        for arg in expected:
            assert arg in args
예제 #29
0
    def test_low_end_device_mode(self, config_stub, monkeypatch, parser,
                                 low_end_device_mode, arg):
        monkeypatch.setattr(qtargs.objects, 'backend', usertypes.Backend.QtWebEngine)

        config_stub.val.qt.low_end_device_mode = low_end_device_mode
        parsed = parser.parse_args([])
        args = qtargs.qt_args(parsed)

        if arg is None:
            assert '--enable-low-end-device-mode' not in args
            assert '--disable-low-end-device-mode' not in args
        else:
            assert arg in args
예제 #30
0
    def test_disable_features_passthrough(self, config_stub, parser,
                                          via_commandline, passed_features):
        flag = qtargs._DISABLE_FEATURES + ','.join(passed_features)

        config_flag = flag.lstrip('-')
        config_stub.val.qt.args = ([] if via_commandline else [config_flag])
        parsed = parser.parse_args(
            ['--qt-flag', config_flag] if via_commandline else [])
        args = qtargs.qt_args(parsed)

        disable_features_args = [
            arg for arg in args if arg.startswith(qtargs._DISABLE_FEATURES)
        ]
        assert disable_features_args == [flag]