|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 let cw; |
|
6 let win; |
|
7 let currentTest; |
|
8 |
|
9 let getGroupItem = function (index) { |
|
10 return cw.GroupItems.groupItems[index]; |
|
11 } |
|
12 |
|
13 let createGroupItem = function (numTabs) { |
|
14 let bounds = new cw.Rect(20, 20, 200, 200); |
|
15 let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); |
|
16 cw.UI.setActive(groupItem); |
|
17 |
|
18 for (let i=0; i<numTabs || 0; i++) |
|
19 win.gBrowser.loadOneTab('about:blank', {inBackground: true}); |
|
20 |
|
21 return groupItem; |
|
22 } |
|
23 |
|
24 let tests = []; |
|
25 |
|
26 let next = function () { |
|
27 let test = tests.shift(); |
|
28 |
|
29 if (test) { |
|
30 // check that the previous test left things as expected |
|
31 if (currentTest) { |
|
32 currentTest += ' (post-check)'; |
|
33 assertTabViewIsHidden(); |
|
34 assertNumberOfGroupItems(1); |
|
35 assertNumberOfTabs(1); |
|
36 } |
|
37 |
|
38 currentTest = test.name; |
|
39 showTabView(test.func, win); |
|
40 } else |
|
41 promiseWindowClosed(win).then(finish); |
|
42 } |
|
43 |
|
44 let assertTabViewIsHidden = function () { |
|
45 ok(!win.TabView.isVisible(), currentTest + ': tabview is hidden'); |
|
46 } |
|
47 |
|
48 let assertNumberOfGroupItems = function (num) { |
|
49 is(cw.GroupItems.groupItems.length, num, currentTest + ': number of groupItems is equal to ' + num); |
|
50 } |
|
51 |
|
52 let assertNumberOfTabs = function (num) { |
|
53 is(win.gBrowser.tabs.length, num, currentTest + ': number of tabs is equal to ' + num); |
|
54 } |
|
55 |
|
56 let assertGroupItemRemoved = function (groupItem) { |
|
57 is(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem was removed'); |
|
58 } |
|
59 |
|
60 let assertGroupItemExists = function (groupItem) { |
|
61 isnot(cw.GroupItems.groupItems.indexOf(groupItem), -1, currentTest + ': groupItem still exists'); |
|
62 } |
|
63 |
|
64 // setup: 1 non-empty group |
|
65 // action: close the group |
|
66 // expected: new group with blank tab is created and zoomed into |
|
67 let testSingleGroup1 = function () { |
|
68 let groupItem = getGroupItem(0); |
|
69 closeGroupItem(groupItem, function () { |
|
70 assertNumberOfGroupItems(1); |
|
71 assertGroupItemRemoved(groupItem); |
|
72 whenTabViewIsHidden(next, win); |
|
73 }); |
|
74 } |
|
75 |
|
76 // setup: 1 non-empty group |
|
77 // action: hide the group, exit panorama |
|
78 // expected: new group with blank tab is created and zoomed into |
|
79 let testSingleGroup2 = function () { |
|
80 let groupItem = getGroupItem(0); |
|
81 hideGroupItem(groupItem, function () { |
|
82 hideTabView(function () { |
|
83 assertNumberOfGroupItems(1); |
|
84 assertGroupItemRemoved(groupItem); |
|
85 next(); |
|
86 }, win); |
|
87 }); |
|
88 } |
|
89 |
|
90 // setup: 2 non-empty groups |
|
91 // action: close one group |
|
92 // expected: nothing should happen |
|
93 let testNonEmptyGroup1 = function () { |
|
94 let groupItem = getGroupItem(0); |
|
95 let newGroupItem = createGroupItem(1); |
|
96 assertNumberOfGroupItems(2); |
|
97 |
|
98 closeGroupItem(groupItem, function () { |
|
99 assertNumberOfGroupItems(1); |
|
100 assertGroupItemExists(newGroupItem); |
|
101 hideTabView(next, win); |
|
102 }); |
|
103 } |
|
104 |
|
105 // setup: 2 non-empty groups |
|
106 // action: hide one group, exit panorama |
|
107 // expected: nothing should happen |
|
108 let testNonEmptyGroup2 = function () { |
|
109 let groupItem = getGroupItem(0); |
|
110 let newGroupItem = createGroupItem(1); |
|
111 assertNumberOfGroupItems(2); |
|
112 |
|
113 hideGroupItem(groupItem, function () { |
|
114 hideTabView(function () { |
|
115 assertNumberOfGroupItems(1); |
|
116 assertGroupItemRemoved(groupItem); |
|
117 assertGroupItemExists(newGroupItem); |
|
118 next(); |
|
119 }, win); |
|
120 }); |
|
121 } |
|
122 |
|
123 // setup: 1 pinned tab, 1 empty group |
|
124 // action: exit panorama |
|
125 // expected: nothing should happen |
|
126 let testPinnedTab1 = function () { |
|
127 win.gBrowser.pinTab(win.gBrowser.selectedTab); |
|
128 |
|
129 let groupItem = getGroupItem(0); |
|
130 hideTabView(function () { |
|
131 assertNumberOfGroupItems(1); |
|
132 assertGroupItemExists(groupItem); |
|
133 win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
|
134 next(); |
|
135 }, win); |
|
136 } |
|
137 |
|
138 // setup: 1 pinned tab |
|
139 // action: exit panorama |
|
140 // expected: new blank group is created |
|
141 let testPinnedTab2 = function () { |
|
142 win.gBrowser.pinTab(win.gBrowser.selectedTab); |
|
143 getGroupItem(0).close(); |
|
144 |
|
145 hideTabView(function () { |
|
146 assertNumberOfTabs(1); |
|
147 assertNumberOfGroupItems(1); |
|
148 win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
|
149 next(); |
|
150 }, win); |
|
151 } |
|
152 |
|
153 // setup: 1 pinned tab, 1 empty group, 1 non-empty group |
|
154 // action: close non-empty group |
|
155 // expected: nothing should happen |
|
156 let testPinnedTab3 = function () { |
|
157 win.gBrowser.pinTab(win.gBrowser.selectedTab); |
|
158 |
|
159 let groupItem = getGroupItem(0); |
|
160 let newGroupItem = createGroupItem(1); |
|
161 assertNumberOfGroupItems(2); |
|
162 |
|
163 closeGroupItem(newGroupItem, function () { |
|
164 assertNumberOfGroupItems(1); |
|
165 assertGroupItemExists(groupItem); |
|
166 |
|
167 win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
|
168 hideTabView(next, win); |
|
169 }); |
|
170 } |
|
171 |
|
172 // setup: 1 pinned tab, 1 empty group, 1 non-empty group |
|
173 // action: hide non-empty group, exit panorama |
|
174 // expected: nothing should happen |
|
175 let testPinnedTab4 = function () { |
|
176 win.gBrowser.pinTab(win.gBrowser.selectedTab); |
|
177 |
|
178 let groupItem = getGroupItem(0); |
|
179 let newGroupItem = createGroupItem(1); |
|
180 assertNumberOfGroupItems(2); |
|
181 |
|
182 hideGroupItem(newGroupItem, function () { |
|
183 hideTabView(function () { |
|
184 assertNumberOfGroupItems(1); |
|
185 assertGroupItemExists(groupItem); |
|
186 assertGroupItemRemoved(newGroupItem); |
|
187 win.gBrowser.unpinTab(win.gBrowser.selectedTab); |
|
188 next(); |
|
189 }, win); |
|
190 }); |
|
191 } |
|
192 |
|
193 // setup: 1 non-empty group, 1 empty group |
|
194 // action: close non-empty group |
|
195 // expected: empty group is re-used, new tab is created and zoomed into |
|
196 let testEmptyGroup1 = function () { |
|
197 let groupItem = getGroupItem(0); |
|
198 let newGroupItem = createGroupItem(0); |
|
199 assertNumberOfGroupItems(2); |
|
200 |
|
201 closeGroupItem(groupItem, function () { |
|
202 assertNumberOfGroupItems(1); |
|
203 assertGroupItemExists(newGroupItem); |
|
204 whenTabViewIsHidden(next, win); |
|
205 }); |
|
206 } |
|
207 |
|
208 // setup: 1 non-empty group, 1 empty group |
|
209 // action: hide non-empty group, exit panorama |
|
210 // expected: empty group is re-used, new tab is created and zoomed into |
|
211 let testEmptyGroup2 = function () { |
|
212 let groupItem = getGroupItem(0); |
|
213 let newGroupItem = createGroupItem(0); |
|
214 assertNumberOfGroupItems(2); |
|
215 |
|
216 hideGroupItem(groupItem, function () { |
|
217 hideTabView(function () { |
|
218 assertNumberOfGroupItems(1); |
|
219 assertGroupItemRemoved(groupItem); |
|
220 assertGroupItemExists(newGroupItem); |
|
221 next(); |
|
222 }, win); |
|
223 }); |
|
224 } |
|
225 |
|
226 // setup: 1 hidden group, 1 non-empty group |
|
227 // action: close non-empty group |
|
228 // expected: nothing should happen |
|
229 let testHiddenGroup1 = function () { |
|
230 let groupItem = getGroupItem(0); |
|
231 let hiddenGroupItem = createGroupItem(1); |
|
232 assertNumberOfGroupItems(2); |
|
233 |
|
234 hideGroupItem(hiddenGroupItem, function () { |
|
235 closeGroupItem(groupItem, function () { |
|
236 assertNumberOfGroupItems(1); |
|
237 assertGroupItemRemoved(groupItem); |
|
238 assertGroupItemExists(hiddenGroupItem); |
|
239 hideTabView(next, win); |
|
240 }); |
|
241 }); |
|
242 } |
|
243 |
|
244 // setup: 1 hidden group, 1 non-empty group |
|
245 // action: hide non-empty group, exit panorama |
|
246 // expected: new group with blank tab is created and zoomed into |
|
247 let testHiddenGroup2 = function () { |
|
248 let groupItem = getGroupItem(0); |
|
249 let hiddenGroupItem = createGroupItem(1); |
|
250 assertNumberOfGroupItems(2); |
|
251 |
|
252 hideGroupItem(hiddenGroupItem, function () { |
|
253 hideGroupItem(groupItem, function () { |
|
254 hideTabView(function () { |
|
255 assertNumberOfGroupItems(1); |
|
256 assertGroupItemRemoved(groupItem); |
|
257 assertGroupItemRemoved(hiddenGroupItem); |
|
258 next(); |
|
259 }, win); |
|
260 }); |
|
261 }); |
|
262 } |
|
263 |
|
264 tests.push({name: 'testSingleGroup1', func: testSingleGroup1}); |
|
265 tests.push({name: 'testSingleGroup2', func: testSingleGroup2}); |
|
266 |
|
267 tests.push({name: 'testNonEmptyGroup1', func: testNonEmptyGroup1}); |
|
268 tests.push({name: 'testNonEmptyGroup2', func: testNonEmptyGroup2}); |
|
269 |
|
270 tests.push({name: 'testPinnedTab1', func: testPinnedTab1}); |
|
271 tests.push({name: 'testPinnedTab2', func: testPinnedTab2}); |
|
272 tests.push({name: 'testPinnedTab3', func: testPinnedTab3}); |
|
273 tests.push({name: 'testPinnedTab4', func: testPinnedTab4}); |
|
274 |
|
275 tests.push({name: 'testEmptyGroup1', func: testEmptyGroup1}); |
|
276 tests.push({name: 'testEmptyGroup2', func: testEmptyGroup2}); |
|
277 |
|
278 tests.push({name: 'testHiddenGroup1', func: testHiddenGroup1}); |
|
279 tests.push({name: 'testHiddenGroup2', func: testHiddenGroup2}), |
|
280 |
|
281 waitForExplicitFinish(); |
|
282 |
|
283 newWindowWithTabView(window => { |
|
284 win = window; |
|
285 cw = win.TabView.getContentWindow(); |
|
286 next(); |
|
287 }); |
|
288 } |