browser_dbg_conditional-breakpoints-02.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. * Bug 740825: Test the debugger conditional breakpoints.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";
  8. function test() {
  9. let options = {
  10. source: TAB_URL,
  11. line: 1
  12. };
  13. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  14. const gTab = aTab;
  15. const gPanel = aPanel;
  16. const gDebugger = gPanel.panelWin;
  17. const gEditor = gDebugger.DebuggerView.editor;
  18. const gSources = gDebugger.DebuggerView.Sources;
  19. const queries = gDebugger.require("./content/queries");
  20. const constants = gDebugger.require("./content/constants");
  21. const actions = bindActionCreators(gPanel);
  22. const getState = gDebugger.DebuggerController.getState;
  23. const CONDITIONAL_POPUP_SHOWN = gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_SHOWN;
  24. // This test forces conditional breakpoints to be evaluated on the
  25. // client-side
  26. var client = gPanel.target.client;
  27. client.mainRoot.traits.conditionalBreakpoints = false;
  28. function addBreakpoint1() {
  29. return actions.addBreakpoint({ actor: gSources.selectedValue, line: 18 });
  30. }
  31. function addBreakpoint2() {
  32. let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);
  33. setCaretPosition(19);
  34. gSources._onCmdAddBreakpoint();
  35. return finished;
  36. }
  37. function modBreakpoint2() {
  38. setCaretPosition(19);
  39. let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);
  40. gSources._onCmdAddConditionalBreakpoint();
  41. return popupShown;
  42. }
  43. function* addBreakpoint3() {
  44. let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);
  45. let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);
  46. setCaretPosition(20);
  47. gSources._onCmdAddConditionalBreakpoint();
  48. yield finished;
  49. yield popupShown;
  50. }
  51. function* modBreakpoint3() {
  52. setCaretPosition(20);
  53. let popupShown = waitForDebuggerEvents(gPanel, CONDITIONAL_POPUP_SHOWN);
  54. gSources._onCmdAddConditionalBreakpoint();
  55. yield popupShown;
  56. typeText(gSources._cbTextbox, "bamboocha");
  57. let finished = waitForDispatch(gPanel, constants.SET_BREAKPOINT_CONDITION);
  58. EventUtils.sendKey("RETURN", gDebugger);
  59. yield finished;
  60. }
  61. function addBreakpoint4() {
  62. let finished = waitForDispatch(gPanel, constants.ADD_BREAKPOINT);
  63. setCaretPosition(21);
  64. gSources._onCmdAddBreakpoint();
  65. return finished;
  66. }
  67. function delBreakpoint4() {
  68. let finished = waitForDispatch(gPanel, constants.REMOVE_BREAKPOINT);
  69. setCaretPosition(21);
  70. gSources._onCmdAddBreakpoint();
  71. return finished;
  72. }
  73. function testBreakpoint(aLine, aPopupVisible, aConditionalExpression) {
  74. const source = queries.getSelectedSource(getState());
  75. ok(source,
  76. "There should be a selected item in the sources pane.");
  77. const bp = queries.getBreakpoint(getState(), {
  78. actor: source.actor,
  79. line: aLine
  80. });
  81. const bpItem = gSources._getBreakpoint(bp);
  82. ok(bp, "There should be a breakpoint.");
  83. ok(bpItem, "There should be a breakpoint in the sources pane.");
  84. is(bp.location.actor, source.actor,
  85. "The breakpoint on line " + aLine + " wasn't added on the correct source.");
  86. is(bp.location.line, aLine,
  87. "The breakpoint on line " + aLine + " wasn't found.");
  88. is(!!bp.disabled, false,
  89. "The breakpoint on line " + aLine + " should be enabled.");
  90. is(gSources._conditionalPopupVisible, aPopupVisible,
  91. "The breakpoint on line " + aLine + " should have a correct popup state (2).");
  92. is(bp.condition, aConditionalExpression,
  93. "The breakpoint on line " + aLine + " should have a correct conditional expression.");
  94. }
  95. function testNoBreakpoint(aLine) {
  96. let selectedActor = gSources.selectedValue;
  97. let selectedBreakpoint = gSources._selectedBreakpoint;
  98. ok(selectedActor,
  99. "There should be a selected item in the sources pane for line " + aLine + ".");
  100. ok(!selectedBreakpoint,
  101. "There should be no selected brekapoint in the sources pane for line " + aLine + ".");
  102. ok(isCaretPos(gPanel, aLine),
  103. "The editor caret position is not properly set.");
  104. }
  105. function setCaretPosition(aLine) {
  106. gEditor.setCursor({ line: aLine - 1, ch: 0 });
  107. }
  108. function clickOnBreakpoint(aIndex) {
  109. EventUtils.sendMouseEvent({ type: "click" },
  110. gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex],
  111. gDebugger);
  112. }
  113. function waitForConditionUpdate() {
  114. // This will close the popup and send another request to update
  115. // the condition
  116. gSources._hideConditionalPopup();
  117. return waitForDispatch(gPanel, constants.SET_BREAKPOINT_CONDITION);
  118. }
  119. Task.spawn(function* () {
  120. let onCaretUpdated = waitForCaretAndScopes(gPanel, 17);
  121. callInTab(gTab, "ermahgerd");
  122. yield onCaretUpdated;
  123. is(gDebugger.gThreadClient.state, "paused",
  124. "Should only be getting stack frames while paused.");
  125. is(queries.getSourceCount(getState()), 1,
  126. "Found the expected number of sources.");
  127. is(gEditor.getText().indexOf("ermahgerd"), 253,
  128. "The correct source was loaded initially.");
  129. is(gSources.selectedValue, gSources.values[0],
  130. "The correct source is selected.");
  131. is(queries.getBreakpoints(getState()).length, 0,
  132. "No breakpoints currently added.");
  133. yield addBreakpoint1();
  134. testBreakpoint(18, false, undefined);
  135. yield addBreakpoint2();
  136. testBreakpoint(19, false, undefined);
  137. yield modBreakpoint2();
  138. testBreakpoint(19, true, undefined);
  139. yield waitForConditionUpdate();
  140. yield addBreakpoint3();
  141. testBreakpoint(20, true, "");
  142. yield waitForConditionUpdate();
  143. yield modBreakpoint3();
  144. testBreakpoint(20, false, "bamboocha");
  145. yield addBreakpoint4();
  146. testBreakpoint(21, false, undefined);
  147. yield delBreakpoint4();
  148. setCaretPosition(18);
  149. is(gSources._selectedBreakpoint.location.line, 18,
  150. "The selected breakpoint is line 18");
  151. yield testBreakpoint(18, false, undefined);
  152. setCaretPosition(19);
  153. is(gSources._selectedBreakpoint.location.line, 19,
  154. "The selected breakpoint is line 19");
  155. yield testBreakpoint(19, false, "");
  156. setCaretPosition(20);
  157. is(gSources._selectedBreakpoint.location.line, 20,
  158. "The selected breakpoint is line 20");
  159. yield testBreakpoint(20, false, "bamboocha");
  160. setCaretPosition(17);
  161. yield testNoBreakpoint(17);
  162. setCaretPosition(21);
  163. yield testNoBreakpoint(21);
  164. clickOnBreakpoint(0);
  165. is(gSources._selectedBreakpoint.location.line, 18,
  166. "The selected breakpoint is line 18");
  167. yield testBreakpoint(18, false, undefined);
  168. clickOnBreakpoint(1);
  169. is(gSources._selectedBreakpoint.location.line, 19,
  170. "The selected breakpoint is line 19");
  171. yield testBreakpoint(19, false, "");
  172. clickOnBreakpoint(2);
  173. is(gSources._selectedBreakpoint.location.line, 20,
  174. "The selected breakpoint is line 20");
  175. testBreakpoint(20, true, "bamboocha");
  176. // Reset traits back to default value
  177. client.mainRoot.traits.conditionalBreakpoints = true;
  178. resumeDebuggerThenCloseAndFinish(gPanel);
  179. });
  180. });
  181. }