browser/components/sessionstore/test/browser_586068-multi_window.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.

     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 const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand";
     7 function test() {
     8   TestRunner.run();
     9 }
    11 function runTests() {
    12   Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false);
    13   registerCleanupFunction(function () {
    14     Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
    15   });
    17   // The first window will be put into the already open window and the second
    18   // window will be opened with _openWindowWithState, which is the source of the problem.
    19   let state = { windows: [
    20     {
    21       tabs: [
    22         { entries: [{ url: "http://example.org#0" }], extData: { "uniq": r() } }
    23       ],
    24       selected: 1
    25     },
    26     {
    27       tabs: [
    28         { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } },
    29         { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } },
    30         { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } },
    31         { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } },
    32         { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } },
    33         { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } }
    34       ],
    35       selected: 4
    36     }
    37   ] };
    38   let numTabs = state.windows[0].tabs.length + state.windows[1].tabs.length;
    40   let loadCount = 0;
    41   gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
    42     if (++loadCount == numTabs) {
    43       // We don't actually care about load order in this test, just that they all
    44       // do load.
    45       is(loadCount, numTabs, "all tabs were restored");
    46       is(aNeedRestore, 0, "there are no tabs left needing restore");
    48       gProgressListener.unsetCallback();
    49       executeSoon(next);
    50     }
    51   });
    53   // We also want to catch the 2nd window, so we need to observe domwindowopened
    54   Services.ww.registerNotification(function observer(aSubject, aTopic, aData) {
    55     if (aTopic == "domwindowopened") {
    56       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    57       win.addEventListener("load", function onLoad() {
    58         win.removeEventListener("load", onLoad);
    59         Services.ww.unregisterNotification(observer);
    60         win.gBrowser.addTabsProgressListener(gProgressListener);
    61       });
    62     }
    63   });
    65   yield ss.setBrowserState(JSON.stringify(state));
    66 }

mercurial