browser_menulist.js (3041B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /* import-globals-from ../../mochitest/attributes.js */ 8 /* import-globals-from ../../mochitest/role.js */ 9 /* import-globals-from ../../mochitest/states.js */ 10 loadScripts( 11 { name: "role.js", dir: MOCHITESTS_DIR }, 12 { name: "states.js", dir: MOCHITESTS_DIR }, 13 { name: "attributes.js", dir: MOCHITESTS_DIR } 14 ); 15 16 addAccessibleTask( 17 "mac/doc_menulist.xhtml", 18 async (browser, accDoc) => { 19 const menulist = getNativeInterface(accDoc, "defaultZoom"); 20 21 let actions = menulist.actionNames; 22 ok(actions.includes("AXPress"), "menu has press action"); 23 24 let event = waitForMacEvent("AXMenuOpened"); 25 menulist.performAction("AXPress"); 26 const menupopup = await event; 27 28 const menuItems = menupopup.getAttributeValue("AXChildren"); 29 is(menuItems.length, 4, "Found four children in menulist"); 30 is( 31 menuItems[0].getAttributeValue("AXTitle"), 32 "50%", 33 "First item has correct title" 34 ); 35 is( 36 menuItems[1].getAttributeValue("AXTitle"), 37 "100%", 38 "Second item has correct title" 39 ); 40 is( 41 menuItems[2].getAttributeValue("AXTitle"), 42 "150%", 43 "Third item has correct title" 44 ); 45 is( 46 menuItems[3].getAttributeValue("AXTitle"), 47 "200%", 48 "Fourth item has correct title" 49 ); 50 }, 51 { topLevel: false, chrome: true } 52 ); 53 54 addAccessibleTask( 55 "mac/doc_menulist.xhtml", 56 async (browser, accDoc) => { 57 const menulist = getNativeInterface(accDoc, "defaultZoom"); 58 59 const actions = menulist.actionNames; 60 ok(actions.includes("AXPress"), "menu has press action"); 61 let event = waitForMacEvent("AXMenuOpened"); 62 menulist.performAction("AXPress"); 63 await event; 64 65 const menu = menulist.getAttributeValue("AXChildren")[0]; 66 ok(menu, "Menulist contains menu"); 67 const children = menu.getAttributeValue("AXChildren"); 68 is(children.length, 4, "Menu has 4 items"); 69 70 // Menu is open, initial focus should land on the first item 71 is( 72 children[0].getAttributeValue("AXSelected"), 73 1, 74 "First menu item is selected" 75 ); 76 // focus the second item, and verify it is selected 77 event = waitForMacEvent("AXFocusedUIElementChanged", iface => { 78 try { 79 return iface.getAttributeValue("AXTitle") == "100%"; 80 } catch (e) { 81 return false; 82 } 83 }); 84 EventUtils.synthesizeKey("KEY_ArrowDown"); 85 await event; 86 87 is( 88 children[0].getAttributeValue("AXSelected"), 89 0, 90 "First menu item is no longer selected" 91 ); 92 is( 93 children[1].getAttributeValue("AXSelected"), 94 1, 95 "Second menu item is selected" 96 ); 97 // press the second item, check for selected event 98 event = waitForMacEvent("AXMenuItemSelected"); 99 children[1].performAction("AXPress"); 100 await event; 101 }, 102 { topLevel: false, chrome: true } 103 );