tor-browser

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

test_watchpoint-05.js (3290B)


      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 /*
      8 - Adds a 'get or set' watchpoint. Tests that the debugger will pause on both get and set.
      9 */
     10 
     11 add_task(
     12  threadFrontTest(async args => {
     13    await testGetPauseWithGetOrSetWatchpoint(args);
     14    await testSetPauseWithGetOrSetWatchpoint(args);
     15  })
     16 );
     17 
     18 async function testGetPauseWithGetOrSetWatchpoint({ threadFront, debuggee }) {
     19  function evaluateTestCode(debuggee) {
     20    /* eslint-disable */
     21    Cu.evalInSandbox(
     22      `                                   // 1
     23      function stopMe(obj) {              // 2
     24        debugger;                         // 3
     25        obj.a + 4;                        // 4
     26      }                                   //
     27      stopMe({a: 1})`,
     28      debuggee,
     29      "1.8",
     30      "test_watchpoint-05.js"
     31    );
     32    /* eslint-disable */
     33  }
     34 
     35  const packet = await executeOnNextTickAndWaitForPause(
     36    () => evaluateTestCode(debuggee),
     37    threadFront
     38  );
     39 
     40  info("Test that we paused on the debugger statement");
     41  Assert.equal(packet.frame.where.line, 3);
     42 
     43  info("Add get or set watchpoint.");
     44  const args = packet.frame.arguments;
     45  const obj = args[0];
     46  const objClient = threadFront.pauseGrip(obj);
     47  await objClient.addWatchpoint("a", "obj.a", "getorset");
     48 
     49  info("Test that watchpoint triggers pause on get.");
     50  const packet2 = await resumeAndWaitForPause(threadFront);
     51  Assert.equal(packet2.frame.where.line, 4);
     52  Assert.equal(packet2.why.type, "getWatchpoint");
     53  Assert.equal(obj.preview.ownProperties.a.value, 1);
     54 
     55  await resume(threadFront);
     56 }
     57 
     58 async function testSetPauseWithGetOrSetWatchpoint({
     59  commands,
     60  threadFront,
     61  debuggee,
     62 }) {
     63  async function evaluateJS(input) {
     64    const { result } = await commands.scriptCommand.execute(input, {
     65      frameActor: packet.frame.actorID,
     66    });
     67    return result;
     68  }
     69 
     70  function evaluateTestCode(debuggee) {
     71    /* eslint-disable */
     72    Cu.evalInSandbox(
     73      `                                   // 1
     74      function stopMe(obj) {              // 2
     75        debugger;                         // 3
     76        obj.a = 2;                        // 4
     77      }                                   //
     78      stopMe({a: { b: 1 }})`,
     79      debuggee,
     80      "1.8",
     81      "test_watchpoint-05.js"
     82    );
     83    /* eslint-disable */
     84  }
     85 
     86  const packet = await executeOnNextTickAndWaitForPause(
     87    () => evaluateTestCode(debuggee),
     88    threadFront
     89  );
     90 
     91  info("Test that we paused on the debugger statement");
     92  Assert.equal(packet.frame.where.line, 3);
     93 
     94  info("Add get or set watchpoint");
     95  const args = packet.frame.arguments;
     96  const obj = args[0];
     97  const objClient = threadFront.pauseGrip(obj);
     98  await objClient.addWatchpoint("a", "obj.a", "getorset");
     99 
    100  let result = await evaluateJS("obj.a");
    101  Assert.equal(result.getGrip().preview.ownProperties.b.value, 1);
    102 
    103  result = await evaluateJS("obj.a.b");
    104  Assert.equal(result, 1);
    105 
    106  info("Test that watchpoint triggers pause on set");
    107  const packet2 = await resumeAndWaitForPause(threadFront);
    108  Assert.equal(packet2.frame.where.line, 4);
    109  Assert.equal(packet2.why.type, "setWatchpoint");
    110  Assert.equal(obj.preview.ownProperties.a.value.ownPropertyLength, 1);
    111 
    112  await resume(threadFront);
    113 }