Greasemonkey: Add test for @require support.

There's is a lot of asserts in that one test but it tests everything.
This commit is contained in:
Jimmy 2018-01-02 16:01:01 +13:00
parent fa1ac8d93c
commit 919fe45813

View File

@ -128,3 +128,33 @@ def test_load_emits_signal(qtbot):
gm_manager = greasemonkey.GreasemonkeyManager() gm_manager = greasemonkey.GreasemonkeyManager()
with qtbot.wait_signal(gm_manager.scripts_reloaded): with qtbot.wait_signal(gm_manager.scripts_reloaded):
gm_manager.load_scripts() gm_manager.load_scripts()
def test_required_scripts_are_included(download_stub, tmpdir):
test_require_script = textwrap.dedent("""
// ==UserScript==
// @name qutebrowser test userscript
// @namespace invalid.org
// @include http://localhost:*/data/title.html
// @match http://trolol*
// @exclude https://badhost.xxx/*
// @run-at document-start
// @require http://localhost/test.js
// ==/UserScript==
console.log("Script is running.");
""")
_save_script(test_require_script, 'requiring.user.js')
with open(str(tmpdir / 'test.js'), 'w', encoding='UTF-8') as f:
f.write("REQUIRED SCRIPT")
gm_manager = greasemonkey.GreasemonkeyManager()
assert len(gm_manager._in_progress_dls) == 1
for download in gm_manager._in_progress_dls:
download.finished.emit()
scripts = gm_manager.all_scripts()
assert len(scripts) == 1
assert "REQUIRED SCRIPT" in scripts[0].code()
# Additionally check that the base script is still being parsed correctly
assert "Script is running." in scripts[0].code()
assert scripts[0].excludes