Bug 1441310 - Refactor breakpoint server tests.
authorMiriam <bmiriam1230@gmail.com>
Thu, 08 Aug 2019 21:55:49 +0000
changeset 487199 cf55053805142e0d98a439c6a15a8c8a8b7a8122
parent 487198 eaae932bdaefff72b5eb71c7f7bf3b76b267f97e
child 487200 56140cb1ec04ae56e13293b210e589f01b730031
push id36413
push usercsabou@mozilla.com
push dateFri, 09 Aug 2019 21:56:59 +0000
treeherdermozilla-central@2909b0a1eb06 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1441310
milestone70.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 1441310 - Refactor breakpoint server tests. Differential Revision: https://phabricator.services.mozilla.com/D41051
devtools/server/tests/unit/test_breakpoint-02.js
devtools/server/tests/unit/test_breakpoint-04.js
devtools/server/tests/unit/test_breakpoint-09.js
devtools/server/tests/unit/test_breakpoint-10.js
devtools/server/tests/unit/test_breakpoint-11.js
devtools/server/tests/unit/test_breakpoint-13.js
devtools/server/tests/unit/test_breakpoint-14.js
devtools/server/tests/unit/test_breakpoint-16.js
devtools/server/tests/unit/test_breakpoint-18.js
--- a/devtools/server/tests/unit/test_breakpoint-02.js
+++ b/devtools/server/tests/unit/test_breakpoint-02.js
@@ -4,41 +4,43 @@
 
 "use strict";
 
 /**
  * Check that setting breakpoints when the debuggee is running works.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, client, debuggee }) => {
-    return new Promise(resolve => {
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = { sourceUrl: source.url, line: debuggee.line0 + 3 };
-
-        await threadFront.resume();
-
-        // Setting the breakpoint later should interrupt the debuggee.
-        threadFront.once("paused", function(packet) {
-          Assert.equal(packet.why.type, "interrupted");
-        });
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = { sourceUrl: source.url, line: debuggee.line0 + 3 };
 
-        threadFront.setBreakpoint(location, {});
-        await client.waitForRequestsToSettle();
-        executeSoon(resolve);
-      });
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 1);
+    Assert.equal(packet.why.type, "debuggerStatement");
+
+    await threadFront.resume();
 
-      /* eslint-disable */
-    Cu.evalInSandbox(
-      "var line0 = Error().lineNumber;\n" +
-      "debugger;\n" +
-      "var a = 1;\n" +  // line0 + 2
-      "var b = 2;\n",  // line0 + 3
-      debuggee
-    );
-    /* eslint-enable */
+    // Setting the breakpoint later should interrupt the debuggee.
+    threadFront.once("paused", function(packet) {
+      Assert.equal(packet.why.type, "interrupted");
     });
+
+    threadFront.setBreakpoint(location, {});
+    await client.waitForRequestsToSettle();
   })
 );
