qutebrowser/tests/unit/browser/webkit/network/test_webkitqutescheme.py

64 lines
2.3 KiB
Python
Raw Normal View History

2016-02-05 15:14:23 +01:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2016 Daniel Schadt
#
# 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 pytest
import logging
from PyQt5.QtCore import QUrl
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):
if path == '/existing/file.html':
2016-02-05 15:14:23 +01:00
return b'foobar'
raise pdfjs.PDFJSNotFound(path)
monkeypatch.setattr('qutebrowser.browser.pdfjs.get_pdfjs_res',
2016-04-27 18:30:54 +02:00
get_pdfjs_res)
2016-02-05 15:14:23 +01:00
2016-09-14 12:05:15 +02:00
@pytest.fixture(autouse=True)
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(
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):
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 ==
'pdfjs resource requested but not found: /no/file.html')