Bug 876277 - Cleanup debugger stackframes tests, r=past
authorVictor Porof <vporof@mozilla.com>
Fri, 13 Sep 2013 16:23:18 +0300
changeset 147087 77b93e70c30a7a1a4e9d8531bae957015ef61835
parent 147086 4559ea542aa9225cfd29f67cb553609a5d8b045b
child 147088 39471a71749473661a0093050cf993fc2c962125
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerspast
bugs876277
milestone26.0a1
Bug 876277 - Cleanup debugger stackframes tests, r=past
browser/devtools/debugger/test/browser_dbg_select-line.js
browser/devtools/debugger/test/browser_dbg_stack-01.js
browser/devtools/debugger/test/browser_dbg_stack-02.js
browser/devtools/debugger/test/browser_dbg_stack-03.js
browser/devtools/debugger/test/browser_dbg_stack-04.js
browser/devtools/debugger/test/browser_dbg_stack-05.js
browser/devtools/debugger/test/browser_dbg_stack-06.js
--- a/browser/devtools/debugger/test/browser_dbg_stack-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-01.js
@@ -1,54 +1,41 @@
-/* vim:set ts=2 sw=2 sts=2 et: */
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that stackframes are added when debugger is paused.
  */
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
+const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gFrames;
 
 function test() {
-  debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
-    gPane = aPane;
-    gDebugger = gPane.panelWin;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-    testSimpleCall();
+    waitForSourceAndCaretAndScopes(gPanel, ".html", 14).then(performTest);
+    gDebuggee.simpleCall();
   });
 }
 
-function testSimpleCall() {
-  gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-    Services.tm.currentThread.dispatch({ run: function() {
-
-      let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-      let childNodes = frames.childNodes;
-
-      is(gDebugger.DebuggerController.activeThread.state, "paused",
-        "Should only be getting stack frames while paused.");
+function performTest() {
+  is(gDebugger.gThreadClient.state, "paused",
+    "Should only be getting stack frames while paused.");
+  is(gFrames.itemCount, 1,
+    "Should have only one frame.");
 
-      is(frames.querySelectorAll(".dbg-stackframe").length, 1,
-        "Should have only one frame.");
-
-      is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
-        "All children should be frames.");
-
-      gDebugger.DebuggerController.activeThread.resume(function() {
-        closeDebuggerAndFinish();
-      });
-    }}, 0);
-  });
-
-  gDebuggee.simpleCall();
+  resumeDebuggerThenCloseAndFinish(gPanel);
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gFrames = null;
 });
--- a/browser/devtools/debugger/test/browser_dbg_stack-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-02.js
@@ -1,86 +1,83 @@
-/* vim:set ts=2 sw=2 sts=2 et: */
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that stackframes are added when debugger is paused in eval calls.
  */
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
+const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gFrames;
 
 function test() {
-  debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
-    gPane = aPane;
-    gDebugger = gPane.panelWin;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-    testEvalCall();
+    waitForSourceAndCaretAndScopes(gPanel, ".html", 18).then(performTest);
+    gDebuggee.evalCall();
   });
 }
 
