tor-browser

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

test_breakpoint-04.js (1740B)


      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 that setting a breakpoint in a line in a child script works.
      8 */
      9 
     10 add_task(
     11  threadFrontTest(async ({ threadFront, client, debuggee }) => {
     12    const packet = await executeOnNextTickAndWaitForPause(
     13      () => evaluateTestCode(debuggee),
     14      threadFront
     15    );
     16    const source = await getSourceById(threadFront, packet.frame.where.actor);
     17    const location = { sourceUrl: source.url, line: debuggee.line0 + 3 };
     18 
     19    //Pause at debugger statement.
     20    Assert.equal(packet.frame.where.line, debuggee.line0 + 5);
     21    Assert.equal(packet.why.type, "debuggerStatement");
     22 
     23    threadFront.setBreakpoint(location, {});
     24    await client.waitForRequestsToSettle();
     25    await resume(threadFront);
     26 
     27    const packet2 = await waitForPause(threadFront);
     28    // Check the return value.
     29    Assert.equal(packet2.frame.where.actor, source.actor);
     30    Assert.equal(packet2.frame.where.line, location.line);
     31    Assert.equal(packet2.why.type, "breakpoint");
     32    // Check that the breakpoint worked.
     33    Assert.equal(debuggee.a, 1);
     34    Assert.equal(debuggee.b, undefined);
     35 
     36    // Remove the breakpoint.
     37    threadFront.removeBreakpoint(location);
     38    await client.waitForRequestsToSettle();
     39 
     40    await resume(threadFront);
     41  })
     42 );
     43 
     44 function evaluateTestCode(debuggee) {
     45  // prettier-ignore
     46  Cu.evalInSandbox(
     47    "var line0 = Error().lineNumber;\n" +
     48    "function foo() {\n" + // line0 + 1
     49    "  this.a = 1;\n" +    // line0 + 2
     50    "  this.b = 2;\n" +    // line0 + 3
     51    "}\n" +                // line0 + 4
     52    "debugger;\n" +        // line0 + 5
     53    "foo();\n",            // line0 + 6
     54    debuggee
     55  );
     56 }