browser/components/tabview/test/browser_tabview_bug650573.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:803fa506b992
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
5 let stateBackup = ss.getBrowserState();
6
7 function test() {
8 waitForExplicitFinish();
9
10 registerCleanupFunction(function () {
11 ss.setBrowserState(stateBackup);
12 });
13
14 TabView._initFrame(function() {
15 executeSoon(testRestoreNormal);
16 });
17 }
18
19 function testRestoreNormal() {
20 testRestore("normal", function () {
21 waitForBrowserState(JSON.parse(stateBackup), testRestorePinned);
22 });
23 }
24
25 function testRestorePinned() {
26 gBrowser.loadOneTab("about:blank", {inBackground: true});
27 gBrowser.pinTab(gBrowser.tabs[0]);
28
29 testRestore("pinned", function () {
30 waitForBrowserState(JSON.parse(stateBackup), testRestoreHidden);
31 });
32 }
33
34 function testRestoreHidden() {
35 let groupItem = createGroupItemWithBlankTabs(window, 20, 20, 20, 1);
36 let tabItem = groupItem.getChild(0);
37
38 hideGroupItem(groupItem, function () {
39 testRestore("hidden", function () {
40 isnot(tabItem.container.style.display, "none", "tabItem is visible");
41 waitForFocus(finish);
42 });
43 });
44 }
45
46 function testRestore(prefix, callback) {
47 waitForBrowserState(createBrowserState(), function () {
48 is(gBrowser.tabs.length, 2, prefix + ": two tabs restored");
49
50 let cw = TabView.getContentWindow();
51 is(cw.GroupItems.groupItems.length, 2, prefix + ": we have two groupItems");
52
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");
56
57 is(groupItem2.id, "2nd-group-id", prefix + ": groupItem2's ID is valid");
58 is(groupItem2.getChildren().length, 1, prefix + ": groupItem2 has one child");
59
60 callback();
61 });
62 }
63
64 function waitForBrowserState(state, callback) {
65 window.addEventListener("SSWindowStateReady", function onReady() {
66 window.removeEventListener("SSWindowStateReady", onReady, false);
67 executeSoon(callback);
68 }, false);
69
70 ss.setBrowserState(JSON.stringify(state));
71 }
72
73 function createBrowserState() {
74 let bounds = {left: 20, top: 20, width: 20, height: 20};
75
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 };
81
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 };
87
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 };
93
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