-function testEvalCall() {
-  gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-    Services.tm.currentThread.dispatch({ run: function() {
+function performTest() {
+  is(gDebugger.gThreadClient.state, "paused",
+    "Should only be getting stack frames while paused.");
+  is(gFrames.itemCount, 2,
+    "Should have two frames.");
 
-      let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-      let childNodes = frames.childNodes;
-
-      is(gDebugger.DebuggerController.activeThread.state, "paused",
-        "Should only be getting stack frames while paused.");
-
-      is(frames.querySelectorAll(".dbg-stackframe").length, 2,
-        "Should have two frames.");
+  is(gFrames.getItemAtIndex(0).value,
+    "evalCall", "Oldest frame name should be correct.");
+  is(gFrames.getItemAtIndex(0).description,
+    TAB_URL, "Oldest frame url should be correct.");
 
-      is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
-        "All children should be frames.");
-
-      is(frames.querySelector("#stackframe-0 .dbg-stackframe-title").getAttribute("value"),
-        "(eval)", "Frame name should be (eval)");
+  is(gFrames.getItemAtIndex(1).value,
+    "(eval)", "Newest frame name should be correct.");
+  is(gFrames.getItemAtIndex(1).description,
+    TAB_URL, "Newest frame url should be correct.");
 
-      ok(frames.querySelector("#stackframe-0").parentNode.hasAttribute("checked"),
-        "First frame should be selected by default.");
+  is(gFrames.selectedIndex, 1,
+    "Newest frame should be selected by default.");
+  isnot(gFrames.selectedIndex, 0,
+    "Oldest frame should not be selected.");
 
-      ok(!frames.querySelector("#stackframe-1").parentNode.hasAttribute("checked"),
-        "Second frame should not be selected.");
-
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    gFrames.getItemAtIndex(0).target,
+    gDebugger);
 
-      EventUtils.sendMouseEvent({ type: "mousedown" },
-        frames.querySelector("#stackframe-1"),
-        gDebugger);
-
-      ok(!frames.querySelector("#stackframe-0").parentNode.hasAttribute("checked"),
-         "First frame should not be selected after click.");
+  isnot(gFrames.selectedIndex, 1,
+    "Newest frame should not be selected after click.");
+  is(gFrames.selectedIndex, 0,
+    "Oldest frame should be selected after click.");
 
-      ok(frames.querySelector("#stackframe-1").parentNode.hasAttribute("checked"),
-         "Second frame should be selected after click.");
-
-
-      EventUtils.sendMouseEvent({ type: "mousedown" },
-        frames.querySelector("#stackframe-0 .dbg-stackframe-title"),
-        gDebugger);
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    gFrames.getItemAtIndex(1).target.querySelector(".dbg-stackframe-title"),
+    gDebugger);
 
-      ok(frames.querySelector("#stackframe-0").parentNode.hasAttribute("checked"),
-         "First frame should be selected after click inside the first frame.");
-
-      ok(!frames.querySelector("#stackframe-1").parentNode.hasAttribute("checked"),
-         "Second frame should not be selected after click inside the first frame.");
-
+  is(gFrames.selectedIndex, 1,
+    "Newest frame should be selected after click inside the newest frame.");
+  isnot(gFrames.selectedIndex, 0,
+    "Oldest frame should not be selected after click inside the newest frame.");
 
-      gDebugger.DebuggerController.activeThread.resume(function() {
-        closeDebuggerAndFinish();
-      });
-    }}, 0);
-  });
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    gFrames.getItemAtIndex(0).target.querySelector(".dbg-stackframe-details"),
+    gDebugger);
 
-  gDebuggee.evalCall();
+  isnot(gFrames.selectedIndex, 1,
+    "Newest frame should not be selected after click inside the oldest frame.");
+  is(gFrames.selectedIndex, 0,
+    "Oldest frame should be selected after click inside the oldest frame.");
+
+  resumeDebuggerThenCloseAndFinish(gPanel);
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gFrames = null;
 });
--- a/browser/devtools/debugger/test/browser_dbg_stack-03.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-03.js
@@ -1,71 +1,60 @@
-/* vim:set ts=2 sw=2 sts=2 et: */
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that stackframes are scrollable.
  */
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
+const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gFrames;
 
 function test() {
-  debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
-    gPane = aPane;
-    gDebugger = gPane.panelWin;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-    testRecurse();
+    waitForSourceAndCaretAndScopes(gPanel, ".html", 26).then(performTest);
+
+    gDebuggee.gRecurseLimit = (gDebugger.gCallStackPageSize * 2) + 1;
+    gDebuggee.recurse();
   });
 }
 
