Bug 876277 - Cleanup debugger search tests, r=past

--HG--
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-01.js => browser/devtools/debugger/test/browser_dbg_search-basic.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-03.js => browser/devtools/debugger/test/browser_dbg_search-global-01.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-04.js => browser/devtools/debugger/test/browser_dbg_search-global-02.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-05.js => browser/devtools/debugger/test/browser_dbg_search-global-03.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-06.js => browser/devtools/debugger/test/browser_dbg_search-global-04.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-07.js => browser/devtools/debugger/test/browser_dbg_search-global-05.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-08.js => browser/devtools/debugger/test/browser_dbg_search-global-06.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-02.js => browser/devtools/debugger/test/browser_dbg_search-sources-01.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-files_ui.js => browser/devtools/debugger/test/browser_dbg_search-sources-02.js
rename : browser/devtools/debugger/test/browser_dbg_function-search.js => browser/devtools/debugger/test/browser_dbg_search-symbols.js
rename : browser/devtools/debugger/test/browser_dbg_scripts-searching-popup.js => browser/devtools/debugger/test/browser_dbg_searchbox-help-popup.js
This commit is contained in:
Victor Porof 2013-09-13 16:23:17 +03:00
parent 2f015dcdc1
commit b7c021dec1
22 changed files with 2257 additions and 3230 deletions

View File

@ -1,499 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_function-search-02.html";
/**
* Tests if the function searching works properly.
*/
let gPane = null;
let gTab = null;
let gDebuggee = null;
let gDebugger = null;
let gEditor = null;
let gSources = null;
let gSearchBox = null;
let gFilteredFunctions = null;
function test()
{
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
Services.tm.currentThread.dispatch({ run: testFunctionsFilter }, 0);
});
});
}
function testFunctionsFilter()
{
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
gFilteredFunctions = gDebugger.DebuggerView.FilteredFunctions;
htmlSearch(function() {
showSource("test-function-search-01.js", function() {
firstSearch(function() {
showSource("test-function-search-02.js", function() {
secondSearch(function() {
showSource("test-function-search-03.js", function() {
thirdSearch(function() {
saveSearch(function() {
filterSearch(function() {
bogusSearch(function() {
anotherSearch(function() {
emptySearch(function() {
closeDebuggerAndFinish();
});
})
})
});
});
});
});
});
});
});
});
});
}
function htmlSearch(callback) {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view");
let url = gSources.selectedValue;
if (url.indexOf("-02.html") != -1) {
executeSoon(function() {
let expectedResults = [
["inline", "-02.html", "", 16, 15],
["arrow", "-02.html", "", 17, 10],
["foo", "-02.html", "", 19, 10],
["foo2", "-02.html", "", 20, 10],
["bar2", "-02.html", "", 20, 17]
];
for (let [label, value, description, line, col] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
info("Editor caret position: " + gEditor.getCaretPosition().toSource());
ok(gEditor.getCaretPosition().line == line &&
gEditor.getCaretPosition().col == col,
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel, label,
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue, value,
"The current source isn't the correct one, according to the value.");
EventUtils.sendKey("DOWN", gDebugger);
}
ok(gEditor.getCaretPosition().line == expectedResults[0][3] &&
gEditor.getCaretPosition().col == expectedResults[0][4],
"The editor didn't jump to the correct line again.");
executeSoon(callback);
});
} else {
ok(false, "How did you get here? Go away, you.");
}
});
write("@");
}
function firstSearch(callback) {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view");
let url = gSources.selectedValue;
if (url.indexOf("-01.js") != -1) {
executeSoon(function() {
let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
let expectedResults = [
["test", "-01.js", "", 3, 9],
["anonymousExpression", "-01.js", "test.prototype", 8, 2],
["namedExpression" + s + "NAME", "-01.js", "test.prototype", 10, 2],
["a_test", "-01.js", "foo", 21, 2],
["n_test" + s + "x", "-01.js", "foo", 23, 2],
["a_test", "-01.js", "foo.sub", 26, 4],
["n_test" + s + "y", "-01.js", "foo.sub", 28, 4],
["a_test", "-01.js", "foo.sub.sub", 31, 6],
["n_test" + s + "z", "-01.js", "foo.sub.sub", 33, 6],
["test_SAME_NAME", "-01.js", "foo.sub.sub.sub", 36, 8]
];
for (let [label, value, description, line, col] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
info("Editor caret position: " + gEditor.getCaretPosition().toSource());
ok(gEditor.getCaretPosition().line == line &&
gEditor.getCaretPosition().col == col,
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel, label,
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue, value,
"The current source isn't the correct one, according to the value.");
EventUtils.sendKey("DOWN", gDebugger);
}
ok(gEditor.getCaretPosition().line == expectedResults[0][3] &&
gEditor.getCaretPosition().col == expectedResults[0][4],
"The editor didn't jump to the correct line again.");
executeSoon(callback);
});
} else {
ok(false, "How did you get here? Go away, you.");
}
});
write("@");
}
function secondSearch(callback) {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
let expectedResults = [
["test2", "-02.js", "", 3, 4],
["test3" + s + "test3_NAME", "-02.js", "", 7, 4],
["test4_SAME_NAME", "-02.js", "", 10, 4],
["x" + s + "X", "-02.js", "test.prototype", 13, 0],
["y" + s + "Y", "-02.js", "test.prototype.sub", 15, 0],
["z" + s + "Z", "-02.js", "test.prototype.sub.sub", 17, 0],
["t", "-02.js", "test.prototype.sub.sub.sub", 19, 0],
["x", "-02.js", "", 19, 31],
["y", "-02.js", "", 19, 40],
["z", "-02.js", "", 19, 49]
];
for (let [label, value, description, line, col] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
info("Editor caret position: " + gEditor.getCaretPosition().toSource());
ok(gEditor.getCaretPosition().line == line &&
gEditor.getCaretPosition().col == col,
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel, label,
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue, value,
"The current source isn't the correct one, according to the value.");
EventUtils.sendKey("DOWN", gDebugger);
}
ok(gEditor.getCaretPosition().line == expectedResults[0][3] &&
gEditor.getCaretPosition().col == expectedResults[0][4],
"The editor didn't jump to the correct line again.");
executeSoon(callback);
});
} else {
ok(false, "How did you get here? Go away, you.");
}
});
write("@");
}
function thirdSearch(callback) {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view");
let url = gSources.selectedValue;
if (url.indexOf("-03.js") != -1) {
executeSoon(function() {
let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
let expectedResults = [
["namedEventListener", "-03.js", "", 3, 42],
["a" + s + "A", "-03.js", "bar", 9, 4],
["b" + s + "B", "-03.js", "bar.alpha", 14, 4],
["c" + s + "C", "-03.js", "bar.alpha.beta", 19, 4],
["d" + s + "D", "-03.js", "theta", 24, 4],
["fun", "-03.js", "", 28, 6],
["foo", "-03.js", "", 28, 12],
["bar", "-03.js", "", 28, 18],
["t_foo", "-03.js", "", 28, 24],
["w_bar" + s + "baz", "-03.js", "window", 28, 37]
];
for (let [label, value, description, line, col] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
info("Editor caret position: " + gEditor.getCaretPosition().toSource());
ok(gEditor.getCaretPosition().line == line &&
gEditor.getCaretPosition().col == col,
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel, label,
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue, value,
"The current source isn't the correct one, according to the value.");
EventUtils.sendKey("DOWN", gDebugger);
}
ok(gEditor.getCaretPosition().line == expectedResults[0][3] &&
gEditor.getCaretPosition().col == expectedResults[0][4],
"The editor didn't jump to the correct line again.");
executeSoon(callback);
});
} else {
ok(false, "How did you get here? Go away, you.");
}
});
write("@");
}
function filterSearch(callback) {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view");
let url = gSources.selectedValue;
if (url.indexOf("-03.js") != -1) {
executeSoon(function() {
let s = " " + gDebugger.L10N.getStr("functionSearchSeparatorLabel") + " ";
let expectedResults = [
["namedEventListener", "-03.js", "", 3, 42],
["a" + s + "A", "-03.js", "bar", 9, 4],
["bar", "-03.js", "", 28, 18],
["w_bar" + s + "baz", "-03.js", "window", 28, 37],
["test3" + s + "test3_NAME", "-02.js", "", 7, 4],
["test4_SAME_NAME", "-02.js", "", 10, 4],
["anonymousExpression", "-01.js", "test.prototype", 8, 2],
["namedExpression" + s + "NAME", "-01.js", "test.prototype", 10, 2],
["a_test", "-01.js", "foo", 21, 2],
["a_test", "-01.js", "foo.sub", 26, 4]
];
for (let [label, value, description, line, col] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
info("Editor caret position: " + gEditor.getCaretPosition().toSource());
ok(gEditor.getCaretPosition().line == line &&
gEditor.getCaretPosition().col == col,
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel, label,
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue, value,
"The current source isn't the correct one, according to the value.");
EventUtils.sendKey("DOWN", gDebugger);
}
ok(gEditor.getCaretPosition().line == expectedResults[0][3] &&
gEditor.getCaretPosition().col == expectedResults[0][4],
"The editor didn't jump to the correct line again.");
executeSoon(callback);
});
} else {
ok(false, "How did you get here? Go away, you.");
}
});
write("@a");
}
function bogusSearch(callback) {
gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
ok(true, "Popup was successfully hidden after no matches were found!");
executeSoon(callback);
});
write("@bogus");
}
function anotherSearch(callback) {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
ok(true, "Popup was successfully shown after some matches were found!");
executeSoon(callback);
});
write("@NAME");
}
function emptySearch(callback) {
gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
ok(true, "Popup was successfully hidden when nothing was searched!");
executeSoon(callback);
});
clear();
}
function showSource(label, callback) {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(callback);
});
gSources.selectedLabel = label;
}
function saveSearch(callback) {
gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(callback);
});
if (Math.random() >= 0.5) {
EventUtils.sendKey("RETURN", gDebugger);
} else {
EventUtils.sendMouseEvent({ type: "click" },
gFilteredFunctions.selectedItem.target,
gDebugger);
}
}
function waitForCaretPos(number, callback)
{
// Poll every few milliseconds until the source editor line is active.
let count = 0;
let intervalID = window.setInterval(function() {
info("count: " + count + " ");
info("caret: " + gEditor.getCaretPosition().line);
if (++count > 50) {
ok(false, "Timed out while polling for the line.");
window.clearInterval(intervalID);
return closeDebuggerAndFinish();
}
if (gEditor.getCaretPosition().line != number) {
return;
}
// We got the source editor at the expected line, it's safe to callback.
window.clearInterval(intervalID);
callback();
}, 100);
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function backspace(times) {
for (let i = 0; i < times; i++) {
EventUtils.sendKey("BACK_SPACE", gDebugger);
}
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchBox = null;
gFilteredFunctions = null;
});

