browser_inspector_keyboard-shortcuts.js (1685B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Tests that the keybindings for highlighting different elements work as 6 // intended. 7 8 const TEST_URI = 9 "data:text/html;charset=utf-8," + 10 "<html><head><title>Test for the highlighter keybindings</title></head>" + 11 "<body><p><strong>Greetings, earthlings!</strong>" + 12 " I come in peace.</p></body></html>"; 13 14 const TEST_DATA = [ 15 { key: "KEY_ArrowLeft", selectedNode: "p" }, 16 { key: "KEY_ArrowLeft", selectedNode: "body" }, 17 { key: "KEY_ArrowLeft", selectedNode: "html" }, 18 { key: "KEY_ArrowRight", selectedNode: "body" }, 19 { key: "KEY_ArrowRight", selectedNode: "p" }, 20 { key: "KEY_ArrowRight", selectedNode: "strong" }, 21 ]; 22 23 add_task(async function () { 24 const { inspector } = await openInspectorForURL(TEST_URI); 25 26 info("Selecting the deepest element to start with"); 27 await selectNode("strong", inspector); 28 29 const nodeFront = await getNodeFront("strong", inspector); 30 is( 31 inspector.selection.nodeFront, 32 nodeFront, 33 "<strong> should be selected initially" 34 ); 35 36 info("Focusing the currently active breadcrumb button"); 37 const bc = inspector.breadcrumbs; 38 bc.nodeHierarchy[bc.currentIndex].button.focus(); 39 40 for (const { key, selectedNode } of TEST_DATA) { 41 info("Pressing " + key + " to select " + selectedNode); 42 43 const updated = inspector.once("inspector-updated"); 44 EventUtils.synthesizeKey(key); 45 await updated; 46 47 const selectedNodeFront = await getNodeFront(selectedNode, inspector); 48 is( 49 inspector.selection.nodeFront, 50 selectedNodeFront, 51 selectedNode + " is selected." 52 ); 53 } 54 });