browser_dbg_server-conditional-bp-01.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 adding conditional breakpoints (with server-side support)
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";
  8. function test() {
  9. // Linux debug test slaves are a bit slow at this test sometimes.
  10. requestLongerTimeout(2);
  11. let options = {
  12. source: TAB_URL,
  13. line: 1
  14. };
  15. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  16. const gTab = aTab;
  17. const gPanel = aPanel;
  18. const gDebugger = gPanel.panelWin;
  19. const gEditor = gDebugger.DebuggerView.editor;
  20. const gSources = gDebugger.DebuggerView.Sources;
  21. const queries = gDebugger.require("./content/queries");
  22. const constants = gDebugger.require("./content/constants");
  23. const actions = bindActionCreators(gPanel);
  24. const getState = gDebugger.DebuggerController.getState;
  25. const addBreakpoints = Task.async(function* () {
  26. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 18 },
  27. "undefined");
  28. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 19 },
  29. "null");
  30. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 20 },
  31. "42");
  32. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 21 },
  33. "true");
  34. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 22 },
  35. "'nasu'");
  36. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 23 },
  37. "/regexp/");
  38. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 24 },
  39. "({})");
  40. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 25 },
  41. "(function() {})");
  42. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 26 },
  43. "(function() { return false; })()");
  44. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 27 },
  45. "a");
  46. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 28 },
  47. "a !== undefined");
  48. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 29 },
  49. "b");
  50. yield actions.addBreakpoint({ actor: gSources.selectedValue, line: 30 },
  51. "a !== null");
  52. });
  53. function resumeAndTestBreakpoint(line) {
  54. let finished = waitForCaretUpdated(gPanel, line).then(() => testBreakpoint(line));
  55. EventUtils.sendMouseEvent({ type: "mousedown" },
  56. gDebugger.document.getElementById("resume"),
  57. gDebugger);
  58. return finished;
  59. }
  60. function resumeAndTestNoBreakpoint() {
  61. let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
  62. is(gSources.itemCount, 1,
  63. "Found the expected number of sources.");
  64. is(gEditor.getText().indexOf("ermahgerd"), 253,
  65. "The correct source was loaded initially.");
  66. is(gSources.selectedValue, gSources.values[0],
  67. "The correct source is selected.");
  68. ok(gSources.selectedItem,
  69. "There should be a selected source in the sources pane.");
  70. ok(!gSources._selectedBreakpoint,
  71. "There should be no selected breakpoint in the sources pane.");
  72. is(gSources._conditionalPopupVisible, false,
  73. "The breakpoint conditional expression popup should not be shown.");
  74. is(gDebugger.document.querySelectorAll(".dbg-stackframe").length, 0,
  75. "There should be no visible stackframes.");
  76. is(gDebugger.document.querySelectorAll(".dbg-breakpoint").length, 13,
  77. "There should be thirteen visible breakpoints.");
  78. });
  79. gDebugger.gThreadClient.resume();
  80. return finished;
  81. }
  82. function testBreakpoint(line, highlightBreakpoint) {
  83. // Highlight the breakpoint only if required.
  84. if (highlightBreakpoint) {
  85. let finished = waitForCaretUpdated(gPanel, line).then(() => testBreakpoint(line));
  86. gSources.highlightBreakpoint({ actor: gSources.selectedValue, line: line });
  87. return finished;
  88. }
  89. let selectedActor = gSources.selectedValue;
  90. let selectedBreakpoint = gSources._selectedBreakpoint;
  91. let selectedBreakpointItem = gSources._getBreakpoint(selectedBreakpoint);
  92. ok(selectedActor,
  93. "There should be a selected item in the sources pane.");
  94. ok(selectedBreakpoint,
  95. "There should be a selected breakpoint in the sources pane.");
  96. let source = gSources.selectedItem.attachment.source;
  97. let bp = queries.getBreakpoint(getState(), selectedBreakpoint.location);
  98. ok(bp, "The selected breakpoint exists");
  99. is(bp.location.actor, source.actor,
  100. "The breakpoint on line " + line + " wasn't added on the correct source.");
  101. is(bp.location.line, line,
  102. "The breakpoint on line " + line + " wasn't found.");
  103. is(!!bp.disabled, false,
  104. "The breakpoint on line " + line + " should be enabled.");
  105. is(!!selectedBreakpointItem.attachment.openPopup, false,
  106. "The breakpoint on line " + line + " should not have opened a popup.");
  107. is(gSources._conditionalPopupVisible, false,
  108. "The breakpoint conditional expression popup should not have been shown.");
  109. isnot(bp.condition, undefined,
  110. "The breakpoint on line " + line + " should have a conditional expression.");
  111. ok(isCaretPos(gPanel, line),
  112. "The editor caret position is not properly set.");
  113. }
  114. const testAfterReload = Task.async(function* () {
  115. let selectedActor = gSources.selectedValue;
  116. let selectedBreakpoint = gSources._selectedBreakpoint;
  117. ok(selectedActor,
  118. "There should be a selected item in the sources pane after reload.");
  119. ok(!selectedBreakpoint,
  120. "There should be no selected breakpoint in the sources pane after reload.");
  121. yield testBreakpoint(18, true);
  122. yield testBreakpoint(19, true);
  123. yield testBreakpoint(20, true);
  124. yield testBreakpoint(21, true);
  125. yield testBreakpoint(22, true);
  126. yield testBreakpoint(23, true);
  127. yield testBreakpoint(24, true);
  128. yield testBreakpoint(25, true);
  129. yield testBreakpoint(26, true);
  130. yield testBreakpoint(27, true);
  131. yield testBreakpoint(28, true);
  132. yield testBreakpoint(29, true);
  133. yield testBreakpoint(30, true);
  134. is(gSources.itemCount, 1,
  135. "Found the expected number of sources.");
  136. is(gEditor.getText().indexOf("ermahgerd"), 253,
  137. "The correct source was loaded again.");
  138. is(gSources.selectedValue, gSources.values[0],
  139. "The correct source is selected.");
  140. ok(gSources.selectedItem,
  141. "There should be a selected source in the sources pane.");
  142. ok(gSources._selectedBreakpoint,
  143. "There should be a selected breakpoint in the sources pane.");
  144. is(gSources._conditionalPopupVisible, false,
  145. "The breakpoint conditional expression popup should not be shown.");
  146. });
  147. Task.spawn(function* () {
  148. let onCaretUpdated = waitForCaretAndScopes(gPanel, 17);
  149. callInTab(gTab, "ermahgerd");
  150. yield onCaretUpdated;
  151. yield addBreakpoints();
  152. is(gDebugger.gThreadClient.state, "paused",
  153. "Should only be getting stack frames while paused.");
  154. is(queries.getSourceCount(getState()), 1,
  155. "Found the expected number of sources.");
  156. is(gEditor.getText().indexOf("ermahgerd"), 253,
  157. "The correct source was loaded initially.");
  158. is(gSources.selectedValue, gSources.values[0],
  159. "The correct source is selected.");
  160. is(queries.getBreakpoints(getState()).length, 13,
  161. "13 breakpoints currently added.");
  162. yield resumeAndTestBreakpoint(20);
  163. yield resumeAndTestBreakpoint(21);
  164. yield resumeAndTestBreakpoint(22);
  165. yield resumeAndTestBreakpoint(23);
  166. yield resumeAndTestBreakpoint(24);
  167. yield resumeAndTestBreakpoint(25);
  168. yield resumeAndTestBreakpoint(27);
  169. yield resumeAndTestBreakpoint(28);
  170. yield resumeAndTestBreakpoint(29);
  171. yield resumeAndTestBreakpoint(30);
  172. yield resumeAndTestNoBreakpoint();
  173. let sourceShown = waitForSourceShown(gPanel, ".html");
  174. reload(gPanel),
  175. yield sourceShown;
  176. testAfterReload();
  177. // When a breakpoint is highlighted, the conditional expression
  178. // popup opens, and then closes, and when it closes it sends the
  179. // expression to the server which pauses the server. Make sure
  180. // we wait if there is a pending request.
  181. if (gDebugger.gThreadClient.state === "paused") {
  182. yield waitForThreadEvents(gPanel, "resumed");
  183. }
  184. closeDebuggerAndFinish(gPanel);
  185. });
  186. });
  187. }