From 7c573bcc7e1982734ff0f1c042e4d78f8f7fe6e9 Mon Sep 17 00:00:00 2001 From: Tomasz Cebula Date: Fri, 9 Sep 2022 10:21:14 +0200 Subject: Fix for dissapearing Widgets --- qutebrowser/mainwindow/statusbar/bar.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index e2b6e5786..7bf42675d 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -287,6 +287,8 @@ class StatusBar(QWidget): self.backforward, self.tabindex, self.keystring, self.prog, self.clock, *self._text_widgets]: assert isinstance(widget, QWidget) + if widget in [self.prog, self.backforward]: + widget.enabled=False widget.hide() self._hbox.removeWidget(widget) self._text_widgets.clear() -- cgit v1.2.3-54-g00ecf From de7bb2791fa494d080a15ce30ce9dc49d455fa7c Mon Sep 17 00:00:00 2001 From: Tomasz Cebula Date: Sat, 10 Sep 2022 09:44:17 +0200 Subject: Style and type adjustment for the widget fix Added proper whitespace and mypy type ignore --- qutebrowser/mainwindow/statusbar/bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index 7bf42675d..c78426100 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -288,7 +288,7 @@ class StatusBar(QWidget): self.keystring, self.prog, self.clock, *self._text_widgets]: assert isinstance(widget, QWidget) if widget in [self.prog, self.backforward]: - widget.enabled=False + widget.enabled = False # type: ignore[attr-defined] widget.hide() self._hbox.removeWidget(widget) self._text_widgets.clear() -- cgit v1.2.3-54-g00ecf From 9c460903c583a87320a89e95f78314e494eefbdb Mon Sep 17 00:00:00 2001 From: Tomasz Cebula Date: Sat, 10 Sep 2022 09:53:05 +0200 Subject: Another style fix --- qutebrowser/mainwindow/statusbar/bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qutebrowser/mainwindow/statusbar/bar.py b/qutebrowser/mainwindow/statusbar/bar.py index c78426100..7e5a8ff2c 100644 --- a/qutebrowser/mainwindow/statusbar/bar.py +++ b/qutebrowser/mainwindow/statusbar/bar.py @@ -288,7 +288,7 @@ class StatusBar(QWidget): self.keystring, self.prog, self.clock, *self._text_widgets]: assert isinstance(widget, QWidget) if widget in [self.prog, self.backforward]: - widget.enabled = False # type: ignore[attr-defined] + widget.enabled = False # type: ignore[attr-defined] widget.hide() self._hbox.removeWidget(widget) self._text_widgets.clear() -- cgit v1.2.3-54-g00ecf From 79bb6670d8969b850965cd5d895bcd8f09d59311 Mon Sep 17 00:00:00 2001 From: toofar Date: Fri, 16 Sep 2022 16:40:57 +1200 Subject: 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. --- .../unit/mainwindow/statusbar/test_backforward.py | 71 ++++++++++++++-------- tests/unit/mainwindow/statusbar/test_progress.py | 8 +++ 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. -- cgit v1.2.3-54-g00ecf