toolkit/devtools/server/tests/unit/test_sourcemaps-07.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-07.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     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 + * Test that we don't permanently cache sources from source maps.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +
    1.15 +Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
    1.16 +
    1.17 +function run_test()
    1.18 +{
    1.19 +  initTestDebuggerServer();
    1.20 +  gDebuggee = addTestGlobal("test-source-map");
    1.21 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.22 +  gClient.connect(function() {
    1.23 +    attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
    1.24 +      gThreadClient = aThreadClient;
    1.25 +      test_cached_original_sources();
    1.26 +    });
    1.27 +  });
    1.28 +  do_test_pending();
    1.29 +}
    1.30 +
    1.31 +function test_cached_original_sources()
    1.32 +{
    1.33 +  writeFile("temp.js", "initial content");
    1.34 +
    1.35 +  gClient.addOneTimeListener("newSource", onNewSource);
    1.36 +
    1.37 +  let node = new SourceNode(1, 0,
    1.38 +                            getFileUrl("temp.js"),
    1.39 +                            "function funcFromTemp() {}\n");
    1.40 +  let { code, map } = node.toStringWithSourceMap({
    1.41 +    file: "abc.js"
    1.42 +  });
    1.43 +  code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
    1.44 +
    1.45 +
    1.46 +  Components.utils.evalInSandbox(code, gDebuggee, "1.8",
    1.47 +                                 "http://example.com/www/js/abc.js", 1);
    1.48 +}
    1.49 +
    1.50 +function onNewSource(aEvent, aPacket) {
    1.51 +  let sourceClient = gThreadClient.source(aPacket.source);
    1.52 +  sourceClient.source(function (aResponse) {
    1.53 +    do_check_true(!aResponse.error,
    1.54 +                  "Should not be an error grabbing the source");
    1.55 +    do_check_eq(aResponse.source, "initial content",
    1.56 +                "The correct source content should be sent");
    1.57 +
    1.58 +    writeFile("temp.js", "new content");
    1.59 +
    1.60 +    sourceClient.source(function (aResponse) {
    1.61 +      do_check_true(!aResponse.error,
    1.62 +                    "Should not be an error grabbing the source");
    1.63 +      do_check_eq(aResponse.source, "new content",
    1.64 +                  "The correct source content should not be cached, so we should get the new content");
    1.65 +
    1.66 +      do_get_file("temp.js").remove(false);
    1.67 +      finishClient(gClient);
    1.68 +    });
    1.69 +  });
    1.70 +}

mercurial