browser_markup_accessibility_focus_blur.js (2186B)
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 // Test inspector markup view handling focus and blur when moving between markup 8 // view, its root and other containers, and other parts of inspector. 9 10 add_task(async function () { 11 const { inspector } = await openInspectorForURL( 12 "data:text/html;charset=utf-8,<h1>foo</h1><span>bar</span>" 13 ); 14 const markup = inspector.markup; 15 const doc = markup.doc; 16 const win = doc.defaultView; 17 18 const spanContainer = await getContainerForSelector("span", inspector); 19 const rootContainer = markup.getContainer(markup._rootNode); 20 21 is( 22 doc.activeElement, 23 doc.body, 24 "Keyboard focus by default is on document body" 25 ); 26 27 await selectNode("span", inspector); 28 29 is(doc.activeElement, doc.body, "Keyboard focus is still on document body"); 30 31 info("Focusing on the test span node using 'Return' key"); 32 // Focus on the tree element. 33 rootContainer.elt.focus(); 34 EventUtils.synthesizeKey("VK_RETURN", {}, win); 35 36 is( 37 doc.activeElement, 38 spanContainer.editor.tag, 39 "Keyboard focus should be on tag element of focused container" 40 ); 41 42 info("Focusing on search box, external to markup view document"); 43 await focusSearchBoxUsingShortcut(inspector.panelWin); 44 45 is( 46 doc.activeElement, 47 doc.body, 48 "Keyboard focus should be removed from focused container" 49 ); 50 51 info("Selecting the test span node again"); 52 await selectNode("span", inspector); 53 54 is( 55 doc.activeElement, 56 doc.body, 57 "Keyboard focus should again be on document body" 58 ); 59 60 info("Focusing on the test span node using 'Space' key"); 61 // Focus on the tree element. 62 rootContainer.elt.focus(); 63 EventUtils.synthesizeKey("VK_SPACE", {}, win); 64 65 is( 66 doc.activeElement, 67 spanContainer.editor.tag, 68 "Keyboard focus should again be on tag element of focused container" 69 ); 70 71 await clickOnInspectMenuItem("h1"); 72 is( 73 doc.activeElement, 74 rootContainer.elt, 75 "When inspect menu item is used keyboard focus should move to tree." 76 ); 77 });