+
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
+  Cu.evalInSandbox(
+    "var line0 = Error().lineNumber;\n" +
+    "debugger;\n" +
+    "var a = 1;\n" +  // line0 + 2
+    "var b = 2;\n",  // line0 + 3
+    debuggee
+  );
+  /* eslint-disable */
+}
--- a/devtools/server/tests/unit/test_breakpoint-04.js
+++ b/devtools/server/tests/unit/test_breakpoint-04.js
@@ -4,54 +4,55 @@
 
 "use strict";
 
 /**
  * Check that setting a breakpoint in a line in a child script works.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, client, debuggee }) => {
-    return new Promise(resolve => {
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = { sourceUrl: source.url, line: debuggee.line0 + 3 };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = { sourceUrl: source.url, line: debuggee.line0 + 3 };
 
-        threadFront.setBreakpoint(location, {});
-        await client.waitForRequestsToSettle();
-
-        threadFront.once("paused", async function(packet) {
-          // Check the return value.
-          Assert.equal(packet.frame.where.actor, source.actor);
-          Assert.equal(packet.frame.where.line, location.line);
-          Assert.equal(packet.why.type, "breakpoint");
-          // Check that the breakpoint worked.
-          Assert.equal(debuggee.a, 1);
-          Assert.equal(debuggee.b, undefined);
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 5);
+    Assert.equal(packet.why.type, "debuggerStatement");
 
-          // Remove the breakpoint.
-          threadFront.removeBreakpoint(location);
-          await client.waitForRequestsToSettle();
-          threadFront.resume().then(resolve);
-        });
-
-        // Continue until the breakpoint is hit.
-        await threadFront.resume();
-      });
+    threadFront.setBreakpoint(location, {});
+    await client.waitForRequestsToSettle();
+    await resume(threadFront);
 
-      /* eslint-disable */
-      Cu.evalInSandbox(
-        "var line0 = Error().lineNumber;\n" +
-        "function foo() {\n" + // line0 + 1
-        "  this.a = 1;\n" +    // line0 + 2
-        "  this.b = 2;\n" +    // line0 + 3
-        "}\n" +                // line0 + 4
-        "debugger;\n" +        // line0 + 5
-        "foo();\n",            // line0 + 6
-        debuggee
-      );
-      /* eslint-enable */
-    });
+    const packet2 = await waitForPause(threadFront);
+    // Check the return value.
+    Assert.equal(packet2.frame.where.actor, source.actor);
+    Assert.equal(packet2.frame.where.line, location.line);
+    Assert.equal(packet2.why.type, "breakpoint");
+    // Check that the breakpoint worked.
+    Assert.equal(debuggee.a, 1);
+    Assert.equal(debuggee.b, undefined);
+
+    // Remove the breakpoint.
+    threadFront.removeBreakpoint(location);
+    await client.waitForRequestsToSettle();
+
+    await resume(threadFront);
   })
 );
+
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
+  Cu.evalInSandbox(
+    "var line0 = Error().lineNumber;\n" +
+    "function foo() {\n" + // line0 + 1
+    "  this.a = 1;\n" +    // line0 + 2
+    "  this.b = 2;\n" +    // line0 + 3
+    "}\n" +                // line0 + 4
+    "debugger;\n" +        // line0 + 5
+    "foo();\n",            // line0 + 6
+    debuggee
+  );
+  /* eslint-disable */
+}
--- a/devtools/server/tests/unit/test_breakpoint-09.js
+++ b/devtools/server/tests/unit/test_breakpoint-09.js
@@ -3,65 +3,71 @@
 /* eslint-disable no-shadow, max-nested-callbacks */
 
 "use strict";
 
 /**
  * Check that removing a breakpoint works.
  */
 
+let done = false;
+
 add_task(
-  threadFrontTest(({ threadFront, client, debuggee }) => {
-    return new Promise(resolve => {
-      let done = false;
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = { sourceUrl: source.url, line: debuggee.line0 + 2 };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = { sourceUrl: source.url, line: debuggee.line0 + 2 };
+
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 7);
+    Assert.equal(packet.why.type, "debuggerStatement");
+
+    threadFront.setBreakpoint(location, {});
+    await client.waitForRequestsToSettle();
+
+    await resume(threadFront);
+
+    const packet2 = await waitForPause(threadFront);
 
-        threadFront.setBreakpoint(location, {});
-        await client.waitForRequestsToSettle();
-        threadFront.once("paused", async function(packet) {
-          // Check the return value.
-          Assert.equal(packet.frame.where.actor, source.actorID);
-          Assert.equal(packet.frame.where.line, location.line);
-          Assert.equal(packet.why.type, "breakpoint");
-          // Check that the breakpoint worked.
-          Assert.equal(debuggee.a, undefined);
+    // Check the return value.
+    Assert.equal(packet2.frame.where.actor, source.actorID);
+    Assert.equal(packet2.frame.where.line, location.line);
+    Assert.equal(packet2.why.type, "breakpoint");
+    // Check that the breakpoint worked.
+    Assert.equal(debuggee.a, undefined);
+
+    // Remove the breakpoint.
+    threadFront.removeBreakpoint(location);
+    await client.waitForRequestsToSettle();
 
-          // Remove the breakpoint.
-          threadFront.removeBreakpoint(location);
-          await client.waitForRequestsToSettle();
-          done = true;
-          threadFront.once("paused", function(packet) {
-            // The breakpoint should not be hit again.
-            threadFront.resume().then(function() {
-              Assert.ok(false);
-            });
-          });
-          await threadFront.resume();
-          resolve();
-        });
+    done = true;
+    threadFront.once("paused", function(packet) {
+      // The breakpoint should not be hit again.
+      threadFront.resume().then(function() {
+        Assert.ok(false);
+      });
+    });
 
-        // Continue until the breakpoint is hit.
-        await threadFront.resume();
-      });
+    await resume(threadFront);
+  })
+);
 