View File

@ -1,310 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests basic functionality of scripts filtering (token search and line jump).
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchBox = null;
function test()
{
requestLongerTimeout(3);
debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
testScriptSearching();
});
});
}
function testScriptSearching() {
let noMatchingSources = gDebugger.L10N.getStr("noMatchingSourcesText");
let token = "";
Services.tm.currentThread.dispatch({ run: function() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
write(":12");
ok(gEditor.getCaretPosition().line == 11 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
ok(gEditor.getCaretPosition().line == 12 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line after Meta+G");
EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
ok(gEditor.getCaretPosition().line == 13 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line after Ctrl+N");
EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger);
ok(gEditor.getCaretPosition().line == 12 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line after Meta+Shift+G");
EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger);
ok(gEditor.getCaretPosition().line == 11 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line after Ctrl+P");
for (let i = 0; i < 100; i++) {
EventUtils.sendKey("DOWN", gDebugger);
}
ok(gEditor.getCaretPosition().line == 32 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line after multiple DOWN keys");
for (let i = 0; i < 100; i++) {
EventUtils.sendKey("UP", gDebugger);
}
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line after multiple UP keys");
token = "debugger";
write("#" + token);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (1)");
EventUtils.sendKey("DOWN", gDebugger);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (2)");
EventUtils.sendKey("DOWN", gDebugger);
ok(gEditor.getCaretPosition().line == 12 &&
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct token. (3)");
EventUtils.sendKey("RETURN", gDebugger);
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't jump to the correct token. (4)");
EventUtils.sendKey("ENTER", gDebugger);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (5)");
EventUtils.sendKey("UP", gDebugger);
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't jump to the correct token. (5.1)");
token = "debugger;";
write(":bogus#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (6)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write(":13#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (7)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write(":#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (8)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("::#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (9)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write(":::#" + token);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (10)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("#" + token + ":bogus");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (6)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("#" + token + ":13");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (7)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("#" + token + ":");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (8)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("#" + token + "::");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (9)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("#" + token + ":::");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (10)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write(":i am not a number");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't remain at the correct token. (11)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write("#__i do not exist__");
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't remain at the correct token. (12)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
token = "debugger";
write("#" + token);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (12.1)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
clear();
EventUtils.sendKey("RETURN", gDebugger);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor shouldn't jump to another token. (12.2)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
EventUtils.sendKey("ENTER", gDebugger);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor shouldn't jump to another token. (12.3)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
write(":1:2:3:a:b:c:::12");
ok(gEditor.getCaretPosition().line == 11 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line. (13)");
write("#don't#find#me#instead#find#" + token);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (14)");
EventUtils.sendKey("DOWN", gDebugger);
ok(gEditor.getCaretPosition().line == 8 &&
gEditor.getCaretPosition().col == 2 + token.length,
"The editor didn't jump to the correct token. (15)");
EventUtils.sendKey("DOWN", gDebugger);
ok(gEditor.getCaretPosition().line == 12 &&
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct token. (16)");
EventUtils.sendKey("RETURN", gDebugger);
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't jump to the correct token. (17)");
EventUtils.sendKey("ENTER", gDebugger);
ok(gEditor.getCaretPosition().line == 2 &&
gEditor.getCaretPosition().col == 44 + token.length,
"The editor didn't jump to the correct token. (18)");
EventUtils.sendKey("UP", gDebugger);
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't jump to the correct token. (18.1)");
clear();
ok(gEditor.getCaretPosition().line == 19 &&
gEditor.getCaretPosition().col == 4 + token.length,
"The editor didn't remain at the correct token. (19)");
is(gSources.visibleItems.length, 1,
"Not all the scripts are shown after the search. (20)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice that matches are found.");
gEditor.setSelection(1, 5);
EventUtils.synthesizeKey("F", { accelKey:true });
is(gSearchBox.value, "#" + gEditor.getSelectedText(),
"The search field has the right initial value.");
closeDebuggerAndFinish();
}}, 0);
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchBox = null;
});

View File

@ -1,267 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests basic functionality of scripts filtering (file search).
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
firstSearch();
});
}
function firstSearch() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-01.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 4 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line. (1)");
is(gSources.visibleItems.length, 1,
"Not all the correct scripts are shown after the search. (1)");
secondSearch();
});
} else {
ok(false, "Get off my lawn.");
}
});
write(".*-01\.js:5");
}
function secondSearch() {
let token = "deb";
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
append("#" + token);
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct line. (2)");
is(gSources.visibleItems.length, 1,
"Not all the correct scripts are shown after the search. (2)");
waitForFirstScript();
});
} else {
ok(false, "Get off my lawn.");
}
});
gSources.selectedIndex = 1;
}
function waitForFirstScript() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-01.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
thirdSearch();
});
}
});
gSources.selectedIndex = 0;
}
function thirdSearch() {
let token = "deb";
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length,
"The editor didn't jump to the correct line. (3)");
is(gSources.visibleItems.length, 1,
"Not all the correct scripts are shown after the search. (3)");
fourthSearch(0, "ugger;", token);
});
} else {
ok(false, "Get off my lawn.");
}
});
write(".*-02\.js#" + token);
}
function fourthSearch(i, string, token) {
info("Searchbox value: " + gSearchBox.value);
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length + i,
"The editor didn't remain at the correct token. (4)");
if (string[i]) {
EventUtils.sendChar(string[i], gDebugger);
fourthSearch(i + 1, string, token);
return;
}
clear();
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length + i,
"The editor didn't remain at the correct token. (5)");
executeSoon(function() {
let noMatchingSources = gDebugger.L10N.getStr("noMatchingSourcesText");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the searchbox was emptied.");
is(gSources.selectedIndex, 1,
"The scripts container should have retained its selected index after the searchbox was emptied.");
write("BOGUS");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length + i,
"The editor didn't remain at the correct token. (6)");
is(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should display a notice that no scripts match the searched token.");
is(gSources.visibleItems.length, 0,
"No scripts should be displayed in the scripts container after a bogus search.");
is(gSources.selectedIndex, 1,
"The scripts container should retain its selected index after a bogus search.");
clear();
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length + i,
"The editor didn't remain at the correct token. (7)");
isnot(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should not display a notice after the searchbox was emptied.");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the searchbox was emptied.");
is(gSources.selectedIndex, 1,
"The scripts container should have retained its selected index after the searchbox was emptied of a bogus search.");
noMatchingSourcesSingleCharCheck(token, i);
});
}
function noMatchingSourcesSingleCharCheck(token, i) {
let noMatchingSources = gDebugger.L10N.getStr("noMatchingSourcesText");
write("x");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 8 + token.length + i,
"The editor didn't remain at the correct token. (8)");
is(gSources.widget.getAttribute("label"), noMatchingSources,
"The scripts container should display a notice after no matches are found.");
is(gSources.visibleItems.length, 0,
"No scripts should be shown after no matches are found.");
is(gSources.selectedIndex, 1,
"The scripts container should have retained its selected index after no matches are found.");
closeDebuggerAndFinish();
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchBox = null;
});

View File

