Skip to content

Commit a7e4b96

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 3b643c8 commit a7e4b96

File tree

3 files changed

+145
-9
lines changed

3 files changed

+145
-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: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
(
40+
inline("sit"),
41+
)
42+
]
43+
),
44+
)
45+
46+
def test_restore(self):
47+
self.marionette.execute_script(
48+
"""
49+
Services.prefs.setBoolPref("browser.sessionstore.persist_closed_tabs_between_sessions", true);
50+
"""
51+
)
52+
53+
self.wait_for_windows(
54+
self.all_windows, "Not all requested windows have been opened"
55+
)
56+
57+
self.assertEqual(
58+
len(self.marionette.chrome_window_handles),
59+
2,
60+
msg="Should have 3 windows open.",
61+
)
62+
self.assertEqual(
63+
self.marionette.execute_script(
64+
"""
65+
const lazy = {};
66+
ChromeUtils.defineESModuleGetters(lazy, {
67+
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
68+
});
69+
function getAllBrowserWindows() {
70+
return Array.from(Services.wm.getEnumerator("navigator:browser"));
71+
}
72+
let windows = getAllBrowserWindows();
73+
windows[1].resizeTo(500, 500)
74+
return windows[1].document.documentElement.getAttribute("height")
75+
"""
76+
),
77+
"500",
78+
"Window has been set to correct height"
79+
)
80+
81+
self.marionette.quit()
82+
self.marionette.start_session()
83+
self.marionette.set_context("chrome")
84+
85+
86+
# restore the previous session
87+
self.marionette.execute_script(
88+
"""
89+
const lazy = {};
90+
ChromeUtils.defineESModuleGetters(lazy, {
91+
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
92+
});
93+
function observeClosedObjectsChange() {
94+
return new Promise(resolve => {
95+
function observe(subject, topic, data) {
96+
if (topic == "sessionstore-closed-objects-changed") {
97+
Services.obs.removeObserver(this, "sessionstore-closed-objects-changed");
98+
resolve('observed closed objects changed');
99+
};
100+
}
101+
Services.obs.addObserver(observe, "sessionstore-closed-objects-changed");
102+
});
103+
};
104+
105+
async function checkForWindowHeight() {
106+
let closedWindowsObserver = observeClosedObjectsChange();
107+
lazy.SessionStore.restoreLastSession();
108+
await closedWindowsObserver;
109+
}
110+
checkForWindowHeight();
111+
"""
112+
)
113+
114+
self.assertEqual(
115+
len(self.marionette.chrome_window_handles),
116+
2,
117+
msg="Windows from last session have been restored.",
118+
)
119+
120+
self.assertEqual(
121+
self.marionette.execute_script(
122+
"""
123+
const lazy = {};
124+
ChromeUtils.defineESModuleGetters(lazy, {
125+
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
126+
});
127+
let state = SessionStore.getCurrentState()
128+
return state.windows[1]["height"]
129+
"""
130+
),
131+
500,
132+
"Second window has correct height"
133+
)

0 commit comments

Comments
 (0)