summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-01-16 11:06:56 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-01-16 11:25:52 +0100
commitfbe29a2a25c96c213bc81f9836ec75e2aa3e0bd9 (patch)
tree352069952e4aed6e2f772c3200359b0713603a33
parent4aa0194b722bd25a52189997230817209b9e0e0b (diff)
downloadqutebrowser-fbe29a2a25c96c213bc81f9836ec75e2aa3e0bd9.tar.gz
qutebrowser-fbe29a2a25c96c213bc81f9836ec75e2aa3e0bd9.zip
tests: Improve tests for data: URL workaround
-rw-r--r--tests/end2end/features/downloads.feature10
-rw-r--r--tests/unit/browser/webengine/test_webenginedownloads.py117
2 files changed, 78 insertions, 49 deletions
diff --git a/tests/end2end/features/downloads.feature b/tests/end2end/features/downloads.feature
index 57d6dfb7f..f20377db5 100644
--- a/tests/end2end/features/downloads.feature
+++ b/tests/end2end/features/downloads.feature
@@ -92,16 +92,6 @@ Feature: Downloading things from a website.
And I run :leave-mode
Then no crash should happen
- @qtwebkit_skip
- Scenario: Downloading a data: link via QtWebEngine (issue 1214)
- When I set downloads.location.suggestion to filename
- And I set downloads.location.prompt to true
- And I open data/data_link.html
- And I hint with args "links" and follow s
- And I wait for "Asking question <qutebrowser.utils.usertypes.Question default='download.pdf' mode=<PromptMode.download: 5> option=None text=* title='Save file to:'>, *" in the log
- And I run :leave-mode
- Then no crash should happen
-
Scenario: Aborting a download in a different window (issue 3378)
When I set downloads.location.suggestion to filename
And I set downloads.location.prompt to true
diff --git a/tests/unit/browser/webengine/test_webenginedownloads.py b/tests/unit/browser/webengine/test_webenginedownloads.py
index 98918571b..b1b18003c 100644
--- a/tests/unit/browser/webengine/test_webenginedownloads.py
+++ b/tests/unit/browser/webengine/test_webenginedownloads.py
@@ -42,45 +42,84 @@ def test_get_suggested_filename(path, expected):
assert webenginedownloads._get_suggested_filename(path) == expected
-@pytest.mark.parametrize('with_slash', [True, False])
-def test_data_url_workaround_needed(qapp, qtbot, webengineview, with_slash):
+class TestDataUrlWorkaround:
+
"""With data URLs, we get rather weird base64 filenames back from QtWebEngine.
- This test verifies that our workaround for this is still needed, i.e. if we get
- those base64-filenames rather than a "download.pdf" like with Chromium.
+ See https://bugreports.qt.io/browse/QTBUG-90355
"""
- # https://stackoverflow.com/a/17280876/2085149
- pdf_source = [
- '%PDF-1.0',
- '1 0 obj<</Pages 2 0 R>>endobj',
- '2 0 obj<</Kids[3 0 R]/Count 1>>endobj',
- '3 0 obj<</MediaBox[0 0 3 3]>>endobj',
- 'trailer<</Root 1 0 R>>',
- ]
-
- if with_slash:
- pdf_source.insert(1, '% ?') # this results in a slash in base64
-
- pdf_data = '\n'.join(pdf_source).encode('ascii')
- base64_data = base64.b64encode(pdf_data).decode('ascii')
-
- if with_slash:
- assert '/' in base64_data
- expected = base64_data.split('/')[1]
- else:
- assert '/' not in base64_data
- expected = 'pdf' # from the mimetype
-
- def check_item(item):
- assert item.mimeType() == 'application/pdf'
- assert item.url().scheme() == 'data'
- assert os.path.basename(item.path()) == expected
- return True
-
- profile = QWebEngineProfile.defaultProfile()
- profile.setParent(qapp)
-
- url = urlutils.data_url('application/pdf', pdf_data)
-
- with qtbot.waitSignal(profile.downloadRequested, check_params_cb=check_item):
- webengineview.load(url)
+
+ @pytest.fixture(params=[True, False])
+ def pdf_bytes(self, request):
+ with_slash = request.param
+
+ # https://stackoverflow.com/a/17280876/2085149
+ pdf_source = [
+ '%PDF-1.0',
+ '1 0 obj<</Pages 2 0 R>>endobj',
+ '2 0 obj<</Kids[3 0 R]/Count 1>>endobj',
+ '3 0 obj<</MediaBox[0 0 3 3]>>endobj',
+ 'trailer<</Root 1 0 R>>',
+ ]
+
+ if with_slash:
+ pdf_source.insert(1, '% ?') # this results in a slash in base64
+
+ return '\n'.join(pdf_source).encode('ascii')
+
+ @pytest.fixture
+ def pdf_url(self, pdf_bytes):
+ return urlutils.data_url('application/pdf', pdf_bytes)
+
+ @pytest.fixture
+ def webengine_profile(self, qapp):
+ profile = QWebEngineProfile.defaultProfile()
+ profile.setParent(qapp)
+ return profile
+
+ @pytest.fixture
+ def download_manager(self, qapp, qtbot, webengine_profile, download_tmpdir,
+ config_stub):
+ config_stub.val.downloads.location.suggestion = 'filename'
+ manager = webenginedownloads.DownloadManager(parent=qapp)
+ manager.install(webengine_profile)
+ yield manager
+ webengine_profile.downloadRequested.disconnect()
+
+ def test_workaround(self, webengine_tab, message_mock, qtbot,
+ pdf_url, download_manager):
+ """Verify our workaround works properly."""
+ with qtbot.waitSignal(message_mock.got_question):
+ webengine_tab.load_url(pdf_url)
+
+ question = message_mock.get_question()
+ assert question.default == 'download.pdf'
+
+ @pytest.fixture
+ def expected_wrong_filename(self, pdf_bytes):
+ with_slash = b'% ?' in pdf_bytes
+ base64_data = base64.b64encode(pdf_bytes).decode('ascii')
+
+ if with_slash:
+ assert '/' in base64_data
+ return base64_data.split('/')[1]
+ else:
+ assert '/' not in base64_data
+ return 'pdf' # from the mimetype
+
+ def test_workaround_needed(self, qtbot, webengineview,
+ pdf_url, expected_wrong_filename, webengine_profile):
+ """Verify that our workaround for this is still needed.
+
+ In other words, check whether we get those base64-filenames rather than a
+ "download.pdf" like with Chromium.
+ """
+ def check_item(item):
+ assert item.mimeType() == 'application/pdf'
+ assert item.url().scheme() == 'data'
+ assert os.path.basename(item.path()) == expected_wrong_filename
+ return True
+
+ with qtbot.waitSignal(webengine_profile.downloadRequested,
+ check_params_cb=check_item):
+ webengineview.load(pdf_url)