diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-06-11 19:14:14 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-06-11 19:14:14 +0200 |
commit | b0d3c8eee3ee78c011feeac36cf7c8ee9785b63b (patch) | |
tree | a92b03c89138f37b73582152348ee4503343a1e7 /tests | |
parent | c6cdd3f8440b22a294911ebed0492beea8913c49 (diff) | |
download | qutebrowser-b0d3c8eee3ee78c011feeac36cf7c8ee9785b63b.tar.gz qutebrowser-b0d3c8eee3ee78c011feeac36cf7c8ee9785b63b.zip |
Greasemonkey: Make sure script names are unique
Fixes #6353
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/browser/webengine/test_webenginetab.py | 39 | ||||
-rw-r--r-- | tests/unit/javascript/test_greasemonkey.py | 14 |
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/browser/webengine/test_webenginetab.py b/tests/unit/browser/webengine/test_webenginetab.py index 274e216ba..3d8eec663 100644 --- a/tests/unit/browser/webengine/test_webenginetab.py +++ b/tests/unit/browser/webengine/test_webenginetab.py @@ -164,6 +164,45 @@ class TestWebengineScripts: assert scripts_helper.get_script().injectionPoint() == expected + @pytest.mark.parametrize('header1, header2, expected_names', [ + ( + ["// @namespace ns1", "// @name same"], + ["// @namespace ns2", "// @name same"], + ['GM-ns1/same', 'GM-ns2/same'], + ), + ( + ["// @name same"], + ["// @name same"], + ['GM-same', 'GM-same-2'], + ), + ( + ["// @name same"], + ["// @name sam"], + ['GM-same', 'GM-sam'], + ), + ]) + def test_greasemonkey_duplicate_name(self, scripts_helper, + header1, header2, expected_names): + template = """ + // ==UserScript== + {header} + // ==/UserScript== + """ + template = textwrap.dedent(template.lstrip('\n')) + + source1 = template.format(header="\n".join(header1)) + script1 = greasemonkey.GreasemonkeyScript.parse(source1) + source2 = template.format(header="\n".join(header2)) + script2 = greasemonkey.GreasemonkeyScript.parse(source2) + scripts_helper.inject([script1, script2]) + + names = [script.name() for script in scripts_helper.get_scripts()] + assert names == expected_names + + source3 = textwrap.dedent(template.lstrip('\n')).format(header="// @name other") + script3 = greasemonkey.GreasemonkeyScript.parse(source3) + scripts_helper.inject([script3]) + def test_notification_permission_workaround(): """Make sure the value for QWebEnginePage::Notifications is correct.""" diff --git a/tests/unit/javascript/test_greasemonkey.py b/tests/unit/javascript/test_greasemonkey.py index 2bfb9ca83..17847816d 100644 --- a/tests/unit/javascript/test_greasemonkey.py +++ b/tests/unit/javascript/test_greasemonkey.py @@ -131,6 +131,20 @@ def test_no_name_with_fallback(): assert script.name == r"C:\COM1" +@pytest.mark.parametrize('properties, inc_counter, expected', [ + ([("name", "gorilla")], False, "GM-gorilla"), + ([("namespace", "apes"), ("name", "gorilla")], False, "GM-apes/gorilla"), + + ([("name", "gorilla")], True, "GM-gorilla-2"), + ([("namespace", "apes"), ("name", "gorilla")], True, "GM-apes/gorilla-2"), +]) +def test_full_name(properties, inc_counter, expected): + script = greasemonkey.GreasemonkeyScript(properties, code="") + if inc_counter: + script.dedup_suffix += 1 + assert script.full_name() == expected + + def test_bad_scheme(caplog): """qute:// isn't in the list of allowed schemes.""" _save_script("var nothing = true;\n", 'nothing.user.js') |