browser/components/sessionstore/test/browser_461634.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial