Bug 999854 - Rewrite browser_dbg_pretty-print-on-paused.js to use Task.spawn. r=vporof
authorNick Fitzgerald <fitzgen@mozilla.com>
Thu, 24 Apr 2014 13:09:00 -0400
changeset 198618 06d54318284ef0d39294cd1125e60cabc63e237c
parent 198617 0e0d3955de465a48c58e123d084877cd6525497f
child 198619 e063eb25827ac05c044d2c718b6c951b5a444dac
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof
bugs999854
milestone31.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 999854 - Rewrite browser_dbg_pretty-print-on-paused.js to use Task.spawn. r=vporof
browser/devtools/debugger/test/browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js
browser/devtools/debugger/test/browser_dbg_pretty-print-on-paused.js
browser/devtools/debugger/test/head.js
--- a/browser/devtools/debugger/test/browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js
+++ b/browser/devtools/debugger/test/browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js
@@ -4,18 +4,16 @@
 /**
  * Bug 978019: Setting a breakpoint on the last line of a Debugger.Script and
  * reloading should still hit the breakpoint.
  */
 
 const TAB_URL = EXAMPLE_URL + "doc_breakpoints-break-on-last-line-of-script-on-reload.html";
 const CODE_URL = EXAMPLE_URL + "code_breakpoints-break-on-last-line-of-script-on-reload.js";
 
-const { promiseInvoke } = require("devtools/async-utils");
-
 function test() {
   let gPanel, gDebugger, gThreadClient, gEvents;
 
   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gPanel = aPanel;
     gDebugger = gPanel.panelWin;
     gThreadClient = gDebugger.gThreadClient;
     gEvents = gDebugger.EVENTS;
@@ -54,25 +52,25 @@ function test() {
         // Refresh and hit the debugger statement again.
         yield promise.all([
           reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN),
           waitForCaretAndScopes(gPanel, 1)
         ]);
 
         // And we should hit the breakpoints as we resume.
         yield promise.all([
-          doResume(),
+          doResume(gPanel),
           waitForCaretAndScopes(gPanel, 3)
         ]);
         yield promise.all([
-          doResume(),
+          doResume(gPanel),
           waitForCaretAndScopes(gPanel, 4)
         ]);
         yield promise.all([
-          doResume(),
+          doResume(gPanel),
           waitForCaretAndScopes(gPanel, 5)
         ]);
 
         // Clean up the breakpoints.
         yield promise.all([
           rdpInvoke(bp1, bp1.remove),
           rdpInvoke(bp2, bp1.remove),
           rdpInvoke(bp3, bp1.remove),
@@ -85,33 +83,16 @@ function test() {
           "browser_dbg_breakpoints-break-on-last-line-of-script-on-reload.js",
           e
         );
         ok(false);
       }
     });
   });
 
-  function rdpInvoke(obj, method) {
-    return promiseInvoke(obj, method)
-      .then(({error, message }) => {
-        if (error) {
-          throw new Error(error + ": " + message);
-        }
-      });
-  }
-
-  function doResume() {
-    return rdpInvoke(gThreadClient, gThreadClient.resume);
-  }
-
-  function doInterrupt() {
-    return rdpInvoke(gThreadClient, gThreadClient.interrupt);
-  }
-
   function setBreakpoint(location) {
     let deferred = promise.defer();
     gThreadClient.setBreakpoint(location, ({ error, message }, bpClient) => {
       if (error) {
         deferred.reject(error + ": " + message);
       }
       deferred.resolve(bpClient);
     });
--- a/browser/devtools/debugger/test/browser_dbg_pretty-print-on-paused.js
+++ b/browser/devtools/debugger/test/browser_dbg_pretty-print-on-paused.js
@@ -1,81 +1,67 @@
 /* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
- * Test that pretty printing when the debugger is paused
- * does not switch away from the selected source.
+ * Test that pretty printing when the debugger is paused does not switch away
+ * from the selected source.
  */
 
 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-on-paused.html";
 
-let gTab, gDebuggee, gPanel, gDebugger;
-let gSources;
+let gTab, gDebuggee, gPanel, gDebugger, gThreadClient, gSources;
 
-let gSecondSourceLabel = "code_ugly-2.js";
+const SECOND_SOURCE_VALUE = EXAMPLE_URL + "code_ugly-2.js";
 
 function test(){
   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
     gPanel = aPanel;
     gDebugger = gPanel.panelWin;
+    gThreadClient = gDebugger.gThreadClient;
     gSources = gDebugger.DebuggerView.Sources;
 
-    gPanel.addBreakpoint({ url: gSources.values[0], line: 6 });
+    Task.spawn(function* () {
+      try {
+        yield ensureSourceIs(gPanel, "code_script-switching-02.js", true);
+
+        yield doInterrupt(gPanel);
+        yield rdpInvoke(gThreadClient, gThreadClient.setBreakpoint, {
+          url: gSources.selectedValue,
+          line: 6
+        });
+        yield doResume(gPanel);
+
+        const bpHit = waitForCaretAndScopes(gPanel, 6);
+        // Get the debuggee call off this tick so that we aren't accidentally
+        // blocking the yielding of bpHit which causes a deadlock.
+        executeSoon(() => gDebuggee.secondCall());
+        yield bpHit;
 
-    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
-      .then(testPaused)
-      .then(() => {
-        // Switch to the second source.
-        let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
-        gSources.selectedIndex = 1;
-        return finished;
-      })
-      .then(testSecondSourceIsSelected)
-      .then(() => {
-        const finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
-        clickPrettyPrintButton();
-        testProgressBarShown();
-        return finished;
-      })
-      .then(testSecondSourceIsStillSelected)
-      .then(() => closeDebuggerAndFinish(gPanel))
-      .then(null, aError => {
-        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
-      })
+        info("Switch to the second source.");
+        const sourceShown = waitForSourceShown(gPanel, SECOND_SOURCE_VALUE);
+        gSources.selectedValue = SECOND_SOURCE_VALUE;
+        yield sourceShown;
 
-    gDebuggee.secondCall();
+        info("Pretty print the source.");
+        const prettyPrinted = waitForSourceShown(gPanel, SECOND_SOURCE_VALUE);
+        gDebugger.document.getElementById("pretty-print").click();
+        yield prettyPrinted;
+
+        yield resumeDebuggerThenCloseAndFinish(gPanel);
+      } catch (e) {
+        DevToolsUtils.reportException("browser_dbg_pretty-print-on-paused.js", e);
+        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
+      }
+    });
   });
 }
 
