123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
- /* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
- /**
- * Tests if the function searching works properly.
- */
- const TAB_URL = EXAMPLE_URL + "doc_function-search.html";
- var gTab, gPanel, gDebugger;
- var gEditor, gSources, gSearchBox, gFilteredFunctions;
- function test() {
- let options = {
- source: EXAMPLE_URL + "code_function-search-01.js",
- line: 1
- };
- initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
- gTab = aTab;
- gPanel = aPanel;
- gDebugger = gPanel.panelWin;
- gEditor = gDebugger.DebuggerView.editor;
- gSources = gDebugger.DebuggerView.Sources;
- gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
- gFilteredFunctions = gDebugger.DebuggerView.Filtering.FilteredFunctions;
- showSource("doc_function-search.html")
- .then(htmlSearch)
- .then(() => showSource("code_function-search-01.js"))
- .then(firstJsSearch)
- .then(() => showSource("code_function-search-02.js"))
- .then(secondJsSearch)
- .then(() => showSource("code_function-search-03.js"))
- .then(thirdJsSearch)
- .then(saveSearch)
- .then(filterSearch)
- .then(bogusSearch)
- .then(incrementalSearch)
- .then(emptySearch)
- .then(() => closeDebuggerAndFinish(gPanel))
- .then(null, aError => {
- ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
- });
- });
- }
- function htmlSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popupshown").then(() => {
- writeInfo();
- is(gFilteredFunctions.selectedIndex, 0,
- "An item should be selected in the filtered functions view (1).");
- ok(gFilteredFunctions.selectedItem,
- "An item should be selected in the filtered functions view (2).");
- if (gSources.selectedItem.attachment.source.url.indexOf(".html") != -1) {
- let expectedResults = [
- ["inline", ".html", "", 19, 16],
- ["arrow", ".html", "", 20, 11],
- ["foo", ".html", "", 22, 11],
- ["foo2", ".html", "", 23, 11],
- ["bar2", ".html", "", 23, 18]
- ];
- for (let [label, value, description, line, column] of expectedResults) {
- let target = gFilteredFunctions.selectedItem.target;
- if (label) {
- is(target.querySelector(".results-panel-item-label").getAttribute("value"),
- gDebugger.SourceUtils.trimUrlLength(label + "()"),
- "The correct label (" + label + ") is currently selected.");
- } else {
- ok(!target.querySelector(".results-panel-item-label"),
- "Shouldn't create empty label nodes.");
- }
- if (value) {
- ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
- "The correct value (" + value + ") is attached.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-below"),
- "Shouldn't create empty label nodes.");
- }
- if (description) {
- is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
- "The correct description (" + description + ") is currently shown.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-before"),
- "Shouldn't create empty label nodes.");
- }
- ok(isCaretPos(gPanel, line, column),
- "The editor didn't jump to the correct line.");
- EventUtils.sendKey("DOWN", gDebugger);
- }
- ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
- "The editor didn't jump to the correct line again.");
- deferred.resolve();
- } else {
- ok(false, "How did you get here? Go away, you.");
- }
- });
- setText(gSearchBox, "@");
- return deferred.promise;
- }
- function firstJsSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popupshown").then(() => {
- writeInfo();
- is(gFilteredFunctions.selectedIndex, 0,
- "An item should be selected in the filtered functions view (1).");
- ok(gFilteredFunctions.selectedItem,
- "An item should be selected in the filtered functions view (2).");
- if (gSources.selectedItem.attachment.source.url.indexOf("-01.js") != -1) {
- let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
- let expectedResults = [
- ["test", "-01.js", "", 4, 10],
- ["anonymousExpression", "-01.js", "test.prototype", 9, 3],
- ["namedExpression" + s + "NAME", "-01.js", "test.prototype", 11, 3],
- ["a_test", "-01.js", "foo", 22, 3],
- ["n_test" + s + "x", "-01.js", "foo", 24, 3],
- ["a_test", "-01.js", "foo.sub", 27, 5],
- ["n_test" + s + "y", "-01.js", "foo.sub", 29, 5],
- ["a_test", "-01.js", "foo.sub.sub", 32, 7],
- ["n_test" + s + "z", "-01.js", "foo.sub.sub", 34, 7],
- ["test_SAME_NAME", "-01.js", "foo.sub.sub.sub", 37, 9]
- ];
- for (let [label, value, description, line, column] of expectedResults) {
- let target = gFilteredFunctions.selectedItem.target;
- if (label) {
- is(target.querySelector(".results-panel-item-label").getAttribute("value"),
- gDebugger.SourceUtils.trimUrlLength(label + "()"),
- "The correct label (" + label + ") is currently selected.");
- } else {
- ok(!target.querySelector(".results-panel-item-label"),
- "Shouldn't create empty label nodes.");
- }
- if (value) {
- ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
- "The correct value (" + value + ") is attached.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-below"),
- "Shouldn't create empty label nodes.");
- }
- if (description) {
- is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
- "The correct description (" + description + ") is currently shown.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-before"),
- "Shouldn't create empty label nodes.");
- }
- ok(isCaretPos(gPanel, line, column),
- "The editor didn't jump to the correct line.");
- EventUtils.sendKey("DOWN", gDebugger);
- }
- ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
- "The editor didn't jump to the correct line again.");
- deferred.resolve();
- } else {
- ok(false, "How did you get here? Go away, you.");
- }
- });
- setText(gSearchBox, "@");
- return deferred.promise;
- }
- function secondJsSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popupshown").then(() => {
- writeInfo();
- is(gFilteredFunctions.selectedIndex, 0,
- "An item should be selected in the filtered functions view (1).");
- ok(gFilteredFunctions.selectedItem,
- "An item should be selected in the filtered functions view (2).");
- if (gSources.selectedItem.attachment.source.url.indexOf("-02.js") != -1) {
- let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
- let expectedResults = [
- ["test2", "-02.js", "", 4, 5],
- ["test3" + s + "test3_NAME", "-02.js", "", 8, 5],
- ["test4_SAME_NAME", "-02.js", "", 11, 5],
- ["x" + s + "X", "-02.js", "test.prototype", 14, 1],
- ["y" + s + "Y", "-02.js", "test.prototype.sub", 16, 1],
- ["z" + s + "Z", "-02.js", "test.prototype.sub.sub", 18, 1],
- ["t", "-02.js", "test.prototype.sub.sub.sub", 20, 1],
- ["x", "-02.js", "this", 20, 32],
- ["y", "-02.js", "this", 20, 41],
- ["z", "-02.js", "this", 20, 50]
- ];
- for (let [label, value, description, line, column] of expectedResults) {
- let target = gFilteredFunctions.selectedItem.target;
- if (label) {
- is(target.querySelector(".results-panel-item-label").getAttribute("value"),
- gDebugger.SourceUtils.trimUrlLength(label + "()"),
- "The correct label (" + label + ") is currently selected.");
- } else {
- ok(!target.querySelector(".results-panel-item-label"),
- "Shouldn't create empty label nodes.");
- }
- if (value) {
- ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
- "The correct value (" + value + ") is attached.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-below"),
- "Shouldn't create empty label nodes.");
- }
- if (description) {
- is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
- "The correct description (" + description + ") is currently shown.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-before"),
- "Shouldn't create empty label nodes.");
- }
- ok(isCaretPos(gPanel, line, column),
- "The editor didn't jump to the correct line.");
- EventUtils.sendKey("DOWN", gDebugger);
- }
- ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
- "The editor didn't jump to the correct line again.");
- deferred.resolve();
- } else {
- ok(false, "How did you get here? Go away, you.");
- }
- });
- setText(gSearchBox, "@");
- return deferred.promise;
- }
- function thirdJsSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popupshown").then(() => {
- writeInfo();
- is(gFilteredFunctions.selectedIndex, 0,
- "An item should be selected in the filtered functions view (1).");
- ok(gFilteredFunctions.selectedItem,
- "An item should be selected in the filtered functions view (2).");
- if (gSources.selectedItem.attachment.source.url.indexOf("-03.js") != -1) {
- let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
- let expectedResults = [
- ["namedEventListener", "-03.js", "", 4, 43],
- ["a" + s + "A", "-03.js", "bar", 10, 5],
- ["b" + s + "B", "-03.js", "bar.alpha", 15, 5],
- ["c" + s + "C", "-03.js", "bar.alpha.beta", 20, 5],
- ["d" + s + "D", "-03.js", "this.theta", 25, 5],
- ["fun", "-03.js", "", 29, 7],
- ["foo", "-03.js", "", 29, 13],
- ["bar", "-03.js", "", 29, 19],
- ["t_foo", "-03.js", "this", 29, 25],
- ["w_bar" + s + "baz", "-03.js", "window", 29, 38]
- ];
- for (let [label, value, description, line, column] of expectedResults) {
- let target = gFilteredFunctions.selectedItem.target;
- if (label) {
- is(target.querySelector(".results-panel-item-label").getAttribute("value"),
- gDebugger.SourceUtils.trimUrlLength(label + "()"),
- "The correct label (" + label + ") is currently selected.");
- } else {
- ok(!target.querySelector(".results-panel-item-label"),
- "Shouldn't create empty label nodes.");
- }
- if (value) {
- ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
- "The correct value (" + value + ") is attached.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-below"),
- "Shouldn't create empty label nodes.");
- }
- if (description) {
- is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
- "The correct description (" + description + ") is currently shown.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-before"),
- "Shouldn't create empty label nodes.");
- }
- ok(isCaretPos(gPanel, line, column),
- "The editor didn't jump to the correct line.");
- EventUtils.sendKey("DOWN", gDebugger);
- }
- ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
- "The editor didn't jump to the correct line again.");
- deferred.resolve();
- } else {
- ok(false, "How did you get here? Go away, you.");
- }
- });
- setText(gSearchBox, "@");
- return deferred.promise;
- }
- function filterSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popupshown").then(() => {
- writeInfo();
- is(gFilteredFunctions.selectedIndex, 0,
- "An item should be selected in the filtered functions view (1).");
- ok(gFilteredFunctions.selectedItem,
- "An item should be selected in the filtered functions view (2).");
- if (gSources.selectedItem.attachment.source.url.indexOf("-03.js") != -1) {
- let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
- let expectedResults = [
- ["namedEventListener", "-03.js", "", 4, 43],
- ["bar", "-03.js", "", 29, 19],
- ["w_bar" + s + "baz", "-03.js", "window", 29, 38],
- ["anonymousExpression", "-01.js", "test.prototype", 9, 3],
- ["namedExpression" + s + "NAME", "-01.js", "test.prototype", 11, 3],
- ["arrow", ".html", "", 20, 11],
- ["bar2", ".html", "", 23, 18]
- ];
- for (let [label, value, description, line, column] of expectedResults) {
- let target = gFilteredFunctions.selectedItem.target;
- if (label) {
- is(target.querySelector(".results-panel-item-label").getAttribute("value"),
- gDebugger.SourceUtils.trimUrlLength(label + "()"),
- "The correct label (" + label + ") is currently selected.");
- } else {
- ok(!target.querySelector(".results-panel-item-label"),
- "Shouldn't create empty label nodes.");
- }
- if (value) {
- ok(target.querySelector(".results-panel-item-label-below").getAttribute("value").includes(value),
- "The correct value (" + value + ") is attached.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-below"),
- "Shouldn't create empty label nodes.");
- }
- if (description) {
- is(target.querySelector(".results-panel-item-label-before").getAttribute("value"), description,
- "The correct description (" + description + ") is currently shown.");
- } else {
- ok(!target.querySelector(".results-panel-item-label-before"),
- "Shouldn't create empty label nodes.");
- }
- ok(isCaretPos(gPanel, line, column),
- "The editor didn't jump to the correct line.");
- EventUtils.sendKey("DOWN", gDebugger);
- }
- ok(isCaretPos(gPanel, expectedResults[0][3], expectedResults[0][4]),
- "The editor didn't jump to the correct line again.");
- deferred.resolve();
- } else {
- ok(false, "How did you get here? Go away, you.");
- }
- });
- setText(gSearchBox, "@r");
- return deferred.promise;
- }
- function bogusSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popuphidden").then(() => {
- ok(true, "Popup was successfully hidden after no matches were found.");
- deferred.resolve();
- });
- setText(gSearchBox, "@bogus");
- return deferred.promise;
- }
- function incrementalSearch() {
- let deferred = promise.defer();
- once(gDebugger, "popupshown").then(() => {
- ok(true, "Popup was successfully shown after some matches were found.");
- deferred.resolve();
- });
- setText(gSearchBox, "@NAME");
- return deferred.promise;
- }
- function emptySearch() {
- let deferred = promise.defer();
- once(gDebugger, "popuphidden").then(() => {
- ok(true, "Popup was successfully hidden when nothing was searched.");
- deferred.resolve();
- });
- clearText(gSearchBox);
- return deferred.promise;
- }
- function showSource(aLabel) {
- let deferred = promise.defer();
- waitForSourceShown(gPanel, aLabel).then(deferred.resolve);
- gSources.selectedItem = e => e.attachment.label == aLabel;
- return deferred.promise;
- }
- function saveSearch() {
- let finished = once(gDebugger, "popuphidden");
- // Either by pressing RETURN or clicking on an item in the popup,
- // the popup should hide and the item should become selected.
- let random = Math.random();
- if (random >= 0.33) {
- EventUtils.sendKey("RETURN", gDebugger);
- } else if (random >= 0.66) {
- EventUtils.sendKey("RETURN", gDebugger);
- } else {
- EventUtils.sendMouseEvent({ type: "click" },
- gFilteredFunctions.selectedItem.target,
- gDebugger);
- }
- return finished;
- }
- function writeInfo() {
- info("Current source url:\n" + getSelectedSourceURL(gSources));
- info("Debugger editor text:\n" + gEditor.getText());
- }
- registerCleanupFunction(function () {
- gTab = null;
- gPanel = null;
- gDebugger = null;
- gEditor = null;
- gSources = null;
- gSearchBox = null;
- gFilteredFunctions = null;
- });
|