browser_action.js (2566B)
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 /** 8 * Test basic press action. 9 */ 10 addAccessibleTask( 11 ` 12 <button id="btn" onclick="this.textContent = 'Clicked'">Click me</button> 13 `, 14 async function testBasicPress() { 15 const actions = await runPython(` 16 global doc 17 doc = getDocIa2() 18 global btn 19 btn = findIa2ByDomId(doc, "btn").QueryInterface(IAccessibleAction) 20 return str([[btn.name(i), btn.localizedName(i), btn.description(i)] for i in range(btn.nActions())]) 21 `); 22 is(actions, "[['press', 'Press', 'Press']]", "btn has correct actions"); 23 24 const nameChanged = waitForEvent(EVENT_NAME_CHANGE, "btn"); 25 await runPython(` 26 btn.doAction(0) 27 `); 28 await nameChanged; 29 } 30 ); 31 32 /** 33 * Test aria-actions. 34 */ 35 addAccessibleTask( 36 ` 37 <div id="container"> 38 <dialog aria-actions="btn1" id="dlg1" open> 39 Hello 40 <form method="dialog"> 41 <button id="btn1">Close</button> 42 </form> 43 </dialog> 44 <dialog aria-actions="btn2" id="dlg2" onclick="" open> 45 Dialog with its own click listener 46 <form method="dialog"> 47 <button id="btn2">Close</button> 48 </form> 49 </dialog> 50 </div>`, 51 async function testAriaActions() { 52 let actions = await runPython(` 53 global doc 54 doc = getDocIa2() 55 global dlg1 56 dlg1 = findIa2ByDomId(doc, "dlg1").QueryInterface(IAccessibleAction) 57 return str([[dlg1.name(i), dlg1.localizedName(i), dlg1.description(i)] for i in range(dlg1.nActions())]) 58 `); 59 is( 60 actions, 61 "[['custom_btn1', 'Close', 'Close']]", 62 "dlg1 has correct actions" 63 ); 64 65 let reorder = waitForEvent(EVENT_REORDER, "container"); 66 await runPython(` 67 dlg1.doAction(0) 68 `); 69 await reorder; 70 71 // Test dialog with its own click listener, and therefore has the aria-actions 72 // target actions appended to its own actions. 73 actions = await runPython(` 74 global dlg2 75 dlg2 = findIa2ByDomId(doc, "dlg2").QueryInterface(IAccessibleAction) 76 return str([[dlg2.name(i), dlg2.localizedName(i), dlg2.description(i)] for i in range(dlg2.nActions())]) 77 `); 78 is( 79 actions, 80 "[['click', 'Click', 'Click'], ['custom_btn2', 'Close', 'Close']]", 81 "dlg2 has correct actions" 82 ); 83 84 reorder = waitForEvent(EVENT_REORDER, "container"); 85 await runPython(` 86 dlg2.doAction(1) 87 `); 88 await reorder; 89 } 90 );