summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2022-09-16 16:40:57 +1200
committertoofar <toofar@spalge.com>2022-09-16 16:51:41 +1200
commit79bb6670d8969b850965cd5d895bcd8f09d59311 (patch)
tree67fb0ddd5d2c38540626480be5f631209182d59a
parent9c460903c583a87320a89e95f78314e494eefbdb (diff)
downloadqutebrowser-79bb6670d8969b850965cd5d895bcd8f09d59311.tar.gz
qutebrowser-79bb6670d8969b850965cd5d895bcd8f09d59311.zip
bar: Test enabled attribute on progress and backforward
There is now some code in statusbar relying on the enabled attribute stopping events from being processed (or at least stopping them from showing the widget again). So add tests to make sure that behaviour keeps working. Also split the big test in test_backforward into a couple of smaller ones and pull some common lines out to a (still clunky) fixture.
-rw-r--r--tests/unit/mainwindow/statusbar/test_backforward.py71
-rw-r--r--tests/unit/mainwindow/statusbar/test_progress.py8
2 files changed, 52 insertions, 27 deletions
diff --git a/tests/unit/mainwindow/statusbar/test_backforward.py b/tests/unit/mainwindow/statusbar/test_backforward.py
index d3e033b34..ac73f8ee1 100644
--- a/tests/unit/mainwindow/statusbar/test_backforward.py
+++ b/tests/unit/mainwindow/statusbar/test_backforward.py
@@ -31,55 +31,72 @@ def backforward_widget(qtbot):
return widget
+@pytest.fixture
+def tabs(tabbed_browser_stubs):
+ tabbed_browser = tabbed_browser_stubs[0]
+ tabbed_browser.widget.current_index = 1
+ return tabbed_browser
+
+
@pytest.mark.parametrize('can_go_back, can_go_forward, expected_text', [
(False, False, ''),
(True, False, '[<]'),
(False, True, '[>]'),
(True, True, '[<>]'),
])
-def test_backforward_widget(backforward_widget, tabbed_browser_stubs,
- fake_web_tab, can_go_back, can_go_forward,
- expected_text):
+def test_widget_state(backforward_widget, tabs,
+ fake_web_tab, can_go_back, can_go_forward,
+ expected_text):
"""Ensure the Backforward widget shows the correct text."""
tab = fake_web_tab(can_go_back=can_go_back, can_go_forward=can_go_forward)
- tabbed_browser = tabbed_browser_stubs[0]
- tabbed_browser.widget.current_index = 1
- tabbed_browser.widget.tabs = [tab]
+ tabs.widget.tabs = [tab]
backforward_widget.enabled = True
- backforward_widget.on_tab_cur_url_changed(tabbed_browser)
+ backforward_widget.on_tab_cur_url_changed(tabs)
assert backforward_widget.text() == expected_text
assert backforward_widget.isVisible() == bool(expected_text)
- # Check that the widget stays hidden if not in the statusbar
- backforward_widget.enabled = False
- backforward_widget.hide()
- backforward_widget.on_tab_cur_url_changed(tabbed_browser)
- assert backforward_widget.isHidden()
- # Check that the widget gets reset if empty.
- if can_go_back and can_go_forward:
- tab = fake_web_tab(can_go_back=False, can_go_forward=False)
- tabbed_browser.widget.tabs = [tab]
- backforward_widget.enabled = True
- backforward_widget.on_tab_cur_url_changed(tabbed_browser)
- assert backforward_widget.text() == ''
- assert not backforward_widget.isVisible()
+def test_state_changes_on_tab_change(backforward_widget, tabs, fake_web_tab):
+ """Test we go invisible when switching to a tab without history."""
+ tab_with_history = fake_web_tab(can_go_back=True, can_go_forward=True)
+ tab_without_history = fake_web_tab(can_go_back=False, can_go_forward=False)
+ tabs.widget.tabs = [tab_with_history]
+ backforward_widget.enabled = True
+
+ backforward_widget.on_tab_cur_url_changed(tabs)
+ assert backforward_widget.isVisible()
+
+ tabs.widget.tabs = [tab_without_history]
+ backforward_widget.on_tab_cur_url_changed(tabs)
+ assert backforward_widget.text() == ''
+ assert not backforward_widget.isVisible()
-def test_none_tab(backforward_widget, tabbed_browser_stubs, fake_web_tab):
+def test_none_tab(backforward_widget, tabs, fake_web_tab):
"""Make sure nothing crashes when passing None as tab."""
tab = fake_web_tab(can_go_back=True, can_go_forward=True)
- tabbed_browser = tabbed_browser_stubs[0]
- tabbed_browser.widget.current_index = 1
- tabbed_browser.widget.tabs = [tab]
+ tabs.widget.tabs = [tab]
backforward_widget.enabled = True
- backforward_widget.on_tab_cur_url_changed(tabbed_browser)
+ backforward_widget.on_tab_cur_url_changed(tabs)
assert backforward_widget.text() == '[<>]'
assert backforward_widget.isVisible()
- tabbed_browser.widget.current_index = -1
- backforward_widget.on_tab_cur_url_changed(tabbed_browser)
+ tabs.widget.current_index = -1
+ backforward_widget.on_tab_cur_url_changed(tabs)
assert backforward_widget.text() == ''
assert not backforward_widget.isVisible()
+
+
+def test_not_shown_when_disabled(backforward_widget, tabs, fake_web_tab):
+ """The widget shouldn't get shown on an event when it's disabled."""
+ tab = fake_web_tab(can_go_back=True, can_go_forward=True)
+ tabs.widget.tabs = [tab]
+
+ backforward_widget.enabled = False
+ backforward_widget.on_tab_cur_url_changed(tabs)
+ assert not backforward_widget.isVisible()
+
+ backforward_widget.on_tab_changed(tab)
+ assert not backforward_widget.isVisible()
diff --git a/tests/unit/mainwindow/statusbar/test_progress.py b/tests/unit/mainwindow/statusbar/test_progress.py
index 888ed5943..1cc3bf9af 100644
--- a/tests/unit/mainwindow/statusbar/test_progress.py
+++ b/tests/unit/mainwindow/statusbar/test_progress.py
@@ -69,6 +69,14 @@ def test_tab_changed(fake_web_tab, progress_widget, progress, load_status,
assert actual == expected
+def test_not_shown_when_disabled(progress_widget, fake_web_tab):
+ """The widget shouldn't get shown on an event when it's disabled."""
+ tab = fake_web_tab(progress=15, load_status=usertypes.LoadStatus.loading)
+ progress_widget.enabled = False
+ progress_widget.on_tab_changed(tab)
+ assert not progress_widget.isVisible()
+
+
def test_progress_affecting_statusbar_height(config_stub, fake_statusbar,
progress_widget):
"""Make sure the statusbar stays the same height when progress is shown.