1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_461634.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test() { 1.9 + /** Test for Bug 461634 **/ 1.10 + 1.11 + waitForExplicitFinish(); 1.12 + 1.13 + const REMEMBER = Date.now(), FORGET = Math.random(); 1.14 + let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [ 1.15 + { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, 1.16 + { state: { entries: [{ url: "http://www.example.net/" }] }, title: REMEMBER }, 1.17 + { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET }, 1.18 + { state: { entries: [{ url: "http://www.example.net/" }] }, title: REMEMBER }, 1.19 + ] }] }; 1.20 + let remember_count = 2; 1.21 + 1.22 + function countByTitle(aClosedTabList, aTitle) 1.23 + aClosedTabList.filter(function(aData) aData.title == aTitle).length; 1.24 + 1.25 + function testForError(aFunction) { 1.26 + try { 1.27 + aFunction(); 1.28 + return false; 1.29 + } 1.30 + catch (ex) { 1.31 + return ex.name == "NS_ERROR_ILLEGAL_VALUE"; 1.32 + } 1.33 + } 1.34 + 1.35 + // open a window and add the above closed tab list 1.36 + let newWin = openDialog(location, "", "chrome,all,dialog=no"); 1.37 + newWin.addEventListener("load", function(aEvent) { 1.38 + newWin.removeEventListener("load", arguments.callee, false); 1.39 + 1.40 + gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", 1.41 + test_state.windows[0]._closedTabs.length); 1.42 + ss.setWindowState(newWin, JSON.stringify(test_state), true); 1.43 + 1.44 + let closedTabs = JSON.parse(ss.getClosedTabData(newWin)); 1.45 + is(closedTabs.length, test_state.windows[0]._closedTabs.length, 1.46 + "Closed tab list has the expected length"); 1.47 + is(countByTitle(closedTabs, FORGET), 1.48 + test_state.windows[0]._closedTabs.length - remember_count, 1.49 + "The correct amout of tabs are to be forgotten"); 1.50 + is(countByTitle(closedTabs, REMEMBER), remember_count, 1.51 + "Everything is set up."); 1.52 + 1.53 + // all of the following calls with illegal arguments should throw NS_ERROR_ILLEGAL_VALUE 1.54 + ok(testForError(function() ss.forgetClosedTab({}, 0)), 1.55 + "Invalid window for forgetClosedTab throws"); 1.56 + ok(testForError(function() ss.forgetClosedTab(newWin, -1)), 1.57 + "Invalid tab for forgetClosedTab throws"); 1.58 + ok(testForError(function() ss.forgetClosedTab(newWin, test_state.windows[0]._closedTabs.length + 1)), 1.59 + "Invalid tab for forgetClosedTab throws"); 1.60 + 1.61 + // Remove third tab, then first tab 1.62 + ss.forgetClosedTab(newWin, 2); 1.63 + ss.forgetClosedTab(newWin, null); 1.64 + 1.65 + closedTabs = JSON.parse(ss.getClosedTabData(newWin)); 1.66 + is(closedTabs.length, remember_count, 1.67 + "The correct amout of tabs was removed"); 1.68 + is(countByTitle(closedTabs, FORGET), 0, 1.69 + "All tabs specifically forgotten were indeed removed"); 1.70 + is(countByTitle(closedTabs, REMEMBER), remember_count, 1.71 + "... and tabs not specifically forgetten weren't."); 1.72 + 1.73 + // clean up 1.74 + newWin.close(); 1.75 + gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo"); 1.76 + finish(); 1.77 + }, false); 1.78 +}