|
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 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 setup_code(); |
|
23 }); |
|
24 }); |
|
25 do_test_pending(); |
|
26 } |
|
27 |
|
28 // The MAP_FILE_NAME is .txt so that the OS will definitely have an extension -> |
|
29 // content type mapping for the extension. If it doesn't (like .map or .json), |
|
30 // it logs console errors, which cause the test to fail. See bug 907839. |
|
31 const MAP_FILE_NAME = "temporary-generated.txt"; |
|
32 |
|
33 const TEMP_FILE_1 = "temporary1.js"; |
|
34 const TEMP_FILE_2 = "temporary2.js"; |
|
35 const TEMP_GENERATED_SOURCE = "temporary-generated.js"; |
|
36 |
|
37 function setup_code() { |
|
38 let node = new SourceNode(1, 0, |
|
39 getFileUrl(TEMP_FILE_1, true), |
|
40 "function temporary1() {}\n"); |
|
41 let { code, map } = node.toStringWithSourceMap({ |
|
42 file: getFileUrl(TEMP_GENERATED_SOURCE, true) |
|
43 }); |
|
44 |
|
45 code += "//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true); |
|
46 writeFile(MAP_FILE_NAME, map.toString()); |
|
47 |
|
48 Cu.evalInSandbox(code, |
|
49 gDebuggee, |
|
50 "1.8", |
|
51 getFileUrl(TEMP_GENERATED_SOURCE, true), |
|
52 1); |
|
53 |
|
54 test_initial_sources(); |
|
55 } |
|
56 |
|
57 function test_initial_sources() { |
|
58 gThreadClient.getSources(function ({ error, sources }) { |
|
59 do_check_true(!error); |
|
60 do_check_eq(sources.length, 1); |
|
61 do_check_eq(sources[0].url, getFileUrl(TEMP_FILE_1, true)); |
|
62 setup_new_code(); |
|
63 }); |
|
64 } |
|
65 |
|
66 function setup_new_code() { |
|
67 let node = new SourceNode(1, 0, |
|
68 getFileUrl(TEMP_FILE_2, true), |
|
69 "function temporary2() {}\n"); |
|
70 let { code, map } = node.toStringWithSourceMap({ |
|
71 file: getFileUrl(TEMP_GENERATED_SOURCE, true) |
|
72 }); |
|
73 |
|
74 code += "\n//# sourceMappingURL=" + getFileUrl(MAP_FILE_NAME, true); |
|
75 writeFile(MAP_FILE_NAME, map.toString()); |
|
76 |
|
77 Cu.evalInSandbox(code, |
|
78 gDebuggee, |
|
79 "1.8", |
|
80 getFileUrl(TEMP_GENERATED_SOURCE, true), |
|
81 1); |
|
82 |
|
83 gClient.addOneTimeListener("newSource", test_new_sources); |
|
84 } |
|
85 |
|
86 function test_new_sources() { |
|
87 gThreadClient.getSources(function ({ error, sources }) { |
|
88 do_check_true(!error); |
|
89 |
|
90 // Should now have TEMP_FILE_2 as a source. |
|
91 do_check_eq(sources.length, 2); |
|
92 let s = sources.filter(s => s.url === getFileUrl(TEMP_FILE_2, true))[0]; |
|
93 do_check_true(!!s); |
|
94 |
|
95 finish_test(); |
|
96 }); |
|
97 } |
|
98 |
|
99 function finish_test() { |
|
100 do_get_file(MAP_FILE_NAME).remove(false); |
|
101 finishClient(gClient); |
|
102 } |