Bug 894311 - Add some tests, r=rcampbell
authorVictor Porof <vporof@mozilla.com>
Thu, 05 Sep 2013 11:03:07 +0300
changeset 146966 7b74e2d12cf7fde17e00104e543485110752fc67
parent 146965 47cc9c07b703dfefdc990bc26b483f4ca28a9cba
child 146967 159e240fc628fea2921b51e139887f0cdd846e25
push id2642
push uservporof@mozilla.com
push dateFri, 13 Sep 2013 13:23:59 +0000
treeherderfx-team@159e240fc628 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs894311
milestone26.0a1
Bug 894311 - Add some tests, r=rcampbell
browser/devtools/debugger/test/Makefile.in
browser/devtools/debugger/test/browser_dbg_search-basic-01.js
browser/devtools/debugger/test/browser_dbg_search-basic-02.js
browser/devtools/debugger/test/browser_dbg_search-basic-03.js
browser/devtools/debugger/test/browser_dbg_search-basic-04.js
browser/devtools/debugger/test/browser_dbg_search-basic.js
browser/devtools/debugger/test/browser_dbg_searchbox-parse.js
--- a/browser/devtools/debugger/test/Makefile.in
+++ b/browser/devtools/debugger/test/Makefile.in
@@ -51,28 +51,32 @@ MOCHITEST_BROWSER_TESTS = \
 	browser_dbg_progress-listener-bug.js \
 	browser_dbg_reload-preferred-script-01.js \
 	browser_dbg_reload-preferred-script-02.js \
 	browser_dbg_reload-preferred-script-03.js \
 	browser_dbg_reload-same-script.js \
 	browser_dbg_scripts-switching-01.js \
 	browser_dbg_scripts-switching-02.js \
 	browser_dbg_scripts-switching-03.js \
-	browser_dbg_search-basic.js \
+	browser_dbg_search-basic-01.js \
+	browser_dbg_search-basic-02.js \
+	browser_dbg_search-basic-03.js \
+	browser_dbg_search-basic-04.js \
 	browser_dbg_search-global-01.js \
 	browser_dbg_search-global-02.js \
 	browser_dbg_search-global-03.js \
 	browser_dbg_search-global-04.js \
 	browser_dbg_search-global-05.js \
 	browser_dbg_search-global-06.js \
 	browser_dbg_search-sources-01.js \
 	browser_dbg_search-sources-02.js \
 	browser_dbg_search-sources-03.js \
 	browser_dbg_search-symbols.js \
 	browser_dbg_searchbox-help-popup.js \
+	browser_dbg_searchbox-parse.js \
 	browser_dbg_source-maps-01.js \
 	browser_dbg_source-maps-02.js \
 	browser_dbg_source-maps-03.js \
 	browser_dbg_sources-cache.js \
 	browser_dbg_sources-labels.js \
 	browser_dbg_sources-sorting.js \
 	browser_dbg_stack-01.js \
 	browser_dbg_stack-02.js \
