tor-browser

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

test_watchpoint-03.js (2209B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* eslint-disable no-shadow */
      4 
      5 "use strict";
      6 /*
      7 See Bug 1601311.
      8 Tests that removing a watchpoint does not change the value of the property that had the watchpoint.
      9 */
     10 
     11 add_task(
     12  threadFrontTest(async ({ commands, threadFront, debuggee }) => {
     13    async function evaluateJS(input) {
     14      const { result } = await commands.scriptCommand.execute(input, {
     15        frameActor: packet.frame.actorID,
     16      });
     17      return result;
     18    }
     19 
     20    function evaluateTestCode(debuggee) {
     21      /* eslint-disable */
     22      Cu.evalInSandbox(
     23        `                                   // 1
     24                  function stopMe(obj) {              // 2
     25                    debugger;                         // 3
     26                    obj.a = 2;                        // 4
     27                    debugger;                         // 5
     28                  }                                   //
     29 
     30                  stopMe({a: 1})`,
     31        debuggee,
     32        "1.8",
     33        "test_watchpoint-03.js"
     34      );
     35      /* eslint-disable */
     36    }
     37 
     38    const packet = await executeOnNextTickAndWaitForPause(
     39      () => evaluateTestCode(debuggee),
     40      threadFront
     41    );
     42 
     43    info("Test that we paused on the debugger statement.");
     44    Assert.equal(packet.frame.where.line, 3);
     45 
     46    info("Add set watchpoint.");
     47    const args = packet.frame.arguments;
     48    const obj = args[0];
     49    const objClient = threadFront.pauseGrip(obj);
     50    await objClient.addWatchpoint("a", "obj.a", "set");
     51 
     52    info("Test that we pause on set.");
     53    const packet2 = await resumeAndWaitForPause(threadFront);
     54    Assert.equal(packet2.frame.where.line, 4);
     55 
     56    const packet3 = await resumeAndWaitForPause(threadFront);
     57 
     58    info("Test that we pause on the second debugger statement.");
     59    Assert.equal(packet3.frame.where.line, 5);
     60    Assert.equal(packet3.why.type, "debuggerStatement");
     61 
     62    info("Remove watchpoint.");
     63    await objClient.removeWatchpoint("a");
     64 
     65    info("Test that the value has updated.");
     66    const result = await evaluateJS("obj.a");
     67    Assert.equal(result, 2);
     68 
     69    info("Finish test.");
     70    await resume(threadFront);
     71  })
     72 );