|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that prettifying JS sources with type errors works as expected. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_included-script.html"; |
|
9 const JS_URL = EXAMPLE_URL + "code_location-changes.js"; |
|
10 |
|
11 let gTab, gDebuggee, gPanel, gDebugger, gClient; |
|
12 let gEditor, gSources, gControllerSources, gPrettyPrinted; |
|
13 |
|
14 function test() { |
|
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
16 gTab = aTab; |
|
17 gDebuggee = aDebuggee; |
|
18 gPanel = aPanel; |
|
19 gDebugger = gPanel.panelWin; |
|
20 gClient = gDebugger.gClient; |
|
21 gEditor = gDebugger.DebuggerView.editor; |
|
22 gSources = gDebugger.DebuggerView.Sources; |
|
23 gControllerSources = gDebugger.DebuggerController.SourceScripts; |
|
24 |
|
25 // We can't feed javascript files with syntax errors to the debugger, |
|
26 // because they will never run, thus sometimes getting gc'd before the |
|
27 // debugger is opened, or even before the target finishes navigating. |
|
28 // Make the client lie about being able to parse perfectly fine code. |
|
29 gClient.request = (function (aOriginalRequestMethod) { |
|
30 return function (aPacket, aCallback) { |
|
31 if (aPacket.type == "prettyPrint") { |
|
32 gPrettyPrinted = true; |
|
33 return executeSoon(() => aCallback({ error: "prettyPrintError" })); |
|
34 } |
|
35 return aOriginalRequestMethod(aPacket, aCallback); |
|
36 }; |
|
37 }(gClient.request)); |
|
38 |
|
39 Task.spawn(function() { |
|
40 yield waitForSourceShown(gPanel, JS_URL); |
|
41 |
|
42 // From this point onward, the source editor's text should never change. |
|
43 gEditor.once("change", () => { |
|
44 ok(false, "The source editor text shouldn't have changed."); |
|
45 }); |
|
46 |
|
47 is(gSources.selectedValue, JS_URL, |
|
48 "The correct source is currently selected."); |
|
49 ok(gEditor.getText().contains("myFunction"), |
|
50 "The source shouldn't be pretty printed yet."); |
|
51 |
|
52 clickPrettyPrintButton(); |
|
53 |
|
54 let { source } = gSources.selectedItem.attachment; |
|
55 try { |
|
56 yield gControllerSources.togglePrettyPrint(source); |
|
57 ok(false, "The promise for a prettified source should be rejected!"); |
|
58 } catch ([source, error]) { |
|
59 ok(error.contains("prettyPrintError"), |
|
60 "The promise was correctly rejected with a meaningful message."); |
|
61 } |
|
62 |
|
63 let [source, text] = yield gControllerSources.getText(source); |
|
64 is(gSources.selectedValue, JS_URL, |
|
65 "The correct source is still selected."); |
|
66 ok(gEditor.getText().contains("myFunction"), |
|
67 "The displayed source hasn't changed."); |
|
68 ok(text.contains("myFunction"), |
|
69 "The cached source text wasn't altered in any way."); |
|
70 |
|
71 is(gPrettyPrinted, true, |
|
72 "The hijacked pretty print method was executed."); |
|
73 |
|
74 yield closeDebuggerAndFinish(gPanel); |
|
75 }); |
|
76 }); |
|
77 } |
|
78 |
|
79 function clickPrettyPrintButton() { |
|
80 gDebugger.document.getElementById("pretty-print").click(); |
|
81 } |
|
82 |
|
83 registerCleanupFunction(function() { |
|
84 gTab = null; |
|
85 gDebuggee = null; |
|
86 gPanel = null; |
|
87 gDebugger = null; |
|
88 gClient = null; |
|
89 gEditor = null; |
|
90 gSources = null; |
|
91 gControllerSources = null; |
|
92 gPrettyPrinted = null; |
|
93 }); |