|
1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 "use strict"; |
|
7 |
|
8 let gStartView = null; |
|
9 |
|
10 function test() { |
|
11 runTests(); |
|
12 } |
|
13 |
|
14 function scrollToEnd() { |
|
15 getBrowser().contentWindow.scrollBy(50000, 0); |
|
16 } |
|
17 |
|
18 function setup() { |
|
19 PanelUI.hide(); |
|
20 |
|
21 if (!BrowserUI.isStartTabVisible) { |
|
22 let tab = yield addTab("about:start"); |
|
23 gStartView = tab.browser.contentWindow.HistoryStartView._view; |
|
24 |
|
25 yield waitForCondition(() => BrowserUI.isStartTabVisible); |
|
26 |
|
27 yield hideContextUI(); |
|
28 } |
|
29 |
|
30 HistoryTestHelper.setup(); |
|
31 |
|
32 // Scroll to make sure all tiles are visible. |
|
33 scrollToEnd(); |
|
34 } |
|
35 |
|
36 function tearDown() { |
|
37 PanelUI.hide(); |
|
38 HistoryTestHelper.restore(); |
|
39 } |
|
40 |
|
41 function uriFromIndex(aIndex) { |
|
42 return "http://mock-history-" + aIndex + ".com.br/" |
|
43 } |
|
44 |
|
45 gTests.push({ |
|
46 desc: "Test history StartUI hide", |
|
47 setUp: setup, |
|
48 tearDown: tearDown, |
|
49 run: function testHistoryStartHide() { |
|
50 let hideButton = document.getElementById("hide-selected-button"); |
|
51 |
|
52 // --------- hide item 2 |
|
53 |
|
54 let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
55 |
|
56 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
57 sendContextMenuClickToElement(window, item, 10, 10); |
|
58 yield promise; |
|
59 |
|
60 ok(!hideButton.hidden, "Hide button is visible."); |
|
61 |
|
62 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
63 hideButton.click(); |
|
64 yield promise; |
|
65 |
|
66 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
67 |
|
68 ok(!item, "Item not in grid"); |
|
69 ok(!gStartView._pinHelper.isPinned(uriFromIndex(2)), "Item hidden"); |
|
70 is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated"); |
|
71 |
|
72 // --------- hide multiple items |
|
73 |
|
74 let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
75 let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
76 let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
77 |
|
78 scrollToEnd(); |
|
79 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
80 sendContextMenuClickToElement(window, item1, 10, 10); |
|
81 sendContextMenuClickToElement(window, item2, 10, 10); |
|
82 sendContextMenuClickToElement(window, item3, 10, 10); |
|
83 yield promise; |
|
84 |
|
85 ok(!hideButton.hidden, "Hide button is visible."); |
|
86 |
|
87 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
88 EventUtils.synthesizeMouse(hideButton, 10, 10, {}, window); |
|
89 yield promise; |
|
90 |
|
91 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
92 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
93 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
94 |
|
95 ok(!item1 && !item2 && !item3, "Items are not in grid"); |
|
96 ok(!gStartView._pinHelper.isPinned(uriFromIndex(0)) && !gStartView._pinHelper.isPinned(uriFromIndex(5)) && !gStartView._pinHelper.isPinned(uriFromIndex(12)) , "Items hidden"); |
|
97 ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
|
98 } |
|
99 }); |
|
100 |
|
101 gTests.push({ |
|
102 desc: "Test history StartUI delete", |
|
103 setUp: setup, |
|
104 tearDown: tearDown, |
|
105 run: function testHistoryStartDelete() { |
|
106 let restoreButton = document.getElementById("restore-selected-button"); |
|
107 let deleteButton = document.getElementById("delete-selected-button"); |
|
108 |
|
109 // --------- delete item 2 and restore |
|
110 |
|
111 let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
112 let initialLocation = gStartView._set.getIndexOfItem(item); |
|
113 |
|
114 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
115 sendContextMenuClickToElement(window, item, 10, 10); |
|
116 yield promise; |
|
117 |
|
118 ok(!deleteButton.hidden, "Delete button is visible."); |
|
119 |
|
120 let promise = waitForCondition(() => !restoreButton.hidden); |
|
121 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
|
122 yield promise; |
|
123 |
|
124 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
125 |
|
126 ok(!item, "Item not in grid"); |
|
127 ok(HistoryTestHelper._nodes[uriFromIndex(2)], "Item not actually deleted yet"); |
|
128 ok(!restoreButton.hidden, "Restore button is visible."); |
|
129 ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
|
130 |
|
131 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
132 EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); |
|
133 yield promise; |
|
134 |
|
135 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
136 ok(item, "Item back in grid"); |
|
137 ok(gStartView._set.getIndexOfItem(item) === initialLocation, "Back in same position."); |
|
138 ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
|
139 |
|
140 // --------- delete item 2 for realz |
|
141 |
|
142 let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
143 |
|
144 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
145 sendContextMenuClickToElement(window, item, 10, 10); |
|
146 yield promise; |
|
147 |
|
148 yield waitForCondition(() => !deleteButton.hidden); |
|
149 |
|
150 ok(!deleteButton.hidden, "Delete button is visible."); |
|
151 |
|
152 let promise = waitForCondition(() => !restoreButton.hidden); |
|
153 let populateGridSpy = spyOnMethod(gStartView, "populateGrid"); |
|
154 |
|
155 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
|
156 yield promise; |
|
157 |
|
158 is(populateGridSpy.callCount, 1, "populateGrid was called in response to the deleting a tile"); |
|
159 |
|
160 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
161 |
|
162 ok(!item, "Item not in grid"); |
|
163 ok(HistoryTestHelper._nodes[uriFromIndex(2)], "Item not deleted yet"); |
|
164 ok(!restoreButton.hidden, "Restore button is visible."); |
|
165 |
|
166 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
167 Elements.contextappbar.dismiss(); |
|
168 yield promise; |
|
169 |
|
170 is(populateGridSpy.callCount, 1, "populateGrid not called when a removed item is actually deleted"); |
|
171 populateGridSpy.restore(); |
|
172 |
|
173 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; |
|
174 |
|
175 ok(!item, "Item not in grid"); |
|
176 ok(!HistoryTestHelper._nodes[uriFromIndex(2)], "Item RIP"); |
|
177 is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated"); |
|
178 |
|
179 // --------- delete multiple items and restore |
|
180 |
|
181 let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
182 let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
183 let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
184 |
|
185 let initialLocation1 = gStartView._set.getIndexOfItem(item1); |
|
186 let initialLocation2 = gStartView._set.getIndexOfItem(item2); |
|
187 let initialLocation3 = gStartView._set.getIndexOfItem(item3); |
|
188 |
|
189 scrollToEnd(); |
|
190 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
191 sendContextMenuClickToElement(window, item1, 10, 10); |
|
192 sendContextMenuClickToElement(window, item2, 10, 10); |
|
193 sendContextMenuClickToElement(window, item3, 10, 10); |
|
194 yield promise; |
|
195 |
|
196 yield waitForCondition(() => !deleteButton.hidden); |
|
197 |
|
198 ok(!deleteButton.hidden, "Delete button is visible."); |
|
199 |
|
200 let promise = waitForCondition(() => !restoreButton.hidden); |
|
201 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
|
202 yield promise; |
|
203 |
|
204 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
205 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
206 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
207 |
|
208 ok(!item1 && !item2 && !item3, "Items are not in grid"); |
|
209 ok(HistoryTestHelper._nodes[uriFromIndex(0)] && HistoryTestHelper._nodes[uriFromIndex(5)] && HistoryTestHelper._nodes[uriFromIndex(12)], |
|
210 "Items not deleted yet"); |
|
211 ok(!restoreButton.hidden, "Restore button is visible."); |
|
212 ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
|
213 |
|
214 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
215 EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); |
|
216 yield promise; |
|
217 |
|
218 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
219 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
220 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
221 |
|
222 ok(item1 && item2 && item3, "Items are back in grid"); |
|
223 ok(gStartView._set.getIndexOfItem(item1) === initialLocation1 && |
|
224 gStartView._set.getIndexOfItem(item2) === initialLocation2 && |
|
225 gStartView._set.getIndexOfItem(item3) === initialLocation3, "Items back in the same position."); |
|
226 ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
|
227 |
|
228 // --------- delete multiple items for good |
|
229 |
|
230 let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
231 let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
232 let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
233 |
|
234 scrollToEnd(); |
|
235 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
236 sendContextMenuClickToElement(window, item1, 10, 10); |
|
237 sendContextMenuClickToElement(window, item2, 10, 10); |
|
238 sendContextMenuClickToElement(window, item3, 10, 10); |
|
239 yield promise; |
|
240 |
|
241 yield waitForCondition(() => !deleteButton.hidden); |
|
242 |
|
243 ok(!deleteButton.hidden, "Delete button is visible."); |
|
244 |
|
245 let promise = waitForCondition(() => !restoreButton.hidden); |
|
246 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
|
247 yield promise; |
|
248 |
|
249 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
250 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
251 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
252 |
|
253 ok(!item1 && !item2 && !item3, "Items are not in grid"); |
|
254 ok(HistoryTestHelper._nodes[uriFromIndex(0)] && HistoryTestHelper._nodes[uriFromIndex(5)] && HistoryTestHelper._nodes[uriFromIndex(12)], |
|
255 "Items not deleted yet"); |
|
256 ok(!restoreButton.hidden, "Restore button is visible."); |
|
257 ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
|
258 |
|
259 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
|
260 Elements.contextappbar.dismiss(); |
|
261 yield promise; |
|
262 |
|
263 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; |
|
264 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; |
|
265 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; |
|
266 |
|
267 ok(!item1 && !item2 && !item3, "Items are not in grid"); |
|
268 ok(!HistoryTestHelper._nodes[uriFromIndex(0)] && !HistoryTestHelper._nodes[uriFromIndex(5)] && !HistoryTestHelper._nodes[uriFromIndex(12)], |
|
269 "Items are gone"); |
|
270 ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
|
271 } |
|
272 }); |