browser_dbg_break-on-dom-02.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. * Tests that event listeners are fetched when the events tab is selected
  6. * or while sources are fetched and the events tab is focused.
  7. */
  8. const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html";
  9. function test() {
  10. let options = {
  11. source: TAB_URL,
  12. line: 1
  13. };
  14. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  15. let gPanel = aPanel;
  16. let gDebugger = aPanel.panelWin;
  17. let gView = gDebugger.DebuggerView;
  18. let gEvents = gView.EventListeners;
  19. let gController = gDebugger.DebuggerController;
  20. let constants = gDebugger.require("./content/constants");
  21. Task.spawn(function* () {
  22. yield testFetchOnFocus();
  23. yield testFetchOnReloadWhenFocused();
  24. yield testFetchOnReloadWhenNotFocused();
  25. yield closeDebuggerAndFinish(aPanel);
  26. });
  27. function testFetchOnFocus() {
  28. return Task.spawn(function* () {
  29. let fetched = waitForDispatch(aPanel, constants.FETCH_EVENT_LISTENERS);
  30. gView.toggleInstrumentsPane({ visible: true, animated: false }, 1);
  31. is(gView.instrumentsPaneHidden, false,
  32. "The instruments pane should be visible now.");
  33. is(gView.instrumentsPaneTab, "events-tab",
  34. "The events tab should be selected.");
  35. yield fetched;
  36. ok(true,
  37. "Event listeners were fetched when the events tab was selected");
  38. is(gEvents.itemCount, 4,
  39. "There should be 4 events displayed in the view.");
  40. });
  41. }
  42. function testFetchOnReloadWhenFocused() {
  43. return Task.spawn(function* () {
  44. let fetched = waitForDispatch(aPanel, constants.FETCH_EVENT_LISTENERS);
  45. let reloading = once(gDebugger.gTarget, "will-navigate");
  46. let reloaded = waitForNavigation(gPanel);
  47. gDebugger.DebuggerController._target.activeTab.reload();
  48. yield reloading;
  49. is(gEvents.itemCount, 0,
  50. "There should be no events displayed in the view while reloading.");
  51. ok(true,
  52. "Event listeners were removed when the target started navigating.");
  53. yield reloaded;
  54. is(gView.instrumentsPaneHidden, false,
  55. "The instruments pane should still be visible.");
  56. is(gView.instrumentsPaneTab, "events-tab",
  57. "The events tab should still be selected.");
  58. yield fetched;
  59. is(gEvents.itemCount, 4,
  60. "There should be 4 events displayed in the view after reloading.");
  61. ok(true,
  62. "Event listeners were added back after the target finished navigating.");
  63. });
  64. }
  65. function testFetchOnReloadWhenNotFocused() {
  66. return Task.spawn(function* () {
  67. gController.dispatch({
  68. type: gDebugger.services.WAIT_UNTIL,
  69. predicate: action => {
  70. return (action.type === constants.FETCH_EVENT_LISTENERS ||
  71. action.type === constants.UPDATE_EVENT_BREAKPOINTS);
  72. },
  73. run: (dispatch, getState, action) => {
  74. if (action.type === constants.FETCH_EVENT_LISTENERS) {
  75. ok(false, "Shouldn't have fetched any event listeners.");
  76. }
  77. else if (action.type === constants.UPDATE_EVENT_BREAKPOINTS) {
  78. ok(false, "Shouldn't have updated any event breakpoints.");
  79. }
  80. }
  81. });
  82. gView.toggleInstrumentsPane({ visible: true, animated: false }, 0);
  83. is(gView.instrumentsPaneHidden, false,
  84. "The instruments pane should still be visible.");
  85. is(gView.instrumentsPaneTab, "variables-tab",
  86. "The variables tab should be selected.");
  87. let reloading = once(gDebugger.gTarget, "will-navigate");
  88. let reloaded = waitForNavigation(gPanel);
  89. gDebugger.DebuggerController._target.activeTab.reload();
  90. yield reloading;
  91. is(gEvents.itemCount, 0,
  92. "There should be no events displayed in the view while reloading.");
  93. ok(true,
  94. "Event listeners were removed when the target started navigating.");
  95. yield reloaded;
  96. is(gView.instrumentsPaneHidden, false,
  97. "The instruments pane should still be visible.");
  98. is(gView.instrumentsPaneTab, "variables-tab",
  99. "The variables tab should still be selected.");
  100. // Just to be really sure that the events will never ever fire.
  101. yield waitForTime(1000);
  102. is(gEvents.itemCount, 0,
  103. "There should be no events displayed in the view after reloading.");
  104. ok(true,
  105. "Event listeners were not added after the target finished navigating.");
  106. });
  107. }
  108. });
  109. }