|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test that auto pretty printing doesn't accidentally toggle |
|
6 * pretty printing off when we switch to a minified source |
|
7 * that is already pretty printed. |
|
8 */ |
|
9 |
|
10 const TAB_URL = EXAMPLE_URL + "doc_auto-pretty-print-02.html"; |
|
11 |
|
12 let gTab, gDebuggee, gPanel, gDebugger; |
|
13 let gEditor, gSources, gPrefs, gOptions, gView; |
|
14 |
|
15 let gFirstSourceLabel = "code_ugly-6.js"; |
|
16 let gSecondSourceLabel = "code_ugly-7.js"; |
|
17 |
|
18 let gOriginalPref = Services.prefs.getBoolPref("devtools.debugger.auto-pretty-print"); |
|
19 Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true); |
|
20 |
|
21 function test(){ |
|
22 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
23 gTab = aTab; |
|
24 gDebuggee = aDebuggee; |
|
25 gPanel = aPanel; |
|
26 gDebugger = gPanel.panelWin; |
|
27 gEditor = gDebugger.DebuggerView.editor; |
|
28 gSources = gDebugger.DebuggerView.Sources; |
|
29 gPrefs = gDebugger.Prefs; |
|
30 gOptions = gDebugger.DebuggerView.Options; |
|
31 gView = gDebugger.DebuggerView; |
|
32 |
|
33 // Should be on by default. |
|
34 testAutoPrettyPrintOn(); |
|
35 |
|
36 waitForSourceShown(gPanel, gFirstSourceLabel) |
|
37 .then(testSourceIsUgly) |
|
38 .then(() => waitForSourceShown(gPanel, gFirstSourceLabel)) |
|
39 .then(testSourceIsPretty) |
|
40 .then(testPrettyPrintButtonOn) |
|
41 .then(() => { |
|
42 // Switch to the second source. |
|
43 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); |
|
44 gSources.selectedIndex = 1; |
|
45 return finished; |
|
46 }) |
|
47 .then(testSecondSourceLabel) |
|
48 .then(() => { |
|
49 // Switch back to first source. |
|
50 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); |
|
51 gSources.selectedIndex = 0; |
|
52 return finished; |
|
53 }) |
|
54 .then(testFirstSourceLabel) |
|
55 .then(testPrettyPrintButtonOn) |
|
56 // Disable auto pretty printing so it does not affect the following tests. |
|
57 .then(disableAutoPrettyPrint) |
|
58 .then(() => closeDebuggerAndFinish(gPanel)) |
|
59 .then(null, aError => { |
|
60 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError)); |
|
61 }) |
|
62 }); |
|
63 } |
|
64 |
|
65 function testSourceIsUgly() { |
|
66 ok(!gEditor.getText().contains("\n "), |
|
67 "The source shouldn't be pretty printed yet."); |
|
68 } |
|
69 |
|
70 function testFirstSourceLabel(){ |
|
71 ok(gSources.containsValue(EXAMPLE_URL + gFirstSourceLabel), |
|
72 "First source url is correct."); |
|
73 } |
|
74 |
|
75 function testSecondSourceLabel(){ |
|
76 ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel), |
|
77 "Second source url is correct."); |
|
78 } |
|
79 |
|
80 function testAutoPrettyPrintOn(){ |
|
81 is(gPrefs.autoPrettyPrint, true, |
|
82 "The auto-pretty-print pref should be on."); |
|
83 is(gOptions._autoPrettyPrint.getAttribute("checked"), "true", |
|
84 "The Auto pretty print menu item should be checked."); |
|
85 } |
|
86 |
|
87 function testPrettyPrintButtonOn(){ |
|
88 is(gDebugger.document.getElementById("pretty-print").checked, true, |
|
89 "The button should be checked when the source is selected."); |
|
90 } |
|
91 |
|
92 function disableAutoPrettyPrint(){ |
|
93 gOptions._autoPrettyPrint.setAttribute("checked", "false"); |
|
94 gOptions._toggleAutoPrettyPrint(); |
|
95 gOptions._onPopupHidden(); |
|
96 } |
|
97 |
|
98 function testSourceIsPretty() { |
|
99 ok(gEditor.getText().contains("\n "), |
|
100 "The source should be pretty printed.") |
|
101 } |
|
102 |
|
103 registerCleanupFunction(function() { |
|
104 gTab = null; |
|
105 gDebuggee = null; |
|
106 gPanel = null; |
|
107 gDebugger = null; |
|
108 gEditor = null; |
|
109 gSources = null; |
|
110 gOptions = null; |
|
111 gPrefs = null; |
|
112 gView = null; |
|
113 Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref); |
|
114 }); |