tor-browser

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

test_conditional_breakpoint-01.js (1330B)


      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 conditional breakpoint when condition evaluates to true.
      8 */
      9 
     10 add_task(
     11  threadFrontTest(async ({ threadFront, debuggee }) => {
     12    let hitBreakpoint = false;
     13 
     14    const packet1 = await executeOnNextTickAndWaitForPause(
     15      () => evalCode(debuggee),
     16      threadFront
     17    );
     18 
     19    const source = await getSourceById(threadFront, packet1.frame.where.actor);
     20    const location = { sourceUrl: source.url, line: 3 };
     21    threadFront.setBreakpoint(location, { condition: "a === 1" });
     22 
     23    // Continue until the breakpoint is hit.
     24    const packet2 = await resumeAndWaitForPause(threadFront);
     25 
     26    Assert.equal(hitBreakpoint, false);
     27    hitBreakpoint = true;
     28 
     29    // Check the return value.
     30    Assert.equal(packet2.why.type, "breakpoint");
     31    Assert.equal(packet2.frame.where.line, 3);
     32 
     33    // Remove the breakpoint.
     34    await threadFront.removeBreakpoint(location);
     35 
     36    await threadFront.resume();
     37 
     38    Assert.equal(hitBreakpoint, true);
     39  })
     40 );
     41 
     42 function evalCode(debuggee) {
     43  /* eslint-disable */
     44  Cu.evalInSandbox(
     45    "debugger;\n" + // line 1
     46      "var a = 1;\n" + // line 2
     47      "var b = 2;\n", // line 3
     48    debuggee,
     49    "1.8",
     50    "test.js",
     51    1
     52  );
     53  /* eslint-enable */
     54 }