browser_dbg_pretty-print-07.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 basic pretty printing functionality. Would be an xpcshell test, except
  5. // for bug 921252.
  6. var gTab, gPanel, gClient, gThreadClient, gSource;
  7. const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html";
  8. function test() {
  9. let options = {
  10. source: EXAMPLE_URL + "code_ugly-2.js",
  11. line: 1
  12. };
  13. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  14. gTab = aTab;
  15. gPanel = aPanel;
  16. gClient = gPanel.panelWin.gClient;
  17. gThreadClient = gPanel.panelWin.DebuggerController.activeThread;
  18. findSource();
  19. });
  20. }
  21. function findSource() {
  22. gThreadClient.getSources(({ error, sources }) => {
  23. ok(!error);
  24. sources = sources.filter(s => s.url.includes("code_ugly-2.js"));
  25. is(sources.length, 1);
  26. gSource = sources[0];
  27. prettyPrintSource();
  28. });
  29. }
  30. function prettyPrintSource() {
  31. gThreadClient.source(gSource).prettyPrint(4, testPrettyPrinted);
  32. }
  33. function testPrettyPrinted({ error, source }) {
  34. ok(!error, "Should not get an error while pretty-printing");
  35. ok(source.includes("\n "),
  36. "Source should be pretty-printed");
  37. disablePrettyPrint();
  38. }
  39. function disablePrettyPrint() {
  40. gThreadClient.source(gSource).disablePrettyPrint(testUgly);
  41. }
  42. function testUgly({ error, source }) {
  43. ok(!error, "Should not get an error while disabling pretty-printing");
  44. ok(!source.includes("\n "),
  45. "Source should not be pretty after disabling pretty-printing");
  46. closeDebuggerAndFinish(gPanel);
  47. }
  48. registerCleanupFunction(function () {
  49. gTab = gPanel = gClient = gThreadClient = gSource = null;
  50. });