tor-browser

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

test_source-01.js (1567B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // This test ensures that we can create SourceActors and SourceFronts properly,
      7 // and that they can communicate over the protocol to fetch the source text for
      8 // a given script.
      9 
     10 const SOURCE_URL = "http://example.com/foobar.js";
     11 const SOURCE_CONTENT = "stopMe()";
     12 
     13 add_task(
     14  threadFrontTest(async ({ threadFront, debuggee }) => {
     15    DevToolsServer.LONG_STRING_LENGTH = 200;
     16 
     17    await executeOnNextTickAndWaitForPause(
     18      () => evaluateTestCode(debuggee),
     19      threadFront
     20    );
     21    const response = await threadFront.getSources();
     22 
     23    Assert.ok(!!response);
     24    Assert.ok(!!response.sources);
     25 
     26    const source = response.sources.filter(function (s) {
     27      return s.url === SOURCE_URL;
     28    })[0];
     29 
     30    Assert.ok(!!source);
     31 
     32    const sourceFront = threadFront.source(source);
     33    const response2 = await sourceFront.source();
     34 
     35    Assert.ok(!!response2);
     36    Assert.ok(!!response2.contentType);
     37    Assert.ok(response2.contentType.includes("javascript"));
     38 
     39    Assert.ok(!!response2.source);
     40    Assert.equal(SOURCE_CONTENT, response2.source);
     41 
     42    await threadFront.resume();
     43  })
     44 );
     45 
     46 function evaluateTestCode(debuggee) {
     47  Cu.evalInSandbox(
     48    "" +
     49      // These arguments are tested.
     50      // eslint-disable-next-line no-unused-vars
     51      function stopMe(arg1) {
     52        debugger;
     53      },
     54    debuggee,
     55    "1.8",
     56    getFileUrl("test_source-01.js")
     57  );
     58 
     59  Cu.evalInSandbox(SOURCE_CONTENT, debuggee, "1.8", SOURCE_URL);
     60 }