1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_history.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,272 @@ 1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +"use strict"; 1.10 + 1.11 +let gStartView = null; 1.12 + 1.13 +function test() { 1.14 + runTests(); 1.15 +} 1.16 + 1.17 +function scrollToEnd() { 1.18 + getBrowser().contentWindow.scrollBy(50000, 0); 1.19 +} 1.20 + 1.21 +function setup() { 1.22 + PanelUI.hide(); 1.23 + 1.24 + if (!BrowserUI.isStartTabVisible) { 1.25 + let tab = yield addTab("about:start"); 1.26 + gStartView = tab.browser.contentWindow.HistoryStartView._view; 1.27 + 1.28 + yield waitForCondition(() => BrowserUI.isStartTabVisible); 1.29 + 1.30 + yield hideContextUI(); 1.31 + } 1.32 + 1.33 + HistoryTestHelper.setup(); 1.34 + 1.35 + // Scroll to make sure all tiles are visible. 1.36 + scrollToEnd(); 1.37 +} 1.38 + 1.39 +function tearDown() { 1.40 + PanelUI.hide(); 1.41 + HistoryTestHelper.restore(); 1.42 +} 1.43 + 1.44 +function uriFromIndex(aIndex) { 1.45 + return "http://mock-history-" + aIndex + ".com.br/" 1.46 +} 1.47 + 1.48 +gTests.push({ 1.49 + desc: "Test history StartUI hide", 1.50 + setUp: setup, 1.51 + tearDown: tearDown, 1.52 + run: function testHistoryStartHide() { 1.53 + let hideButton = document.getElementById("hide-selected-button"); 1.54 + 1.55 + // --------- hide item 2 1.56 + 1.57 + let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.58 + 1.59 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.60 + sendContextMenuClickToElement(window, item, 10, 10); 1.61 + yield promise; 1.62 + 1.63 + ok(!hideButton.hidden, "Hide button is visible."); 1.64 + 1.65 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.66 + hideButton.click(); 1.67 + yield promise; 1.68 + 1.69 + item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.70 + 1.71 + ok(!item, "Item not in grid"); 1.72 + ok(!gStartView._pinHelper.isPinned(uriFromIndex(2)), "Item hidden"); 1.73 + is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated"); 1.74 + 1.75 + // --------- hide multiple items 1.76 + 1.77 + let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.78 + let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.79 + let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.80 + 1.81 + scrollToEnd(); 1.82 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.83 + sendContextMenuClickToElement(window, item1, 10, 10); 1.84 + sendContextMenuClickToElement(window, item2, 10, 10); 1.85 + sendContextMenuClickToElement(window, item3, 10, 10); 1.86 + yield promise; 1.87 + 1.88 + ok(!hideButton.hidden, "Hide button is visible."); 1.89 + 1.90 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.91 + EventUtils.synthesizeMouse(hideButton, 10, 10, {}, window); 1.92 + yield promise; 1.93 + 1.94 + item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.95 + item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.96 + item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.97 + 1.98 + ok(!item1 && !item2 && !item3, "Items are not in grid"); 1.99 + ok(!gStartView._pinHelper.isPinned(uriFromIndex(0)) && !gStartView._pinHelper.isPinned(uriFromIndex(5)) && !gStartView._pinHelper.isPinned(uriFromIndex(12)) , "Items hidden"); 1.100 + ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); 1.101 + } 1.102 +}); 1.103 + 1.104 +gTests.push({ 1.105 + desc: "Test history StartUI delete", 1.106 + setUp: setup, 1.107 + tearDown: tearDown, 1.108 + run: function testHistoryStartDelete() { 1.109 + let restoreButton = document.getElementById("restore-selected-button"); 1.110 + let deleteButton = document.getElementById("delete-selected-button"); 1.111 + 1.112 + // --------- delete item 2 and restore 1.113 + 1.114 + let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.115 + let initialLocation = gStartView._set.getIndexOfItem(item); 1.116 + 1.117 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.118 + sendContextMenuClickToElement(window, item, 10, 10); 1.119 + yield promise; 1.120 + 1.121 + ok(!deleteButton.hidden, "Delete button is visible."); 1.122 + 1.123 + let promise = waitForCondition(() => !restoreButton.hidden); 1.124 + EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); 1.125 + yield promise; 1.126 + 1.127 + item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.128 + 1.129 + ok(!item, "Item not in grid"); 1.130 + ok(HistoryTestHelper._nodes[uriFromIndex(2)], "Item not actually deleted yet"); 1.131 + ok(!restoreButton.hidden, "Restore button is visible."); 1.132 + ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); 1.133 + 1.134 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.135 + EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); 1.136 + yield promise; 1.137 + 1.138 + item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.139 + ok(item, "Item back in grid"); 1.140 + ok(gStartView._set.getIndexOfItem(item) === initialLocation, "Back in same position."); 1.141 + ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); 1.142 + 1.143 + // --------- delete item 2 for realz 1.144 + 1.145 + let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.146 + 1.147 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.148 + sendContextMenuClickToElement(window, item, 10, 10); 1.149 + yield promise; 1.150 + 1.151 + yield waitForCondition(() => !deleteButton.hidden); 1.152 + 1.153 + ok(!deleteButton.hidden, "Delete button is visible."); 1.154 + 1.155 + let promise = waitForCondition(() => !restoreButton.hidden); 1.156 + let populateGridSpy = spyOnMethod(gStartView, "populateGrid"); 1.157 + 1.158 + EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); 1.159 + yield promise; 1.160 + 1.161 + is(populateGridSpy.callCount, 1, "populateGrid was called in response to the deleting a tile"); 1.162 + 1.163 + item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.164 + 1.165 + ok(!item, "Item not in grid"); 1.166 + ok(HistoryTestHelper._nodes[uriFromIndex(2)], "Item not deleted yet"); 1.167 + ok(!restoreButton.hidden, "Restore button is visible."); 1.168 + 1.169 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.170 + Elements.contextappbar.dismiss(); 1.171 + yield promise; 1.172 + 1.173 + is(populateGridSpy.callCount, 1, "populateGrid not called when a removed item is actually deleted"); 1.174 + populateGridSpy.restore(); 1.175 + 1.176 + item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; 1.177 + 1.178 + ok(!item, "Item not in grid"); 1.179 + ok(!HistoryTestHelper._nodes[uriFromIndex(2)], "Item RIP"); 1.180 + is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated"); 1.181 + 1.182 + // --------- delete multiple items and restore 1.183 + 1.184 + let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.185 + let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.186 + let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.187 + 1.188 + let initialLocation1 = gStartView._set.getIndexOfItem(item1); 1.189 + let initialLocation2 = gStartView._set.getIndexOfItem(item2); 1.190 + let initialLocation3 = gStartView._set.getIndexOfItem(item3); 1.191 + 1.192 + scrollToEnd(); 1.193 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.194 + sendContextMenuClickToElement(window, item1, 10, 10); 1.195 + sendContextMenuClickToElement(window, item2, 10, 10); 1.196 + sendContextMenuClickToElement(window, item3, 10, 10); 1.197 + yield promise; 1.198 + 1.199 + yield waitForCondition(() => !deleteButton.hidden); 1.200 + 1.201 + ok(!deleteButton.hidden, "Delete button is visible."); 1.202 + 1.203 + let promise = waitForCondition(() => !restoreButton.hidden); 1.204 + EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); 1.205 + yield promise; 1.206 + 1.207 + item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.208 + item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.209 + item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.210 + 1.211 + ok(!item1 && !item2 && !item3, "Items are not in grid"); 1.212 + ok(HistoryTestHelper._nodes[uriFromIndex(0)] && HistoryTestHelper._nodes[uriFromIndex(5)] && HistoryTestHelper._nodes[uriFromIndex(12)], 1.213 + "Items not deleted yet"); 1.214 + ok(!restoreButton.hidden, "Restore button is visible."); 1.215 + ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); 1.216 + 1.217 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.218 + EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); 1.219 + yield promise; 1.220 + 1.221 + item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.222 + item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.223 + item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.224 + 1.225 + ok(item1 && item2 && item3, "Items are back in grid"); 1.226 + ok(gStartView._set.getIndexOfItem(item1) === initialLocation1 && 1.227 + gStartView._set.getIndexOfItem(item2) === initialLocation2 && 1.228 + gStartView._set.getIndexOfItem(item3) === initialLocation3, "Items back in the same position."); 1.229 + ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); 1.230 + 1.231 + // --------- delete multiple items for good 1.232 + 1.233 + let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.234 + let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.235 + let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.236 + 1.237 + scrollToEnd(); 1.238 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.239 + sendContextMenuClickToElement(window, item1, 10, 10); 1.240 + sendContextMenuClickToElement(window, item2, 10, 10); 1.241 + sendContextMenuClickToElement(window, item3, 10, 10); 1.242 + yield promise; 1.243 + 1.244 + yield waitForCondition(() => !deleteButton.hidden); 1.245 + 1.246 + ok(!deleteButton.hidden, "Delete button is visible."); 1.247 + 1.248 + let promise = waitForCondition(() => !restoreButton.hidden); 1.249 + EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); 1.250 + yield promise; 1.251 + 1.252 + item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.253 + item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.254 + item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.255 + 1.256 + ok(!item1 && !item2 && !item3, "Items are not in grid"); 1.257 + ok(HistoryTestHelper._nodes[uriFromIndex(0)] && HistoryTestHelper._nodes[uriFromIndex(5)] && HistoryTestHelper._nodes[uriFromIndex(12)], 1.258 + "Items not deleted yet"); 1.259 + ok(!restoreButton.hidden, "Restore button is visible."); 1.260 + ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); 1.261 + 1.262 + let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); 1.263 + Elements.contextappbar.dismiss(); 1.264 + yield promise; 1.265 + 1.266 + item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; 1.267 + item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; 1.268 + item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; 1.269 + 1.270 + ok(!item1 && !item2 && !item3, "Items are not in grid"); 1.271 + ok(!HistoryTestHelper._nodes[uriFromIndex(0)] && !HistoryTestHelper._nodes[uriFromIndex(5)] && !HistoryTestHelper._nodes[uriFromIndex(12)], 1.272 + "Items are gone"); 1.273 + ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); 1.274 + } 1.275 +});