browser_dbg_location-changes-04-breakpoint.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 reloading a page with a breakpoint set does not cause it to
  6. * fire more than once.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_included-script.html";
  9. const SOURCE_URL = EXAMPLE_URL + "code_location-changes.js";
  10. function test() {
  11. const options = {
  12. source: SOURCE_URL,
  13. line: 1
  14. };
  15. initDebugger(TAB_URL, options).then(([aTab, aDebuggee, aPanel]) => {
  16. const gTab = aTab;
  17. const gDebuggee = aDebuggee;
  18. const gPanel = aPanel;
  19. const gDebugger = gPanel.panelWin;
  20. const gEditor = gDebugger.DebuggerView.editor;
  21. const gSources = gDebugger.DebuggerView.Sources;
  22. const queries = gDebugger.require("./content/queries");
  23. const actions = bindActionCreators(gPanel);
  24. const getState = gDebugger.DebuggerController.getState;
  25. function clickButtonAndPause() {
  26. const paused = waitForPause(gDebugger.gThreadClient);
  27. BrowserTestUtils.synthesizeMouse("button", 2, 2, {}, gBrowser.selectedBrowser);
  28. return paused;
  29. }
  30. Task.spawn(function* () {
  31. let onCaretUpdated = waitForCaretUpdated(gPanel, 17);
  32. callInTab(gTab, "runDebuggerStatement");
  33. yield onCaretUpdated;
  34. const location = { actor: getSourceActor(gSources, SOURCE_URL), line: 5 };
  35. yield actions.addBreakpoint(location);
  36. const caretUpdated = waitForSourceAndCaret(gPanel, ".js", 5);
  37. gSources.highlightBreakpoint(location);
  38. yield caretUpdated;
  39. ok(true, "Switched to the desired function when adding a breakpoint");
  40. is(gDebugger.gThreadClient.state, "paused",
  41. "The breakpoint was hit (1).");
  42. is(getSelectedSourceURL(gSources), SOURCE_URL,
  43. "The currently shown source is correct (1).");
  44. ok(isCaretPos(gPanel, 5),
  45. "The source editor caret position is correct (1).");
  46. yield doResume(gPanel);
  47. isnot(gDebugger.gThreadClient.state, "paused",
  48. "The breakpoint was not hit yet (2).");
  49. is(getSelectedSourceURL(gSources), SOURCE_URL,
  50. "The currently shown source is correct (2).");
  51. ok(isCaretPos(gPanel, 5),
  52. "The source editor caret position is correct (2).");
  53. let packet = yield clickButtonAndPause();
  54. is(packet.why.type, "breakpoint",
  55. "Execution has advanced to the breakpoint.");
  56. isnot(packet.why.type, "debuggerStatement",
  57. "The breakpoint was hit before the debugger statement.");
  58. yield ensureCaretAt(gPanel, 5, 1, true);
  59. is(gDebugger.gThreadClient.state, "paused",
  60. "The breakpoint was hit (3).");
  61. is(getSelectedSourceURL(gSources), SOURCE_URL,
  62. "The currently shown source is incorrect (3).");
  63. ok(isCaretPos(gPanel, 5),
  64. "The source editor caret position is incorrect (3).");
  65. let paused = waitForPause(gDebugger.gThreadClient);
  66. gDebugger.gThreadClient.resume();
  67. packet = yield paused;
  68. is(packet.why.type, "debuggerStatement",
  69. "Execution has advanced to the next line.");
  70. isnot(packet.why.type, "breakpoint",
  71. "No ghost breakpoint was hit.");
  72. yield ensureCaretAt(gPanel, 6, 1, true);
  73. is(gDebugger.gThreadClient.state, "paused",
  74. "The debugger statement was hit (4).");
  75. is(getSelectedSourceURL(gSources), SOURCE_URL,
  76. "The currently shown source is incorrect (4).");
  77. ok(isCaretPos(gPanel, 6),
  78. "The source editor caret position is incorrect (4).");
  79. yield promise.all([
  80. reload(gPanel),
  81. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN)
  82. ]);
  83. isnot(gDebugger.gThreadClient.state, "paused",
  84. "The breakpoint wasn't hit yet (5).");
  85. is(getSelectedSourceURL(gSources), SOURCE_URL,
  86. "The currently shown source is incorrect (5).");
  87. ok(isCaretPos(gPanel, 1),
  88. "The source editor caret position is incorrect (5).");
  89. paused = waitForPause(gDebugger.gThreadClient);
  90. clickButtonAndPause();
  91. packet = yield paused;
  92. is(packet.why.type, "breakpoint",
  93. "Execution has advanced to the breakpoint.");
  94. isnot(packet.why.type, "debuggerStatement",
  95. "The breakpoint was hit before the debugger statement.");
  96. yield ensureCaretAt(gPanel, 5, 1, true);
  97. is(gDebugger.gThreadClient.state, "paused",
  98. "The breakpoint was hit (6).");
  99. is(getSelectedSourceURL(gSources), SOURCE_URL,
  100. "The currently shown source is incorrect (6).");
  101. ok(isCaretPos(gPanel, 5),
  102. "The source editor caret position is incorrect (6).");
  103. paused = waitForPause(gDebugger.gThreadClient);
  104. gDebugger.gThreadClient.resume();
  105. packet = yield paused;
  106. is(packet.why.type, "debuggerStatement",
  107. "Execution has advanced to the next line.");
  108. isnot(packet.why.type, "breakpoint",
  109. "No ghost breakpoint was hit.");
  110. yield ensureCaretAt(gPanel, 6, 1, true);
  111. is(gDebugger.gThreadClient.state, "paused",
  112. "The debugger statement was hit (7).");
  113. is(getSelectedSourceURL(gSources), SOURCE_URL,
  114. "The currently shown source is incorrect (7).");
  115. ok(isCaretPos(gPanel, 6),
  116. "The source editor caret position is incorrect (7).");
  117. let sourceShown = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
  118. // Click the second source in the list.
  119. yield actions.selectSource(getSourceForm(gSources, TAB_URL));
  120. yield sourceShown;
  121. is(gEditor.getText().indexOf("debugger"), 447,
  122. "The correct source is shown in the source editor.");
  123. is(gEditor.getBreakpoints().length, 0,
  124. "No breakpoints should be shown for the second source.");
  125. yield ensureCaretAt(gPanel, 1, 1, true);
  126. sourceShown = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
  127. yield actions.selectSource(getSourceForm(gSources, SOURCE_URL));
  128. yield sourceShown;
  129. is(gEditor.getText().indexOf("debugger"), 148,
  130. "The correct source is shown in the source editor.");
  131. is(gEditor.getBreakpoints().length, 1,
  132. "One breakpoint should be shown for the first source.");
  133. yield ensureCaretAt(gPanel, 6, 1, true);
  134. resumeDebuggerThenCloseAndFinish(gPanel);
  135. });
  136. });
  137. }