-function testRecurse() {
-  gDebuggee.gRecurseLimit = (gDebugger.gCallStackPageSize * 2) + 1;
-
-  gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-    Services.tm.currentThread.dispatch({ run: function() {
+function performTest() {
+  is(gDebugger.gThreadClient.state, "paused",
+    "Should only be getting stack frames while paused.");
+  is(gFrames.itemCount, gDebugger.gCallStackPageSize,
+    "Should have only the max limit of frames.");
 
-      let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-      let pageSize = gDebugger.gCallStackPageSize;
-      let recurseLimit = gDebuggee.gRecurseLimit;
-      let childNodes = frames.childNodes;
-
-      is(frames.querySelectorAll(".dbg-stackframe").length, pageSize,
-        "Should have the max limit of frames.");
-
-      is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
-        "All children should be frames.");
-
+  gDebugger.gThreadClient.addOneTimeListener("framesadded", () => {
+    is(gFrames.itemCount, gDebugger.gCallStackPageSize * 2,
+      "Should now have twice the max limit of frames.");
 
-      gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-        is(frames.querySelectorAll(".dbg-stackframe").length, pageSize * 2,
-          "Should now have twice the max limit of frames.");
-
-        gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-          is(frames.querySelectorAll(".dbg-stackframe").length, recurseLimit,
-            "Should have reached the recurse limit.");
+    gDebugger.gThreadClient.addOneTimeListener("framesadded", () => {
+      is(gFrames.itemCount, gDebuggee.gRecurseLimit,
+        "Should have reached the recurse limit.");
 
-          gDebugger.DebuggerController.activeThread.resume(function() {
-            window.clearInterval(scrollingInterval);
-            closeDebuggerAndFinish();
-          });
-        });
+      gDebugger.gThreadClient.resume(() => {
+        window.clearInterval(scrollingIntervalId);
+        closeDebuggerAndFinish(gPanel);
       });
-
-      let scrollingInterval = window.setInterval(function() {
-        frames.scrollByIndex(-1);
-      }, 100);
-    }}, 0);
+    });
   });
 
-  gDebuggee.recurse();
+  let scrollingIntervalId = window.setInterval(() => {
+    gFrames.widget._list.scrollByIndex(-1);
+  }, 100);
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gFrames = null;
 });
--- a/browser/devtools/debugger/test/browser_dbg_stack-04.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-04.js
@@ -1,65 +1,48 @@
-/* vim:set ts=2 sw=2 sts=2 et: */
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that stackframes are cleared after resume.
  */
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
+const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
+
+let gTab, gDebuggee, gPanel, gDebugger;
+let gFrames;
 
 function test() {
-  debug_tab_pane(STACK_URL, function(aTab, aDebuggee, aPane) {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
-    gPane = aPane;
-    gDebugger = gPane.panelWin;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-    testEvalCallResume();
+    waitForSourceAndCaretAndScopes(gPanel, ".html", 18).then(performTest);
+    gDebuggee.evalCall();
   });
 }
 
-function testEvalCallResume() {
-  gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-    Services.tm.currentThread.dispatch({ run: function() {
-
-      let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-      let childNodes = frames.childNodes;
-
-      is(gDebugger.DebuggerController.activeThread.state, "paused",
-        "Should only be getting stack frames while paused.");
-
-      is(frames.querySelectorAll(".dbg-stackframe").length, 2,
-        "Should have two frames.");
-
-      is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
-        "All children should be frames.");
-
+function performTest() {
+  is(gDebugger.gThreadClient.state, "paused",
+    "Should only be getting stack frames while paused.");
+  is(gFrames.itemCount, 2,
+    "Should have two frames.");
 
-      gDebugger.addEventListener("Debugger:AfterFramesCleared", function listener() {
-        gDebugger.removeEventListener("Debugger:AfterFramesCleared", listener, true);
-
-        is(frames.querySelectorAll(".dbg-stackframe").length, 0,
-          "Should have no frames after resume");
-
-        is(childNodes.length, 0,
-          "Should only have no children.");
+  gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => {
+    is(gFrames.itemCount, 0,
+      "Should have no frames after resume.");
 
-        closeDebuggerAndFinish();
-      }, true);
+    closeDebuggerAndFinish(gPanel);
+  }, true);
 
-      gDebugger.DebuggerController.activeThread.resume();
-    }}, 0);
-  });
-
-  gDebuggee.evalCall();
+  gDebugger.gThreadClient.resume();
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gFrames = null;
 });
--- a/browser/devtools/debugger/test/browser_dbg_stack-05.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-05.js
@@ -1,114 +1,154 @@
-/* vim:set ts=2 sw=2 sts=2 et: */
-/*
- * Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that switching between stack frames properly sets the current debugger
+ * location in the source editor.
  */
 
