browser/metro/base/tests/mochitest/browser_snappedState.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

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 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 var gStartDoc = null;
michael@0 8
michael@0 9 function test() {
michael@0 10 if (!isLandscapeMode()) {
michael@0 11 todo(false, "browser_snapped_tests need landscape mode to run.");
michael@0 12 return;
michael@0 13 }
michael@0 14
michael@0 15 runTests();
michael@0 16 }
michael@0 17
michael@0 18 function showStartUI() {
michael@0 19 if (!BrowserUI.isStartTabVisible) {
michael@0 20 let tab = yield addTab("about:start");
michael@0 21 gStartDoc = tab.browser.contentWindow.document;
michael@0 22 } else {
michael@0 23 gStartDoc = Browser.selectedBrowser.contentWindow.document;
michael@0 24 }
michael@0 25 }
michael@0 26
michael@0 27 function setUpSnapped() {
michael@0 28 yield showStartUI();
michael@0 29 yield setSnappedViewstate();
michael@0 30 }
michael@0 31
michael@0 32 function setUpPortrait() {
michael@0 33 yield showStartUI();
michael@0 34 yield setPortraitViewstate();
michael@0 35 }
michael@0 36
michael@0 37 function getNarrowTitle(aVboxId) {
michael@0 38 let vbox = gStartDoc.getElementById(aVboxId);
michael@0 39 return vbox.querySelector(".narrow-title");
michael@0 40 }
michael@0 41
michael@0 42 function narrowTitleVisible(aVboxId) {
michael@0 43 let title = getNarrowTitle(aVboxId);
michael@0 44 let display = getComputedStyle(title).getPropertyValue("display");
michael@0 45
michael@0 46 return display !== "none";
michael@0 47 }
michael@0 48
michael@0 49 function wideTitleVisible(aVboxId) {
michael@0 50 let vbox = gStartDoc.getElementById(aVboxId);
michael@0 51 let title = vbox.querySelector(".wide-title");
michael@0 52 let display = getComputedStyle(title).getPropertyValue("display");
michael@0 53
michael@0 54 return display !== "none";
michael@0 55 }
michael@0 56
michael@0 57 gTests.push({
michael@0 58 desc: "Test Snapped titles",
michael@0 59 setUp: setUpSnapped,
michael@0 60 run: function() {
michael@0 61 ok(narrowTitleVisible("start-topsites"), "topsites narrow title is visible");
michael@0 62 ok(narrowTitleVisible("start-bookmarks"), "bookmarks narrow title is visible");
michael@0 63 ok(narrowTitleVisible("start-history"), "history narrow title is visible");
michael@0 64
michael@0 65 ok(!wideTitleVisible("start-topsites"), "topsites wide title is not visible");
michael@0 66 ok(!wideTitleVisible("start-bookmarks"), "bookmarks wide title is not visible");
michael@0 67 ok(!wideTitleVisible("start-history"), "history wide title is not visible");
michael@0 68 },
michael@0 69 tearDown: restoreViewstate
michael@0 70 });
michael@0 71
michael@0 72 gTests.push({
michael@0 73 desc: "Test Snapped titles",
michael@0 74 setUp: setUpSnapped,
michael@0 75 run: function() {
michael@0 76 let topsites = gStartDoc.getElementById("start-topsites");
michael@0 77 let bookmarks = gStartDoc.getElementById("start-bookmarks");
michael@0 78 let history = gStartDoc.getElementById("start-history");
michael@0 79
michael@0 80 ok(topsites.hasAttribute("expanded"), "topsites is expanded");
michael@0 81 ok(!bookmarks.hasAttribute("expanded"), "bookmarks is collapsed");
michael@0 82 ok(!history.hasAttribute("expanded"), "history is collapsed");
michael@0 83
michael@0 84 // Expand bookmarks
michael@0 85 sendElementTap(Browser.selectedBrowser.contentWindow, getNarrowTitle("start-bookmarks"));
michael@0 86
michael@0 87 yield waitForCondition(() => bookmarks.hasAttribute("expanded"));
michael@0 88
michael@0 89 ok(!topsites.hasAttribute("expanded"), "topsites is collapsed");
michael@0 90 ok(bookmarks.hasAttribute("expanded"), "bookmarks is expanded");
michael@0 91 ok(!history.hasAttribute("expanded"), "history is collapsed");
michael@0 92 },
michael@0 93 tearDown: restoreViewstate
michael@0 94 });
michael@0 95
michael@0 96 /* Disabled because it breaks at specific screen sizes (bug 936735).
michael@0 97 gTests.push({
michael@0 98 desc: "Test Snapped scrolls vertically",
michael@0 99 setUp: function() {
michael@0 100
michael@0 101 // Populate with mock data and expand bookmarks
michael@0 102 BookmarksTestHelper.setup();
michael@0 103 sendElementTap(Browser.selectedBrowser.contentWindow, getNarrowTitle("start-bookmarks"));
michael@0 104
michael@0 105 yield waitForCondition(() => gStartDoc.getElementById("start-bookmarks").hasAttribute("expanded"));
michael@0 106
michael@0 107 yield setUpSnapped();
michael@0 108 },
michael@0 109 run: function() {
michael@0 110 ok(Browser.selectedBrowser.contentWindow.scrollMaxY !== 0, "Snapped scrolls vertically");
michael@0 111 ok(Browser.selectedBrowser.contentWindow.scrollMaxX === 0, "Snapped does not scroll horizontally");
michael@0 112 },
michael@0 113 tearDown: function() {
michael@0 114 BookmarksTestHelper.restore();
michael@0 115 yield restoreViewstate();
michael@0 116 }
michael@0 117 });
michael@0 118 */
michael@0 119
michael@0 120 gTests.push({
michael@0 121 desc: "Test tile selection is cleared and disabled",
michael@0 122 setUp: function() {
michael@0 123 BookmarksTestHelper.setup();
michael@0 124 HistoryTestHelper.setup();
michael@0 125 showStartUI();
michael@0 126 },
michael@0 127 run: function() {
michael@0 128 // minimal event mocking to trigger context-click handlers
michael@0 129 function makeMockEvent(item) {
michael@0 130 return {
michael@0 131 stopPropagation: function() {},
michael@0 132 target: item
michael@0 133 };
michael@0 134 }
michael@0 135 let startWin = Browser.selectedBrowser.contentWindow;
michael@0 136 // make sure the bookmarks grid is showing
michael@0 137 startWin.StartUI.onNarrowTitleClick("start-bookmarks");
michael@0 138 let bookmarksGrid = startWin.document.querySelector("#start-bookmarks-grid");
michael@0 139 // sanity check
michael@0 140 ok(bookmarksGrid, "matched bookmarks grid");
michael@0 141 ok(bookmarksGrid.children[0], "bookmarks grid has items");
michael@0 142 // select a tile (balancing implementation leakage with test simplicity)
michael@0 143 let mockEvent = makeMockEvent(bookmarksGrid.children[0]);
michael@0 144 bookmarksGrid.handleItemContextMenu(bookmarksGrid.children[0], mockEvent);
michael@0 145 // check tile was selected
michael@0 146 is(bookmarksGrid.selectedItems.length, 1, "Tile got selected in landscape view");
michael@0 147 // switch to snapped view
michael@0 148 yield setSnappedViewstate();
michael@0 149 is(bookmarksGrid.selectedItems.length, 0, "grid items selection cleared in snapped view");
michael@0 150 // attempt to select a tile in snapped view
michael@0 151 mockEvent = makeMockEvent(bookmarksGrid.children[0]);
michael@0 152 bookmarksGrid.handleItemContextMenu(bookmarksGrid.children[0], mockEvent);
michael@0 153 is(bookmarksGrid.selectedItems.length, 0, "no grid item selections possible in snapped view");
michael@0 154 },
michael@0 155 tearDown: function() {
michael@0 156 BookmarksTestHelper.restore();
michael@0 157 HistoryTestHelper.restore();
michael@0 158 yield restoreViewstate();
michael@0 159 }
michael@0 160 });
michael@0 161
michael@0 162 gTests.push({
michael@0 163 desc: "Navbar contextual buttons are not shown in snapped",
michael@0 164 setUp: setUpSnapped,
michael@0 165 run: function() {
michael@0 166 let toolbarContextual = document.getElementById("toolbar-contextual");
michael@0 167 let visibility = getComputedStyle(toolbarContextual).getPropertyValue("visibility");
michael@0 168 ok(visibility === "collapse" || visibility === "hidden", "Contextual buttons not shown in navbar");
michael@0 169 },
michael@0 170 tearDown: restoreViewstate
michael@0 171 });
michael@0 172
michael@0 173 gTests.push({
michael@0 174 desc: "Test Portrait titles",
michael@0 175 setUp: setUpPortrait,
michael@0 176 run: function() {
michael@0 177 // Check title visibility
michael@0 178 ok(!narrowTitleVisible("start-topsites"), "topsites narrow title is not visible");
michael@0 179 ok(!narrowTitleVisible("start-bookmarks"), "bookmarks narrow title is not visible");
michael@0 180 ok(!narrowTitleVisible("start-history"), "history narrow title is not visible");
michael@0 181
michael@0 182 ok(wideTitleVisible("start-topsites"), "topsites wide title is visible");
michael@0 183 ok(wideTitleVisible("start-bookmarks"), "bookmarks wide title is visible");
michael@0 184 ok(wideTitleVisible("start-history"), "history wide title is visible");
michael@0 185 },
michael@0 186 tearDown: restoreViewstate
michael@0 187 });
michael@0 188
michael@0 189 /* Disabled because it breaks at specific screen sizes (bug 936735).
michael@0 190 gTests.push({
michael@0 191 desc: "Test portrait scrolls vertically",
michael@0 192 setUp: function() {
michael@0 193 // Populate with mock data
michael@0 194 BookmarksTestHelper.setup();
michael@0 195 HistoryTestHelper.setup();
michael@0 196
michael@0 197 yield setUpPortrait();
michael@0 198 },
michael@0 199 run: function() {
michael@0 200 ok(Browser.selectedBrowser.contentWindow.scrollMaxY !== 0, "Portrait scrolls vertically");
michael@0 201 ok(Browser.selectedBrowser.contentWindow.scrollMaxX === 0, "Portrait does not scroll horizontally");
michael@0 202 },
michael@0 203 tearDown: function() {
michael@0 204 BookmarksTestHelper.restore();
michael@0 205 HistoryTestHelper.restore();
michael@0 206 yield restoreViewstate();
michael@0 207 }
michael@0 208 });
michael@0 209 */

mercurial