toolkit/devtools/server/tests/unit/test_sourcemaps-06.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:9b52f7c17952
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Check that we can load sources whose content is embedded in the
6 * "sourcesContent" field of a source map.
7 */
8
9 var gDebuggee;
10 var gClient;
11 var gThreadClient;
12
13 Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
14
15 function run_test()
16 {
17 initTestDebuggerServer();
18 gDebuggee = addTestGlobal("test-source-map");
19 gClient = new DebuggerClient(DebuggerServer.connectPipe());
20 gClient.connect(function() {
21 attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
22 gThreadClient = aThreadClient;
23 test_source_content();
24 });
25 });
26 do_test_pending();
27 }
28
29 function test_source_content()
30 {
31 let numNewSources = 0;
32
33 gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) {
34 if (++numNewSources !== 3) {
35 return;
36 }
37 gClient.removeListener("newSource", _onNewSource);
38
39 gThreadClient.getSources(function (aResponse) {
40 do_check_true(!aResponse.error, "Should not get an error");
41
42 testContents(aResponse.sources, () => {
43 finishClient(gClient);
44 });
45 });
46 });
47
48 let node = new SourceNode(null, null, null, [
49 new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
50 new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
51 new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
52 ]);
53
54 node.setSourceContent("a.js", "content for http://example.com/www/js/a.js");
55 node.setSourceContent("b.js", "content for http://example.com/www/js/b.js");
56 node.setSourceContent("c.js", "content for http://example.com/www/js/c.js");
57
58 let { code, map } = node.toStringWithSourceMap({
59 file: "abc.js"
60 });
61
62 code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
63
64 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
65 "http://example.com/www/js/abc.js", 1);
66 }
67
68 function testContents(aSources, aCallback) {
69 if (aSources.length === 0) {
70 aCallback();
71 return;
72 }
73
74 let source = aSources[0];
75 let sourceClient = gThreadClient.source(aSources[0]);
76
77 sourceClient.source((aResponse) => {
78 do_check_true(!aResponse.error,
79 "Should not get an error loading the source from sourcesContent");
80
81 let expectedContent = "content for " + source.url;
82 do_check_eq(aResponse.source, expectedContent,
83 "Should have the expected source content");
84
85 testContents(aSources.slice(1), aCallback);
86 });
87 }

mercurial