1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug650573.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); 1.8 +let stateBackup = ss.getBrowserState(); 1.9 + 1.10 +function test() { 1.11 + waitForExplicitFinish(); 1.12 + 1.13 + registerCleanupFunction(function () { 1.14 + ss.setBrowserState(stateBackup); 1.15 + }); 1.16 + 1.17 + TabView._initFrame(function() { 1.18 + executeSoon(testRestoreNormal); 1.19 + }); 1.20 +} 1.21 + 1.22 +function testRestoreNormal() { 1.23 + testRestore("normal", function () { 1.24 + waitForBrowserState(JSON.parse(stateBackup), testRestorePinned); 1.25 + }); 1.26 +} 1.27 + 1.28 +function testRestorePinned() { 1.29 + gBrowser.loadOneTab("about:blank", {inBackground: true}); 1.30 + gBrowser.pinTab(gBrowser.tabs[0]); 1.31 + 1.32 + testRestore("pinned", function () { 1.33 + waitForBrowserState(JSON.parse(stateBackup), testRestoreHidden); 1.34 + }); 1.35 +} 1.36 + 1.37 +function testRestoreHidden() { 1.38 + let groupItem = createGroupItemWithBlankTabs(window, 20, 20, 20, 1); 1.39 + let tabItem = groupItem.getChild(0); 1.40 + 1.41 + hideGroupItem(groupItem, function () { 1.42 + testRestore("hidden", function () { 1.43 + isnot(tabItem.container.style.display, "none", "tabItem is visible"); 1.44 + waitForFocus(finish); 1.45 + }); 1.46 + }); 1.47 +} 1.48 + 1.49 +function testRestore(prefix, callback) { 1.50 + waitForBrowserState(createBrowserState(), function () { 1.51 + is(gBrowser.tabs.length, 2, prefix + ": two tabs restored"); 1.52 + 1.53 + let cw = TabView.getContentWindow(); 1.54 + is(cw.GroupItems.groupItems.length, 2, prefix + ": we have two groupItems"); 1.55 + 1.56 + let [groupItem1, groupItem2] = cw.GroupItems.groupItems; 1.57 + is(groupItem1.id, "1st-group-id", prefix + ": groupItem1's ID is valid"); 1.58 + is(groupItem1.getChildren().length, 1, prefix + ": groupItem1 has one child"); 1.59 + 1.60 + is(groupItem2.id, "2nd-group-id", prefix + ": groupItem2's ID is valid"); 1.61 + is(groupItem2.getChildren().length, 1, prefix + ": groupItem2 has one child"); 1.62 + 1.63 + callback(); 1.64 + }); 1.65 +} 1.66 + 1.67 +function waitForBrowserState(state, callback) { 1.68 + window.addEventListener("SSWindowStateReady", function onReady() { 1.69 + window.removeEventListener("SSWindowStateReady", onReady, false); 1.70 + executeSoon(callback); 1.71 + }, false); 1.72 + 1.73 + ss.setBrowserState(JSON.stringify(state)); 1.74 +} 1.75 + 1.76 +function createBrowserState() { 1.77 + let bounds = {left: 20, top: 20, width: 20, height: 20}; 1.78 + 1.79 + let tabViewGroups = {nextID: 99, activeGroupId: 1}; 1.80 + let tabViewGroup = { 1.81 + "1st-group-id": {bounds: bounds, title: "new group 1", id: "1st-group-id"}, 1.82 + "2nd-group-id": {bounds: bounds, title: "new group 2", id: "2nd-group-id"} 1.83 + }; 1.84 + 1.85 + let tab1Data = {bounds: bounds, url: "about:rights", groupID: "2nd-group-id"}; 1.86 + let tab1 = { 1.87 + entries: [{url: "about:rights"}], 1.88 + extData: {"tabview-tab": JSON.stringify(tab1Data)} 1.89 + }; 1.90 + 1.91 + let tab2Data = {bounds: bounds, url: "about:mozilla", groupID: "1st-group-id"}; 1.92 + let tab2 = { 1.93 + entries: [{url: "about:mozilla"}], 1.94 + extData: {"tabview-tab": JSON.stringify(tab2Data)} 1.95 + }; 1.96 + 1.97 + return {windows: [{ 1.98 + tabs: [tab1, tab2], 1.99 + selected: 1, 1.100 + extData: {"tabview-groups": JSON.stringify(tabViewGroups), 1.101 + "tabview-group": JSON.stringify(tabViewGroup)} 1.102 + }]}; 1.103 +}