Add a test for a None currentWidget with backforward widget

This commit is contained in:
Florian Bruhin 2017-07-10 08:00:09 +02:00
parent 5fb6cb713b
commit e81dcccace
3 changed files with 25 additions and 2 deletions

View File

@ -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():

View File

@ -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

View File

@ -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()