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: * Check basic source map integration with the "sources" packet in the RDP. 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_simple_source_map(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_simple_source_map() michael@0: { michael@0: // Because we are source mapping, we should be notified of a.js, b.js, and michael@0: // c.js as sources, and shouldn"t receive abc.js or test_sourcemaps-01.js. michael@0: let expectedSources = new Set(["http://example.com/www/js/a.js", michael@0: "http://example.com/www/js/b.js", michael@0: "http://example.com/www/js/c.js"]); michael@0: michael@0: gClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: gThreadClient.getSources(function (aResponse) { michael@0: do_check_true(!aResponse.error, "Should not get an error"); michael@0: michael@0: for (let s of aResponse.sources) { michael@0: do_check_neq(s.url, "http://example.com/www/js/abc.js", michael@0: "Shouldn't get the generated source's url.") michael@0: expectedSources.delete(s.url); michael@0: } michael@0: michael@0: do_check_eq(expectedSources.size, 0, michael@0: "Should have found all the expected sources sources by now."); michael@0: michael@0: finishClient(gClient); michael@0: }); michael@0: }); michael@0: michael@0: let { code, map } = (new SourceNode(null, null, null, [ michael@0: new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"), michael@0: new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"), michael@0: new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"), michael@0: "debugger;\n" michael@0: ])).toStringWithSourceMap({ michael@0: file: "abc.js", michael@0: sourceRoot: "http://example.com/www/js/" michael@0: }); michael@0: michael@0: code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString()); michael@0: michael@0: Components.utils.evalInSandbox(code, gDebuggee, "1.8", michael@0: "http://example.com/www/js/abc.js", 1); michael@0: }