|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
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 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_event-listeners-02.html"; |
|
10 |
|
11 function test() { |
|
12 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
13 let gDebugger = aPanel.panelWin; |
|
14 let gView = gDebugger.DebuggerView; |
|
15 let gEvents = gView.EventListeners; |
|
16 |
|
17 Task.spawn(function() { |
|
18 yield waitForSourceShown(aPanel, ".html"); |
|
19 yield testFetchOnFocus(); |
|
20 yield testFetchOnReloadWhenFocused(); |
|
21 yield testFetchOnReloadWhenNotFocused(); |
|
22 yield closeDebuggerAndFinish(aPanel); |
|
23 }); |
|
24 |
|
25 function testFetchOnFocus() { |
|
26 return Task.spawn(function() { |
|
27 let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED); |
|
28 |
|
29 gView.toggleInstrumentsPane({ visible: true, animated: false }, 1); |
|
30 is(gView.instrumentsPaneHidden, false, |
|
31 "The instruments pane should be visible now."); |
|
32 is(gView.instrumentsPaneTab, "events-tab", |
|
33 "The events tab should be selected."); |
|
34 |
|
35 yield fetched; |
|
36 |
|
37 ok(true, |
|
38 "Event listeners were fetched when the events tab was selected"); |
|
39 is(gEvents.itemCount, 4, |
|
40 "There should be 4 events displayed in the view."); |
|
41 }); |
|
42 } |
|
43 |
|
44 function testFetchOnReloadWhenFocused() { |
|
45 return Task.spawn(function() { |
|
46 let fetched = waitForDebuggerEvents(aPanel, gDebugger.EVENTS.EVENT_LISTENERS_FETCHED); |
|
47 |
|
48 let reloading = once(gDebugger.gTarget, "will-navigate"); |
|
49 let reloaded = waitForSourcesAfterReload(); |
|
50 gDebugger.DebuggerController._target.activeTab.reload(); |
|
51 |
|
52 yield reloading; |
|
53 |
|
54 is(gEvents.itemCount, 0, |
|
55 "There should be no events displayed in the view while reloading."); |
|
56 ok(true, |
|
57 "Event listeners were removed when the target started navigating."); |
|
58 |
|
59 yield reloaded; |
|
60 |
|
61 is(gView.instrumentsPaneHidden, false, |
|
62 "The instruments pane should still be visible."); |
|
63 is(gView.instrumentsPaneTab, "events-tab", |
|
64 "The events tab should still be selected."); |
|
65 |
|
66 yield fetched; |
|
67 |
|
68 is(gEvents.itemCount, 4, |
|
69 "There should be 4 events displayed in the view after reloading."); |
|
70 ok(true, |
|
71 "Event listeners were added back after the target finished navigating."); |
|
72 }); |
|
73 } |
|
74 |
|
75 function testFetchOnReloadWhenNotFocused() { |
|
76 return Task.spawn(function() { |
|
77 gDebugger.on(gDebugger.EVENTS.EVENT_LISTENERS_FETCHED, () => { |
|
78 ok(false, "Shouldn't have fetched any event listeners."); |
|
79 }); |
|
80 gDebugger.on(gDebugger.EVENTS.EVENT_BREAKPOINTS_UPDATED, () => { |
|
81 ok(false, "Shouldn't have updated any event breakpoints."); |
|
82 }); |
|
83 |
|
84 gView.toggleInstrumentsPane({ visible: true, animated: false }, 0); |
|
85 is(gView.instrumentsPaneHidden, false, |
|
86 "The instruments pane should still be visible."); |
|
87 is(gView.instrumentsPaneTab, "variables-tab", |
|
88 "The variables tab should be selected."); |
|
89 |
|
90 let reloading = once(gDebugger.gTarget, "will-navigate"); |
|
91 let reloaded = waitForSourcesAfterReload(); |
|
92 gDebugger.DebuggerController._target.activeTab.reload(); |
|
93 |
|
94 yield reloading; |
|
95 |
|
96 is(gEvents.itemCount, 0, |
|
97 "There should be no events displayed in the view while reloading."); |
|
98 ok(true, |
|
99 "Event listeners were removed when the target started navigating."); |
|
100 |
|
101 yield reloaded; |
|
102 |
|
103 is(gView.instrumentsPaneHidden, false, |
|
104 "The instruments pane should still be visible."); |
|
105 is(gView.instrumentsPaneTab, "variables-tab", |
|
106 "The variables tab should still be selected."); |
|
107 |
|
108 // Just to be really sure that the events will never ever fire. |
|
109 yield waitForTime(1000); |
|
110 |
|
111 is(gEvents.itemCount, 0, |
|
112 "There should be no events displayed in the view after reloading."); |
|
113 ok(true, |
|
114 "Event listeners were not added after the target finished navigating."); |
|
115 }); |
|
116 } |
|
117 |
|
118 function waitForSourcesAfterReload() { |
|
119 return promise.all([ |
|
120 waitForDebuggerEvents(aPanel, gDebugger.EVENTS.NEW_SOURCE), |
|
121 waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCES_ADDED), |
|
122 waitForDebuggerEvents(aPanel, gDebugger.EVENTS.SOURCE_SHOWN) |
|
123 ]); |
|
124 } |
|
125 }); |
|
126 } |