1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/browser_menu_hoverstate.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,147 @@ 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 +function test() { 1.11 + if (!isLandscapeMode()) { 1.12 + todo(false, "browser_snapped_tests need landscape mode to run."); 1.13 + return; 1.14 + } 1.15 + 1.16 + runTests(); 1.17 +} 1.18 +let tabAdded = false; 1.19 + 1.20 +function setUp() { 1.21 + if (!tabAdded) { 1.22 + yield addTab(chromeRoot + "res/textdivs01.html"); 1.23 + tabAdded = true; 1.24 + } 1.25 + yield hideContextUI(); 1.26 +} 1.27 + 1.28 +XPCOMUtils.defineLazyServiceGetter(this, "gDOMUtils", 1.29 + "@mozilla.org/inspector/dom-utils;1", "inIDOMUtils"); 1.30 + 1.31 +const kActiveState = 0x00000001; 1.32 +const kHoverState = 0x00000004; 1.33 + 1.34 +gTests.push({ 1.35 + desc: "hover states of menus", 1.36 + setUp: setUp, 1.37 + run: function() { 1.38 + // Clicking on menu items should not leave the clicked menu item 1.39 + // in the :active or :hover state. 1.40 + 1.41 + let typesArray = [ 1.42 + "copy", 1.43 + "paste" 1.44 + ]; 1.45 + 1.46 + let promise = waitForEvent(document, "popupshown"); 1.47 + ContextMenuUI.showContextMenu({ 1.48 + target: null, 1.49 + json: { 1.50 + types: typesArray, 1.51 + string: '', 1.52 + xPos: 1, 1.53 + yPos: 1, 1.54 + leftAligned: true, 1.55 + bottomAligned: true 1.56 + }}); 1.57 + yield promise; 1.58 + 1.59 + // should be visible 1.60 + ok(ContextMenuUI._menuPopup.visible, "is visible"); 1.61 + 1.62 + let menuItem = document.getElementById("context-copy"); 1.63 + promise = waitForEvent(document, "popuphidden"); 1.64 + sendNativeTap(menuItem); 1.65 + yield promise; 1.66 + 1.67 + for (let idx = 0; idx < ContextMenuUI.commands.childNodes.length; idx++) { 1.68 + let item = ContextMenuUI.commands.childNodes[idx]; 1.69 + let state = gDOMUtils.getContentState(item); 1.70 + if ((state & kHoverState) || (state & kActiveState)) { 1.71 + ok(false, "found invalid state on context menu item (" + state.toString(2) + ")"); 1.72 + } 1.73 + } 1.74 + 1.75 + // Do it again, but this time check the visible menu too and 1.76 + // click a different menu item. 1.77 + promise = waitForEvent(document, "popupshown"); 1.78 + ContextMenuUI.showContextMenu({ 1.79 + target: null, 1.80 + json: { 1.81 + types: typesArray, 1.82 + string: '', 1.83 + xPos: 1, 1.84 + yPos: 1, 1.85 + leftAligned: true, 1.86 + bottomAligned: true 1.87 + }}); 1.88 + yield promise; 1.89 + 1.90 + // should be visible 1.91 + ok(ContextMenuUI._menuPopup.visible, "is visible"); 1.92 + 1.93 + for (let idx = 0; idx < ContextMenuUI.commands.childNodes.length; idx++) { 1.94 + let item = ContextMenuUI.commands.childNodes[idx]; 1.95 + let state = gDOMUtils.getContentState(item); 1.96 + if ((state & kHoverState) || (state & kActiveState)) { 1.97 + ok(false, "found invalid state on context menu item (" + state.toString(2) + ")"); 1.98 + } 1.99 + } 1.100 + 1.101 + menuItem = document.getElementById("context-paste"); 1.102 + promise = waitForEvent(document, "popuphidden"); 1.103 + sendNativeTap(menuItem); 1.104 + yield promise; 1.105 + 1.106 + for (let idx = 0; idx < ContextMenuUI.commands.childNodes.length; idx++) { 1.107 + let item = ContextMenuUI.commands.childNodes[idx]; 1.108 + let state = gDOMUtils.getContentState(item); 1.109 + if ((state & kHoverState) || (state & kActiveState)) { 1.110 + ok(false, "found invalid state on context menu item (" + state.toString(2) + ")"); 1.111 + } 1.112 + } 1.113 + }, 1.114 + tearDown: function () { 1.115 + clearNativeTouchSequence(); 1.116 + } 1.117 +}); 1.118 + 1.119 +gTests.push({ 1.120 + desc: "hover states of nav bar buttons", 1.121 + setUp: setUp, 1.122 + run: function() { 1.123 + // show nav bar 1.124 + yield showNavBar(); 1.125 + 1.126 + // tap bookmark button 1.127 + sendNativeTap(Appbar.starButton); 1.128 + yield waitForMs(100); 1.129 + 1.130 + // check hover state 1.131 + let state = gDOMUtils.getContentState(Appbar.starButton); 1.132 + if ((state & kHoverState) || (state & kActiveState)) { 1.133 + ok(false, "found invalid state on star button (" + state.toString(2) + ")"); 1.134 + } 1.135 + 1.136 + // tap bookmark button 1.137 + sendNativeTap(Appbar.starButton); 1.138 + yield waitForMs(100); 1.139 + 1.140 + // check hover state 1.141 + let state = gDOMUtils.getContentState(Appbar.starButton); 1.142 + if ((state & kHoverState) || (state & kActiveState)) { 1.143 + ok(false, "found invalid state on star button (" + state.toString(2) + ")"); 1.144 + } 1.145 + }, 1.146 + tearDown: function () { 1.147 + clearNativeTouchSequence(); 1.148 + } 1.149 +}); 1.150 +