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

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:d6f584893df8
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 "newSource" 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.addListener("newSource", function _onNewSource(aEvent, aPacket) {
37 do_check_eq(aEvent, "newSource");
38 do_check_eq(aPacket.type, "newSource");
39 do_check_true(!!aPacket.source);
40
41 do_check_true(expectedSources.has(aPacket.source.url),
42 "The source url should be one of our original sources.");
43 expectedSources.delete(aPacket.source.url);
44
45 if (expectedSources.size === 0) {
46 gClient.removeListener("newSource", _onNewSource);
47 finishClient(gClient);
48 }
49 });
50
51 let { code, map } = (new SourceNode(null, null, null, [
52 new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
53 new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
54 new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
55 ])).toStringWithSourceMap({
56 file: "abc.js",
57 sourceRoot: "http://example.com/www/js/"
58 });
59
60 code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
61
62 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
63 "http://example.com/www/js/abc.js", 1);
64 }

mercurial