Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
# add this directory to the path
sys.path.append(os.path.dirname(__file__))
from session_store_test_case import SessionStoreTestCase
def saved_group(index):
return {
"id": f"saved-{index}",
"name": f"Group {index}",
"color": "blue",
"collapsed": False,
"tabs": [
{
"state": {
"entries": [{"url": f"about:robots?{index}"}],
"index": 1,
"groupId": f"saved-{index}",
},
"title": "robots",
"pos": 1,
"closedAt": 0,
}
],
}
class TestSavedGroupsSurviveUnusableSession(SessionStoreTestCase):
"""A session that cannot be prepared must not take the saved tab groups with it.
SessionStore replaces sessionstore.jsonlz4 on its next write, so dropping the
saved groups because the rest of the state could not be processed makes the
loss permanent.
"""
def setUp(self):
super().setUp(
startup_page=1,
include_private=False,
restore_on_demand=False,
)
def _restart_with(self, state):
self.marionette.execute_async_script(
"""
let [state, resolve] = arguments;
IOUtils.writeJSON(
PathUtils.join(PathUtils.profileDir, "saved-groups-fixture.jsonlz4"),
state,
{ compress: true }
).then(resolve);
""",
script_args=[state],
)
self.marionette.quit()
profile_dir = self.marionette.instance.profile.profile
os.replace(
os.path.join(profile_dir, "saved-groups-fixture.jsonlz4"),
os.path.join(profile_dir, "sessionstore.jsonlz4"),
)
self.marionette.start_session()
self.marionette.set_context("chrome")
def _saved_group_ids(self):
return self.marionette.execute_script(
"return SessionStore.savedGroups.map(group => group?.id ?? null)"
)
def _principal(self):
return self.marionette.execute_script(
"""
const { E10SUtils } = ChromeUtils.importESModule(
"resource://gre/modules/E10SUtils.sys.mjs"
);
return E10SUtils.SERIALIZED_SYSTEMPRINCIPAL;
"""
)
def test_saved_groups_are_kept_when_the_window_cannot_be_prepared(self):
# The window has no _closedTabs, which makes
# #prepDataForDeferredRestore() throw inside #initSession()'s try block
# before the saved groups are assigned. The tab is untouched, so the
# browser still restores a window.
state = {
"windows": [
{
"tabs": [
{
"entries": [
{
"url": "about:blank",
"triggeringPrincipal_base64": self._principal(),
}
],
"index": 1,
}
],
"selected": 1,
}
],
"savedGroups": [saved_group(i) for i in (1, 2, 3)],
}
self._restart_with(state)
self.assertEqual(
self._saved_group_ids(),
["saved-1", "saved-2", "saved-3"],
"Saved tab groups should survive a session that cannot be prepared",
)