Greasemonkey: skip window scoping test on webkit

The implementation of Proxy in JSCore used by current QtWebkit (webkit
602.1) doesn't support the `set()` handler for whatever reason. So
instead of testing for a specific behaviour that we can't ensure on that
version let's just skip the tests and handle user complaints with
sympathy.
This commit is contained in:
Jimmy 2018-04-25 16:26:43 +12:00
parent 19242b6cb2
commit 13249329f7
4 changed files with 20 additions and 18 deletions

View File

@ -30,6 +30,7 @@ markers =
qtbug60673: Tests which are broken if the conversion from orange selection to real selection is flaky qtbug60673: Tests which are broken if the conversion from orange selection to real selection is flaky
fake_os: Fake utils.is_* to a fake operating system fake_os: Fake utils.is_* to a fake operating system
unicode_locale: Tests which need an unicode locale to work unicode_locale: Tests which need an unicode locale to work
qtwebkit6021_skip: Tests which would fail on WebKit version 602.1
qt_log_level_fail = WARNING qt_log_level_fail = WARNING
qt_log_ignore = qt_log_ignore =
^SpellCheck: .* ^SpellCheck: .*

View File

@ -145,22 +145,16 @@
} }
}; };
/* TamperMonkey allows assinging to `window` to change the visible global /*
* scope, without breaking other scripts. Eg if the page has set * Try to give userscripts an environment that they expect. Which
* window.$ for an object for some reason (hello 4chan) * seems to be that the global window object should look the same as
* - typeof $ === 'object' * the page's one and that if a script writes to an attribute of
* - typeof window.$ == 'undefined' * window it should be able to access that variable in the global
* - window.$ = function() {} * scope.
* - typeof $ === 'function' * Use a Proxy to stop scripts from actually changing the global
* - typeof window.$ == 'function' * window (that's what unsafeWindow is for).
* Just shadowing `window` won't work because if you try to use '$' * Use the "with" statement to make the proxy provide what looks
* from the global scope you will still get the pages one. * like global scope.
* Additionally the userscript expects `window` to actually look
* like a fully featured browser window object.
*
* So let's try to use a Proxy on window and the possibly deprecated
* `with` function to make that proxy shadow the global scope.
* unsafeWindow should still be the actual global page window.
* *
* There are other Proxy functions that we may need to override. * There are other Proxy functions that we may need to override.
* set, get and has are definitely required. * set, get and has are definitely required.
@ -187,7 +181,8 @@
return key in qute_gm_window_shadow || key in target; return key in qute_gm_window_shadow || key in target;
} }
}; };
const qute_gm_window_proxy = new Proxy(unsafeWindow, qute_gm_windowProxyHandler); const qute_gm_window_proxy = new Proxy(
unsafeWindow, qute_gm_windowProxyHandler);
with (qute_gm_window_proxy) { with (qute_gm_window_proxy) {
// We can't return `this` or `qute_gm_window_proxy` from // We can't return `this` or `qute_gm_window_proxy` from

View File

@ -36,7 +36,7 @@ from helpers import logfail
from helpers.logfail import fail_on_logging from helpers.logfail import fail_on_logging
from helpers.messagemock import message_mock from helpers.messagemock import message_mock
from helpers.fixtures import * # noqa: F403 from helpers.fixtures import * # noqa: F403
from qutebrowser.utils import qtutils, standarddir, usertypes, utils from qutebrowser.utils import qtutils, standarddir, usertypes, utils, version
from qutebrowser.misc import objects from qutebrowser.misc import objects
import qutebrowser.app # To register commands import qutebrowser.app # To register commands
@ -77,6 +77,10 @@ def _apply_platform_markers(config, item):
"https://bugreports.qt.io/browse/QTBUG-60673"), "https://bugreports.qt.io/browse/QTBUG-60673"),
('unicode_locale', sys.getfilesystemencoding() == 'ascii', ('unicode_locale', sys.getfilesystemencoding() == 'ascii',
"Skipped because of ASCII locale"), "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: for searched_marker, condition, default_reason in markers:

View File

@ -212,6 +212,8 @@ class TestWindowIsolation:
page.runJavaScript(self.test_script, callback_checker.callback) page.runJavaScript(self.test_script, callback_checker.callback)
callback_checker.check(self.expected) callback_checker.check(self.expected)
# The JSCore in 602.1 doesn't fully support Proxy.
@pytest.mark.qtwebkit6021_skip
def test_webkit(self, webview): def test_webkit(self, webview):
elem = webview.page().mainFrame().documentElement() elem = webview.page().mainFrame().documentElement()
elem.evaluateJavaScript(self.setup_script) elem.evaluateJavaScript(self.setup_script)