browser_dbg_breakpoints-pane.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 723071: Test adding a pane to display the list of breakpoints across
  6. * all sources in the debuggee.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  9. function test() {
  10. let options = {
  11. source: EXAMPLE_URL + "code_script-switching-01.js",
  12. line: 1
  13. };
  14. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  15. const gTab = aTab;
  16. const gPanel = aPanel;
  17. const gDebugger = gPanel.panelWin;
  18. const gEditor = gDebugger.DebuggerView.editor;
  19. const gSources = gDebugger.DebuggerView.Sources;
  20. const queries = gDebugger.require("./content/queries");
  21. const actions = bindActionCreators(gPanel);
  22. const getState = gDebugger.DebuggerController.getState;
  23. const { getBreakpoint } = queries;
  24. let breakpointsAdded = 0;
  25. let breakpointsDisabled = 0;
  26. let breakpointsRemoved = 0;
  27. let breakpointsList;
  28. const addBreakpoints = Task.async(function* (aIncrementFlag) {
  29. const loc1 = { actor: gSources.selectedValue, line: 6 };
  30. yield actions.addBreakpoint(loc1);
  31. onBreakpointAdd(getBreakpoint(getState(), loc1), {
  32. increment: aIncrementFlag,
  33. line: 6,
  34. text: "debugger;"
  35. });
  36. const loc2 = { actor: gSources.selectedValue, line: 7 };
  37. yield actions.addBreakpoint(loc2);
  38. onBreakpointAdd(getBreakpoint(getState(), loc2), {
  39. increment: aIncrementFlag,
  40. line: 7,
  41. text: "function foo() {}"
  42. });
  43. const loc3 = {actor: gSources.selectedValue, line: 9 };
  44. yield actions.addBreakpoint(loc3);
  45. onBreakpointAdd(getBreakpoint(getState(), loc3), {
  46. increment: aIncrementFlag,
  47. line: 9,
  48. text: "foo();"
  49. });
  50. });
  51. function disableBreakpoints() {
  52. let deferred = promise.defer();
  53. let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
  54. info("Nodes to disable: " + breakpointsAdded.length);
  55. is(nodes.length, breakpointsAdded,
  56. "The number of nodes to disable is incorrect.");
  57. for (let node of nodes) {
  58. info("Disabling breakpoint: " + node.id);
  59. let sourceItem = gSources.getItemForElement(node);
  60. let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
  61. info("Found data: " + breakpointItem.attachment.toSource());
  62. actions.disableBreakpoint(breakpointItem.attachment).then(() => {
  63. if (++breakpointsDisabled == breakpointsAdded) {
  64. deferred.resolve();
  65. }
  66. });
  67. }
  68. return deferred.promise;
  69. }
  70. function removeBreakpoints() {
  71. let deferred = promise.defer();
  72. let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
  73. info("Nodes to remove: " + breakpointsAdded.length);
  74. is(nodes.length, breakpointsAdded,
  75. "The number of nodes to remove is incorrect.");
  76. for (let node of nodes) {
  77. info("Removing breakpoint: " + node.id);
  78. let sourceItem = gSources.getItemForElement(node);
  79. let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
  80. info("Found data: " + breakpointItem.attachment.toSource());
  81. actions.removeBreakpoint(breakpointItem.attachment).then(() => {
  82. if (++breakpointsRemoved == breakpointsAdded) {
  83. deferred.resolve();
  84. }
  85. });
  86. }
  87. return deferred.promise;
  88. }
  89. function onBreakpointAdd(bp, testData) {
  90. if (testData.increment) {
  91. breakpointsAdded++;
  92. }
  93. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
  94. testData.increment
  95. ? "Should have added a breakpoint in the pane."
  96. : "Should have the same number of breakpoints in the pane.");
  97. let identifier = queries.makeLocationId(bp.location);
  98. let node = gDebugger.document.getElementById("breakpoint-" + identifier);
  99. let line = node.getElementsByClassName("dbg-breakpoint-line")[0];
  100. let text = node.getElementsByClassName("dbg-breakpoint-text")[0];
  101. let check = node.querySelector("checkbox");
  102. ok(node,
  103. "Breakpoint element found successfully.");
  104. is(line.getAttribute("value"), testData.line,
  105. "The expected information wasn't found in the breakpoint element.");
  106. is(text.getAttribute("value"), testData.text,
  107. "The expected line text wasn't found in the breakpoint element.");
  108. is(check.getAttribute("checked"), "true",
  109. "The breakpoint enable checkbox is checked as expected.");
  110. }
  111. Task.spawn(function* () {
  112. yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1);
  113. is(gDebugger.gThreadClient.state, "paused",
  114. "Should only be getting stack frames while paused.");
  115. is(queries.getSourceCount(getState()), 2,
  116. "Found the expected number of sources.");
  117. is(gEditor.getText().indexOf("debugger"), 166,
  118. "The correct source was loaded initially.");
  119. is(gSources.selectedValue, gSources.values[1],
  120. "The correct source is selected.");
  121. is(queries.getBreakpoints(getState()).length, 0,
  122. "No breakpoints currently added.");
  123. let breakpointsParent = gSources.widget._parent;
  124. breakpointsList = gSources.widget._list;
  125. is(breakpointsParent.childNodes.length, 1, // one sources list
  126. "Found junk in the breakpoints container.");
  127. is(breakpointsList.childNodes.length, 1, // one sources group
  128. "Found junk in the breakpoints container.");
  129. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
  130. "No breakpoints should be visible at this point.");
  131. yield addBreakpoints(true);
  132. is(breakpointsAdded, 3,
  133. "Should have added 3 breakpoints so far.");
  134. is(breakpointsDisabled, 0,
  135. "Shouldn't have disabled anything so far.");
  136. is(breakpointsRemoved, 0,
  137. "Shouldn't have removed anything so far.");
  138. is(breakpointsParent.childNodes.length, 1, // one sources list
  139. "Found junk in the breakpoints container.");
  140. is(breakpointsList.childNodes.length, 1, // one sources group
  141. "Found junk in the breakpoints container.");
  142. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 3,
  143. "3 breakpoints should be visible at this point.");
  144. yield disableBreakpoints();
  145. is(breakpointsAdded, 3,
  146. "Should still have 3 breakpoints added so far.");
  147. is(breakpointsDisabled, 3,
  148. "Should have 3 disabled breakpoints.");
  149. is(breakpointsRemoved, 0,
  150. "Shouldn't have removed anything so far.");
  151. is(breakpointsParent.childNodes.length, 1, // one sources list
  152. "Found junk in the breakpoints container.");
  153. is(breakpointsList.childNodes.length, 1, // one sources group
  154. "Found junk in the breakpoints container.");
  155. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
  156. "Should have the same number of breakpoints in the pane.");
  157. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsDisabled,
  158. "Should have the same number of disabled breakpoints.");
  159. yield addBreakpoints();
  160. is(breakpointsAdded, 3,
  161. "Should still have only 3 breakpoints added so far.");
  162. is(breakpointsDisabled, 3,
  163. "Should still have 3 disabled breakpoints.");
  164. is(breakpointsRemoved, 0,
  165. "Shouldn't have removed anything so far.");
  166. is(breakpointsParent.childNodes.length, 1, // one sources list
  167. "Found junk in the breakpoints container.");
  168. is(breakpointsList.childNodes.length, 1, // one sources group
  169. "Found junk in the breakpoints container.");
  170. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
  171. "Since half of the breakpoints already existed, but disabled, " +
  172. "only half of the added breakpoints are actually in the pane.");
  173. yield removeBreakpoints();
  174. is(breakpointsRemoved, 3,
  175. "Should have 3 removed breakpoints.");
  176. is(breakpointsParent.childNodes.length, 1, // one sources list
  177. "Found junk in the breakpoints container.");
  178. is(breakpointsList.childNodes.length, 1, // one sources group
  179. "Found junk in the breakpoints container.");
  180. is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
  181. "No breakpoints should be visible at this point.");
  182. const cleared = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED);
  183. gDebugger.gThreadClient.resume();
  184. yield cleared;
  185. is(queries.getBreakpoints(getState()).length, 0,
  186. "No breakpoints currently added.");
  187. closeDebuggerAndFinish(gPanel);
  188. });
  189. callInTab(gTab, "firstCall");
  190. });
  191. }