browser/devtools/debugger/test/browser_dbg_pretty-print-13.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Make sure that clicking the pretty print button prettifies the source, even
michael@0 6 * when the source URL does not end in ".js", but the content type is
michael@0 7 * JavaScript.
michael@0 8 */
michael@0 9
michael@0 10 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-3.html";
michael@0 11
michael@0 12 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 13 let gEditor, gSources;
michael@0 14
michael@0 15 function test() {
michael@0 16 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 17 gTab = aTab;
michael@0 18 gDebuggee = aDebuggee;
michael@0 19 gPanel = aPanel;
michael@0 20 gDebugger = gPanel.panelWin;
michael@0 21 gEditor = gDebugger.DebuggerView.editor;
michael@0 22 gSources = gDebugger.DebuggerView.Sources;
michael@0 23
michael@0 24 promise.all([waitForSourceShown(gPanel, "code_ugly-8"),
michael@0 25 waitForEditorLocationSet(gPanel)])
michael@0 26 .then(testSourceIsUgly)
michael@0 27 .then(() => {
michael@0 28 const finished = waitForSourceShown(gPanel, "code_ugly-8");
michael@0 29 clickPrettyPrintButton();
michael@0 30 testProgressBarShown();
michael@0 31 return finished;
michael@0 32 })
michael@0 33 .then(testSourceIsPretty)
michael@0 34 .then(testEditorShown)
michael@0 35 .then(testSourceIsStillPretty)
michael@0 36 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 37 .then(null, aError => {
michael@0 38 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
michael@0 39 });
michael@0 40 });
michael@0 41 }
michael@0 42
michael@0 43 function testSourceIsUgly() {
michael@0 44 ok(!gEditor.getText().contains("\n "),
michael@0 45 "The source shouldn't be pretty printed yet.");
michael@0 46 }
michael@0 47
michael@0 48 function clickPrettyPrintButton() {
michael@0 49 gDebugger.document.getElementById("pretty-print").click();
michael@0 50 }
michael@0 51
michael@0 52 function testProgressBarShown() {
michael@0 53 const deck = gDebugger.document.getElementById("editor-deck");
michael@0 54 is(deck.selectedIndex, 2, "The progress bar should be shown");
michael@0 55 }
michael@0 56
michael@0 57 function testSourceIsPretty() {
michael@0 58 ok(gEditor.getText().contains("\n "),
michael@0 59 "The source should be pretty printed.")
michael@0 60 }
michael@0 61
michael@0 62 function testEditorShown() {
michael@0 63 const deck = gDebugger.document.getElementById("editor-deck");
michael@0 64 is(deck.selectedIndex, 0, "The editor should be shown");
michael@0 65 }
michael@0 66
michael@0 67 function testSourceIsStillPretty() {
michael@0 68 const deferred = promise.defer();
michael@0 69
michael@0 70 const { source } = gSources.selectedItem.attachment;
michael@0 71 gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => {
michael@0 72 ok(text.contains("\n "),
michael@0 73 "Subsequent calls to getText return the pretty printed source.");
michael@0 74 deferred.resolve();
michael@0 75 });
michael@0 76
michael@0 77 return deferred.promise;
michael@0 78 }
michael@0 79
michael@0 80 registerCleanupFunction(function() {
michael@0 81 gTab = null;
michael@0 82 gDebuggee = null;
michael@0 83 gPanel = null;
michael@0 84 gDebugger = null;
michael@0 85 gEditor = null;
michael@0 86 gSources = null;
michael@0 87 });

mercurial