qutescheme: Add tests for redirects

This commit is contained in:
Florian Bruhin 2025-10-02 08:59:23 +02:00
parent 25ff649efe
commit 0867a95abb
1 changed files with 30 additions and 0 deletions

View File

@ -17,6 +17,36 @@ from qutebrowser.utils import resources, urlmatch
from qutebrowser.misc import guiprocess
class TestDataForUrl:
@pytest.mark.parametrize(
"url, expected",
[
# QUrl.UrlFormattingOption.StripTrailingSlash
(QUrl("qute://abc/xyz/"), QUrl("qute://abc/xyz")),
# QUrl.UrlFormattingOption.NormalizePathSegments
(QUrl("qute://abc/uvw/../xyz"), QUrl("qute://abc/xyz")),
# Adding host trailing slash
(QUrl("qute://abc"), QUrl("qute://abc/")),
(QUrl("qute://abc?q=42"), QUrl("qute://abc/?q=42")),
# path -> host
(QUrl("qute:abc"), QUrl("qute://abc/")),
(QUrl("qute:abc?q=42"), QUrl("qute://abc/?q=42")),
],
ids=lambda url: url.toString(),
)
def test_redirects(self, url: QUrl, expected: QUrl) -> None:
with pytest.raises(qutescheme.Redirect) as exc:
qutescheme.data_for_url(url)
assert exc.value.url == expected
def test_invalid_redirect(self) -> None:
url = QUrl("qute:-")
with pytest.raises(
qutescheme.NotFoundError, match="No handler found for qute:-"
):
qutescheme.data_for_url(url)
class TestJavascriptHandler:
"""Test the qute://javascript endpoint."""