browser_dbg_pretty-print-09.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 pretty printing source mapped sources.
  5. var gClient;
  6. var gThreadClient;
  7. var gSource;
  8. var gTab, gPanel, gClient, gThreadClient, gSource;
  9. const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html";
  10. function test() {
  11. let options = {
  12. source: EXAMPLE_URL + "code_ugly-2.js",
  13. line: 1
  14. };
  15. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  16. gTab = aTab;
  17. gPanel = aPanel;
  18. gClient = gPanel.panelWin.gClient;
  19. gThreadClient = gPanel.panelWin.DebuggerController.activeThread;
  20. findSource();
  21. });
  22. }
  23. const dataUrl = s => "data:text/javascript," + s;
  24. // These should match the instructions in code_ugly-4.js.
  25. const A = "function a(){b()}";
  26. const A_URL = dataUrl(A);
  27. const B = "function b(){debugger}";
  28. const B_URL = dataUrl(B);
  29. function findSource() {
  30. gThreadClient.getSources(({ error, sources }) => {
  31. ok(!error);
  32. sources = sources.filter(s => s.url === B_URL);
  33. is(sources.length, 1);
  34. gSource = sources[0];
  35. prettyPrint();
  36. });
  37. }
  38. function prettyPrint() {
  39. gThreadClient.source(gSource).prettyPrint(2, runCode);
  40. }
  41. function runCode({ error }) {
  42. ok(!error);
  43. gClient.addOneTimeListener("paused", testDbgStatement);
  44. callInTab(gTab, "a");
  45. }
  46. function testDbgStatement(event, { frame, why }) {
  47. is(why.type, "debuggerStatement");
  48. const { source, line } = frame.where;
  49. is(source.url, B_URL);
  50. is(line, 2);
  51. disablePrettyPrint();
  52. }
  53. function disablePrettyPrint() {
  54. gThreadClient.source(gSource).disablePrettyPrint(testUgly);
  55. }
  56. function testUgly({ error, source }) {
  57. ok(!error);
  58. ok(!source.includes("\n "));
  59. getFrame();
  60. }
  61. function getFrame() {
  62. gThreadClient.getFrames(0, 1, testFrame);
  63. }
  64. function testFrame({ frames: [frame] }) {
  65. const { source, line } = frame.where;
  66. is(source.url, B_URL);
  67. is(line, 1);
  68. resumeDebuggerThenCloseAndFinish(gPanel);
  69. }
  70. registerCleanupFunction(function () {
  71. gTab = gPanel = gClient = gThreadClient = null;
  72. });