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
|
"use strict";
add_setup(async function() {
await SpecialPowers.pushPrefEnv({
set: [["dom.ipc.processCount", 1]],
});
});
add_task(async function() {
/** Test for Bug 350525 **/
function test(aLambda) {
try {
return aLambda() || true;
} catch (ex) {}
return false;
}
/**
* setCustomWindowValue, et al.
*/
let key = "Unique name: " + Date.now();
let value = "Unique value: " + Math.random();
// test adding
ok(
test(() => ss.setCustomWindowValue(window, key, value)),
"set a window value"
);
// test retrieving
is(
ss.getCustomWindowValue(window, key),
value,
"stored window value matches original"
);
// test deleting
ok(
test(() => ss.deleteCustomWindowValue(window, key)),
"delete the window value"
);
// value should not exist post-delete
is(ss.getCustomWindowValue(window, key), "", "window value was deleted");
// test deleting a non-existent value
ok(
test(() => ss.deleteCustomWindowValue(window, key)),
"delete non-existent window value"
);
/**
* setCustomTabValue, et al.
*/
key = "Unique name: " + Math.random();
value = "Unique value: " + Date.now();
let tab = BrowserTestUtils.addTab(gBrowser);
tab.linkedBrowser.stop();
// test adding
ok(
test(() => ss.setCustomTabValue(tab, key, value)),
"store a tab value"
);
// test retrieving
is(ss.getCustomTabValue(tab, key), value, "stored tab value match original");
// test deleting
ok(
test(() => ss.deleteCustomTabValue(tab, key)),
"delete the tab value"
);
// value should not exist post-delete
is(ss.getCustomTabValue(tab, key), "", "tab value was deleted");
// test deleting a non-existent value
ok(
test(() => ss.deleteCustomTabValue(tab, key)),
"delete non-existent tab value"
);
// clean up
await promiseRemoveTabAndSessionState(tab);
/**
* getClosedTabCount, undoCloseTab
*/
// get closed tab count
let count = ss.getClosedTabCount(window);
let max_tabs_undo = Services.prefs.getIntPref(
"browser.sessionstore.max_tabs_undo"
);
ok(
0 <= count && count <= max_tabs_undo,
"getClosedTabCount returns zero or at most max_tabs_undo"
);
// create a new tab
let testURL = "about:mozilla";
tab = BrowserTestUtils.addTab(gBrowser, testURL);
await promiseBrowserLoaded(tab.linkedBrowser);
// make sure that the next closed tab will increase getClosedTabCount
Services.prefs.setIntPref(
"browser.sessionstore.max_tabs_undo",
max_tabs_undo + 1
);
registerCleanupFunction(() =>
Services.prefs.clearUserPref("browser.sessionstore.max_tabs_undo")
);
// remove tab
await promiseRemoveTabAndSessionState(tab);
// getClosedTabCount
let newcount = ss.getClosedTabCount(window);
ok(
newcount > count,
"after closing a tab, getClosedTabCount has been incremented"
);
// undoCloseTab
tab = test(() => ss.undoCloseTab(window, 0));
ok(tab, "undoCloseTab doesn't throw");
await promiseTabRestored(tab);
is(tab.linkedBrowser.currentURI.spec, testURL, "correct tab was reopened");
// clean up
gBrowser.removeTab(tab);
});
|