toolkit/devtools/server/tests/unit/test_sourcemaps-13.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-13.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     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 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 +      setup_code();
    1.26 +    });
    1.27 +  });
    1.28 +  do_test_pending();
    1.29 +}
    1.30 +
    1.31 +// The MAP_FILE_NAME is .txt so that the OS will definitely have an extension ->
    1.32 +// content type mapping for the extension. If it doesn't (like .map or .json),
    1.33 +// it logs console errors, which cause the test to fail. See bug 907839.
    1.34 +const MAP_FILE_NAME = "temporary-generated.txt";
    1.35 +
    1.36 +const TEMP_FILE_1 = "temporary1.js";
    1.37 +const TEMP_FILE_2 = "temporary2.js";
    1.38 +const TEMP_GENERATED_SOURCE = "temporary-generated.js";
    1.39 +
    1.40 +function setup_code() {
    1.41 +  let node = new SourceNode(1, 0,
    1.42 +                            getFileUrl(TEMP_FILE_1, true),
    1.43 +                            "function temporary1() {}\n");
    1.44 +  let { code, map } = node.toStringWithSourceMap({
    1.45 +    file: getFileUrl(TEMP_GENERATED_SOURCE, true)
    1.46 +  });
    1.47 +
    1.48 +  code += "//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true);
    1.49 +  writeFile(MAP_FILE_NAME, map.toString());
    1.50 +
    1.51 +  Cu.evalInSandbox(code,
    1.52 +                   gDebuggee,
    1.53 +                   "1.8",
    1.54 +                   getFileUrl(TEMP_GENERATED_SOURCE, true),
    1.55 +                   1);
    1.56 +
    1.57 +  test_initial_sources();
    1.58 +}
    1.59 +
    1.60 +function test_initial_sources() {
    1.61 +  gThreadClient.getSources(function ({ error, sources }) {
    1.62 +    do_check_true(!error);
    1.63 +    do_check_eq(sources.length, 1);
    1.64 +    do_check_eq(sources[0].url, getFileUrl(TEMP_FILE_1, true));
    1.65 +    setup_new_code();
    1.66 +  });
    1.67 +}
    1.68 +
    1.69 +function setup_new_code() {
    1.70 +  let node = new SourceNode(1, 0,
    1.71 +                            getFileUrl(TEMP_FILE_2, true),
    1.72 +                            "function temporary2() {}\n");
    1.73 +  let { code, map } = node.toStringWithSourceMap({
    1.74 +    file: getFileUrl(TEMP_GENERATED_SOURCE, true)
    1.75 +  });
    1.76 +
    1.77 +  code += "\n//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true);
    1.78 +  writeFile(MAP_FILE_NAME, map.toString());
    1.79 +
    1.80 +  Cu.evalInSandbox(code,
    1.81 +                   gDebuggee,
    1.82 +                   "1.8",
    1.83 +                   getFileUrl(TEMP_GENERATED_SOURCE, true),
    1.84 +                   1);
    1.85 +
    1.86 +  gClient.addOneTimeListener("newSource", test_new_sources);
    1.87 +}
    1.88 +
    1.89 +function test_new_sources() {
    1.90 +  gThreadClient.getSources(function ({ error, sources }) {
    1.91 +    do_check_true(!error);
    1.92 +
    1.93 +    // Should now have TEMP_FILE_2 as a source.
    1.94 +    do_check_eq(sources.length, 2);
    1.95 +    let s = sources.filter(s => s.url === getFileUrl(TEMP_FILE_2, true))[0];
    1.96 +    do_check_true(!!s);
    1.97 +
    1.98 +    finish_test();
    1.99 +  });
   1.100 +}
   1.101 +
   1.102 +function finish_test() {
   1.103 +  do_get_file(MAP_FILE_NAME).remove(false);
   1.104 +  finishClient(gClient);
   1.105 +}

mercurial