|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 requestLongerTimeout(4); |
|
6 let cw; |
|
7 let win; |
|
8 let groupItem; |
|
9 |
|
10 let next = function () { |
|
11 let test = tests.shift(); |
|
12 |
|
13 if (test) { |
|
14 test(); |
|
15 return; |
|
16 } |
|
17 |
|
18 win.close(); |
|
19 finish(); |
|
20 } |
|
21 |
|
22 let closeTabItemManually = function (tabItem) { |
|
23 EventUtils.synthesizeMouseAtCenter(tabItem.container, {button: 1}, cw); |
|
24 } |
|
25 |
|
26 let prepareTest = function (testName) { |
|
27 let originalBounds = groupItem.getChild(0).getBounds(); |
|
28 |
|
29 let tabItem = groupItem.getChild(1); |
|
30 let bounds = tabItem.getBounds(); |
|
31 closeTabItemManually(tabItem); |
|
32 |
|
33 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), testName + ': tabs did not change their size'); |
|
34 ok(bounds.equals(groupItem.getChild(1).getBounds()), testName + ': third tab is now on second tab\'s previous position'); |
|
35 |
|
36 return originalBounds; |
|
37 } |
|
38 |
|
39 let cleanUpTest = function (testName, originalBounds, callback) { |
|
40 // Use setTimeout here because the groupItem.arrange() call uses |
|
41 // animation to re-arrange the tabItems. |
|
42 win.setTimeout(function () { |
|
43 ok(!originalBounds.equals(groupItem.getChild(0).getBounds()), testName + ': tabs changed their size'); |
|
44 |
|
45 // cleanup |
|
46 cw.UI.setActive(groupItem); |
|
47 win.gBrowser.loadOneTab('about:blank', {inBackground: true}); |
|
48 afterAllTabsLoaded(callback, win); |
|
49 }, 500); |
|
50 } |
|
51 |
|
52 let tests = []; |
|
53 |
|
54 // focus group title's input field to cause item arrange |
|
55 let testFocusTitle = function () { |
|
56 let originalBounds = prepareTest('testFocusTitle'); |
|
57 |
|
58 let target = groupItem.$titleShield[0]; |
|
59 EventUtils.synthesizeMouseAtCenter(target, {}, cw); |
|
60 |
|
61 cleanUpTest('testFocusTitle', originalBounds, next); |
|
62 } |
|
63 |
|
64 // hide tabview to cause item arrange |
|
65 let testHideTabView = function () { |
|
66 let originalBounds = prepareTest('testHideTabView'); |
|
67 |
|
68 hideTabView(function () { |
|
69 cleanUpTest('testHideTabView', originalBounds, function () { |
|
70 showTabView(next, win); |
|
71 }); |
|
72 }, win); |
|
73 } |
|
74 |
|
75 // (undo) close a group to cause item arrange |
|
76 let testCloseGroupUndo = function () { |
|
77 let originalBounds = prepareTest('testCloseGroupUndo'); |
|
78 |
|
79 hideGroupItem(groupItem, function () { |
|
80 unhideGroupItem(groupItem, function () { |
|
81 cleanUpTest('testCloseGroupUndo', originalBounds, next); |
|
82 }); |
|
83 }); |
|
84 } |
|
85 |
|
86 // leave the group's container with the mouse to cause item arrange |
|
87 let testMouseOut = function () { |
|
88 let originalBounds = prepareTest('testMouseOut'); |
|
89 let doc = cw.document.documentElement; |
|
90 let bounds = groupItem.getBounds(); |
|
91 |
|
92 EventUtils.synthesizeMouse(doc, bounds.right - 5, bounds.bottom - 5, {type: 'mousemove'}, cw); |
|
93 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testMouseOut: tabs did not change their size'); |
|
94 |
|
95 EventUtils.synthesizeMouse(doc, bounds.right + 1, bounds.bottom + 1, {type: 'mousemove'}, cw); |
|
96 cleanUpTest('testMouseOut', originalBounds, next); |
|
97 } |
|
98 |
|
99 // sort item (drag it around) in its group to cause item arrange |
|
100 let testSortInGroup = function () { |
|
101 let originalBounds = prepareTest('testSortInGroup'); |
|
102 let target = groupItem.getChild(0).container; |
|
103 |
|
104 // simulate drag/drop sorting |
|
105 EventUtils.synthesizeMouse(target, 20, 20, {type: 'mousedown'}, cw); |
|
106 EventUtils.synthesizeMouse(target, 40, 20, {type: 'mousemove'}, cw); |
|
107 EventUtils.synthesizeMouse(target, 20, 20, {type: 'mouseup'}, cw); |
|
108 |
|
109 cleanUpTest('testSortInGroup', originalBounds, next); |
|
110 } |
|
111 |
|
112 // arrange items when the containing group is resized |
|
113 let testResizeGroup = function () { |
|
114 let originalBounds = prepareTest('testResizeGroup'); |
|
115 let oldBounds = groupItem.getBounds(); |
|
116 let resizer = groupItem.$resizer[0]; |
|
117 |
|
118 // simulate drag/drop resizing |
|
119 EventUtils.synthesizeMouse(resizer, 5, 5, {type: 'mousedown'}, cw); |
|
120 EventUtils.synthesizeMouse(resizer, 40, 20, {type: 'mousemove'}, cw); |
|
121 EventUtils.synthesizeMouse(resizer, 20, 20, {type: 'mouseup'}, cw); |
|
122 |
|
123 // reset group size |
|
124 groupItem.setBounds(oldBounds); |
|
125 groupItem.setUserSize(); |
|
126 |
|
127 cleanUpTest('testResizeGroup', originalBounds, next); |
|
128 } |
|
129 |
|
130 // make sure we don't freeze item size when removing an item from a stack |
|
131 let testRemoveWhileStacked = function () { |
|
132 let oldBounds = groupItem.getBounds(); |
|
133 groupItem.setSize(250, 250, true); |
|
134 groupItem.setUserSize(); |
|
135 |
|
136 ok(!groupItem.isStacked(), 'testRemoveWhileStacked: group is not stacked'); |
|
137 |
|
138 let originalBounds; |
|
139 let tabItem = groupItem.getChild(0); |
|
140 |
|
141 // add new tabs to let the group stack |
|
142 while (!groupItem.isStacked()) { |
|
143 originalBounds = tabItem.getBounds(); |
|
144 win.gBrowser.addTab(); |
|
145 } |
|
146 |
|
147 afterAllTabsLoaded(function () { |
|
148 tabItem.close(); |
|
149 ok(!groupItem.isStacked(), 'testRemoveWhileStacked: group is not stacked'); |
|
150 |
|
151 let bounds = groupItem.getChild(0).getBounds(); |
|
152 ok(originalBounds.equals(bounds), 'testRemoveWhileStacked: tabs did not change their size'); |
|
153 |
|
154 // reset group size |
|
155 groupItem.setBounds(oldBounds); |
|
156 groupItem.setUserSize(); |
|
157 |
|
158 next(); |
|
159 }, win); |
|
160 } |
|
161 |
|
162 // 1) make sure item size is frozen when removing an item in expanded mode |
|
163 // 2) make sure item size stays frozen while moving the mouse in the expanded |
|
164 // layer |
|
165 let testExpandedMode = function () { |
|
166 let oldBounds = groupItem.getBounds(); |
|
167 groupItem.setSize(100, 100, true); |
|
168 groupItem.setUserSize(); |
|
169 |
|
170 ok(groupItem.isStacked(), 'testExpandedMode: group is stacked'); |
|
171 |
|
172 groupItem.addSubscriber('expanded', function onGroupExpanded() { |
|
173 groupItem.removeSubscriber('expanded', onGroupExpanded); |
|
174 onExpanded(); |
|
175 }); |
|
176 |
|
177 groupItem.addSubscriber('collapsed', function onGroupCollapsed() { |
|
178 groupItem.removeSubscriber('collapsed', onGroupCollapsed); |
|
179 onCollapsed(); |
|
180 }); |
|
181 |
|
182 let onExpanded = function () { |
|
183 let originalBounds = groupItem.getChild(0).getBounds(); |
|
184 let tabItem = groupItem.getChild(1); |
|
185 let bounds = tabItem.getBounds(); |
|
186 |
|
187 while (groupItem.getChildren().length > 2) |
|
188 closeTabItemManually(groupItem.getChild(1)); |
|
189 |
|
190 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testExpandedMode: tabs did not change their size'); |
|
191 |
|
192 // move the mouse over the expanded layer |
|
193 let trayBounds = groupItem.expanded.bounds; |
|
194 let target = groupItem.expanded.$tray[0]; |
|
195 EventUtils.synthesizeMouse(target, trayBounds.right - 5, trayBounds.bottom -5, {type: 'mousemove'}, cw); |
|
196 |
|
197 ok(originalBounds.equals(groupItem.getChild(0).getBounds()), 'testExpandedMode: tabs did not change their size'); |
|
198 groupItem.collapse(); |
|
199 } |
|
200 |
|
201 let onCollapsed = function () { |
|
202 // reset group size |
|
203 groupItem.setBounds(oldBounds); |
|
204 groupItem.setUserSize(); |
|
205 |
|
206 next(); |
|
207 } |
|
208 |
|
209 groupItem.expand(); |
|
210 } |
|
211 |
|
212 tests.push(testFocusTitle); |
|
213 tests.push(testHideTabView); |
|
214 tests.push(testCloseGroupUndo); |
|
215 tests.push(testMouseOut); |
|
216 tests.push(testSortInGroup); |
|
217 tests.push(testResizeGroup); |
|
218 tests.push(testRemoveWhileStacked); |
|
219 tests.push(testExpandedMode); |
|
220 |
|
221 waitForExplicitFinish(); |
|
222 |
|
223 newWindowWithTabView(function (tvwin) { |
|
224 win = tvwin; |
|
225 |
|
226 registerCleanupFunction(function () { |
|
227 if (!win.closed) |
|
228 win.close(); |
|
229 }); |
|
230 |
|
231 cw = win.TabView.getContentWindow(); |
|
232 |
|
233 groupItem = cw.GroupItems.groupItems[0]; |
|
234 groupItem.setSize(400, 200, true); |
|
235 groupItem.setUserSize(); |
|
236 |
|
237 for (let i=0; i<3; i++) |
|
238 win.gBrowser.loadOneTab('about:blank', {inBackground: true}); |
|
239 |
|
240 afterAllTabsLoaded(next, win); |
|
241 }); |
|
242 } |