rename from browser/devtools/debugger/test/browser_dbg_search-basic.js
rename to browser/devtools/debugger/test/browser_dbg_search-basic-01.js
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_search-basic-02.js
@@ -0,0 +1,124 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests basic file search functionality.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gSources, gSearchBox;
+
+function test() {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
+    gTab = aTab;
+    gDebuggee = aDebuggee;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gSources = gDebugger.DebuggerView.Sources;
+    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
+
+    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
+      .then(performSimpleSearch)
+      .then(() => verifySourceAndCaret("-01.js", 1, 1, [1, 1]))
+      .then(combineWithLineSearch)
+      .then(() => verifySourceAndCaret("-01.js", 2, 1, [53, 53]))
+      .then(combineWithTokenSearch)
+      .then(() => verifySourceAndCaret("-01.js", 2, 48, [96, 100]))
+      .then(combineWithTokenColonSearch)
+      .then(() => verifySourceAndCaret("-01.js", 2, 11, [56, 63]))
+      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
+
+    gDebuggee.firstCall();
+  });
+}
+
+function performSimpleSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-02.js"),
+    ensureCaretAt(gPanel, 6),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
+    waitForSourceShown(gPanel, "-01.js")
+  ]);
+
+  setText(gSearchBox, "1");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 1)
+  ]));
+}
+
+function combineWithLineSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 1),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
+    waitForCaretUpdated(gPanel, 2)
+  ]);
+
+  typeText(gSearchBox, ":2");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 2)
+  ]));
+}
+
+function combineWithTokenSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 2),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
+    waitForCaretUpdated(gPanel, 2, 48)
+  ]);
+
+  backspaceText(gSearchBox, 2);
+  typeText(gSearchBox, "#zero");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 2, 48)
+  ]));
+}
+
+function combineWithTokenColonSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 2, 48),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
+    waitForCaretUpdated(gPanel, 2, 11)
+  ]);
+
+  backspaceText(gSearchBox, 4);
+  typeText(gSearchBox, "http://");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 2, 11)
+  ]));
+}
+
+function verifySourceAndCaret(aUrl, aLine, aColumn, aSelection) {
+  ok(gSources.selectedItem.label.contains(aUrl),
+    "The selected item's label appears to be correct.");
+  ok(gSources.selectedItem.value.contains(aUrl),
+    "The selected item's value appears to be correct.");
+  ok(isCaretPos(gPanel, aLine, aColumn),
+    "The current caret position appears to be correct.");
+  ok(isEditorSel(gPanel, aSelection),
+    "The current editor selection appears to be correct.");
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gSources = null;
+  gSearchBox = null;
+});
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_search-basic-03.js
@@ -0,0 +1,120 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that searches which cause a popup to be shown properly handle the
+ * ESCAPE key.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gSources, gSearchBox;
+
+function test() {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
+    gTab = aTab;
+    gDebuggee = aDebuggee;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gSources = gDebugger.DebuggerView.Sources;
+    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
+
+    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
+      .then(performFileSearch)
+      .then(escapeAndHide)
+      .then(escapeAndClear)
+      .then(() => verifySourceAndCaret("-01.js", 1, 1))
+      .then(performFunctionSearch)
+      .then(escapeAndHide)
+      .then(escapeAndClear)
+      .then(() => verifySourceAndCaret("-01.js", 4, 10))
+      .then(performGlobalSearch)
+      .then(escapeAndClear)
+      .then(() => verifySourceAndCaret("-01.js", 4, 10))
+      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
+
+    gDebuggee.firstCall();
+  });
+}
+
+function performFileSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-02.js"),
+    ensureCaretAt(gPanel, 6),
+    once(gDebugger, "popupshown"),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FILE_SEARCH_MATCH_FOUND),
+    waitForSourceShown(gPanel, "-01.js")
+  ]);
+
+  setText(gSearchBox, ".");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 1)
+  ]));
+}
+
+function performFunctionSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 1),
+    once(gDebugger, "popupshown"),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FUNCTION_SEARCH_MATCH_FOUND)
+  ]);
+
+  setText(gSearchBox, "@");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 4, 10)
+  ]));
+}
+
+function performGlobalSearch() {
+  let finished = promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 4, 10),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.GLOBAL_SEARCH_MATCH_FOUND)
+  ]);
+
+  setText(gSearchBox, "!first");
+
+  return finished.then(() => promise.all([
+    ensureSourceIs(gPanel, "-01.js"),
+    ensureCaretAt(gPanel, 4, 10)
+  ]));
+}
+
+function escapeAndHide() {
+  let finished = once(gDebugger, "popuphidden", true);
+  EventUtils.sendKey("ESCAPE", gDebugger);
+  return finished;
+}
+
+function escapeAndClear() {
+  EventUtils.sendKey("ESCAPE", gDebugger);
+  is(gSearchBox.getAttribute("value"), "",
+    "The searchbox has properly emptied after pressing escape.");
+}
+
+function verifySourceAndCaret(aUrl, aLine, aColumn) {
+  ok(gSources.selectedItem.label.contains(aUrl),
+    "The selected item's label appears to be correct.");
+  ok(gSources.selectedItem.value.contains(aUrl),
+    "The selected item's value appears to be correct.");
+  ok(isCaretPos(gPanel, aLine, aColumn),
+    "The current caret position appears to be correct.");
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gSources = null;
+  gSearchBox = null;
+});
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_search-basic-04.js
@@ -0,0 +1,132 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that the selection is dropped for line and token searches, after
+ * pressing backspace enough times.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gEditor, gSources, 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;
+    gSearchBox = gDebugger.DebuggerView.Filtering._searchbox;
+
+    waitForSourceShown(gPanel, "-01.js")
+      .then(testLineSearch)
+      .then(testTokenSearch)
+      .then(() => closeDebuggerAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
+  });
+}
+
+function testLineSearch() {
+  setText(gSearchBox, ":42");
+  ok(isCaretPos(gPanel, 1),
+    "The editor caret position appears to be correct (1.1).");
+  ok(isEditorSel(gPanel, [1, 1]),
+    "The editor selection appears to be correct (1.1).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (1.1).");
+
+  backspaceText(gSearchBox, 1);
+  ok(isCaretPos(gPanel, 4),
+    "The editor caret position appears to be correct (1.2).");
+  ok(isEditorSel(gPanel, [110, 110]),
+    "The editor selection appears to be correct (1.2).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (1.2).");
+
+  backspaceText(gSearchBox, 1);
+  ok(isCaretPos(gPanel, 4),
+    "The editor caret position appears to be correct (1.3).");
+  ok(isEditorSel(gPanel, [110, 110]),
+    "The editor selection appears to be correct (1.3).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (1.3).");
+
+  setText(gSearchBox, ":4");
+  ok(isCaretPos(gPanel, 4),
+    "The editor caret position appears to be correct (1.4).");
+  ok(isEditorSel(gPanel, [110, 110]),
+    "The editor selection appears to be correct (1.4).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (1.4).");
+
+  gSearchBox.select();
+  backspaceText(gSearchBox, 1);
+  ok(isCaretPos(gPanel, 4),
+    "The editor caret position appears to be correct (1.5).");
+  ok(isEditorSel(gPanel, [110, 110]),
+    "The editor selection appears to be correct (1.5).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (1.5).");
+  is(gSearchBox.value, "",
+    "The searchbox should have been cleared.");
+}
+
+function testTokenSearch() {
+  setText(gSearchBox, "#;\"");
+  ok(isCaretPos(gPanel, 5, 23),
+    "The editor caret position appears to be correct (2.1).");
+  ok(isEditorSel(gPanel, [153, 155]),
+    "The editor selection appears to be correct (2.1).");
+  is(gEditor.getSelectedText(), ";\"",
+    "The editor selected text appears to be correct (2.1).");
+
+  backspaceText(gSearchBox, 1);
+  ok(isCaretPos(gPanel, 5, 22),
+    "The editor caret position appears to be correct (2.2).");
+  ok(isEditorSel(gPanel, [153, 154]),
+    "The editor selection appears to be correct (2.2).");
+  is(gEditor.getSelectedText(), ";",
+    "The editor selected text appears to be correct (2.2).");
+
+  backspaceText(gSearchBox, 1);
+  ok(isCaretPos(gPanel, 5, 22),
+    "The editor caret position appears to be correct (2.3).");
+  ok(isEditorSel(gPanel, [154, 154]),
+    "The editor selection appears to be correct (2.3).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (2.3).");
+
+  setText(gSearchBox, "#;");
+  ok(isCaretPos(gPanel, 5, 22),
+    "The editor caret position appears to be correct (2.4).");
+  ok(isEditorSel(gPanel, [153, 154]),
+    "The editor selection appears to be correct (2.4).");
+  is(gEditor.getSelectedText(), ";",
+    "The editor selected text appears to be correct (2.4).");
+
+  gSearchBox.select();
+  backspaceText(gSearchBox, 1);
+  ok(isCaretPos(gPanel, 5, 22),
+    "The editor caret position appears to be correct (2.5).");
+  ok(isEditorSel(gPanel, [154, 154]),
+    "The editor selection appears to be correct (2.5).");
+  is(gEditor.getSelectedText(), "",
+    "The editor selected text appears to be correct (2.5).");
+  is(gSearchBox.value, "",
+    "The searchbox should have been cleared.");
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gEditor = null;
+  gSources = null;
+  gSearchBox = null;
+});
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_searchbox-parse.js
@@ -0,0 +1,124 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that text entered in the debugger's searchbox is properly parsed.
+ */
+
+function test() {
+  initDebugger("about:blank").then(([aTab, aDebuggee, aPanel]) => {
+    let filterView = aPanel.panelWin.DebuggerView.Filtering;
+    let searchbox = aPanel.panelWin.DebuggerView.Filtering._searchbox;
+
+    setText(searchbox, "");
+    is(filterView.searchData.toSource(), '["", [""]]',
+      "The searchbox data wasn't parsed correctly (1).");
+
+    setText(searchbox, "#token");
+    is(filterView.searchData.toSource(), '["#", ["", "token"]]',
+      "The searchbox data wasn't parsed correctly (2).");
+
+    setText(searchbox, ":42");
+    is(filterView.searchData.toSource(), '[":", ["", 42]]',
+      "The searchbox data wasn't parsed correctly (3).");
+
+    setText(searchbox, "#token:42");
+    is(filterView.searchData.toSource(), '["#", ["", "token:42"]]',
+      "The searchbox data wasn't parsed correctly (4).");
+
+    setText(searchbox, ":42#token");
+    is(filterView.searchData.toSource(), '["#", [":42", "token"]]',
+      "The searchbox data wasn't parsed correctly (5).");
+
+    setText(searchbox, "#token:42#token:42");
+    is(filterView.searchData.toSource(), '["#", ["#token:42", "token:42"]]',
+      "The searchbox data wasn't parsed correctly (6).");
+
+    setText(searchbox, ":42#token:42#token");
+    is(filterView.searchData.toSource(), '["#", [":42#token:42", "token"]]',
+      "The searchbox data wasn't parsed correctly (7).");
+
+
+    setText(searchbox, "file");
+    is(filterView.searchData.toSource(), '["", ["file"]]',
+      "The searchbox data wasn't parsed correctly (8).");
+
+    setText(searchbox, "file#token");
+    is(filterView.searchData.toSource(), '["#", ["file", "token"]]',
+      "The searchbox data wasn't parsed correctly (9).");
+
+    setText(searchbox, "file:42");
+    is(filterView.searchData.toSource(), '[":", ["file", 42]]',
+      "The searchbox data wasn't parsed correctly (10).");
+
+    setText(searchbox, "file#token:42");
+    is(filterView.searchData.toSource(), '["#", ["file", "token:42"]]',
+      "The searchbox data wasn't parsed correctly (11).");
+
+    setText(searchbox, "file:42#token");
+    is(filterView.searchData.toSource(), '["#", ["file:42", "token"]]',
+      "The searchbox data wasn't parsed correctly (12).");
+
+    setText(searchbox, "file#token:42#token:42");
+    is(filterView.searchData.toSource(), '["#", ["file#token:42", "token:42"]]',
+      "The searchbox data wasn't parsed correctly (13).");
+
+    setText(searchbox, "file:42#token:42#token");
+    is(filterView.searchData.toSource(), '["#", ["file:42#token:42", "token"]]',
+      "The searchbox data wasn't parsed correctly (14).");
+
+
+    setText(searchbox, "!token");
+    is(filterView.searchData.toSource(), '["!", ["token"]]',
+      "The searchbox data wasn't parsed correctly (15).");
+
+    setText(searchbox, "!token#global");
+    is(filterView.searchData.toSource(), '["!", ["token#global"]]',
+      "The searchbox data wasn't parsed correctly (16).");
+
+    setText(searchbox, "!token#global:42");
+    is(filterView.searchData.toSource(), '["!", ["token#global:42"]]',
+      "The searchbox data wasn't parsed correctly (17).");
+
+    setText(searchbox, "!token:42#global");
+    is(filterView.searchData.toSource(), '["!", ["token:42#global"]]',
+      "The searchbox data wasn't parsed correctly (18).");
+
+
+    setText(searchbox, "@token");
+    is(filterView.searchData.toSource(), '["@", ["token"]]',
+      "The searchbox data wasn't parsed correctly (19).");
+
+    setText(searchbox, "@token#global");
+    is(filterView.searchData.toSource(), '["@", ["token#global"]]',
+      "The searchbox data wasn't parsed correctly (20).");
+
+    setText(searchbox, "@token#global:42");
+    is(filterView.searchData.toSource(), '["@", ["token#global:42"]]',
+      "The searchbox data wasn't parsed correctly (21).");
+
+    setText(searchbox, "@token:42#global");
+    is(filterView.searchData.toSource(), '["@", ["token:42#global"]]',
+      "The searchbox data wasn't parsed correctly (22).");
+
+
+    setText(searchbox, "*token");
+    is(filterView.searchData.toSource(), '["*", ["token"]]',
+      "The searchbox data wasn't parsed correctly (23).");
+
+    setText(searchbox, "*token#global");
+    is(filterView.searchData.toSource(), '["*", ["token#global"]]',
+      "The searchbox data wasn't parsed correctly (24).");
+
+    setText(searchbox, "*token#global:42");
+    is(filterView.searchData.toSource(), '["*", ["token#global:42"]]',
+      "The searchbox data wasn't parsed correctly (25).");
+
+    setText(searchbox, "*token:42#global");
+    is(filterView.searchData.toSource(), '["*", ["token:42#global"]]',
+      "The searchbox data wasn't parsed correctly (26).");
+
+
+    closeDebuggerAndFinish(aPanel);
+  });
+}