browser_inspector_search-reserved.js (3115B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Testing searching for ids and classes that contain reserved characters. 6 const TEST_URL = URL_ROOT + "doc_inspector_search-reserved.html"; 7 8 // An array of (key, suggestions) pairs where key is a key to press and 9 // suggestions is an array of suggestions that should be shown in the popup. 10 // Suggestion is an object with label of the entry and optional count 11 // (defaults to 1) 12 const TEST_DATA = [ 13 { 14 key: "#", 15 suggestions: [{ label: "#d1\\.d2" }], 16 }, 17 { 18 key: "d", 19 suggestions: [{ label: "#d1\\.d2" }], 20 }, 21 { 22 key: "VK_BACK_SPACE", 23 suggestions: [{ label: "#d1\\.d2" }], 24 }, 25 { 26 key: "VK_BACK_SPACE", 27 suggestions: [], 28 }, 29 { 30 key: ".", 31 suggestions: [{ label: ".c1\\.c2" }], 32 }, 33 { 34 key: "c", 35 suggestions: [{ label: ".c1\\.c2" }], 36 }, 37 { 38 key: "VK_BACK_SPACE", 39 suggestions: [{ label: ".c1\\.c2" }], 40 }, 41 { 42 key: "VK_BACK_SPACE", 43 suggestions: [], 44 }, 45 { 46 key: "d", 47 suggestions: [{ label: "div" }, { label: "#d1\\.d2" }], 48 }, 49 { 50 key: "VK_BACK_SPACE", 51 suggestions: [], 52 }, 53 { 54 key: "c", 55 suggestions: [{ label: ".c1\\.c2" }], 56 }, 57 { 58 key: "VK_BACK_SPACE", 59 suggestions: [], 60 }, 61 { 62 key: "b", 63 suggestions: [{ label: "body" }], 64 }, 65 { 66 key: "o", 67 suggestions: [{ label: "body" }], 68 }, 69 { 70 key: "d", 71 suggestions: [{ label: "body" }], 72 }, 73 { 74 key: "y", 75 suggestions: [], 76 }, 77 { 78 key: " ", 79 suggestions: [{ label: "body div" }], 80 }, 81 { 82 key: ".", 83 suggestions: [{ label: "body .c1\\.c2" }], 84 }, 85 { 86 key: "VK_BACK_SPACE", 87 suggestions: [{ label: "body div" }], 88 }, 89 { 90 key: "#", 91 suggestions: [{ label: "body #d1\\.d2" }], 92 }, 93 ]; 94 95 add_task(async function () { 96 const { inspector } = await openInspectorForURL(TEST_URL); 97 const searchBox = inspector.searchBox; 98 const popup = inspector.searchSuggestions.searchPopup; 99 100 await focusSearchBoxUsingShortcut(inspector.panelWin); 101 102 for (const { key, suggestions } of TEST_DATA) { 103 info("Pressing " + key + " to get " + formatSuggestions(suggestions)); 104 105 const command = once(searchBox, "input"); 106 const onSearchProcessingDone = 107 inspector.searchSuggestions.once("processing-done"); 108 EventUtils.synthesizeKey(key, {}, inspector.panelWin); 109 await command; 110 111 info("Waiting for search query to complete"); 112 await onSearchProcessingDone; 113 114 info( 115 "Query completed. Performing checks for input '" + searchBox.value + "'" 116 ); 117 const actualSuggestions = popup.getItems(); 118 119 is( 120 popup.isOpen ? actualSuggestions.length : 0, 121 suggestions.length, 122 "There are expected number of suggestions." 123 ); 124 125 for (let i = 0; i < suggestions.length; i++) { 126 is( 127 suggestions[i].label, 128 actualSuggestions[i].label, 129 "The suggestion at " + i + "th index is correct." 130 ); 131 } 132 } 133 }); 134 135 function formatSuggestions(suggestions) { 136 return "[" + suggestions.map(s => "'" + s.label + "'").join(", ") + "]"; 137 }