browser_dbg_source-maps-01.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * Test that we can set breakpoints and step through source mapped
  6. * coffee script.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_binary_search.html";
  9. const COFFEE_URL = EXAMPLE_URL + "code_binary_search.coffee";
  10. var gTab, gPanel, gDebugger;
  11. var gEditor, gSources;
  12. function test() {
  13. let options = {
  14. source: COFFEE_URL,
  15. line: 1
  16. };
  17. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  18. gTab = aTab;
  19. gPanel = aPanel;
  20. gDebugger = gPanel.panelWin;
  21. gEditor = gDebugger.DebuggerView.editor;
  22. gSources = gDebugger.DebuggerView.Sources;
  23. checkSourceMapsEnabled();
  24. checkInitialSource();
  25. testSetBreakpoint()
  26. .then(testSetBreakpointBlankLine)
  27. .then(testHitBreakpoint)
  28. .then(testStepping)
  29. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  30. .then(null, aError => {
  31. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  32. });
  33. });
  34. }
  35. function checkSourceMapsEnabled() {
  36. is(Services.prefs.getBoolPref("devtools.debugger.source-maps-enabled"), true,
  37. "The source maps functionality should be enabled by default.");
  38. is(gDebugger.Prefs.sourceMapsEnabled, true,
  39. "The source maps pref should be true from startup.");
  40. is(gDebugger.DebuggerView.Options._showOriginalSourceItem.getAttribute("checked"), "true",
  41. "Source maps should be enabled from startup.");
  42. }
  43. function checkInitialSource() {
  44. isnot(gSources.selectedItem.attachment.source.url.indexOf(".coffee"), -1,
  45. "The debugger should show the source mapped coffee source file.");
  46. is(gSources.selectedValue.indexOf(".js"), -1,
  47. "The debugger should not show the generated js source file.");
  48. is(gEditor.getText().indexOf("isnt"), 218,
  49. "The debugger's editor should have the coffee source source displayed.");
  50. is(gEditor.getText().indexOf("function"), -1,
  51. "The debugger's editor should not have the JS source displayed.");
  52. }
  53. function testSetBreakpoint() {
  54. let deferred = promise.defer();
  55. let sourceForm = getSourceForm(gSources, COFFEE_URL);
  56. gDebugger.gThreadClient.interrupt(aResponse => {
  57. let source = gDebugger.gThreadClient.source(sourceForm);
  58. source.setBreakpoint({ line: 5 }, aResponse => {
  59. ok(!aResponse.error,
  60. "Should be able to set a breakpoint in a coffee source file.");
  61. ok(!aResponse.actualLocation,
  62. "Should be able to set a breakpoint on line 5.");
  63. deferred.resolve();
  64. });
  65. });
  66. return deferred.promise;
  67. }
  68. function testSetBreakpointBlankLine() {
  69. let deferred = promise.defer();
  70. let sourceForm = getSourceForm(gSources, COFFEE_URL);
  71. let source = gDebugger.gThreadClient.source(sourceForm);
  72. source.setBreakpoint({ line: 8 }, aResponse => {
  73. ok(!aResponse.error,
  74. "Should be able to set a breakpoint in a coffee source file on a blank line.");
  75. ok(!aResponse.isPending,
  76. "Should not be a pending breakpoint.");
  77. ok(!aResponse.actualLocation,
  78. "Should not be a moved breakpoint.");
  79. deferred.resolve();
  80. });
  81. return deferred.promise;
  82. }
  83. function testHitBreakpoint() {
  84. let deferred = promise.defer();
  85. gDebugger.gThreadClient.resume(aResponse => {
  86. ok(!aResponse.error, "Shouldn't get an error resuming.");
  87. is(aResponse.type, "resumed", "Type should be 'resumed'.");
  88. gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
  89. is(aPacket.type, "paused",
  90. "We should now be paused again.");
  91. is(aPacket.why.type, "breakpoint",
  92. "and the reason we should be paused is because we hit a breakpoint.");
  93. // Check that we stopped at the right place, by making sure that the
  94. // environment is in the state that we expect.
  95. is(aPacket.frame.environment.bindings.variables.start.value, 0,
  96. "'start' is 0.");
  97. is(aPacket.frame.environment.bindings.variables.stop.value.type, "undefined",
  98. "'stop' hasn't been assigned to yet.");
  99. is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
  100. "'pivot' hasn't been assigned to yet.");
  101. waitForCaretUpdated(gPanel, 5).then(deferred.resolve);
  102. });
  103. // This will cause the breakpoint to be hit, and put us back in the
  104. // paused state.
  105. callInTab(gTab, "binary_search", [0, 2, 3, 5, 7, 10], 5);
  106. });
  107. return deferred.promise;
  108. }
  109. function testStepping() {
  110. let deferred = promise.defer();
  111. gDebugger.gThreadClient.stepIn(aResponse => {
  112. ok(!aResponse.error, "Shouldn't get an error resuming.");
  113. is(aResponse.type, "resumed", "Type should be 'resumed'.");
  114. // After stepping, we will pause again, so listen for that.
  115. gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
  116. is(aPacket.type, "paused",
  117. "We should now be paused again.");
  118. is(aPacket.why.type, "resumeLimit",
  119. "and the reason we should be paused is because we hit the resume limit.");
  120. // Check that we stopped at the right place, by making sure that the
  121. // environment is in the state that we expect.
  122. is(aPacket.frame.environment.bindings.variables.start.value, 0,
  123. "'start' is 0.");
  124. is(aPacket.frame.environment.bindings.variables.stop.value, 5,
  125. "'stop' is 5.");
  126. is(aPacket.frame.environment.bindings.variables.pivot.value.type, "undefined",
  127. "'pivot' hasn't been assigned to yet.");
  128. waitForCaretUpdated(gPanel, 6).then(deferred.resolve);
  129. });
  130. });
  131. return deferred.promise;
  132. }
  133. registerCleanupFunction(function () {
  134. gTab = null;
  135. gPanel = null;
  136. gDebugger = null;
  137. gEditor = null;
  138. gSources = null;
  139. });