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
|
/* 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(function* test_1() {
let win = yield promiseNewWindowLoaded();
win.gBrowser.addTab("http://www.example.com/1");
win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("http://www.example.com/2");
win = yield promiseNewWindowLoaded();
win.gBrowser.addTab("http://www.example.com/3");
win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("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(yield promiseRecoveryFileContents());
is(state.windows.length, 3,
"sessionstore state: 3 windows in data being written to disk");
is(state.selectedWindow, 3,
"Selected window is updated to match one of the saved windows");
ok(state.windows.every(win => !win.isPrivate),
"Saved windows are not private");
is(state._closedWindows.length, 0,
"sessionstore state: no closed windows in data being written to disk");
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
// Test opening default mochitest window + 2 private windows
add_task(function* test_2() {
let win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("http://www.example.com/1");
win = yield promiseNewWindowLoaded({private: true});
win.gBrowser.addTab("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(yield promiseRecoveryFileContents());
is(state.windows.length, 1,
"sessionstore state: 1 windows in data being written to disk");
is(state.selectedWindow, 1,
"Selected window is updated to match one of the saved windows");
is(state._closedWindows.length, 0,
"sessionstore state: no closed windows in data being written to disk");
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
// Test opening default-normal-private-normal windows and closing a normal window
add_task(function* test_3() {
let normalWindow = yield promiseNewWindowLoaded();
yield promiseTabLoad(normalWindow, "http://www.example.com/");
let win = yield promiseNewWindowLoaded({private: true});
yield promiseTabLoad(win, "http://www.example.com/");
win = yield promiseNewWindowLoaded();
yield promiseTabLoad(win, "http://www.example.com/");
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");
yield 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(yield 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(win => !win.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(win => !win.isPrivate),
"Closed windows are not private");
// Cleanup.
yield promiseAllButPrimaryWindowClosed();
forgetClosedWindows();
});
function* promiseTabLoad(win, url) {
let browser = win.gBrowser.selectedBrowser;
browser.loadURI(url);
yield promiseBrowserLoaded(browser);
yield TabStateFlusher.flush(browser);
}
|