summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-04-01 06:15:52 +0200
committerFlorian Bruhin <git@the-compiler.org>2016-04-01 06:15:52 +0200
commit6631c6456cae10ddd10c06125a0a4a7818349019 (patch)
tree21074e3f9201d8abc36df6f7801867553ed57860
parent70fedf618a6672ad8a93cc54f624bb72d91d2995 (diff)
parentd83d2e442ed1a1e3e8b5b794506ff65d58efc16a (diff)
downloadqutebrowser-6631c6456cae10ddd10c06125a0a4a7818349019.tar.gz
qutebrowser-6631c6456cae10ddd10c06125a0a4a7818349019.zip
Merge branch 'session-tests'
-rw-r--r--qutebrowser/misc/sessions.py10
-rw-r--r--tests/integration/data/sessions/history_replace_state.html16
-rw-r--r--tests/integration/features/sessions.feature31
-rw-r--r--tests/integration/features/test_sessions.py21
4 files changed, 77 insertions, 1 deletions
diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py
index 36b23eda8..0e3670ad0 100644
--- a/qutebrowser/misc/sessions.py
+++ b/qutebrowser/misc/sessions.py
@@ -143,10 +143,18 @@ class SessionManager(QObject):
history = tab.page().history()
for idx, item in enumerate(history.items()):
qtutils.ensure_valid(item)
+
item_data = {
'url': bytes(item.url().toEncoded()).decode('ascii'),
- 'title': item.title(),
}
+
+ if not item.title():
+ # https://github.com/The-Compiler/qutebrowser/issues/879
+ if history.currentItemIndex() == idx:
+ item_data['title'] = tab.page().mainFrame().title()
+ else:
+ item_data['title'] = item_data['url']
+
if item.originalUrl() != item.url():
encoded = item.originalUrl().toEncoded()
item_data['original-url'] = bytes(encoded).decode('ascii')
diff --git a/tests/integration/data/sessions/history_replace_state.html b/tests/integration/data/sessions/history_replace_state.html
new file mode 100644
index 000000000..c221187ae
--- /dev/null
+++ b/tests/integration/data/sessions/history_replace_state.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test title</title>
+ <script type="text/javascript">
+ window.onload = function () {
+ console.log("Calling history.replaceState");
+ history.replaceState({}, '', window.location + '?state=2');
+ }
+ </script>
+ </head>
+ <body>
+ This page calls history.replaceState() via JS.
+ </body>
+</html>
diff --git a/tests/integration/features/sessions.feature b/tests/integration/features/sessions.feature
new file mode 100644
index 000000000..9815a5da1
--- /dev/null
+++ b/tests/integration/features/sessions.feature
@@ -0,0 +1,31 @@
+Feature: Saving and loading sessions
+
+ # https://github.com/The-Compiler/qutebrowser/issues/879
+
+ Scenario: Saving a session with a page using history.replaceState()
+ When I open data/sessions/history_replace_state.html
+ Then the javascript message "Calling history.replaceState" should be logged
+ And the session should look like:
+ windows:
+ - tabs:
+ - history:
+ - url: about:blank
+ - active: true
+ url: http://localhost:*/data/sessions/history_replace_state.html?state=2
+ title: Test title
+
+ Scenario: Saving a session with a page using history.replaceState() and navigating away
+ When I open data/sessions/history_replace_state.html
+ And I open data/hello.txt
+ Then the javascript message "Calling history.replaceState" should be logged
+ And the session should look like:
+ windows:
+ - tabs:
+ - history:
+ - url: about:blank
+ - url: http://localhost:*/data/sessions/history_replace_state.html?state=2
+ # What we'd *really* expect here is "Test title", but that
+ # workaround is the best we can do.
+ title: http://localhost:*/data/sessions/history_replace_state.html?state=2
+ - active: true
+ url: http://localhost:*/data/hello.txt
diff --git a/tests/integration/features/test_sessions.py b/tests/integration/features/test_sessions.py
new file mode 100644
index 000000000..0af29f414
--- /dev/null
+++ b/tests/integration/features/test_sessions.py
@@ -0,0 +1,21 @@
+# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
+
+# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+#
+# This file is part of qutebrowser.
+#
+# qutebrowser is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# qutebrowser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
+
+import pytest_bdd as bdd
+bdd.scenarios('sessions.feature')