@ -1,337 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests basic functionality of global search (lowercase + upper case, expected
* UI behavior, number of results found etc.)
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
firstSearch();
});
}
function firstSearch() {
is(gSearchView.widget._list.childNodes.length, 0,
"The global search pane shouldn't have any child nodes yet.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible yet.");
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 0,
"The editor shouldn't have jumped to a matching line yet.");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the global search.");
let scriptResults = gDebugger.document.querySelectorAll(".dbg-source-results");
is(scriptResults.length, 2,
"There should be matches found in two scripts.");
let item0 = gDebugger.SourceResults.getItemForElement(scriptResults[0]);
let item1 = gDebugger.SourceResults.getItemForElement(scriptResults[1]);
is(item0.instance.expanded, true,
"The first script results should automatically be expanded.")
is(item1.instance.expanded, false,
"The second script results should not be automatically expanded.")
let searchResult0 = scriptResults[0].querySelectorAll(".dbg-search-result");
let searchResult1 = scriptResults[1].querySelectorAll(".dbg-search-result");
is(searchResult0.length, 1,
"There should be one line result for the first url.");
is(searchResult1.length, 2,
"There should be two line results for the second url.");
let firstLine0 = searchResult0[0];
is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
"The first result for the first script doesn't have the correct line attached.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1,
"The first result for the first script doesn't have the correct number of nodes for a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 3,
"The first result for the first script doesn't have the correct number of strings in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
"The first result for the first script doesn't have the correct number of matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
"The first result for the first script doesn't have the correct match in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
"The first result for the first script doesn't have the correct number of non-matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ",
"The first result for the first script doesn't have the correct non-matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.",
"The first result for the first script doesn't have the correct non-matches in a line.");
let firstLine1 = searchResult1[0];
is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
"The first result for the second script doesn't have the correct line attached.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
"The first result for the second script doesn't have the correct number of nodes for a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3,
"The first result for the second script doesn't have the correct number of strings in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
"The first result for the second script doesn't have the correct number of matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
"The first result for the second script doesn't have the correct match in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
"The first result for the second script doesn't have the correct number of non-matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is ",
"The first result for the second script doesn't have the correct non-matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "dicated to the Public Domain.",
"The first result for the second script doesn't have the correct non-matches in a line.");
let secondLine1 = searchResult1[1];
is(secondLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "6",
"The second result for the second script doesn't have the correct line attached.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
"The second result for the second script doesn't have the correct number of nodes for a line.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents-string").length, 3,
"The second result for the second script doesn't have the correct number of strings in a line.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 1,
"The second result for the second script doesn't have the correct number of matches in a line.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "de",
"The second result for the second script doesn't have the correct match in a line.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 2,
"The second result for the second script doesn't have the correct number of non-matches in a line.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), ' eval("',
"The second result for the second script doesn't have the correct non-matches in a line.");
is(secondLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), 'bugger;");',
"The second result for the second script doesn't have the correct non-matches in a line.");
secondSearch();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!de");
});
}
function secondSearch() {
isnot(gSearchView.widget._list.childNodes.length, 0,
"The global search pane should have some child nodes from the previous search.");
is(gSearchView.widget._parent.hidden, false,
"The global search pane should be visible from the previous search.");
is(gSearchView._splitter.hidden, false,
"The global search pane splitter should be visible from the previous search.");
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 0,
"The editor shouldn't have jumped to a matching line yet.");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the global search.");
let scriptResults = gDebugger.document.querySelectorAll(".dbg-source-results");
is(scriptResults.length, 2,
"There should be matches found in two scripts.");
let item0 = gDebugger.SourceResults.getItemForElement(scriptResults[0]);
let item1 = gDebugger.SourceResults.getItemForElement(scriptResults[1]);
is(item0.instance.expanded, true,
"The first script results should automatically be expanded.")
is(item1.instance.expanded, false,
"The first script results should not be automatically expanded.")
let searchResult0 = scriptResults[0].querySelectorAll(".dbg-search-result");
let searchResult1 = scriptResults[1].querySelectorAll(".dbg-search-result");
is(searchResult0.length, 1,
"There should be one line result for the first url.");
is(searchResult1.length, 1,
"There should be one line result for the second url.");
let firstLine0 = searchResult0[0];
is(firstLine0.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
"The first result for the first script doesn't have the correct line attached.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents").length, 1,
"The first result for the first script doesn't have the correct number of nodes for a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string").length, 5,
"The first result for the first script doesn't have the correct number of strings in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2,
"The first result for the first script doesn't have the correct number of matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed",
"The first result for the first script doesn't have the correct matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed",
"The first result for the first script doesn't have the correct matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3,
"The first result for the first script doesn't have the correct number of non-matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d",
"The first result for the first script doesn't have the correct non-matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat",
"The first result for the first script doesn't have the correct non-matches in a line.");
is(firstLine0.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.",
"The first result for the first script doesn't have the correct non-matches in a line.");
let firstLine1 = searchResult1[0];
is(firstLine1.querySelector(".dbg-results-line-number").getAttribute("value"), "1",
"The first result for the second script doesn't have the correct line attached.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents").length, 1,
"The first result for the second script doesn't have the correct number of nodes for a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string").length, 5,
"The first result for the second script doesn't have the correct number of strings in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]").length, 2,
"The first result for the second script doesn't have the correct number of matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[0].getAttribute("value"), "ed",
"The first result for the second script doesn't have the correct matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=true]")[1].getAttribute("value"), "ed",
"The first result for the second script doesn't have the correct matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]").length, 3,
"The first result for the second script doesn't have the correct number of non-matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[0].getAttribute("value"), "/* Any copyright is d",
"The first result for the second script doesn't have the correct non-matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[1].getAttribute("value"), "icat",
"The first result for the second script doesn't have the correct non-matches in a line.");
is(firstLine1.querySelectorAll(".dbg-results-line-contents-string[match=false]")[2].getAttribute("value"), " to the Public Domain.",
"The first result for the second script doesn't have the correct non-matches in a line.");
testClearView();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
backspace(2);
append("ED");
});
}
function testClearView() {
gSearchView.clearView();
is(gSearchView.widget._list.childNodes.length, 0,
"The global search pane shouldn't have any child nodes after clearView().");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after clearView().");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after clearView().");
closeDebuggerAndFinish();
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function backspace(times) {
for (let i = 0; i < times; i++) {
EventUtils.sendKey("BACK_SPACE", gDebugger);
}
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -1,285 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results switch back and forth, and wrap around
* when switching between them.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
doSearch();
});
}
function doSearch() {
is(gSearchView.widget._list.childNodes.length, 0,
"The global search pane shouldn't have any child nodes yet.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible yet.");
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 0,
"The editor shouldn't have jumped to a matching line yet.");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the global search.");
isnot(gSearchView.widget._list.childNodes.length, 0,
"The global search pane should be visible now.");
isnot(gSearchView.widget._parent.hidden, true,
"The global search pane should be visible now.");
isnot(gSearchView._splitter.hidden, true,
"The global search pane splitter should be visible now.");
doFirstJump();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!eval");
});
}
function doFirstJump() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-01.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 4 &&
gEditor.getCaretPosition().col == 6,
"The editor didn't jump to the correct line. (1)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (1)");
doSecondJump();
});
} else {
ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
}
});
executeSoon(function() {
EventUtils.sendKey("DOWN", gDebugger);
});
}
function doSecondJump() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 6,
"The editor didn't jump to the correct line. (2)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (2)");
doWrapAroundJump();
});
} else {
ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
}
});
executeSoon(function() {
EventUtils.sendKey("RETURN", gDebugger);
});
}
function doWrapAroundJump() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-01.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 4 &&
gEditor.getCaretPosition().col == 6,
"The editor didn't jump to the correct line. (3)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (3)");
doBackwardsWrapAroundJump();
});
} else {
ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
}
});
executeSoon(function() {
EventUtils.sendKey("ENTER", gDebugger);
});
}
function doBackwardsWrapAroundJump() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 6,
"The editor didn't jump to the correct line. (4)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (4)");
testSearchTokenEmpty();
});
} else {
ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
}
});
executeSoon(function() {
EventUtils.sendKey("UP", gDebugger);
});
}
function testSearchTokenEmpty() {
gDebugger.addEventListener("Debugger:GlobalSearch:TokenEmpty", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 6,
"The editor didn't remain at the correct line. (5)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (5)");
is(gSearchView.widget._list.childNodes.length, 0,
"The global search pane shouldn't have any child nodes after clear().");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after clear().");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after clear().");
closeDebuggerAndFinish();
});
} else {
ok(false, "How did you get here? Go away!");
}
});
backspace(4);
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function backspace(times) {
for (let i = 0; i < times; i++) {
EventUtils.sendKey("BACK_SPACE", gDebugger);
}
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -1,162 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results are cleared on location changes, and
* the expected UI behaviors are triggered.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
requestLongerTimeout(3);
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
doSearch();
});
}
function doSearch() {
is(gSearchView.widget._list.childNodes.length, 0,
"The global search pane shouldn't have any child nodes yet.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible yet.");
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 0,
"The editor shouldn't have jumped to a matching line yet.");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the global search.");
isnot(gSearchView.widget._list.childNodes.length, 0,
"The global search pane should be visible now.");
isnot(gSearchView.widget._parent.hidden, true,
"The global search pane should be visible now.");
isnot(gSearchView._splitter.hidden, true,
"The global search pane splitter should be visible now.");
testLocationChange();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!eval");
});
}
function testLocationChange()
{
gDebugger.DebuggerController._target.once("navigate", function onTabNavigated(aEvent, aPacket) {
ok(true, "tabNavigated event was fired after location change.");
info("Still attached to the tab.");
executeSoon(function() {
is(gSearchView.widget._list.childNodes.length, 0,
"The global search pane shouldn't have any child nodes after a page navigation.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after a page navigation.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after a page navigation.");
closeDebuggerAndFinish();
});
});
gDebugger.DebuggerController.client.activeTab.navigateTo(TAB1_URL);
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -1,150 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results trigger MatchFound and NoMatchFound events
* properly, and triggers the expected UI behavior.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gDebugger.DebuggerController.activeThread.resume(function() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
doSearch();
});
}
function doSearch() {
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 0,
"The editor shouldn't have jumped to a matching line yet.");
is(gSources.visibleItems.length, 2,
"Not all the scripts are shown after the global search.");
testSearchMatchNotFound();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!eval");
});
}
function testSearchMatchNotFound() {
gDebugger.addEventListener("Debugger:GlobalSearch:MatchNotFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't remain at the correct line.");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search.");
closeDebuggerAndFinish();
});
} else {
ok(false, "How did you get here? Go away!");
}
});
append("/punch him/");
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -1,262 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results are expanded on scroll or click, and
* clicking matches makes the source editor shows the correct script and
* makes a selection based on the match.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
doSearch();
}
function doSearch() {
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
continueTest();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!a");
});
}
function continueTest() {
let scriptResults = gDebugger.document.querySelectorAll(".dbg-source-results");
is(scriptResults.length, 2,
"There should be matches found in two scripts.");
testScrollToExpand(scriptResults);
testExpandCollapse(scriptResults);
testAdditionalScrollToExpand(scriptResults);
testClickLineToJump(scriptResults, [testClickMatchToJump, closeDebuggerAndFinish]);
}
function testScrollToExpand(scriptResults) {
let item0 = gDebugger.SourceResults.getItemForElement(scriptResults[0]);
let item1 = gDebugger.SourceResults.getItemForElement(scriptResults[1]);
is(item0.instance.expanded, true,
"The first script results should automatically be expanded.");
is(item1.instance.expanded, false,
"The first script results should not be automatically expanded.");
gSearchView._forceExpandResults = true;
gSearchView._onScroll();
is(item0.instance.expanded, true,
"The first script results should be expanded after scrolling.");
is(item1.instance.expanded, true,
"The second script results should be expanded after scrolling.");
}
function testExpandCollapse(scriptResults) {
let item0 = gDebugger.SourceResults.getItemForElement(scriptResults[0]);
let item1 = gDebugger.SourceResults.getItemForElement(scriptResults[1]);
let firstHeader = scriptResults[0].querySelector(".dbg-results-header");
let secondHeader = scriptResults[1].querySelector(".dbg-results-header");
EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
is(item0.instance.expanded, false,
"The first script results should be collapsed on click.")
is(item1.instance.expanded, false,
"The second script results should be collapsed on click.")
EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
is(item0.instance.expanded, true,
"The first script results should be expanded on an additional click.");
is(item1.instance.expanded, true,
"The second script results should be expanded on an additional click.");
}
function testAdditionalScrollToExpand(scriptResults) {
let item0 = gDebugger.SourceResults.getItemForElement(scriptResults[0]);
let item1 = gDebugger.SourceResults.getItemForElement(scriptResults[1]);
let firstHeader = scriptResults[0].querySelector(".dbg-results-header");
let secondHeader = scriptResults[1].querySelector(".dbg-results-header");
EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
is(item0.instance.expanded, false,
"The first script results should be recollapsed on click.")
is(item1.instance.expanded, false,
"The second script results should be recollapsed on click.")
gSearchView._onScroll();
is(item0.instance.expanded, false,
"The first script results should not be automatically re-expanded on scroll after a user collapsed them.")
is(item1.instance.expanded, false,
"The second script results should not be automatically re-expanded on scroll after a user collapsed them.")
}
function testClickLineToJump(scriptResults, callbacks) {
let targetResults = scriptResults[0];
let firstHeader = targetResults.querySelector(".dbg-results-header");
let firstHeaderItem = gDebugger.SourceResults.getItemForElement(firstHeader);
firstHeaderItem.instance.expand()
is(firstHeaderItem.instance.expanded, true,
"The first script results should be expanded after direct function call.");
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-01.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 4,
"The editor didn't jump to the correct line. (1)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (1)");
callbacks[0](scriptResults, callbacks.slice(1));
});
} else {
ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
}
});
let firstLine = targetResults.querySelector(".dbg-results-line-contents");
EventUtils.sendMouseEvent({ type: "click" }, firstLine);
}
function testClickMatchToJump(scriptResults, callbacks) {
let targetResults = scriptResults[1];
let secondHeader = targetResults.querySelector(".dbg-results-header");
let secondHeaderItem = gDebugger.SourceResults.getItemForElement(secondHeader);
secondHeaderItem.instance.expand()
is(secondHeaderItem.instance.expanded, true,
"The second script results should be expanded after direct function call.");
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + aEvent.detail.url + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 5 &&
gEditor.getCaretPosition().col == 5,
"The editor didn't jump to the correct line. (1)");
is(gSources.visibleItems.length, 2,
"Not all the correct scripts are shown after the search. (1)");
callbacks[0]();
});
} else {
ok(false, "We jumped in a bowl of hot lava (aka WRONG MATCH). That was bad for us.");
}
});
let matches = targetResults.querySelectorAll(".dbg-results-line-contents-string[match=true]");
let lastMatch = matches[matches.length - 1];
EventUtils.sendMouseEvent({ type: "click" }, lastMatch);
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -1,208 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
/**
* Tests if the global search results are hidden when they're supposed to
* (after a focus lost, or when ESCAPE is pressed).
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchView = null;
var gSearchBox = null;
function test()
{
let scriptShown = false;
let framesAdded = false;
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.SourceResults.prototype.alwaysExpand = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
let url = aEvent.detail.url;
if (url.indexOf("-02.js") != -1) {
scriptShown = true;
gDebugger.removeEventListener(aEvent.type, _onEvent);
runTest();
}
});
gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
framesAdded = true;
runTest();
});
gDebuggee.firstCall();
});
function runTest()
{
if (scriptShown && framesAdded) {
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
}
}
}
function testScriptSearching() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
doSearch();
}
function doSearch() {
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
testFocusLost();
});
} else {
ok(false, "The current script shouldn't have changed after a global search.");
}
});
executeSoon(function() {
write("!a");
});
}
function testFocusLost()
{
is(gSearchView.widget._parent.hidden, false,
"The global search pane should be visible after a search.");
gDebugger.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
reshowSearch();
});
} else {
ok(false, "The current script shouldn't have changed after the global search stopped.");
}
});
executeSoon(function() {
gDebugger.DebuggerView.editor.focus();
});
}
function reshowSearch() {
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after the search was stopped.");
gDebugger.addEventListener("Debugger:GlobalSearch:MatchFound", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
testEscape();
});
} else {
ok(false, "The current script shouldn't have changed after a global re-search.");
}
});
executeSoon(function() {
sendEnter();
});
}
function testEscape()
{
is(gSearchView.widget._parent.hidden, false,
"The global search pane should be visible after a re-search.");
gDebugger.addEventListener("Debugger:GlobalSearch:ViewCleared", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("-02.js") != -1) {
executeSoon(function() {
finalCheck();
});
} else {
ok(false, "The current script shouldn't have changed after the global search escaped.");
}
});
executeSoon(function() {
sendEscape();
});
}
function finalCheck()
{
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after the search was escaped.");
closeDebuggerAndFinish();
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function sendEnter() {
gSearchBox.focus();
EventUtils.sendKey("ENTER", gDebugger);
}
function sendEscape() {
gSearchBox.focus();
EventUtils.sendKey("ESCAPE", gDebugger);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -1,693 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_update-editor-mode.html";
/**
* Tests basic functionality of scripts filtering (file search) helper UI.
*/
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gEditor = null;
var gSources = null;
var gSearchBox = null;
var gFilteredSources = null;
function test()
{
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
Services.tm.currentThread.dispatch({ run: testScriptSearching }, 0);
});
});
}
function testScriptSearching() {
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
gFilteredSources = gDebugger.DebuggerView.FilteredSources;
firstSearch();
}
function firstSearch() {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
for (let i = 0; i < gFilteredSources.itemCount; i++) {
is(gFilteredSources.labels[i],
gDebugger.SourceUtils.trimUrlLength(gSources.labels[i]),
"The filtered sources view should have the correct labels.");
is(gFilteredSources.values[i],
gDebugger.SourceUtils.trimUrlLength(gSources.values[i], 0, "start"),
"The filtered sources view should have the correct values.");
is(gFilteredSources.visibleItems[i].label,
gDebugger.SourceUtils.trimUrlLength(gSources.labels[i]),
"The filtered sources view should have the correct labels.");
is(gFilteredSources.visibleItems[i].value,
gDebugger.SourceUtils.trimUrlLength(gSources.values[i], 0, "start"),
"The filtered sources view should have the correct values.");
is(gFilteredSources.visibleItems[i].attachment.fullLabel, gSources.labels[i],
"The filtered sources view should have the correct labels.");
is(gFilteredSources.visibleItems[i].attachment.fullValue, gSources.values[i],
"The filtered sources view should have the correct values.");
}
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("update-editor-mode.html") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
secondSearch();
});
} else {
ok(false, "How did you get here?");
}
});
write(".");
}
function secondSearch() {
let sourceshown = false;
let popupshown = false;
let proceeded = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent1(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent1);
sourceshown = true;
executeSoon(proceed);
});
gDebugger.addEventListener("popupshown", function _onEvent2(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent2);
popupshown = true;
executeSoon(proceed);
});
function proceed() {
if (!sourceshown || !popupshown || proceeded) {
return;
}
proceeded = true;
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 1,
"The filtered sources view should have 1 items available.");
is(gFilteredSources.visibleItems.length, 1,
"The filtered sources view should have 1 items visible.");
for (let i = 0; i < gFilteredSources.itemCount; i++) {
is(gFilteredSources.labels[i],
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].label),
"The filtered sources view should have the correct labels.");
is(gFilteredSources.values[i],
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].value, 0, "start"),
"The filtered sources view should have the correct values.");
is(gFilteredSources.visibleItems[i].label,
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].label),
"The filtered sources view should have the correct labels.");
is(gFilteredSources.visibleItems[i].value,
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].value, 0, "start"),
"The filtered sources view should have the correct values.");
is(gFilteredSources.visibleItems[i].attachment.fullLabel, gSources.visibleItems[i].label,
"The filtered sources view should have the correct labels.");
is(gFilteredSources.visibleItems[i].attachment.fullValue, gSources.visibleItems[i].value,
"The filtered sources view should have the correct values.");
}
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("test-script-switching-01.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 1,
"Not all the correct scripts are shown after the search.");
thirdSearch();
});
} else {
ok(false, "How did you get here?");
}
}
write(".-0");
}
function thirdSearch() {
let sourceshown = false;
let popupshown = false;
let proceeded = false;
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent1(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent1);
sourceshown = true;
executeSoon(proceed);
});
gDebugger.addEventListener("popupshown", function _onEvent2(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent2);
popupshown = true;
executeSoon(proceed);
});
function proceed() {
if (!sourceshown || !popupshown || proceeded) {
return;
}
proceeded = true;
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
for (let i = 0; i < gFilteredSources.itemCount; i++) {
is(gFilteredSources.labels[i],
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].label),
"The filtered sources view should have the correct labels.");
is(gFilteredSources.values[i],
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].value, 0, "start"),
"The filtered sources view should have the correct values.");
is(gFilteredSources.visibleItems[i].label,
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].label),
"The filtered sources view should have the correct labels.");
is(gFilteredSources.visibleItems[i].value,
gDebugger.SourceUtils.trimUrlLength(gSources.visibleItems[i].value, 0, "start"),
"The filtered sources view should have the correct values.");
is(gFilteredSources.visibleItems[i].attachment.fullLabel, gSources.visibleItems[i].label,
"The filtered sources view should have the correct labels.");
is(gFilteredSources.visibleItems[i].attachment.fullValue, gSources.visibleItems[i].value,
"The filtered sources view should have the correct values.");
}
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("update-editor-mode.html") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
goDown();
});
} else {
ok(false, "How did you get here?");
}
}
write(".-");
}
function goDown() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("test-editor-mode") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
goDownAgain();
});
} else {
ok(false, "How did you get here?");
}
});
EventUtils.sendKey("DOWN", gDebugger);
}
function goDownAgain() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("test-script-switching-01.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
goDownAndWrap();
});
} else {
ok(false, "How did you get here?");
}
});
EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
}
function goDownAndWrap() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("update-editor-mode.html") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
goUpAndWrap();
});
} else {
ok(false, "How did you get here?");
}
});
EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
}
function goUpAndWrap() {
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("test-script-switching-01.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
clickAndSwitch();
});
} else {
ok(false, "How did you get here?");
}
});
EventUtils.sendKey("UP", gDebugger);
}
function clickAndSwitch() {
let sourceshown = false;
let popuphidden = false;
let popupshown = false;
let reopened = false;
let proceeded = false;
gDebugger.addEventListener("popuphidden", function _onEvent2(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent2);
info("Popup was hidden...");
popuphidden = true;
gDebugger.addEventListener("popupshown", function _onEvent3(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent3);
info("Popup was shown...");
popupshown = true;
proceed();
});
reopen();
});
function reopen() {
if (!sourceshown || !popuphidden || reopened) {
return;
}
info("Reopening popup...");
reopened = true;
append(".-");
}
function proceed() {
if (!sourceshown || !popuphidden || !popupshown || proceeded) {
return;
}
info("Proceeding with next test...");
proceeded = true;
executeSoon(clickAndSwitchAgain);
}
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("update-editor-mode.html") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
info("Source was shown and verified");
sourceshown = true;
reopen();
});
} else {
ok(false, "How did you get here?");
}
});
ok(gFilteredSources.widget._parent.querySelectorAll(".results-panel-item")[0]
.classList.contains("results-panel-item"),
"The first visible item target isn't the correct one.");
EventUtils.sendMouseEvent({ type: "click" },
gFilteredSources.widget._parent.querySelectorAll(".results-panel-item")[0],
gDebugger);
}
function clickAndSwitchAgain() {
let sourceshown = false;
let popuphidden = false;
let popupshown = false;
let reopened = false;
let proceeded = false;
gDebugger.addEventListener("popuphidden", function _onEvent2(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent2);
info("Popup was hidden...");
popuphidden = true;
gDebugger.addEventListener("popupshown", function _onEvent3(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent3);
info("Popup was shown...");
popupshown = true;
proceed();
});
reopen();
});
function reopen() {
if (!sourceshown || !popuphidden || reopened) {
return;
}
info("Reopening popup...");
reopened = true;
append(".-");
}
function proceed() {
if (!sourceshown || !popuphidden || !popupshown || proceeded) {
return;
}
info("Proceeding with next test...");
proceeded = true;
executeSoon(switchFocusWithEscape);
}
gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) {
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
is(gFilteredSources.itemCount, 3,
"The filtered sources view should have 3 items available.");
is(gFilteredSources.visibleItems.length, 3,
"The filtered sources view should have 3 items visible.");
is(gFilteredSources.selectedValue,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedValue, 0, "start"),
"The correct item should be selected in the filtered sources view");
is(gFilteredSources.selectedLabel,
gDebugger.SourceUtils.trimUrlLength(gSources.selectedLabel),
"The correct item should be selected in the filtered sources view");
let url = gSources.selectedValue;
if (url.indexOf("test-script-switching-01.js") != -1) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
info("Source was shown and verified");
sourceshown = true;
reopen();
});
} else {
ok(false, "How did you get here?");
}
});
ok(gFilteredSources.widget._parent.querySelectorAll(".results-panel-item")[2]
.classList.contains("results-panel-item"),
"The first visible item target isn't the correct one.");
EventUtils.sendMouseEvent({ type: "click" },
gFilteredSources.widget._parent.querySelectorAll(".results-panel-item")[2],
gDebugger);
}
function switchFocusWithEscape() {
gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("update-editor-mode.html") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
focusAgainAfterEscape();
});
} else {
ok(false, "How did you get here?");
}
});
EventUtils.sendKey("ESCAPE", gDebugger);
}
function focusAgainAfterEscape() {
gDebugger.addEventListener("popupshown", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("test-script-switching-01.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 1,
"Not all the correct scripts are shown after the search.");
switchFocusWithReturn();
});
} else {
ok(false, "How did you get here?");
}
});
append("0");
}
function switchFocusWithReturn() {
gDebugger.addEventListener("popuphidden", function _onEvent(aEvent) {
gDebugger.removeEventListener(aEvent.type, _onEvent);
info("Current script url:\n" + gSources.selectedValue + "\n");
info("Debugger editor text:\n" + gEditor.getText() + "\n");
let url = gSources.selectedValue;
if (url.indexOf("test-script-switching-01.js") != -1) {
executeSoon(function() {
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
ok(gEditor.getCaretPosition().line == 0 &&
gEditor.getCaretPosition().col == 0,
"The editor didn't jump to the correct line.");
is(gSources.visibleItems.length, 3,
"Not all the correct scripts are shown after the search.");
closeDebuggerAndFinish();
});
} else {
ok(false, "How did you get here?");
}
});
EventUtils.sendKey("RETURN", gDebugger);
}
function clear() {
gSearchBox.focus();
gSearchBox.value = "";
}
function write(text) {
clear();
append(text);
}
function append(text) {
gSearchBox.focus();
for (let i = 0; i < text.length; i++) {
EventUtils.sendChar(text[i], gDebugger);
}
info("Editor caret position: " + gEditor.getCaretPosition().toSource() + "\n");
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchBox = null;
gFilteredSources = null;
});