-      /* eslint-disable */
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
       Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
                        "function foo(stop) {\n" + // line0 + 1
                        "  this.a = 1;\n" +        // line0 + 2
                        "  if (stop) return;\n" +  // line0 + 3
                        "  delete this.a;\n" +     // line0 + 4
                        "  foo(true);\n" +         // line0 + 5
                        "}\n" +                    // line0 + 6
                        "debugger;\n" +            // line1 + 7
                        "foo();\n",                // line1 + 8
                        debuggee);
       /* eslint-enable */
-      if (!done) {
-        Assert.ok(false);
-      }
-    });
-  })
-);
+  if (!done) {
+    Assert.ok(false);
+  }
+}
--- a/devtools/server/tests/unit/test_breakpoint-10.js
+++ b/devtools/server/tests/unit/test_breakpoint-10.js
@@ -5,75 +5,79 @@
 "use strict";
 
 /**
  * Check that setting a breakpoint in a line with multiple entry points
  * triggers no matter which entry point we reach.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, client, debuggee }) => {
-    return new Promise(resolve => {
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = {
-          sourceUrl: source.url,
-          line: debuggee.line0 + 3,
-          column: 5,
-        };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 3,
+      column: 5,
+    };
 
-        threadFront.setBreakpoint(location, {});
-        await client.waitForRequestsToSettle();
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 1);
+    Assert.equal(packet.why.type, "debuggerStatement");
+
+    threadFront.setBreakpoint(location, {});
+    await client.waitForRequestsToSettle();
+
+    await resume(threadFront);
 
-        threadFront.once("paused", async function(packet) {
-          // Check the return value.
-          Assert.equal(packet.why.type, "breakpoint");
-          // Check that the breakpoint worked.
-          Assert.equal(debuggee.i, 0);
-
-          // Remove the breakpoint.
-          threadFront.removeBreakpoint(location);
-          await client.waitForRequestsToSettle();
+    const packet2 = await waitForPause(threadFront);
+    // Check the return value.
+    Assert.equal(packet2.why.type, "breakpoint");
+    // Check that the breakpoint worked.
+    Assert.equal(debuggee.i, 0);
+    // Check pause location
+    Assert.equal(packet2.frame.where.line, debuggee.line0 + 3);
+    Assert.equal(packet2.frame.where.column, 5);
 
-          const location2 = {
-            sourceUrl: source.url,
-            line: debuggee.line0 + 3,
-            column: 12,
-          };
-          threadFront.setBreakpoint(location2, {});
-          await client.waitForRequestsToSettle();
+    // Remove the breakpoint.
+    threadFront.removeBreakpoint(location);
+    await client.waitForRequestsToSettle();
 
-          threadFront.once("paused", async function(packet) {
-            // Check the return value.
-            Assert.equal(packet.why.type, "breakpoint");
-            // Check that the breakpoint worked.
-            Assert.equal(debuggee.i, 1);
+    const location2 = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 3,
+      column: 12,
+    };
+    threadFront.setBreakpoint(location2, {});
+    await client.waitForRequestsToSettle();
 
-            // Remove the breakpoint.
-            threadFront.removeBreakpoint(location2);
-            await client.waitForRequestsToSettle();
-
-            threadFront.resume().then(resolve);
-          });
+    await resume(threadFront);
+    const packet3 = await waitForPause(threadFront);
+    // Check the return value.
+    Assert.equal(packet3.why.type, "breakpoint");
+    // Check that the breakpoint worked.
+    Assert.equal(debuggee.i, 1);
+    // Check execution location
+    Assert.equal(packet3.frame.where.line, debuggee.line0 + 3);
+    Assert.equal(packet3.frame.where.column, 12);
 
-          // Continue until the breakpoint is hit again.
-          await threadFront.resume();
-        });
+    // Remove the breakpoint.
+    threadFront.removeBreakpoint(location2);
+    await client.waitForRequestsToSettle();
 
-        // Continue until the breakpoint is hit.
-        await threadFront.resume();
-      });
+    await resume(threadFront);
+  })
+);
 
-      /* eslint-disable */
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
       Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
                        "debugger;\n" +                      // line0 + 1
                        "var a, i = 0;\n" +                  // line0 + 2
                        "for (i = 1; i <= 2; i++) {\n" +     // line0 + 3
                        "  a = i;\n" +                       // line0 + 4
                        "}\n",                               // line0 + 5
                        debuggee);
       /* eslint-enable */
