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 461634 **/
8 waitForExplicitFinish();
10 const REMEMBER = Date.now(), FORGET = Math.random();
11 let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [
12 { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET },
13 { state: { entries: [{ url: "http://www.example.net/" }] }, title: REMEMBER },
14 { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET },
15 { state: { entries: [{ url: "http://www.example.net/" }] }, title: REMEMBER },
16 ] }] };
17 let remember_count = 2;
19 function countByTitle(aClosedTabList, aTitle)
20 aClosedTabList.filter(function(aData) aData.title == aTitle).length;
22 function testForError(aFunction) {
23 try {
24 aFunction();
25 return false;
26 }
27 catch (ex) {
28 return ex.name == "NS_ERROR_ILLEGAL_VALUE";
29 }
30 }
32 // open a window and add the above closed tab list
33 let newWin = openDialog(location, "", "chrome,all,dialog=no");
34 newWin.addEventListener("load", function(aEvent) {
35 newWin.removeEventListener("load", arguments.callee, false);
37 gPrefService.setIntPref("browser.sessionstore.max_tabs_undo",
38 test_state.windows[0]._closedTabs.length);
39 ss.setWindowState(newWin, JSON.stringify(test_state), true);
41 let closedTabs = JSON.parse(ss.getClosedTabData(newWin));
42 is(closedTabs.length, test_state.windows[0]._closedTabs.length,
43 "Closed tab list has the expected length");
44 is(countByTitle(closedTabs, FORGET),
45 test_state.windows[0]._closedTabs.length - remember_count,
46 "The correct amout of tabs are to be forgotten");
47 is(countByTitle(closedTabs, REMEMBER), remember_count,
48 "Everything is set up.");
50 // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE
51 ok(testForError(function() ss.forgetClosedTab({}, 0)),
52 "Invalid window for forgetClosedTab throws");
53 ok(testForError(function() ss.forgetClosedTab(newWin, -1)),
54 "Invalid tab for forgetClosedTab throws");
55 ok(testForError(function() ss.forgetClosedTab(newWin, test_state.windows[0]._closedTabs.length + 1)),
56 "Invalid tab for forgetClosedTab throws");
58 // Remove third tab, then first tab
59 ss.forgetClosedTab(newWin, 2);
60 ss.forgetClosedTab(newWin, null);
62 closedTabs = JSON.parse(ss.getClosedTabData(newWin));
63 is(closedTabs.length, remember_count,
64 "The correct amout of tabs was removed");
65 is(countByTitle(closedTabs, FORGET), 0,
66 "All tabs specifically forgotten were indeed removed");
67 is(countByTitle(closedTabs, REMEMBER), remember_count,
68 "... and tabs not specifically forgetten weren't.");
70 // clean up
71 newWin.close();
72 gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
73 finish();
74 }, false);
75 }