browser_inspector_breadcrumbs_keyboard_trap.js (2542B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test ability to tab to and away from breadcrumbs using keyboard. 7 8 const TEST_URL = URL_ROOT + "doc_inspector_breadcrumbs.html"; 9 10 /** 11 * Test data has the format of: 12 * { 13 * desc {String} description for better logging 14 * focused {Boolean} flag, indicating if breadcrumbs contain focus 15 * key {String} key event's key 16 * options {?Object} optional event data such as shiftKey, etc 17 * } 18 */ 19 const TEST_DATA = [ 20 { 21 desc: "Move the focus away from breadcrumbs to a next focusable element", 22 focused: false, 23 key: "VK_TAB", 24 options: {}, 25 }, 26 { 27 desc: "Move the focus back to the breadcrumbs", 28 focused: true, 29 key: "VK_TAB", 30 options: { shiftKey: true }, 31 }, 32 { 33 desc: 34 "Move the focus back away from breadcrumbs to a previous focusable " + 35 "element", 36 focused: false, 37 key: "VK_TAB", 38 options: { shiftKey: true }, 39 }, 40 { 41 desc: "Move the focus back to the breadcrumbs", 42 focused: true, 43 key: "VK_TAB", 44 options: {}, 45 }, 46 ]; 47 48 add_task(async function () { 49 const { inspector } = await openInspectorForURL(TEST_URL); 50 const doc = inspector.panelDoc; 51 const { breadcrumbs } = inspector; 52 const { waitForHighlighterTypeShown } = getHighlighterTestHelpers(inspector); 53 54 await selectNode("#i2", inspector); 55 56 info("Clicking on the corresponding breadcrumbs node to focus it"); 57 const container = doc.getElementById("inspector-breadcrumbs"); 58 59 const button = container.querySelector(`button[aria-pressed="true"]`); 60 const onHighlight = waitForHighlighterTypeShown( 61 inspector.highlighters.TYPES.BOXMODEL 62 ); 63 button.click(); 64 await onHighlight; 65 66 // Ensure a breadcrumb is focused. 67 is(doc.activeElement, container, "Focus is on selected breadcrumb"); 68 is( 69 container.getAttribute("aria-activedescendant"), 70 button.id, 71 "aria-activedescendant is set correctly" 72 ); 73 74 for (const { desc, focused, key, options } of TEST_DATA) { 75 info(desc); 76 77 EventUtils.synthesizeKey(key, options); 78 // Wait until the keyPromise promise resolves. 79 await breadcrumbs.keyPromise; 80 81 if (focused) { 82 is(doc.activeElement, container, "Focus is on selected breadcrumb"); 83 } else { 84 ok(!containsFocus(doc, container), "Focus is outside of breadcrumbs"); 85 } 86 is( 87 container.getAttribute("aria-activedescendant"), 88 button.id, 89 "aria-activedescendant is set correctly" 90 ); 91 } 92 });