Bug 876277 - Cleanup debugger sourcemaps tests, r=past
authorVictor Porof <vporof@mozilla.com>
Fri, 13 Sep 2013 16:23:17 +0300
changeset 147085 4d259d8db441bbd6d95ba8ac53d99517e7f11550
parent 147084 e721f3ee92bfc2c335518e69562af8eea4c2ad6c
child 147086 4559ea542aa9225cfd29f67cb553609a5d8b045b
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerspast
bugs876277
milestone26.0a1
Bug 876277 - Cleanup debugger sourcemaps tests, r=past
browser/devtools/debugger/test/browser_dbg_source-maps-01.js
browser/devtools/debugger/test/browser_dbg_source-maps-02.js
browser/devtools/debugger/test/browser_dbg_source-maps-03.js
browser/devtools/debugger/test/browser_dbg_source_maps-01.js
browser/devtools/debugger/test/browser_dbg_source_maps-02.js
browser/devtools/debugger/test/browser_dbg_source_maps-03.js
rename from browser/devtools/debugger/test/browser_dbg_source_maps-01.js
rename to browser/devtools/debugger/test/browser_dbg_source-maps-01.js
--- a/browser/devtools/debugger/test/browser_dbg_source_maps-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_source-maps-01.js
@@ -1,157 +1,165 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
- * Test that we can set breakpoints and step through source mapped coffee
- * script.
+ * Test that we can set breakpoints and step through source mapped
+ * coffee script.
  */
 
-const TAB_URL = EXAMPLE_URL + "binary_search.html";
+const TAB_URL = EXAMPLE_URL + "doc_binary_search.html";
+const COFFEE_URL = EXAMPLE_URL + "code_binary_search.coffee";
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
+let gTab, gDebuggee, gPanel, gDebugger;
+let gEditor, gSources;
 
-function test()
-{
-  let scriptShown = false;
-  let framesAdded = false;
-  let resumed = false;
-  let testStarted = false;
+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;
+
+    checkSourceMapsEnabled();
 
-  SpecialPowers.pushPrefEnv({"set": [["devtools.debugger.source-maps-enabled", true]]}, () => {
-    debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
-      resumed = true;
-      gTab = aTab;
-      gDebuggee = aDebuggee;
-      gPane = aPane;
-      gDebugger = gPane.panelWin;
+    waitForSourceShown(gPanel, ".coffee")
+      .then(checkInitialSource)
+      .then(testSetBreakpoint)
+      .then(testSetBreakpointBlankLine)
+      .then(testHitBreakpoint)
+      .then(testStepping)
+      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
+  });
+}
 
