test_contextmenu.html (3719B)
1 <html> 2 3 <head> 4 <title>Context menu tests</title> 5 6 <link rel="stylesheet" type="text/css" 7 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 8 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 11 12 <script type="application/javascript" 13 src="../common.js"></script> 14 <script type="application/javascript" 15 src="../role.js"></script> 16 <script type="application/javascript" 17 src="../states.js"></script> 18 <script type="application/javascript" 19 src="../events.js"></script> 20 21 <script type="application/javascript"> 22 // ////////////////////////////////////////////////////////////////////////// 23 // Invokers 24 25 function showContextMenu(aID) { 26 this.DOMNode = getNode(aID); 27 28 this.eventSeq = [ 29 new invokerChecker(EVENT_MENUPOPUP_START, getContextMenuNode()), 30 ]; 31 32 this.invoke = function showContextMenu_invoke() { 33 synthesizeMouse(this.DOMNode, 4, 4, { type: "contextmenu", button: 2 }); 34 }; 35 36 this.getID = function showContextMenu_getID() { 37 return "show context menu"; 38 }; 39 } 40 41 function selectMenuItem() { 42 this.eventSeq = [ 43 new invokerChecker(EVENT_FOCUS, getFocusedMenuItem), 44 ]; 45 46 this.invoke = function selectMenuItem_invoke() { 47 synthesizeKey("KEY_ArrowDown"); 48 }; 49 50 this.getID = function selectMenuItem_getID() { 51 return "select first menuitem"; 52 }; 53 } 54 55 function closeContextMenu() { 56 this.eventSeq = [ 57 new invokerChecker(EVENT_MENUPOPUP_END, 58 getAccessible(getContextMenuNode())), 59 ]; 60 61 this.invoke = function closeContextMenu_invoke() { 62 synthesizeKey("KEY_Escape"); 63 }; 64 65 this.getID = function closeContextMenu_getID() { 66 return "close context menu"; 67 }; 68 } 69 70 function getContextMenuNode() { 71 return getRootAccessible().DOMDocument. 72 getElementById("contentAreaContextMenu"); 73 } 74 75 function getFocusedMenuItem() { 76 var menu = getAccessible(getAccessible(getContextMenuNode())); 77 for (var idx = 0; idx < menu.childCount; idx++) { 78 var item = menu.getChildAt(idx); 79 80 if (hasState(item, STATE_FOCUSED)) 81 return getAccessible(item); 82 } 83 return null; 84 } 85 86 // ////////////////////////////////////////////////////////////////////////// 87 // Do tests 88 89 var gQueue = null; 90 // gA11yEventDumpID = "eventdump"; // debug stuff 91 // gA11yEventDumpToConsole = true; 92 93 function doTests() { 94 gQueue = new eventQueue(); 95 96 gQueue.push(new showContextMenu("input")); 97 gQueue.push(new selectMenuItem()); 98 gQueue.push(new closeContextMenu()); 99 100 gQueue.invoke(); // Will call SimpleTest.finish(); 101 } 102 103 const {AppConstants} = ChromeUtils.importESModule( 104 "resource://gre/modules/AppConstants.sys.mjs" 105 ); 106 if (AppConstants.platform == "macosx" && 107 Services.prefs.getBoolPref("widget.macos.native-context-menus", false)) { 108 ok(true, "Native context menus handle accessibility notifications natively and cannot be tested with synthesized key events."); 109 } else { 110 SimpleTest.waitForExplicitFinish(); 111 addA11yLoadEvent(doTests); 112 } 113 </script> 114 </head> 115 116 <body> 117 118 <a target="_blank" 119 href="https://bugzilla.mozilla.org/show_bug.cgi?id=580535" 120 title="Broken accessibility in context menus"> 121 Mozilla Bug 580535 122 </a><br> 123 124 <p id="display"></p> 125 <div id="content" style="display: none"></div> 126 <pre id="test"> 127 </pre> 128 129 <input id="input"> 130 131 <div id="eventdump"></div> 132 </body> 133 </html>