browser_dbg_auto-pretty-print-01.js 3.2 KB

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