-    });
-  })
-);
+}
--- a/devtools/server/tests/unit/test_breakpoint-11.js
+++ b/devtools/server/tests/unit/test_breakpoint-11.js
@@ -5,71 +5,75 @@
 "use strict";
 
 /**
  * Make sure that setting a breakpoint in a line with bytecodes in multiple
  * scripts, sets the breakpoint in all of them (bug 793214).
  */
 
 add_task(
-  threadFrontTest(({ threadFront, debuggee }) => {
-    return new Promise(resolve => {
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = {
-          sourceUrl: source.url,
-          line: debuggee.line0 + 2,
-          column: 8,
-        };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 2,
+      column: 8,
+    };
 
-        threadFront.setBreakpoint(location, {});
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 1);
+    Assert.equal(packet.why.type, "debuggerStatement");
+
+    threadFront.setBreakpoint(location, {});
+    await resume(threadFront);
 
-        threadFront.once("paused", function(packet) {
-          // Check the return value.
-          Assert.equal(packet.why.type, "breakpoint");
-          // Check that the breakpoint worked.
-          Assert.equal(debuggee.a, undefined);
+    const packet2 = await waitForPause(threadFront);
 
-          // Remove the breakpoint.
-          threadFront.removeBreakpoint(location);
+    // Check the return value.
+    Assert.equal(packet2.why.type, "breakpoint");
+    // Check that the breakpoint worked.
+    Assert.equal(debuggee.a, undefined);
+    // Check execution location
+    Assert.equal(packet2.frame.where.line, debuggee.line0 + 2);
+    Assert.equal(packet2.frame.where.column, 8);
 
-          const location2 = {
-            sourceUrl: source.url,
-            line: debuggee.line0 + 2,
-            column: 32,
-          };
+    // Remove the breakpoint.
+    threadFront.removeBreakpoint(location);
 
-          threadFront.setBreakpoint(location2, {});
+    const location2 = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 2,
+      column: 32,
+    };
+    threadFront.setBreakpoint(location2, {});
 
-          threadFront.once("paused", function(packet) {
-            // Check the return value.
-            Assert.equal(packet.why.type, "breakpoint");
-            // Check that the breakpoint worked.
-            Assert.equal(debuggee.a.b, 1);
-            Assert.equal(debuggee.res, undefined);
+    await resume(threadFront);
+    const packet3 = await waitForPause(threadFront);
 
-            // Remove the breakpoint.
-            threadFront.removeBreakpoint(location2);
-
-            threadFront.resume().then(resolve);
-          });
+    // Check the return value.
+    Assert.equal(packet3.why.type, "breakpoint");
+    // Check that the breakpoint worked.
+    Assert.equal(debuggee.a.b, 1);
+    Assert.equal(debuggee.res, undefined);
+    // Check execution location
+    Assert.equal(packet3.frame.where.line, debuggee.line0 + 2);
+    Assert.equal(packet3.frame.where.column, 32);
 
-          // Continue until the breakpoint is hit again.
-          threadFront.resume();
-        });
+    // Remove the breakpoint.
+    threadFront.removeBreakpoint(location2);
 
-        // Continue until the breakpoint is hit.
-        threadFront.resume();
-      });
+    await resume(threadFront);
+  })
+);
 
