michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests basic functionality of global search (lowercase + upper case, expected michael@0: * UI behavior, number of results found etc.) michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gSearchView, gSearchBox; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gSearchView = gDebugger.DebuggerView.GlobalSearch; michael@0: gSearchBox = gDebugger.DebuggerView.Filtering._searchbox; michael@0: michael@0: waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1) michael@0: .then(firstSearch) michael@0: .then(secondSearch) michael@0: .then(clearSearch) michael@0: .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + aError.message + "\n" + aError.stack); michael@0: }); michael@0: michael@0: gDebuggee.firstCall(); michael@0: }); michael@0: } michael@0: michael@0: function firstSearch() { michael@0: let deferred = promise.defer(); michael@0: michael@0: is(gSearchView.itemCount, 0, michael@0: "The global search pane shouldn't have any entries yet."); michael@0: is(gSearchView.widget._parent.hidden, true, michael@0: "The global search pane shouldn't be visible yet."); michael@0: is(gSearchView._splitter.hidden, true, michael@0: "The global search pane splitter shouldn't be visible yet."); michael@0: michael@0: gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { michael@0: // Some operations are synchronously dispatched on the main thread, michael@0: // to avoid blocking UI, thus giving the impression of faster searching. michael@0: executeSoon(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(isCaretPos(gPanel, 1), michael@0: "The editor shouldn't have jumped to a matching line yet."); michael@0: ok(gSources.selectedValue.contains("-02.js"), michael@0: "The current source shouldn't have changed after a global search."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search."); michael@0: michael@0: let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); michael@0: is(sourceResults.length, 2, michael@0: "There should be matches found in two sources."); michael@0: michael@0: let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); michael@0: let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); michael@0: is(item0.instance.expanded, true, michael@0: "The first source results should automatically be expanded.") michael@0: is(item1.instance.expanded, true, michael@0: "The second source results should automatically be expanded.") michael@0: michael@0: let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result"); michael@0: let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result"); michael@0: is(searchResult0.length, 1, michael@0: "There should be one line result for the first url."); michael@0: is(searchResult1.length, 2, michael@0: "There should be two line results for the second url."); michael@0: michael@0: let firstLine0 = searchResult0[0]; michael@0: is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1", michael@0: "The first result for the first source doesn't have the correct line attached."); michael@0: michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1, michael@0: "The first result for the first source doesn't have the correct number of nodes for a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 3, michael@0: "The first result for the first source doesn't have the correct number of strings in a line."); michael@0: michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, michael@0: "The first result for the first source doesn't have the correct number of matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", michael@0: "The first result for the first source doesn't have the correct match in a line."); michael@0: michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, michael@0: "The first result for the first source doesn't have the correct number of non-matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ", michael@0: "The first result for the first source doesn't have the correct non-matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.", michael@0: "The first result for the first source doesn't have the correct non-matches in a line."); michael@0: michael@0: let firstLine1 = searchResult1[0]; michael@0: is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1", michael@0: "The first result for the second source doesn't have the correct line attached."); michael@0: michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1, michael@0: "The first result for the second source doesn't have the correct number of nodes for a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3, michael@0: "The first result for the second source doesn't have the correct number of strings in a line."); michael@0: michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, michael@0: "The first result for the second source doesn't have the correct number of matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", michael@0: "The first result for the second source doesn't have the correct match in a line."); michael@0: michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, michael@0: "The first result for the second source doesn't have the correct number of non-matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ", michael@0: "The first result for the second source doesn't have the correct non-matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.", michael@0: "The first result for the second source doesn't have the correct non-matches in a line."); michael@0: michael@0: let secondLine1 = searchResult1[1]; michael@0: is(secondLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "6", michael@0: "The second result for the second source doesn't have the correct line attached."); michael@0: michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents").length, 1, michael@0: "The second result for the second source doesn't have the correct number of nodes for a line."); michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3, michael@0: "The second result for the second source doesn't have the correct number of strings in a line."); michael@0: michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1, michael@0: "The second result for the second source doesn't have the correct number of matches in a line."); michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de", michael@0: "The second result for the second source doesn't have the correct match in a line."); michael@0: michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2, michael@0: "The second result for the second source doesn't have the correct number of non-matches in a line."); michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), ' eval("', michael@0: "The second result for the second source doesn't have the correct non-matches in a line."); michael@0: is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), 'bugger;");', michael@0: "The second result for the second source doesn't have the correct non-matches in a line."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: setText(gSearchBox, "!de"); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function secondSearch() { michael@0: let deferred = promise.defer(); michael@0: michael@0: is(gSearchView.itemCount, 2, michael@0: "The global search pane should have some child nodes from the previous search."); michael@0: is(gSearchView.widget._parent.hidden, false, michael@0: "The global search pane should be visible from the previous search."); michael@0: is(gSearchView._splitter.hidden, false, michael@0: "The global search pane splitter should be visible from the previous search."); michael@0: michael@0: gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => { michael@0: // Some operations are synchronously dispatched on the main thread, michael@0: // to avoid blocking UI, thus giving the impression of faster searching. michael@0: executeSoon(() => { michael@0: info("Current source url:\n" + gSources.selectedValue); michael@0: info("Debugger editor text:\n" + gEditor.getText()); michael@0: michael@0: ok(isCaretPos(gPanel, 1), michael@0: "The editor shouldn't have jumped to a matching line yet."); michael@0: ok(gSources.selectedValue.contains("-02.js"), michael@0: "The current source shouldn't have changed after a global search."); michael@0: is(gSources.visibleItems.length, 2, michael@0: "Not all the sources are shown after the global search."); michael@0: michael@0: let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results"); michael@0: is(sourceResults.length, 2, michael@0: "There should be matches found in two sources."); michael@0: michael@0: let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]); michael@0: let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]); michael@0: is(item0.instance.expanded, true, michael@0: "The first source results should automatically be expanded.") michael@0: is(item1.instance.expanded, true, michael@0: "The second source results should automatically be expanded.") michael@0: michael@0: let searchResult0 = sourceResults[0].querySelectorAll(".dbg-search-result"); michael@0: let searchResult1 = sourceResults[1].querySelectorAll(".dbg-search-result"); michael@0: is(searchResult0.length, 1, michael@0: "There should be one line result for the first url."); michael@0: is(searchResult1.length, 1, michael@0: "There should be one line result for the second url."); michael@0: michael@0: let firstLine0 = searchResult0[0]; michael@0: is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1", michael@0: "The first result for the first source doesn't have the correct line attached."); michael@0: michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1, michael@0: "The first result for the first source doesn't have the correct number of nodes for a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 5, michael@0: "The first result for the first source doesn't have the correct number of strings in a line."); michael@0: michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2, michael@0: "The first result for the first source doesn't have the correct number of matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed", michael@0: "The first result for the first source doesn't have the correct matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed", michael@0: "The first result for the first source doesn't have the correct matches in a line."); michael@0: michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3, michael@0: "The first result for the first source doesn't have the correct number of non-matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d", michael@0: "The first result for the first source doesn't have the correct non-matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat", michael@0: "The first result for the first source doesn't have the correct non-matches in a line."); michael@0: is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.", michael@0: "The first result for the first source doesn't have the correct non-matches in a line."); michael@0: michael@0: let firstLine1 = searchResult1[0]; michael@0: is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1", michael@0: "The first result for the second source doesn't have the correct line attached."); michael@0: michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1, michael@0: "The first result for the second source doesn't have the correct number of nodes for a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 5, michael@0: "The first result for the second source doesn't have the correct number of strings in a line."); michael@0: michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2, michael@0: "The first result for the second source doesn't have the correct number of matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed", michael@0: "The first result for the second source doesn't have the correct matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed", michael@0: "The first result for the second source doesn't have the correct matches in a line."); michael@0: michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3, michael@0: "The first result for the second source doesn't have the correct number of non-matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d", michael@0: "The first result for the second source doesn't have the correct non-matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat", michael@0: "The first result for the second source doesn't have the correct non-matches in a line."); michael@0: is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.", michael@0: "The first result for the second source doesn't have the correct non-matches in a line."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: backspaceText(gSearchBox, 2); michael@0: typeText(gSearchBox, "ED"); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function clearSearch() { michael@0: gSearchView.clearView(); michael@0: michael@0: is(gSearchView.itemCount, 0, michael@0: "The global search pane shouldn't have any child nodes after clearing."); michael@0: is(gSearchView.widget._parent.hidden, true, michael@0: "The global search pane shouldn't be visible after clearing."); michael@0: is(gSearchView._splitter.hidden, true, michael@0: "The global search pane splitter shouldn't be visible after clearing."); michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: gSearchView = null; michael@0: gSearchBox = null; michael@0: });