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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:4d3cfab901ec
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Test that we don't permanently cache sources from source maps.
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_cached_original_sources();
23 });
24 });
25 do_test_pending();
26 }
27
28 function test_cached_original_sources()
29 {
30 writeFile("temp.js", "initial content");
31
32 gClient.addOneTimeListener("newSource", onNewSource);
33
34 let node = new SourceNode(1, 0,
35 getFileUrl("temp.js"),
36 "function funcFromTemp() {}\n");
37 let { code, map } = node.toStringWithSourceMap({
38 file: "abc.js"
39 });
40 code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
41
42
43 Components.utils.evalInSandbox(code, gDebuggee, "1.8",
44 "http://example.com/www/js/abc.js", 1);
45 }
46
47 function onNewSource(aEvent, aPacket) {
48 let sourceClient = gThreadClient.source(aPacket.source);
49 sourceClient.source(function (aResponse) {
50 do_check_true(!aResponse.error,
51 "Should not be an error grabbing the source");
52 do_check_eq(aResponse.source, "initial content",
53 "The correct source content should be sent");
54
55 writeFile("temp.js", "new content");
56
57 sourceClient.source(function (aResponse) {
58 do_check_true(!aResponse.error,
59 "Should not be an error grabbing the source");
60 do_check_eq(aResponse.source, "new content",
61 "The correct source content should not be cached, so we should get the new content");
62
63 do_get_file("temp.js").remove(false);
64 finishClient(gClient);
65 });
66 });
67 }

mercurial