summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-09-05 22:31:21 +1200
committerFlorian Bruhin <me@the-compiler.org>2023-09-06 15:39:40 +0200
commitb5f68e0eeac376e0354b2e7f0ed4ed4fe42f4e45 (patch)
tree48d46117c9aca4cd8686536bb59270078eb70fce
parent2d19fad1cce158b2a7f986e965dd9848a7064574 (diff)
downloadqutebrowser-b5f68e0eeac376e0354b2e7f0ed4ed4fe42f4e45.tar.gz
qutebrowser-b5f68e0eeac376e0354b2e7f0ed4ed4fe42f4e45.zip
Merge pull request #7847 from pylbrecht/broken-hints
Allow navigating from file:// to remote origins via hints. Previously you would have seen a "Your internet access is blocked" chrome error page.
-rw-r--r--qutebrowser/browser/webengine/webengineelem.py16
-rw-r--r--tests/end2end/data/hints/link_inject.html19
-rw-r--r--tests/end2end/features/conftest.py8
-rw-r--r--tests/end2end/features/hints.feature7
-rw-r--r--tests/end2end/fixtures/quteprocess.py2
-rw-r--r--tests/helpers/testutils.py22
6 files changed, 60 insertions, 14 deletions
diff --git a/qutebrowser/browser/webengine/webengineelem.py b/qutebrowser/browser/webengine/webengineelem.py
index 20c3a36d4..c387ebbcf 100644
--- a/qutebrowser/browser/webengine/webengineelem.py
+++ b/qutebrowser/browser/webengine/webengineelem.py
@@ -215,14 +215,16 @@ class WebEngineElement(webelem.AbstractWebElement):
return False
# Qt 6.3+ needs a user interaction to allow navigations from qute:// to
- # outside qute:// (like e.g. on qute://bookmarks).
+ # outside qute:// (like e.g. on qute://bookmarks), as well as from file:// to
+ # outside of file:// (e.g. users having a local bookmarks.html).
versions = version.qtwebengine_versions()
- if (
- baseurl.scheme() == "qute" and
- url.scheme() != "qute" and
- versions.webengine >= utils.VersionNumber(6, 3)
- ):
- return True
+ for scheme in ["qute", "file"]:
+ if (
+ baseurl.scheme() == scheme and
+ url.scheme() != scheme and
+ versions.webengine >= utils.VersionNumber(6, 3)
+ ):
+ return True
return url.scheme() not in urlutils.WEBENGINE_SCHEMES
diff --git a/tests/end2end/data/hints/link_inject.html b/tests/end2end/data/hints/link_inject.html
new file mode 100644
index 000000000..7ef352028
--- /dev/null
+++ b/tests/end2end/data/hints/link_inject.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>A link to use hints on</title>
+ <script>
+ function injectPort() {
+ const queryString = document.location.search;
+ const params = new URLSearchParams(queryString);
+ const port = params.get("port")
+ let link = document.getElementById("link");
+ link.href = link.href.replace("<port>", port);
+ }
+ </script>
+ </head>
+ <body onload="injectPort()">
+ <a href="http://localhost:<port>/data/hello.txt" id="link">Follow me!</a>
+ </body>
+</html>
diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py
index 9dd497c0b..089f0c42c 100644
--- a/tests/end2end/features/conftest.py
+++ b/tests/end2end/features/conftest.py
@@ -33,8 +33,7 @@ def _get_echo_exe_path():
Path to the "echo"-utility.
"""
if utils.is_windows:
- return os.path.join(testutils.abs_datapath(), 'userscripts',
- 'echo.bat')
+ return str(testutils.abs_datapath() / 'userscripts' / 'echo.bat')
else:
return shutil.which("echo")
@@ -199,6 +198,7 @@ def open_path(quteproc, server, path):
- With "... as a URL", it's opened according to new_instance_open_target.
"""
path = path.replace('(port)', str(server.port))
+ path = testutils.substitute_testdata(path)
new_tab = False
new_bg_tab = False
@@ -270,7 +270,7 @@ def run_command(quteproc, server, tmpdir, command):
invalid = False
command = command.replace('(port)', str(server.port))
- command = command.replace('(testdata)', testutils.abs_datapath())
+ command = testutils.substitute_testdata(command)
command = command.replace('(tmpdir)', str(tmpdir))
command = command.replace('(dirsep)', os.sep)
command = command.replace('(echo-exe)', _get_echo_exe_path())
@@ -364,7 +364,7 @@ def hint(quteproc, args):
@bdd.when(bdd.parsers.parse('I hint with args "{args}" and follow {letter}'))
def hint_and_follow(quteproc, args, letter):
- args = args.replace('(testdata)', testutils.abs_datapath())
+ args = testutils.substitute_testdata(args)
args = args.replace('(python-executable)', sys.executable)
quteproc.send_cmd(':hint {}'.format(args))
quteproc.wait_for(message='hints: *')
diff --git a/tests/end2end/features/hints.feature b/tests/end2end/features/hints.feature
index 80348c908..ddf42132f 100644
--- a/tests/end2end/features/hints.feature
+++ b/tests/end2end/features/hints.feature
@@ -44,6 +44,13 @@ Feature: Using hints
- data/hints/link_blank.html
- data/hello.txt
+ # https://github.com/qutebrowser/qutebrowser/issues/7842
+ @qtwebkit_skip
+ Scenario: Following a hint from a local file to a remote origin
+ When I open file://(testdata)/hints/link_inject.html?port=(port)
+ And I hint with args "links" and follow a
+ Then data/hello.txt should be loaded
+
Scenario: Following a hint to link with sub-element and force to open in current tab.
When I open data/hints/link_span.html
And I hint with args "links current" and follow a
diff --git a/tests/end2end/fixtures/quteprocess.py b/tests/end2end/fixtures/quteprocess.py
index a3929ed7e..cf00c38da 100644
--- a/tests/end2end/fixtures/quteprocess.py
+++ b/tests/end2end/fixtures/quteprocess.py
@@ -393,7 +393,7 @@ class QuteProc(testprocess.Process):
verbatim.
"""
special_schemes = ['about:', 'qute:', 'chrome:', 'view-source:',
- 'data:', 'http:', 'https:']
+ 'data:', 'http:', 'https:', 'file:']
server = self.request.getfixturevalue('server')
server_port = server.port if port is None else port
diff --git a/tests/helpers/testutils.py b/tests/helpers/testutils.py
index dc6fdac32..d74c46fcb 100644
--- a/tests/helpers/testutils.py
+++ b/tests/helpers/testutils.py
@@ -192,8 +192,26 @@ def pattern_match(*, pattern, value):
def abs_datapath():
"""Get the absolute path to the end2end data directory."""
- file_abs = os.path.abspath(os.path.dirname(__file__))
- return os.path.join(file_abs, '..', 'end2end', 'data')
+ path = pathlib.Path(__file__).parent / '..' / 'end2end' / 'data'
+ return path.resolve()
+
+
+def substitute_testdata(path):
+ r"""Replace the (testdata) placeholder in path with `abs_datapath()`.
+
+ If path is starting with file://, return path as an URI with file:// removed. This
+ is useful if path is going to be inserted into an URI:
+
+ >>> path = substitute_testdata("C:\Users\qute")
+ >>> f"file://{path}/slug # results in valid URI
+ 'file:///C:/Users/qute/slug'
+ """
+ if path.startswith('file://'):
+ testdata_path = abs_datapath().as_uri().replace('file://', '')
+ else:
+ testdata_path = str(abs_datapath())
+
+ return path.replace('(testdata)', testdata_path)
@contextlib.contextmanager