browser_inspector_search-03.js (5169B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Testing that searching for elements using the inspector search field 6 // produces correct suggestions. 7 8 const TEST_URL = URL_ROOT + "doc_inspector_search.html"; 9 10 // See head.js `checkMarkupSearchSuggestions` function 11 const TEST_DATA = [ 12 { 13 key: "d", 14 value: "d", 15 suggestions: ["div", "#d1", "#d2"], 16 }, 17 { 18 key: "i", 19 value: "di", 20 suggestions: ["div"], 21 }, 22 { 23 key: "v", 24 value: "div", 25 suggestions: [], 26 }, 27 { 28 key: ".", 29 value: "div.", 30 suggestions: ["div.c1"], 31 }, 32 { 33 key: "VK_BACK_SPACE", 34 value: "div", 35 suggestions: [], 36 }, 37 { 38 key: "#", 39 value: "div#", 40 suggestions: ["div#d1", "div#d2"], 41 }, 42 { 43 key: "VK_BACK_SPACE", 44 value: "div", 45 suggestions: [], 46 }, 47 { 48 key: "VK_BACK_SPACE", 49 value: "di", 50 suggestions: ["div"], 51 }, 52 { 53 key: "VK_BACK_SPACE", 54 value: "d", 55 suggestions: ["div", "#d1", "#d2"], 56 }, 57 { 58 key: "VK_BACK_SPACE", 59 value: "", 60 suggestions: [], 61 }, 62 { 63 key: ".", 64 value: ".", 65 suggestions: [".c1", ".c2"], 66 }, 67 { 68 key: "c", 69 value: ".c", 70 suggestions: [".c1", ".c2"], 71 }, 72 { 73 key: "2", 74 value: ".c2", 75 suggestions: [], 76 }, 77 { 78 key: "VK_BACK_SPACE", 79 value: ".c", 80 suggestions: [".c1", ".c2"], 81 }, 82 { 83 key: "1", 84 value: ".c1", 85 suggestions: [], 86 }, 87 { 88 key: "#", 89 value: ".c1#", 90 suggestions: ["#d2", "#p1", "#s2"], 91 }, 92 { 93 key: "VK_BACK_SPACE", 94 value: ".c1", 95 suggestions: [], 96 }, 97 { 98 key: "VK_BACK_SPACE", 99 value: ".c", 100 suggestions: [".c1", ".c2"], 101 }, 102 { 103 key: "VK_BACK_SPACE", 104 value: ".", 105 suggestions: [".c1", ".c2"], 106 }, 107 { 108 key: "VK_BACK_SPACE", 109 value: "", 110 suggestions: [], 111 }, 112 { 113 key: "#", 114 value: "#", 115 suggestions: [ 116 "#b1", 117 "#d1", 118 "#d2", 119 "#p1", 120 "#p2", 121 "#p3", 122 "#root", 123 "#s1", 124 "#s2", 125 ], 126 }, 127 { 128 key: "p", 129 value: "#p", 130 suggestions: ["#p1", "#p2", "#p3"], 131 }, 132 { 133 key: "VK_BACK_SPACE", 134 value: "#", 135 suggestions: [ 136 "#b1", 137 "#d1", 138 "#d2", 139 "#p1", 140 "#p2", 141 "#p3", 142 "#root", 143 "#s1", 144 "#s2", 145 ], 146 }, 147 { 148 key: "VK_BACK_SPACE", 149 value: "", 150 suggestions: [], 151 }, 152 { 153 key: "p", 154 value: "p", 155 suggestions: ["p", "#p1", "#p2", "#p3"], 156 }, 157 { 158 key: "[", 159 value: "p[", 160 suggestions: [], 161 }, 162 { 163 key: "i", 164 value: "p[i", 165 suggestions: [], 166 }, 167 { 168 key: "d", 169 value: "p[id", 170 suggestions: [], 171 }, 172 { 173 key: "*", 174 value: "p[id*", 175 suggestions: [], 176 }, 177 { 178 key: "=", 179 value: "p[id*=", 180 suggestions: [], 181 }, 182 { 183 key: "p", 184 value: "p[id*=p", 185 suggestions: [], 186 }, 187 { 188 key: "]", 189 value: "p[id*=p]", 190 suggestions: [], 191 }, 192 { 193 key: ".", 194 value: "p[id*=p].", 195 suggestions: ["p[id*=p].c1", "p[id*=p].c2"], 196 }, 197 { 198 key: "VK_BACK_SPACE", 199 value: "p[id*=p]", 200 suggestions: [], 201 }, 202 { 203 key: "#", 204 value: "p[id*=p]#", 205 suggestions: ["p[id*=p]#p1", "p[id*=p]#p2", "p[id*=p]#p3"], 206 }, 207 ]; 208 209 add_task(async function () { 210 const { inspector } = await openInspectorForURL(TEST_URL); 211 await checkMarkupSearchSuggestions(inspector, TEST_DATA); 212 }); 213 214 add_task(async function () { 215 const { inspector } = 216 await openInspectorForURL(`data:text/html,<meta charset=utf8> 217 <main> 218 <div class="testA_alpha"></div> 219 <div class="test1_numeric"></div> 220 <div class="test-_dash"></div> 221 <div class="test__underscore"></div> 222 <test-foo></test-element> 223 <test-bar></test-element> 224 </main>`); 225 226 const testSuggestions = [ 227 "test-bar", 228 "test-foo", 229 ".test__underscore", 230 ".test-_dash", 231 ".test1_numeric", 232 ".testA_alpha", 233 ]; 234 235 await checkMarkupSearchSuggestions(inspector, [ 236 { 237 key: "t", 238 value: "t", 239 suggestions: testSuggestions, 240 }, 241 { 242 key: "e", 243 value: "te", 244 suggestions: testSuggestions, 245 }, 246 { 247 key: "s", 248 value: "tes", 249 suggestions: testSuggestions, 250 }, 251 { 252 key: "t", 253 value: "test", 254 suggestions: testSuggestions, 255 }, 256 { 257 key: "-", 258 value: "test-", 259 suggestions: ["test-bar", "test-foo", ".test-_dash"], 260 }, 261 { 262 key: "f", 263 value: "test-f", 264 suggestions: ["test-foo"], 265 }, 266 { 267 key: "VK_BACK_SPACE", 268 value: "test-", 269 suggestions: ["test-bar", "test-foo", ".test-_dash"], 270 }, 271 { 272 key: "VK_BACK_SPACE", 273 value: "test", 274 suggestions: testSuggestions, 275 }, 276 { 277 key: "_", 278 value: "test_", 279 suggestions: [".test__underscore"], 280 }, 281 { 282 key: "VK_BACK_SPACE", 283 value: "test", 284 suggestions: testSuggestions, 285 }, 286 { 287 key: "1", 288 value: "test1", 289 suggestions: [".test1_numeric"], 290 }, 291 { 292 key: "VK_BACK_SPACE", 293 value: "test", 294 suggestions: testSuggestions, 295 }, 296 { 297 key: "A", 298 value: "testA", 299 suggestions: [".testA_alpha"], 300 }, 301 ]); 302 });