Clean up pdfjs tests.

This commit is contained in:
Florian Bruhin 2016-01-05 18:45:35 +01:00
parent 88d28e690e
commit d75ee78845

View File

@ -31,23 +31,18 @@ from qutebrowser.browser import pdfjs
# because we use qutebrowser.browser.webelem.javascript_escape. Characters # because we use qutebrowser.browser.webelem.javascript_escape. Characters
# like " are already replaced by QUrl. # like " are already replaced by QUrl.
@pytest.mark.parametrize('url, expected', [ @pytest.mark.parametrize('url, expected', [
('http://foo.bar', ('http://foo.bar', "http://foo.bar"),
'PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.info;\n' ('http://"', ''),
'PDFView.open("http://foo.bar");\n'), ('\0', '%00'),
('http://"',
'PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.info;\n'
'PDFView.open("");\n'),
('\0',
'PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.info;\n'
'PDFView.open("%00");\n'),
('http://foobar/");alert("attack!");', ('http://foobar/");alert("attack!");',
'PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.info;\n' 'http://foobar/%22);alert(%22attack!%22);'),
'PDFView.open("http://foobar/%22);alert(%22attack!%22);");\n'),
]) ])
def test_generate_pdfjs_script(url, expected): def test_generate_pdfjs_script(url, expected):
expected_code = ('PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.info;\n'
'PDFView.open("{}");\n'.format(expected))
url = QUrl(url) url = QUrl(url)
actual = pdfjs._generate_pdfjs_script(url) actual = pdfjs._generate_pdfjs_script(url)
assert actual == expected assert actual == expected_code
def test_fix_urls(): def test_fix_urls():
@ -79,4 +74,3 @@ def test_fix_urls():
]) ])
def test_remove_prefix(path, expected): def test_remove_prefix(path, expected):
assert pdfjs._remove_prefix(path) == expected assert pdfjs._remove_prefix(path) == expected