-// Test that switching between stack frames properly sets the current debugger
-// location in the source editor.
-
-const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
 
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
+let gTab, gDebuggee, gPanel, gDebugger;
+let gEditor, gSources, gFrames;
 
 function test() {
-  let scriptShown = false;
-  let framesAdded = false;
-
-  debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
-    gPane = aPane;
-    gDebugger = gPane.panelWin;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gEditor = gDebugger.DebuggerView.editor;
+    gSources = gDebugger.DebuggerView.Sources;
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-    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();
-    });
+    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6)
+      .then(initialChecks)
+      .then(testNewestTwoFrames)
+      .then(testOldestTwoFrames)
+      .then(testAfterResume)
+      .then(() => closeDebuggerAndFinish(gPanel))
+      .then(null, aError => {
+        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
+      });
 
     gDebuggee.firstCall();
   });
+}
 
-  function runTest()
-  {
-    if (scriptShown && framesAdded) {
-      Services.tm.currentThread.dispatch({ run: testRecurse }, 0);
-    }
-  }
+function initialChecks() {
+  is(gDebugger.gThreadClient.state, "paused",
+    "Should only be getting stack frames while paused.");
+  is(gFrames.itemCount, 4,
+    "Should have four frames.");
 }
 
-function testRecurse()
-{
-  let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-  let childNodes = frames.childNodes;
+function testNewestTwoFrames() {
+  let deferred = promise.defer();
+
+  is(gFrames.selectedIndex, 3,
+    "Newest frame should be selected by default.");
+  is(gSources.selectedIndex, 1,
+    "The second source is selected in the widget.");
+  ok(isCaretPos(gPanel, 6),
+    "Editor caret location is correct.");
+
+  // The editor's debug location takes a tick to update.
+  executeSoon(() => {
+    is(gEditor.getDebugLocation(), 5,
+      "Editor debug location is correct.");
 
-  is(frames.querySelectorAll(".dbg-stackframe").length, 4,
-    "Correct number of frames.");
+    EventUtils.sendMouseEvent({ type: "mousedown" },
+      gFrames.getItemAtIndex(2).target,
+      gDebugger);
+
+    is(gFrames.selectedIndex, 2,
+      "Third frame should be selected after click.");
+    is(gSources.selectedIndex, 1,
+      "The second source is still selected in the widget.");
+    ok(isCaretPos(gPanel, 6),
+      "Editor caret location is correct.");
+
+    // The editor's debug location takes a tick to update.
+    executeSoon(() => {
+      is(gEditor.getDebugLocation(), 5,
+        "Editor debug location is correct.");
+
+      deferred.resolve();
+    });
+  });
 
-  is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
-    "All children should be frames.");
+  return deferred.promise;
+}
+
+function testOldestTwoFrames() {
+  let deferred = promise.defer();
 
-  ok(frames.querySelector("#stackframe-0").parentNode.hasAttribute("checked"),
-    "First frame should be selected by default.");
+  waitForSourceAndCaret(gPanel, "-01.js", 5).then(() => {
+    is(gFrames.selectedIndex, 1,
+      "Second frame should be selected after click.");
+    is(gSources.selectedIndex, 0,
+      "The first source is now selected in the widget.");
+    ok(isCaretPos(gPanel, 5),
+      "Editor caret location is correct.");
+
+    // The editor's debug location takes a tick to update.
+    executeSoon(() => {
+      is(gEditor.getDebugLocation(), 4,
+        "Editor debug location is correct.");
 
-  ok(!frames.querySelector("#stackframe-2").parentNode.hasAttribute("checked"),
-    "Third frame should not be selected.");
+      EventUtils.sendMouseEvent({ type: "mousedown" },
+        gFrames.getItemAtIndex(0).target,
+        gDebugger);
 
-  is(gDebugger.editor.getDebugLocation(), 5,
-     "editor debugger location is correct.");
+      is(gFrames.selectedIndex, 0,
+        "Oldest frame should be selected after click.");
+      is(gSources.selectedIndex, 0,
+        "The first source is still selected in the widget.");
+      ok(isCaretPos(gPanel, 5),
+        "Editor caret location is correct.");
 
+      // The editor's debug location takes a tick to update.
+      executeSoon(() => {
+        is(gEditor.getDebugLocation(), 4,
+          "Editor debug location is correct.");
+
+        deferred.resolve();
+      });
+    });
+  });
 
   EventUtils.sendMouseEvent({ type: "mousedown" },
-    frames.querySelector("#stackframe-2"),
+    gFrames.getItemAtIndex(1).target,
     gDebugger);
 
-  ok(!frames.querySelector("#stackframe-0").parentNode.hasAttribute("checked"),
-     "First frame should not be selected after click.");
-
-  ok(frames.querySelector("#stackframe-2").parentNode.hasAttribute("checked"),
-     "Third frame should be selected after click.");
+  return deferred.promise;
+}
 
