1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test opening default mochitest-normal-private-normal-private windows
// (saving the state with last window being private)
requestLongerTimeout(2);
add_task(async function test_1() {
let win = await promiseNewWindowLoaded();
await promiseTabLoad(win, "http://www.example.com/#1");
win = await promiseNewWindowLoaded({ private: true });
await promiseTabLoad(win, "http://www.example.com/#2");
win = await promiseNewWindowLoaded();
await promiseTabLoad(win, "http://www.example.com/#3");
win = await promiseNewWindowLoaded({ private: true });
await promiseTabLoad(win, "http://www.example.com/#4");
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 5, "Browser has opened 5 windows");
is(curState.windows[2].isPrivate, true, "Window is private");
is(curState.windows[4].isPrivate, true, "Last window is private");
is(curState.selectedWindow, 5, "Last window opened is the one selected");
let state = JSON.parse(await promiseRecoveryFileContents());
is(
state.windows.length,
2,
"sessionstore state: 2 windows in data being written to disk"
);
is(
state.selectedWindow,
2,
"Selected window is updated to match one of the saved windows"
);
ok(
state.windows.every(win2 => !win2.isPrivate),
"Saved windows are not private"
);
is(
state._closedWindows.length,
0,
"sessionstore state: no closed windows in data being written to disk"
);
// Cleanup.
await promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
// Test opening default mochitest window + 2 private windows
add_task(async function test_2() {
let win = await promiseNewWindowLoaded({ private: true });
await promiseTabLoad(win, "http://www.example.com/#1");
win = await promiseNewWindowLoaded({ private: true });
await promiseTabLoad(win, "http://www.example.com/#2");
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 3, "Browser has opened 3 windows");
is(curState.windows[1].isPrivate, true, "Window 1 is private");
is(curState.windows[2].isPrivate, true, "Window 2 is private");
is(curState.selectedWindow, 3, "Last window opened is the one selected");
let state = JSON.parse(await promiseRecoveryFileContents());
is(
state.windows.length,
0,
"sessionstore state: no window in data being written to disk"
);
is(
state.selectedWindow,
0,
"Selected window updated to 0 given there are no saved windows"
);
is(
state._closedWindows.length,
0,
"sessionstore state: no closed windows in data being written to disk"
);
// Cleanup.
await promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
// Test opening default-normal-private-normal windows and closing a normal window
add_task(async function test_3() {
let normalWindow = await promiseNewWindowLoaded();
await promiseTabLoad(normalWindow, "http://www.example.com/#1");
let win = await promiseNewWindowLoaded({ private: true });
await promiseTabLoad(win, "http://www.example.com/#2");
win = await promiseNewWindowLoaded();
await promiseTabLoad(win, "http://www.example.com/#3");
let curState = JSON.parse(ss.getBrowserState());
is(curState.windows.length, 4, "Browser has opened 4 windows");
is(curState.windows[2].isPrivate, true, "Window 2 is private");
is(curState.selectedWindow, 4, "Last window opened is the one selected");
await BrowserTestUtils.closeWindow(normalWindow);
// Pin and unpin a tab before checking the written state so that
// the list of restoring windows gets cleared. Otherwise the
// window we just closed would be marked as not closed.
let tab = win.gBrowser.tabs[0];
win.gBrowser.pinTab(tab);
win.gBrowser.unpinTab(tab);
let state = JSON.parse(await promiseRecoveryFileContents());
is(
state.windows.length,
1,
"sessionstore state: 1 window in data being written to disk"
);
is(
state.selectedWindow,
1,
"Selected window is updated to match one of the saved windows"
);
ok(
state.windows.every(win2 => !win2.isPrivate),
"Saved windows are not private"
);
is(
state._closedWindows.length,
1,
"sessionstore state: 1 closed window in data being written to disk"
);
ok(
state._closedWindows.every(win2 => !win2.isPrivate),
"Closed windows are not private"
);
// Cleanup.
await promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
async function promiseTabLoad(win, url) {
let tab = BrowserTestUtils.addTab(win.gBrowser, url);
await promiseBrowserLoaded(tab.linkedBrowser);
await TabStateFlusher.flush(tab.linkedBrowser);
}
|