tor-browser

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

test_blackboxing-02.js (2462B)


      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 that we don't hit breakpoints in black boxed sources, and that when we
      8 * unblack box the source again, the breakpoint hasn't disappeared and we will
      9 * hit it again.
     10 */
     11 
     12 const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
     13 const SOURCE_URL = "http://example.com/source.js";
     14 
     15 add_task(
     16  threadFrontTest(async ({ threadFront, debuggee }) => {
     17    // Set up
     18    await executeOnNextTickAndWaitForPause(
     19      () => evalCode(debuggee),
     20      threadFront
     21    );
     22 
     23    threadFront.setBreakpoint({ sourceUrl: BLACK_BOXED_URL, line: 2 }, {});
     24    await threadFront.resume();
     25 
     26    // Test the breakpoint in the black boxed source
     27    const { error, sources } = await threadFront.getSources();
     28    Assert.ok(!error, "Should not get an error: " + error);
     29    const sourceFront = threadFront.source(
     30      sources.filter(s => s.url == BLACK_BOXED_URL)[0]
     31    );
     32 
     33    await blackBox(sourceFront);
     34 
     35    const packet1 = await executeOnNextTickAndWaitForPause(
     36      debuggee.runTest,
     37      threadFront
     38    );
     39 
     40    Assert.equal(
     41      packet1.why.type,
     42      "debuggerStatement",
     43      "We should pass over the breakpoint since the source is black boxed."
     44    );
     45 
     46    await threadFront.resume();
     47 
     48    // Test the breakpoint in the unblack boxed source
     49    await unBlackBox(sourceFront);
     50 
     51    const packet2 = await executeOnNextTickAndWaitForPause(
     52      debuggee.runTest,
     53      threadFront
     54    );
     55 
     56    Assert.equal(
     57      packet2.why.type,
     58      "breakpoint",
     59      "We should hit the breakpoint again"
     60    );
     61 
     62    await threadFront.resume();
     63  })
     64 );
     65 
     66 function evalCode(debuggee) {
     67  /* eslint-disable no-undef */
     68  // prettier-ignore
     69  Cu.evalInSandbox(
     70    "" + function doStuff(k) { // line 1
     71      const arg = 15;          // line 2 - Break here
     72      k(arg);                  // line 3
     73    },                         // line 4
     74    debuggee,
     75    "1.8",
     76    BLACK_BOXED_URL,
     77    1
     78  );
     79  // prettier-ignore
     80  Cu.evalInSandbox(
     81    "" + function runTest() { // line 1
     82      doStuff(                // line 2
     83        function() {         // line 3
     84          debugger;           // line 5
     85        }                     // line 6
     86      );                      // line 7
     87    }                         // line 8
     88    + "\n debugger;",         // line 9
     89    debuggee,
     90    "1.8",
     91    SOURCE_URL,
     92    1
     93  );
     94  /* eslint-enable no-undef */
     95 }