qutebrowser/tests/unit/mainwindow/statusbar/test_progress.py

102 lines
3.5 KiB
Python
Raw Normal View History

# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2016-01-04 07:12:39 +01:00
# Copyright 2014-2016 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/>.
2015-04-02 13:05:23 +02:00
"""Test Progress widget."""
import pytest
from qutebrowser.mainwindow.statusbar.progress import Progress
2016-06-13 17:49:52 +02:00
from qutebrowser.utils import usertypes
@pytest.fixture
def progress_widget(qtbot, monkeypatch, config_stub):
2015-04-05 20:30:31 +02:00
"""Create a Progress widget and checks its initial state."""
config_stub.data = {
'colors': {'statusbar.progress.bg': 'black'},
'fonts': {},
}
monkeypatch.setattr(
'qutebrowser.mainwindow.statusbar.progress.style.config', config_stub)
widget = Progress()
qtbot.add_widget(widget)
assert not widget.isVisible()
assert not widget.isTextVisible()
return widget
def test_load_started(progress_widget):
2015-04-05 20:30:31 +02:00
"""Ensure the Progress widget reacts properly when the page starts loading.
Args:
progress_widget: Progress widget that will be tested.
"""
progress_widget.on_load_started()
assert progress_widget.value() == 0
assert progress_widget.isVisible()
@pytest.mark.parametrize('progress, load_status, expected_visible', [
(15, usertypes.LoadStatus.loading, True),
(100, usertypes.LoadStatus.success, False),
(100, usertypes.LoadStatus.error, False),
(100, usertypes.LoadStatus.warn, False),
(100, usertypes.LoadStatus.none, False),
])
def test_tab_changed(fake_web_tab, progress_widget, progress, load_status,
expected_visible):
2015-04-05 20:30:31 +02:00
"""Test that progress widget value and visibility state match expectations.
Args:
progress_widget: Progress widget that will be tested.
"""
tab = fake_web_tab(progress=progress, load_status=load_status)
progress_widget.on_tab_changed(tab)
2015-04-05 20:30:31 +02:00
actual = progress_widget.value(), progress_widget.isVisible()
expected = tab.progress(), expected_visible
2015-04-05 20:30:31 +02:00
assert actual == expected
2015-08-25 21:21:49 +02:00
def test_progress_affecting_statusbar_height(fake_statusbar, progress_widget):
"""Make sure the statusbar stays the same height when progress is shown.
2017-02-05 00:13:11 +01:00
https://github.com/qutebrowser/qutebrowser/issues/886
https://github.com/qutebrowser/qutebrowser/pull/890
"""
2015-08-25 21:21:49 +02:00
expected_height = fake_statusbar.fontMetrics().height()
assert fake_statusbar.height() == expected_height
2015-08-25 21:21:49 +02:00
fake_statusbar.hbox.addWidget(progress_widget)
progress_widget.show()
2015-08-25 21:21:49 +02:00
assert fake_statusbar.height() == expected_height
2015-08-25 21:21:49 +02:00
def test_progress_big_statusbar(qtbot, fake_statusbar, progress_widget):
"""Make sure the progress bar is small with a big statusbar.
2017-02-05 00:13:11 +01:00
https://github.com/qutebrowser/qutebrowser/commit/46d1760798b730852e2207e2cdc05a9308e44f80
"""
2015-08-25 21:21:49 +02:00
fake_statusbar.hbox.addWidget(progress_widget)
progress_widget.show()
expected_height = progress_widget.height()
2015-08-25 21:21:49 +02:00
fake_statusbar.hbox.addStrut(50)
assert progress_widget.height() == expected_height