-      /* eslint-disable */
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
       Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
                        "debugger;\n" +                      // line0 + 1
                        "var a = { b: 1, f: function() { return 2; } };\n" + // line0+2
                        "var res = a.f();\n",               // line0 + 3
                        debuggee);
       /* eslint-enable */
-    });
-  })
-);
+}
--- a/devtools/server/tests/unit/test_breakpoint-13.js
+++ b/devtools/server/tests/unit/test_breakpoint-13.js
@@ -5,86 +5,88 @@
 "use strict";
 
 /**
  * Check that execution doesn't pause twice while stepping, when encountering
  * either a breakpoint or a debugger statement.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, debuggee }) => {
-    return new Promise(resolve => {
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = { sourceUrl: source.url, line: debuggee.line0 + 2 };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 2,
+    };
 
-        threadFront.setBreakpoint(location, {});
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 4);
+    Assert.equal(packet.why.type, "debuggerStatement");
+
+    threadFront.setBreakpoint(location, {});
 
-        const testCallbacks = [
-          function(packet) {
-            // Check that the stepping worked.
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 5);
-            Assert.equal(packet.why.type, "resumeLimit");
-          },
-          function(packet) {
-            // Entered the foo function call frame.
-            Assert.equal(packet.frame.where.line, location.line);
-            Assert.notEqual(packet.why.type, "breakpoint");
-            Assert.equal(packet.why.type, "resumeLimit");
-          },
-          function(packet) {
-            // Check that the breakpoint wasn't the reason for this pause, but
-            // that the frame is about to be popped while stepping.
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 3);
-            Assert.notEqual(packet.why.type, "breakpoint");
-            Assert.equal(packet.why.type, "resumeLimit");
-            Assert.equal(packet.why.frameFinished.return.type, "undefined");
-          },
-          function(packet) {
-            // Check that the debugger statement wasn't the reason for this pause.
-            Assert.equal(debuggee.a, 1);
-            Assert.equal(debuggee.b, undefined);
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 6);
-            Assert.notEqual(packet.why.type, "debuggerStatement");
-            Assert.equal(packet.why.type, "resumeLimit");
-            Assert.equal(packet.poppedFrames.length, 1);
-          },
-          function(packet) {
-            // Check that the debugger statement wasn't the reason for this pause.
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 7);
-            Assert.notEqual(packet.why.type, "debuggerStatement");
-            Assert.equal(packet.why.type, "resumeLimit");
-          },
-        ];
+    const testCallbacks = [
+      function(packet) {
+        // Check that the stepping worked.
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 5);
+        Assert.equal(packet.why.type, "resumeLimit");
+      },
+      function(packet) {
+        // Entered the foo function call frame.
+        Assert.equal(packet.frame.where.line, location.line);
+        Assert.notEqual(packet.why.type, "breakpoint");
+        Assert.equal(packet.why.type, "resumeLimit");
+      },
+      function(packet) {
+        // Check that the breakpoint wasn't the reason for this pause, but
+        // that the frame is about to be popped while stepping.
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 3);
+        Assert.notEqual(packet.why.type, "breakpoint");
+        Assert.equal(packet.why.type, "resumeLimit");
+        Assert.equal(packet.why.frameFinished.return.type, "undefined");
+      },
+      function(packet) {
+        // Check that the debugger statement wasn't the reason for this pause.
+        Assert.equal(debuggee.a, 1);
+        Assert.equal(debuggee.b, undefined);
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 6);
+        Assert.notEqual(packet.why.type, "debuggerStatement");
+        Assert.equal(packet.why.type, "resumeLimit");
+        Assert.equal(packet.poppedFrames.length, 1);
+      },
+      function(packet) {
+        // Check that the debugger statement wasn't the reason for this pause.
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 7);
+        Assert.notEqual(packet.why.type, "debuggerStatement");
+        Assert.equal(packet.why.type, "resumeLimit");
+      },
+    ];
 
-        for (const callback of testCallbacks) {
-          const waiter = waitForPause(threadFront);
-          threadFront.stepIn();
-          const packet = await waiter;
-          callback(packet);
-        }
+    for (const callback of testCallbacks) {
+      const waiter = waitForPause(threadFront);
+      threadFront.stepIn();
+      const packet = await waiter;
+      callback(packet);
+    }
 
-        // Remove the breakpoint and finish.
-        const waiter = waitForPause(threadFront);
-        threadFront.stepIn();
-        await waiter;
-        threadFront.removeBreakpoint(location);
+    // Remove the breakpoint and finish.
+    threadFront.removeBreakpoint(location);
+    await threadFront.resume();
+  })
+);
 
-        threadFront.resume().then(resolve);
-      });
-
-      /* eslint-disable */
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
       Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
                        "function foo() {\n" + // line0 + 1
                        "  this.a = 1;\n" +    // line0 + 2 <-- Breakpoint is set here.
                        "}\n" +                // line0 + 3
                        "debugger;\n" +        // line0 + 4
                        "foo();\n" +           // line0 + 5
                        "debugger;\n" +        // line0 + 6
                        "var b = 2;\n",        // line0 + 7
                        debuggee);
       /* eslint-enable */
