Exemplo n.º 1
0
def pytest_report_header(config):
    if config.webengine:
        backend_version = version.qtwebengine_versions(avoid_init=True)
    else:
        backend_version = version.qWebKitVersion()

    return f'backend: {backend_version}'
Exemplo n.º 2
0
def test_window_isolation(js_tester, request):
    """Check that greasemonkey scripts get a shadowed global scope."""
    # Change something in the global scope
    setup_script = "window.$ = 'global'"

    # Greasemonkey script to report back on its scope.
    test_gm_script = greasemonkey.GreasemonkeyScript.parse(
        textwrap.dedent("""
            // ==UserScript==
            // @name scopetest
            // ==/UserScript==
            // Check the thing the page set is set to the expected type
            result.push(window.$);
            result.push($);
            // Now overwrite it
            window.$ = 'shadowed';
            // And check everything is how the script would expect it to be
            // after just writing to the "global" scope
            result.push(window.$);
            result.push($);
        """)
    )

    # The compiled source of that scripts with some additional setup
    # bookending it.
    test_script = "\n".join([
        """
        const result = [];
        """,
        test_gm_script.code(),
        """
        // Now check that the actual global scope has
        // not been overwritten
        result.push(window.$);
        result.push($);
        // And return our findings
        result;
        """
    ])

    # What we expect the script to report back.
    expected = ["global", "global", "shadowed", "shadowed", "global", "global"]

    # The JSCore in 602.1 doesn't fully support Proxy.
    xfail = False
    if (js_tester.tab.backend == usertypes.Backend.QtWebKit and
            version.qWebKitVersion() == '602.1'):
        expected[-1] = 'shadowed'
        expected[-2] = 'shadowed'
        xfail = True

    js_tester.run(setup_script)
    js_tester.run(test_script, expected=expected)

    if xfail:
        pytest.xfail("Broken on WebKit 602.1")
Exemplo n.º 3
0
def _apply_platform_markers(config, item):
    """Apply a skip marker to a given item."""
    markers = [
        ('posix', pytest.mark.skipif, not utils.is_posix,
         "Requires a POSIX os"),
        ('windows', pytest.mark.skipif, not utils.is_windows,
         "Requires Windows"),
        ('linux', pytest.mark.skipif, not utils.is_linux, "Requires Linux"),
        ('mac', pytest.mark.skipif, not utils.is_mac, "Requires macOS"),
        ('not_mac', pytest.mark.skipif, utils.is_mac, "Skipped on macOS"),
        ('not_frozen', pytest.mark.skipif, getattr(sys, 'frozen', False),
         "Can't be run when frozen"),
        ('frozen', pytest.mark.skipif, not getattr(sys, 'frozen', False),
         "Can only run when frozen"),
        ('ci', pytest.mark.skipif, not testutils.ON_CI, "Only runs on CI."),
        ('no_ci', pytest.mark.skipif, testutils.ON_CI, "Skipped on CI."),
        ('unicode_locale', pytest.mark.skipif,
         sys.getfilesystemencoding() == 'ascii',
         "Skipped because of ASCII locale"),
        ('qtbug60673', pytest.mark.xfail, qtutils.version_check('5.8')
         and not qtutils.version_check('5.10')
         and config.webengine, "Broken on webengine due to "
         "https://bugreports.qt.io/browse/QTBUG-60673"),
        ('qtbug80085', pytest.mark.xfail,
         qtutils.version_check('5.14', compiled=False)
         and config.webengine, "Broken on webengine due to "
         "https://bugreports.qt.io/browse/QTBUG-80085"),
        (
            'qtwebkit6021_xfail',
            pytest.mark.xfail,
            version.qWebKitVersion and  # type: ignore
            version.qWebKitVersion() == '602.1',
            "Broken on WebKit 602.1")
    ]

    for searched_marker, new_marker_kind, condition, default_reason in markers:
        marker = item.get_closest_marker(searched_marker)
        if not marker or not condition:
            continue

        if 'reason' in marker.kwargs:
            reason = '{}: {}'.format(default_reason, marker.kwargs['reason'])
            del marker.kwargs['reason']
        else:
            reason = default_reason + '.'
        new_marker = new_marker_kind(condition,
                                     *marker.args,
                                     reason=reason,
                                     **marker.kwargs)
        item.add_marker(new_marker)
