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 sources from 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: test_cached_original_sources(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_cached_original_sources() michael@0: { michael@0: writeFile("temp.js", "initial content"); michael@0: michael@0: gClient.addOneTimeListener("newSource", onNewSource); michael@0: michael@0: let node = new SourceNode(1, 0, michael@0: getFileUrl("temp.js"), michael@0: "function funcFromTemp() {}\n"); michael@0: let { code, map } = node.toStringWithSourceMap({ michael@0: file: "abc.js" michael@0: }); michael@0: code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()); michael@0: michael@0: michael@0: Components.utils.evalInSandbox(code, gDebuggee, "1.8", michael@0: "http://example.com/www/js/abc.js", 1); michael@0: } michael@0: michael@0: function onNewSource(aEvent, aPacket) { michael@0: let sourceClient = gThreadClient.source(aPacket.source); michael@0: sourceClient.source(function (aResponse) { michael@0: do_check_true(!aResponse.error, michael@0: "Should not be an error grabbing the source"); michael@0: do_check_eq(aResponse.source, "initial content", michael@0: "The correct source content should be sent"); michael@0: michael@0: writeFile("temp.js", "new content"); michael@0: michael@0: sourceClient.source(function (aResponse) { michael@0: do_check_true(!aResponse.error, michael@0: "Should not be an error grabbing the source"); michael@0: do_check_eq(aResponse.source, "new content", michael@0: "The correct source content should not be cached, so we should get the new content"); michael@0: michael@0: do_get_file("temp.js").remove(false); michael@0: finishClient(gClient); michael@0: }); michael@0: }); michael@0: }