toolkit/devtools/server/tests/unit/test_sourcemaps-06.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_sourcemaps-06.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Check that we can load sources whose content is embedded in the
     1.9 + * "sourcesContent" field of a source map.
    1.10 + */
    1.11 +
    1.12 +var gDebuggee;
    1.13 +var gClient;
    1.14 +var gThreadClient;
    1.15 +
    1.16 +Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
    1.17 +
    1.18 +function run_test()
    1.19 +{
    1.20 +  initTestDebuggerServer();
    1.21 +  gDebuggee = addTestGlobal("test-source-map");
    1.22 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.23 +  gClient.connect(function() {
    1.24 +    attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
    1.25 +      gThreadClient = aThreadClient;
    1.26 +      test_source_content();
    1.27 +    });
    1.28 +  });
    1.29 +  do_test_pending();
    1.30 +}
    1.31 +
    1.32 +function test_source_content()
    1.33 +{
    1.34 +  let numNewSources = 0;
    1.35 +
    1.36 +  gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) {
    1.37 +    if (++numNewSources !== 3) {
    1.38 +      return;
    1.39 +    }
    1.40 +    gClient.removeListener("newSource", _onNewSource);
    1.41 +
    1.42 +    gThreadClient.getSources(function (aResponse) {
    1.43 +      do_check_true(!aResponse.error, "Should not get an error");
    1.44 +
    1.45 +      testContents(aResponse.sources, () => {
    1.46 +        finishClient(gClient);
    1.47 +      });
    1.48 +    });
    1.49 +  });
    1.50 +
    1.51 +  let node = new SourceNode(null, null, null, [
    1.52 +    new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
    1.53 +    new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
    1.54 +    new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
    1.55 +  ]);
    1.56 +
    1.57 +  node.setSourceContent("a.js", "content for http://example.com/www/js/a.js");
    1.58 +  node.setSourceContent("b.js", "content for http://example.com/www/js/b.js");
    1.59 +  node.setSourceContent("c.js", "content for http://example.com/www/js/c.js");
    1.60 +
    1.61 +  let { code, map } = node.toStringWithSourceMap({
    1.62 +    file: "abc.js"
    1.63 +  });
    1.64 +
    1.65 +  code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
    1.66 +
    1.67 +  Components.utils.evalInSandbox(code, gDebuggee, "1.8",
    1.68 +                                 "http://example.com/www/js/abc.js", 1);
    1.69 +}
    1.70 +
    1.71 +function testContents(aSources, aCallback) {
    1.72 +  if (aSources.length === 0) {
    1.73 +    aCallback();
    1.74 +    return;
    1.75 +  }
    1.76 +
    1.77 +  let source = aSources[0];
    1.78 +  let sourceClient = gThreadClient.source(aSources[0]);
    1.79 +
    1.80 +  sourceClient.source((aResponse) => {
    1.81 +    do_check_true(!aResponse.error,
    1.82 +                  "Should not get an error loading the source from sourcesContent");
    1.83 +
    1.84 +    let expectedContent = "content for " + source.url;
    1.85 +    do_check_eq(aResponse.source, expectedContent,
    1.86 +                "Should have the expected source content");
    1.87 +
    1.88 +    testContents(aSources.slice(1), aCallback);
    1.89 +  });
    1.90 +}

mercurial