2016-03-24 06:14:16 +01:00
|
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
2018-02-05 12:19:50 +01:00
|
|
|
|
# Copyright 2016-2018 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
|
|
|
|
|
|
2017-05-19 08:10:17 +02:00
|
|
|
|
from PyQt5.QtCore import QUrl
|
|
|
|
|
|
2017-04-24 06:58:41 +02:00
|
|
|
|
from qutebrowser.utils import usertypes, urlutils
|
2016-03-25 23:56:39 +01:00
|
|
|
|
from qutebrowser.mainwindow.statusbar import url
|
2017-05-19 08:10:17 +02:00
|
|
|
|
from helpers import utils
|
2016-03-24 06:14:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def url_widget(qtbot, monkeypatch, config_stub):
|
|
|
|
|
"""Fixture providing a Url widget."""
|
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-05-12 17:21:13 +02:00
|
|
|
|
@pytest.mark.parametrize('url_text, expected', [
|
2017-04-24 06:58:41 +02:00
|
|
|
|
('http://example.com/foo/bar.html', 'http://example.com/foo/bar.html'),
|
2016-05-12 17:21:13 +02:00
|
|
|
|
('http://test.gr/%CE%B1%CE%B2%CE%B3%CE%B4.txt', 'http://test.gr/αβγδ.txt'),
|
|
|
|
|
('http://test.ru/%D0%B0%D0%B1%D0%B2%D0%B3.txt', 'http://test.ru/абвг.txt'),
|
|
|
|
|
('http://test.com/s%20p%20a%20c%20e.txt', 'http://test.com/s p a c e.txt'),
|
|
|
|
|
('http://test.com/%22quotes%22.html', 'http://test.com/%22quotes%22.html'),
|
2016-05-18 16:20:20 +02:00
|
|
|
|
('http://username:secret%20password@test.com', 'http://username@test.com'),
|
2017-04-24 06:58:41 +02:00
|
|
|
|
('http://example.com%5b/', '(invalid URL!) http://example.com%5b/'),
|
|
|
|
|
# https://bugreports.qt.io/browse/QTBUG-60364
|
2017-05-23 08:08:46 +02:00
|
|
|
|
pytest.param('http://www.xn--80ak6aa92e.com',
|
|
|
|
|
'(unparseable URL!) http://www.аррӏе.com', marks=utils.qt58),
|
|
|
|
|
pytest.param('http://www.xn--80ak6aa92e.com',
|
|
|
|
|
'http://www.xn--80ak6aa92e.com', marks=utils.qt59),
|
2017-04-24 06:58:41 +02:00
|
|
|
|
# IDN URL
|
|
|
|
|
('http://www.ä.com', '(www.xn--4ca.com) http://www.ä.com'),
|
|
|
|
|
(None, ''),
|
2016-05-12 17:21:13 +02:00
|
|
|
|
])
|
2017-04-24 06:58:41 +02:00
|
|
|
|
@pytest.mark.parametrize('which', ['normal', 'hover'])
|
|
|
|
|
def test_set_url(url_widget, url_text, expected, which):
|
2016-05-12 17:21:13 +02:00
|
|
|
|
"""Test text when hovering over a percent encoded link."""
|
2017-04-24 06:58:41 +02:00
|
|
|
|
if which == 'normal':
|
2017-04-24 07:47:58 +02:00
|
|
|
|
if url_text is None:
|
2017-04-24 08:41:29 +02:00
|
|
|
|
qurl = None
|
|
|
|
|
else:
|
|
|
|
|
qurl = QUrl(url_text)
|
|
|
|
|
if not qurl.isValid():
|
|
|
|
|
# Special case for the invalid URL above
|
|
|
|
|
expected = "Invalid URL!"
|
2017-04-24 07:47:58 +02:00
|
|
|
|
url_widget.set_url(qurl)
|
2017-04-24 06:58:41 +02:00
|
|
|
|
else:
|
|
|
|
|
url_widget.set_hover_url(url_text)
|
|
|
|
|
|
2016-05-12 17:21:13 +02:00
|
|
|
|
assert url_widget.text() == expected
|
2017-04-24 06:58:41 +02:00
|
|
|
|
|
|
|
|
|
if which == 'hover' and expected:
|
|
|
|
|
assert url_widget._urltype == url.UrlType.hover
|
|
|
|
|
else:
|
|
|
|
|
assert url_widget._urltype == url.UrlType.normal
|
2016-05-12 17:21:13 +02:00
|
|
|
|
|
|
|
|
|
|
2016-03-24 06:14:16 +01:00
|
|
|
|
@pytest.mark.parametrize('status, expected', [
|
2016-06-13 17:49:52 +02:00
|
|
|
|
(usertypes.LoadStatus.success, url.UrlType.success),
|
|
|
|
|
(usertypes.LoadStatus.success_https, url.UrlType.success_https),
|
|
|
|
|
(usertypes.LoadStatus.error, url.UrlType.error),
|
|
|
|
|
(usertypes.LoadStatus.warn, url.UrlType.warn),
|
|
|
|
|
(usertypes.LoadStatus.loading, url.UrlType.normal),
|
|
|
|
|
(usertypes.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."""
|
2016-07-11 15:02:57 +02:00
|
|
|
|
url_widget.set_url(QUrl('www.example.com'))
|
2016-03-25 23:56:39 +01:00
|
|
|
|
url_widget.on_load_status_changed(status.name)
|
|
|
|
|
assert url_widget._urltype == expected
|
|
|
|
|
|
|
|
|
|
|
2016-07-08 10:17:53 +02:00
|
|
|
|
@pytest.mark.parametrize('load_status, qurl', [
|
|
|
|
|
(url.UrlType.success, QUrl('http://abc123.com/this/awesome/url.html')),
|
|
|
|
|
(url.UrlType.success, QUrl('http://reddit.com/r/linux')),
|
2017-04-24 06:58:41 +02:00
|
|
|
|
(url.UrlType.success, QUrl('http://ä.com/')),
|
2016-07-08 10:17:53 +02:00
|
|
|
|
(url.UrlType.success_https, QUrl('www.google.com')),
|
|
|
|
|
(url.UrlType.success_https, QUrl('https://supersecret.gov/nsa/files.txt')),
|
2016-07-08 11:14:17 +02:00
|
|
|
|
(url.UrlType.warn, QUrl('www.shadysite.org/some/file/with/issues.htm')),
|
2016-07-08 10:17:53 +02:00
|
|
|
|
(url.UrlType.error, QUrl('invalid::/url')),
|
2017-04-24 08:41:29 +02:00
|
|
|
|
(url.UrlType.error, QUrl()),
|
2016-03-24 06:14:16 +01:00
|
|
|
|
])
|
2016-07-08 18:48:24 +02:00
|
|
|
|
def test_on_tab_changed(url_widget, fake_web_tab, load_status, qurl):
|
|
|
|
|
tab_widget = fake_web_tab(load_status=load_status, url=qurl)
|
2016-03-24 06:14:16 +01:00
|
|
|
|
url_widget.on_tab_changed(tab_widget)
|
2017-04-24 08:41:29 +02:00
|
|
|
|
|
2016-07-08 10:17:53 +02:00
|
|
|
|
assert url_widget._urltype == load_status
|
2017-04-24 08:41:29 +02:00
|
|
|
|
if not qurl.isValid():
|
|
|
|
|
expected = ''
|
|
|
|
|
else:
|
|
|
|
|
expected = urlutils.safe_display_string(qurl)
|
|
|
|
|
assert url_widget.text() == expected
|
2016-03-29 00:12:16 +02:00
|
|
|
|
|
|
|
|
|
|
2016-07-11 14:28:51 +02:00
|
|
|
|
@pytest.mark.parametrize('qurl, load_status, expected_status', [
|
|
|
|
|
(
|
|
|
|
|
QUrl('http://abc123.com/this/awesome/url.html'),
|
|
|
|
|
usertypes.LoadStatus.success,
|
|
|
|
|
url.UrlType.success
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
QUrl('https://supersecret.gov/nsa/files.txt'),
|
|
|
|
|
usertypes.LoadStatus.success_https,
|
|
|
|
|
url.UrlType.success_https
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
QUrl('http://www.qutebrowser.org/CONTRIBUTING.html'),
|
|
|
|
|
usertypes.LoadStatus.loading,
|
|
|
|
|
url.UrlType.normal
|
|
|
|
|
),
|
|
|
|
|
(
|
|
|
|
|
QUrl('www.whatisthisurl.com'),
|
|
|
|
|
usertypes.LoadStatus.warn,
|
|
|
|
|
url.UrlType.warn
|
|
|
|
|
),
|
2016-03-29 00:12:16 +02:00
|
|
|
|
])
|
2016-07-11 14:28:51 +02:00
|
|
|
|
def test_normal_url(url_widget, qurl, load_status, expected_status):
|
|
|
|
|
url_widget.set_url(qurl)
|
2016-03-29 00:12:16 +02:00
|
|
|
|
url_widget.on_load_status_changed(load_status.name)
|
2016-07-11 14:59:00 +02:00
|
|
|
|
url_widget.set_hover_url(qurl.toDisplayString())
|
2016-06-14 09:45:20 +02:00
|
|
|
|
url_widget.set_hover_url("")
|
2016-07-11 15:02:57 +02:00
|
|
|
|
assert url_widget.text() == qurl.toDisplayString()
|
2016-03-29 00:12:16 +02:00
|
|
|
|
assert url_widget._urltype == expected_status
|