michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); michael@0: let stateBackup = ss.getBrowserState(); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: registerCleanupFunction(function () { michael@0: ss.setBrowserState(stateBackup); michael@0: }); michael@0: michael@0: TabView._initFrame(function() { michael@0: executeSoon(testRestoreNormal); michael@0: }); michael@0: } michael@0: michael@0: function testRestoreNormal() { michael@0: testRestore("normal", function () { michael@0: waitForBrowserState(JSON.parse(stateBackup), testRestorePinned); michael@0: }); michael@0: } michael@0: michael@0: function testRestorePinned() { michael@0: gBrowser.loadOneTab("about:blank", {inBackground: true}); michael@0: gBrowser.pinTab(gBrowser.tabs[0]); michael@0: michael@0: testRestore("pinned", function () { michael@0: waitForBrowserState(JSON.parse(stateBackup), testRestoreHidden); michael@0: }); michael@0: } michael@0: michael@0: function testRestoreHidden() { michael@0: let groupItem = createGroupItemWithBlankTabs(window, 20, 20, 20, 1); michael@0: let tabItem = groupItem.getChild(0); michael@0: michael@0: hideGroupItem(groupItem, function () { michael@0: testRestore("hidden", function () { michael@0: isnot(tabItem.container.style.display, "none", "tabItem is visible"); michael@0: waitForFocus(finish); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function testRestore(prefix, callback) { michael@0: waitForBrowserState(createBrowserState(), function () { michael@0: is(gBrowser.tabs.length, 2, prefix + ": two tabs restored"); michael@0: michael@0: let cw = TabView.getContentWindow(); michael@0: is(cw.GroupItems.groupItems.length, 2, prefix + ": we have two groupItems"); michael@0: michael@0: let [groupItem1, groupItem2] = cw.GroupItems.groupItems; michael@0: is(groupItem1.id, "1st-group-id", prefix + ": groupItem1's ID is valid"); michael@0: is(groupItem1.getChildren().length, 1, prefix + ": groupItem1 has one child"); michael@0: michael@0: is(groupItem2.id, "2nd-group-id", prefix + ": groupItem2's ID is valid"); michael@0: is(groupItem2.getChildren().length, 1, prefix + ": groupItem2 has one child"); michael@0: michael@0: callback(); michael@0: }); michael@0: } michael@0: michael@0: function waitForBrowserState(state, callback) { michael@0: window.addEventListener("SSWindowStateReady", function onReady() { michael@0: window.removeEventListener("SSWindowStateReady", onReady, false); michael@0: executeSoon(callback); michael@0: }, false); michael@0: michael@0: ss.setBrowserState(JSON.stringify(state)); michael@0: } michael@0: michael@0: function createBrowserState() { michael@0: let bounds = {left: 20, top: 20, width: 20, height: 20}; michael@0: michael@0: let tabViewGroups = {nextID: 99, activeGroupId: 1}; michael@0: let tabViewGroup = { michael@0: "1st-group-id": {bounds: bounds, title: "new group 1", id: "1st-group-id"}, michael@0: "2nd-group-id": {bounds: bounds, title: "new group 2", id: "2nd-group-id"} michael@0: }; michael@0: michael@0: let tab1Data = {bounds: bounds, url: "about:rights", groupID: "2nd-group-id"}; michael@0: let tab1 = { michael@0: entries: [{url: "about:rights"}], michael@0: extData: {"tabview-tab": JSON.stringify(tab1Data)} michael@0: }; michael@0: michael@0: let tab2Data = {bounds: bounds, url: "about:mozilla", groupID: "1st-group-id"}; michael@0: let tab2 = { michael@0: entries: [{url: "about:mozilla"}], michael@0: extData: {"tabview-tab": JSON.stringify(tab2Data)} michael@0: }; michael@0: michael@0: return {windows: [{ michael@0: tabs: [tab1, tab2], michael@0: selected: 1, michael@0: extData: {"tabview-groups": JSON.stringify(tabViewGroups), michael@0: "tabview-group": JSON.stringify(tabViewGroup)} michael@0: }]}; michael@0: }