Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
5 function test() {
6 /** Test for Bug 491577 **/
8 // test setup
9 waitForExplicitFinish();
11 const REMEMBER = Date.now(), FORGET = Math.random();
12 let test_state = {
13 windows: [ { tabs: [{ entries: [{ url: "http://example.com/" }] }], selected: 1 } ],
14 _closedWindows : [
15 // _closedWindows[0]
16 {
17 tabs: [
18 { entries: [{ url: "http://example.com/", title: "title" }] },
19 { entries: [{ url: "http://mozilla.org/", title: "title" }] }
20 ],
21 selected: 2,
22 title: FORGET,
23 _closedTabs: []
24 },
25 // _closedWindows[1]
26 {
27 tabs: [
28 { entries: [{ url: "http://mozilla.org/", title: "title" }] },
29 { entries: [{ url: "http://example.com/", title: "title" }] },
30 { entries: [{ url: "http://mozilla.org/", title: "title" }] },
31 ],
32 selected: 3,
33 title: REMEMBER,
34 _closedTabs: []
35 },
36 // _closedWindows[2]
37 {
38 tabs: [
39 { entries: [{ url: "http://example.com/", title: "title" }] }
40 ],
41 selected: 1,
42 title: FORGET,
43 _closedTabs: [
44 {
45 state: {
46 entries: [
47 { url: "http://mozilla.org/", title: "title" },
48 { url: "http://mozilla.org/again", title: "title" }
49 ]
50 },
51 pos: 1,
52 title: "title"
53 },
54 {
55 state: {
56 entries: [
57 { url: "http://example.com", title: "title" }
58 ]
59 },
60 title: "title"
61 }
62 ]
63 }
64 ]
65 };
66 let remember_count = 1;
68 function countByTitle(aClosedWindowList, aTitle)
69 aClosedWindowList.filter(function(aData) aData.title == aTitle).length;
71 function testForError(aFunction) {
72 try {
73 aFunction();
74 return false;
75 }
76 catch (ex) {
77 return ex.name == "NS_ERROR_ILLEGAL_VALUE";
78 }
79 }
81 // open a window and add the above closed window list
82 let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");
83 newWin.addEventListener("load", function(aEvent) {
84 this.removeEventListener("load", arguments.callee, false);
85 gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
86 test_state._closedWindows.length);
87 ss.setWindowState(newWin, JSON.stringify(test_state), true);
89 let closedWindows = JSON.parse(ss.getClosedWindowData());
90 is(closedWindows.length, test_state._closedWindows.length,
91 "Closed window list has the expected length");
92 is(countByTitle(closedWindows, FORGET),
93 test_state._closedWindows.length - remember_count,
94 "The correct amount of windows are to be forgotten");
95 is(countByTitle(closedWindows, REMEMBER), remember_count,
96 "Everything is set up.");
98 // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE
99 ok(testForError(function() ss.forgetClosedWindow(-1)),
100 "Invalid window for forgetClosedWindow throws");
101 ok(testForError(function() ss.forgetClosedWindow(test_state._closedWindows.length + 1)),
102 "Invalid window for forgetClosedWindow throws");
104 // Remove third window, then first window
105 ss.forgetClosedWindow(2);
106 ss.forgetClosedWindow(null);
108 closedWindows = JSON.parse(ss.getClosedWindowData());
109 is(closedWindows.length, remember_count,
110 "The correct amount of windows were removed");
111 is(countByTitle(closedWindows, FORGET), 0,
112 "All windows specifically forgotten were indeed removed");
113 is(countByTitle(closedWindows, REMEMBER), remember_count,
114 "... and windows not specifically forgetten weren't.");
116 // clean up
117 newWin.close();
118 gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
119 finish();
120 }, false);
121 }