Bug 876277 - Add more debugger tests, r=past
authorVictor Porof <vporof@mozilla.com>
Fri, 13 Sep 2013 16:23:16 +0300
changeset 159989 708bac7a4c99c320c4a5a097054ec4d95b92a3d2
parent 159988 647b5d5dc08181d87e9181889001197f61eca866
child 159990 0d004fdd1fdb8ce857a5aa0358bd752e23f70613
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs876277
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 876277 - Add more debugger tests, r=past
browser/devtools/debugger/test/browser_dbg_reload-preferred-script-02.js
browser/devtools/debugger/test/browser_dbg_reload-preferred-script-03.js
browser/devtools/debugger/test/browser_dbg_variables-view-filter-searchbox.js
browser/devtools/debugger/test/browser_dbg_variables-view-reexpand-02.js
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_reload-preferred-script-02.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests if the preferred source is shown when a page is loaded and
+ * the preferred source is specified after another source might have been shown.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
+const PREFERRED_URL = EXAMPLE_URL + "code_script-switching-02.js";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gSources;
+
+function test() {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
+    gTab = aTab;
+    gDebuggee = aDebuggee;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gSources = gDebugger.DebuggerView.Sources;
+
+    waitForSourceShown(gPanel, PREFERRED_URL).then(finishTest);
+    gSources.preferredSource = PREFERRED_URL;
+  });
+}
+
+function finishTest() {
+  info("Currently preferred source: " + gSources.preferredValue);
+  info("Currently selected source: " + gSources.selectedValue);
+
+  is(gSources.preferredValue, PREFERRED_URL,
+    "The preferred source url wasn't set correctly.");
+  is(gSources.selectedValue, PREFERRED_URL,
+    "The selected source isn't the correct one.");
+
+  closeDebuggerAndFinish(gPanel);
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gSources = null;
+});
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_reload-preferred-script-03.js
@@ -0,0 +1,59 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests if the preferred source is shown when a page is loaded and
+ * the preferred source is specified after another source was definitely shown.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
+const FIRST_URL = EXAMPLE_URL + "code_script-switching-01.js";
+const SECOND_URL = EXAMPLE_URL + "code_script-switching-02.js";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gSources;
+
+function test() {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
+    gTab = aTab;
+    gDebuggee = aDebuggee;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gSources = gDebugger.DebuggerView.Sources;
+
+    waitForSourceShown(gPanel, FIRST_URL)
+      .then(() => testSource("", FIRST_URL))
+      .then(() => switchToSource(SECOND_URL))
+      .then(() => testSource(SECOND_URL))
+      .then(() => switchToSource(FIRST_URL))
+      .then(() => testSource(FIRST_URL))
+      .then(() => closeDebuggerAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
+  });
+}
+
+function testSource(aPreferredUrl, aSelectedUrl = aPreferredUrl) {
+  info("Currently preferred source: " + gSources.preferredValue);
+  info("Currently selected source: " + gSources.selectedValue);
+
+  is(gSources.preferredValue, aPreferredUrl,
+    "The preferred source url wasn't set correctly.");
+  is(gSources.selectedValue, aSelectedUrl,
+    "The selected source isn't the correct one.");
+}
+
+function switchToSource(aUrl) {
+  let finished = waitForSourceShown(gPanel, aUrl);
+  gSources.preferredSource = aUrl;
+  return finished;
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gSources = null;
+});
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_variables-view-filter-searchbox.js
@@ -0,0 +1,146 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Make sure that the variables view correctly shows the searchbox
+ * when prompted.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_with-frame.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gVariables;
+
+function test() {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
+    gTab = aTab;
+    gDebuggee = aDebuggee;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gVariables = gDebugger.DebuggerView.Variables;
+
+    waitForSourceShown(gPanel, ".html").then(performTest);
+  });
+}
+
+function performTest() {
+  // Step 1: the searchbox shouldn't initially be shown.
+
+  ok(!gVariables._searchboxNode,
+    "There should not initially be a searchbox available in the variables view.");
+  ok(!gVariables._searchboxContainer,
+    "There should not initially be a searchbox container available in the variables view.");
+  ok(!gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should not be found.");
+
+  // Step 2: test enable/disable cycles.
+
+  gVariables._enableSearch();
+  ok(gVariables._searchboxNode,
+    "There should be a searchbox available after enabling.");
+  ok(gVariables._searchboxContainer,
+    "There should be a searchbox container available after enabling.");
+  ok(gVariables._searchboxContainer.hidden,
+    "The searchbox container should be hidden at this point.");
+  ok(gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should be found.");
+
+  gVariables._disableSearch();
+  ok(!gVariables._searchboxNode,
+    "There shouldn't be a searchbox available after disabling.");
+  ok(!gVariables._searchboxContainer,
+    "There shouldn't be a searchbox container available after disabling.");
+  ok(!gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should not be found.");
+
+  // Step 3: add a placeholder while the searchbox is hidden.
+
+  var placeholder = "not freshly squeezed mango juice";
+
+  gVariables.searchPlaceholder = placeholder;
+  is(gVariables.searchPlaceholder, placeholder,
+    "The placeholder getter didn't return the expected string");
+
+  // Step 4: enable search and check the placeholder.
+
+  gVariables._enableSearch();
+  ok(gVariables._searchboxNode,
+    "There should be a searchbox available after enabling.");
+  ok(gVariables._searchboxContainer,
+    "There should be a searchbox container available after enabling.");
+  ok(gVariables._searchboxContainer.hidden,
+    "The searchbox container should be hidden at this point.");
+  ok(gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should be found.");
+
+  is(gVariables._searchboxNode.getAttribute("placeholder"),
+    placeholder, "There correct placeholder should be applied to the searchbox.");
+
+  // Step 5: add a placeholder while the searchbox is visible and check wether
+  // it has been immediatey applied.
+
+  var placeholder = "freshly squeezed mango juice";
+
+  gVariables.searchPlaceholder = placeholder;
+  is(gVariables.searchPlaceholder, placeholder,
+    "The placeholder getter didn't return the expected string");
+
+  is(gVariables._searchboxNode.getAttribute("placeholder"),
+    placeholder, "There correct placeholder should be applied to the searchbox.");
+
+  // Step 4: disable, enable, then test the placeholder.
+
+  gVariables._disableSearch();
+  ok(!gVariables._searchboxNode,
+    "There shouldn't be a searchbox available after disabling again.");
+  ok(!gVariables._searchboxContainer,
+    "There shouldn't be a searchbox container available after disabling again.");
+  ok(!gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should not be found.");
+
+  gVariables._enableSearch();
+  ok(gVariables._searchboxNode,
+    "There should be a searchbox available after enabling again.");
+  ok(gVariables._searchboxContainer,
+    "There should be a searchbox container available after enabling again.");
+  ok(gVariables._searchboxContainer.hidden,
+    "The searchbox container should be hidden at this point.");
+  ok(gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should be found.");
+
+  is(gVariables._searchboxNode.getAttribute("placeholder"),
+    placeholder, "There correct placeholder should be applied to the searchbox again.");
+
+  // Step 5: alternate disable, enable, then test the placeholder.
+
+  gVariables.searchEnabled = false;
+  ok(!gVariables._searchboxNode,
+    "There shouldn't be a searchbox available after disabling again.");
+  ok(!gVariables._searchboxContainer,
+    "There shouldn't be a searchbox container available after disabling again.");
+  ok(!gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should not be found.");
+
+  gVariables.searchEnabled = true;
+  ok(gVariables._searchboxNode,
+    "There should be a searchbox available after enabling again.");
+  ok(gVariables._searchboxContainer,
+    "There should be a searchbox container available after enabling again.");
+  ok(gVariables._searchboxContainer.hidden,
+    "The searchbox container should be hidden at this point.");
+  ok(gVariables._parent.parentNode.querySelector(".variables-view-searchinput"),
+    "The searchbox element should be found.");
+
+  is(gVariables._searchboxNode.getAttribute("placeholder"),
+    placeholder, "There correct placeholder should be applied to the searchbox again.");
+
+  closeDebuggerAndFinish(gPanel);
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gVariables = null;
+});
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_variables-view-reexpand-02.js
@@ -0,0 +1,224 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Make sure that the variables view correctly re-expands nodes after pauses,
+ * with the caveat that there are no ignored items in the hierarchy.
+ */
+
+const TAB_URL = EXAMPLE_URL + "doc_with-frame.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gBreakpoints, gSources, gVariables;
+
+function test() {
+  // Debug test slaves are a bit slow at this test.
+  requestLongerTimeout(4);
+
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
+    gTab = aTab;
+    gDebuggee = aDebuggee;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gBreakpoints = gDebugger.DebuggerController.Breakpoints;
+    gSources = gDebugger.DebuggerView.Sources;
+    gVariables = gDebugger.DebuggerView.Variables;
+
+    // Always expand all scopes between pauses.
+    gVariables.commitHierarchyIgnoredItems = Object.create(null);
+
+    waitForSourceShown(gPanel, ".html")
+      .then(addBreakpoint)
+      .then(() => ensureThreadClientState(gPanel, "resumed"))
+      .then(pauseDebuggee)
+      .then(prepareVariablesAndProperties)
+      .then(stepInDebuggee)
+      .then(testVariablesExpand)
+      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
+  });
+}
+
+function addBreakpoint() {
+  return gBreakpoints.addBreakpoint({ url: gSources.selectedValue, line: 21 });
+}
+
+function pauseDebuggee() {
+  // Spin the event loop before causing the debuggee to pause, to allow
+  // this function to return first.
+  executeSoon(() => {
+    EventUtils.sendMouseEvent({ type: "click" },
+      gDebuggee.document.querySelector("button"),
+      gDebuggee);
+  });
+
+  // The first 'with' scope should be expanded by default, but the
+  // variables haven't been fetched yet. This is how 'with' scopes work.
+  return promise.all([
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES)
+  ]);
+}
+
+function stepInDebuggee() {
+  // Spin the event loop before causing the debuggee to pause, to allow
+  // this function to return first.
+  executeSoon(() => {
+    EventUtils.sendMouseEvent({ type: "mousedown" },
+      gDebugger.document.querySelector("#step-in"),
+      gDebugger);
+  });
+
+  return promise.all([
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES, 1),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 3),
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 4),
+  ]);
+}
+
+function testVariablesExpand() {
+  let localScope = gVariables.getScopeAtIndex(0);
+  let withScope = gVariables.getScopeAtIndex(1);
+  let functionScope = gVariables.getScopeAtIndex(2);
+  let globalScope = gVariables.getScopeAtIndex(3);
+
+  let thisVar = localScope.get("this");
+  let windowVar = thisVar.get("window");
+  let documentVar = windowVar.get("document");
+  let locationVar = documentVar.get("location");
+
+  is(localScope.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The localScope arrow should still be expanded.");
+  is(withScope.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The withScope arrow should still be expanded.");
+  is(functionScope.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The functionScope arrow should still be expanded.");
+  is(globalScope.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The globalScope arrow should still be expanded.");
+  is(thisVar.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The thisVar arrow should still be expanded.");
+  is(windowVar.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The windowVar arrow should still be expanded.");
+  is(documentVar.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The documentVar arrow should still be expanded.");
+  is(locationVar.target.querySelector(".arrow").hasAttribute("open"), true,
+    "The locationVar arrow should still be expanded.");
+
+  is(localScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The localScope enumerables should still be expanded.");
+  is(withScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The withScope enumerables should still be expanded.");
+  is(functionScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The functionScope enumerables should still be expanded.");
+  is(globalScope.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The globalScope enumerables should still be expanded.");
+  is(thisVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The thisVar enumerables should still be expanded.");
+  is(windowVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The windowVar enumerables should still be expanded.");
+  is(documentVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The documentVar enumerables should still be expanded.");
+  is(locationVar.target.querySelector(".variables-view-element-details").hasAttribute("open"), true,
+    "The locationVar enumerables should still be expanded.");
+
+  is(localScope.expanded, true,
+    "The localScope expanded getter should return true.");
+  is(withScope.expanded, true,
+    "The withScope expanded getter should return true.");
+  is(functionScope.expanded, true,
+    "The functionScope expanded getter should return true.");
+  is(globalScope.expanded, true,
+    "The globalScope expanded getter should return true.");
+  is(thisVar.expanded, true,
+    "The thisVar expanded getter should return true.");
+  is(windowVar.expanded, true,
+    "The windowVar expanded getter should return true.");
+  is(documentVar.expanded, true,
+    "The documentVar expanded getter should return true.");
+  is(locationVar.expanded, true,
+    "The locationVar expanded getter should return true.");
+}
+
+function prepareVariablesAndProperties() {
+  let deferred = promise.defer();
+
+  let localScope = gVariables.getScopeAtIndex(0);
+  let withScope = gVariables.getScopeAtIndex(1);
+  let functionScope = gVariables.getScopeAtIndex(2);
+  let globalScope = gVariables.getScopeAtIndex(3);
+
+  is(localScope.expanded, true,
+    "The localScope should be expanded.");
+  is(withScope.expanded, false,
+    "The withScope should not be expanded yet.");
+  is(functionScope.expanded, false,
+    "The functionScope should not be expanded yet.");
+  is(globalScope.expanded, false,
+    "The globalScope should not be expanded yet.");
+
+  // Wait for only two events to be triggered, because the Function scope is
+  // an environment to which scope arguments and variables are already attached.
+  waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_VARIABLES, 2).then(() => {
+    is(localScope.expanded, true,
+      "The localScope should now be expanded.");
+    is(withScope.expanded, true,
+      "The withScope should now be expanded.");
+    is(functionScope.expanded, true,
+      "The functionScope should now be expanded.");
+    is(globalScope.expanded, true,
+      "The globalScope should now be expanded.");
+
+    let thisVar = localScope.get("this");
+
+    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
+      let windowVar = thisVar.get("window");
+
+      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
+        let documentVar = windowVar.get("document");
+
+        waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
+          let locationVar = documentVar.get("location");
+
+          waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_PROPERTIES, 1).then(() => {
+            is(thisVar.expanded, true,
+              "The local scope 'this' should be expanded.");
+            is(windowVar.expanded, true,
+              "The local scope 'this.window' should be expanded.");
+            is(documentVar.expanded, true,
+              "The local scope 'this.window.document' should be expanded.");
+            is(locationVar.expanded, true,
+              "The local scope 'this.window.document.location' should be expanded.");
+
+            deferred.resolve();
+          });
+
+          locationVar.expand();
+        });
+
+        documentVar.expand();
+      });
+
+      windowVar.expand();
+    });
+
+    thisVar.expand();
+  });
+
+  withScope.expand();
+  functionScope.expand();
+  globalScope.expand();
+
+  return deferred.promise;
+}
+
+registerCleanupFunction(function() {
+  gTab = null;
+  gDebuggee = null;
+  gPanel = null;
+  gDebugger = null;
+  gBreakpoints = null;
+  gSources = null;
+  gVariables = null;
+});