browser_dbg_pretty-print-11.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  5. * Make sure that pretty printing is maintained across refreshes.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html";
  8. var gTab, gPanel, gDebugger;
  9. var gEditor, gSources;
  10. function test() {
  11. // Wait for debugger panel to be fully set and break on debugger statement
  12. let options = {
  13. source: EXAMPLE_URL + "code_ugly.js",
  14. line: 2
  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. testSourceIsUgly();
  23. const finished = waitForCaretUpdated(gPanel, 7);
  24. clickPrettyPrintButton();
  25. finished.then(testSourceIsPretty)
  26. .then(() => {
  27. const finished = waitForCaretUpdated(gPanel, 7);
  28. const reloaded = reloadActiveTab(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
  29. return Promise.all([finished, reloaded]);
  30. })
  31. .then(testSourceIsPretty)
  32. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  33. .then(null, aError => {
  34. ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
  35. });
  36. });
  37. }
  38. function testSourceIsUgly() {
  39. ok(!gEditor.getText().includes("\n "),
  40. "The source shouldn't be pretty printed yet.");
  41. }
  42. function clickPrettyPrintButton() {
  43. gDebugger.document.getElementById("pretty-print").click();
  44. }
  45. function testSourceIsPretty() {
  46. ok(gEditor.getText().includes("\n "),
  47. "The source should be pretty printed.");
  48. }
  49. registerCleanupFunction(function () {
  50. gTab = null;
  51. gPanel = null;
  52. gDebugger = null;
  53. gEditor = null;
  54. gSources = null;
  55. });