Add missing tests for qute://pdfjs

This commit is contained in:
Florian Bruhin 2018-09-09 19:22:39 +02:00
parent b4077a8543
commit 9b04c4b8e0

View File

@ -23,7 +23,7 @@ import time
import logging import logging
import py.path # pylint: disable=no-name-in-module import py.path # pylint: disable=no-name-in-module
from PyQt5.QtCore import QUrl from PyQt5.QtCore import QUrl, QUrlQuery
import pytest import pytest
from qutebrowser.browser import qutescheme, pdfjs, downloads from qutebrowser.browser import qutescheme, pdfjs, downloads
@ -213,9 +213,26 @@ class TestPDFJSHandler:
QUrl('qute://pdfjs/web/viewer.html?filename=foobar')) QUrl('qute://pdfjs/web/viewer.html?filename=foobar'))
assert b'PDF.js' in data 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): def test_file(self, download_tmpdir):
"""Load a file via qute://pdfjs/file.""" """Load a file via qute://pdfjs/file."""
(download_tmpdir / 'testfile').write_binary(b'foo') (download_tmpdir / 'testfile').write_binary(b'foo')
_mimetype, data = qutescheme.data_for_url( _mimetype, data = qutescheme.data_for_url(
QUrl('qute://pdfjs/file?filename=testfile')) QUrl('qute://pdfjs/file?filename=testfile'))
assert data == b'foo' 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)