tor-browser

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

test_breakpoint-12.js (3375B)


      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 * Make sure that setting a breakpoint twice in a line without bytecodes works
      9 * as expected.
     10 */
     11 
     12 const NUM_BREAKPOINTS = 10;
     13 var gBpActor;
     14 var gCount;
     15 
     16 add_task(
     17  threadFrontTest(({ threadFront, debuggee }) => {
     18    return new Promise(resolve => {
     19      threadFront.once("paused", async function (packet) {
     20        const source = await getSourceById(
     21          threadFront,
     22          packet.frame.where.actor
     23        );
     24        const location = { line: debuggee.line0 + 3 };
     25 
     26        source.setBreakpoint(location).then(function ([response]) {
     27          // Check that the breakpoint has properly skipped forward one line.
     28          Assert.equal(response.actualLocation.source.actor, source.actor);
     29          Assert.equal(response.actualLocation.line, location.line + 1);
     30          gBpActor = response.actor;
     31 
     32          // Set more breakpoints at the same location.
     33          set_breakpoints(source, location);
     34        });
     35      });
     36 
     37      /* eslint-disable no-multi-spaces */
     38      Cu.evalInSandbox(
     39        "var line0 = Error().lineNumber;\n" +
     40          "function foo() {\n" + // line0 + 1
     41          "  this.a = 1;\n" + // line0 + 2
     42          "  // A comment.\n" + // line0 + 3
     43          "  this.b = 2;\n" + // line0 + 4
     44          "}\n" + // line0 + 5
     45          "debugger;\n" + // line0 + 6
     46          "foo();\n", // line0 + 7
     47        debuggee
     48      );
     49      /* eslint-enable no-multi-spaces */
     50 
     51      // Set many breakpoints at the same location.
     52      function set_breakpoints(source, location) {
     53        Assert.notEqual(gCount, NUM_BREAKPOINTS);
     54        source.setBreakpoint(location).then(function ([response, bpClient]) {
     55          // Check that the breakpoint has properly skipped forward one line.
     56          Assert.equal(response.actualLocation.source.actor, source.actor);
     57          Assert.equal(response.actualLocation.line, location.line + 1);
     58          // Check that the same breakpoint actor was returned.
     59          Assert.equal(response.actor, gBpActor);
     60 
     61          if (++gCount < NUM_BREAKPOINTS) {
     62            set_breakpoints(source, location);
     63            return;
     64          }
     65 
     66          // After setting all the breakpoints, check that only one has effectively
     67          // remained.
     68          threadFront.once("paused", function (packet) {
     69            // Check the return value.
     70            Assert.equal(packet.frame.where.actor, source.actor);
     71            Assert.equal(packet.frame.where.line, location.line + 1);
     72            Assert.equal(packet.why.type, "breakpoint");
     73            Assert.equal(packet.why.actors[0], bpClient.actor);
     74            // Check that the breakpoint worked.
     75            Assert.equal(debuggee.a, 1);
     76            Assert.equal(debuggee.b, undefined);
     77 
     78            threadFront.once("paused", function () {
     79              // We don't expect any more pauses after the breakpoint was hit once.
     80              Assert.ok(false);
     81            });
     82            threadFront.resume().then(function () {
     83              // Give any remaining breakpoints a chance to trigger.
     84              do_timeout(1000, resolve);
     85            });
     86          });
     87          // Continue until the breakpoint is hit.
     88          threadFront.resume();
     89        });
     90      }
     91    });
     92  })
     93 );