browser_dbg_source-maps-04.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 bogus source maps don't break debugging.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_minified_bogus_map.html";
  8. const JS_URL = EXAMPLE_URL + "code_math_bogus_map.js";
  9. // This test causes an error to be logged in the console, which appears in TBPL
  10. // logs, so we are disabling that here.
  11. DevToolsUtils.reportingDisabled = true;
  12. var gPanel, gDebugger, gFrames, gSources, gPrefs, gOptions;
  13. function test() {
  14. let options = {
  15. source: JS_URL,
  16. line: 1
  17. };
  18. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  19. gPanel = aPanel;
  20. gDebugger = gPanel.panelWin;
  21. gFrames = gDebugger.DebuggerView.StackFrames;
  22. gSources = gDebugger.DebuggerView.Sources;
  23. gPrefs = gDebugger.Prefs;
  24. gOptions = gDebugger.DebuggerView.Options;
  25. is(gPrefs.pauseOnExceptions, false,
  26. "The pause-on-exceptions pref should be disabled by default.");
  27. isnot(gOptions._pauseOnExceptionsItem.getAttribute("checked"), "true",
  28. "The pause-on-exceptions menu item should not be checked.");
  29. checkInitialSource();
  30. enablePauseOnExceptions()
  31. .then(disableIgnoreCaughtExceptions)
  32. .then(testSetBreakpoint)
  33. .then(reloadPage)
  34. .then(testHitBreakpoint)
  35. .then(enableIgnoreCaughtExceptions)
  36. .then(disablePauseOnExceptions)
  37. .then(() => closeDebuggerAndFinish(gPanel))
  38. .then(null, aError => {
  39. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  40. });
  41. });
  42. }
  43. function checkInitialSource() {
  44. isnot(gSources.selectedItem.attachment.source.url.indexOf("code_math_bogus_map.js"), -1,
  45. "The debugger should show the minified js file.");
  46. }
  47. function enablePauseOnExceptions() {
  48. let deferred = promise.defer();
  49. gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
  50. is(gPrefs.pauseOnExceptions, true,
  51. "The pause-on-exceptions pref should now be enabled.");
  52. ok(true, "Pausing on exceptions was enabled.");
  53. deferred.resolve();
  54. });
  55. gOptions._pauseOnExceptionsItem.setAttribute("checked", "true");
  56. gOptions._togglePauseOnExceptions();
  57. return deferred.promise;
  58. }
  59. function disableIgnoreCaughtExceptions() {
  60. let deferred = promise.defer();
  61. gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
  62. is(gPrefs.ignoreCaughtExceptions, false,
  63. "The ignore-caught-exceptions pref should now be disabled.");
  64. ok(true, "Ignore caught exceptions was disabled.");
  65. deferred.resolve();
  66. });
  67. gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "false");
  68. gOptions._toggleIgnoreCaughtExceptions();
  69. return deferred.promise;
  70. }
  71. function testSetBreakpoint() {
  72. let deferred = promise.defer();
  73. let sourceForm = getSourceForm(gSources, JS_URL);
  74. let source = gDebugger.gThreadClient.source(sourceForm);
  75. source.setBreakpoint({ line: 3, column: 18 }, aResponse => {
  76. ok(!aResponse.error,
  77. "Should be able to set a breakpoint in a js file.");
  78. ok(!aResponse.actualLocation,
  79. "Should be able to set a breakpoint on line 3 and column 18.");
  80. deferred.resolve();
  81. });
  82. return deferred.promise;
  83. }
  84. function reloadPage() {
  85. let loaded = waitForSourceAndCaret(gPanel, ".js", 3);
  86. gDebugger.DebuggerController._target.activeTab.reload();
  87. return loaded.then(() => ok(true, "Page was reloaded and execution resumed."));
  88. }
  89. function testHitBreakpoint() {
  90. let deferred = promise.defer();
  91. gDebugger.gThreadClient.resume(aResponse => {
  92. ok(!aResponse.error, "Shouldn't get an error resuming.");
  93. is(aResponse.type, "resumed", "Type should be 'resumed'.");
  94. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => {
  95. is(gFrames.itemCount, 2, "Should have two frames.");
  96. // This is weird, but we need to let the debugger a chance to
  97. // update first
  98. executeSoon(() => {
  99. gDebugger.gThreadClient.resume(() => {
  100. gDebugger.gThreadClient.addOneTimeListener("paused", () => {
  101. gDebugger.gThreadClient.resume(() => {
  102. // We also need to make sure the next step doesn't add a
  103. // "resumed" handler until this is completely finished
  104. executeSoon(() => {
  105. deferred.resolve();
  106. });
  107. });
  108. });
  109. });
  110. });
  111. });
  112. });
  113. return deferred.promise;
  114. }
  115. function enableIgnoreCaughtExceptions() {
  116. let deferred = promise.defer();
  117. gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
  118. is(gPrefs.ignoreCaughtExceptions, true,
  119. "The ignore-caught-exceptions pref should now be enabled.");
  120. ok(true, "Ignore caught exceptions was enabled.");
  121. deferred.resolve();
  122. });
  123. gOptions._ignoreCaughtExceptionsItem.setAttribute("checked", "true");
  124. gOptions._toggleIgnoreCaughtExceptions();
  125. return deferred.promise;
  126. }
  127. function disablePauseOnExceptions() {
  128. let deferred = promise.defer();
  129. gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
  130. is(gPrefs.pauseOnExceptions, false,
  131. "The pause-on-exceptions pref should now be disabled.");
  132. ok(true, "Pausing on exceptions was disabled.");
  133. deferred.resolve();
  134. });
  135. gOptions._pauseOnExceptionsItem.setAttribute("checked", "false");
  136. gOptions._togglePauseOnExceptions();
  137. return deferred.promise;
  138. }
  139. registerCleanupFunction(function () {
  140. gPanel = null;
  141. gDebugger = null;
  142. gFrames = null;
  143. gSources = null;
  144. gPrefs = null;
  145. gOptions = null;
  146. DevToolsUtils.reportingDisabled = false;
  147. });