Add some tests for progressbar sizing in statusbar.

This commit is contained in:
Florian Bruhin 2015-08-25 21:07:35 +02:00
parent a981688509
commit 8c76db3892

View File

@ -23,11 +23,29 @@
from collections import namedtuple
import pytest
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout
from PyQt5.QtCore import QSize, Qt
from qutebrowser.browser import webview
from qutebrowser.mainwindow.statusbar.progress import Progress
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())
@pytest.fixture
def progress_widget(qtbot, monkeypatch, config_stub):
"""Create a Progress widget and checks its initial state."""
@ -44,6 +62,23 @@ def progress_widget(qtbot, monkeypatch, config_stub):
return widget
@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
def test_load_started(progress_widget):
"""Ensure the Progress widget reacts properly when the page starts loading.
@ -78,3 +113,30 @@ def test_tab_changed(progress_widget, tab, expected_visible):
actual = progress_widget.value(), progress_widget.isVisible()
expected = tab.progress, expected_visible
assert actual == expected
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