|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests that system event listeners don't get duplicated in the view. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initDebugger("about:blank").then(([aTab, aDebuggee, aPanel]) => { |
|
10 let gDebugger = aPanel.panelWin; |
|
11 let gView = gDebugger.DebuggerView; |
|
12 let gEvents = gView.EventListeners; |
|
13 let gL10N = gDebugger.L10N; |
|
14 |
|
15 is(gEvents.itemCount, 0, |
|
16 "There are no events displayed in the corresponding pane yet."); |
|
17 |
|
18 gEvents.addListener({ |
|
19 type: "foo", |
|
20 node: { selector: "#first" }, |
|
21 function: { url: null } |
|
22 }); |
|
23 |
|
24 is(gEvents.itemCount, 1, |
|
25 "There was a system event listener added in the view."); |
|
26 is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), |
|
27 "The correct string is used as the event's url."); |
|
28 is(gEvents.attachments[0].type, "foo", |
|
29 "The correct string is used as the event's type."); |
|
30 is(gEvents.attachments[0].selectors.toString(), "#first", |
|
31 "The correct array of selectors is used as the event's target."); |
|
32 |
|
33 gEvents.addListener({ |
|
34 type: "bar", |
|
35 node: { selector: "#second" }, |
|
36 function: { url: null } |
|
37 }); |
|
38 |
|
39 is(gEvents.itemCount, 2, |
|
40 "There was another system event listener added in the view."); |
|
41 is(gEvents.attachments[1].url, gL10N.getStr("eventNative"), |
|
42 "The correct string is used as the event's url."); |
|
43 is(gEvents.attachments[1].type, "bar", |
|
44 "The correct string is used as the event's type."); |
|
45 is(gEvents.attachments[1].selectors.toString(), "#second", |
|
46 "The correct array of selectors is used as the event's target."); |
|
47 |
|
48 gEvents.addListener({ |
|
49 type: "foo", |
|
50 node: { selector: "#first" }, |
|
51 function: { url: null } |
|
52 }); |
|
53 |
|
54 is(gEvents.itemCount, 2, |
|
55 "There wasn't another system event listener added in the view."); |
|
56 is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), |
|
57 "The correct string is used as the event's url."); |
|
58 is(gEvents.attachments[0].type, "foo", |
|
59 "The correct string is used as the event's type."); |
|
60 is(gEvents.attachments[0].selectors.toString(), "#first", |
|
61 "The correct array of selectors is used as the event's target."); |
|
62 |
|
63 gEvents.addListener({ |
|
64 type: "foo", |
|
65 node: { selector: "#second" }, |
|
66 function: { url: null } |
|
67 }); |
|
68 |
|
69 is(gEvents.itemCount, 2, |
|
70 "There still wasn't another system event listener added in the view."); |
|
71 is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), |
|
72 "The correct string is used as the event's url."); |
|
73 is(gEvents.attachments[0].type, "foo", |
|
74 "The correct string is used as the event's type."); |
|
75 is(gEvents.attachments[0].selectors.toString(), "#first,#second", |
|
76 "The correct array of selectors is used as the event's target."); |
|
77 |
|
78 |
|
79 gEvents.addListener({ |
|
80 type: null, |
|
81 node: { selector: "#bogus" }, |
|
82 function: { url: null } |
|
83 }); |
|
84 |
|
85 is(gEvents.itemCount, 2, |
|
86 "No bogus system event listener was added in the view."); |
|
87 |
|
88 is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), |
|
89 "The correct string is used as the first event's url."); |
|
90 is(gEvents.attachments[0].type, "foo", |
|
91 "The correct string is used as the first event's type."); |
|
92 is(gEvents.attachments[0].selectors.toString(), "#first,#second", |
|
93 "The correct array of selectors is used as the first event's target."); |
|
94 |
|
95 is(gEvents.attachments[1].url, gL10N.getStr("eventNative"), |
|
96 "The correct string is used as the second event's url."); |
|
97 is(gEvents.attachments[1].type, "bar", |
|
98 "The correct string is used as the second event's type."); |
|
99 is(gEvents.attachments[1].selectors.toString(), "#second", |
|
100 "The correct array of selectors is used as the second event's target."); |
|
101 |
|
102 closeDebuggerAndFinish(aPanel); |
|
103 }); |
|
104 } |