Add a test for a None currentWidget with backforward widget
This commit is contained in:
parent
5fb6cb713b
commit
e81dcccace
@ -29,7 +29,9 @@ class Backforward(textbase.TextBase):
|
||||
def on_tab_cur_url_changed(self, tabs):
|
||||
"""Called on URL changes."""
|
||||
tab = tabs.currentWidget()
|
||||
if tab is None: # pragma: no cover
|
||||
if tab is None:
|
||||
self.setText('')
|
||||
self.hide()
|
||||
return
|
||||
text = ''
|
||||
if tab.history.can_go_back():
|
||||
|
@ -620,7 +620,10 @@ class TabbedBrowserStub(QObject):
|
||||
return self.current_index
|
||||
|
||||
def currentWidget(self):
|
||||
return self.tabs[self.currentIndex() - 1]
|
||||
idx = self.currentIndex()
|
||||
if idx == -1:
|
||||
return None
|
||||
return self.tabs[idx - 1]
|
||||
|
||||
def tabopen(self, url):
|
||||
self.opened_url = url
|
||||
|
@ -56,3 +56,21 @@ def test_backforward_widget(backforward_widget, stubs,
|
||||
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
|
||||
assert backforward_widget.text() == ''
|
||||
assert not backforward_widget.isVisible()
|
||||
|
||||
|
||||
def test_none_tab(backforward_widget, stubs, 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 = stubs.TabbedBrowserStub()
|
||||
tabbed_browser.current_index = 1
|
||||
tabbed_browser.tabs = [tab]
|
||||
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
|
||||
|
||||
assert backforward_widget.text() == '[<>]'
|
||||
assert backforward_widget.isVisible()
|
||||
|
||||
tabbed_browser.current_index = -1
|
||||
backforward_widget.on_tab_cur_url_changed(tabbed_browser)
|
||||
|
||||
assert backforward_widget.text() == ''
|
||||
assert not backforward_widget.isVisible()
|
||||
|
Loading…
Reference in New Issue
Block a user