qutebrowser/tests/browser/test_commands.py

91 lines
2.7 KiB
Python
Raw Normal View History

2015-05-25 01:31:50 +02:00
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
# Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# 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/>.
"""Tests for qutebrowser.browser.commands."""
import collections
import pytest
2015-07-20 11:23:34 +02:00
from PyQt5.QtNetwork import (QNetworkCookieJar, QAbstractNetworkCache,
QNetworkCacheMetaData)
2015-05-25 01:31:50 +02:00
2015-08-16 23:20:30 +02:00
from qutebrowser.browser import commands
2015-05-25 01:31:50 +02:00
from qutebrowser.mainwindow import tabbedbrowser
from qutebrowser.utils import objreg
2015-07-20 11:23:34 +02:00
from qutebrowser.keyinput import modeman
2015-05-25 01:31:50 +02:00
ObjectsRet = collections.namedtuple('Dispatcher', ['tb', 'cd'])
2015-07-20 11:23:34 +02:00
class FakeNetworkCache(QAbstractNetworkCache):
2015-05-25 01:31:50 +02:00
2015-07-20 11:23:34 +02:00
def cacheSize(self):
return 0
2015-05-25 01:31:50 +02:00
2015-07-20 11:23:34 +02:00
def data(self, _url):
return None
2015-05-25 01:31:50 +02:00
2015-07-20 11:23:34 +02:00
def insert(self, _dev):
pass
2015-05-25 01:31:50 +02:00
2015-07-20 11:23:34 +02:00
def metaData(self, _url):
return QNetworkCacheMetaData()
def prepare(self, _metadata):
return None
def remove(self, _url):
return False
def updateMetaData(self, _url):
pass
2015-05-25 01:31:50 +02:00
@pytest.yield_fixture(autouse=True)
2015-07-20 11:23:34 +02:00
def cookiejar_and_cache():
"""Fixture providing a fake cookie jar and cache."""
2015-05-25 01:31:50 +02:00
jar = QNetworkCookieJar()
2015-07-20 11:23:34 +02:00
cache = FakeNetworkCache()
2015-05-25 01:31:50 +02:00
objreg.register('cookie-jar', jar)
2015-07-20 11:23:34 +02:00
objreg.register('cache', cache)
yield
2015-05-25 01:31:50 +02:00
objreg.delete('cookie-jar')
2015-07-20 11:23:34 +02:00
objreg.delete('cache')
2015-05-25 01:31:50 +02:00
2015-07-20 11:23:34 +02:00
@pytest.yield_fixture
def objects(qtbot, default_config, key_config_stub, tab_registry,
host_blocker_stub):
2015-05-25 01:31:50 +02:00
"""Fixture providing a CommandDispatcher and a fake TabbedBrowser."""
win_id = 0
2015-07-20 11:23:34 +02:00
modeman.init(win_id, parent=None)
2015-05-25 01:31:50 +02:00
tabbed_browser = tabbedbrowser.TabbedBrowser(win_id)
qtbot.add_widget(tabbed_browser)
2015-07-20 11:23:34 +02:00
objreg.register('tabbed-browser', tabbed_browser, scope='window',
window=win_id)
2015-05-25 01:31:50 +02:00
dispatcher = commands.CommandDispatcher(win_id, tabbed_browser)
2015-07-20 11:23:34 +02:00
objreg.register('command-dispatcher', dispatcher, scope='window',
window=win_id)
yield ObjectsRet(tabbed_browser, dispatcher)
2015-05-25 01:31:50 +02:00
2015-08-16 22:51:00 +02:00
@pytest.mark.skipif(True, reason="Work in progress")
2015-05-25 01:31:50 +02:00
def test_openurl(objects):
2015-07-20 11:23:34 +02:00
objects.cd.openurl('localhost')