tor-browser

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

test_blackboxing-04.js (1850B)


      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 behavior of blackboxing sources we are currently paused in.
      8 */
      9 
     10 add_task(
     11  threadFrontTest(async ({ threadFront, debuggee }) => {
     12    // Set up
     13    await executeOnNextTickAndWaitForPause(
     14      () => evalCode(debuggee),
     15      threadFront
     16    );
     17 
     18    threadFront.setBreakpoint({ sourceUrl: BLACK_BOXED_URL, line: 2 }, {});
     19 
     20    // Test black boxing a source while pausing in the source
     21    const { error, sources } = await threadFront.getSources();
     22    Assert.ok(!error, "Should not get an error: " + error);
     23    const sourceFront = threadFront.source(
     24      sources.filter(s => s.url == BLACK_BOXED_URL)[0]
     25    );
     26 
     27    const pausedInSource = await blackBox(sourceFront);
     28    Assert.ok(
     29      pausedInSource,
     30      "We should be notified that we are currently paused in this source"
     31    );
     32    await threadFront.resume();
     33  })
     34 );
     35 
     36 const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
     37 const SOURCE_URL = "http://example.com/source.js";
     38 
     39 function evalCode(debuggee) {
     40  /* eslint-disable no-multi-spaces, no-undef */
     41  // prettier-ignore
     42  Cu.evalInSandbox(
     43    "" +
     44      function doStuff(k) { // line 1
     45        debugger;           // line 2
     46        k(100);             // line 3
     47      },                    // line 4
     48    debuggee,
     49    "1.8",
     50    BLACK_BOXED_URL,
     51    1
     52  );
     53  // prettier-ignore
     54  Cu.evalInSandbox(
     55    "" +
     56    function runTest() { // line 1
     57      doStuff(           // line 2
     58        function(n) {    // line 3
     59          return n;      // line 4
     60        }                // line 5
     61      );                 // line 6
     62    } +                  // line 7
     63      "\n runTest();",   // line 8
     64    debuggee,
     65    "1.8",
     66    SOURCE_URL,
     67    1
     68  );
     69  /* eslint-enable no-multi-spaces, no-undef */
     70 }