tor-browser

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

test_stepping-16.js (2310B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Test stepping from inside a blackboxed function
      8 * test-page: https://dbg-blackbox-stepping2.glitch.me/
      9 */
     10 
     11 async function invokeAndPause({ global, threadFront }, expression, url) {
     12  return executeOnNextTickAndWaitForPause(
     13    () => Cu.evalInSandbox(expression, global, "1.8", url, 1),
     14    threadFront
     15  );
     16 }
     17 
     18 add_task(
     19  threadFrontTest(async ({ commands, threadFront, debuggee }) => {
     20    const dbg = { global: debuggee, threadFront };
     21    invokeAndPause(
     22      dbg,
     23      `function outermost() {
     24        blackboxed(
     25          function inner1() {
     26            return 1;
     27          },
     28          function inner2() {
     29            return 2;
     30          }
     31        );
     32      }`,
     33      "http://example.com/unblackboxed.js"
     34    );
     35    invokeAndPause(
     36      dbg,
     37      `function blackboxed(...args) {
     38        for (const arg of args) {
     39          arg();
     40        }
     41      }`,
     42      "http://example.com/blackboxed.js"
     43    );
     44 
     45    const { sources } = await getSources(threadFront);
     46    const blackboxedSourceFront = threadFront.source(
     47      sources.find(source => source.url == "http://example.com/blackboxed.js")
     48    );
     49    const unblackboxedSource = sources.find(
     50      source => source.url == "http://example.com/unblackboxed.js"
     51    );
     52    const unblackboxedActor = unblackboxedSource.actor;
     53    const unblackboxedSourceFront = threadFront.source(unblackboxedSource);
     54 
     55    await setBreakpoint(threadFront, {
     56      sourceUrl: unblackboxedSourceFront.url,
     57      line: 4,
     58    });
     59    blackBox(blackboxedSourceFront);
     60 
     61    async function testStepping(action, expectedLine) {
     62      commands.scriptCommand.execute("outermost()");
     63      await waitForPause(threadFront);
     64      await stepOver(threadFront);
     65      const packet = await action(threadFront);
     66      const { actor, line } = packet.frame.where;
     67      equal(actor, unblackboxedActor, "Paused in unblackboxed source");
     68      equal(line, expectedLine, "Paused at correct line");
     69      await threadFront.resume();
     70    }
     71 
     72    info("Step Out to outermost");
     73    await testStepping(stepOut, 10);
     74 
     75    info("Step Over to outermost");
     76    await testStepping(stepOver, 10);
     77 
     78    info("Step In to inner2");
     79    await testStepping(stepIn, 7);
     80  })
     81 );