-  is(gDebugger.editor.getDebugLocation(), 4,
-     "editor debugger location is correct after click.");
-
-
-  EventUtils.sendMouseEvent({ type: "mousedown" },
-    frames.querySelector("#stackframe-0 .dbg-stackframe-title"),
-    gDebugger);
+function testAfterResume() {
+  let deferred = promise.defer();
 
-  ok(frames.querySelector("#stackframe-0").parentNode.hasAttribute("checked"),
-     "First frame should be selected after click inside the first frame.");
-
-  ok(!frames.querySelector("#stackframe-2").parentNode.hasAttribute("checked"),
-     "Third frame should not be selected after click inside the first frame.");
+  gDebugger.once(gDebugger.EVENTS.AFTER_FRAMES_CLEARED, () => {
+    is(gFrames.itemCount, 0,
+      "Should have no frames after resume.");
+    ok(isCaretPos(gPanel, 5),
+      "Editor caret location is correct after resume.");
+    is(gEditor.getDebugLocation(), -1,
+      "Editor debug location is correct after resume.");
 
-  is(gDebugger.editor.getDebugLocation(), 5,
-     "editor debugger location is correct (frame 0 again).");
+    deferred.resolve();
+  }, true);
 
-  gDebugger.DebuggerController.activeThread.resume(function() {
-    is(gDebugger.editor.getDebugLocation(), -1,
-       "editor debugger location is correct after resume.");
+  gDebugger.gThreadClient.resume();
 
-    closeDebuggerAndFinish();
-  });
+  return deferred.promise;
 }
 
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gEditor = null;
+  gFrames = null;
 });
+
rename from browser/devtools/debugger/test/browser_dbg_select-line.js
rename to browser/devtools/debugger/test/browser_dbg_stack-06.js
--- a/browser/devtools/debugger/test/browser_dbg_select-line.js
+++ b/browser/devtools/debugger/test/browser_dbg_stack-06.js
@@ -1,122 +1,65 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
- * Make sure that selecting a stack frame loads the right script in the editor
+ * Make sure that selecting a stack frame loads the right source in the editor
  * pane and highlights the proper line.
  */
 
-const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching.html";
-
-var gPane = null;
-var gTab = null;
-var gDebuggee = null;
-var gDebugger = null;
-var gSources = null;
+const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
 
