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

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

mercurial