tor-browser

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

test_breakpoint-24.js (6827B)


      1 /* eslint-disable max-nested-callbacks */
      2 /* Any copyright is dedicated to the Public Domain.
      3   http://creativecommons.org/publicdomain/zero/1.0/ */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Bug 1441183 - Verify that the debugger advances to a new location
      9 * when encountering debugger statements and brakpoints
     10 *
     11 * Bug 1613165 - Verify that debugger statement is not disabled by
     12 *  adding/removing a breakpoint
     13 */
     14 add_task(
     15  threadFrontTest(async props => {
     16    await testDebuggerStatements(props);
     17    await testBreakpoints(props);
     18    await testBreakpointsAndDebuggerStatements(props);
     19    await testLoops(props);
     20    await testRemovingBreakpoint(props);
     21    await testAddingBreakpoint(props);
     22  })
     23 );
     24 
     25 // Ensure that we advance to the next line when we
     26 // step to a debugger statement and resume.
     27 async function testDebuggerStatements({ commands, threadFront }) {
     28  commands.scriptCommand.execute(`function foo(stop) {
     29      debugger;
     30      debugger;
     31      debugger;
     32    }
     33    foo();
     34    //# sourceURL=http://example.com/code.js`);
     35 
     36  await performActions(threadFront, [
     37    [
     38      "paused at first debugger statement",
     39      { line: 2, type: "debuggerStatement" },
     40      "stepOver",
     41    ],
     42    [
     43      "paused at the second debugger statement",
     44      { line: 3, type: "resumeLimit" },
     45      "resume",
     46    ],
     47    [
     48      "paused at the third debugger statement",
     49      { line: 4, type: "debuggerStatement" },
     50      "resume",
     51    ],
     52  ]);
     53 }
     54 
     55 // Ensure that we advance to the next line when we hit a breakpoint
     56 // on a line with a debugger statement and resume.
     57 async function testBreakpointsAndDebuggerStatements({ commands, threadFront }) {
     58  commands.scriptCommand.execute(`function foo(stop) {
     59      debugger;
     60      debugger;
     61      debugger;
     62    }
     63    foo();
     64    //# sourceURL=http://example.com/testBreakpointsAndDebuggerStatements.js`);
     65 
     66  threadFront.setBreakpoint(
     67    {
     68      sourceUrl: "http://example.com/testBreakpointsAndDebuggerStatements.js",
     69      line: 3,
     70    },
     71    {}
     72  );
     73 
     74  await performActions(threadFront, [
     75    [
     76      "paused at first debugger statement",
     77      { line: 2, type: "debuggerStatement" },
     78      "resume",
     79    ],
     80    [
     81      "paused at the breakpoint at the second debugger statement",
     82      { line: 3, type: "breakpoint" },
     83      "resume",
     84    ],
     85    [
     86      "pause at the third debugger statement",
     87      { line: 4, type: "debuggerStatement" },
     88      "resume",
     89    ],
     90  ]);
     91 }
     92 
     93 // Ensure that we advance to the next line when we step to
     94 // a line with a breakpoint and resume.
     95 async function testBreakpoints({ commands, threadFront }) {
     96  commands.scriptCommand.execute(`function foo(stop) {
     97      debugger;
     98      a();
     99      debugger;
    100    }
    101    function a() {}
    102    foo();
    103    //# sourceURL=http://example.com/testBreakpoints.js`);
    104 
    105  threadFront.setBreakpoint(
    106    { sourceUrl: "http://example.com/testBreakpoints.js", line: 3, column: 6 },
    107    {}
    108  );
    109 
    110  await performActions(threadFront, [
    111    [
    112      "paused at first debugger statement",
    113      { line: 2, type: "debuggerStatement" },
    114      "stepOver",
    115    ],
    116    ["paused at a()", { line: 3, type: "resumeLimit" }, "resume"],
    117    [
    118      "pause at the second debugger satement",
    119      { line: 4, type: "debuggerStatement" },
    120      "resume",
    121    ],
    122  ]);
    123 }
    124 
    125 // Ensure that we advance to the next line when we step to
    126 // a line with a breakpoint and resume.
    127 async function testLoops({ commands, threadFront }) {
    128  commands.scriptCommand.execute(`function foo(stop) {
    129      let i = 0;
    130      debugger;
    131      while (i++ < 2) {
    132        debugger;
    133      }
    134      debugger;
    135    }
    136    foo();
    137    //# sourceURL=http://example.com/testLoops.js`);
    138 
    139  await performActions(threadFront, [
    140    [
    141      "paused at first debugger statement",
    142      { line: 3, type: "debuggerStatement" },
    143      "resume",
    144    ],
    145    [
    146      "pause at the second debugger satement",
    147      { line: 5, type: "debuggerStatement" },
    148      "resume",
    149    ],
    150    [
    151      "pause at the second debugger satement (2nd time)",
    152      { line: 5, type: "debuggerStatement" },
    153      "resume",
    154    ],
    155    [
    156      "pause at the third debugger satement",
    157      { line: 7, type: "debuggerStatement" },
    158      "resume",
    159    ],
    160  ]);
    161 }
    162 
    163 // Bug 1613165 - ensure that if you pause on a breakpoint on a line with
    164 // debugger statement, remove the breakpoint, and try to pause on the
    165 // debugger statement before pausing anywhere else, debugger pauses instead of
    166 // skipping debugger statement.
    167 async function testRemovingBreakpoint({ commands, threadFront }) {
    168  commands.scriptCommand.execute(`function foo(stop) {
    169      debugger;
    170    }
    171    foo();
    172    foo();
    173    //# sourceURL=http://example.com/testRemovingBreakpoint.js`);
    174 
    175  const location = {
    176    sourceUrl: "http://example.com/testRemovingBreakpoint.js",
    177    line: 2,
    178    column: 6,
    179  };
    180 
    181  threadFront.setBreakpoint(location, {});
    182 
    183  info("paused at the breakpoint at the first debugger statement");
    184  const packet = await waitForEvent(threadFront, "paused");
    185  Assert.equal(packet.frame.where.line, 2);
    186  Assert.equal(packet.why.type, "breakpoint");
    187  threadFront.removeBreakpoint(location);
    188 
    189  info("paused at the first debugger statement");
    190  const packet2 = await resumeAndWaitForPause(threadFront);
    191  Assert.equal(packet2.frame.where.line, 2);
    192  Assert.equal(packet2.why.type, "debuggerStatement");
    193  await threadFront.resume();
    194 }
    195 
    196 // Bug 1613165 - ensure if you pause on a debugger statement, add a
    197 // breakpoint on the same line, and try to pause on the breakpoint
    198 // before pausing anywhere else, debugger pauses on that line instead of
    199 // skipping breakpoint.
    200 async function testAddingBreakpoint({ commands, threadFront }) {
    201  commands.scriptCommand.execute(`function foo(stop) {
    202      debugger;
    203    }
    204    foo();
    205    foo();
    206    //# sourceURL=http://example.com/testAddingBreakpoint.js`);
    207 
    208  const location = {
    209    sourceUrl: "http://example.com/testAddingBreakpoint.js",
    210    line: 2,
    211    column: 6,
    212  };
    213 
    214  info("paused at the first debugger statement");
    215  const packet = await waitForEvent(threadFront, "paused");
    216  Assert.equal(packet.frame.where.line, 2);
    217  Assert.equal(packet.why.type, "debuggerStatement");
    218  threadFront.setBreakpoint(location, {});
    219 
    220  info("paused at the breakpoint at the first debugger statement");
    221  const packet2 = await resumeAndWaitForPause(threadFront);
    222  Assert.equal(packet2.frame.where.line, 2);
    223  Assert.equal(packet2.why.type, "breakpoint");
    224  await threadFront.resume();
    225 }
    226 
    227 async function performActions(threadFront, actions) {
    228  for (const action of actions) {
    229    await performAction(threadFront, action);
    230  }
    231 }
    232 
    233 async function performAction(threadFront, [description, result, action]) {
    234  info(description);
    235  const packet = await waitForEvent(threadFront, "paused");
    236  Assert.equal(packet.frame.where.line, result.line);
    237  Assert.equal(packet.why.type, result.type);
    238  await threadFront[action]();
    239 }