-function testPaused() {
-  is(gDebugger.gThreadClient.paused, true,
-    "The thread should be paused");
-}
-
-function testSecondSourceIsSelected() {
-  ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel),
-    "The second source should be selected.");
-}
-
-function clickPrettyPrintButton() {
-  gDebugger.document.getElementById("pretty-print").click();
-}
-
-function testProgressBarShown() {
-  const deck = gDebugger.document.getElementById("editor-deck");
-  is(deck.selectedIndex, 2, "The progress bar should be shown");
-}
-
-function testSecondSourceIsStillSelected() {
-  ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel),
-    "The second source should still be selected.");
-}
-
 registerCleanupFunction(function() {
   gTab = null;
   gDebuggee = null;
   gPanel = null;
   gDebugger = null;
+  gThreadClient = null;
   gSources = null;
 });
--- a/browser/devtools/debugger/test/head.js
+++ b/browser/devtools/debugger/test/head.js
@@ -20,16 +20,17 @@ let { Promise: promise } = Cu.import("re
 let { gDevTools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
 let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
 let { require } = devtools;
 let { DevToolsUtils } = Cu.import("resource://gre/modules/devtools/DevToolsUtils.jsm", {});
 let { BrowserToolboxProcess } = Cu.import("resource:///modules/devtools/ToolboxProcess.jsm", {});
 let { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
 let { DebuggerClient } = Cu.import("resource://gre/modules/devtools/dbg-client.jsm", {});
 let { AddonManager } = Cu.import("resource://gre/modules/AddonManager.jsm", {});
+const { promiseInvoke } = require("devtools/async-utils");
 let TargetFactory = devtools.TargetFactory;
 let Toolbox = devtools.Toolbox;
 
 const EXAMPLE_URL = "http://example.com/browser/browser/devtools/debugger/test/";
 
 gDevTools.testing = true;
 SimpleTest.registerCleanupFunction(() => {
   gDevTools.testing = false;
@@ -851,8 +852,28 @@ function attachAddonActorForUrl(aClient,
   getAddonActorForUrl(aClient, aUrl).then(aGrip => {
     aClient.attachAddon(aGrip.actor, aResponse => {
       deferred.resolve([aGrip, aResponse]);
     });
   });
 
   return deferred.promise;
 }
+
+function rdpInvoke(aClient, aMethod, ...args) {
+  return promiseInvoke(aClient, aMethod, ...args)
+    .then(({error, message }) => {
+      if (error) {
+        throw new Error(error + ": " + message);
+      }
+    });
+}
+
+function doResume(aPanel) {
+  const threadClient = aPanel.panelWin.gThreadClient;
+  return rdpInvoke(threadClient, threadClient.resume);
+}
+
+function doInterrupt(aPanel) {
+  const threadClient = aPanel.panelWin.gThreadClient;
+  return rdpInvoke(threadClient, threadClient.interrupt);
+}
+