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
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 setup() { |
michael@0 | 15 | PanelUI.hide(); |
michael@0 | 16 | |
michael@0 | 17 | if (!BrowserUI.isStartTabVisible) { |
michael@0 | 18 | let tab = yield addTab("about:start"); |
michael@0 | 19 | gStartView = tab.browser.contentWindow.BookmarksStartView._view; |
michael@0 | 20 | |
michael@0 | 21 | yield waitForCondition(() => BrowserUI.isStartTabVisible); |
michael@0 | 22 | |
michael@0 | 23 | yield hideContextUI(); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | BookmarksTestHelper.setup(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function tearDown() { |
michael@0 | 30 | PanelUI.hide(); |
michael@0 | 31 | BookmarksTestHelper.restore(); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | gTests.push({ |
michael@0 | 35 | desc: "Test bookmarks StartUI hide", |
michael@0 | 36 | setUp: setup, |
michael@0 | 37 | tearDown: tearDown, |
michael@0 | 38 | run: function testBookmarksStartHide() { |
michael@0 | 39 | let hideButton = document.getElementById("hide-selected-button"); |
michael@0 | 40 | |
michael@0 | 41 | // --------- hide item 2 |
michael@0 | 42 | |
michael@0 | 43 | let item = gStartView._getItemForBookmarkId(2); |
michael@0 | 44 | |
michael@0 | 45 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 46 | sendContextMenuClickToElement(window, item, 10, 10); |
michael@0 | 47 | yield promise; |
michael@0 | 48 | |
michael@0 | 49 | ok(!hideButton.hidden, "Hide button is visible."); |
michael@0 | 50 | |
michael@0 | 51 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 52 | hideButton.click(); |
michael@0 | 53 | yield promise; |
michael@0 | 54 | |
michael@0 | 55 | item = gStartView._getItemForBookmarkId(2); |
michael@0 | 56 | |
michael@0 | 57 | ok(!item, "Item not in grid"); |
michael@0 | 58 | ok(!gStartView._pinHelper.isPinned(2), "Item hidden"); |
michael@0 | 59 | ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
michael@0 | 60 | |
michael@0 | 61 | // --------- hide multiple items |
michael@0 | 62 | |
michael@0 | 63 | let item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 64 | let item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 65 | let item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 66 | |
michael@0 | 67 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 68 | sendContextMenuClickToElement(window, item1, 10, 10); |
michael@0 | 69 | sendContextMenuClickToElement(window, item2, 10, 10); |
michael@0 | 70 | sendContextMenuClickToElement(window, item3, 10, 10); |
michael@0 | 71 | yield promise; |
michael@0 | 72 | |
michael@0 | 73 | ok(!hideButton.hidden, "Hide button is visible."); |
michael@0 | 74 | |
michael@0 | 75 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 76 | EventUtils.synthesizeMouse(hideButton, 10, 10, {}, window); |
michael@0 | 77 | yield promise; |
michael@0 | 78 | |
michael@0 | 79 | item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 80 | item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 81 | item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 82 | |
michael@0 | 83 | ok(!item1 && !item2 && !item3, "Items are not in grid"); |
michael@0 | 84 | ok(!gStartView._pinHelper.isPinned(0) && !gStartView._pinHelper.isPinned(5) && !gStartView._pinHelper.isPinned(12) , "Items hidden"); |
michael@0 | 85 | ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
michael@0 | 86 | } |
michael@0 | 87 | }); |
michael@0 | 88 | |
michael@0 | 89 | gTests.push({ |
michael@0 | 90 | desc: "Test bookmarks StartUI delete", |
michael@0 | 91 | setUp: setup, |
michael@0 | 92 | tearDown: tearDown, |
michael@0 | 93 | run: function testBookmarksStartDelete() { |
michael@0 | 94 | let restoreButton = document.getElementById("restore-selected-button"); |
michael@0 | 95 | let deleteButton = document.getElementById("delete-selected-button"); |
michael@0 | 96 | |
michael@0 | 97 | // --------- delete item 2 and restore |
michael@0 | 98 | |
michael@0 | 99 | let item = gStartView._getItemForBookmarkId(2); |
michael@0 | 100 | let initialLocation = gStartView._set.getIndexOfItem(item); |
michael@0 | 101 | |
michael@0 | 102 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 103 | sendContextMenuClickToElement(window, item, 10, 10); |
michael@0 | 104 | yield promise; |
michael@0 | 105 | |
michael@0 | 106 | ok(!deleteButton.hidden, "Delete button is visible."); |
michael@0 | 107 | |
michael@0 | 108 | let promise = waitForCondition(() => !restoreButton.hidden); |
michael@0 | 109 | EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
michael@0 | 110 | yield promise; |
michael@0 | 111 | |
michael@0 | 112 | item = gStartView._getItemForBookmarkId(2); |
michael@0 | 113 | |
michael@0 | 114 | ok(!item, "Item not in grid"); |
michael@0 | 115 | ok(BookmarksTestHelper._nodes[2], "Item not deleted yet"); |
michael@0 | 116 | ok(!restoreButton.hidden, "Restore button is visible."); |
michael@0 | 117 | ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
michael@0 | 118 | |
michael@0 | 119 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 120 | EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); |
michael@0 | 121 | yield promise; |
michael@0 | 122 | |
michael@0 | 123 | item = gStartView._getItemForBookmarkId(2); |
michael@0 | 124 | ok(item, "Item back in grid"); |
michael@0 | 125 | ok(gStartView._set.getIndexOfItem(item) === initialLocation, "Back in same position."); |
michael@0 | 126 | |
michael@0 | 127 | // --------- delete item 2 for realz |
michael@0 | 128 | |
michael@0 | 129 | let item = gStartView._getItemForBookmarkId(2); |
michael@0 | 130 | |
michael@0 | 131 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 132 | sendContextMenuClickToElement(window, item, 10, 10); |
michael@0 | 133 | yield promise; |
michael@0 | 134 | |
michael@0 | 135 | ok(!deleteButton.hidden, "Delete button is visible."); |
michael@0 | 136 | |
michael@0 | 137 | let promise = waitForCondition(() => !restoreButton.hidden); |
michael@0 | 138 | EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
michael@0 | 139 | yield promise; |
michael@0 | 140 | |
michael@0 | 141 | item = gStartView._getItemForBookmarkId(2); |
michael@0 | 142 | |
michael@0 | 143 | ok(!item, "Item not in grid"); |
michael@0 | 144 | ok(BookmarksTestHelper._nodes[2], "Item not deleted yet"); |
michael@0 | 145 | ok(!restoreButton.hidden, "Restore button is visible."); |
michael@0 | 146 | |
michael@0 | 147 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 148 | Elements.contextappbar.dismiss(); |
michael@0 | 149 | yield promise; |
michael@0 | 150 | |
michael@0 | 151 | item = gStartView._getItemForBookmarkId(2); |
michael@0 | 152 | |
michael@0 | 153 | ok(!item, "Item not in grid"); |
michael@0 | 154 | ok(!BookmarksTestHelper._nodes[2], "Item RIP"); |
michael@0 | 155 | ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
michael@0 | 156 | |
michael@0 | 157 | // --------- delete multiple items and restore |
michael@0 | 158 | |
michael@0 | 159 | let item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 160 | let item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 161 | let item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 162 | |
michael@0 | 163 | let initialLocation1 = gStartView._set.getIndexOfItem(item1); |
michael@0 | 164 | let initialLocation2 = gStartView._set.getIndexOfItem(item2); |
michael@0 | 165 | let initialLocation3 = gStartView._set.getIndexOfItem(item3); |
michael@0 | 166 | |
michael@0 | 167 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 168 | sendContextMenuClickToElement(window, item1, 10, 10); |
michael@0 | 169 | sendContextMenuClickToElement(window, item2, 10, 10); |
michael@0 | 170 | sendContextMenuClickToElement(window, item3, 10, 10); |
michael@0 | 171 | yield promise; |
michael@0 | 172 | |
michael@0 | 173 | ok(!deleteButton.hidden, "Delete button is visible."); |
michael@0 | 174 | |
michael@0 | 175 | let promise = waitForCondition(() => !restoreButton.hidden); |
michael@0 | 176 | EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
michael@0 | 177 | yield promise; |
michael@0 | 178 | |
michael@0 | 179 | item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 180 | item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 181 | item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 182 | |
michael@0 | 183 | ok(!item1 && !item2 && !item3, "Items are not in grid"); |
michael@0 | 184 | ok(BookmarksTestHelper._nodes[0] && BookmarksTestHelper._nodes[5] && BookmarksTestHelper._nodes[12], |
michael@0 | 185 | "Items not deleted yet"); |
michael@0 | 186 | ok(!restoreButton.hidden, "Restore button is visible."); |
michael@0 | 187 | ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
michael@0 | 188 | |
michael@0 | 189 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 190 | EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); |
michael@0 | 191 | yield promise; |
michael@0 | 192 | |
michael@0 | 193 | item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 194 | item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 195 | item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 196 | |
michael@0 | 197 | ok(item1 && item2 && item3, "Items are back in grid"); |
michael@0 | 198 | ok(gStartView._set.getIndexOfItem(item1) === initialLocation1 && |
michael@0 | 199 | gStartView._set.getIndexOfItem(item2) === initialLocation2 && |
michael@0 | 200 | gStartView._set.getIndexOfItem(item3) === initialLocation3, "Items back in the same position."); |
michael@0 | 201 | ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); |
michael@0 | 202 | |
michael@0 | 203 | // --------- delete multiple items for good |
michael@0 | 204 | |
michael@0 | 205 | let item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 206 | let item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 207 | let item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 208 | |
michael@0 | 209 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 210 | sendContextMenuClickToElement(window, item1, 10, 10); |
michael@0 | 211 | sendContextMenuClickToElement(window, item2, 10, 10); |
michael@0 | 212 | sendContextMenuClickToElement(window, item3, 10, 10); |
michael@0 | 213 | yield promise; |
michael@0 | 214 | |
michael@0 | 215 | yield waitForCondition(() => !deleteButton.hidden); |
michael@0 | 216 | |
michael@0 | 217 | ok(!deleteButton.hidden, "Delete button is visible."); |
michael@0 | 218 | |
michael@0 | 219 | let promise = waitForCondition(() => !restoreButton.hidden); |
michael@0 | 220 | EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); |
michael@0 | 221 | yield promise; |
michael@0 | 222 | |
michael@0 | 223 | item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 224 | item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 225 | item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 226 | |
michael@0 | 227 | ok(!item1 && !item2 && !item3, "Items are not in grid"); |
michael@0 | 228 | ok(BookmarksTestHelper._nodes[0] && BookmarksTestHelper._nodes[5] && BookmarksTestHelper._nodes[12], |
michael@0 | 229 | "Items not deleted yet"); |
michael@0 | 230 | ok(!restoreButton.hidden, "Restore button is visible."); |
michael@0 | 231 | |
michael@0 | 232 | let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); |
michael@0 | 233 | Elements.contextappbar.dismiss(); |
michael@0 | 234 | yield promise; |
michael@0 | 235 | |
michael@0 | 236 | item1 = gStartView._getItemForBookmarkId(0); |
michael@0 | 237 | item2 = gStartView._getItemForBookmarkId(5); |
michael@0 | 238 | item3 = gStartView._getItemForBookmarkId(12); |
michael@0 | 239 | |
michael@0 | 240 | ok(!item1 && !item2 && !item3, "Items are not in grid"); |
michael@0 | 241 | ok(!BookmarksTestHelper._nodes[0] && !BookmarksTestHelper._nodes[5] && !BookmarksTestHelper._nodes[12], |
michael@0 | 242 | "Items are gone"); |
michael@0 | 243 | ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); |
michael@0 | 244 | } |
michael@0 | 245 | }); |