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 "newSource" 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.addListener("newSource", function _onNewSource(aEvent, aPacket) { michael@0: do_check_eq(aEvent, "newSource"); michael@0: do_check_eq(aPacket.type, "newSource"); michael@0: do_check_true(!!aPacket.source); michael@0: michael@0: do_check_true(expectedSources.has(aPacket.source.url), michael@0: "The source url should be one of our original sources."); michael@0: expectedSources.delete(aPacket.source.url); michael@0: michael@0: if (expectedSources.size === 0) { michael@0: gClient.removeListener("newSource", _onNewSource); 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: ])).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: }