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

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

mercurial