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