From 1ed637a90614c3d52954146cd8ef9533dd0824e0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 6 Sep 2016 13:55:35 +0200 Subject: [PATCH] QtWebEngine: Initial session implementation --- qutebrowser/browser/webengine/webenginetab.py | 14 +++++++++++--- tests/end2end/features/backforward.feature | 1 - tests/end2end/features/conftest.py | 8 -------- tests/end2end/features/test_marks_bdd.py | 2 -- tests/end2end/features/test_sessions_bdd.py | 3 --- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/qutebrowser/browser/webengine/webenginetab.py b/qutebrowser/browser/webengine/webenginetab.py index 01ad4c406..5e48b7cf5 100644 --- a/qutebrowser/browser/webengine/webenginetab.py +++ b/qutebrowser/browser/webengine/webenginetab.py @@ -24,7 +24,7 @@ import functools -from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QPoint, QUrl +from PyQt5.QtCore import pyqtSlot, Qt, QEvent, QPoint, QUrl, QTimer from PyQt5.QtGui import QKeyEvent, QIcon # pylint: disable=no-name-in-module,import-error,useless-suppression from PyQt5.QtWidgets import QOpenGLWidget @@ -32,7 +32,7 @@ from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineScript # pylint: enable=no-name-in-module,import-error,useless-suppression from qutebrowser.browser import browsertab, mouse -from qutebrowser.browser.webengine import webview, webengineelem +from qutebrowser.browser.webengine import webview, webengineelem, tabhistory from qutebrowser.utils import usertypes, qtutils, log, javascript, utils @@ -302,7 +302,15 @@ class WebEngineHistory(browsertab.AbstractHistory): return qtutils.deserialize(data, self._history) def load_items(self, items): - log.stub() + stream, _data, cur_data = tabhistory.serialize(items) + qtutils.deserialize_stream(stream, self._history) + if cur_data is not None: + if 'zoom' in cur_data: + self._tab.zoom.set_factor(cur_data['zoom']) + if ('scroll-pos' in cur_data and + self._tab.scroller.pos_px() == QPoint(0, 0)): + QTimer.singleShot(0, functools.partial( + self._tab.scroller.to_point, cur_data['scroll-pos'])) class WebEngineZoom(browsertab.AbstractZoom): diff --git a/tests/end2end/features/backforward.feature b/tests/end2end/features/backforward.feature index 73b4bd919..d7e83da49 100644 --- a/tests/end2end/features/backforward.feature +++ b/tests/end2end/features/backforward.feature @@ -19,7 +19,6 @@ Feature: Going back and forward. - active: true url: http://localhost:*/data/backforward/2.txt - @qtwebengine_todo: FIXME why is this broken? Scenario: Going back in a new tab Given I open data/backforward/1.txt When I open data/backforward/2.txt diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index e911b14a5..62af27eaa 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -408,8 +408,6 @@ def compare_session(request, quteproc, expected): partial_compare is used, which means only the keys/values listed will be compared. """ - if request.config.webengine: - pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") quteproc.compare_session(expected) @@ -473,8 +471,6 @@ def check_open_tabs(quteproc, request, tabs): It expects a list of URLs, with an optional "(active)" suffix. """ - if request.config.webengine: - pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") session = quteproc.get_session() active_suffix = ' (active)' tabs = tabs.splitlines() @@ -530,8 +526,6 @@ def _get_scroll_values(quteproc): @bdd.then(bdd.parsers.re(r"the page should be scrolled " r"(?Phorizontally|vertically)")) def check_scrolled(request, quteproc, direction): - if request.config.webengine: - pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") x, y = _get_scroll_values(quteproc) if direction == 'horizontally': assert x != 0 @@ -543,8 +537,6 @@ def check_scrolled(request, quteproc, direction): @bdd.then("the page should not be scrolled") def check_not_scrolled(request, quteproc): - if request.config.webengine: - pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") x, y = _get_scroll_values(quteproc) assert x == 0 assert y == 0 diff --git a/tests/end2end/features/test_marks_bdd.py b/tests/end2end/features/test_marks_bdd.py index 58aec5a00..27362874b 100644 --- a/tests/end2end/features/test_marks_bdd.py +++ b/tests/end2end/features/test_marks_bdd.py @@ -24,8 +24,6 @@ bdd.scenarios('marks.feature') @bdd.then(bdd.parsers.parse("the page should be scrolled to {x} {y}")) def check_y(request, quteproc, x, y): - if request.config.webengine: - pytest.xfail(reason="QtWebEngine TODO: Sessions are not implemented") data = quteproc.get_session() pos = data['windows'][0]['tabs'][0]['history'][-1]['scroll-pos'] assert int(x) == pos['x'] diff --git a/tests/end2end/features/test_sessions_bdd.py b/tests/end2end/features/test_sessions_bdd.py index 15cf4612b..b505f9fc0 100644 --- a/tests/end2end/features/test_sessions_bdd.py +++ b/tests/end2end/features/test_sessions_bdd.py @@ -25,9 +25,6 @@ import pytest_bdd as bdd bdd.scenarios('sessions.feature') -pytestmark = pytest.mark.qtwebengine_todo("Sessions are not implemented") - - @bdd.when(bdd.parsers.parse('I have a "{name}" session file:\n{contents}')) def create_session_file(quteproc, name, contents): filename = os.path.join(quteproc.basedir, 'data', 'sessions',