1# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: 2 3# Copyright 2017-2021 Florian Bruhin (The Compiler) <mail@qutebrowser.org> 4# 5# This file is part of qutebrowser. 6# 7# qutebrowser is free software: you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation, either version 3 of the License, or 10# (at your option) any later version. 11# 12# qutebrowser is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with qutebrowser. If not, see <https://www.gnu.org/licenses/>. 19 20"""Test Backforward widget.""" 21 22import pytest 23 24from qutebrowser.mainwindow.statusbar import backforward 25 26 27@pytest.fixture 28def backforward_widget(qtbot): 29 widget = backforward.Backforward() 30 qtbot.add_widget(widget) 31 return widget 32 33 34@pytest.mark.parametrize('can_go_back, can_go_forward, expected_text', [ 35 (False, False, ''), 36 (True, False, '[<]'), 37 (False, True, '[>]'), 38 (True, True, '[<>]'), 39]) 40def test_backforward_widget(backforward_widget, tabbed_browser_stubs, 41 fake_web_tab, can_go_back, can_go_forward, 42 expected_text): 43 """Ensure the Backforward widget shows the correct text.""" 44 tab = fake_web_tab(can_go_back=can_go_back, can_go_forward=can_go_forward) 45 tabbed_browser = tabbed_browser_stubs[0] 46 tabbed_browser.widget.current_index = 1 47 tabbed_browser.widget.tabs = [tab] 48 backforward_widget.enabled = True 49 backforward_widget.on_tab_cur_url_changed(tabbed_browser) 50 assert backforward_widget.text() == expected_text 51 assert backforward_widget.isVisible() == bool(expected_text) 52 53 # Check that the widget stays hidden if not in the statusbar 54 backforward_widget.enabled = False 55 backforward_widget.hide() 56 backforward_widget.on_tab_cur_url_changed(tabbed_browser) 57 assert backforward_widget.isHidden() 58 59 # Check that the widget gets reset if empty. 60 if can_go_back and can_go_forward: 61 tab = fake_web_tab(can_go_back=False, can_go_forward=False) 62 tabbed_browser.widget.tabs = [tab] 63 backforward_widget.enabled = True 64 backforward_widget.on_tab_cur_url_changed(tabbed_browser) 65 assert backforward_widget.text() == '' 66 assert not backforward_widget.isVisible() 67 68 69def test_none_tab(backforward_widget, tabbed_browser_stubs, fake_web_tab): 70 """Make sure nothing crashes when passing None as tab.""" 71 tab = fake_web_tab(can_go_back=True, can_go_forward=True) 72 tabbed_browser = tabbed_browser_stubs[0] 73 tabbed_browser.widget.current_index = 1 74 tabbed_browser.widget.tabs = [tab] 75 backforward_widget.enabled = True 76 backforward_widget.on_tab_cur_url_changed(tabbed_browser) 77 78 assert backforward_widget.text() == '[<>]' 79 assert backforward_widget.isVisible() 80 81 tabbed_browser.widget.current_index = -1 82 backforward_widget.on_tab_cur_url_changed(tabbed_browser) 83 84 assert backforward_widget.text() == '' 85 assert not backforward_widget.isVisible() 86