browser/components/sessionstore/test/browser_586068-select.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, true);
    13   registerCleanupFunction(function () {
    14     Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
    15   });
    17   let state = { windows: [{ tabs: [
    18     { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
    19     { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
    20     { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
    21     { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
    22     { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
    23     { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }
    24   ], selected: 1 }] };
    26   let expectedCounts = [
    27     [5, 1, 0],
    28     [4, 1, 1],
    29     [3, 1, 2],
    30     [2, 1, 3],
    31     [1, 1, 4],
    32     [0, 1, 5]
    33   ];
    34   let tabOrder = [0, 5, 1, 4, 3, 2];
    36   let loadCount = 0;
    37   gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
    38     loadCount++;
    39     let expected = expectedCounts[loadCount - 1];
    41     is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
    42     is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
    43     is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
    45     if (loadCount < state.windows[0].tabs.length) {
    46       // double check that this tab was the right one
    47       let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq;
    48       let tab;
    49       for (let i = 0; i < window.gBrowser.tabs.length; i++) {
    50         if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
    51           tab = window.gBrowser.tabs[i];
    52       }
    54       is(ss.getTabValue(tab, "uniq"), expectedData,
    55         "load " + loadCount + " - correct tab was restored");
    57       // select the next tab
    58       window.gBrowser.selectTabAtIndex(tabOrder[loadCount]);
    59     } else {
    60       gProgressListener.unsetCallback();
    61       executeSoon(next);
    62     }
    63   });
    65   yield ss.setBrowserState(JSON.stringify(state));
    66 }

mercurial