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