Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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/. */
6 "use strict";
8 let gStartView = null;
10 function test() {
11 runTests();
12 }
14 function scrollToEnd() {
15 getBrowser().contentWindow.scrollBy(50000, 0);
16 }
18 function setup() {
19 PanelUI.hide();
21 if (!BrowserUI.isStartTabVisible) {
22 let tab = yield addTab("about:start");
23 gStartView = tab.browser.contentWindow.HistoryStartView._view;
25 yield waitForCondition(() => BrowserUI.isStartTabVisible);
27 yield hideContextUI();
28 }
30 HistoryTestHelper.setup();
32 // Scroll to make sure all tiles are visible.
33 scrollToEnd();
34 }
36 function tearDown() {
37 PanelUI.hide();
38 HistoryTestHelper.restore();
39 }
41 function uriFromIndex(aIndex) {
42 return "http://mock-history-" + aIndex + ".com.br/"
43 }
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");
52 // --------- hide item 2
54 let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
56 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
57 sendContextMenuClickToElement(window, item, 10, 10);
58 yield promise;
60 ok(!hideButton.hidden, "Hide button is visible.");
62 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
63 hideButton.click();
64 yield promise;
66 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
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");
72 // --------- hide multiple items
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];
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;
85 ok(!hideButton.hidden, "Hide button is visible.");
87 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
88 EventUtils.synthesizeMouse(hideButton, 10, 10, {}, window);
89 yield promise;
91 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0];
92 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0];
93 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0];
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 });
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");
109 // --------- delete item 2 and restore
111 let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
112 let initialLocation = gStartView._set.getIndexOfItem(item);
114 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
115 sendContextMenuClickToElement(window, item, 10, 10);
116 yield promise;
118 ok(!deleteButton.hidden, "Delete button is visible.");
120 let promise = waitForCondition(() => !restoreButton.hidden);
121 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window);
122 yield promise;
124 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
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");
131 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
132 EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window);
133 yield promise;
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");
140 // --------- delete item 2 for realz
142 let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
144 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
145 sendContextMenuClickToElement(window, item, 10, 10);
146 yield promise;
148 yield waitForCondition(() => !deleteButton.hidden);
150 ok(!deleteButton.hidden, "Delete button is visible.");
152 let promise = waitForCondition(() => !restoreButton.hidden);
153 let populateGridSpy = spyOnMethod(gStartView, "populateGrid");
155 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window);
156 yield promise;
158 is(populateGridSpy.callCount, 1, "populateGrid was called in response to the deleting a tile");
160 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
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.");
166 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
167 Elements.contextappbar.dismiss();
168 yield promise;
170 is(populateGridSpy.callCount, 1, "populateGrid not called when a removed item is actually deleted");
171 populateGridSpy.restore();
173 item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0];
175 ok(!item, "Item not in grid");
176 ok(!HistoryTestHelper._nodes[uriFromIndex(2)], "Item RIP");
177 is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated");
179 // --------- delete multiple items and restore
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];
185 let initialLocation1 = gStartView._set.getIndexOfItem(item1);
186 let initialLocation2 = gStartView._set.getIndexOfItem(item2);
187 let initialLocation3 = gStartView._set.getIndexOfItem(item3);
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;
196 yield waitForCondition(() => !deleteButton.hidden);
198 ok(!deleteButton.hidden, "Delete button is visible.");
200 let promise = waitForCondition(() => !restoreButton.hidden);
201 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window);
202 yield promise;
204 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0];
205 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0];
206 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0];
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");
214 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
215 EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window);
216 yield promise;
218 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0];
219 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0];
220 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0];
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");
228 // --------- delete multiple items for good
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];
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;
241 yield waitForCondition(() => !deleteButton.hidden);
243 ok(!deleteButton.hidden, "Delete button is visible.");
245 let promise = waitForCondition(() => !restoreButton.hidden);
246 EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window);
247 yield promise;
249 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0];
250 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0];
251 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0];
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");
259 let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar);
260 Elements.contextappbar.dismiss();
261 yield promise;
263 item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0];
264 item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0];
265 item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0];
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 });