browser/components/tabview/test/browser_tabview_bug650573.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
     5 let stateBackup = ss.getBrowserState();
     7 function test() {
     8   waitForExplicitFinish();
    10   registerCleanupFunction(function () {
    11     ss.setBrowserState(stateBackup);
    12   });
    14   TabView._initFrame(function() {
    15     executeSoon(testRestoreNormal);
    16   });
    17 }
    19 function testRestoreNormal() {
    20   testRestore("normal", function () {
    21     waitForBrowserState(JSON.parse(stateBackup), testRestorePinned);
    22   });
    23 }
    25 function testRestorePinned() {
    26   gBrowser.loadOneTab("about:blank", {inBackground: true});
    27   gBrowser.pinTab(gBrowser.tabs[0]);
    29   testRestore("pinned", function () {
    30     waitForBrowserState(JSON.parse(stateBackup), testRestoreHidden);
    31   });
    32 }
    34 function testRestoreHidden() {
    35   let groupItem = createGroupItemWithBlankTabs(window, 20, 20, 20, 1);
    36   let tabItem = groupItem.getChild(0);
    38   hideGroupItem(groupItem, function () {
    39     testRestore("hidden", function () {
    40       isnot(tabItem.container.style.display, "none", "tabItem is visible");
    41       waitForFocus(finish);
    42     });
    43   });
    44 }
    46 function testRestore(prefix, callback) {
    47   waitForBrowserState(createBrowserState(), function () {
    48     is(gBrowser.tabs.length, 2, prefix + ": two tabs restored");
    50     let cw = TabView.getContentWindow();
    51     is(cw.GroupItems.groupItems.length, 2, prefix + ": we have two groupItems");
    53     let [groupItem1, groupItem2] = cw.GroupItems.groupItems;
    54     is(groupItem1.id, "1st-group-id", prefix + ": groupItem1's ID is valid");
    55     is(groupItem1.getChildren().length, 1, prefix + ": groupItem1 has one child");
    57     is(groupItem2.id, "2nd-group-id", prefix + ": groupItem2's ID is valid");
    58     is(groupItem2.getChildren().length, 1, prefix + ": groupItem2 has one child");
    60     callback();
    61   });
    62 }
    64 function waitForBrowserState(state, callback) {
    65   window.addEventListener("SSWindowStateReady", function onReady() {
    66     window.removeEventListener("SSWindowStateReady", onReady, false);
    67     executeSoon(callback);
    68   }, false);
    70   ss.setBrowserState(JSON.stringify(state));
    71 }
    73 function createBrowserState() {
    74   let bounds = {left: 20, top: 20, width: 20, height: 20};
    76   let tabViewGroups = {nextID: 99, activeGroupId: 1};
    77   let tabViewGroup = {
    78     "1st-group-id": {bounds: bounds, title: "new group 1", id: "1st-group-id"},
    79     "2nd-group-id": {bounds: bounds, title: "new group 2", id: "2nd-group-id"}
    80   };
    82   let tab1Data = {bounds: bounds, url: "about:rights", groupID: "2nd-group-id"};
    83   let tab1 = {
    84     entries: [{url: "about:rights"}],
    85     extData: {"tabview-tab": JSON.stringify(tab1Data)}
    86   };
    88   let tab2Data = {bounds: bounds, url: "about:mozilla", groupID: "1st-group-id"};
    89   let tab2 = {
    90     entries: [{url: "about:mozilla"}],
    91     extData: {"tabview-tab": JSON.stringify(tab2Data)}
    92   };
    94   return {windows: [{
    95     tabs: [tab1, tab2],
    96     selected: 1,
    97     extData: {"tabview-groups": JSON.stringify(tabViewGroups),
    98     "tabview-group": JSON.stringify(tabViewGroup)}
    99   }]};
   100 }

mercurial