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 that we can load sources whose content is embedded in the michael@0: * "sourcesContent" field of a source map. 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_source_content(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_source_content() michael@0: { michael@0: let numNewSources = 0; michael@0: michael@0: gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) { michael@0: if (++numNewSources !== 3) { michael@0: return; michael@0: } michael@0: gClient.removeListener("newSource", _onNewSource); michael@0: michael@0: gThreadClient.getSources(function (aResponse) { michael@0: do_check_true(!aResponse.error, "Should not get an error"); michael@0: michael@0: testContents(aResponse.sources, () => { michael@0: finishClient(gClient); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: let node = 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: ]); michael@0: michael@0: node.setSourceContent("a.js", "content for http://example.com/www/js/a.js"); michael@0: node.setSourceContent("b.js", "content for http://example.com/www/js/b.js"); michael@0: node.setSourceContent("c.js", "content for http://example.com/www/js/c.js"); michael@0: michael@0: let { code, map } = node.toStringWithSourceMap({ michael@0: file: "abc.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: } michael@0: michael@0: function testContents(aSources, aCallback) { michael@0: if (aSources.length === 0) { michael@0: aCallback(); michael@0: return; michael@0: } michael@0: michael@0: let source = aSources[0]; michael@0: let sourceClient = gThreadClient.source(aSources[0]); michael@0: michael@0: sourceClient.source((aResponse) => { michael@0: do_check_true(!aResponse.error, michael@0: "Should not get an error loading the source from sourcesContent"); michael@0: michael@0: let expectedContent = "content for " + source.url; michael@0: do_check_eq(aResponse.source, expectedContent, michael@0: "Should have the expected source content"); michael@0: michael@0: testContents(aSources.slice(1), aCallback); michael@0: }); michael@0: }