View File

@ -1,57 +0,0 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
var gPane = null;
var gTab = null;
var gDebuggee = null;
var gDebugger = null;
var gSearchBox = null;
var gSearchBoxPanel = null;
function test()
{
debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
gTab = aTab;
gDebuggee = aDebuggee;
gPane = aPane;
gDebugger = gPane.panelWin;
runTest();
});
}
function runTest() {
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
gSearchBoxPanel = gDebugger.DebuggerView.Filtering._searchboxHelpPanel;
focusSearchbox();
}
function focusSearchbox() {
is(gSearchBoxPanel.state, "closed",
"The search box panel shouldn't be visible yet.");
gSearchBoxPanel.addEventListener("popupshown", function _onEvent(aEvent) {
gSearchBoxPanel.removeEventListener(aEvent.type, _onEvent);
is(gSearchBoxPanel.state, "open",
"The search box panel should be visible after searching started.");
closeDebuggerAndFinish();
});
EventUtils.sendMouseEvent({ type: "click" }, gSearchBox);
}
registerCleanupFunction(function() {
removeTab(gTab);
gPane = null;
gTab = null;
gDebuggee = null;
gDebugger = null;
gSearchBox = null;
gSearchBoxPanel = null;
});

View File

@ -0,0 +1,300 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests basic search functionality (find token and jump to line).
*/
const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gFiltering, gSearchBox;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gFiltering = gDebugger.DebuggerView.Filtering;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceShown(gPanel, ".html").then(performTest);
});
}
function performTest() {
setText(gSearchBox, ":12");
is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 12),
"The editor didn't jump to the correct line.");
EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 13),
"The editor didn't jump to the correct line after Meta+G.");
EventUtils.synthesizeKey("n", { ctrlKey: true }, gDebugger);
is(gFiltering.searchData.toSource(), '[":", ["", 14]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14),
"The editor didn't jump to the correct line after Ctrl+N.");
EventUtils.synthesizeKey("G", { metaKey: true, shiftKey: true }, gDebugger);
is(gFiltering.searchData.toSource(), '[":", ["", 13]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 13),
"The editor didn't jump to the correct line after Meta+Shift+G.");
EventUtils.synthesizeKey("p", { ctrlKey: true }, gDebugger);
is(gFiltering.searchData.toSource(), '[":", ["", 12]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 12),
"The editor didn't jump to the correct line after Ctrl+P.");
for (let i = 0; i < 100; i++) {
EventUtils.sendKey("DOWN", gDebugger);
}
is(gFiltering.searchData.toSource(), '[":", ["", 36]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 36),
"The editor didn't jump to the correct line after multiple DOWN keys.");
for (let i = 0; i < 100; i++) {
EventUtils.sendKey("UP", gDebugger);
}
is(gFiltering.searchData.toSource(), '[":", ["", 1]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 1),
"The editor didn't jump to the correct line after multiple UP keys.");
let token = "debugger";
setText(gSearchBox, "#" + token);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor didn't jump to the correct token (1).");
EventUtils.sendKey("DOWN", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length),
"The editor didn't jump to the correct token (2).");
EventUtils.sendKey("DOWN", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 18, 15 + token.length),
"The editor didn't jump to the correct token (3).");
EventUtils.sendKey("RETURN", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 26, 11 + token.length),
"The editor didn't jump to the correct token (4).");
EventUtils.sendKey("ENTER", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor didn't jump to the correct token (5).");
EventUtils.sendKey("UP", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 26, 11 + token.length),
"The editor didn't jump to the correct token (6).");
setText(gSearchBox, ":bogus#" + token + ";");
is(gFiltering.searchData.toSource(), '["#", [":bogus", "debugger;"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (7).");
setText(gSearchBox, ":13#" + token + ";");
is(gFiltering.searchData.toSource(), '["#", [":13", "debugger;"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (8).");
setText(gSearchBox, ":#" + token + ";");
is(gFiltering.searchData.toSource(), '["#", [":", "debugger;"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (9).");
setText(gSearchBox, "::#" + token + ";");
is(gFiltering.searchData.toSource(), '["#", ["::", "debugger;"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (10).");
setText(gSearchBox, ":::#" + token + ";");
is(gFiltering.searchData.toSource(), '["#", [":::", "debugger;"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (11).");
setText(gSearchBox, "#" + token + ";" + ":bogus");
is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:bogus"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (12).");
setText(gSearchBox, "#" + token + ";" + ":13");
is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:13"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (13).");
setText(gSearchBox, "#" + token + ";" + ":");
is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (14).");
setText(gSearchBox, "#" + token + ";" + "::");
is(gFiltering.searchData.toSource(), '["#", ["", "debugger;::"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (15).");
setText(gSearchBox, "#" + token + ";" + ":::");
is(gFiltering.searchData.toSource(), '["#", ["", "debugger;:::"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't jump to the correct token (16).");
setText(gSearchBox, ":i am not a number");
is(gFiltering.searchData.toSource(), '[":", ["", 0]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't remain at the correct token (17).");
setText(gSearchBox, "#__i do not exist__");
is(gFiltering.searchData.toSource(), '["#", ["", "__i do not exist__"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length + 1),
"The editor didn't remain at the correct token (18).");
setText(gSearchBox, "#" + token);
is(gFiltering.searchData.toSource(), '["#", ["", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor didn't jump to the correct token (19).");
clearText(gSearchBox);
is(gFiltering.searchData.toSource(), '["", [""]]',
"The searchbox data wasn't parsed correctly.");
EventUtils.sendKey("RETURN", gDebugger);
is(gFiltering.searchData.toSource(), '["", [""]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor shouldn't jump to another token (20).");
EventUtils.sendKey("ENTER", gDebugger);
is(gFiltering.searchData.toSource(), '["", [""]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor shouldn't jump to another token (21).");
setText(gSearchBox, ":1:2:3:a:b:c:::12");
is(gFiltering.searchData.toSource(), '[":", [":1:2:3:a:b:c::", 12]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 12),
"The editor didn't jump to the correct line (22).");
setText(gSearchBox, "#don't#find#me#instead#find#" + token);
is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor didn't jump to the correct token (23).");
EventUtils.sendKey("DOWN", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 14, 9 + token.length),
"The editor didn't jump to the correct token (24).");
EventUtils.sendKey("DOWN", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 18, 15 + token.length),
"The editor didn't jump to the correct token (25).");
EventUtils.sendKey("RETURN", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 26, 11 + token.length),
"The editor didn't jump to the correct token (26).");
EventUtils.sendKey("ENTER", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 8, 12 + token.length),
"The editor didn't jump to the correct token (27).");
EventUtils.sendKey("UP", gDebugger);
is(gFiltering.searchData.toSource(), '["#", ["#don\'t#find#me#instead#find", "debugger"]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 26, 11 + token.length),
"The editor didn't jump to the correct token (28).");
clearText(gSearchBox);
is(gFiltering.searchData.toSource(), '["", [""]]',
"The searchbox data wasn't parsed correctly.");
ok(isCaretPos(gPanel, 26, 11 + token.length),
"The editor didn't remain at the correct token (29).");
is(gSources.visibleItems.length, 1,
"Not all the sources are shown after the search (30).");
gEditor.focus();
gEditor.setSelection(1, 5);
ok(isCaretPos(gPanel, 1, 6),
"The editor caret position didn't update after selecting some text.");
EventUtils.synthesizeKey("F", { accelKey: true });
is(gFiltering.searchData.toSource(), '["#", ["", "!-- "]]',
"The searchbox data wasn't parsed correctly.");
is(gSearchBox.value, "#!-- ",
"The search field has the right initial value (1).");
gEditor.focus();
gEditor.setSelection(415, 418);
ok(isCaretPos(gPanel, 21, 30),
"The editor caret position didn't update after selecting some number.");
EventUtils.synthesizeKey("L", { accelKey: true });
is(gFiltering.searchData.toSource(), '[":", ["", 100]]',
"The searchbox data wasn't parsed correctly.");
is(gSearchBox.value, ":100",
"The search field has the right initial value (2).");
closeDebuggerAndFinish(gPanel);
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gFiltering = null;
gSearchBox = null;
});

View File

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

View File

@ -0,0 +1,218 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the global search results switch back and forth, and wrap around
* when switching between them.
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchView, gSearchBox;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(firstSearch)
.then(doFirstJump)
.then(doSecondJump)
.then(doWrapAroundJump)
.then(doBackwardsWrapAroundJump)
.then(testSearchTokenEmpty)
.then(() => resumeDebuggerThenCloseAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
gDebuggee.firstCall();
});
}
function firstSearch() {
let deferred = promise.defer();
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any entries yet.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible yet.");
gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
// Some operations are synchronously dispatched on the main thread,
// to avoid blocking UI, thus giving the impression of faster searching.
executeSoon(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6),
"The editor shouldn't have jumped to a matching line yet.");
ok(gSources.selectedValue.contains("-02.js"),
"The current source shouldn't have changed after a global search.");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search.");
deferred.resolve();
});
});
setText(gSearchBox, "!eval");
return deferred.promise;
}
function doFirstJump() {
let deferred = promise.defer();
waitForSourceAndCaret(gPanel, "-01.js", 5).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(gSources.selectedValue.contains("-01.js"),
"The currently shown source is incorrect (1).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (1).");
// The editor's selected text takes a tick to update.
executeSoon(() => {
ok(isCaretPos(gPanel, 5, 7),
"The editor didn't jump to the correct line (1).");
is(gEditor.getSelectedText(), "eval",
"The editor didn't select the correct text (1).");
deferred.resolve();
});
});
EventUtils.sendKey("DOWN", gDebugger);
return deferred.promise;
}
function doSecondJump() {
let deferred = promise.defer();
waitForSourceAndCaret(gPanel, "-02.js", 6).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(gSources.selectedValue.contains("-02.js"),
"The currently shown source is incorrect (2).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (2).");
// The editor's selected text takes a tick to update.
executeSoon(() => {
ok(isCaretPos(gPanel, 6, 7),
"The editor didn't jump to the correct line (2).");
is(gEditor.getSelectedText(), "eval",
"The editor didn't select the correct text (2).");
deferred.resolve();
});
});
EventUtils.sendKey("DOWN", gDebugger);
return deferred.promise;
}
function doWrapAroundJump() {
let deferred = promise.defer();
waitForSourceAndCaret(gPanel, "-01.js", 5).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(gSources.selectedValue.contains("-01.js"),
"The currently shown source is incorrect (3).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (3).");
// The editor's selected text takes a tick to update.
executeSoon(() => {
ok(isCaretPos(gPanel, 5, 7),
"The editor didn't jump to the correct line (3).");
is(gEditor.getSelectedText(), "eval",
"The editor didn't select the correct text (3).");
deferred.resolve();
});
});
EventUtils.sendKey("DOWN", gDebugger);
return deferred.promise;
}
function doBackwardsWrapAroundJump() {
let deferred = promise.defer();
waitForSourceAndCaret(gPanel, "-02.js", 6).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(gSources.selectedValue.contains("-02.js"),
"The currently shown source is incorrect (4).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (4).");
// The editor's selected text takes a tick to update.
executeSoon(() => {
ok(isCaretPos(gPanel, 6, 7),
"The editor didn't jump to the correct line (4).");
is(gEditor.getSelectedText(), "eval",
"The editor didn't select the correct text (4).");
deferred.resolve();
});
});
EventUtils.sendKey("UP", gDebugger);
return deferred.promise;
}
function testSearchTokenEmpty() {
backspaceText(gSearchBox, 4);
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(gSources.selectedValue.contains("-02.js"),
"The currently shown source is incorrect (4).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (4).");
ok(isCaretPos(gPanel, 6, 7),
"The editor didn't remain at the correct line (4).");
is(gEditor.getSelectedText(), "",
"The editor shouldn't keep the previous text selected (4).");
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any child nodes after clearing.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after clearing.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after clearing.");
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,106 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the global search results are cleared on location changes, and
* the expected UI behaviors are triggered.
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchView, gSearchBox;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(firstSearch)
.then(performTest)
.then(() => closeDebuggerAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
gDebuggee.firstCall();
});
}
function firstSearch() {
let deferred = promise.defer();
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any entries yet.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible yet.");
gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
// Some operations are synchronously dispatched on the main thread,
// to avoid blocking UI, thus giving the impression of faster searching.
executeSoon(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6),
"The editor shouldn't have jumped to a matching line yet.");
ok(gSources.selectedValue.contains("-02.js"),
"The current source shouldn't have changed after a global search.");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search.");
deferred.resolve();
});
});
setText(gSearchBox, "!eval");
return deferred.promise;
}
function performTest() {
let deferred = promise.defer();
is(gSearchView.itemCount, 2,
"The global search pane should have some entries from the previous search.");
is(gSearchView.widget._parent.hidden, false,
"The global search pane should be visible from the previous search.");
is(gSearchView._splitter.hidden, false,
"The global search pane splitter should be visible from the previous search.");
reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any entries after a page navigation.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after a page navigation.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after a page navigation.");
deferred.resolve();
});
return deferred.promise;
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,94 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the global search results trigger MatchFound and NoMatchFound events
* properly, and triggers the expected UI behavior.
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchView, gSearchBox;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(firstSearch)
.then(secondSearch)
.then(() => resumeDebuggerThenCloseAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
gDebuggee.firstCall();
});
}
function firstSearch() {
let deferred = promise.defer();
gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
// Some operations are synchronously dispatched on the main thread,
// to avoid blocking UI, thus giving the impression of faster searching.
executeSoon(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6),
"The editor shouldn't have jumped to a matching line yet.");
ok(gSources.selectedValue.contains("-02.js"),
"The current source shouldn't have changed after a global search.");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search.");
deferred.resolve();
});
});
setText(gSearchBox, "!eval");
return deferred.promise;
}
function secondSearch() {
let deferred = promise.defer();
gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_NOT_FOUND, () => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6),
"The editor shouldn't have jumped to a matching line yet.");
ok(gSources.selectedValue.contains("-02.js"),
"The current source shouldn't have changed after a global search.");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search.");
deferred.resolve();
});
typeText(gSearchBox, "/");
return deferred.promise;
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,156 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the global search results are expanded/collapsed on click, and
* clicking matches makes the source editor shows the correct source and
* makes a selection based on the match.
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchView, gSearchBox;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(doSearch)
.then(testExpandCollapse)
.then(testClickLineToJump)
.then(testClickMatchToJump)
.then(() => resumeDebuggerThenCloseAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
gDebuggee.firstCall();
});
}
function doSearch() {
let deferred = promise.defer();
gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
// Some operations are synchronously dispatched on the main thread,
// to avoid blocking UI, thus giving the impression of faster searching.
executeSoon(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6),
"The editor shouldn't have jumped to a matching line yet.");
ok(gSources.selectedValue.contains("-02.js"),
"The current source shouldn't have changed after a global search.");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search.");
deferred.resolve();
});
});
setText(gSearchBox, "!a");
return deferred.promise;
}
function testExpandCollapse() {
let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
let item0 = gDebugger.SourceResults.getItemForElement(sourceResults[0]);
let item1 = gDebugger.SourceResults.getItemForElement(sourceResults[1]);
let firstHeader = sourceResults[0].querySelector(".dbg-results-header");
let secondHeader = sourceResults[1].querySelector(".dbg-results-header");
EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
is(item0.instance.expanded, false,
"The first source results should be collapsed on click.")
is(item1.instance.expanded, false,
"The second source results should be collapsed on click.")
EventUtils.sendMouseEvent({ type: "click" }, firstHeader);
EventUtils.sendMouseEvent({ type: "click" }, secondHeader);
is(item0.instance.expanded, true,
"The first source results should be expanded on an additional click.");
is(item1.instance.expanded, true,
"The second source results should be expanded on an additional click.");
}
function testClickLineToJump() {
let deferred = promise.defer();
let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
let firstHeader = sourceResults[0].querySelector(".dbg-results-header");
let firstLine = sourceResults[0].querySelector(".dbg-results-line-contents");
waitForSourceAndCaret(gPanel, "-01.js", 1, 5).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 1, 5),
"The editor didn't jump to the correct line (1).");
is(gEditor.getSelectedText(), "A",
"The editor didn't select the correct text (1).");
ok(gSources.selectedValue.contains("-01.js"),
"The currently shown source is incorrect (1).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (1).");
deferred.resolve();
});
EventUtils.sendMouseEvent({ type: "click" }, firstLine);
return deferred.promise;
}
function testClickMatchToJump() {
let deferred = promise.defer();
let sourceResults = gDebugger.document.querySelectorAll(".dbg-source-results");
let secondHeader = sourceResults[1].querySelector(".dbg-results-header");
let secondMatches = sourceResults[1].querySelectorAll(".dbg-results-line-contents-string[match=true]");
let lastMatch = Array.slice(secondMatches).pop();
waitForSourceAndCaret(gPanel, "-02.js", 6, 6).then(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6, 6),
"The editor didn't jump to the correct line (2).");
is(gEditor.getSelectedText(), "a",
"The editor didn't select the correct text (2).");
ok(gSources.selectedValue.contains("-02.js"),
"The currently shown source is incorrect (2).");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search (2).");
deferred.resolve();
});
EventUtils.sendMouseEvent({ type: "click" }, lastMatch);
return deferred.promise;
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,121 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if the global search results are hidden when they're supposed to
* (after a focus lost, or when ESCAPE is pressed).
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchView, gSearchBox;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.GlobalSearch;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(doSearch)
.then(testFocusLost)
.then(doSearch)
.then(testEscape)
.then(() => resumeDebuggerThenCloseAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
gDebuggee.firstCall();
});
}
function doSearch() {
let deferred = promise.defer();
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any entries yet.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible yet.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible yet.");
gDebugger.once(gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND, () => {
// Some operations are synchronously dispatched on the main thread,
// to avoid blocking UI, thus giving the impression of faster searching.
executeSoon(() => {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
ok(isCaretPos(gPanel, 6),
"The editor shouldn't have jumped to a matching line yet.");
ok(gSources.selectedValue.contains("-02.js"),
"The current source shouldn't have changed after a global search.");
is(gSources.visibleItems.length, 2,
"Not all the sources are shown after the global search.");
deferred.resolve();
});
});
setText(gSearchBox, "!a");
return deferred.promise;
}
function testFocusLost() {
is(gSearchView.itemCount, 2,
"The global search pane should have some entries from the previous search.");
is(gSearchView.widget._parent.hidden, false,
"The global search pane should be visible from the previous search.");
is(gSearchView._splitter.hidden, false,
"The global search pane splitter should be visible from the previous search.");
gDebugger.DebuggerView.editor.focus();
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any child nodes after clearing.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after clearing.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after clearing.");
}
function testEscape() {
is(gSearchView.itemCount, 2,
"The global search pane should have some entries from the previous search.");
is(gSearchView.widget._parent.hidden, false,
"The global search pane should be visible from the previous search.");
is(gSearchView._splitter.hidden, false,
"The global search pane splitter should be visible from the previous search.");
gSearchBox.focus();
EventUtils.sendKey("ESCAPE", gDebugger);
is(gSearchView.itemCount, 0,
"The global search pane shouldn't have any child nodes after clearing.");
is(gSearchView.widget._parent.hidden, true,
"The global search pane shouldn't be visible after clearing.");
is(gSearchView._splitter.hidden, true,
"The global search pane splitter shouldn't be visible after clearing.");
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,237 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests basic functionality of sources filtering (file search).
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchView, gSearchBox;
function test() {
// Debug test slaves are a bit slow at this test.
requestLongerTimeout(3);
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchView = gDebugger.DebuggerView.FilteredSources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceShown(gPanel, "-01.js")
.then(bogusSearch)
.then(firstSearch)
.then(secondSearch)
.then(thirdSearch)
.then(fourthSearch)
.then(fifthSearch)
.then(sixthSearch)
.then(seventhSearch)
.then(() => closeDebuggerAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
});
}
function bogusSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND)
]);
setText(gSearchBox, "BOGUS");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 0, hidden: true })
]));
}
function firstSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
]);
setText(gSearchBox, "-02.js");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 1, hidden: false })
]));
}
function secondSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 5)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 5),
verifyContents({ itemCount: 1, hidden: false })
]));
typeText(gSearchBox, ":5");
return finished;
});
setText(gSearchBox, ".*-01\.js");
return finished;
}
function thirdSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 6, 12)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 6, 12),
verifyContents({ itemCount: 1, hidden: false })
]));
typeText(gSearchBox, "#deb");
return finished;
});
setText(gSearchBox, ".*-02\.js");
return finished;
}
function fourthSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 2, 9),
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 2, 9),
verifyContents({ itemCount: 1, hidden: false })
// ...because we simply searched for ":" in the current file.
]));
typeText(gSearchBox, "#:"); // # has precedence.
return finished;
});
setText(gSearchBox, ".*-01\.js");
return finished;
}
function fifthSearch() {
let finished = promise.all([
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-02.js")
])
.then(() => {
let finished = promise.all([
once(gDebugger, "popuphidden"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_NOT_FOUND),
waitForCaretUpdated(gPanel, 1, 3)
])
.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1, 3),
verifyContents({ itemCount: 0, hidden: true })
// ...because the searched label includes ":5", so nothing is found.
]));
typeText(gSearchBox, ":5#*"); // # has precedence.
return finished;
});
setText(gSearchBox, ".*-02\.js");
return finished;
}
function sixthSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 1, 3),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForCaretUpdated(gPanel, 5)
]);
backspaceText(gSearchBox, 2);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 5),
verifyContents({ itemCount: 1, hidden: false })
]));
}
function seventhSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-02.js"),
ensureCaretAt(gPanel, 5),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js"),
]);
backspaceText(gSearchBox, 6);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents({ itemCount: 2, hidden: false })
]));
}
function verifyContents(aArgs) {
is(gSources.visibleItems.length, 2,
"The unmatched sources in the widget should not be hidden.");
is(gSearchView.itemCount, aArgs.itemCount,
"No sources should be displayed in the sources container after a bogus search.");
is(gSearchView.hidden, aArgs.hidden,
"No sources should be displayed in the sources container after a bogus search.");
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,280 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests more complex functionality of sources filtering (file search).
*/
const TAB_URL = EXAMPLE_URL + "doc_editor-mode.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSourceUtils, gSearchView, gSearchBox;
function test() {
// Debug test slaves are a bit slow at this test.
requestLongerTimeout(3);
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSourceUtils = gDebugger.SourceUtils;
gSearchView = gDebugger.DebuggerView.FilteredSources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
waitForSourceShown(gPanel, "-01.js")
.then(firstSearch)
.then(secondSearch)
.then(thirdSearch)
.then(fourthSearch)
.then(fifthSearch)
.then(goDown)
.then(goDownAndWrap)
.then(goUpAndWrap)
.then(goUp)
.then(returnAndSwitch)
.then(firstSearch)
.then(clickAndSwitch)
.then(() => closeDebuggerAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
});
}
function firstSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)
]);
setText(gSearchBox, ".");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d",
"doc_editor-mode.html"
])
]));
}
function secondSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)
]);
typeText(gSearchBox, "-0");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents(["code_script-switching-01.js?a=b"])
]));
}
function thirdSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND)
]);
backspaceText(gSearchBox, 1);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d",
"doc_editor-mode.html"
])
]));
}
function fourthSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "test-editor-mode")
]);
setText(gSearchBox, "code_test");
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "test-editor-mode"),
ensureCaretAt(gPanel, 1),
verifyContents(["code_test-editor-mode?c=d"])
]));
}
function fifthSearch() {
let finished = promise.all([
ensureSourceIs(gPanel, "test-editor-mode"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popupshown"),
waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
waitForSourceShown(gPanel, "-01.js")
]);
backspaceText(gSearchBox, 4);
return finished.then(() => promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d"
])
]));
}
function goDown() {
let finished = promise.all([
ensureSourceIs(gPanel, "-01.js"),
ensureCaretAt(gPanel, 1),
waitForSourceShown(gPanel, "test-editor-mode"),
]);
EventUtils.sendKey("DOWN", gDebugger);
return finished.then(() => promise.all([
ensureSourceIs(gPanel,"test-editor-mode"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d"
])
]));
}
function goDownAndWrap() {
let finished = promise.all([
ensureSourceIs(gPanel, "test-editor-mode"),
ensureCaretAt(gPanel, 1),
waitForSourceShown(gPanel, "-01.js")
]);
EventUtils.synthesizeKey("g", { metaKey: true }, gDebugger);
return finished.then(() => promise.all([
ensureSourceIs(gPanel,"-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d"
])
]));
}
function goUpAndWrap() {
let finished = promise.all([
ensureSourceIs(gPanel,"-01.js"),
ensureCaretAt(gPanel, 1),
waitForSourceShown(gPanel, "test-editor-mode")
]);
EventUtils.synthesizeKey("G", { metaKey: true }, gDebugger);
return finished.then(() => promise.all([
ensureSourceIs(gPanel,"test-editor-mode"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d"
])
]));
}
function goUp() {
let finished = promise.all([
ensureSourceIs(gPanel,"test-editor-mode"),
ensureCaretAt(gPanel, 1),
waitForSourceShown(gPanel, "-01.js"),
]);
EventUtils.sendKey("UP", gDebugger);
return finished.then(() => promise.all([
ensureSourceIs(gPanel,"-01.js"),
ensureCaretAt(gPanel, 1),
verifyContents([
"code_script-switching-01.js?a=b",
"code_test-editor-mode?c=d"
])
]));
}
function returnAndSwitch() {
let finished = promise.all([
ensureSourceIs(gPanel,"-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popuphidden")
]);
EventUtils.sendKey("RETURN", gDebugger);
return finished.then(() => promise.all([
ensureSourceIs(gPanel,"-01.js"),
ensureCaretAt(gPanel, 1)
]));
}
function clickAndSwitch() {
let finished = promise.all([
ensureSourceIs(gPanel,"-01.js"),
ensureCaretAt(gPanel, 1),
once(gDebugger, "popuphidden"),
waitForSourceShown(gPanel, "test-editor-mode")
]);
EventUtils.sendMouseEvent({ type: "click" }, gSearchView.items[1].target, gDebugger);
return finished.then(() => promise.all([
ensureSourceIs(gPanel,"test-editor-mode"),
ensureCaretAt(gPanel, 1)
]));
}
function verifyContents(aMatches) {
is(gSources.visibleItems.length, 3,
"The unmatched sources in the widget should not be hidden.");
is(gSearchView.itemCount, aMatches.length,
"The filtered sources view should have the right items available.");
for (let i = 0; i < gSearchView.itemCount; i++) {
let trimmedLabel = gSourceUtils.trimUrlLength(gSourceUtils.trimUrlQuery(aMatches[i]));
let trimmedValue = gSourceUtils.trimUrlLength(EXAMPLE_URL + aMatches[i], 0, "start");
isnot(gSearchView.labels.indexOf(trimmedLabel), -1,
"The filtered sources view should have the correct labels.");
isnot(gSearchView.values.indexOf(trimmedValue), -1,
"The filtered sources view should have the correct values.");
}
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSourceUtils = null;
gSearchView = null;
gSearchBox = null;
});

