browser_inspector_search-selection.js (2562B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Testing navigation between nodes in search results 6 7 const TEST_URL = URL_ROOT + "doc_inspector_search.html"; 8 9 add_task(async function () { 10 const { inspector } = await openInspectorForURL(TEST_URL); 11 12 info("Focus the search box"); 13 await focusSearchBoxUsingShortcut(inspector.panelWin); 14 15 info("Enter body > p to search"); 16 const searchText = "body > p"; 17 // EventUtils.sendString will trigger multiple updates, so wait until the final one. 18 const processingDone = new Promise(resolve => { 19 const off = inspector.searchSuggestions.on("processing-done", data => { 20 if (data.query == searchText) { 21 resolve(); 22 off(); 23 } 24 }); 25 }); 26 EventUtils.sendString(searchText, inspector.panelWin); 27 28 info("Wait for search query to complete"); 29 await processingDone; 30 31 let msg = "Press enter and expect a new selection"; 32 await sendKeyAndCheck(inspector, msg, "VK_RETURN", {}, "#p1"); 33 34 msg = "Press enter to cycle through multiple nodes"; 35 await sendKeyAndCheck(inspector, msg, "VK_RETURN", {}, "#p2"); 36 37 msg = "Press shift-enter to select the previous node"; 38 await sendKeyAndCheck(inspector, msg, "VK_RETURN", { shiftKey: true }, "#p1"); 39 40 if (AppConstants.platform === "macosx") { 41 msg = "Press meta-g to cycle through multiple nodes"; 42 await sendKeyAndCheck(inspector, msg, "VK_G", { metaKey: true }, "#p2"); 43 44 msg = "Press shift+meta-g to select the previous node"; 45 await sendKeyAndCheck( 46 inspector, 47 msg, 48 "VK_G", 49 { metaKey: true, shiftKey: true }, 50 "#p1" 51 ); 52 } else { 53 msg = "Press ctrl-g to cycle through multiple nodes"; 54 await sendKeyAndCheck(inspector, msg, "VK_G", { ctrlKey: true }, "#p2"); 55 56 msg = "Press shift+ctrl-g to select the previous node"; 57 await sendKeyAndCheck( 58 inspector, 59 msg, 60 "VK_G", 61 { ctrlKey: true, shiftKey: true }, 62 "#p1" 63 ); 64 } 65 }); 66 67 const sendKeyAndCheck = async function ( 68 inspector, 69 description, 70 key, 71 modifiers, 72 expectedId 73 ) { 74 info(description); 75 const onSelect = inspector.once("inspector-updated"); 76 EventUtils.synthesizeKey(key, modifiers, inspector.panelWin); 77 await onSelect; 78 79 const selectedNode = inspector.selection.nodeFront; 80 info(selectedNode.id + " is selected with text " + inspector.searchBox.value); 81 const targetNode = await getNodeFront(expectedId, inspector); 82 is(selectedNode, targetNode, "Correct node " + expectedId + " is selected"); 83 };