-      gDebugger.addEventListener("Debugger:SourceShown", function _onSourceShown(aEvent) {
-        gDebugger.removeEventListener("Debugger:SourceShown", _onSourceShown);
-        ok(aEvent.detail.url.indexOf(".coffee") != -1,
-           "The debugger should show the source mapped coffee script file.");
-        ok(gDebugger.editor.getText().search(/isnt/) != -1,
-           "The debugger's editor should have the coffee script source displayed.");
+function checkSourceMapsEnabled() {
+  is(Services.prefs.getBoolPref("devtools.debugger.source-maps-enabled"), true,
+    "The source maps functionality should be enabled by default.");
+  is(gDebugger.Prefs.sourceMapsEnabled, true,
+    "The source maps pref should be true from startup.");
+  is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"), "true",
+    "Source maps should be enabled from startup.")
+}
 
-        testSetBreakpoint();
-      });
-    });
-  });
+function checkInitialSource() {
+  isnot(gSources.selectedValue.indexOf(".coffee"), -1,
+    "The debugger should show the source mapped coffee source file.");
+  is(gSources.selectedValue.indexOf(".js"), -1,
+    "The debugger should not show the generated js source file.");
+  is(gEditor.getText().indexOf("isnt"), 218,
+    "The debugger's editor should have the coffee source source displayed.");
+  is(gEditor.getText().indexOf("function"), -1,
+    "The debugger's editor should not have the JS source displayed.");
 }
 
 function testSetBreakpoint() {
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.interrupt(function (aResponse) {
-    activeThread.setBreakpoint({
-      url: EXAMPLE_URL + "binary_search.coffee",
-      line: 5
-    }, function (aResponse, bpClient) {
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.interrupt(aResponse => {
+    gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 5 }, aResponse => {
       ok(!aResponse.error,
-         "Should be able to set a breakpoint in a coffee script file.");
+        "Should be able to set a breakpoint in a coffee source file.");
       ok(!aResponse.actualLocation,
-         "Should be able to set a breakpoint on line 5.");
-      testSetBreakpointBlankLine();
+        "Should be able to set a breakpoint on line 5.");
+
+      deferred.resolve();
     });
   });
+
+  return deferred.promise;
 }
 
 function testSetBreakpointBlankLine() {
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.setBreakpoint({
-      url: EXAMPLE_URL + "binary_search.coffee",
-      line: 3
-  }, function (aResponse, bpClient) {
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.setBreakpoint({ url: COFFEE_URL, line: 3 }, aResponse => {
+    ok(!aResponse.error,
+      "Should be able to set a breakpoint in a coffee source file on a blank line.");
     ok(aResponse.actualLocation,
-       "Because 3 is empty, we should have an actualLocation");
-    is(aResponse.actualLocation.url, EXAMPLE_URL + "binary_search.coffee",
-       "actualLocation.url should be source mapped to the coffee file");
+      "Because 3 is empty, we should have an actualLocation.");
+    is(aResponse.actualLocation.url, COFFEE_URL,
+      "actualLocation.url should be source mapped to the coffee file.");
     is(aResponse.actualLocation.line, 2,
-       "actualLocation.line should be source mapped back to 2");
-    testHitBreakpoint();
+      "actualLocation.line should be source mapped back to 2.");
+
+    deferred.resolve();
   });
+
+  return deferred.promise;
 }
 
 function testHitBreakpoint() {
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.resume(function (aResponse) {
-    ok(!aResponse.error, "Shouldn't get an error resuming");
-    is(aResponse.type, "resumed", "Type should be 'resumed'");
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.resume(aResponse => {
+    ok(!aResponse.error, "Shouldn't get an error resuming.");
+    is(aResponse.type, "resumed", "Type should be 'resumed'.");
 
-    activeThread.addOneTimeListener("paused", function (aEvent, aPacket) {
+    gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
       is(aPacket.type, "paused",
-         "We should now be paused again");
+        "We should now be paused again.");
       is(aPacket.why.type, "breakpoint",
-         "and the reason we should be paused is because we hit a breakpoint");
+        "and the reason we should be paused is because we hit a breakpoint.");
 
       // Check that we stopped at the right place, by making sure that the
       // environment is in the state that we expect.
       is(aPacket.frame.environment.bindings.variables.start.value, 0,
-         "'start' is 0");
+         "'start' is 0.");
       is(aPacket.frame.environment.bindings.variables.stop.value.type, "undefined",
-         "'stop' hasn't been assigned to yet");
+         "'stop' hasn't been assigned to yet.");
       is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
-         "'pivot' hasn't been assigned to yet");
+         "'pivot' hasn't been assigned to yet.");
 
-      waitForCaretPos(4, testStepping);
+      waitForCaretUpdated(gPanel, 5).then(deferred.resolve);
     });
 
-    // This will cause the breakpoint to be hit, and put us back in the paused
-    // state.
-    executeSoon(function() {
-      gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
-    });
+    // This will cause the breakpoint to be hit, and put us back in the
+    // paused state.
+    gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
   });
