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

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:cf4badbf156d
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Check basic source map integration with the "sources" packet in the RDP.
6 */
7
8 var gDebuggee;
9 var gClient;
10 var gThreadClient;
11
12 Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
13
14 function run_test()
15 {
16 initTestDebuggerServer();
17 gDebuggee = addTestGlobal("test-source-map");
18 gClient = new DebuggerClient(DebuggerServer.connectPipe());
19 gClient.connect(function() {
20 attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
21 gThreadClient = aThreadClient;
22 test_simple_source_map();
23 });
24 });
25 do_test_pending();
26 }
27
28 function test_simple_source_map()
29 {
30 // Because we are source mapping, we should be notified of a.js, b.js, and
31 // c.js as sources, and shouldn"t receive abc.js or test_sourcemaps-01.js.
32 let expectedSources = new Set(["http://example.com/www/js/a.js",
33 "http://example.com/www/js/b.js",
34 "http://example.com/www/js/c.js"]);
35
36 gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
37 gThreadClient.getSources(function (aResponse) {
38 do_check_true(!aResponse.error, "Should not get an error");
39
40 for (let s of aResponse.sources) {
41 do_check_neq(s.url, "http://example.com/www/js/abc.js",
42 "Shouldn't get the generated source's url.")
43 expectedSources.delete(s.url);
44 }
45
46 do_check_eq(expectedSources.size, 0,
47 "Should have found all the expected sources sources by now.");
48
49 finishClient(gClient);
50 });
51 });
52
53 let { code, map } = (new SourceNode(null, null, null, [
54 new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
55 new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
56 new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
57 "debugger;\n"
58 ])).toStringWithSourceMap({
59 file: "abc.js",
60 sourceRoot: "http://example.com/www/js/"
61 });
62
63 code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
64
65 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
66 "http://example.com/www/js/abc.js", 1);
67 }

mercurial