tor-browser

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

test_dbgactor.js (1200B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(
      7  Ci.nsIJSInspector
      8 );
      9 
     10 add_task(
     11  threadFrontTest(async ({ threadFront, debuggee }) => {
     12    Assert.equal(xpcInspector.eventLoopNestLevel, 0);
     13 
     14    const packet = await executeOnNextTickAndWaitForPause(
     15      () => evalCode(debuggee),
     16      threadFront
     17    );
     18 
     19    Assert.equal(false, "error" in packet);
     20    Assert.ok("actor" in packet);
     21    Assert.ok("why" in packet);
     22    Assert.equal(packet.why.type, "debuggerStatement");
     23 
     24    // Reach around the protocol to check that the debuggee is in the state
     25    // we expect.
     26    Assert.ok(debuggee.a);
     27    Assert.ok(!debuggee.b);
     28 
     29    Assert.equal(xpcInspector.eventLoopNestLevel, 1);
     30 
     31    // Let the debuggee continue execution.
     32    await threadFront.resume();
     33 
     34    // Now make sure that we've run the code after the debugger statement...
     35    Assert.ok(debuggee.b);
     36 
     37    Assert.equal(xpcInspector.eventLoopNestLevel, 0);
     38  })
     39 );
     40 
     41 function evalCode(debuggee) {
     42  Cu.evalInSandbox(
     43    "var a = true; var b = false; debugger; var b = true;",
     44    debuggee
     45  );
     46 }