browser/devtools/debugger/test/browser_dbg_auto-pretty-print-02.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_auto-pretty-print-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,114 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +  http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Test that auto pretty printing doesn't accidentally toggle
     1.9 + * pretty printing off when we switch to a minified source
    1.10 + * that is already pretty printed.
    1.11 + */
    1.12 +
    1.13 +const TAB_URL = EXAMPLE_URL + "doc_auto-pretty-print-02.html";
    1.14 +
    1.15 +let gTab, gDebuggee, gPanel, gDebugger;
    1.16 +let gEditor, gSources, gPrefs, gOptions, gView;
    1.17 +
    1.18 +let gFirstSourceLabel = "code_ugly-6.js";
    1.19 +let gSecondSourceLabel = "code_ugly-7.js";
    1.20 +
    1.21 +let gOriginalPref = Services.prefs.getBoolPref("devtools.debugger.auto-pretty-print");
    1.22 +Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true);
    1.23 +
    1.24 +function test(){
    1.25 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.26 +    gTab = aTab;
    1.27 +    gDebuggee = aDebuggee;
    1.28 +    gPanel = aPanel;
    1.29 +    gDebugger = gPanel.panelWin;
    1.30 +    gEditor = gDebugger.DebuggerView.editor;
    1.31 +    gSources = gDebugger.DebuggerView.Sources;
    1.32 +    gPrefs = gDebugger.Prefs;
    1.33 +    gOptions = gDebugger.DebuggerView.Options;
    1.34 +    gView = gDebugger.DebuggerView;
    1.35 +
    1.36 +    // Should be on by default.
    1.37 +    testAutoPrettyPrintOn();
    1.38 +
    1.39 +    waitForSourceShown(gPanel, gFirstSourceLabel)
    1.40 +      .then(testSourceIsUgly)
    1.41 +      .then(() => waitForSourceShown(gPanel, gFirstSourceLabel))
    1.42 +      .then(testSourceIsPretty)
    1.43 +      .then(testPrettyPrintButtonOn)
    1.44 +      .then(() => {
    1.45 +        // Switch to the second source.
    1.46 +        let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
    1.47 +        gSources.selectedIndex = 1;
    1.48 +        return finished;
    1.49 +      })
    1.50 +      .then(testSecondSourceLabel)
    1.51 +      .then(() => {
    1.52 +        // Switch back to first source.
    1.53 +        let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
    1.54 +        gSources.selectedIndex = 0;
    1.55 +        return finished;
    1.56 +      })
    1.57 +      .then(testFirstSourceLabel)
    1.58 +      .then(testPrettyPrintButtonOn)
    1.59 +      // Disable auto pretty printing so it does not affect the following tests.
    1.60 +      .then(disableAutoPrettyPrint)
    1.61 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.62 +      .then(null, aError => {
    1.63 +        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
    1.64 +      })
    1.65 +  });
    1.66 +}
    1.67 +
    1.68 +function testSourceIsUgly() {
    1.69 +  ok(!gEditor.getText().contains("\n  "),
    1.70 +    "The source shouldn't be pretty printed yet.");
    1.71 +}
    1.72 +
    1.73 +function testFirstSourceLabel(){
    1.74 +  ok(gSources.containsValue(EXAMPLE_URL + gFirstSourceLabel),
    1.75 +    "First source url is correct.");
    1.76 +}
    1.77 +
    1.78 +function testSecondSourceLabel(){
    1.79 +  ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel),
    1.80 +    "Second source url is correct.");
    1.81 +}
    1.82 +
    1.83 +function testAutoPrettyPrintOn(){
    1.84 +  is(gPrefs.autoPrettyPrint, true,
    1.85 +    "The auto-pretty-print pref should be on.");
    1.86 +  is(gOptions._autoPrettyPrint.getAttribute("checked"), "true",
    1.87 +    "The Auto pretty print menu item should be checked.");
    1.88 +}
    1.89 +
    1.90 +function testPrettyPrintButtonOn(){
    1.91 +  is(gDebugger.document.getElementById("pretty-print").checked, true,
    1.92 +    "The button should be checked when the source is selected.");
    1.93 +}
    1.94 +
    1.95 +function disableAutoPrettyPrint(){
    1.96 +  gOptions._autoPrettyPrint.setAttribute("checked", "false");
    1.97 +  gOptions._toggleAutoPrettyPrint();
    1.98 +  gOptions._onPopupHidden();
    1.99 +}
   1.100 +
   1.101 +function testSourceIsPretty() {
   1.102 +  ok(gEditor.getText().contains("\n  "),
   1.103 +    "The source should be pretty printed.")
   1.104 +}
   1.105 +
   1.106 +registerCleanupFunction(function() {
   1.107 +  gTab = null;
   1.108 +  gDebuggee = null;
   1.109 +  gPanel = null;
   1.110 +  gDebugger = null;
   1.111 +  gEditor = null;
   1.112 +  gSources = null;
   1.113 +  gOptions = null;
   1.114 +  gPrefs = null;
   1.115 +  gView = null;
   1.116 +  Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref);
   1.117 +});

mercurial