Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5 * Make sure the root actor's live tab list implementation works as specified.
6 */
8 let gTestPage = "data:text/html;charset=utf-8," + encodeURIComponent(
9 "<title>JS Debugger BrowserTabList test page</title><body>Yo.</body>");
11 // The tablist object whose behavior we observe.
12 let gTabList;
13 let gFirstActor, gActorA;
14 let gTabA, gTabB, gTabC;
15 let gNewWindow;
17 // Stock onListChanged handler.
18 let onListChangedCount = 0;
19 function onListChangedHandler() {
20 onListChangedCount++;
21 }
23 function test() {
24 if (!DebuggerServer.initialized) {
25 DebuggerServer.init(() => true);
26 DebuggerServer.addBrowserActors();
27 }
29 gTabList = new DebuggerServer.BrowserTabList("fake DebuggerServerConnection");
30 gTabList._testing = true;
31 gTabList.onListChanged = onListChangedHandler;
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 }
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 }
60 function addTabA() {
61 return addTab(gTestPage).then(aTab => {
62 gTabA = aTab;
63 });
64 }
66 function testTabA() {
67 is(onListChangedCount, 1, "onListChanged handler call count");
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");
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 }
81 function addTabB() {
82 return addTab(gTestPage).then(aTab => {
83 gTabB = aTab;
84 });
85 }
87 function testTabB() {
88 is(onListChangedCount, 2, "onListChanged handler call count");
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 }
96 function removeTabA() {
97 let deferred = promise.defer();
99 once(gBrowser.tabContainer, "TabClose").then(aEvent => {
100 ok(!aEvent.detail, "This was a normal tab close");
102 // Let the actor's TabClose handler finish first.
103 executeSoon(deferred.resolve);
104 }, false);
106 removeTab(gTabA);
107 return deferred.promise;
108 }
110 function testTabClosed() {
111 is(onListChangedCount, 3, "onListChanged handler call count");
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");
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 }
125 function addTabC() {
126 return addTab(gTestPage).then(aTab => {
127 gTabC = aTab;
128 });
129 }
131 function testTabC() {
132 is(onListChangedCount, 4, "onListChanged handler call count");
134 gTabList.getList().then(aTabActors => {
135 let tabActors = new Set(aTabActors);
136 is(tabActors.size, 3, "gTabC opened: three tabs in list");
137 });
138 }
140 function removeTabC() {
141 let deferred = promise.defer();
143 once(gBrowser.tabContainer, "TabClose").then(aEvent => {
144 ok(aEvent.detail, "This was a tab closed by moving");
146 // Let the actor's TabClose handler finish first.
147 executeSoon(deferred.resolve);
148 }, false);
150 gNewWindow = gBrowser.replaceTabWithWindow(gTabC);
151 return deferred.promise;
152 }
154 function testNewWindow() {
155 is(onListChangedCount, 5, "onListChanged handler call count");
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");
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 }
169 function removeNewWindow() {
170 let deferred = promise.defer();
172 once(gNewWindow, "unload").then(aEvent => {
173 ok(!aEvent.detail, "This was a normal window close");
175 // Let the actor's TabClose handler finish first.
176 executeSoon(deferred.resolve);
177 }, false);
179 gNewWindow.close();
180 return deferred.promise;
181 }
183 function testWindowClosed() {
184 is(onListChangedCount, 6, "onListChanged handler call count");
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");
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 }
198 function removeTabB() {
199 let deferred = promise.defer();
201 once(gBrowser.tabContainer, "TabClose").then(aEvent => {
202 ok(!aEvent.detail, "This was a normal tab close");
204 // Let the actor's TabClose handler finish first.
205 executeSoon(deferred.resolve);
206 }, false);
208 removeTab(gTabB);
209 return deferred.promise;
210 }
212 function finishUp() {
213 gTabList = gFirstActor = gActorA = gTabA = gTabB = gTabC = gNewWindow = null;
214 finish();
215 }