Exemplo n.º 4
0
def _apply_platform_markers(config, item):
    """Apply a skip marker to a given item."""
    markers = [
        ('posix', not utils.is_posix, "Requires a POSIX os"),
        ('windows', not utils.is_windows, "Requires Windows"),
        ('linux', not utils.is_linux, "Requires Linux"),
        ('mac', not utils.is_mac, "Requires macOS"),
        ('not_mac', utils.is_mac, "Skipped on macOS"),
        ('not_frozen', getattr(sys, 'frozen',
                               False), "Can't be run when frozen"),
        ('frozen', not getattr(sys, 'frozen', False),
         "Can only run when frozen"),
        ('ci', not ON_CI, "Only runs on CI."),
        ('no_ci', ON_CI, "Skipped on CI."),
        ('issue2478', utils.is_windows
         and config.webengine, "Broken with QtWebEngine on Windows"),
        ('issue3572',
         (qtutils.version_check('5.10', compiled=False, exact=True)
          or qtutils.version_check('5.10.1', compiled=False, exact=True))
         and config.webengine and 'TRAVIS' in os.environ,
         "Broken with QtWebEngine with Qt 5.10 on Travis"),
        ('qtbug60673', qtutils.version_check('5.8')
         and not qtutils.version_check('5.10')
         and config.webengine, "Broken on webengine due to "
         "https://bugreports.qt.io/browse/QTBUG-60673"),
        ('unicode_locale', sys.getfilesystemencoding() == 'ascii',
         "Skipped because of ASCII locale"),
        (
            'qtwebkit6021_skip',
            version.qWebKitVersion and  # type: ignore
            version.qWebKitVersion() == '602.1',
            "Broken on WebKit 602.1")
    ]

    for searched_marker, condition, default_reason in markers:
        marker = item.get_closest_marker(searched_marker)
        if not marker or not condition:
            continue

        if 'reason' in marker.kwargs:
            reason = '{}: {}'.format(default_reason, marker.kwargs['reason'])
            del marker.kwargs['reason']
        else:
            reason = default_reason + '.'
        skipif_marker = pytest.mark.skipif(condition,
                                           *marker.args,
                                           reason=reason,
                                           **marker.kwargs)
        item.add_marker(skipif_marker)
Exemplo n.º 5
0
def _apply_platform_markers(config, item):
    """Apply a skip marker to a given item."""
    markers = [
        ('posix', not utils.is_posix, "Requires a POSIX os"),
        ('windows', not utils.is_windows, "Requires Windows"),
        ('linux', not utils.is_linux, "Requires Linux"),
        ('mac', not utils.is_mac, "Requires macOS"),
        ('not_mac', utils.is_mac, "Skipped on macOS"),
        ('not_frozen', getattr(sys, 'frozen', False),
         "Can't be run when frozen"),
        ('frozen', not getattr(sys, 'frozen', False),
         "Can only run when frozen"),
        ('ci', not ON_CI, "Only runs on CI."),
        ('no_ci', ON_CI, "Skipped on CI."),
        ('issue2478', utils.is_windows and config.webengine,
         "Broken with QtWebEngine on Windows"),
        ('issue3572',
         (qtutils.version_check('5.10', compiled=False, exact=True) or
          qtutils.version_check('5.10.1', compiled=False, exact=True)) and
         config.webengine and 'TRAVIS' in os.environ,
         "Broken with QtWebEngine with Qt 5.10 on Travis"),
        ('qtbug60673',
         qtutils.version_check('5.8') and
         not qtutils.version_check('5.10') and
         config.webengine,
         "Broken on webengine due to "
         "https://bugreports.qt.io/browse/QTBUG-60673"),
        ('unicode_locale', sys.getfilesystemencoding() == 'ascii',
         "Skipped because of ASCII locale"),
        ('qtwebkit6021_skip',
         version.qWebKitVersion and
         version.qWebKitVersion() == '602.1',
         "Broken on WebKit 602.1")
    ]

    for searched_marker, condition, default_reason in markers:
        marker = item.get_closest_marker(searched_marker)
        if not marker or not condition:
            continue

        if 'reason' in marker.kwargs:
            reason = '{}: {}'.format(default_reason, marker.kwargs['reason'])
            del marker.kwargs['reason']
        else:
            reason = default_reason + '.'
        skipif_marker = pytest.mark.skipif(condition, *marker.args,
                                           reason=reason, **marker.kwargs)
        item.add_marker(skipif_marker)
Exemplo n.º 6
0
    def code(self):
        """Return the processed JavaScript code of this script.

        Adorns the source code with GM_* methods for Greasemonkey
        compatibility and wraps it in an IIFE to hide it within a
        lexical scope. Note that this means line numbers in your
        browser's debugger/inspector will not match up to the line
        numbers in the source script directly.
        """
        # Don't use Proxy on this webkit version, the support isn't there.
        use_proxy = not (objects.backend == usertypes.Backend.QtWebKit
                         and version.qWebKitVersion() == '602.1')
        template = jinja.js_environment.get_template('greasemonkey_wrapper.js')
        return template.render(scriptName=javascript.string_escape("/".join(
            [self.namespace or '', self.name])),
                               scriptInfo=self._meta_json(),
                               scriptMeta=javascript.string_escape(
                                   self.script_meta or ''),
                               scriptSource=self._code,
                               use_proxy=use_proxy)
Exemplo n.º 7
0
    def code(self):
        """Return the processed JavaScript code of this script.

        Adorns the source code with GM_* methods for Greasemonkey
        compatibility and wraps it in an IIFE to hide it within a
        lexical scope. Note that this means line numbers in your
        browser's debugger/inspector will not match up to the line
        numbers in the source script directly.
        """
        # Don't use Proxy on this webkit version, the support isn't there.
        use_proxy = not (
            objects.backend == usertypes.Backend.QtWebKit and
            version.qWebKitVersion() == '602.1')
        template = jinja.js_environment.get_template('greasemonkey_wrapper.js')
        return template.render(
            scriptName=javascript.string_escape(
                "/".join([self.namespace or '', self.name])),
            scriptInfo=self._meta_json(),
            scriptMeta=javascript.string_escape(self.script_meta or ''),
            scriptSource=self._code,
            use_proxy=use_proxy)