From 9b04c4b8e0dd1bd36a97fd8e64ef88d6f185e215 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 9 Sep 2018 19:22:39 +0200 Subject: [PATCH] Add missing tests for qute://pdfjs --- tests/unit/browser/test_qutescheme.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/unit/browser/test_qutescheme.py b/tests/unit/browser/test_qutescheme.py index 761769e16..db8f9b29b 100644 --- a/tests/unit/browser/test_qutescheme.py +++ b/tests/unit/browser/test_qutescheme.py @@ -23,7 +23,7 @@ import time import logging import py.path # pylint: disable=no-name-in-module -from PyQt5.QtCore import QUrl +from PyQt5.QtCore import QUrl, QUrlQuery import pytest from qutebrowser.browser import qutescheme, pdfjs, downloads @@ -213,9 +213,26 @@ class TestPDFJSHandler: QUrl('qute://pdfjs/web/viewer.html?filename=foobar')) assert b'PDF.js' in data + def test_viewer_no_filename(self): + with pytest.raises(qutescheme.UrlInvalidError): + qutescheme.data_for_url(QUrl('qute://pdfjs/web/viewer.html')) + def test_file(self, download_tmpdir): """Load a file via qute://pdfjs/file.""" (download_tmpdir / 'testfile').write_binary(b'foo') _mimetype, data = qutescheme.data_for_url( QUrl('qute://pdfjs/file?filename=testfile')) assert data == b'foo' + + def test_file_no_filename(self): + with pytest.raises(qutescheme.UrlInvalidError): + qutescheme.data_for_url(QUrl('qute://pdfjs/file')) + + @pytest.mark.parametrize('sep', ['/', os.sep]) + def test_file_pathsep(self, sep): + url = QUrl('qute://pdfjs/file') + query = QUrlQuery() + query.addQueryItem('filename', 'foo{}bar'.format(sep)) + url.setQuery(query) + with pytest.raises(qutescheme.RequestDeniedError): + qutescheme.data_for_url(url)