michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Test that we don't permanently cache source maps. michael@0: */ michael@0: michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gThreadClient; michael@0: michael@0: Components.utils.import("resource:///modules/devtools/SourceMap.jsm"); michael@0: michael@0: function run_test() michael@0: { michael@0: initTestDebuggerServer(); michael@0: gDebuggee = addTestGlobal("test-source-map"); michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function() { michael@0: attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { michael@0: gThreadClient = aThreadClient; michael@0: setup_code(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: // The MAP_FILE_NAME is .txt so that the OS will definitely have an extension -> michael@0: // content type mapping for the extension. If it doesn't (like .map or .json), michael@0: // it logs console errors, which cause the test to fail. See bug 907839. michael@0: const MAP_FILE_NAME = "temporary-generated.txt"; michael@0: michael@0: const TEMP_FILE_1 = "temporary1.js"; michael@0: const TEMP_FILE_2 = "temporary2.js"; michael@0: const TEMP_GENERATED_SOURCE = "temporary-generated.js"; michael@0: michael@0: function setup_code() { michael@0: let node = new SourceNode(1, 0, michael@0: getFileUrl(TEMP_FILE_1, true), michael@0: "function temporary1() {}\n"); michael@0: let { code, map } = node.toStringWithSourceMap({ michael@0: file: getFileUrl(TEMP_GENERATED_SOURCE, true) michael@0: }); michael@0: michael@0: code += "//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true); michael@0: writeFile(MAP_FILE_NAME, map.toString()); michael@0: michael@0: Cu.evalInSandbox(code, michael@0: gDebuggee, michael@0: "1.8", michael@0: getFileUrl(TEMP_GENERATED_SOURCE, true), michael@0: 1); michael@0: michael@0: test_initial_sources(); michael@0: } michael@0: michael@0: function test_initial_sources() { michael@0: gThreadClient.getSources(function ({ error, sources }) { michael@0: do_check_true(!error); michael@0: do_check_eq(sources.length, 1); michael@0: do_check_eq(sources[0].url, getFileUrl(TEMP_FILE_1, true)); michael@0: setup_new_code(); michael@0: }); michael@0: } michael@0: michael@0: function setup_new_code() { michael@0: let node = new SourceNode(1, 0, michael@0: getFileUrl(TEMP_FILE_2, true), michael@0: "function temporary2() {}\n"); michael@0: let { code, map } = node.toStringWithSourceMap({ michael@0: file: getFileUrl(TEMP_GENERATED_SOURCE, true) michael@0: }); michael@0: michael@0: code += "\n//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true); michael@0: writeFile(MAP_FILE_NAME, map.toString()); michael@0: michael@0: Cu.evalInSandbox(code, michael@0: gDebuggee, michael@0: "1.8", michael@0: getFileUrl(TEMP_GENERATED_SOURCE, true), michael@0: 1); michael@0: michael@0: gClient.addOneTimeListener("newSource", test_new_sources); michael@0: } michael@0: michael@0: function test_new_sources() { michael@0: gThreadClient.getSources(function ({ error, sources }) { michael@0: do_check_true(!error); michael@0: michael@0: // Should now have TEMP_FILE_2 as a source. michael@0: do_check_eq(sources.length, 2); michael@0: let s = sources.filter(s => s.url === getFileUrl(TEMP_FILE_2, true))[0]; michael@0: do_check_true(!!s); michael@0: michael@0: finish_test(); michael@0: }); michael@0: } michael@0: michael@0: function finish_test() { michael@0: do_get_file(MAP_FILE_NAME).remove(false); michael@0: finishClient(gClient); michael@0: }