browser_dbg_breakpoints-contextmenu.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 if the context menu associated with each breakpoint does what it should.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  8. function test() {
  9. // Debug test slaves are a bit slow at this test.
  10. requestLongerTimeout(2);
  11. Task.spawn(function* () {
  12. const options = {
  13. source: EXAMPLE_URL + "code_script-switching-01.js",
  14. line: 1
  15. };
  16. const [gTab,, gPanel ] = yield initDebugger(TAB_URL, options);
  17. const gDebugger = gPanel.panelWin;
  18. const gSources = gDebugger.DebuggerView.Sources;
  19. const queries = gDebugger.require("./content/queries");
  20. const actions = bindActionCreators(gPanel);
  21. const getState = gDebugger.DebuggerController.getState;
  22. const addBreakpoints = Task.async(function* () {
  23. yield actions.addBreakpoint({ actor: gSources.values[0], line: 5 });
  24. yield actions.addBreakpoint({ actor: gSources.values[1], line: 6 });
  25. yield actions.addBreakpoint({ actor: gSources.values[1], line: 7 });
  26. yield actions.addBreakpoint({ actor: gSources.values[1], line: 8 });
  27. yield actions.addBreakpoint({ actor: gSources.values[1], line: 9 });
  28. yield ensureThreadClientState(gPanel, "resumed");
  29. gSources.highlightBreakpoint({ actor: gSources.values[1], line: 9 });
  30. });
  31. const pauseAndCheck = Task.async(function* () {
  32. let source = queries.getSelectedSource(getState());
  33. is(source.url, EXAMPLE_URL + "code_script-switching-02.js",
  34. "The currently selected source is incorrect (1).");
  35. is(gSources.selectedIndex, 1,
  36. "The currently selected source is incorrect (2).");
  37. ok(isCaretPos(gPanel, 9),
  38. "The editor location is correct before pausing.");
  39. generateMouseClickInTab(gTab, "content.document.querySelector('button')");
  40. return waitForSourceAndCaretAndScopes(gPanel, "-01.js", 5).then(() => {
  41. let source = queries.getSelectedSource(getState());
  42. is(source.url, EXAMPLE_URL + "code_script-switching-01.js",
  43. "The currently selected source is incorrect (3).");
  44. is(gSources.selectedIndex, 0,
  45. "The currently selected source is incorrect (4).");
  46. ok(isCaretPos(gPanel, 5),
  47. "The editor location is correct after pausing.");
  48. });
  49. });
  50. let initialChecks = Task.async(function* () {
  51. for (let bp of queries.getBreakpoints(getState())) {
  52. ok(bp.actor, "All breakpoint items should have an actor");
  53. ok(!bp.disabled, "All breakpoints should initially be enabled.");
  54. let prefix = "bp-cMenu-"; // "breakpoints context menu"
  55. let identifier = queries.makeLocationId(bp.location);
  56. let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
  57. let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
  58. // Check to make sure that only the bp context menu is shown when right clicking
  59. // this node (Bug 1159276).
  60. let breakpointItem = gSources._getBreakpoint(bp);
  61. let menu = gDebugger.document.getElementById("bp-mPop-" + identifier);
  62. let contextMenuShown = once(gDebugger.document, "popupshown");
  63. EventUtils.synthesizeMouseAtCenter(breakpointItem.prebuiltNode, {type: "contextmenu", button: 2}, gDebugger);
  64. let event = yield contextMenuShown;
  65. is(event.originalTarget.id, menu.id, "The correct context menu was shown");
  66. let contextMenuHidden = once(gDebugger.document, "popuphidden");
  67. menu.hidePopup();
  68. yield contextMenuHidden;
  69. is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
  70. "The 'Enable breakpoint' context menu item should initially be hidden'.");
  71. ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
  72. "The 'Disable breakpoint' context menu item should initially not be hidden'.");
  73. is(breakpointItem.attachment.view.checkbox.getAttribute("checked"), "true",
  74. "All breakpoints should initially have a checked checkbox.");
  75. }
  76. });
  77. const checkBreakpointToggleSelf = Task.async(function* (index) {
  78. EventUtils.sendMouseEvent({ type: "click" },
  79. gDebugger.document.querySelectorAll(".dbg-breakpoint")[index],
  80. gDebugger);
  81. let selectedBreakpoint = gSources._selectedBreakpoint;
  82. let selectedBreakpointItem = gSources._getBreakpoint(selectedBreakpoint);
  83. ok(selectedBreakpoint.actor,
  84. "Selected breakpoint should have an actor.");
  85. ok(!selectedBreakpoint.disabled,
  86. "The breakpoint should not be disabled yet (" + index + ").");
  87. let prefix = "bp-cMenu-"; // "breakpoints context menu"
  88. let identifier = queries.makeLocationId(selectedBreakpoint.location);
  89. let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
  90. let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
  91. is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
  92. "The 'Enable breakpoint' context menu item should be hidden'.");
  93. ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
  94. "The 'Disable breakpoint' context menu item should not be hidden'.");
  95. ok(isCaretPos(gPanel, selectedBreakpoint.location.line),
  96. "The source editor caret position was incorrect (" + index + ").");
  97. // Test disabling this breakpoint.
  98. gSources._onDisableSelf(selectedBreakpoint.location);
  99. yield waitForDispatch(gPanel, gDebugger.constants.REMOVE_BREAKPOINT);
  100. ok(!!queries.getBreakpoint(getState(), selectedBreakpoint.location).disabled,
  101. "The breakpoint should be disabled.");
  102. ok(!gDebugger.document.getElementById(enableSelfId).hasAttribute("hidden"),
  103. "The 'Enable breakpoint' context menu item should not be hidden'.");
  104. is(gDebugger.document.getElementById(disableSelfId).getAttribute("hidden"), "true",
  105. "The 'Disable breakpoint' context menu item should be hidden'.");
  106. ok(!selectedBreakpointItem.attachment.view.checkbox.hasAttribute("checked"),
  107. "The breakpoint should now be unchecked.");
  108. gSources._onEnableSelf(selectedBreakpoint.location);
  109. yield waitForDispatch(gPanel, gDebugger.constants.ADD_BREAKPOINT);
  110. ok(!queries.getBreakpoint(getState(), selectedBreakpoint.location).disabled,
  111. "The breakpoint should be enabled.");
  112. is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
  113. "The 'Enable breakpoint' context menu item should be hidden'.");
  114. ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
  115. "The 'Disable breakpoint' context menu item should not be hidden'.");
  116. ok(selectedBreakpointItem.attachment.view.checkbox.hasAttribute("checked"),
  117. "The breakpoint should now be checked.");
  118. });
  119. const checkBreakpointToggleOthers = Task.async(function* (index) {
  120. EventUtils.sendMouseEvent(
  121. { type: "click" },
  122. gDebugger.document.querySelectorAll(".dbg-breakpoint")[index],
  123. gDebugger
  124. );
  125. // Test disabling other breakpoints.
  126. disableOthers();
  127. yield waitForDispatch(gPanel, gDebugger.constants.REMOVE_BREAKPOINT, 4);
  128. let selectedBreakpoint = queries.getBreakpoint(getState(), gSources._selectedBreakpoint.location);
  129. ok(selectedBreakpoint.actor,
  130. "There should be a breakpoint actor.");
  131. ok(!selectedBreakpoint.disabled,
  132. "The targetted breakpoint should not have been disabled (" + index + ").");
  133. for (let bp of queries.getBreakpoints(getState())) {
  134. if (bp !== selectedBreakpoint) {
  135. ok(bp.disabled,
  136. "Non-targetted breakpoints should have been disabled.");
  137. }
  138. }
  139. // Test re-enabling other breakpoints.
  140. enableOthers();
  141. yield waitForDispatch(gPanel, gDebugger.constants.ADD_BREAKPOINT, 4);
  142. for (let bp of queries.getBreakpoints(getState())) {
  143. ok(!bp.disabled, "All breakpoints should be enabled.");
  144. }
  145. // Test disabling all breakpoints.
  146. disableAll();
  147. yield waitForDispatch(gPanel, gDebugger.constants.REMOVE_BREAKPOINT, 5);
  148. for (let bp of queries.getBreakpoints(getState())) {
  149. ok(!!bp.disabled, "All breakpoints should be disabled.");
  150. }
  151. // Test re-enabling all breakpoints.
  152. enableAll();
  153. yield waitForDispatch(gPanel, gDebugger.constants.ADD_BREAKPOINT, 5);
  154. for (let bp of queries.getBreakpoints(getState())) {
  155. ok(!bp.disabled, "All breakpoints should be enabled.");
  156. }
  157. });
  158. const testDeleteAll = Task.async(function* () {
  159. // Test deleting all breakpoints.
  160. deleteAll();
  161. yield waitForDispatch(gPanel, gDebugger.constants.REMOVE_BREAKPOINT, 5);
  162. ok(!gSources._selectedBreakpoint,
  163. "There should be no breakpoint available after removing all breakpoints.");
  164. for (let bp of queries.getBreakpoints(getState())) {
  165. ok(false, "It's a trap!");
  166. }
  167. });
  168. function disableOthers() {
  169. gSources._onDisableOthers(gSources._selectedBreakpoint.location);
  170. }
  171. function enableOthers() {
  172. gSources._onEnableOthers(gSources._selectedBreakpoint.location);
  173. }
  174. function disableAll() {
  175. gSources._onDisableAll();
  176. }
  177. function enableAll() {
  178. gSources._onEnableAll();
  179. }
  180. function deleteAll() {
  181. gSources._onDeleteAll();
  182. }
  183. yield addBreakpoints();
  184. yield initialChecks();
  185. yield checkBreakpointToggleSelf(0);
  186. yield checkBreakpointToggleOthers(0);
  187. yield checkBreakpointToggleSelf(1);
  188. yield checkBreakpointToggleOthers(1);
  189. yield checkBreakpointToggleSelf(2);
  190. yield checkBreakpointToggleOthers(2);
  191. yield checkBreakpointToggleSelf(3);
  192. yield checkBreakpointToggleOthers(3);
  193. yield checkBreakpointToggleSelf(4);
  194. yield checkBreakpointToggleOthers(4);
  195. yield testDeleteAll();
  196. yield addBreakpoints();
  197. yield initialChecks();
  198. yield pauseAndCheck();
  199. yield checkBreakpointToggleSelf(0);
  200. yield checkBreakpointToggleOthers(0);
  201. yield checkBreakpointToggleSelf(1);
  202. yield checkBreakpointToggleOthers(1);
  203. yield checkBreakpointToggleSelf(2);
  204. yield checkBreakpointToggleOthers(2);
  205. yield checkBreakpointToggleSelf(3);
  206. yield checkBreakpointToggleOthers(3);
  207. yield checkBreakpointToggleSelf(4);
  208. yield checkBreakpointToggleOthers(4);
  209. yield testDeleteAll();
  210. resumeDebuggerThenCloseAndFinish(gPanel);
  211. });
  212. }