-function test()
-{
-  let scriptShown = false;
-  let framesAdded = false;
-  let testStarted = false;
-  let resumed = false;
+let gTab, gDebuggee, gPanel, gDebugger;
+let gEditor, gSources, gFrames;
 
-  debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) {
+function test() {
+  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
     gTab = aTab;
     gDebuggee = aDebuggee;
-    gPane = aPane;
-    gDebugger = gPane.panelWin;
+    gPanel = aPanel;
+    gDebugger = gPanel.panelWin;
+    gEditor = gDebugger.DebuggerView.editor;
     gSources = gDebugger.DebuggerView.Sources;
-    resumed = true;
-
-    gDebugger.addEventListener("Debugger:SourceShown", onScriptShown);
-
-    gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() {
-      framesAdded = true;
-      executeSoon(startTest);
-    });
-
-    executeSoon(function() {
-      gDebuggee.firstCall();
-    });
-  });
-
-  function onScriptShown(aEvent) {
-    scriptShown = aEvent.detail.url.indexOf("-02.js") != -1;
-    executeSoon(startTest);
-  }
-
-  function startTest()
-  {
-    if (scriptShown && framesAdded && resumed && !testStarted) {
-      gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown);
-      testStarted = true;
-      Services.tm.currentThread.dispatch({ run: testSelectLine }, 0);
-    }
-  }
-}
-
-function testSelectLine() {
-  is(gDebugger.DebuggerController.activeThread.state, "paused",
-    "Should only be getting stack frames while paused.");
-
-  is(gSources.itemCount, 2, "Found the expected number of scripts.");
-
-  ok(gDebugger.editor.getText().search(/debugger/) != -1,
-    "The correct script was loaded initially.");
+    gFrames = gDebugger.DebuggerView.StackFrames;
 
-  // Yield control back to the event loop so that the debugger has a
-  // chance to highlight the proper line.
-  executeSoon(function() {
-    // getCaretPosition is 0-based.
-    is(gDebugger.editor.getCaretPosition().line, 5,
-       "The correct line is selected.");
-
-    gDebugger.editor.addEventListener(SourceEditor.EVENTS.TEXT_CHANGED, function onChange() {
-      // Wait for the actual text to be shown.
-      if (gDebugger.editor.getText() == gDebugger.L10N.getStr("loadingText")) {
-        return;
-      }
-      // The requested source text has been shown, remove the event listener.
-      gDebugger.editor.removeEventListener(SourceEditor.EVENTS.TEXT_CHANGED, onChange);
-
-      ok(gDebugger.editor.getText().search(/debugger/) == -1,
-        "The second script is no longer displayed.");
-
-      ok(gDebugger.editor.getText().search(/firstCall/) != -1,
-        "The first script is displayed.");
-
-      // Yield control back to the event loop so that the debugger has a
-      // chance to highlight the proper line.
-      executeSoon(function(){
-        // getCaretPosition is 0-based.
-        is(gDebugger.editor.getCaretPosition().line, 4,
-           "The correct line is selected.");
-
-        closeDebuggerAndFinish();
-      });
-    });
-
-    let frames = gDebugger.DebuggerView.StackFrames.widget._list;
-    let childNodes = frames.childNodes;
-
-    is(frames.querySelectorAll(".dbg-stackframe").length, 4,
-      "Should have two frames.");
-
-    is(childNodes.length, frames.querySelectorAll(".dbg-stackframe").length,
-      "All children should be frames.");
-
-    EventUtils.sendMouseEvent({ type: "mousedown" },
-      frames.querySelector("#stackframe-3"),
-      gDebugger);
+    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6).then(performTest);
+    gDebuggee.firstCall();
   });
 }
 
+function performTest() {
+  is(gFrames.selectedIndex, 3,
+    "Newest frame should be selected by default.");
+  is(gSources.selectedIndex, 1,
+    "The second source is selected in the widget.");
+  is(gEditor.getText().search(/firstCall/), -1,
+    "The first source is not displayed.");
+  is(gEditor.getText().search(/debugger/), 172,
+    "The second source is displayed.")
+
+  waitForSourceAndCaret(gPanel, "-01.js", 6).then(() => {
+    is(gFrames.selectedIndex, 0,
+      "Oldest frame should be selected after click.");
+    is(gSources.selectedIndex, 0,
+      "The first source is now selected in the widget.");
+    is(gEditor.getText().search(/firstCall/), 118,
+      "The first source is displayed.");
+    is(gEditor.getText().search(/debugger/), -1,
+      "The second source is not displayed.");
+
+    resumeDebuggerThenCloseAndFinish(gPanel);
+  });
+
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    gDebugger.document.querySelector("#stackframe-3"),
+    gDebugger);
+}
+
 registerCleanupFunction(function() {
-  removeTab(gTab);
-  gPane = null;
   gTab = null;
   gDebuggee = null;
+  gPanel = null;
   gDebugger = null;
+  gEditor = null;
   gSources = null;
+  gFrames = null;
 });