browser_focus.js (1949B)
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 async function testIsFocusable(pyVar, isFocusable) { 8 const result = await runPython(`${pyVar}.CurrentIsKeyboardFocusable`); 9 if (isFocusable) { 10 ok(result, `${pyVar} is focusable`); 11 } else { 12 ok(!result, `${pyVar} isn't focusable`); 13 } 14 } 15 16 async function testHasFocus(pyVar, hasFocus) { 17 const result = await runPython(`${pyVar}.CurrentHasKeyboardFocus`); 18 if (hasFocus) { 19 ok(result, `${pyVar} has focus`); 20 } else { 21 ok(!result, `${pyVar} doesn't have focus`); 22 } 23 } 24 25 addUiaTask( 26 ` 27 <button id="button1">button1</button> 28 <p id="p">p</p> 29 <button id="button2">button2</button> 30 `, 31 async function (browser) { 32 await definePyVar("doc", `getDocUia()`); 33 await testIsFocusable("doc", true); 34 await testHasFocus("doc", true); 35 36 await assignPyVarToUiaWithId("button1"); 37 await testIsFocusable("button1", true); 38 await testHasFocus("button1", false); 39 info("Focusing button1"); 40 await setUpWaitForUiaEvent("AutomationFocusChanged", "button1"); 41 await invokeFocus(browser, "button1"); 42 await waitForUiaEvent(); 43 ok(true, "Got AutomationFocusChanged event on button1"); 44 await testHasFocus("button1", true); 45 46 await assignPyVarToUiaWithId("p"); 47 await testIsFocusable("p", false); 48 await testHasFocus("p", false); 49 50 await assignPyVarToUiaWithId("button2"); 51 await testIsFocusable("button2", true); 52 await testHasFocus("button2", false); 53 info("Focusing button2"); 54 await setUpWaitForUiaEvent("AutomationFocusChanged", "button2"); 55 await invokeFocus(browser, "button2"); 56 await waitForUiaEvent(); 57 ok(true, "Got AutomationFocusChanged event on button2"); 58 await testHasFocus("button2", true); 59 await testHasFocus("button1", false); 60 } 61 );