-    });
-  })
-);
+}
--- a/devtools/server/tests/unit/test_breakpoint-14.js
+++ b/devtools/server/tests/unit/test_breakpoint-14.js
@@ -5,83 +5,88 @@
 "use strict";
 
 /**
  * Check that a breakpoint or a debugger statement cause execution to pause even
  * in a stepped-over function.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, debuggee }) => {
-    return new Promise(resolve => {
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = { sourceUrl: source.url, line: debuggee.line0 + 2 };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 2,
+    };
+
+    //Pause at debugger statement.
+    Assert.equal(packet.frame.where.line, debuggee.line0 + 4);
+    Assert.equal(packet.why.type, "debuggerStatement");
+
+    threadFront.setBreakpoint(location, {});
 
-        threadFront.setBreakpoint(location, {});
-        const testCallbacks = [
-          function(packet) {
-            // Check that the stepping worked.
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 5);
-            Assert.equal(packet.why.type, "resumeLimit");
-          },
-          function(packet) {
-            // Reached the breakpoint.
-            Assert.equal(packet.frame.where.line, location.line);
-            Assert.equal(packet.why.type, "breakpoint");
-            Assert.notEqual(packet.why.type, "resumeLimit");
-          },
-          function(packet) {
-            // The frame is about to be popped while stepping.
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 3);
-            Assert.notEqual(packet.why.type, "breakpoint");
-            Assert.equal(packet.why.type, "resumeLimit");
-            Assert.equal(packet.why.frameFinished.return.type, "undefined");
-          },
-          function(packet) {
-            // Check that the debugger statement wasn't the reason for this pause.
-            Assert.equal(debuggee.a, 1);
-            Assert.equal(debuggee.b, undefined);
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 6);
-            Assert.notEqual(packet.why.type, "debuggerStatement");
-            Assert.equal(packet.why.type, "resumeLimit");
-            Assert.equal(packet.poppedFrames.length, 1);
-          },
-          function(packet) {
-            // Check that the debugger statement wasn't the reason for this pause.
-            Assert.equal(packet.frame.where.line, debuggee.line0 + 7);
-            Assert.notEqual(packet.why.type, "debuggerStatement");
-            Assert.equal(packet.why.type, "resumeLimit");
-          },
-        ];
+    const testCallbacks = [
+      function(packet) {
+        // Check that the stepping worked.
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 5);
+        Assert.equal(packet.why.type, "resumeLimit");
+      },
+      function(packet) {
+        // Reached the breakpoint.
+        Assert.equal(packet.frame.where.line, location.line);
+        Assert.equal(packet.why.type, "breakpoint");
+        Assert.notEqual(packet.why.type, "resumeLimit");
+      },
+      function(packet) {
+        // The frame is about to be popped while stepping.
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 3);
+        Assert.notEqual(packet.why.type, "breakpoint");
+        Assert.equal(packet.why.type, "resumeLimit");
+        Assert.equal(packet.why.frameFinished.return.type, "undefined");
+      },
+      function(packet) {
+        // Check that the debugger statement wasn't the reason for this pause.
+        Assert.equal(debuggee.a, 1);
+        Assert.equal(debuggee.b, undefined);
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 6);
+        Assert.notEqual(packet.why.type, "debuggerStatement");
+        Assert.equal(packet.why.type, "resumeLimit");
+        Assert.equal(packet.poppedFrames.length, 1);
+      },
+      function(packet) {
+        // Check that the debugger statement wasn't the reason for this pause.
+        Assert.equal(packet.frame.where.line, debuggee.line0 + 7);
+        Assert.notEqual(packet.why.type, "debuggerStatement");
+        Assert.equal(packet.why.type, "resumeLimit");
+      },
+    ];
 
-        for (const callback of testCallbacks) {
-          const waiter = waitForPause(threadFront);
-          threadFront.stepOver();
-          const packet = await waiter;
-          callback(packet);
-        }
+    for (const callback of testCallbacks) {
+      const waiter = waitForPause(threadFront);
+      threadFront.stepOver();
+      const packet = await waiter;
+      callback(packet);
+    }
 
-        // Remove the breakpoint and finish.
-        const waiter = waitForPause(threadFront);
-        threadFront.stepOver();
-        await waiter;
-        threadFront.removeBreakpoint(location);
-        threadFront.resume().then(resolve);
-      });
+    // Remove the breakpoint and finish.
+    threadFront.removeBreakpoint(location);
 
-      /* eslint-disable */
+    await threadFront.resume();
+  })
+);
+
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
       Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
                        "function foo() {\n" + // line0 + 1
                        "  this.a = 1;\n" +    // line0 + 2 <-- Breakpoint is set here.
                        "}\n" +                // line0 + 3
                        "debugger;\n" +        // line0 + 4
                        "foo();\n" +           // line0 + 5
                        "debugger;\n" +        // line0 + 6
                        "var b = 2;\n",        // line0 + 7
                        debuggee);
       /* eslint-enable */
