michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: let gStartView = null; michael@0: michael@0: function test() { michael@0: runTests(); michael@0: } michael@0: michael@0: function scrollToEnd() { michael@0: getBrowser().contentWindow.scrollBy(50000, 0); michael@0: } michael@0: michael@0: function setup() { michael@0: PanelUI.hide(); michael@0: michael@0: if (!BrowserUI.isStartTabVisible) { michael@0: let tab = yield addTab("about:start"); michael@0: gStartView = tab.browser.contentWindow.HistoryStartView._view; michael@0: michael@0: yield waitForCondition(() => BrowserUI.isStartTabVisible); michael@0: michael@0: yield hideContextUI(); michael@0: } michael@0: michael@0: HistoryTestHelper.setup(); michael@0: michael@0: // Scroll to make sure all tiles are visible. michael@0: scrollToEnd(); michael@0: } michael@0: michael@0: function tearDown() { michael@0: PanelUI.hide(); michael@0: HistoryTestHelper.restore(); michael@0: } michael@0: michael@0: function uriFromIndex(aIndex) { michael@0: return "http://mock-history-" + aIndex + ".com.br/" michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "Test history StartUI hide", michael@0: setUp: setup, michael@0: tearDown: tearDown, michael@0: run: function testHistoryStartHide() { michael@0: let hideButton = document.getElementById("hide-selected-button"); michael@0: michael@0: // --------- hide item 2 michael@0: michael@0: let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: sendContextMenuClickToElement(window, item, 10, 10); michael@0: yield promise; michael@0: michael@0: ok(!hideButton.hidden, "Hide button is visible."); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: hideButton.click(); michael@0: yield promise; michael@0: michael@0: item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: michael@0: ok(!item, "Item not in grid"); michael@0: ok(!gStartView._pinHelper.isPinned(uriFromIndex(2)), "Item hidden"); michael@0: is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated"); michael@0: michael@0: // --------- hide multiple items michael@0: michael@0: let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: scrollToEnd(); michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: sendContextMenuClickToElement(window, item1, 10, 10); michael@0: sendContextMenuClickToElement(window, item2, 10, 10); michael@0: sendContextMenuClickToElement(window, item3, 10, 10); michael@0: yield promise; michael@0: michael@0: ok(!hideButton.hidden, "Hide button is visible."); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: EventUtils.synthesizeMouse(hideButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: ok(!item1 && !item2 && !item3, "Items are not in grid"); michael@0: ok(!gStartView._pinHelper.isPinned(uriFromIndex(0)) && !gStartView._pinHelper.isPinned(uriFromIndex(5)) && !gStartView._pinHelper.isPinned(uriFromIndex(12)) , "Items hidden"); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Test history StartUI delete", michael@0: setUp: setup, michael@0: tearDown: tearDown, michael@0: run: function testHistoryStartDelete() { michael@0: let restoreButton = document.getElementById("restore-selected-button"); michael@0: let deleteButton = document.getElementById("delete-selected-button"); michael@0: michael@0: // --------- delete item 2 and restore michael@0: michael@0: let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: let initialLocation = gStartView._set.getIndexOfItem(item); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: sendContextMenuClickToElement(window, item, 10, 10); michael@0: yield promise; michael@0: michael@0: ok(!deleteButton.hidden, "Delete button is visible."); michael@0: michael@0: let promise = waitForCondition(() => !restoreButton.hidden); michael@0: EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: michael@0: ok(!item, "Item not in grid"); michael@0: ok(HistoryTestHelper._nodes[uriFromIndex(2)], "Item not actually deleted yet"); michael@0: ok(!restoreButton.hidden, "Restore button is visible."); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: ok(item, "Item back in grid"); michael@0: ok(gStartView._set.getIndexOfItem(item) === initialLocation, "Back in same position."); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); michael@0: michael@0: // --------- delete item 2 for realz michael@0: michael@0: let item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: sendContextMenuClickToElement(window, item, 10, 10); michael@0: yield promise; michael@0: michael@0: yield waitForCondition(() => !deleteButton.hidden); michael@0: michael@0: ok(!deleteButton.hidden, "Delete button is visible."); michael@0: michael@0: let promise = waitForCondition(() => !restoreButton.hidden); michael@0: let populateGridSpy = spyOnMethod(gStartView, "populateGrid"); michael@0: michael@0: EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: is(populateGridSpy.callCount, 1, "populateGrid was called in response to the deleting a tile"); michael@0: michael@0: item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: michael@0: ok(!item, "Item not in grid"); michael@0: ok(HistoryTestHelper._nodes[uriFromIndex(2)], "Item not deleted yet"); michael@0: ok(!restoreButton.hidden, "Restore button is visible."); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: Elements.contextappbar.dismiss(); michael@0: yield promise; michael@0: michael@0: is(populateGridSpy.callCount, 1, "populateGrid not called when a removed item is actually deleted"); michael@0: populateGridSpy.restore(); michael@0: michael@0: item = gStartView._set.getItemsByUrl(uriFromIndex(2))[0]; michael@0: michael@0: ok(!item, "Item not in grid"); michael@0: ok(!HistoryTestHelper._nodes[uriFromIndex(2)], "Item RIP"); michael@0: is(gStartView._set.itemCount, gStartView.maxTiles, "Grid repopulated"); michael@0: michael@0: // --------- delete multiple items and restore michael@0: michael@0: let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: let initialLocation1 = gStartView._set.getIndexOfItem(item1); michael@0: let initialLocation2 = gStartView._set.getIndexOfItem(item2); michael@0: let initialLocation3 = gStartView._set.getIndexOfItem(item3); michael@0: michael@0: scrollToEnd(); michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: sendContextMenuClickToElement(window, item1, 10, 10); michael@0: sendContextMenuClickToElement(window, item2, 10, 10); michael@0: sendContextMenuClickToElement(window, item3, 10, 10); michael@0: yield promise; michael@0: michael@0: yield waitForCondition(() => !deleteButton.hidden); michael@0: michael@0: ok(!deleteButton.hidden, "Delete button is visible."); michael@0: michael@0: let promise = waitForCondition(() => !restoreButton.hidden); michael@0: EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: ok(!item1 && !item2 && !item3, "Items are not in grid"); michael@0: ok(HistoryTestHelper._nodes[uriFromIndex(0)] && HistoryTestHelper._nodes[uriFromIndex(5)] && HistoryTestHelper._nodes[uriFromIndex(12)], michael@0: "Items not deleted yet"); michael@0: ok(!restoreButton.hidden, "Restore button is visible."); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: EventUtils.synthesizeMouse(restoreButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: ok(item1 && item2 && item3, "Items are back in grid"); michael@0: ok(gStartView._set.getIndexOfItem(item1) === initialLocation1 && michael@0: gStartView._set.getIndexOfItem(item2) === initialLocation2 && michael@0: gStartView._set.getIndexOfItem(item3) === initialLocation3, "Items back in the same position."); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles, "Grid repopulated"); michael@0: michael@0: // --------- delete multiple items for good michael@0: michael@0: let item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: let item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: let item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: scrollToEnd(); michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: sendContextMenuClickToElement(window, item1, 10, 10); michael@0: sendContextMenuClickToElement(window, item2, 10, 10); michael@0: sendContextMenuClickToElement(window, item3, 10, 10); michael@0: yield promise; michael@0: michael@0: yield waitForCondition(() => !deleteButton.hidden); michael@0: michael@0: ok(!deleteButton.hidden, "Delete button is visible."); michael@0: michael@0: let promise = waitForCondition(() => !restoreButton.hidden); michael@0: EventUtils.synthesizeMouse(deleteButton, 10, 10, {}, window); michael@0: yield promise; michael@0: michael@0: item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: ok(!item1 && !item2 && !item3, "Items are not in grid"); michael@0: ok(HistoryTestHelper._nodes[uriFromIndex(0)] && HistoryTestHelper._nodes[uriFromIndex(5)] && HistoryTestHelper._nodes[uriFromIndex(12)], michael@0: "Items not deleted yet"); michael@0: ok(!restoreButton.hidden, "Restore button is visible."); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); michael@0: michael@0: let promise = waitForEvent(Elements.contextappbar, "transitionend", null, Elements.contextappbar); michael@0: Elements.contextappbar.dismiss(); michael@0: yield promise; michael@0: michael@0: item1 = gStartView._set.getItemsByUrl(uriFromIndex(0))[0]; michael@0: item2 = gStartView._set.getItemsByUrl(uriFromIndex(5))[0]; michael@0: item3 = gStartView._set.getItemsByUrl(uriFromIndex(12))[0]; michael@0: michael@0: ok(!item1 && !item2 && !item3, "Items are not in grid"); michael@0: ok(!HistoryTestHelper._nodes[uriFromIndex(0)] && !HistoryTestHelper._nodes[uriFromIndex(5)] && !HistoryTestHelper._nodes[uriFromIndex(12)], michael@0: "Items are gone"); michael@0: ok(gStartView._set.itemCount === gStartView.maxTiles - 1, "Grid repopulated"); michael@0: } michael@0: });