2016-02-05 15:14:23 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2018-02-05 12:19:50 +01:00
|
|
|
# Copyright 2016-2018 Daniel Schadt
|
|
|
|
# Copyright 2016-2018 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
2016-02-05 15:14:23 +01:00
|
|
|
#
|
|
|
|
# This file is part of qutebrowser.
|
|
|
|
#
|
|
|
|
# qutebrowser is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# qutebrowser is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2017-05-17 20:20:12 +02:00
|
|
|
import pytest
|
2016-02-05 15:14:23 +01:00
|
|
|
from PyQt5.QtCore import QUrl
|
|
|
|
|
2017-02-05 17:09:04 +01:00
|
|
|
from qutebrowser.utils import usertypes
|
2016-09-14 12:05:15 +02:00
|
|
|
from qutebrowser.browser import pdfjs, qutescheme
|
2016-09-14 12:08:35 +02:00
|
|
|
# pylint: disable=unused-import
|
2016-09-14 12:05:15 +02:00
|
|
|
from qutebrowser.browser.webkit.network import webkitqutescheme
|
2016-09-14 12:08:35 +02:00
|
|
|
# pylint: enable=unused-import
|
2016-02-05 15:14:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
class TestPDFJSHandler:
|
|
|
|
"""Test the qute://pdfjs endpoint."""
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def fake_pdfjs(self, monkeypatch):
|
|
|
|
def get_pdfjs_res(path):
|
2016-09-14 16:48:49 +02:00
|
|
|
if path == '/existing/file.html':
|
2016-02-05 15:14:23 +01:00
|
|
|
return b'foobar'
|
|
|
|
raise pdfjs.PDFJSNotFound(path)
|
|
|
|
|
2017-03-01 11:33:41 +01:00
|
|
|
monkeypatch.setattr(pdfjs, 'get_pdfjs_res', get_pdfjs_res)
|
2016-02-05 15:14:23 +01:00
|
|
|
|
2016-09-14 12:05:15 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
2017-02-05 17:09:04 +01:00
|
|
|
def patch_backend(self, monkeypatch):
|
|
|
|
monkeypatch.setattr(qutescheme.objects, 'backend',
|
|
|
|
usertypes.Backend.QtWebKit)
|
2016-09-14 12:05:15 +02:00
|
|
|
|
|
|
|
def test_existing_resource(self):
|
2016-02-05 15:14:23 +01:00
|
|
|
"""Test with a resource that exists."""
|
2016-09-14 12:05:15 +02:00
|
|
|
_mimetype, data = qutescheme.data_for_url(
|
2016-09-14 16:48:49 +02:00
|
|
|
QUrl('qute://pdfjs/existing/file.html'))
|
2016-09-14 12:05:15 +02:00
|
|
|
assert data == b'foobar'
|
2016-02-05 15:14:23 +01:00
|
|
|
|
2016-09-14 12:05:15 +02:00
|
|
|
def test_nonexisting_resource(self, caplog):
|
2016-02-05 15:14:23 +01:00
|
|
|
"""Test with a resource that does not exist."""
|
|
|
|
with caplog.at_level(logging.WARNING, 'misc'):
|
2016-09-14 12:05:15 +02:00
|
|
|
with pytest.raises(qutescheme.QuteSchemeError):
|
2016-09-14 16:48:49 +02:00
|
|
|
qutescheme.data_for_url(QUrl('qute://pdfjs/no/file.html'))
|
2016-02-05 15:14:23 +01:00
|
|
|
assert len(caplog.records) == 1
|
|
|
|
assert (caplog.records[0].message ==
|
2016-09-14 16:48:49 +02:00
|
|
|
'pdfjs resource requested but not found: /no/file.html')
|