-    });
-  })
-);
+}
--- a/devtools/server/tests/unit/test_breakpoint-16.js
+++ b/devtools/server/tests/unit/test_breakpoint-16.js
@@ -4,60 +4,64 @@
 
 "use strict";
 
 /**
  * Check that we can set breakpoints in columns, not just lines.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, debuggee, client }) => {
-    return new Promise(resolve => {
-      // Debugger statement
-      threadFront.once("paused", async function(packet) {
-        const source = await getSourceById(
-          threadFront,
-          packet.frame.where.actor
-        );
-        const location = {
-          sourceUrl: source.url,
-          line: debuggee.line0 + 1,
-          column: 55,
-        };
-        let timesBreakpointHit = 0;
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = {
+      sourceUrl: source.url,
+      line: debuggee.line0 + 1,
+      column: 55,
+    };
 
-        threadFront.setBreakpoint(location, {});
+    let timesBreakpointHit = 0;
+    threadFront.setBreakpoint(location, {});
 
-        threadFront.on("paused", function onPaused(packet) {
-          Assert.equal(packet.why.type, "breakpoint");
-          Assert.equal(packet.frame.where.actor, source.actor);
-          Assert.equal(packet.frame.where.line, location.line);
-          Assert.equal(packet.frame.where.column, location.column);
+    while (timesBreakpointHit < 3) {
+      await resume(threadFront);
+      const packet = await waitForPause(threadFront);
+      testAssertions(packet, debuggee, source, location, timesBreakpointHit);
 
-          Assert.equal(debuggee.acc, timesBreakpointHit);
-          Assert.equal(
-            packet.frame.environment.bindings.variables.i.value,
-            timesBreakpointHit
-          );
+      timesBreakpointHit++;
+    }
 
-          if (++timesBreakpointHit === 3) {
-            threadFront.off("paused", onPaused);
-            threadFront.removeBreakpoint(location);
-            threadFront.resume().then(resolve);
-          } else {
-            threadFront.resume();
-          }
-        });
+    threadFront.removeBreakpoint(location);
+    await threadFront.resume();
+  })
+);
 
-        // Continue until the breakpoint is hit.
-        threadFront.resume();
-      });
-
-      /* eslint-disable */
+function evaluateTestCode(debuggee) {
+  /* eslint-disable */
       Cu.evalInSandbox(
         "var line0 = Error().lineNumber;\n" +
         "(function () { debugger; this.acc = 0; for (var i = 0; i < 3; i++) this.acc++; }());",
         debuggee
       );
       /* eslint-enable */
-    });
-  })
-);
+}
+
+function testAssertions(
+  packet,
+  debuggee,
+  source,
+  location,
+  timesBreakpointHit
+) {
+  Assert.equal(packet.why.type, "breakpoint");
+  Assert.equal(packet.frame.where.actor, source.actor);
+  Assert.equal(packet.frame.where.line, location.line);
+  Assert.equal(packet.frame.where.column, location.column);
+
+  Assert.equal(debuggee.acc, timesBreakpointHit);
+  Assert.equal(
+    packet.frame.environment.bindings.variables.i.value,
+    timesBreakpointHit
+  );
+}
--- a/devtools/server/tests/unit/test_breakpoint-18.js
+++ b/devtools/server/tests/unit/test_breakpoint-18.js
@@ -4,61 +4,58 @@
 "use strict";
 
 /**
  * Check that we only break on offsets that are entry points for the line we are
  * breaking on. Bug 907278.
  */
 
 add_task(
-  threadFrontTest(({ threadFront, debuggee, client }) => {
-    return new Promise(resolve => {
-      // Expose console as the test script uses it
-      debuggee.console = { log: x => void x };
+  threadFrontTest(async ({ threadFront, client, debuggee }) => {
+    const packet = await executeOnNextTickAndWaitForPause(
+      () => evaluateTestCode(debuggee),
+      threadFront
+    );
 
-      // Inline all paused listeners as promises won't resolve when paused
-      threadFront.once("paused", async packet1 => {
-        await setBreakpoint(packet1, threadFront, client);
+    const source = await getSourceById(threadFront, packet.frame.where.actor);
+    const location = { sourceUrl: source.url, line: 3 };
+    threadFront.setBreakpoint(location, {});
+    await client.waitForRequestsToSettle();
 
-        threadFront.once("paused", ({ why }) => {
-          Assert.equal(why.type, "breakpoint");
+    debuggee.console = { log: x => void x };
 
-          threadFront.once("paused", packet3 => {
-            testDbgStatement(packet3);
-            resolve();
-          });
-          threadFront.resume();
-        });
-        debuggee.test();
-      });
+    await resume(threadFront);
 
-      Cu.evalInSandbox(
-        "debugger;\n" +
-          function test() {
-            console.log("foo bar");
-            debugger;
-          },
-        debuggee,
-        "1.8",
-        "http://example.com/",
-        1
-      );
-    });
+    const packet2 = await executeOnNextTickAndWaitForPause(
+      debuggee.test,
+      threadFront
+    );
+    Assert.equal(packet2.why.type, "breakpoint");
+
+    threadFront.resume();
+
+    const packet3 = await waitForPause(threadFront);
+    testDbgStatement(packet3);
+
+    await resume(threadFront);
   })
 );
 
-function setBreakpoint(packet, threadFront, client) {
-  return new Promise(async resolve => {
-    const source = await getSourceById(threadFront, packet.frame.where.actor);
-    threadFront.once("resumed", resolve);
-
-    threadFront.setBreakpoint({ sourceUrl: source.url, line: 3 }, {});
-    await client.waitForRequestsToSettle();
-    await threadFront.resume();
-  });
+function evaluateTestCode(debuggee) {
+  Cu.evalInSandbox(
+    "debugger;\n" +
+      function test() {
+        console.log("foo bar");
+        debugger;
+      },
+    debuggee,
+    "1.8",
+    "http://example.com/",
+    1
+  );
 }
 
 function testDbgStatement({ why }) {
   // Should continue to the debugger statement.
   Assert.equal(why.type, "debuggerStatement");
   // Not break on another offset from the same line (that isn't an entry point
   // to the line)
   Assert.notEqual(why.type, "breakpoint");