|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure the root actor's live tab list implementation works as specified. |
|
6 */ |
|
7 |
|
8 let gTestPage = "data:text/html;charset=utf-8," + encodeURIComponent( |
|
9 "<title>JS Debugger BrowserTabList test page</title><body>Yo.</body>"); |
|
10 |
|
11 // The tablist object whose behavior we observe. |
|
12 let gTabList; |
|
13 let gFirstActor, gActorA; |
|
14 let gTabA, gTabB, gTabC; |
|
15 let gNewWindow; |
|
16 |
|
17 // Stock onListChanged handler. |
|
18 let onListChangedCount = 0; |
|
19 function onListChangedHandler() { |
|
20 onListChangedCount++; |
|
21 } |
|
22 |
|
23 function test() { |
|
24 if (!DebuggerServer.initialized) { |
|
25 DebuggerServer.init(() => true); |
|
26 DebuggerServer.addBrowserActors(); |
|
27 } |
|
28 |
|
29 gTabList = new DebuggerServer.BrowserTabList("fake DebuggerServerConnection"); |
|
30 gTabList._testing = true; |
|
31 gTabList.onListChanged = onListChangedHandler; |
|
32 |
|
33 checkSingleTab() |
|
34 .then(addTabA) |
|
35 .then(testTabA) |
|
36 .then(addTabB) |
|
37 .then(testTabB) |
|
38 .then(removeTabA) |
|
39 .then(testTabClosed) |
|
40 .then(addTabC) |
|
41 .then(testTabC) |
|
42 .then(removeTabC) |
|
43 .then(testNewWindow) |
|
44 .then(removeNewWindow) |
|
45 .then(testWindowClosed) |
|
46 .then(removeTabB) |
|
47 .then(checkSingleTab) |
|
48 .then(finishUp); |
|
49 } |
|
50 |
|
51 function checkSingleTab() { |
|
52 return gTabList.getList().then(aTabActors => { |
|
53 is(aTabActors.length, 1, "initial tab list: contains initial tab"); |
|
54 gFirstActor = aTabActors[0]; |
|
55 is(gFirstActor.url, "about:blank", "initial tab list: initial tab URL is 'about:blank'"); |
|
56 is(gFirstActor.title, "New Tab", "initial tab list: initial tab title is 'New Tab'"); |
|
57 }); |
|
58 } |
|
59 |
|
60 function addTabA() { |
|
61 return addTab(gTestPage).then(aTab => { |
|
62 gTabA = aTab; |
|
63 }); |
|
64 } |
|
65 |
|
66 function testTabA() { |
|
67 is(onListChangedCount, 1, "onListChanged handler call count"); |
|
68 |
|
69 return gTabList.getList().then(aTabActors => { |
|
70 let tabActors = new Set(aTabActors); |
|
71 is(tabActors.size, 2, "gTabA opened: two tabs in list"); |
|
72 ok(tabActors.has(gFirstActor), "gTabA opened: initial tab present"); |
|
73 |
|
74 info("actors: " + [a.url for (a of tabActors)]); |
|
75 gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
|
76 ok(gActorA.url.match(/^data:text\/html;/), "gTabA opened: new tab URL"); |
|
77 is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabA opened: new tab title"); |
|
78 }); |
|
79 } |
|
80 |
|
81 function addTabB() { |
|
82 return addTab(gTestPage).then(aTab => { |
|
83 gTabB = aTab; |
|
84 }); |
|
85 } |
|
86 |
|
87 function testTabB() { |
|
88 is(onListChangedCount, 2, "onListChanged handler call count"); |
|
89 |
|
90 return gTabList.getList().then(aTabActors => { |
|
91 let tabActors = new Set(aTabActors); |
|
92 is(tabActors.size, 3, "gTabB opened: three tabs in list"); |
|
93 }); |
|
94 } |
|
95 |
|
96 function removeTabA() { |
|
97 let deferred = promise.defer(); |
|
98 |
|
99 once(gBrowser.tabContainer, "TabClose").then(aEvent => { |
|
100 ok(!aEvent.detail, "This was a normal tab close"); |
|
101 |
|
102 // Let the actor's TabClose handler finish first. |
|
103 executeSoon(deferred.resolve); |
|
104 }, false); |
|
105 |
|
106 removeTab(gTabA); |
|
107 return deferred.promise; |
|
108 } |
|
109 |
|
110 function testTabClosed() { |
|
111 is(onListChangedCount, 3, "onListChanged handler call count"); |
|
112 |
|
113 gTabList.getList().then(aTabActors => { |
|
114 let tabActors = new Set(aTabActors); |
|
115 is(tabActors.size, 2, "gTabA closed: two tabs in list"); |
|
116 ok(tabActors.has(gFirstActor), "gTabA closed: initial tab present"); |
|
117 |
|
118 info("actors: " + [a.url for (a of tabActors)]); |
|
119 gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
|
120 ok(gActorA.url.match(/^data:text\/html;/), "gTabA closed: new tab URL"); |
|
121 is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabA closed: new tab title"); |
|
122 }); |
|
123 } |
|
124 |
|
125 function addTabC() { |
|
126 return addTab(gTestPage).then(aTab => { |
|
127 gTabC = aTab; |
|
128 }); |
|
129 } |
|
130 |
|
131 function testTabC() { |
|
132 is(onListChangedCount, 4, "onListChanged handler call count"); |
|
133 |
|
134 gTabList.getList().then(aTabActors => { |
|
135 let tabActors = new Set(aTabActors); |
|
136 is(tabActors.size, 3, "gTabC opened: three tabs in list"); |
|
137 }); |
|
138 } |
|
139 |
|
140 function removeTabC() { |
|
141 let deferred = promise.defer(); |
|
142 |
|
143 once(gBrowser.tabContainer, "TabClose").then(aEvent => { |
|
144 ok(aEvent.detail, "This was a tab closed by moving"); |
|
145 |
|
146 // Let the actor's TabClose handler finish first. |
|
147 executeSoon(deferred.resolve); |
|
148 }, false); |
|
149 |
|
150 gNewWindow = gBrowser.replaceTabWithWindow(gTabC); |
|
151 return deferred.promise; |
|
152 } |
|
153 |
|
154 function testNewWindow() { |
|
155 is(onListChangedCount, 5, "onListChanged handler call count"); |
|
156 |
|
157 return gTabList.getList().then(aTabActors => { |
|
158 let tabActors = new Set(aTabActors); |
|
159 is(tabActors.size, 3, "gTabC closed: three tabs in list"); |
|
160 ok(tabActors.has(gFirstActor), "gTabC closed: initial tab present"); |
|
161 |
|
162 info("actors: " + [a.url for (a of tabActors)]); |
|
163 gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
|
164 ok(gActorA.url.match(/^data:text\/html;/), "gTabC closed: new tab URL"); |
|
165 is(gActorA.title, "JS Debugger BrowserTabList test page", "gTabC closed: new tab title"); |
|
166 }); |
|
167 } |
|
168 |
|
169 function removeNewWindow() { |
|
170 let deferred = promise.defer(); |
|
171 |
|
172 once(gNewWindow, "unload").then(aEvent => { |
|
173 ok(!aEvent.detail, "This was a normal window close"); |
|
174 |
|
175 // Let the actor's TabClose handler finish first. |
|
176 executeSoon(deferred.resolve); |
|
177 }, false); |
|
178 |
|
179 gNewWindow.close(); |
|
180 return deferred.promise; |
|
181 } |
|
182 |
|
183 function testWindowClosed() { |
|
184 is(onListChangedCount, 6, "onListChanged handler call count"); |
|
185 |
|
186 return gTabList.getList().then(aTabActors => { |
|
187 let tabActors = new Set(aTabActors); |
|
188 is(tabActors.size, 2, "gNewWindow closed: two tabs in list"); |
|
189 ok(tabActors.has(gFirstActor), "gNewWindow closed: initial tab present"); |
|
190 |
|
191 info("actors: " + [a.url for (a of tabActors)]); |
|
192 gActorA = [a for (a of tabActors) if (a !== gFirstActor)][0]; |
|
193 ok(gActorA.url.match(/^data:text\/html;/), "gNewWindow closed: new tab URL"); |
|
194 is(gActorA.title, "JS Debugger BrowserTabList test page", "gNewWindow closed: new tab title"); |
|
195 }); |
|
196 } |
|
197 |
|
198 function removeTabB() { |
|
199 let deferred = promise.defer(); |
|
200 |
|
201 once(gBrowser.tabContainer, "TabClose").then(aEvent => { |
|
202 ok(!aEvent.detail, "This was a normal tab close"); |
|
203 |
|
204 // Let the actor's TabClose handler finish first. |
|
205 executeSoon(deferred.resolve); |
|
206 }, false); |
|
207 |
|
208 removeTab(gTabB); |
|
209 return deferred.promise; |
|
210 } |
|
211 |
|
212 function finishUp() { |
|
213 gTabList = gFirstActor = gActorA = gTabA = gTabB = gTabC = gNewWindow = null; |
|
214 finish(); |
|
215 } |