browser/metro/base/tests/mochitest/browser_menu_hoverstate.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 function test() {
     8   if (!isLandscapeMode()) {
     9     todo(false, "browser_snapped_tests need landscape mode to run.");
    10     return;
    11   }
    13   runTests();
    14 }
    15 let tabAdded = false;
    17 function setUp() {
    18   if (!tabAdded) {
    19     yield addTab(chromeRoot + "res/textdivs01.html");
    20     tabAdded = true;
    21   }
    22   yield hideContextUI();
    23 }
    25 XPCOMUtils.defineLazyServiceGetter(this, "gDOMUtils",
    26   "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils");
    28 const kActiveState = 0x00000001;
    29 const kHoverState = 0x00000004;
    31 gTests.push({
    32   desc: "hover states of menus",
    33   setUp: setUp,
    34   run: function() {
    35     // Clicking on menu items should not leave the clicked menu item
    36     // in the :active or :hover state.
    38     let typesArray = [
    39       "copy",
    40       "paste"
    41     ];
    43     let promise = waitForEvent(document, "popupshown");
    44     ContextMenuUI.showContextMenu({
    45       target: null,
    46       json: {
    47         types: typesArray,
    48         string: '',
    49         xPos: 1,
    50         yPos: 1,
    51         leftAligned: true,
    52         bottomAligned: true
    53     }});
    54     yield promise;
    56     // should be visible
    57     ok(ContextMenuUI._menuPopup.visible, "is visible");
    59     let menuItem = document.getElementById("context-copy");
    60     promise = waitForEvent(document, "popuphidden");
    61     sendNativeTap(menuItem);
    62     yield promise;
    64     for (let idx = 0; idx < ContextMenuUI.commands.childNodes.length; idx++) {
    65       let item = ContextMenuUI.commands.childNodes[idx];
    66       let state = gDOMUtils.getContentState(item);
    67       if ((state & kHoverState) || (state & kActiveState)) {
    68         ok(false, "found invalid state on context menu item (" + state.toString(2) + ")");
    69       }
    70     }
    72     // Do it again, but this time check the visible menu too and
    73     // click a different menu item.
    74     promise = waitForEvent(document, "popupshown");
    75     ContextMenuUI.showContextMenu({
    76       target: null,
    77       json: {
    78         types: typesArray,
    79         string: '',
    80         xPos: 1,
    81         yPos: 1,
    82         leftAligned: true,
    83         bottomAligned: true
    84     }});
    85     yield promise;
    87     // should be visible
    88     ok(ContextMenuUI._menuPopup.visible, "is visible");
    90     for (let idx = 0; idx < ContextMenuUI.commands.childNodes.length; idx++) {
    91       let item = ContextMenuUI.commands.childNodes[idx];
    92       let state = gDOMUtils.getContentState(item);
    93       if ((state & kHoverState) || (state & kActiveState)) {
    94         ok(false, "found invalid state on context menu item (" + state.toString(2) + ")");
    95       }
    96     }
    98     menuItem = document.getElementById("context-paste");
    99     promise = waitForEvent(document, "popuphidden");
   100     sendNativeTap(menuItem);
   101     yield promise;
   103     for (let idx = 0; idx < ContextMenuUI.commands.childNodes.length; idx++) {
   104       let item = ContextMenuUI.commands.childNodes[idx];
   105       let state = gDOMUtils.getContentState(item);
   106       if ((state & kHoverState) || (state & kActiveState)) {
   107         ok(false, "found invalid state on context menu item (" + state.toString(2) + ")");
   108       }
   109     }
   110   },
   111   tearDown: function () {
   112     clearNativeTouchSequence();
   113   }
   114 });
   116 gTests.push({
   117   desc: "hover states of nav bar buttons",
   118   setUp: setUp,
   119   run: function() {
   120     // show nav bar
   121     yield showNavBar();
   123     // tap bookmark button
   124     sendNativeTap(Appbar.starButton);
   125     yield waitForMs(100);
   127     // check hover state
   128     let state = gDOMUtils.getContentState(Appbar.starButton);
   129     if ((state & kHoverState) || (state & kActiveState)) {
   130       ok(false, "found invalid state on star button (" + state.toString(2) + ")");
   131     }
   133     // tap bookmark button
   134     sendNativeTap(Appbar.starButton);
   135     yield waitForMs(100);
   137     // check hover state
   138     let state = gDOMUtils.getContentState(Appbar.starButton);
   139     if ((state & kHoverState) || (state & kActiveState)) {
   140       ok(false, "found invalid state on star button (" + state.toString(2) + ")");
   141     }
   142   },
   143   tearDown: function () {
   144     clearNativeTouchSequence();
   145   }
   146 });

mercurial