browser_inspector_search-09.js (3413B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 requestLongerTimeout(2); 6 7 // Test that searching for XPaths via the search field actually selects the 8 // matching nodes. 9 10 const TEST_URL = URL_ROOT + "doc_inspector_search.html"; 11 12 // The various states of the inspector: [key, id, isTextNode, isValid] 13 // [ 14 // what key to press, 15 // what id should be selected after the keypress, 16 // is the selected node a text node, 17 // is the searched text valid selector 18 // ] 19 const KEY_STATES = [ 20 ["/", "b1", false, true], // / 21 ["*", "b1", false, true], // /* 22 ["VK_RETURN", "root", false, true], // /* 23 ["VK_BACK_SPACE", "root", false, true], // / 24 ["/", "root", false, true], // // 25 ["d", "root", false, true], // //d 26 ["i", "root", false, true], // //di 27 ["v", "root", false, true], // //div 28 ["VK_RETURN", "d1", false, true], // //div 29 ["VK_RETURN", "d2", false, true], // //div 30 ["VK_RETURN", "d1", false, true], // //div 31 ["VK_BACK_SPACE", "d1", false, true], // //di 32 ["VK_BACK_SPACE", "d1", false, true], // //d 33 ["VK_BACK_SPACE", "d1", false, true], // // 34 ["s", "d1", false, true], // //s 35 ["p", "d1", false, true], // //sp 36 ["a", "d1", false, true], // //spa 37 ["n", "d1", false, true], // //span 38 ["/", "d1", false, true], // //span/ 39 ["t", "d1", false, true], // //span/t 40 ["e", "d1", false, true], // //span/te 41 ["x", "d1", false, true], // //span/tex 42 ["t", "d1", false, true], // //span/text 43 ["(", "d1", false, true], // //span/text( 44 [")", "d1", false, true], // //span/text() 45 ["VK_RETURN", "s1", false, true], // //span/text() 46 ["VK_RETURN", "s2", true, true], // //span/text() 47 ]; 48 49 add_task(async function () { 50 const { inspector } = await openInspectorForURL(TEST_URL); 51 const { searchBox } = inspector; 52 53 await selectNode("#b1", inspector); 54 await focusSearchBoxUsingShortcut(inspector.panelWin); 55 56 let index = 0; 57 for (const [key, id, isTextNode, isValid] of KEY_STATES) { 58 info(index + ": Pressing key " + key + " to get id " + id + "."); 59 const onSearchProcessingDone = 60 inspector.searchSuggestions.once("processing-done"); 61 const onSearchResult = inspector.search.once("search-result"); 62 EventUtils.synthesizeKey( 63 key, 64 { shiftKey: key === "*" }, 65 inspector.panelWin 66 ); 67 68 if (key === "VK_RETURN") { 69 info("Waiting for " + (isValid ? "NO " : "") + "results"); 70 await onSearchResult; 71 } 72 73 info("Waiting for search query to complete"); 74 await onSearchProcessingDone; 75 76 if (isTextNode) { 77 info( 78 "Text node of " + 79 inspector.selection.nodeFront.parentNode.id + 80 " is selected with text " + 81 searchBox.value 82 ); 83 84 is( 85 inspector.selection.nodeFront.nodeType, 86 Node.TEXT_NODE, 87 "Correct node is selected for state " + index 88 ); 89 } else { 90 info( 91 inspector.selection.nodeFront.id + 92 " is selected with text " + 93 searchBox.value 94 ); 95 96 const nodeFront = await getNodeFront("#" + id, inspector); 97 is( 98 inspector.selection.nodeFront, 99 nodeFront, 100 "Correct node is selected for state " + index 101 ); 102 } 103 104 is( 105 !searchBox.parentNode.classList.contains("devtools-searchbox-no-match"), 106 isValid, 107 "Correct searchbox result state for state " + index 108 ); 109 110 index++; 111 } 112 });