Skip to content

Commit c619ad7

Browse files
Bug 1863692 - Only transfer window attributes for pinned tabs with deferred sessions r=sessionstore-reviewers,dao
* add new marionette test Differential Revision: https://phabricator.services.mozilla.com/D195006
1 parent 39b4454 commit c619ad7

File tree

3 files changed

+137
-9
lines changed

3 files changed

+137
-9
lines changed

browser/components/sessionstore/SessionStore.sys.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6560,20 +6560,16 @@ var SessionStoreInternal = {
65606560

65616561
hasPinnedTabs ||= !!newWindowState.tabs.length;
65626562

6563-
// At this point the window in the state object has been modified (or not)
6564-
// We want to build the rest of this new window object if we have pinnedTabs.
6565-
if (
6566-
newWindowState.tabs.length ||
6567-
(PERSIST_SESSIONS && newWindowState._closedTabs.length)
6568-
) {
6569-
// First get the other attributes off the window
6563+
// Only transfer over window attributes for pinned tabs, which has
6564+
// already been extracted into newWindowState.tabs.
6565+
if (newWindowState.tabs.length) {
65706566
WINDOW_ATTRIBUTES.forEach(function (attr) {
65716567
if (attr in window) {
65726568
newWindowState[attr] = window[attr];
65736569
delete window[attr];
65746570
}
65756571
});
6576-
// We're just copying position data into the pinned window.
6572+
// We're just copying position data into the window for pinned tabs.
65776573
// Not copying over:
65786574
// - extData
65796575
// - isPopup
@@ -6583,8 +6579,14 @@ var SessionStoreInternal = {
65836579
// remaining data
65846580
window.__lastSessionWindowID = newWindowState.__lastSessionWindowID =
65856581
"" + Date.now() + Math.random();
6582+
}
65866583

6587-
// Actually add this window to our defaultState
6584+
// If this newWindowState contains pinned tabs (stored in tabs) or
6585+
// closed tabs, add it to the defaultState so they're available immediately.
6586+
if (
6587+
newWindowState.tabs.length ||
6588+
(PERSIST_SESSIONS && newWindowState._closedTabs.length)
6589+
) {
65886590
defaultState.windows.push(newWindowState);
65896591
// Remove the window from the state if it doesn't have any tabs
65906592
if (!window.tabs.length) {

browser/components/sessionstore/test/marionette/manifest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tags = local
33

44
[test_persist_closed_tabs_restore_manually.py]
55
[test_restore_loading_tab.py]
6+
[test_restore_manually.py]
67
[test_restore_manually_with_pinned_tabs.py]
78
[test_restore_windows_after_restart_and_quit.py]
89
[test_restore_windows_after_windows_shutdown.py]
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
import os
6+
import sys
7+
8+
# add this directory to the path
9+
sys.path.append(os.path.dirname(__file__))
10+
11+
from session_store_test_case import SessionStoreTestCase
12+
13+
14+
def inline(title):
15+
return "data:text/html;charset=utf-8,<html><head><title>{}</title></head><body></body></html>".format(
16+
title
17+
)
18+
19+
20+
class TestSessionRestoreManually(SessionStoreTestCase):
21+
"""
22+
Test that window attributes for each window are restored
23+
correctly (with manual session restore) in a new session.
24+
"""
25+
26+
def setUp(self):
27+
super(TestSessionRestoreManually, self).setUp(
28+
startup_page=1,
29+
include_private=False,
30+
restore_on_demand=True,
31+
test_windows=set(
32+
[
33+
# Window 1
34+
(
35+
inline("lorem ipsom"),
36+
inline("dolor"),
37+
),
38+
# Window 2
39+
(inline("sit"),),
40+
]
41+
),
42+
)
43+
44+
def test_restore(self):
45+
self.marionette.execute_script(
46+
"""
47+
Services.prefs.setBoolPref("browser.sessionstore.persist_closed_tabs_between_sessions", true);
48+
"""
49+
)
50+
51+
self.wait_for_windows(
52+
self.all_windows, "Not all requested windows have been opened"
53+
)
54+
55+
self.assertEqual(
56+
len(self.marionette.chrome_window_handles),
57+
2,
58+
msg="Should have 3 windows open.",
59+
)
60+
self.marionette.execute_script(
61+
"""
62+
const lazy = {};
63+
ChromeUtils.defineESModuleGetters(lazy, {
64+
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
65+
});
66+
function getAllBrowserWindows() {
67+
return Array.from(Services.wm.getEnumerator("navigator:browser"));
68+
}
69+
let windows = getAllBrowserWindows();
70+
windows[1].resizeTo(500, 500)
71+
"""
72+
)
73+
74+
self.marionette.quit()
75+
self.marionette.start_session()
76+
self.marionette.set_context("chrome")
77+
78+
# restore the previous session
79+
self.marionette.execute_script(
80+
"""
81+
const lazy = {};
82+
ChromeUtils.defineESModuleGetters(lazy, {
83+
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
84+
});
85+
function observeClosedObjectsChange() {
86+
return new Promise(resolve => {
87+
function observe(subject, topic, data) {
88+
if (topic == "sessionstore-closed-objects-changed") {
89+
Services.obs.removeObserver(this, "sessionstore-closed-objects-changed");
90+
resolve('observed closed objects changed');
91+
};
92+
}
93+
Services.obs.addObserver(observe, "sessionstore-closed-objects-changed");
94+
});
95+
};
96+
97+
async function checkForWindowHeight() {
98+
let closedWindowsObserver = observeClosedObjectsChange();
99+
lazy.SessionStore.restoreLastSession();
100+
await closedWindowsObserver;
101+
}
102+
checkForWindowHeight();
103+
"""
104+
)
105+
106+
self.assertEqual(
107+
len(self.marionette.chrome_window_handles),
108+
2,
109+
msg="Windows from last session have been restored.",
110+
)
111+
112+
self.assertEqual(
113+
self.marionette.execute_script(
114+
"""
115+
const lazy = {};
116+
ChromeUtils.defineESModuleGetters(lazy, {
117+
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
118+
});
119+
let state = SessionStore.getCurrentState()
120+
return state.windows[1]["height"]
121+
"""
122+
),
123+
500,
124+
"Second window has been restored to the correct height.",
125+
)

0 commit comments

Comments
 (0)