Greasemonkey: add more end2end tests

Test document-end and noframes. Because coverage.py told me to.
Hopefully this doesn't slow the test run down too much, particularly the
"should not be logged" bit.

I'm just reusing and existing test html page that used an iframe because
I'm lazy.
This commit is contained in:
Jimmy 2017-11-01 23:41:52 +13:00
parent 361a1ed6e4
commit dd59f8d724
2 changed files with 41 additions and 14 deletions

View File

@ -124,11 +124,23 @@ Feature: Javascript stuff
And I run :tab-next
Then the window sizes should be the same
Scenario: Have a greasemonkey script run on a page
When I have a greasemonkey file saved
Scenario: Have a greasemonkey script run at page start
When I have a greasemonkey file saved for document-start with noframes unset
And I run :greasemonkey-reload
And I open data/title.html
And I open data/hints/iframe.html
# This second reload is required in webengine < 5.8 for scripts
# registered to run at document-start, some sort of timing issue.
And I run :reload
Then the javascript message "Script is running." should be logged
Then the javascript message "Script is running on /data/hints/iframe.html" should be logged
Scenario: Have a greasemonkey script running on frames
When I have a greasemonkey file saved for document-end with noframes unset
And I run :greasemonkey-reload
And I open data/hints/iframe.html
Then the javascript message "Script is running on /data/hints/html/wrapped.html" should be logged
Scenario: Have a greasemonkey script running on noframes
When I have a greasemonkey file saved for document-end with noframes set
And I run :greasemonkey-reload
And I open data/hints/iframe.html
Then the javascript message "Script is running on /data/hints/html/wrapped.html" should not be logged

View File

@ -32,22 +32,37 @@ def check_window_sizes(quteproc):
visible_size = visible.message.split()[-1]
assert hidden_size == visible_size
test_gm_script="""
test_gm_script = r"""
// ==UserScript==
// @name Qutebrowser test userscript
// @namespace invalid.org
// @include http://localhost:*/data/title.html
// @include http://localhost:*/data/hints/iframe.html
// @include http://localhost:*/data/hints/html/wrapped.html
// @exclude ???
// @run-at document-start
// @run-at {stage}
// {frames}
// ==/UserScript==
console.log("Script is running on " + window.location.pathname);
"""
@bdd.when("I have a greasemonkey file saved")
def create_greasemonkey_file(quteproc):
script_path = os.path.join(quteproc.basedir, 'data', 'greasemonkey')
os.mkdir(script_path)
file_path = os.path.join(script_path, 'test.user.js')
with open(file_path, 'w', encoding='utf-8') as f:
f.write(test_gm_script)
@bdd.when(bdd.parsers.parse("I have a greasemonkey file saved for {stage} "
"with noframes {frameset}"))
def create_greasemonkey_file(quteproc, stage, frameset):
script_path = os.path.join(quteproc.basedir, 'data', 'greasemonkey')
try:
os.mkdir(script_path)
except FileExistsError:
pass
file_path = os.path.join(script_path, 'test.user.js')
if frameset == "set":
frames = "@noframes"
elif frameset == "unset":
frames = ""
else:
raise ValueError("noframes can only be set or unset, "
"not {}".format(frameset))
with open(file_path, 'w', encoding='utf-8') as f:
f.write(test_gm_script.format(stage=stage,
frames=frames))