summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_break-on-dom-07.js
blob: 107eab5f888841f7c2c98aa92ccf8af26c8a1ecd (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Tests that system event listeners don't get duplicated in the view.
 */

function test() {
  initDebugger().then(([aTab,, aPanel]) => {
    let gDebugger = aPanel.panelWin;
    let gView = gDebugger.DebuggerView;
    let gEvents = gView.EventListeners;
    let gL10N = gDebugger.L10N;

    is(gEvents.itemCount, 0,
      "There are no events displayed in the corresponding pane yet.");

    gEvents.addListener({
      type: "foo",
      node: { selector: "#first" },
      function: { url: null }
    });

    is(gEvents.itemCount, 1,
      "There was a system event listener added in the view.");
    is(gEvents.attachments[0].url, gL10N.getStr("eventNative"),
      "The correct string is used as the event's url.");
    is(gEvents.attachments[0].type, "foo",
      "The correct string is used as the event's type.");
    is(gEvents.attachments[0].selectors.toString(), "#first",
      "The correct array of selectors is used as the event's target.");

    gEvents.addListener({
      type: "bar",
      node: { selector: "#second" },
      function: { url: null }
    });

    is(gEvents.itemCount, 2,
      "There was another system event listener added in the view.");
    is(gEvents.attachments[1].url, gL10N.getStr("eventNative"),
      "The correct string is used as the event's url.");
    is(gEvents.attachments[1].type, "bar",
      "The correct string is used as the event's type.");
    is(gEvents.attachments[1].selectors.toString(), "#second",
      "The correct array of selectors is used as the event's target.");

    gEvents.addListener({
      type: "foo",
      node: { selector: "#first" },
      function: { url: null }
    });

    is(gEvents.itemCount, 2,
      "There wasn't another system event listener added in the view.");
    is(gEvents.attachments[0].url, gL10N.getStr("eventNative"),
      "The correct string is used as the event's url.");
    is(gEvents.attachments[0].type, "foo",
      "The correct string is used as the event's type.");
    is(gEvents.attachments[0].selectors.toString(), "#first",
      "The correct array of selectors is used as the event's target.");

    gEvents.addListener({
      type: "foo",
      node: { selector: "#second" },
      function: { url: null }
    });

    is(gEvents.itemCount, 2,
      "There still wasn't another system event listener added in the view.");
    is(gEvents.attachments[0].url, gL10N.getStr("eventNative"),
      "The correct string is used as the event's url.");
    is(gEvents.attachments[0].type, "foo",
      "The correct string is used as the event's type.");
    is(gEvents.attachments[0].selectors.toString(), "#first,#second",
      "The correct array of selectors is used as the event's target.");


    gEvents.addListener({
      type: null,
      node: { selector: "#bogus" },
      function: { url: null }
    });

    is(gEvents.itemCount, 2,
      "No bogus system event listener was added in the view.");

    is(gEvents.attachments[0].url, gL10N.getStr("eventNative"),
      "The correct string is used as the first event's url.");
    is(gEvents.attachments[0].type, "foo",
      "The correct string is used as the first event's type.");
    is(gEvents.attachments[0].selectors.toString(), "#first,#second",
      "The correct array of selectors is used as the first event's target.");

    is(gEvents.attachments[1].url, gL10N.getStr("eventNative"),
      "The correct string is used as the second event's url.");
    is(gEvents.attachments[1].type, "bar",
      "The correct string is used as the second event's type.");
    is(gEvents.attachments[1].selectors.toString(), "#second",
      "The correct array of selectors is used as the second event's target.");

    closeDebuggerAndFinish(aPanel);
  });
}