tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_breakpoint-01.js (1545B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Check basic breakpoint functionality.
      8 */
      9 
     10 add_task(
     11  threadFrontTest(async ({ threadFront, debuggee }) => {
     12    info("Wait for the debugger statement to be hit");
     13    const packet1 = await executeOnNextTickAndWaitForPause(
     14      () => evaluateTestCode(debuggee),
     15      threadFront
     16    );
     17    const source = await getSourceById(threadFront, packet1.frame.where.actor);
     18    const location = { sourceUrl: source.url, line: debuggee.line0 + 3 };
     19 
     20    threadFront.setBreakpoint(location, {});
     21 
     22    const packet2 = await resumeAndWaitForPause(threadFront);
     23 
     24    info("Paused at the breakpoint");
     25    Assert.equal(packet2.frame.where.actor, source.actor);
     26    Assert.equal(packet2.frame.where.line, location.line);
     27    Assert.equal(packet2.why.type, "breakpoint");
     28 
     29    info("Check that the breakpoint worked.");
     30    Assert.equal(debuggee.a, 1);
     31    Assert.equal(debuggee.b, undefined);
     32 
     33    await threadFront.resume();
     34  })
     35 );
     36 
     37 function evaluateTestCode(debuggee) {
     38  /*
     39   * Be sure to run debuggee code in its own HTML 'task', so that when we call
     40   * the onDebuggerStatement hook, the test's own microtasks don't get suspended
     41   * along with the debuggee's.
     42   */
     43  do_timeout(0, () => {
     44    // prettier-ignore
     45    Cu.evalInSandbox(
     46      "var line0 = Error().lineNumber;\n" +
     47      "debugger;\n" + // line0 + 1
     48      "var a = 1;\n" + // line0 + 2
     49      "var b = 2;\n", // line0 + 3
     50      debuggee
     51    );
     52  });
     53 }