summaryrefslogtreecommitdiff
path: root/tests/unit/completion/test_models.py
diff options
context:
space:
mode:
authorJimmy <jimmy@spalge.com>2018-09-09 20:24:14 +1200
committerJimmy <jimmy@spalge.com>2020-02-13 20:59:57 +1300
commitfb48b6c4f4b9c338b742b0b5957797a0c2084ca3 (patch)
treeceae5e52e105873f96a86fee5f39907daccdab38 /tests/unit/completion/test_models.py
parent832568af42d0e7d7d4bdc2d244c0d09e53e970c7 (diff)
downloadqutebrowser-fb48b6c4f4b9c338b742b0b5957797a0c2084ca3.tar.gz
qutebrowser-fb48b6c4f4b9c338b742b0b5957797a0c2084ca3.zip
Add {back,forward}_items to tab history API.
Also use it for the backforward completion. On webengine you can pass `-1` to `backItems()` and it'll return everything but on webkit that just crashes. So I went with a high default. Since we cannot instantiate a QWebHistory and fill it with items without triggering a page load and all the signals from that being fired I'm not sure how to do that in a unit test. I mocked out `back_items()` in the tab history API rather than `backItems()` in the backend because the AbstractHistory doesn't do anything by default.
Diffstat (limited to 'tests/unit/completion/test_models.py')
-rw-r--r--tests/unit/completion/test_models.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py
index 7c77db3f3..d8006d10a 100644
--- a/tests/unit/completion/test_models.py
+++ b/tests/unit/completion/test_models.py
@@ -1158,6 +1158,11 @@ def tab_with_history(fake_web_tab, tabbed_browser_stubs, info, monkeypatch):
"""Returns a fake tab with some fake history items."""
pytest.importorskip('PyQt5.QtWebEngineWidgets')
tab = fake_web_tab(QUrl('https://github.com'), 'GitHub', 0)
+ current_idx = 2
+ monkeypatch.setattr(
+ tab.history, 'current_idx',
+ lambda: current_idx,
+ )
history = []
for url, title in [
@@ -1173,11 +1178,21 @@ def tab_with_history(fake_web_tab, tabbed_browser_stubs, info, monkeypatch):
history.append(entry)
tab.history._history = mock.Mock(spec=QWebEngineHistory)
tab.history._history.items.return_value = history
-
monkeypatch.setattr(
- tab.history, 'current_idx',
- lambda: 2,
+ tab.history, 'back_items',
+ lambda *_args: (
+ entry for idx, entry in enumerate(tab.history._history.items())
+ if idx < current_idx
+ ),
+ )
+ monkeypatch.setattr(
+ tab.history, 'forward_items',
+ lambda *_args: (
+ entry for idx, entry in enumerate(tab.history._history.items())
+ if idx > current_idx
+ ),
)
+
tabbed_browser_stubs[0].widget.tabs = [tab]
tabbed_browser_stubs[0].widget.current_index = 0
return tab