View File

@ -0,0 +1,409 @@
/* 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";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSources, gSearchBox, gFilteredFunctions;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSources = gDebugger.DebuggerView.Sources;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
gFilteredFunctions = gDebugger.DebuggerView.FilteredFunctions;
waitForSourceShown(gPanel, "-01.js")
.then(() => 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();
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view.");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view.");
if (gSources.selectedValue.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) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
ok(isCaretPos(gPanel, line, column),
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel.contains(value),
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue.contains(value),
"The current source isn't the correct one, according to the value.");
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();
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view.");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view.");
if (gSources.selectedValue.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) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
ok(isCaretPos(gPanel, line, column),
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel.contains(value),
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue.contains(value),
"The current source isn't the correct one, according to the value.");
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();
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view.");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view.");
if (gSources.selectedValue.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", "", 20, 32],
["y", "-02.js", "", 20, 41],
["z", "-02.js", "", 20, 50]
];
for (let [label, value, description, line, column] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
ok(isCaretPos(gPanel, line, column),
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel.contains(value),
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue.contains(value),
"The current source isn't the correct one, according to the value.");
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();
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view.");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view.");
if (gSources.selectedValue.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", "theta", 25, 5],
["fun", "-03.js", "", 29, 7],
["foo", "-03.js", "", 29, 13],
["bar", "-03.js", "", 29, 19],
["t_foo", "-03.js", "", 29, 25],
["w_bar" + s + "baz", "-03.js", "window", 29, 38]
];
for (let [label, value, description, line, column] of expectedResults) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
ok(isCaretPos(gPanel, line, column),
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel.contains(value),
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue.contains(value),
"The current source isn't the correct one, according to the value.");
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();
ok(gFilteredFunctions.selectedValue,
"An item should be selected in the filtered functions view.");
ok(gFilteredFunctions.selectedLabel,
"An item should be selected in the filtered functions view.");
if (gSources.selectedValue.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) {
is(gFilteredFunctions.selectedItem.label,
gDebugger.SourceUtils.trimUrlLength(label + "()"),
"The corect label (" + label + ") is currently selected.");
ok(gFilteredFunctions.selectedItem.value.contains(value),
"The corect value (" + value + ") is attached.");
is(gFilteredFunctions.selectedItem.description, description,
"The corect description (" + description + ") is currently shown.");
ok(isCaretPos(gPanel, line, column),
"The editor didn't jump to the correct line.");
ok(gSources.selectedLabel.contains(value),
"The current source isn't the correct one, according to the label.");
ok(gSources.selectedValue.contains(value),
"The current source isn't the correct one, according to the value.");
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.selectedLabel = aLabel;
return deferred.promise;
}
function saveSearch() {
let finished = once(gDebugger, "popuphidden");
// Either by pressing RETURN, ENTER, 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("ENTER", gDebugger);
} else {
EventUtils.sendMouseEvent({ type: "click" },
gFilteredFunctions.selectedItem.target,
gDebugger);
}
return finished;
}
function writeInfo() {
info("Current source url:\n" + gSources.selectedValue);
info("Debugger editor text:\n" + gEditor.getText());
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSources = null;
gSearchBox = null;
gFilteredFunctions = null;
});

View File

@ -0,0 +1,62 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Make sure that the searchbox popup is displayed when focusing the searchbox,
* and hidden when the user starts typing.
*/
const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
let gTab, gDebuggee, gPanel, gDebugger;
let gEditor, gSearchBox, gSearchBoxPanel;
function test() {
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
gTab = aTab;
gDebuggee = aDebuggee;
gPanel = aPanel;
gDebugger = gPanel.panelWin;
gEditor = gDebugger.DebuggerView.editor;
gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
gSearchBoxPanel = gDebugger.DebuggerView.Filtering._searchboxHelpPanel;
waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
.then(() => showPopup())
.then(() => hidePopup())
.then(() => resumeDebuggerThenCloseAndFinish(gPanel))
.then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
});
gDebuggee.firstCall();
});
}
function showPopup() {
is(gSearchBoxPanel.state, "closed",
"The search box panel shouldn't be visible yet.");
let finished = once(gSearchBoxPanel, "popupshown");
EventUtils.sendMouseEvent({ type: "click" }, gSearchBox, gDebugger);
return finished;
}
function hidePopup() {
is(gSearchBoxPanel.state, "open",
"The search box panel should be visible after searching started.");
let finished = once(gSearchBoxPanel, "popuphidden");
setText(gSearchBox, "#");
return finished;
}
registerCleanupFunction(function() {
gTab = null;
gDebuggee = null;
gPanel = null;
gDebugger = null;
gEditor = null;
gSearchBox = null;
gSearchBoxPanel = null;
});