+
+  return deferred.promise;
 }
 
 function testStepping() {
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.stepIn(function (aResponse) {
-    ok(!aResponse.error, "Shouldn't get an error resuming");
-    is(aResponse.type, "resumed", "Type should be 'resumed'");
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.stepIn(aResponse => {
+    ok(!aResponse.error, "Shouldn't get an error resuming.");
+    is(aResponse.type, "resumed", "Type should be 'resumed'.");
 
     // After stepping, we will pause again, so listen for that.
-    activeThread.addOneTimeListener("paused", function (aEvent, aPacket) {
+    gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
+      is(aPacket.type, "paused",
+        "We should now be paused again.");
+      is(aPacket.why.type, "resumeLimit",
+        "and the reason we should be paused is because we hit the resume limit.");
 
       // Check that we stopped at the right place, by making sure that the
       // environment is in the state that we expect.
       is(aPacket.frame.environment.bindings.variables.start.value, 0,
-         "'start' is 0");
+         "'start' is 0.");
       is(aPacket.frame.environment.bindings.variables.stop.value, 5,
-         "'stop' hasn't been assigned to yet");
+         "'stop' hasn't been assigned to yet.");
       is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
-         "'pivot' hasn't been assigned to yet");
+         "'pivot' hasn't been assigned to yet.");
 
-      waitForCaretPos(5, closeDebuggerAndFinish);
+      waitForCaretUpdated(gPanel, 6).then(deferred.resolve);
     });
   });
-}
 
-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 + " ");
-    if (++count > 50) {
-      ok(false, "Timed out while polling for the line.");
-      window.clearInterval(intervalID);
-      return closeDebuggerAndFinish();
-    }
-    if (gDebugger.DebuggerView.editor.getCaretPosition().line != number) {
-      return;
-    }
-    // We got the source editor at the expected line, it's safe to callback.
-    window.clearInterval(intervalID);
-    callback();
-  }, 100);
+  return deferred.promise;
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gEditor = null;
+  gSources = null;
 });
rename from browser/devtools/debugger/test/browser_dbg_source_maps-02.js
rename to browser/devtools/debugger/test/browser_dbg_source-maps-02.js
--- a/browser/devtools/debugger/test/browser_dbg_source_maps-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_source-maps-02.js
@@ -1,204 +1,160 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Test that we can toggle between the original and generated sources.
  */
 
