Greasemonkey: add minimal end-to-end test.
Just runs a greasemonkey script on a test page and uses console.log to ensure it is running. Tests @include, and basic happy path greasemonkey.py operation (loading and parsing script, scrip_for on webkit), only testing document-start injecting point but that is the troublsome one at this point. Tested on py35 debian unstable (oldwebkit and qtwebengine5.9) debian stable qtwebengine5.7. Note the extra :reload call for qt5.7 because document-start scripts don't seem to run on the first page load with the current insertion point. I need to look into this more to look at ways of fixing this.
This commit is contained in:
parent
7c497427ce
commit
4c3461038d
@ -123,3 +123,12 @@ Feature: Javascript stuff
|
||||
And I wait for "[*/data/javascript/windowsize.html:*] loaded" in the log
|
||||
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
|
||||
And I run :greasemonkey-reload
|
||||
And I open data/title.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
|
||||
|
@ -17,6 +17,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest_bdd as bdd
|
||||
bdd.scenarios('javascript.feature')
|
||||
|
||||
@ -29,3 +31,23 @@ def check_window_sizes(quteproc):
|
||||
hidden_size = hidden.message.split()[-1]
|
||||
visible_size = visible.message.split()[-1]
|
||||
assert hidden_size == visible_size
|
||||
|
||||
test_gm_script="""
|
||||
// ==UserScript==
|
||||
// @name Qutebrowser test userscript
|
||||
// @namespace invalid.org
|
||||
// @include http://localhost:*/data/title.html
|
||||
// @exclude ???
|
||||
// @run-at document-start
|
||||
// ==/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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user