tor-browser

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

test_breakpoint-16.js (1827B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* eslint-disable no-shadow, max-nested-callbacks */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Check that we can set breakpoints in columns, not just lines.
      9 */
     10 
     11 add_task(
     12  threadFrontTest(async ({ threadFront, debuggee }) => {
     13    const packet = await executeOnNextTickAndWaitForPause(
     14      () => evaluateTestCode(debuggee),
     15      threadFront
     16    );
     17    const source = await getSourceById(threadFront, packet.frame.where.actor);
     18    const location = {
     19      sourceUrl: source.url,
     20      line: debuggee.line0 + 1,
     21      column: 55,
     22    };
     23 
     24    let timesBreakpointHit = 0;
     25    threadFront.setBreakpoint(location, {});
     26 
     27    while (timesBreakpointHit < 3) {
     28      await resume(threadFront);
     29      const packet = await waitForPause(threadFront);
     30      await testAssertions(
     31        packet,
     32        debuggee,
     33        source,
     34        location,
     35        timesBreakpointHit
     36      );
     37 
     38      timesBreakpointHit++;
     39    }
     40 
     41    threadFront.removeBreakpoint(location);
     42    await threadFront.resume();
     43  })
     44 );
     45 
     46 function evaluateTestCode(debuggee) {
     47  // prettier-ignore
     48  Cu.evalInSandbox(
     49    "var line0 = Error().lineNumber;\n" +
     50    "(function () { debugger; this.acc = 0; for (var i = 0; i < 3; i++) this.acc++; }());",
     51    debuggee
     52  );
     53 }
     54 
     55 async function testAssertions(
     56  packet,
     57  debuggee,
     58  source,
     59  location,
     60  timesBreakpointHit
     61 ) {
     62  Assert.equal(packet.why.type, "breakpoint");
     63  Assert.equal(packet.frame.where.actor, source.actor);
     64  Assert.equal(packet.frame.where.line, location.line);
     65  Assert.equal(packet.frame.where.column, location.column);
     66 
     67  Assert.equal(debuggee.acc, timesBreakpointHit);
     68  const environment = await packet.frame.getEnvironment();
     69  Assert.equal(environment.bindings.variables.i.value, timesBreakpointHit);
     70 }