browser_inspector_search-suggests-ids-and-classes.js (2838B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that the selector-search input proposes ids and classes even when . and 6 // # is missing, but that this only occurs when the query is one word (no 7 // selector combination) 8 9 // The various states of the inspector: [key, suggestions array] 10 // [ 11 // what key to press, 12 // suggestions [ 13 // suggestion1, 14 // suggestion2, 15 // … 16 // ] 17 // ] 18 const KEY_STATES = [ 19 ["s", ["span", ".span", "#span"]], 20 ["p", ["span", ".span", "#span"]], 21 ["a", ["span", ".span", "#span"]], 22 ["n", ["span", ".span", "#span"]], 23 [" ", ["span div"]], 24 // mixed tag/class/id suggestions only work for the first word 25 ["d", ["span div"]], 26 ["VK_BACK_SPACE", ["span div"]], 27 ["VK_BACK_SPACE", ["span", ".span", "#span"]], 28 ["VK_BACK_SPACE", ["span", ".span", "#span"]], 29 ["VK_BACK_SPACE", ["span", ".span", "#span"]], 30 ["VK_BACK_SPACE", ["span", ".span", "#span"]], 31 ["VK_BACK_SPACE", []], 32 // Test that mixed tags, classes and ids are grouped by types, sorted by 33 // count and alphabetical order 34 ["b", ["body", "button", ".ba", ".bb", ".bc", "#ba", "#bb", "#bc"]], 35 ]; 36 37 const TEST_URL = `<span class="span" id="span"> 38 <div class="div" id="div"></div> 39 </span> 40 <button class="ba bc" id="bc"></button> 41 <button class="bb bc" id="bb"></button> 42 <button class="bc" id="ba"></button>`; 43 44 add_task(async function () { 45 const { inspector } = await openInspectorForURL( 46 "data:text/html;charset=utf-8," + encodeURI(TEST_URL) 47 ); 48 49 const searchBox = inspector.panelWin.document.getElementById( 50 "inspector-searchbox" 51 ); 52 const popup = inspector.searchSuggestions.searchPopup; 53 54 await focusSearchBoxUsingShortcut(inspector.panelWin); 55 56 for (const [key, expectedSuggestions] of KEY_STATES) { 57 info( 58 "pressing key " + 59 key + 60 " to get suggestions " + 61 JSON.stringify(expectedSuggestions) 62 ); 63 64 const onCommand = once(searchBox, "input", true); 65 const onSearchProcessingDone = 66 inspector.searchSuggestions.once("processing-done"); 67 EventUtils.synthesizeKey(key, {}, inspector.panelWin); 68 await onCommand; 69 70 info("Waiting for the suggestions to be retrieved"); 71 await onSearchProcessingDone; 72 73 const actualSuggestions = Array.from(popup.list.querySelectorAll("li")).map( 74 li => li.textContent 75 ); 76 is( 77 popup.isOpen ? actualSuggestions.length : 0, 78 expectedSuggestions.length, 79 "There are expected number of suggestions" 80 ); 81 82 for (let i = 0; i < expectedSuggestions.length; i++) { 83 is( 84 actualSuggestions[i], 85 expectedSuggestions[i], 86 "The suggestion at " + i + "th index is correct." 87 ); 88 } 89 } 90 });