Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
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 */
10 const TAB_URL = EXAMPLE_URL + "doc_auto-pretty-print-02.html";
12 let gTab, gDebuggee, gPanel, gDebugger;
13 let gEditor, gSources, gPrefs, gOptions, gView;
15 let gFirstSourceLabel = "code_ugly-6.js";
16 let gSecondSourceLabel = "code_ugly-7.js";
18 let gOriginalPref = Services.prefs.getBoolPref("devtools.debugger.auto-pretty-print");
19 Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true);
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;
33 // Should be on by default.
34 testAutoPrettyPrintOn();
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 }
65 function testSourceIsUgly() {
66 ok(!gEditor.getText().contains("\n "),
67 "The source shouldn't be pretty printed yet.");
68 }
70 function testFirstSourceLabel(){
71 ok(gSources.containsValue(EXAMPLE_URL + gFirstSourceLabel),
72 "First source url is correct.");
73 }
75 function testSecondSourceLabel(){
76 ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel),
77 "Second source url is correct.");
78 }
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 }
87 function testPrettyPrintButtonOn(){
88 is(gDebugger.document.getElementById("pretty-print").checked, true,
89 "The button should be checked when the source is selected.");
90 }
92 function disableAutoPrettyPrint(){
93 gOptions._autoPrettyPrint.setAttribute("checked", "false");
94 gOptions._toggleAutoPrettyPrint();
95 gOptions._onPopupHidden();
96 }
98 function testSourceIsPretty() {
99 ok(gEditor.getText().contains("\n "),
100 "The source should be pretty printed.")
101 }
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 });