michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: var gStartDoc = null; michael@0: michael@0: function test() { michael@0: if (!isLandscapeMode()) { michael@0: todo(false, "browser_snapped_tests need landscape mode to run."); michael@0: return; michael@0: } michael@0: michael@0: runTests(); michael@0: } michael@0: michael@0: function showStartUI() { michael@0: if (!BrowserUI.isStartTabVisible) { michael@0: let tab = yield addTab("about:start"); michael@0: gStartDoc = tab.browser.contentWindow.document; michael@0: } else { michael@0: gStartDoc = Browser.selectedBrowser.contentWindow.document; michael@0: } michael@0: } michael@0: michael@0: function setUpSnapped() { michael@0: yield showStartUI(); michael@0: yield setSnappedViewstate(); michael@0: } michael@0: michael@0: function setUpPortrait() { michael@0: yield showStartUI(); michael@0: yield setPortraitViewstate(); michael@0: } michael@0: michael@0: function getNarrowTitle(aVboxId) { michael@0: let vbox = gStartDoc.getElementById(aVboxId); michael@0: return vbox.querySelector(".narrow-title"); michael@0: } michael@0: michael@0: function narrowTitleVisible(aVboxId) { michael@0: let title = getNarrowTitle(aVboxId); michael@0: let display = getComputedStyle(title).getPropertyValue("display"); michael@0: michael@0: return display !== "none"; michael@0: } michael@0: michael@0: function wideTitleVisible(aVboxId) { michael@0: let vbox = gStartDoc.getElementById(aVboxId); michael@0: let title = vbox.querySelector(".wide-title"); michael@0: let display = getComputedStyle(title).getPropertyValue("display"); michael@0: michael@0: return display !== "none"; michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "Test Snapped titles", michael@0: setUp: setUpSnapped, michael@0: run: function() { michael@0: ok(narrowTitleVisible("start-topsites"), "topsites narrow title is visible"); michael@0: ok(narrowTitleVisible("start-bookmarks"), "bookmarks narrow title is visible"); michael@0: ok(narrowTitleVisible("start-history"), "history narrow title is visible"); michael@0: michael@0: ok(!wideTitleVisible("start-topsites"), "topsites wide title is not visible"); michael@0: ok(!wideTitleVisible("start-bookmarks"), "bookmarks wide title is not visible"); michael@0: ok(!wideTitleVisible("start-history"), "history wide title is not visible"); michael@0: }, michael@0: tearDown: restoreViewstate michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Test Snapped titles", michael@0: setUp: setUpSnapped, michael@0: run: function() { michael@0: let topsites = gStartDoc.getElementById("start-topsites"); michael@0: let bookmarks = gStartDoc.getElementById("start-bookmarks"); michael@0: let history = gStartDoc.getElementById("start-history"); michael@0: michael@0: ok(topsites.hasAttribute("expanded"), "topsites is expanded"); michael@0: ok(!bookmarks.hasAttribute("expanded"), "bookmarks is collapsed"); michael@0: ok(!history.hasAttribute("expanded"), "history is collapsed"); michael@0: michael@0: // Expand bookmarks michael@0: sendElementTap(Browser.selectedBrowser.contentWindow, getNarrowTitle("start-bookmarks")); michael@0: michael@0: yield waitForCondition(() => bookmarks.hasAttribute("expanded")); michael@0: michael@0: ok(!topsites.hasAttribute("expanded"), "topsites is collapsed"); michael@0: ok(bookmarks.hasAttribute("expanded"), "bookmarks is expanded"); michael@0: ok(!history.hasAttribute("expanded"), "history is collapsed"); michael@0: }, michael@0: tearDown: restoreViewstate michael@0: }); michael@0: michael@0: /* Disabled because it breaks at specific screen sizes (bug 936735). michael@0: gTests.push({ michael@0: desc: "Test Snapped scrolls vertically", michael@0: setUp: function() { michael@0: michael@0: // Populate with mock data and expand bookmarks michael@0: BookmarksTestHelper.setup(); michael@0: sendElementTap(Browser.selectedBrowser.contentWindow, getNarrowTitle("start-bookmarks")); michael@0: michael@0: yield waitForCondition(() => gStartDoc.getElementById("start-bookmarks").hasAttribute("expanded")); michael@0: michael@0: yield setUpSnapped(); michael@0: }, michael@0: run: function() { michael@0: ok(Browser.selectedBrowser.contentWindow.scrollMaxY !== 0, "Snapped scrolls vertically"); michael@0: ok(Browser.selectedBrowser.contentWindow.scrollMaxX === 0, "Snapped does not scroll horizontally"); michael@0: }, michael@0: tearDown: function() { michael@0: BookmarksTestHelper.restore(); michael@0: yield restoreViewstate(); michael@0: } michael@0: }); michael@0: */ michael@0: michael@0: gTests.push({ michael@0: desc: "Test tile selection is cleared and disabled", michael@0: setUp: function() { michael@0: BookmarksTestHelper.setup(); michael@0: HistoryTestHelper.setup(); michael@0: showStartUI(); michael@0: }, michael@0: run: function() { michael@0: // minimal event mocking to trigger context-click handlers michael@0: function makeMockEvent(item) { michael@0: return { michael@0: stopPropagation: function() {}, michael@0: target: item michael@0: }; michael@0: } michael@0: let startWin = Browser.selectedBrowser.contentWindow; michael@0: // make sure the bookmarks grid is showing michael@0: startWin.StartUI.onNarrowTitleClick("start-bookmarks"); michael@0: let bookmarksGrid = startWin.document.querySelector("#start-bookmarks-grid"); michael@0: // sanity check michael@0: ok(bookmarksGrid, "matched bookmarks grid"); michael@0: ok(bookmarksGrid.children[0], "bookmarks grid has items"); michael@0: // select a tile (balancing implementation leakage with test simplicity) michael@0: let mockEvent = makeMockEvent(bookmarksGrid.children[0]); michael@0: bookmarksGrid.handleItemContextMenu(bookmarksGrid.children[0], mockEvent); michael@0: // check tile was selected michael@0: is(bookmarksGrid.selectedItems.length, 1, "Tile got selected in landscape view"); michael@0: // switch to snapped view michael@0: yield setSnappedViewstate(); michael@0: is(bookmarksGrid.selectedItems.length, 0, "grid items selection cleared in snapped view"); michael@0: // attempt to select a tile in snapped view michael@0: mockEvent = makeMockEvent(bookmarksGrid.children[0]); michael@0: bookmarksGrid.handleItemContextMenu(bookmarksGrid.children[0], mockEvent); michael@0: is(bookmarksGrid.selectedItems.length, 0, "no grid item selections possible in snapped view"); michael@0: }, michael@0: tearDown: function() { michael@0: BookmarksTestHelper.restore(); michael@0: HistoryTestHelper.restore(); michael@0: yield restoreViewstate(); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Navbar contextual buttons are not shown in snapped", michael@0: setUp: setUpSnapped, michael@0: run: function() { michael@0: let toolbarContextual = document.getElementById("toolbar-contextual"); michael@0: let visibility = getComputedStyle(toolbarContextual).getPropertyValue("visibility"); michael@0: ok(visibility === "collapse" || visibility === "hidden", "Contextual buttons not shown in navbar"); michael@0: }, michael@0: tearDown: restoreViewstate michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Test Portrait titles", michael@0: setUp: setUpPortrait, michael@0: run: function() { michael@0: // Check title visibility michael@0: ok(!narrowTitleVisible("start-topsites"), "topsites narrow title is not visible"); michael@0: ok(!narrowTitleVisible("start-bookmarks"), "bookmarks narrow title is not visible"); michael@0: ok(!narrowTitleVisible("start-history"), "history narrow title is not visible"); michael@0: michael@0: ok(wideTitleVisible("start-topsites"), "topsites wide title is visible"); michael@0: ok(wideTitleVisible("start-bookmarks"), "bookmarks wide title is visible"); michael@0: ok(wideTitleVisible("start-history"), "history wide title is visible"); michael@0: }, michael@0: tearDown: restoreViewstate michael@0: }); michael@0: michael@0: /* Disabled because it breaks at specific screen sizes (bug 936735). michael@0: gTests.push({ michael@0: desc: "Test portrait scrolls vertically", michael@0: setUp: function() { michael@0: // Populate with mock data michael@0: BookmarksTestHelper.setup(); michael@0: HistoryTestHelper.setup(); michael@0: michael@0: yield setUpPortrait(); michael@0: }, michael@0: run: function() { michael@0: ok(Browser.selectedBrowser.contentWindow.scrollMaxY !== 0, "Portrait scrolls vertically"); michael@0: ok(Browser.selectedBrowser.contentWindow.scrollMaxX === 0, "Portrait does not scroll horizontally"); michael@0: }, michael@0: tearDown: function() { michael@0: BookmarksTestHelper.restore(); michael@0: HistoryTestHelper.restore(); michael@0: yield restoreViewstate(); michael@0: } michael@0: }); michael@0: */