2015-04-02 03:39:25 +02:00
|
|
|
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
|
|
|
|
|
|
|
# Copyright 2014-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/>.
|
|
|
|
|
|
|
|
|
2015-04-02 13:05:23 +02:00
|
|
|
"""Test Progress widget."""
|
2015-04-02 03:39:25 +02:00
|
|
|
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
import pytest
|
2015-08-25 21:07:35 +02:00
|
|
|
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
|
|
|
|
from PyQt5.QtCore import QSize, Qt
|
2015-04-02 03:39:25 +02:00
|
|
|
|
|
|
|
from qutebrowser.browser import webview
|
|
|
|
from qutebrowser.mainwindow.statusbar.progress import Progress
|
|
|
|
|
|
|
|
|
2015-08-25 21:07:35 +02:00
|
|
|
class FakeStatusBar(QWidget):
|
|
|
|
|
|
|
|
"""Fake statusbar to test progressbar sizing."""
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
self.hbox = QHBoxLayout(self)
|
|
|
|
self.hbox.addStretch()
|
|
|
|
self.hbox.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.setAttribute(Qt.WA_StyledBackground, True)
|
|
|
|
self.setStyleSheet('background-color: red;')
|
|
|
|
|
|
|
|
def minimumSizeHint(self):
|
|
|
|
return QSize(1, self.fontMetrics().height())
|
|
|
|
|
|
|
|
|
2015-04-02 03:39:25 +02:00
|
|
|
@pytest.fixture
|
2015-05-07 07:58:22 +02:00
|
|
|
def progress_widget(qtbot, monkeypatch, config_stub):
|
2015-04-05 20:30:31 +02:00
|
|
|
"""Create a Progress widget and checks its initial state."""
|
2015-05-07 07:58:22 +02:00
|
|
|
config_stub.data = {
|
|
|
|
'colors': {'statusbar.progress.bg': 'black'},
|
|
|
|
'fonts': {},
|
|
|
|
}
|
|
|
|
monkeypatch.setattr(
|
|
|
|
'qutebrowser.mainwindow.statusbar.progress.style.config', config_stub)
|
2015-04-02 03:39:25 +02:00
|
|
|
widget = Progress()
|
|
|
|
qtbot.add_widget(widget)
|
|
|
|
assert not widget.isVisible()
|
|
|
|
assert not widget.isTextVisible()
|
|
|
|
return widget
|
|
|
|
|
|
|
|
|
2015-08-25 21:07:35 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def statusbar(qtbot):
|
|
|
|
container = QWidget()
|
|
|
|
qtbot.add_widget(container)
|
|
|
|
vbox = QVBoxLayout(container)
|
|
|
|
vbox.addStretch()
|
|
|
|
|
|
|
|
statusbar = FakeStatusBar(container)
|
|
|
|
statusbar.container = container # to make sure container isn't GCed
|
|
|
|
vbox.addWidget(statusbar)
|
|
|
|
|
|
|
|
container.show()
|
|
|
|
qtbot.waitForWindowShown(container)
|
|
|
|
return statusbar
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-02 03:39:25 +02:00
|
|
|
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.
|
|
|
|
|
2015-04-02 03:39:25 +02:00
|
|
|
Args:
|
|
|
|
progress_widget: Progress widget that will be tested.
|
|
|
|
"""
|
|
|
|
progress_widget.on_load_started()
|
|
|
|
assert progress_widget.value() == 0
|
|
|
|
assert progress_widget.isVisible()
|
|
|
|
|
|
|
|
|
|
|
|
# mock tab object
|
|
|
|
Tab = namedtuple('Tab', 'progress load_status')
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('tab, expected_visible', [
|
|
|
|
(Tab(15, webview.LoadStatus.loading), True),
|
|
|
|
(Tab(100, webview.LoadStatus.success), False),
|
|
|
|
(Tab(100, webview.LoadStatus.error), False),
|
|
|
|
(Tab(100, webview.LoadStatus.warn), False),
|
|
|
|
(Tab(100, webview.LoadStatus.none), False),
|
|
|
|
])
|
|
|
|
def test_tab_changed(progress_widget, tab, expected_visible):
|
2015-04-05 20:30:31 +02:00
|
|
|
"""Test that progress widget value and visibility state match expectations.
|
|
|
|
|
|
|
|
This uses a dummy Tab object.
|
2015-04-02 03:39:25 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
progress_widget: Progress widget that will be tested.
|
|
|
|
"""
|
|
|
|
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
|
|
|
|
assert actual == expected
|
2015-08-25 21:07:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_progress_affecting_statusbar_height(statusbar, progress_widget):
|
|
|
|
"""Make sure the statusbar stays the same height when progress is shown.
|
|
|
|
|
|
|
|
https://github.com/The-Compiler/qutebrowser/issues/886
|
|
|
|
https://github.com/The-Compiler/qutebrowser/pull/890
|
|
|
|
"""
|
|
|
|
expected_height = statusbar.fontMetrics().height()
|
|
|
|
assert statusbar.height() == expected_height
|
|
|
|
|
|
|
|
statusbar.hbox.addWidget(progress_widget)
|
|
|
|
progress_widget.show()
|
|
|
|
|
|
|
|
assert statusbar.height() == expected_height
|
|
|
|
|
|
|
|
|
|
|
|
def test_progress_big_statusbar(qtbot, statusbar, progress_widget):
|
|
|
|
"""Make sure the progress bar is small with a big statusbar.
|
|
|
|
|
|
|
|
https://github.com/The-Compiler/qutebrowser/commit/46d1760798b730852e2207e2cdc05a9308e44f80
|
|
|
|
"""
|
|
|
|
statusbar.hbox.addWidget(progress_widget)
|
|
|
|
progress_widget.show()
|
|
|
|
expected_height = progress_widget.height()
|
|
|
|
statusbar.hbox.addStrut(50)
|
|
|
|
assert progress_widget.height() == expected_height
|