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

mercurial