browser_dbg_breakpoints-disabled-reload.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 that disabled breakpoints survive target navigation.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
  8. function test() {
  9. let options = {
  10. source: EXAMPLE_URL + "code_script-switching-01.js",
  11. line: 1
  12. };
  13. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  14. const gPanel = aPanel;
  15. const gTab = aTab;
  16. const gDebugger = gPanel.panelWin;
  17. const gEvents = gDebugger.EVENTS;
  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. let gBreakpointLocation;
  24. Task.spawn(function* () {
  25. gBreakpointLocation = { actor: getSourceActor(gSources, EXAMPLE_URL + "code_script-switching-01.js"),
  26. line: 5 };
  27. yield actions.addBreakpoint(gBreakpointLocation);
  28. yield ensureThreadClientState(gPanel, "resumed");
  29. yield testWhenBreakpointEnabledAndFirstSourceShown();
  30. gSources._preferredSourceURL = EXAMPLE_URL + "code_script-switching-02.js";
  31. yield reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN);
  32. yield testWhenBreakpointEnabledAndSecondSourceShown();
  33. yield actions.disableBreakpoint(gBreakpointLocation);
  34. yield reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN);
  35. yield testWhenBreakpointDisabledAndSecondSourceShown();
  36. yield actions.enableBreakpoint(gBreakpointLocation);
  37. yield reloadActiveTab(gPanel, gEvents.SOURCE_SHOWN);
  38. yield testWhenBreakpointEnabledAndSecondSourceShown();
  39. yield resumeDebuggerThenCloseAndFinish(gPanel);
  40. });
  41. function verifyView({ disabled }) {
  42. return Task.spawn(function* () {
  43. // It takes a tick for the checkbox in the SideMenuWidget and the
  44. // gutter in the editor to get updated.
  45. yield waitForTick();
  46. let breakpoint = queries.getBreakpoint(getState(), gBreakpointLocation);
  47. let breakpointItem = gSources._getBreakpoint(breakpoint);
  48. is(!!breakpoint.disabled, disabled,
  49. "The selected breakpoint state was correct.");
  50. is(breakpointItem.attachment.view.checkbox.hasAttribute("checked"), !disabled,
  51. "The selected breakpoint's checkbox state was correct.");
  52. });
  53. }
  54. // All the following executeSoon()'s are required to spin the event loop
  55. // before causing the debuggee to pause, to allow functions to yield first.
  56. function testWhenBreakpointEnabledAndFirstSourceShown() {
  57. return Task.spawn(function* () {
  58. yield ensureSourceIs(gPanel, "-01.js");
  59. yield verifyView({ disabled: false });
  60. callInTab(gTab, "firstCall");
  61. yield waitForDebuggerEvents(gPanel, gEvents.FETCHED_SCOPES);
  62. yield ensureSourceIs(gPanel, "-01.js");
  63. yield ensureCaretAt(gPanel, 5);
  64. yield verifyView({ disabled: false });
  65. executeSoon(() => gDebugger.gThreadClient.resume());
  66. yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6);
  67. yield verifyView({ disabled: false });
  68. });
  69. }
  70. function testWhenBreakpointEnabledAndSecondSourceShown() {
  71. return Task.spawn(function* () {
  72. yield ensureSourceIs(gPanel, "-02.js", true);
  73. yield verifyView({ disabled: false });
  74. callInTab(gTab, "firstCall");
  75. yield waitForSourceAndCaretAndScopes(gPanel, "-01.js", 1);
  76. yield verifyView({ disabled: false });
  77. executeSoon(() => gDebugger.gThreadClient.resume());
  78. yield waitForSourceAndCaretAndScopes(gPanel, "-02.js", 6);
  79. yield verifyView({ disabled: false });
  80. });
  81. }
  82. function testWhenBreakpointDisabledAndSecondSourceShown() {
  83. return Task.spawn(function* () {
  84. yield ensureSourceIs(gPanel, "-02.js", true);
  85. yield verifyView({ disabled: true });
  86. callInTab(gTab, "firstCall");
  87. yield waitForDebuggerEvents(gPanel, gEvents.FETCHED_SCOPES);
  88. yield ensureSourceIs(gPanel, "-02.js");
  89. yield ensureCaretAt(gPanel, 6);
  90. yield verifyView({ disabled: true });
  91. executeSoon(() => gDebugger.gThreadClient.resume());
  92. yield waitForDebuggerEvents(gPanel, gEvents.AFTER_FRAMES_CLEARED);
  93. yield ensureSourceIs(gPanel, "-02.js");
  94. yield ensureCaretAt(gPanel, 6);
  95. yield verifyView({ disabled: true });
  96. });
  97. }
  98. });
  99. }