1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_search-symbols.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,469 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if the function searching works properly. 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_function-search.html"; 1.12 + 1.13 +let gTab, gDebuggee, gPanel, gDebugger; 1.14 +let gEditor, gSources, gSearchBox, gFilteredFunctions; 1.15 + 1.16 +function test() { 1.17 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.18 + gTab = aTab; 1.19 + gDebuggee = aDebuggee; 1.20 + gPanel = aPanel; 1.21 + gDebugger = gPanel.panelWin; 1.22 + gEditor = gDebugger.DebuggerView.editor; 1.23 + gSources = gDebugger.DebuggerView.Sources; 1.24 + gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; 1.25 + gFilteredFunctions = gDebugger.DebuggerView.FilteredFunctions; 1.26 + 1.27 + waitForSourceShown(gPanel, "-01.js") 1.28 + .then(() => showSource("doc_function-search.html")) 1.29 + .then(htmlSearch) 1.30 + .then(() => showSource("code_function-search-01.js")) 1.31 + .then(firstJsSearch) 1.32 + .then(() => showSource("code_function-search-02.js")) 1.33 + .then(secondJsSearch) 1.34 + .then(() => showSource("code_function-search-03.js")) 1.35 + .then(thirdJsSearch) 1.36 + .then(saveSearch) 1.37 + .then(filterSearch) 1.38 + .then(bogusSearch) 1.39 + .then(incrementalSearch) 1.40 + .then(emptySearch) 1.41 + .then(() => closeDebuggerAndFinish(gPanel)) 1.42 + .then(null, aError => { 1.43 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.44 + }); 1.45 + }); 1.46 +} 1.47 + 1.48 +function htmlSearch() { 1.49 + let deferred = promise.defer(); 1.50 + 1.51 + once(gDebugger, "popupshown").then(() => { 1.52 + writeInfo(); 1.53 + 1.54 + is(gFilteredFunctions.selectedIndex, 0, 1.55 + "An item should be selected in the filtered functions view (1)."); 1.56 + ok(gFilteredFunctions.selectedItem, 1.57 + "An item should be selected in the filtered functions view (2)."); 1.58 + 1.59 + if (gSources.selectedValue.indexOf(".html") != -1) { 1.60 + let expectedResults = [ 1.61 + ["inline", ".html", "", 19, 16], 1.62 + ["arrow", ".html", "", 20, 11], 1.63 + ["foo", ".html", "", 22, 11], 1.64 + ["foo2", ".html", "", 23, 11], 1.65 + ["bar2", ".html", "", 23, 18] 1.66 + ]; 1.67 + 1.68 + for (let [label, value, description, line, column] of expectedResults) { 1.69 + let target = gFilteredFunctions.selectedItem.target; 1.70 + 1.71 + if (label) { 1.72 + is(target.querySelector(".results-panel-item-label").getAttribute("value"), 1.73 + gDebugger.SourceUtils.trimUrlLength(label + "()"), 1.74 + "The corect label (" + label + ") is currently selected."); 1.75 + } else { 1.76 + ok(!target.querySelector(".results-panel-item-label"), 1.77 + "Shouldn't create empty label nodes."); 1.78 + } 1.79 + if (value) { 1.80 + ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").contains(value), 1.81 + "The corect value (" + value + ") is attached."); 1.82 + } else { 1.83 + ok(!target.querySelector(".results-panel-item-label-below"), 1.84 + "Shouldn't create empty label nodes."); 1.85 + } 1.86 + if (description) { 1.87 + is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description, 1.88 + "The corect description (" + description + ") is currently shown."); 1.89 + } else { 1.90 + ok(!target.querySelector(".results-panel-item-label-before"), 1.91 + "Shouldn't create empty label nodes."); 1.92 + } 1.93 + 1.94 + ok(isCaretPos(gPanel, line, column), 1.95 + "The editor didn't jump to the correct line."); 1.96 + 1.97 + EventUtils.sendKey("DOWN", gDebugger); 1.98 + } 1.99 + 1.100 + ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]), 1.101 + "The editor didn't jump to the correct line again."); 1.102 + 1.103 + deferred.resolve(); 1.104 + } else { 1.105 + ok(false, "How did you get here? Go away, you."); 1.106 + } 1.107 + }); 1.108 + 1.109 + setText(gSearchBox, "@"); 1.110 + return deferred.promise; 1.111 +} 1.112 + 1.113 +function firstJsSearch() { 1.114 + let deferred = promise.defer(); 1.115 + 1.116 + once(gDebugger, "popupshown").then(() => { 1.117 + writeInfo(); 1.118 + 1.119 + is(gFilteredFunctions.selectedIndex, 0, 1.120 + "An item should be selected in the filtered functions view (1)."); 1.121 + ok(gFilteredFunctions.selectedItem, 1.122 + "An item should be selected in the filtered functions view (2)."); 1.123 + 1.124 + if (gSources.selectedValue.indexOf("-01.js") != -1) { 1.125 + let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " "; 1.126 + let expectedResults = [ 1.127 + ["test", "-01.js", "", 4, 10], 1.128 + ["anonymousExpression", "-01.js", "test.prototype", 9, 3], 1.129 + ["namedExpression" + s + "NAME", "-01.js", "test.prototype", 11, 3], 1.130 + ["a_test", "-01.js", "foo", 22, 3], 1.131 + ["n_test" + s + "x", "-01.js", "foo", 24, 3], 1.132 + ["a_test", "-01.js", "foo.sub", 27, 5], 1.133 + ["n_test" + s + "y", "-01.js", "foo.sub", 29, 5], 1.134 + ["a_test", "-01.js", "foo.sub.sub", 32, 7], 1.135 + ["n_test" + s + "z", "-01.js", "foo.sub.sub", 34, 7], 1.136 + ["test_SAME_NAME", "-01.js", "foo.sub.sub.sub", 37, 9] 1.137 + ]; 1.138 + 1.139 + for (let [label, value, description, line, column] of expectedResults) { 1.140 + let target = gFilteredFunctions.selectedItem.target; 1.141 + 1.142 + if (label) { 1.143 + is(target.querySelector(".results-panel-item-label").getAttribute("value"), 1.144 + gDebugger.SourceUtils.trimUrlLength(label + "()"), 1.145 + "The corect label (" + label + ") is currently selected."); 1.146 + } else { 1.147 + ok(!target.querySelector(".results-panel-item-label"), 1.148 + "Shouldn't create empty label nodes."); 1.149 + } 1.150 + if (value) { 1.151 + ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").contains(value), 1.152 + "The corect value (" + value + ") is attached."); 1.153 + } else { 1.154 + ok(!target.querySelector(".results-panel-item-label-below"), 1.155 + "Shouldn't create empty label nodes."); 1.156 + } 1.157 + if (description) { 1.158 + is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description, 1.159 + "The corect description (" + description + ") is currently shown."); 1.160 + } else { 1.161 + ok(!target.querySelector(".results-panel-item-label-before"), 1.162 + "Shouldn't create empty label nodes."); 1.163 + } 1.164 + 1.165 + ok(isCaretPos(gPanel, line, column), 1.166 + "The editor didn't jump to the correct line."); 1.167 + 1.168 + EventUtils.sendKey("DOWN", gDebugger); 1.169 + } 1.170 + 1.171 + ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]), 1.172 + "The editor didn't jump to the correct line again."); 1.173 + 1.174 + deferred.resolve() 1.175 + } else { 1.176 + ok(false, "How did you get here? Go away, you."); 1.177 + } 1.178 + }); 1.179 + 1.180 + setText(gSearchBox, "@"); 1.181 + return deferred.promise; 1.182 +} 1.183 + 1.184 +function secondJsSearch() { 1.185 + let deferred = promise.defer(); 1.186 + 1.187 + once(gDebugger, "popupshown").then(() => { 1.188 + writeInfo(); 1.189 + 1.190 + is(gFilteredFunctions.selectedIndex, 0, 1.191 + "An item should be selected in the filtered functions view (1)."); 1.192 + ok(gFilteredFunctions.selectedItem, 1.193 + "An item should be selected in the filtered functions view (2)."); 1.194 + 1.195 + if (gSources.selectedValue.indexOf("-02.js") != -1) { 1.196 + let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " "; 1.197 + let expectedResults = [ 1.198 + ["test2", "-02.js", "", 4, 5], 1.199 + ["test3" + s + "test3_NAME", "-02.js", "", 8, 5], 1.200 + ["test4_SAME_NAME", "-02.js", "", 11, 5], 1.201 + ["x" + s + "X", "-02.js", "test.prototype", 14, 1], 1.202 + ["y" + s + "Y", "-02.js", "test.prototype.sub", 16, 1], 1.203 + ["z" + s + "Z", "-02.js", "test.prototype.sub.sub", 18, 1], 1.204 + ["t", "-02.js", "test.prototype.sub.sub.sub", 20, 1], 1.205 + ["x", "-02.js", "this", 20, 32], 1.206 + ["y", "-02.js", "this", 20, 41], 1.207 + ["z", "-02.js", "this", 20, 50] 1.208 + ]; 1.209 + 1.210 + for (let [label, value, description, line, column] of expectedResults) { 1.211 + let target = gFilteredFunctions.selectedItem.target; 1.212 + 1.213 + if (label) { 1.214 + is(target.querySelector(".results-panel-item-label").getAttribute("value"), 1.215 + gDebugger.SourceUtils.trimUrlLength(label + "()"), 1.216 + "The corect label (" + label + ") is currently selected."); 1.217 + } else { 1.218 + ok(!target.querySelector(".results-panel-item-label"), 1.219 + "Shouldn't create empty label nodes."); 1.220 + } 1.221 + if (value) { 1.222 + ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").contains(value), 1.223 + "The corect value (" + value + ") is attached."); 1.224 + } else { 1.225 + ok(!target.querySelector(".results-panel-item-label-below"), 1.226 + "Shouldn't create empty label nodes."); 1.227 + } 1.228 + if (description) { 1.229 + is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description, 1.230 + "The corect description (" + description + ") is currently shown."); 1.231 + } else { 1.232 + ok(!target.querySelector(".results-panel-item-label-before"), 1.233 + "Shouldn't create empty label nodes."); 1.234 + } 1.235 + 1.236 + ok(isCaretPos(gPanel, line, column), 1.237 + "The editor didn't jump to the correct line."); 1.238 + 1.239 + EventUtils.sendKey("DOWN", gDebugger); 1.240 + } 1.241 + 1.242 + ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]), 1.243 + "The editor didn't jump to the correct line again."); 1.244 + 1.245 + deferred.resolve(); 1.246 + } else { 1.247 + ok(false, "How did you get here? Go away, you."); 1.248 + } 1.249 + }); 1.250 + 1.251 + setText(gSearchBox, "@"); 1.252 + return deferred.promise; 1.253 +} 1.254 + 1.255 +function thirdJsSearch() { 1.256 + let deferred = promise.defer(); 1.257 + 1.258 + once(gDebugger, "popupshown").then(() => { 1.259 + writeInfo(); 1.260 + 1.261 + is(gFilteredFunctions.selectedIndex, 0, 1.262 + "An item should be selected in the filtered functions view (1)."); 1.263 + ok(gFilteredFunctions.selectedItem, 1.264 + "An item should be selected in the filtered functions view (2)."); 1.265 + 1.266 + if (gSources.selectedValue.indexOf("-03.js") != -1) { 1.267 + let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " "; 1.268 + let expectedResults = [ 1.269 + ["namedEventListener", "-03.js", "", 4, 43], 1.270 + ["a" + s + "A", "-03.js", "bar", 10, 5], 1.271 + ["b" + s + "B", "-03.js", "bar.alpha", 15, 5], 1.272 + ["c" + s + "C", "-03.js", "bar.alpha.beta", 20, 5], 1.273 + ["d" + s + "D", "-03.js", "this.theta", 25, 5], 1.274 + ["fun", "-03.js", "", 29, 7], 1.275 + ["foo", "-03.js", "", 29, 13], 1.276 + ["bar", "-03.js", "", 29, 19], 1.277 + ["t_foo", "-03.js", "this", 29, 25], 1.278 + ["w_bar" + s + "baz", "-03.js", "window", 29, 38] 1.279 + ]; 1.280 + 1.281 + for (let [label, value, description, line, column] of expectedResults) { 1.282 + let target = gFilteredFunctions.selectedItem.target; 1.283 + 1.284 + if (label) { 1.285 + is(target.querySelector(".results-panel-item-label").getAttribute("value"), 1.286 + gDebugger.SourceUtils.trimUrlLength(label + "()"), 1.287 + "The corect label (" + label + ") is currently selected."); 1.288 + } else { 1.289 + ok(!target.querySelector(".results-panel-item-label"), 1.290 + "Shouldn't create empty label nodes."); 1.291 + } 1.292 + if (value) { 1.293 + ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").contains(value), 1.294 + "The corect value (" + value + ") is attached."); 1.295 + } else { 1.296 + ok(!target.querySelector(".results-panel-item-label-below"), 1.297 + "Shouldn't create empty label nodes."); 1.298 + } 1.299 + if (description) { 1.300 + is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description, 1.301 + "The corect description (" + description + ") is currently shown."); 1.302 + } else { 1.303 + ok(!target.querySelector(".results-panel-item-label-before"), 1.304 + "Shouldn't create empty label nodes."); 1.305 + } 1.306 + 1.307 + ok(isCaretPos(gPanel, line, column), 1.308 + "The editor didn't jump to the correct line."); 1.309 + 1.310 + EventUtils.sendKey("DOWN", gDebugger); 1.311 + } 1.312 + 1.313 + ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]), 1.314 + "The editor didn't jump to the correct line again."); 1.315 + 1.316 + deferred.resolve(); 1.317 + } else { 1.318 + ok(false, "How did you get here? Go away, you."); 1.319 + } 1.320 + }); 1.321 + 1.322 + setText(gSearchBox, "@"); 1.323 + return deferred.promise; 1.324 +} 1.325 + 1.326 +function filterSearch() { 1.327 + let deferred = promise.defer(); 1.328 + 1.329 + once(gDebugger, "popupshown").then(() => { 1.330 + writeInfo(); 1.331 + 1.332 + is(gFilteredFunctions.selectedIndex, 0, 1.333 + "An item should be selected in the filtered functions view (1)."); 1.334 + ok(gFilteredFunctions.selectedItem, 1.335 + "An item should be selected in the filtered functions view (2)."); 1.336 + 1.337 + if (gSources.selectedValue.indexOf("-03.js") != -1) { 1.338 + let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " "; 1.339 + let expectedResults = [ 1.340 + ["namedEventListener", "-03.js", "", 4, 43], 1.341 + ["bar", "-03.js", "", 29, 19], 1.342 + ["w_bar" + s + "baz", "-03.js", "window", 29, 38], 1.343 + ["anonymousExpression", "-01.js", "test.prototype", 9, 3], 1.344 + ["namedExpression" + s + "NAME", "-01.js", "test.prototype", 11, 3], 1.345 + ["arrow", ".html", "", 20, 11], 1.346 + ["bar2", ".html", "", 23, 18] 1.347 + ]; 1.348 + 1.349 + for (let [label, value, description, line, column] of expectedResults) { 1.350 + let target = gFilteredFunctions.selectedItem.target; 1.351 + 1.352 + if (label) { 1.353 + is(target.querySelector(".results-panel-item-label").getAttribute("value"), 1.354 + gDebugger.SourceUtils.trimUrlLength(label + "()"), 1.355 + "The corect label (" + label + ") is currently selected."); 1.356 + } else { 1.357 + ok(!target.querySelector(".results-panel-item-label"), 1.358 + "Shouldn't create empty label nodes."); 1.359 + } 1.360 + if (value) { 1.361 + ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").contains(value), 1.362 + "The corect value (" + value + ") is attached."); 1.363 + } else { 1.364 + ok(!target.querySelector(".results-panel-item-label-below"), 1.365 + "Shouldn't create empty label nodes."); 1.366 + } 1.367 + if (description) { 1.368 + is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description, 1.369 + "The corect description (" + description + ") is currently shown."); 1.370 + } else { 1.371 + ok(!target.querySelector(".results-panel-item-label-before"), 1.372 + "Shouldn't create empty label nodes."); 1.373 + } 1.374 + 1.375 + ok(isCaretPos(gPanel, line, column), 1.376 + "The editor didn't jump to the correct line."); 1.377 + 1.378 + EventUtils.sendKey("DOWN", gDebugger); 1.379 + } 1.380 + 1.381 + ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]), 1.382 + "The editor didn't jump to the correct line again."); 1.383 + 1.384 + deferred.resolve(); 1.385 + } else { 1.386 + ok(false, "How did you get here? Go away, you."); 1.387 + } 1.388 + }); 1.389 + 1.390 + setText(gSearchBox, "@r"); 1.391 + return deferred.promise; 1.392 +} 1.393 + 1.394 +function bogusSearch() { 1.395 + let deferred = promise.defer(); 1.396 + 1.397 + once(gDebugger, "popuphidden").then(() => { 1.398 + ok(true, "Popup was successfully hidden after no matches were found."); 1.399 + deferred.resolve(); 1.400 + }); 1.401 + 1.402 + setText(gSearchBox, "@bogus"); 1.403 + return deferred.promise; 1.404 +} 1.405 + 1.406 +function incrementalSearch() { 1.407 + let deferred = promise.defer(); 1.408 + 1.409 + once(gDebugger, "popupshown").then(() => { 1.410 + ok(true, "Popup was successfully shown after some matches were found."); 1.411 + deferred.resolve(); 1.412 + }); 1.413 + 1.414 + setText(gSearchBox, "@NAME"); 1.415 + return deferred.promise; 1.416 +} 1.417 + 1.418 +function emptySearch() { 1.419 + let deferred = promise.defer(); 1.420 + 1.421 + once(gDebugger, "popuphidden").then(() => { 1.422 + ok(true, "Popup was successfully hidden when nothing was searched."); 1.423 + deferred.resolve(); 1.424 + }); 1.425 + 1.426 + clearText(gSearchBox); 1.427 + return deferred.promise; 1.428 +} 1.429 + 1.430 +function showSource(aLabel) { 1.431 + let deferred = promise.defer(); 1.432 + 1.433 + waitForSourceShown(gPanel, aLabel).then(deferred.resolve); 1.434 + gSources.selectedItem = e => e.attachment.label == aLabel; 1.435 + 1.436 + return deferred.promise; 1.437 +} 1.438 + 1.439 +function saveSearch() { 1.440 + let finished = once(gDebugger, "popuphidden"); 1.441 + 1.442 + // Either by pressing RETURN or clicking on an item in the popup, 1.443 + // the popup should hide and the item should become selected. 1.444 + let random = Math.random(); 1.445 + if (random >= 0.33) { 1.446 + EventUtils.sendKey("RETURN", gDebugger); 1.447 + } else if (random >= 0.66) { 1.448 + EventUtils.sendKey("RETURN", gDebugger); 1.449 + } else { 1.450 + EventUtils.sendMouseEvent({ type: "click" }, 1.451 + gFilteredFunctions.selectedItem.target, 1.452 + gDebugger); 1.453 + } 1.454 + 1.455 + return finished; 1.456 +} 1.457 + 1.458 +function writeInfo() { 1.459 + info("Current source url:\n" + gSources.selectedValue); 1.460 + info("Debugger editor text:\n" + gEditor.getText()); 1.461 +} 1.462 + 1.463 +registerCleanupFunction(function() { 1.464 + gTab = null; 1.465 + gDebuggee = null; 1.466 + gPanel = null; 1.467 + gDebugger = null; 1.468 + gEditor = null; 1.469 + gSources = null; 1.470 + gSearchBox = null; 1.471 + gFilteredFunctions = null; 1.472 +});