Test tab completion with multiple tabbed browsers.

This commit is contained in:
Ryan Roden-Corrent 2016-06-23 08:21:55 -04:00
parent b6652ad6bc
commit 9d49f5a57d
2 changed files with 22 additions and 10 deletions

View File

@ -235,12 +235,15 @@ def session_manager_stub(stubs):
@pytest.yield_fixture
def tabbed_browser_stub(stubs):
"""Fixture which provides a fake tabbed-browser object."""
stub = stubs.TabbedBrowserStub()
objreg.register('tabbed-browser', stub, scope='window', window=0)
yield stub
def tabbed_browser_stubs(stubs, win_registry):
"""Fixture providing a fake tabbed-browser object on win_id 0 and 1."""
win_registry.add_window(1)
stubs = [stubs.TabbedBrowserStub(), stubs.TabbedBrowserStub()]
objreg.register('tabbed-browser', stubs[0], scope='window', window=0)
objreg.register('tabbed-browser', stubs[1], scope='window', window=1)
yield stubs
objreg.delete('tabbed-browser', scope='window', window=0)
objreg.delete('tabbed-browser', scope='window', window=1)
@pytest.yield_fixture

View File

@ -231,30 +231,39 @@ def test_session_completion(session_manager_stub):
def test_tab_completion(stubs, qtbot, app_stub, win_registry,
tabbed_browser_stub):
tabbed_browser_stub.tabs = [
tabbed_browser_stubs):
tabbed_browser_stubs[0].tabs = [
stubs.FakeWebView(QUrl('https://github.com'), 'GitHub', 0),
stubs.FakeWebView(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
stubs.FakeWebView(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2)
]
tabbed_browser_stubs[1].tabs = [
stubs.FakeWebView(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
]
actual = _get_completions(miscmodels.TabCompletionModel())
assert actual == [
('0', [
('0/1', 'https://github.com', 'GitHub'),
('0/2', 'https://wikipedia.org', 'Wikipedia'),
('0/3', 'https://duckduckgo.com', 'DuckDuckGo')
]),
('1', [
('1/1', 'https://wiki.archlinux.org', 'ArchWiki'),
])
]
def test_tab_completion_delete(stubs, qtbot, app_stub, win_registry,
tabbed_browser_stub):
tabbed_browser_stubs):
"""Verify closing a tab by deleting it from the completion widget."""
tabbed_browser_stub.tabs = [
tabbed_browser_stubs[0].tabs = [
stubs.FakeWebView(QUrl('https://github.com'), 'GitHub', 0),
stubs.FakeWebView(QUrl('https://wikipedia.org'), 'Wikipedia', 1),
stubs.FakeWebView(QUrl('https://duckduckgo.com'), 'DuckDuckGo', 2)
]
tabbed_browser_stubs[1].tabs = [
stubs.FakeWebView(QUrl('https://wiki.archlinux.org'), 'ArchWiki', 0),
]
model = miscmodels.TabCompletionModel()
index = Mock()
cat = Mock()
@ -265,7 +274,7 @@ def test_tab_completion_delete(stubs, qtbot, app_stub, win_registry,
cat.child = Mock(return_value=index)
completion_widget.currentIndex = Mock(return_value=index)
model.delete_cur_item(completion_widget)
actual = [tab.url() for tab in tabbed_browser_stub.tabs]
actual = [tab.url() for tab in tabbed_browser_stubs[0].tabs]
assert actual == [QUrl('https://github.com'),
QUrl('https://duckduckgo.com')]