-const TAB_URL = EXAMPLE_URL + "binary_search.html";
+const TAB_URL = EXAMPLE_URL + "doc_binary_search.html";
+const JS_URL = EXAMPLE_URL + "code_binary_search.js";
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
-var gPrevPref = null;
-
-function test()
-{
-  let scriptShown = false;
-  let framesAdded = false;
-  let resumed = false;
-  let testStarted = false;
+let gTab, gDebuggee, gPanel, gDebugger;
+let gEditor, gSources, gFrames, gPrefs, gOptions;
 
-  gPrevPref = Services.prefs.getBoolPref(
-    "devtools.debugger.source-maps-enabled");
-  SpecialPowers.pushPrefEnv({"set": [["devtools.debugger.source-maps-enabled", true]]}, () => {
-    debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
-      resumed = true;
-      gTab = aTab;
-      gDebuggee = aDebuggee;
-      gPane = aPane;
-      gDebugger = gPane.panelWin;
+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;
+    gFrames = gDebugger.DebuggerView.StackFrames;
+    gPrefs = gDebugger.Prefs;
+    gOptions = gDebugger.DebuggerView.Options;
 
-      gDebugger.addEventListener("Debugger:SourceShown", function _onSourceShown(aEvent) {
-        gDebugger.removeEventListener("Debugger:SourceShown", _onSourceShown);
-        // Show original sources should be already enabled.
-        is(gPrevPref, true,
-          "The source maps functionality should be enabled by default.");
-        is(gDebugger.Prefs.sourceMapsEnabled, true,
-          "The source maps pref should be true from startup.");
-        is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"),
-           "true", "Source maps should be enabled from startup. ")
-
-        ok(aEvent.detail.url.indexOf(".coffee") != -1,
-           "The debugger should show the source mapped coffee script file.");
-        ok(aEvent.detail.url.indexOf(".js") == -1,
-           "The debugger should not show the generated js script file.");
-        ok(gDebugger.editor.getText().search(/isnt/) != -1,
-           "The debugger's editor should have the coffee script source displayed.");
-        ok(gDebugger.editor.getText().search(/function/) == -1,
-           "The debugger's editor should not have the JS source displayed.");
-
-        testToggleGeneratedSource();
+    waitForSourceShown(gPanel, ".coffee")
+      .then(testToggleGeneratedSource)
+      .then(testSetBreakpoint)
+      .then(testHitBreakpoint)
+      .then(testToggleOnPause)
+      .then(testResume)
+      .then(() => closeDebuggerAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
       });
-    });
   });
 }
 
 function testToggleGeneratedSource() {
-  gDebugger.addEventListener("Debugger:SourceShown", function _onSourceShown(aEvent) {
-    gDebugger.removeEventListener("Debugger:SourceShown", _onSourceShown);
-
-    is(gDebugger.Prefs.sourceMapsEnabled, false,
+  let finished = waitForSourceShown(gPanel, ".js").then(() => {
+    is(gPrefs.sourceMapsEnabled, false,
       "The source maps pref should have been set to false.");
-    is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"),
-       "false", "Source maps should be enabled from startup. ")
+    is(gOptions._showOriginalSourceItem.getAttribute("checked"), "false",
+      "Source maps should now be disabled.")
 
-    ok(aEvent.detail.url.indexOf(".coffee") == -1,
-       "The debugger should not show the source mapped coffee script file.");
-    ok(aEvent.detail.url.indexOf(".js") != -1,
-       "The debugger should show the generated js script file.");
-    ok(gDebugger.editor.getText().search(/isnt/) == -1,
-       "The debugger's editor should have the coffee script source displayed.");
-      ok(gDebugger.editor.getText().search(/function/) != -1,
-         "The debugger's editor should not have the JS source displayed.");
+    is(gSources.selectedValue.indexOf(".coffee"), -1,
+      "The debugger should not show the source mapped coffee source file.");
+    isnot(gSources.selectedValue.indexOf(".js"), -1,
+      "The debugger should show the generated js source file.");
 
-    testSetBreakpoint();
+    is(gEditor.getText().indexOf("isnt"), -1,
+      "The debugger's editor should not have the coffee source source displayed.");
+    is(gEditor.getText().indexOf("function"), 36,
+      "The debugger's editor should have the JS source displayed.");
   });
 
-  // Disable source maps.
-  gDebugger.DebuggerView.Options._showOriginalSourceItem.setAttribute("checked",
-                                                                      "false");
-  gDebugger.DebuggerView.Options._toggleShowOriginalSource();
-  gDebugger.DebuggerView.Options._onPopupHidden();
+  gOptions._showOriginalSourceItem.setAttribute("checked", "false");
+  gOptions._toggleShowOriginalSource();
+  gOptions._onPopupHidden();
+
+  return finished;
 }
 
 function testSetBreakpoint() {
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.setBreakpoint({
-    url: EXAMPLE_URL + "binary_search.js",
-    line: 7
-  }, function (aResponse, bpClient) {
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 7 }, aResponse => {
     ok(!aResponse.error,
-       "Should be able to set a breakpoint in a JavaScript file.");
-    testHitBreakpoint();
+      "Should be able to set a breakpoint in a js file.");
+
+    deferred.resolve();
   });
+
+  return deferred.promise;
 }
 
 function testHitBreakpoint() {
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.resume(function (aResponse) {
-    ok(!aResponse.error, "Shouldn't get an error resuming");
-    is(aResponse.type, "resumed", "Type should be 'resumed'");
+  let deferred = promise.defer();
 
-    activeThread.addOneTimeListener("framesadded", function (aEvent, aPacket) {
+  gDebugger.gThreadClient.resume(aResponse => {
+    ok(!aResponse.error, "Shouldn't get an error resuming.");
+    is(aResponse.type, "resumed", "Type should be 'resumed'.");
+
+    waitForCaretAndScopes(gPanel, 7).then(() => {
       // Make sure that we have JavaScript stack frames.
-      let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-      let childNodes = frames.childNodes;
+      is(gFrames.itemCount, 1,
+        "Should have only one frame.");
+      is(gFrames.getItemAtIndex(0).description.indexOf(".coffee"), -1,
+        "First frame should not be a coffee source frame.");
+      isnot(gFrames.getItemAtIndex(0).description.indexOf(".js"), -1,
+        "First frame should be a JS frame.");
 
-      is(frames.querySelectorAll(".dbg-stackframe").length, 1,
-        "Correct number of frames.");
-      ok(frames.querySelector("#stackframe-0 .dbg-stackframe-details")
-         .getAttribute("value").search(/js/),
-         "First frame should be a JS frame.");
-
-      waitForCaretPos(6, testToggleOnPause);
+      deferred.resolve();
     });
 
-    // This will cause the breakpoint to be hit, and put us back in the paused
-    // stated.
-    executeSoon(function() {
-      gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
-    });
+    // This will cause the breakpoint to be hit, and put us back in the
+    // paused state.
+    gDebuggee.binary_search([0, 2, 3, 5, 7, 10], 5);
   });
+
+  return deferred.promise;
 }
 
 function testToggleOnPause() {
-  gDebugger.addEventListener("Debugger:SourceShown", function _onSourceShown(aEvent) {
-    gDebugger.removeEventListener("Debugger:SourceShown", _onSourceShown);
+  let finished = waitForSourceAndCaretAndScopes(gPanel, ".coffee", 5).then(() => {
+    is(gPrefs.sourceMapsEnabled, true,
+      "The source maps pref should have been set to true.");
+    is(gOptions._showOriginalSourceItem.getAttribute("checked"), "true",
+      "Source maps should now be enabled.")
 
-    is(gDebugger.Prefs.sourceMapsEnabled, true,
-      "The source maps pref should have been set to true.");
-    is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"),
-      "true", "Source maps should be enabled. ")
+    isnot(gSources.selectedValue.indexOf(".coffee"), -1,
+      "The debugger should show the source mapped coffee source file.");
+    is(gSources.selectedValue.indexOf(".js"), -1,
+      "The debugger should not show the generated js source file.");
 
-    ok(aEvent.detail.url.indexOf(".coffee") != -1,
-       "The debugger should show the source mapped coffee script file.");
-    ok(aEvent.detail.url.indexOf(".js") == -1,
-       "The debugger should not show the generated js script file.");
-    ok(gDebugger.editor.getText().search(/isnt/) != -1,
-       "The debugger's editor should not have the coffee script source displayed.");
-    ok(gDebugger.editor.getText().search(/function/) == -1,
-       "The debugger's editor should have the JS source displayed.");
+    is(gEditor.getText().indexOf("isnt"), 218,
+      "The debugger's editor should have the coffee source source displayed.");
+    is(gEditor.getText().indexOf("function"), -1,
+      "The debugger's editor should not have the JS source displayed.");
 
-    // Make sure that we have coffee script stack frames.
-    let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-    let childNodes = frames.childNodes;
-
-    is(frames.querySelectorAll(".dbg-stackframe").length, 1,
-      "Correct number of frames.");
-    ok(frames.querySelector("#stackframe-0 .dbg-stackframe-details")
-       .getAttribute("value").search(/coffee/),
-       "First frame should be a coffee script frame.");
-
-    waitForCaretPos(4, resumeAndFinish);
+    // Make sure that we have coffee source stack frames.
+    is(gFrames.itemCount, 1,
+      "Should have only one frame.");
+    is(gFrames.getItemAtIndex(0).description.indexOf(".js"), -1,
+      "First frame should not be a JS frame.");
+    isnot(gFrames.getItemAtIndex(0).description.indexOf(".coffee"), -1,
+      "First frame should be a coffee source frame.");
   });
 
-  // Enable source maps.
-  gDebugger.DebuggerView.Options._showOriginalSourceItem.setAttribute("checked",
-                                                                      "true");
-  gDebugger.DebuggerView.Options._toggleShowOriginalSource();
-  gDebugger.DebuggerView.Options._onPopupHidden();
-}
+  gOptions._showOriginalSourceItem.setAttribute("checked", "true");
+  gOptions._toggleShowOriginalSource();
+  gOptions._onPopupHidden();
 
-function resumeAndFinish()
-{
-  let { activeThread } = gDebugger.DebuggerController;
-  activeThread.resume(function (aResponse) {
-    ok(!aResponse.error, "Shouldn't get an error resuming");
-    is(aResponse.type, "resumed", "Type should be 'resumed'");
-
-    closeDebuggerAndFinish();
-  });
+  return finished;
 }
 
-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 + " ");
-    if (++count > 50) {
-      ok(false, "Timed out while polling for the line.");
-      window.clearInterval(intervalID);
-      return closeDebuggerAndFinish();
-    }
-    if (gDebugger.DebuggerView.editor.getCaretPosition().line != number) {
-      return;
-    }
-    is(gDebugger.DebuggerView.editor.getCaretPosition().line, number,
-       "The right line is focused.")
-    // We got the source editor at the expected line, it's safe to callback.
-    window.clearInterval(intervalID);
-    callback();
-  }, 100);
+function testResume() {
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.resume(aResponse => {
+    ok(!aResponse.error, "Shouldn't get an error resuming.");
+    is(aResponse.type, "resumed", "Type should be 'resumed'.");
+
+    deferred.resolve();
+  });
+
+  return deferred.promise;
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
-  gPrevPref = null;
+  gEditor = null;
+  gSources = null;
+  gFrames = null;
+  gPrefs = null;
+  gOptions = null;
 });
rename from browser/devtools/debugger/test/browser_dbg_source_maps-03.js
rename to browser/devtools/debugger/test/browser_dbg_source-maps-03.js
--- a/browser/devtools/debugger/test/browser_dbg_source_maps-03.js
+++ b/browser/devtools/debugger/test/browser_dbg_source-maps-03.js
@@ -1,117 +1,98 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Test that we can debug minified javascript with source maps.
  */
 
-const TAB_URL = EXAMPLE_URL + "minified.html";
+const TAB_URL = EXAMPLE_URL + "doc_minified.html";
+const JS_URL = EXAMPLE_URL + "code_math.js";
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
-var gClient = null;
-
-let sourceShown = false;
-let hitDebuggerStatement = false;
+let gTab, gDebuggee, gPanel, gDebugger;
+let gEditor, gSources, gFrames;
 
-function test()
-{
-  SpecialPowers.pushPrefEnv({"set": [["devtools.debugger.source-maps-enabled", true]]}, () => {
-    debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
-      gTab = aTab;
-      gDebuggee = aDebuggee;
-      gPane = aPane;
-      gDebugger = gPane.panelWin;
-      gClient = gDebugger.DebuggerController.client;
+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;
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-      testMinJSAndSourceMaps();
-    });
+    waitForSourceShown(gPanel, JS_URL)
+      .then(checkInitialSource)
+      .then(testSetBreakpoint)
+      .then(testHitBreakpoint)
+      .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
   });
 }
 
