diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index b46b5a26a..d18cebf32 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -457,7 +457,8 @@ class SessionManager(QObject): @cmdutils.register(instance='session-manager') @cmdutils.argument('name', completion=miscmodels.session) - def session_load(self, name, clear=False, temp=False, force=False): + def session_load(self, name, clear=False, temp=False, force=False, + delete=False): """Load a session. Args: @@ -466,6 +467,7 @@ class SessionManager(QObject): temp: Don't set the current session for :session-save. force: Force loading internal sessions (starting with an underline). + delete: Delete the saved session once it has loaded. """ if name.startswith('_') and not force: raise cmdexc.CommandError("{} is an internal session, use --force " @@ -482,6 +484,17 @@ class SessionManager(QObject): if clear: for win in old_windows: win.close() + if delete: + try: + self.delete(name) + except SessionError as e: + log.sessions.exception("Error while deleting session!") + raise cmdexc.CommandError( + "Error while deleting session: {}" + .format(e)) + else: + log.sessions.debug( + "Loaded & deleted session {}.".format(name)) @cmdutils.register(instance='session-manager') @cmdutils.argument('name', completion=miscmodels.session) diff --git a/tests/end2end/features/sessions.feature b/tests/end2end/features/sessions.feature index 50054c665..cb54e34cf 100644 --- a/tests/end2end/features/sessions.feature +++ b/tests/end2end/features/sessions.feature @@ -363,6 +363,16 @@ Feature: Saving and loading sessions And I replace "about:blank" by "http://localhost:(port)/data/numbers/2.txt" in the "loaded_session" session file And I run :session-load loaded_session Then data/numbers/2.txt should be loaded + + @qtwebengine_flaky + Scenario: Loading and deleting a session + When I open about:blank + And I run :session-save loaded_session + And I replace "about:blank" by "http://localhost:(port)/data/numbers/2.txt" in the "loaded_session" session file + And I run :session-load --delete loaded_session + And I wait for "Loaded & deleted session loaded_session." in the log + Then data/numbers/2.txt should be loaded + And the session loaded_session should not exist Scenario: Loading a session which doesn't exist When I run :session-load inexistent_session