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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_snappedState.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +var gStartDoc = null;
    1.11 +
    1.12 +function test() {
    1.13 +  if (!isLandscapeMode()) {
    1.14 +    todo(false, "browser_snapped_tests need landscape mode to run.");
    1.15 +    return;
    1.16 +  }
    1.17 +
    1.18 +  runTests();
    1.19 +}
    1.20 +
    1.21 +function showStartUI() {
    1.22 +  if (!BrowserUI.isStartTabVisible) {
    1.23 +    let tab = yield addTab("about:start");
    1.24 +    gStartDoc = tab.browser.contentWindow.document;
    1.25 +  } else {
    1.26 +    gStartDoc = Browser.selectedBrowser.contentWindow.document;
    1.27 +  }
    1.28 +}
    1.29 +
    1.30 +function setUpSnapped() {
    1.31 +  yield showStartUI();
    1.32 +  yield setSnappedViewstate();
    1.33 +}
    1.34 +
    1.35 +function setUpPortrait() {
    1.36 +  yield showStartUI();
    1.37 +  yield setPortraitViewstate();
    1.38 +}
    1.39 +
    1.40 +function getNarrowTitle(aVboxId) {
    1.41 +  let vbox = gStartDoc.getElementById(aVboxId);
    1.42 +  return vbox.querySelector(".narrow-title");
    1.43 +}
    1.44 +
    1.45 +function narrowTitleVisible(aVboxId) {
    1.46 +  let title = getNarrowTitle(aVboxId);
    1.47 +  let display = getComputedStyle(title).getPropertyValue("display");
    1.48 +
    1.49 +  return display !== "none";
    1.50 +}
    1.51 +
    1.52 +function wideTitleVisible(aVboxId) {
    1.53 +  let vbox = gStartDoc.getElementById(aVboxId);
    1.54 +  let title = vbox.querySelector(".wide-title");
    1.55 +  let display = getComputedStyle(title).getPropertyValue("display");
    1.56 +
    1.57 +  return display !== "none";
    1.58 +}
    1.59 +
    1.60 +gTests.push({
    1.61 +  desc: "Test Snapped titles",
    1.62 +  setUp: setUpSnapped,
    1.63 +  run: function() {
    1.64 +    ok(narrowTitleVisible("start-topsites"), "topsites narrow title is visible");
    1.65 +    ok(narrowTitleVisible("start-bookmarks"), "bookmarks narrow title is visible");
    1.66 +    ok(narrowTitleVisible("start-history"), "history narrow title is visible");
    1.67 +
    1.68 +    ok(!wideTitleVisible("start-topsites"), "topsites wide title is not visible");
    1.69 +    ok(!wideTitleVisible("start-bookmarks"), "bookmarks wide title is not visible");
    1.70 +    ok(!wideTitleVisible("start-history"), "history wide title is not visible");
    1.71 +  },
    1.72 +  tearDown: restoreViewstate
    1.73 +});
    1.74 +
    1.75 +gTests.push({
    1.76 +  desc: "Test Snapped titles",
    1.77 +  setUp: setUpSnapped,
    1.78 +  run: function() {
    1.79 +    let topsites = gStartDoc.getElementById("start-topsites");
    1.80 +    let bookmarks = gStartDoc.getElementById("start-bookmarks");
    1.81 +    let history = gStartDoc.getElementById("start-history");
    1.82 +
    1.83 +    ok(topsites.hasAttribute("expanded"), "topsites is expanded");
    1.84 +    ok(!bookmarks.hasAttribute("expanded"), "bookmarks is collapsed");
    1.85 +    ok(!history.hasAttribute("expanded"), "history is collapsed");
    1.86 +
    1.87 +    // Expand bookmarks
    1.88 +    sendElementTap(Browser.selectedBrowser.contentWindow, getNarrowTitle("start-bookmarks"));
    1.89 +
    1.90 +    yield waitForCondition(() => bookmarks.hasAttribute("expanded"));
    1.91 +
    1.92 +    ok(!topsites.hasAttribute("expanded"), "topsites is collapsed");
    1.93 +    ok(bookmarks.hasAttribute("expanded"), "bookmarks is expanded");
    1.94 +    ok(!history.hasAttribute("expanded"), "history is collapsed");
    1.95 +  },
    1.96 +  tearDown: restoreViewstate
    1.97 +});
    1.98 +
    1.99 +/* Disabled because it breaks at specific screen sizes (bug 936735).
   1.100 +gTests.push({
   1.101 +  desc: "Test Snapped scrolls vertically",
   1.102 +  setUp: function() {
   1.103 +
   1.104 +    // Populate with mock data and expand bookmarks
   1.105 +    BookmarksTestHelper.setup();
   1.106 +    sendElementTap(Browser.selectedBrowser.contentWindow, getNarrowTitle("start-bookmarks"));
   1.107 +
   1.108 +    yield waitForCondition(() => gStartDoc.getElementById("start-bookmarks").hasAttribute("expanded"));
   1.109 +
   1.110 +    yield setUpSnapped();
   1.111 +  },
   1.112 +  run: function() {
   1.113 +    ok(Browser.selectedBrowser.contentWindow.scrollMaxY !== 0, "Snapped scrolls vertically");
   1.114 +    ok(Browser.selectedBrowser.contentWindow.scrollMaxX === 0, "Snapped does not scroll horizontally");
   1.115 +  },
   1.116 +  tearDown: function() {
   1.117 +    BookmarksTestHelper.restore();
   1.118 +    yield restoreViewstate();
   1.119 +  }
   1.120 +});
   1.121 +*/
   1.122 +
   1.123 +gTests.push({
   1.124 +  desc: "Test tile selection is cleared and disabled",
   1.125 +  setUp: function() {
   1.126 +    BookmarksTestHelper.setup();
   1.127 +    HistoryTestHelper.setup();
   1.128 +    showStartUI();
   1.129 +  },
   1.130 +  run: function() {
   1.131 +    // minimal event mocking to trigger context-click handlers
   1.132 +    function makeMockEvent(item) {
   1.133 +      return {
   1.134 +        stopPropagation: function() {},
   1.135 +        target: item
   1.136 +      };
   1.137 +    }
   1.138 +    let startWin = Browser.selectedBrowser.contentWindow;
   1.139 +    // make sure the bookmarks grid is showing
   1.140 +    startWin.StartUI.onNarrowTitleClick("start-bookmarks");
   1.141 +    let bookmarksGrid = startWin.document.querySelector("#start-bookmarks-grid");
   1.142 +    // sanity check
   1.143 +    ok(bookmarksGrid, "matched bookmarks grid");
   1.144 +    ok(bookmarksGrid.children[0], "bookmarks grid has items");
   1.145 +    // select a tile (balancing implementation leakage with test simplicity)
   1.146 +    let mockEvent = makeMockEvent(bookmarksGrid.children[0]);
   1.147 +    bookmarksGrid.handleItemContextMenu(bookmarksGrid.children[0], mockEvent);
   1.148 +    // check tile was selected
   1.149 +    is(bookmarksGrid.selectedItems.length, 1, "Tile got selected in landscape view");
   1.150 +    // switch to snapped view
   1.151 +    yield setSnappedViewstate();
   1.152 +    is(bookmarksGrid.selectedItems.length, 0, "grid items selection cleared in snapped view");
   1.153 +    // attempt to select a tile in snapped view
   1.154 +    mockEvent = makeMockEvent(bookmarksGrid.children[0]);
   1.155 +    bookmarksGrid.handleItemContextMenu(bookmarksGrid.children[0], mockEvent);
   1.156 +    is(bookmarksGrid.selectedItems.length, 0, "no grid item selections possible in snapped view");
   1.157 +  },
   1.158 +  tearDown: function() {
   1.159 +    BookmarksTestHelper.restore();
   1.160 +    HistoryTestHelper.restore();
   1.161 +    yield restoreViewstate();
   1.162 +  }
   1.163 +});
   1.164 +
   1.165 +gTests.push({
   1.166 +  desc: "Navbar contextual buttons are not shown in snapped",
   1.167 +  setUp: setUpSnapped,
   1.168 +  run: function() {
   1.169 +    let toolbarContextual = document.getElementById("toolbar-contextual");
   1.170 +    let visibility = getComputedStyle(toolbarContextual).getPropertyValue("visibility");
   1.171 +    ok(visibility === "collapse" || visibility === "hidden", "Contextual buttons not shown in navbar");
   1.172 +  },
   1.173 +  tearDown: restoreViewstate
   1.174 +});
   1.175 +
   1.176 +gTests.push({
   1.177 +  desc: "Test Portrait titles",
   1.178 +  setUp: setUpPortrait,
   1.179 +  run: function() {
   1.180 +    // Check title visibility
   1.181 +    ok(!narrowTitleVisible("start-topsites"), "topsites narrow title is not visible");
   1.182 +    ok(!narrowTitleVisible("start-bookmarks"), "bookmarks narrow title is not visible");
   1.183 +    ok(!narrowTitleVisible("start-history"), "history narrow title is not visible");
   1.184 +
   1.185 +    ok(wideTitleVisible("start-topsites"), "topsites wide title is visible");
   1.186 +    ok(wideTitleVisible("start-bookmarks"), "bookmarks wide title is visible");
   1.187 +    ok(wideTitleVisible("start-history"), "history wide title is visible");
   1.188 +  },
   1.189 +  tearDown: restoreViewstate
   1.190 +});
   1.191 +
   1.192 +/* Disabled because it breaks at specific screen sizes (bug 936735).
   1.193 +gTests.push({
   1.194 +  desc: "Test portrait scrolls vertically",
   1.195 +  setUp: function() {
   1.196 +    // Populate with mock data
   1.197 +    BookmarksTestHelper.setup();
   1.198 +    HistoryTestHelper.setup();
   1.199 +
   1.200 +    yield setUpPortrait();
   1.201 +  },
   1.202 +  run: function() {
   1.203 +    ok(Browser.selectedBrowser.contentWindow.scrollMaxY !== 0, "Portrait scrolls vertically");
   1.204 +    ok(Browser.selectedBrowser.contentWindow.scrollMaxX === 0, "Portrait does not scroll horizontally");
   1.205 +  },
   1.206 +  tearDown: function() {
   1.207 +    BookmarksTestHelper.restore();
   1.208 +    HistoryTestHelper.restore();
   1.209 +    yield restoreViewstate();
   1.210 +  }
   1.211 +});
   1.212 +*/

mercurial