-function testMinJSAndSourceMaps() {
-  gDebugger.addEventListener("Debugger:SourceShown", function _onSourceShown(aEvent) {
-    gDebugger.removeEventListener("Debugger:SourceShown", _onSourceShown);
-    sourceShown = true;
-
-    ok(aEvent.detail.url.indexOf("math.min.js") == -1,
-       "The debugger should not show the minified js");
-    ok(aEvent.detail.url.indexOf("math.js") != -1,
-       "The debugger should show the original js");
-    ok(gDebugger.editor.getText().split("\n").length > 10,
-       "The debugger's editor should have the original source displayed, " +
-       "not the whitespace stripped minified version");
-
-    startTest();
-  });
+function checkInitialSource() {
+  isnot(gSources.selectedValue.indexOf(".js"), -1,
+    "The debugger should not show the minified js file.");
+  is(gSources.selectedValue.indexOf(".min.js"), -1,
+    "The debugger should show the original js file.");
+  is(gEditor.getText().split("\n").length, 46,
+    "The debugger's editor should have the original source displayed, " +
+    "not the whitespace stripped minified version.");
+}
 
-  gClient.addListener("paused", function _onPaused(aEvent, aPacket) {
-    if (aPacket.type === "paused" && aPacket.why.type === "breakpoint") {
-      gClient.removeListener("paused", _onPaused);
-      hitDebuggerStatement = true;
-
-      startTest();
-    }
-  });
-
-  gClient.activeThread.interrupt(function (aResponse) {
-    ok(!aResponse.error, "Shouldn't be an error interrupting.");
+function testSetBreakpoint() {
+  let deferred = promise.defer();
 
-    gClient.activeThread.setBreakpoint({
-      url: EXAMPLE_URL + "math.js",
-      line: 30,
-      column: 10
-    }, function (aResponse) {
-      ok(!aResponse.error, "Shouldn't be an error setting a breakpoint.");
-      ok(!aResponse.actualLocation, "Shouldn't be an actualLocation.");
+  gDebugger.gThreadClient.interrupt(aResponse => {
+    gDebugger.gThreadClient.setBreakpoint({ url: JS_URL, line: 30, column: 10 }, aResponse => {
+      ok(!aResponse.error,
+        "Should be able to set a breakpoint in a js file.");
+      ok(!aResponse.actualLocation,
+        "Should be able to set a breakpoint on line 30 and column 10.");
 
-      gClient.activeThread.resume(function (aResponse) {
-        ok(!aResponse.error, "There shouldn't be an error resuming.");
-        gDebuggee.arithmetic();
-      });
+      deferred.resolve();
     });
   });
-}
 
-function startTest() {
-  if (sourceShown && hitDebuggerStatement) {
-    testCaretPosition();
-  }
-}
-
-function testCaretPosition() {
-  waitForCaretPos(29, function () {
-    closeDebuggerAndFinish();
-  });
+  return deferred.promise;
 }
 
-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 + ", caret at " + gDebugger.DebuggerView.editor.getCaretPosition().line);
-    if (++count > 50) {
-      ok(false, "Timed out while polling for the line.");
-      window.clearInterval(intervalID);
-      return closeDebuggerAndFinish();
-    }
-    if (gDebugger.DebuggerView.editor.getCaretPosition().line != number) {
-      return;
-    }
-    // We got the source editor at the expected line, it's safe to callback.
-    window.clearInterval(intervalID);
-    callback();
-  }, 100);
+function testHitBreakpoint() {
+  let deferred = promise.defer();
+
+  gDebugger.gThreadClient.resume(aResponse => {
+    ok(!aResponse.error, "Shouldn't get an error resuming.");
+    is(aResponse.type, "resumed", "Type should be 'resumed'.");
+
+    waitForCaretAndScopes(gPanel, 30).then(() => {
+      // Make sure that we have the right stack frames.
+      is(gFrames.itemCount, 9,
+        "Should have nine frames.");
+      is(gFrames.getItemAtIndex(0).description.indexOf(".min.js"), -1,
+        "First frame should not be a minified JS frame.");
+      isnot(gFrames.getItemAtIndex(0).description.indexOf(".js"), -1,
+        "First frame should be a JS frame.");
+
+      deferred.resolve();
+    });
+
+    // This will cause the breakpoint to be hit, and put us back in the
+    // paused state.
+    gDebuggee.arithmetic();
+  });
+
+  return deferred.promise;
 }
 
+
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
-  gClient = null;
+  gEditor = null;
+  gSources = null;
+  gFrames = null;
 });