From 8bd6974042c809c91bc6b5973dfcb2164bdf643e Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 28 May 2017 11:07:16 +0200 Subject: [PATCH] Open a window with an empty session With general -> save-session on and only private windows open, we can easily get a session file with "windows: []" in it. If we loaded such a file, we got no windows at all when qutebrowser started. Fixes #2664 --- qutebrowser/misc/sessions.py | 5 ++++- tests/end2end/test_invocations.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index 7932d8456..aa9a1be97 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -390,6 +390,7 @@ class SessionManager(QObject): data = yaml.load(f, Loader=YamlLoader) except (OSError, UnicodeDecodeError, yaml.YAMLError) as e: raise SessionError(e) + log.sessions.debug("Loading session {} from {}...".format(name, path)) for win in data['windows']: window = mainwindow.MainWindow(geometry=win['geometry'], @@ -410,7 +411,9 @@ class SessionManager(QObject): tabbed_browser.setCurrentIndex(tab_to_focus) if win.get('active', False): QTimer.singleShot(0, tabbed_browser.activateWindow) - self.did_load = True + + if data['windows']: + self.did_load = True if not name.startswith('_') and not temp: self._current = name diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index f048849cb..9db39b55a 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -285,3 +285,22 @@ def test_initial_private_browsing(request, quteproc_new): quteproc_new.send_cmd(':quit') quteproc_new.wait_for_quit() + + +def test_loading_empty_session(tmpdir, request, quteproc_new): + """Make sure loading an empty session opens a window.""" + session = tmpdir / 'session.yml' + session.write('windows: []') + + args = _base_args(request.config) + ['--temp-basedir', '-r', str(session)] + quteproc_new.start(args) + + quteproc_new.compare_session(""" + windows: + - tabs: + - history: + - url: about:blank + """) + + quteproc_new.send_cmd(':quit') + quteproc_new.wait_for_quit()