browser/components/sessionstore/test/browser_490040.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 490040 **/
michael@0 7
michael@0 8 waitForExplicitFinish();
michael@0 9
michael@0 10 function testWithState(aState) {
michael@0 11 // Ensure we can store the window if needed.
michael@0 12 let curClosedWindowCount = ss.getClosedWindowCount();
michael@0 13 gPrefService.setIntPref("browser.sessionstore.max_windows_undo",
michael@0 14 curClosedWindowCount + 1);
michael@0 15
michael@0 16 var origWin;
michael@0 17 function windowObserver(aSubject, aTopic, aData) {
michael@0 18 let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow);
michael@0 19 if (origWin && theWin != origWin)
michael@0 20 return;
michael@0 21
michael@0 22 switch (aTopic) {
michael@0 23 case "domwindowopened":
michael@0 24 origWin = theWin;
michael@0 25 theWin.addEventListener("load", function () {
michael@0 26 theWin.removeEventListener("load", arguments.callee, false);
michael@0 27 executeSoon(function () {
michael@0 28 // Close the window as soon as the first tab loads, or
michael@0 29 // immediately if there are no tabs.
michael@0 30 if (aState.windowState.windows[0].tabs[0].entries.length) {
michael@0 31 theWin.gBrowser.addEventListener("load", function() {
michael@0 32 theWin.gBrowser.removeEventListener("load",
michael@0 33 arguments.callee, true);
michael@0 34 theWin.close();
michael@0 35 }, true);
michael@0 36 } else {
michael@0 37 executeSoon(function () {
michael@0 38 theWin.close();
michael@0 39 });
michael@0 40 }
michael@0 41 ss.setWindowState(theWin, JSON.stringify(aState.windowState),
michael@0 42 true);
michael@0 43 });
michael@0 44 }, false);
michael@0 45 break;
michael@0 46
michael@0 47 case "domwindowclosed":
michael@0 48 Services.ww.unregisterNotification(windowObserver);
michael@0 49 // Use executeSoon to ensure this happens after SS observer.
michael@0 50 executeSoon(function () {
michael@0 51 is(ss.getClosedWindowCount(),
michael@0 52 curClosedWindowCount + (aState.shouldBeAdded ? 1 : 0),
michael@0 53 "That window should " + (aState.shouldBeAdded ? "" : "not ") +
michael@0 54 "be restorable");
michael@0 55 executeSoon(runNextTest);
michael@0 56 });
michael@0 57 break;
michael@0 58 }
michael@0 59 }
michael@0 60 Services.ww.registerNotification(windowObserver);
michael@0 61 Services.ww.openWindow(null,
michael@0 62 location,
michael@0 63 "_blank",
michael@0 64 "chrome,all,dialog=no",
michael@0 65 null);
michael@0 66 }
michael@0 67
michael@0 68 // Only windows with open tabs are restorable. Windows where a lone tab is
michael@0 69 // detached may have _closedTabs, but is left with just an empty tab.
michael@0 70 let states = [
michael@0 71 {
michael@0 72 shouldBeAdded: true,
michael@0 73 windowState: {
michael@0 74 windows: [{
michael@0 75 tabs: [{ entries: [{ url: "http://example.com", title: "example.com" }] }],
michael@0 76 selected: 1,
michael@0 77 _closedTabs: []
michael@0 78 }]
michael@0 79 }
michael@0 80 },
michael@0 81 {
michael@0 82 shouldBeAdded: false,
michael@0 83 windowState: {
michael@0 84 windows: [{
michael@0 85 tabs: [{ entries: [] }],
michael@0 86 _closedTabs: []
michael@0 87 }]
michael@0 88 }
michael@0 89 },
michael@0 90 {
michael@0 91 shouldBeAdded: false,
michael@0 92 windowState: {
michael@0 93 windows: [{
michael@0 94 tabs: [{ entries: [] }],
michael@0 95 _closedTabs: [{ state: { entries: [{ url: "http://example.com", index: 1 }] } }]
michael@0 96 }]
michael@0 97 }
michael@0 98 },
michael@0 99 {
michael@0 100 shouldBeAdded: false,
michael@0 101 windowState: {
michael@0 102 windows: [{
michael@0 103 tabs: [{ entries: [] }],
michael@0 104 _closedTabs: [],
michael@0 105 extData: { keyname: "pi != " + Math.random() }
michael@0 106 }]
michael@0 107 }
michael@0 108 }
michael@0 109 ];
michael@0 110
michael@0 111 function runNextTest() {
michael@0 112 if (states.length) {
michael@0 113 let state = states.shift();
michael@0 114 testWithState(state);
michael@0 115 }
michael@0 116 else {
michael@0 117 gPrefService.clearUserPref("browser.sessionstore.max_windows_undo");
michael@0 118 finish();
michael@0 119 }
michael@0 120 }
michael@0 121 runNextTest();
michael@0 122 }
michael@0 123

mercurial