browser/components/tabview/test/browser_tabview_expander.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:3d0f740db49a
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 function test() {
5 waitForExplicitFinish();
6 requestLongerTimeout(2);
7 newWindowWithTabView(onTabViewWindowLoaded);
8 }
9
10 function onTabViewWindowLoaded(win) {
11 ok(win.TabView.isVisible(), "Tab View is visible");
12
13 let contentWindow = win.document.getElementById("tab-view").contentWindow;
14 let [originalTab] = win.gBrowser.visibleTabs;
15 let currentGroup = contentWindow.GroupItems.getActiveGroupItem();
16
17 // let's create a group small enough to get stacked
18 let group = new contentWindow.GroupItem([], {
19 immediately: true,
20 bounds: {left: 20, top: 300, width: 400, height: 400}
21 });
22
23 let expander = contentWindow.iQ(group.container).find(".stackExpander");
24 ok("length" in expander && expander.length == 1, "The group has an expander.");
25
26 // procreate!
27 contentWindow.UI.setActive(group);
28 for (var i=0; i<7; i++) {
29 win.gBrowser.loadOneTab('http://example.com#' + i, {inBackground: true});
30 }
31 let children = group.getChildren();
32
33 // Wait until they all update because, once updated, they will notice that they
34 // don't have favicons and this will change their styling at some unknown time.
35 afterAllTabItemsUpdated(function() {
36 ok(!group.shouldStack(group._children.length), "The group should not stack.");
37 is(expander[0].style.display, "none", "The expander is hidden.");
38
39 // now resize the group down.
40 group.setSize(100, 100, true);
41
42 ok(group.shouldStack(group._children.length), "The group should stack.");
43 isnot(expander[0].style.display, "none", "The expander is now visible!");
44 let expanderBounds = expander.bounds();
45 ok(group.getBounds().contains(expanderBounds), "The expander lies in the group.");
46 let stackCenter = children[0].getBounds().center();
47 ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack.");
48
49 // STAGE 1:
50 // Here, we just expand the group, click elsewhere, and make sure
51 // it collapsed.
52 let stage1expanded = function() {
53 group.removeSubscriber("expanded", stage1expanded);
54
55 ok(group.expanded, "The group is now expanded.");
56 is(expander[0].style.display, "none", "The expander is hidden!");
57
58 let overlay = contentWindow.document.getElementById("expandedTray");
59 ok(overlay, "The expanded tray exists.");
60 let $overlay = contentWindow.iQ(overlay);
61
62 group.addSubscriber("collapsed", stage1collapsed);
63 // null type means "click", for some reason...
64 EventUtils.synthesizeMouse(contentWindow.document.body, 10, $overlay.bounds().bottom + 5,
65 {type: null}, contentWindow);
66 };
67
68 let stage1collapsed = function() {
69 group.removeSubscriber("collapsed", stage1collapsed);
70 ok(!group.expanded, "The group is no longer expanded.");
71 isnot(expander[0].style.display, "none", "The expander is visible!");
72 let expanderBounds = expander.bounds();
73 ok(group.getBounds().contains(expanderBounds), "The expander still lies in the group.");
74 let stackCenter = children[0].getBounds().center();
75 ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack.");
76
77 // now, try opening it up again.
78 group.addSubscriber("expanded", stage2expanded);
79 EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
80 };
81
82 // STAGE 2:
83 // Now make sure every child of the group shows up within this "tray", and
84 // click on one of them and make sure we go into the tab and the tray collapses.
85 let stage2expanded = function() {
86 group.removeSubscriber("expanded", stage2expanded);
87
88 ok(group.expanded, "The group is now expanded.");
89 is(expander[0].style.display, "none", "The expander is hidden!");
90
91 let overlay = contentWindow.document.getElementById("expandedTray");
92 ok(overlay, "The expanded tray exists.");
93 let $overlay = contentWindow.iQ(overlay);
94 let overlayBounds = $overlay.bounds();
95
96 children.forEach(function(child, i) {
97 ok(overlayBounds.contains(child.getBounds()), "Child " + i + " is in the overlay");
98 });
99
100 win.addEventListener("tabviewhidden", stage2hidden, false);
101 // again, null type means "click", for some reason...
102 EventUtils.synthesizeMouse(children[1].container, 2, 2, {type: null}, contentWindow);
103 };
104
105 let stage2hidden = function() {
106 win.removeEventListener("tabviewhidden", stage2hidden, false);
107
108 is(win.gBrowser.selectedTab, children[1].tab, "We clicked on the second child.");
109
110 win.addEventListener("tabviewshown", stage2shown, false);
111 win.TabView.toggle();
112 };
113
114 let stage2shown = function() {
115 win.removeEventListener("tabviewshown", stage2shown, false);
116 ok(!group.expanded, "The group is not expanded.");
117 isnot(expander[0].style.display, "none", "The expander is visible!");
118 let expanderBounds = expander.bounds();
119 ok(group.getBounds().contains(expanderBounds), "The expander still lies in the group.");
120 let stackCenter = children[0].getBounds().center();
121 ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack.");
122
123 is(group.getTopChild(), children[1], "The top child in the stack is the second tab item");
124 let topChildzIndex = children[1].zIndex;
125 // the second tab item should have the largest z-index.
126 // only check the first 6 tabs as the stack only contains 6 tab items.
127 for (let i = 0; i < 6; i++) {
128 if (i != 1)
129 ok(children[i].zIndex < topChildzIndex,
130 "The child[" + i + "] has smaller zIndex than second child");
131 }
132
133 // okay, expand this group one last time
134 group.addSubscriber("expanded", stage3expanded);
135 EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
136 }
137
138 // STAGE 3:
139 // Ensure that stack still shows the same top item after a expand and a collapse.
140 let stage3expanded = function() {
141 group.removeSubscriber("expanded", stage3expanded);
142
143 ok(group.expanded, "The group is now expanded.");
144 let overlay = contentWindow.document.getElementById("expandedTray");
145 let $overlay = contentWindow.iQ(overlay);
146
147 group.addSubscriber("collapsed", stage3collapsed);
148 // null type means "click", for some reason...
149 EventUtils.synthesizeMouse(contentWindow.document.body, 10, $overlay.bounds().bottom + 5,
150 {type: null}, contentWindow);
151 };
152
153 let stage3collapsed = function() {
154 group.removeSubscriber("collapsed", stage3collapsed);
155
156 ok(!group.expanded, "The group is no longer expanded.");
157 isnot(expander[0].style.display, "none", "The expander is visible!");
158
159 let stackCenter = children[0].getBounds().center();
160 ok(stackCenter.y < expanderBounds.center().y, "The expander is below the stack.");
161
162 is(group.getTopChild(), children[1],
163 "The top child in the stack is still the second tab item");
164 let topChildzIndex = children[1].zIndex;
165 // the second tab item should have the largest z-index.
166 // only check the first 6 tabs as the stack only contains 6 tab items.
167 for (let i = 0; i < 6; i++) {
168 if (i != 1)
169 ok(children[i].zIndex < topChildzIndex,
170 "The child[" + i + "] has smaller zIndex than second dhild after a collapse.");
171 }
172
173 // In preparation for Stage 4, find that original tab and make it the active tab.
174 let originalTabItem = originalTab._tabViewTabItem;
175 contentWindow.UI.setActive(originalTabItem);
176
177 // now, try opening it up again.
178 group.addSubscriber("expanded", stage4expanded);
179 EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
180 };
181
182 // STAGE 4:
183 // Activate another tab not in this group, expand our stacked group, but then
184 // enter Panorama (i.e., zoom into this other group), and make sure we can go to
185 // it and that the tray gets collapsed.
186 let stage4expanded = function() {
187 group.removeSubscriber("expanded", stage4expanded);
188
189 ok(group.expanded, "The group is now expanded.");
190 is(expander[0].style.display, "none", "The expander is hidden!");
191 let overlay = contentWindow.document.getElementById("expandedTray");
192 ok(overlay, "The expanded tray exists.");
193
194 let activeTab = contentWindow.UI.getActiveTab();
195 ok(activeTab, "There is an active tab.");
196 let originalTabItem = originalTab._tabViewTabItem;
197
198 isnot(activeTab, originalTabItem, "But it's not what it was a moment ago.");
199 let someChildIsActive = group.getChildren().some(function(child)
200 child == activeTab);
201 ok(someChildIsActive, "Now one of the children in the group is active.");
202
203 // now activate Panorama...
204 win.addEventListener("tabviewhidden", stage4hidden, false);
205 win.TabView.toggle();
206 };
207
208 let stage4hidden = function() {
209 win.removeEventListener("tabviewhidden", stage4hidden, false);
210
211 isnot(win.gBrowser.selectedTab, originalTab, "We did not enter the original tab.");
212
213 let someChildIsSelected = group.getChildren().some(function(child)
214 child.tab == win.gBrowser.selectedTab);
215 ok(someChildIsSelected, "Instead we're in one of the stack's children.");
216
217 win.addEventListener("tabviewshown", stage4shown, false);
218 win.TabView.toggle();
219 };
220
221 let stage4shown = function() {
222 win.removeEventListener("tabviewshown", stage4shown, false);
223
224 let overlay = contentWindow.document.getElementById("expandedTray");
225 ok(!group.expanded, "The group is no longer expanded.");
226 isnot(expander[0].style.display, "none", "The expander is visible!");
227
228 win.close();
229 finish();
230 }
231
232 // get the ball rolling
233 group.addSubscriber("expanded", stage1expanded);
234 EventUtils.sendMouseEvent({ type: "click" }, expander[0], contentWindow);
235 }, win);
236 }

mercurial