2016-03-24 06:14:16 +01:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
2016-03-25 23:56:39 +01:00
|
|
|
# Copyright 2016 Clayton Craft (craftyguy) <craftyguy@gmail.com>
|
2016-03-24 06:14:16 +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/>.
|
|
|
|
|
|
|
|
|
|
|
|
"""Test Statusbar url."""
|
|
|
|
|
|
|
|
import pytest
|
2016-03-25 23:56:39 +01:00
|
|
|
import collections
|
2016-03-24 06:14:16 +01:00
|
|
|
|
2016-03-25 23:56:39 +01:00
|
|
|
from qutebrowser.browser import webview
|
|
|
|
from qutebrowser.mainwindow.statusbar import url
|
2016-03-24 06:14:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def tab_widget():
|
|
|
|
"""Fixture providing a fake tab widget."""
|
2016-03-25 23:56:39 +01:00
|
|
|
tab = collections.namedtuple('Tab', 'cur_url load_status')
|
|
|
|
tab.cur_url = collections.namedtuple('cur_url', 'toDisplayString')
|
2016-03-24 06:14:16 +01:00
|
|
|
return tab
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def url_widget(qtbot, monkeypatch, config_stub):
|
|
|
|
"""Fixture providing a Url widget."""
|
|
|
|
config_stub.data = {
|
|
|
|
'colors': {
|
|
|
|
'statusbar.url.bg': 'white',
|
|
|
|
'statusbar.url.fg': 'black',
|
|
|
|
'statusbar.url.fg.success': 'yellow',
|
|
|
|
'statusbar.url.fg.success.https': 'green',
|
|
|
|
'statusbar.url.fg.error': 'red',
|
|
|
|
'statusbar.url.fg.warn': 'orange',
|
|
|
|
'statusbar.url.fg.hover': 'blue'},
|
|
|
|
'fonts': {},
|
|
|
|
}
|
|
|
|
monkeypatch.setattr(
|
|
|
|
'qutebrowser.mainwindow.statusbar.url.style.config', config_stub)
|
2016-03-25 23:56:39 +01:00
|
|
|
widget = url.UrlText()
|
2016-03-24 06:14:16 +01:00
|
|
|
qtbot.add_widget(widget)
|
|
|
|
assert not widget.isVisible()
|
|
|
|
return widget
|
|
|
|
|
|
|
|
|
2016-03-25 23:56:39 +01:00
|
|
|
@pytest.mark.parametrize('url_text', [
|
|
|
|
'http://abc123.com/this/awesome/url.html',
|
|
|
|
'https://supersecret.gov/nsa/files.txt',
|
|
|
|
'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->',
|
|
|
|
None
|
2016-03-24 06:14:16 +01:00
|
|
|
])
|
2016-03-25 23:56:39 +01:00
|
|
|
def test_set_url(url_widget, url_text):
|
2016-03-24 06:14:16 +01:00
|
|
|
"""Test text displayed by the widget."""
|
2016-03-25 23:56:39 +01:00
|
|
|
url_widget.set_url(url_text)
|
|
|
|
if url_text is not None:
|
|
|
|
assert url_widget.text() == url_text
|
2016-03-24 06:14:16 +01:00
|
|
|
else:
|
|
|
|
assert url_widget.text() == ""
|
|
|
|
|
|
|
|
|
2016-03-25 23:56:39 +01:00
|
|
|
@pytest.mark.parametrize('url_text, title, text', [
|
2016-03-24 06:14:16 +01:00
|
|
|
('http://abc123.com/this/awesome/url.html', 'Awesome site', 'click me!'),
|
|
|
|
('https://supersecret.gov/nsa/files.txt', 'Secret area', None),
|
|
|
|
('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', 'Probably spam', 'definitely'),
|
|
|
|
(None, None, 'did I break?!')
|
|
|
|
])
|
2016-03-25 23:56:39 +01:00
|
|
|
def test_set_hover_url(url_widget, url_text, title, text):
|
2016-03-24 06:14:16 +01:00
|
|
|
"""Test text when hovering over a link."""
|
2016-03-25 23:56:39 +01:00
|
|
|
url_widget.set_hover_url(url_text, title, text)
|
|
|
|
if url_text is not None:
|
|
|
|
assert url_widget.text() == url_text
|
|
|
|
assert url_widget._urltype == url.UrlType.hover
|
2016-03-24 06:14:16 +01:00
|
|
|
else:
|
|
|
|
assert url_widget.text() == ''
|
2016-03-25 23:56:39 +01:00
|
|
|
assert url_widget._urltype == url.UrlType.normal
|
2016-03-24 06:14:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('status, expected', [
|
2016-03-25 23:56:39 +01:00
|
|
|
(webview.LoadStatus.success, url.UrlType.success),
|
|
|
|
(webview.LoadStatus.success_https, url.UrlType.success_https),
|
|
|
|
(webview.LoadStatus.error, url.UrlType.error),
|
|
|
|
(webview.LoadStatus.warn, url.UrlType.warn),
|
|
|
|
(webview.LoadStatus.loading, url.UrlType.normal),
|
|
|
|
(webview.LoadStatus.none, url.UrlType.normal)
|
2016-03-24 06:14:16 +01:00
|
|
|
])
|
|
|
|
def test_on_load_status_changed(url_widget, status, expected):
|
|
|
|
"""Test text when status is changed."""
|
|
|
|
url_widget.set_url('www.example.com')
|
2016-03-25 23:56:39 +01:00
|
|
|
url_widget.on_load_status_changed(status.name)
|
|
|
|
assert url_widget._urltype == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('load_status, url_text', [
|
|
|
|
(url.UrlType.success, 'http://abc123.com/this/awesome/url.html'),
|
|
|
|
(url.UrlType.success, 'http://reddit.com/r/linux'),
|
|
|
|
(url.UrlType.success_https, 'www.google.com'),
|
|
|
|
(url.UrlType.success_https, 'https://supersecret.gov/nsa/files.txt'),
|
2016-03-26 00:35:49 +01:00
|
|
|
(url.UrlType.warn, 'www.shadysite.org/some/path/to/file/with/issues.htm'),
|
2016-03-25 23:56:39 +01:00
|
|
|
(url.UrlType.error, 'Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->'),
|
|
|
|
(url.UrlType.error, None)
|
2016-03-24 06:14:16 +01:00
|
|
|
])
|
2016-03-25 23:56:39 +01:00
|
|
|
def test_on_tab_changed(url_widget, tab_widget, load_status, url_text):
|
|
|
|
tab_widget.load_status = load_status
|
|
|
|
tab_widget.cur_url.toDisplayString = lambda: url_text
|
2016-03-24 06:14:16 +01:00
|
|
|
url_widget.on_tab_changed(tab_widget)
|
2016-03-25 23:56:39 +01:00
|
|
|
if url_text is not None:
|
|
|
|
assert url_widget._urltype == load_status
|
|
|
|
assert url_widget.text() == url_text
|
2016-03-24 06:14:16 +01:00
|
|
|
else:
|
2016-03-25 23:56:39 +01:00
|
|
|
assert url_widget._urltype == url.UrlType.normal
|
2016-03-24 06:14:16 +01:00
|
|
|
assert url_widget.text() == ''
|
2016-03-29 00:12:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('url_text, load_status, expected_status', [
|
|
|
|
('http://abc123.com/this/awesome/url.html', webview.LoadStatus.success,
|
|
|
|
url.UrlType.success),
|
|
|
|
('https://supersecret.gov/nsa/files.txt', webview.LoadStatus.success_https,
|
|
|
|
url.UrlType.success_https),
|
|
|
|
('Th1$ i$ n0t @ n0rm@L uRL! P@n1c! <-->', webview.LoadStatus.error,
|
|
|
|
url.UrlType.error),
|
|
|
|
('http://www.qutebrowser.org/CONTRIBUTING.html', webview.LoadStatus.loading,
|
|
|
|
url.UrlType.normal),
|
|
|
|
('www.whatisthisurl.com', webview.LoadStatus.warn, url.UrlType.warn)
|
|
|
|
])
|
|
|
|
def test_normal_url(url_widget, url_text, load_status, expected_status):
|
|
|
|
url_widget.set_url(url_text)
|
|
|
|
url_widget.on_load_status_changed(load_status.name)
|
|
|
|
url_widget.set_hover_url(url_text, "", "")
|
|
|
|
url_widget.set_hover_url("", "", "")
|
|
|
|
assert url_widget.text() == url_text
|
|
|
|
assert url_widget._urltype == expected_status
|