browser_dbg_server-conditional-bp-05.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 conditional breakpoints throwing exceptions
  6. * with server support
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";
  9. function test() {
  10. const options = {
  11. source: TAB_URL,
  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 constants = gDebugger.require("./content/constants");
  22. const actions = bindActionCreators(gPanel);
  23. const getState = gDebugger.DebuggerController.getState;
  24. function resumeAndTestBreakpoint(line) {
  25. let finished = waitForCaretUpdated(gPanel, line).then(() => testBreakpoint(line));
  26. EventUtils.sendMouseEvent({ type: "mousedown" },
  27. gDebugger.document.getElementById("resume"),
  28. gDebugger);
  29. return finished;
  30. }
  31. function resumeAndTestNoBreakpoint() {
  32. let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
  33. is(gSources.itemCount, 1,
  34. "Found the expected number of sources.");
  35. is(gEditor.getText().indexOf("ermahgerd"), 253,
  36. "The correct source was loaded initially.");
  37. is(gSources.selectedValue, gSources.values[0],
  38. "The correct source is selected.");
  39. ok(gSources.selectedItem,
  40. "There should be a selected source in the sources pane.");
  41. ok(!gSources._selectedBreakpoint,
  42. "There should be no selected breakpoint in the sources pane.");
  43. is(gSources._conditionalPopupVisible, false,
  44. "The breakpoint conditional expression popup should not be shown.");
  45. is(gDebugger.document.querySelectorAll(".dbg-stackframe").length, 0,
  46. "There should be no visible stackframes.");
  47. is(gDebugger.document.querySelectorAll(".dbg-breakpoint").length, 6,
  48. "There should be thirteen visible breakpoints.");
  49. });
  50. gDebugger.gThreadClient.resume();
  51. return finished;
  52. }
  53. function testBreakpoint(line, highlightBreakpoint) {
  54. // Highlight the breakpoint only if required.
  55. if (highlightBreakpoint) {
  56. let finished = waitForCaretUpdated(gPanel, line).then(() => testBreakpoint(line));
  57. gSources.highlightBreakpoint({ actor: gSources.selectedValue, line: line });
  58. return finished;
  59. }
  60. let selectedActor = gSources.selectedValue;
  61. let selectedBreakpoint = gSources._selectedBreakpoint;
  62. let selectedBreakpointItem = gSources._getBreakpoint(selectedBreakpoint);
  63. let source = queries.getSource(getState(), selectedActor);
  64. ok(selectedActor,
  65. "There should be a selected item in the sources pane.");
  66. ok(selectedBreakpoint,
  67. "There should be a selected breakpoint.");
  68. ok(selectedBreakpointItem,
  69. "There should be a selected breakpoint item in the sources pane.");
  70. is(selectedBreakpoint.location.actor, source.actor,
  71. "The breakpoint on line " + line + " wasn't added on the correct source.");
  72. is(selectedBreakpoint.location.line, line,
  73. "The breakpoint on line " + line + " wasn't found.");
  74. is(!!selectedBreakpoint.location.disabled, false,
  75. "The breakpoint on line " + line + " should be enabled.");
  76. is(gSources._conditionalPopupVisible, false,
  77. "The breakpoint conditional expression popup should not have been shown.");
  78. isnot(selectedBreakpoint.condition, undefined,
  79. "The breakpoint on line " + line + " should have a conditional expression.");
  80. ok(isCaretPos(gPanel, line),
  81. "The editor caret position is not properly set.");
  82. }
  83. Task.spawn(function* () {
  84. let onCaretUpdated = waitForCaretAndScopes(gPanel, 17);
  85. callInTab(gTab, "ermahgerd");
  86. yield onCaretUpdated;
  87. yield actions.addBreakpoint(
  88. { actor: gSources.selectedValue, line: 18 }, " 1a"
  89. );
  90. yield actions.addBreakpoint(
  91. { actor: gSources.selectedValue, line: 19 }, "new Error()"
  92. );
  93. yield actions.addBreakpoint(
  94. { actor: gSources.selectedValue, line: 20 }, "true"
  95. );
  96. yield actions.addBreakpoint(
  97. { actor: gSources.selectedValue, line: 21 }, "false"
  98. );
  99. yield actions.addBreakpoint(
  100. { actor: gSources.selectedValue, line: 22 }, "0"
  101. );
  102. yield actions.addBreakpoint(
  103. { actor: gSources.selectedValue, line: 23 }, "randomVar"
  104. );
  105. yield resumeAndTestBreakpoint(18);
  106. yield resumeAndTestBreakpoint(19);
  107. yield resumeAndTestBreakpoint(20);
  108. yield resumeAndTestBreakpoint(23);
  109. yield resumeAndTestNoBreakpoint();
  110. closeDebuggerAndFinish(gPanel);
  111. });
  112. });
  113. }