summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_break-on-dom-02.js
blob: 03d355f7334e5288d64a1325133dfa5c5097d0f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that event listeners are fetched when the events tab is selected
 * or while sources are fetched and the events tab is focused.
 */

const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html";

function test() {
  let options = {
    source: TAB_URL,
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    let gPanel = aPanel;
    let gDebugger = aPanel.panelWin;
    let gView = gDebugger.DebuggerView;
    let gEvents = gView.EventListeners;
    let gController = gDebugger.DebuggerController;
    let constants = gDebugger.require("./content/constants");

    Task.spawn(function* () {
      yield testFetchOnFocus();
      yield testFetchOnReloadWhenFocused();
      yield testFetchOnReloadWhenNotFocused();
      yield closeDebuggerAndFinish(aPanel);
    });

    function testFetchOnFocus() {
      return Task.spawn(function* () {
        let fetched = waitForDispatch(aPanel, constants.FETCH_EVENT_LISTENERS);

        gView.toggleInstrumentsPane({ visible: true, animated: false }, 1);
        is(gView.instrumentsPaneHidden, false,
          "The instruments pane should be visible now.");
        is(gView.instrumentsPaneTab, "events-tab",
          "The events tab should be selected.");

        yield fetched;

        ok(true,
          "Event listeners were fetched when the events tab was selected");
        is(gEvents.itemCount, 4,
          "There should be 4 events displayed in the view.");
      });
    }

    function testFetchOnReloadWhenFocused() {
      return Task.spawn(function* () {
        let fetched = waitForDispatch(aPanel, constants.FETCH_EVENT_LISTENERS);

        let reloading = once(gDebugger.gTarget, "will-navigate");
        let reloaded = waitForNavigation(gPanel);
        gDebugger.DebuggerController._target.activeTab.reload();

        yield reloading;

        is(gEvents.itemCount, 0,
          "There should be no events displayed in the view while reloading.");
        ok(true,
          "Event listeners were removed when the target started navigating.");

        yield reloaded;

        is(gView.instrumentsPaneHidden, false,
          "The instruments pane should still be visible.");
        is(gView.instrumentsPaneTab, "events-tab",
          "The events tab should still be selected.");

        yield fetched;

        is(gEvents.itemCount, 4,
          "There should be 4 events displayed in the view after reloading.");
        ok(true,
          "Event listeners were added back after the target finished navigating.");
      });
    }

    function testFetchOnReloadWhenNotFocused() {
      return Task.spawn(function* () {
        gController.dispatch({
          type: gDebugger.services.WAIT_UNTIL,
          predicate: action => {
            return (action.type === constants.FETCH_EVENT_LISTENERS ||
                    action.type === constants.UPDATE_EVENT_BREAKPOINTS);
          },
          run: (dispatch, getState, action) => {
            if (action.type === constants.FETCH_EVENT_LISTENERS) {
              ok(false, "Shouldn't have fetched any event listeners.");
            }
            else if (action.type === constants.UPDATE_EVENT_BREAKPOINTS) {
              ok(false, "Shouldn't have updated any event breakpoints.");
            }
          }
        });

        gView.toggleInstrumentsPane({ visible: true, animated: false }, 0);
        is(gView.instrumentsPaneHidden, false,
          "The instruments pane should still be visible.");
        is(gView.instrumentsPaneTab, "variables-tab",
          "The variables tab should be selected.");

        let reloading = once(gDebugger.gTarget, "will-navigate");
        let reloaded = waitForNavigation(gPanel);
        gDebugger.DebuggerController._target.activeTab.reload();

        yield reloading;

        is(gEvents.itemCount, 0,
          "There should be no events displayed in the view while reloading.");
        ok(true,
          "Event listeners were removed when the target started navigating.");

        yield reloaded;

        is(gView.instrumentsPaneHidden, false,
          "The instruments pane should still be visible.");
        is(gView.instrumentsPaneTab, "variables-tab",
          "The variables tab should still be selected.");

        // Just to be really sure that the events will never ever fire.
        yield waitForTime(1000);

        is(gEvents.itemCount, 0,
          "There should be no events displayed in the view after reloading.");
        ok(true,
          "Event listeners were not added after the target finished navigating.");
      });
    }
  });
}