OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var pages = [pageUrl('a'), pageUrl('b'), pageUrl('c')]; | 5 var pages = [pageUrl('a'), pageUrl('b'), pageUrl('c')]; |
6 var firstWindowTabIds = []; | 6 var firstWindowTabIds = []; |
7 var recentlyClosedSecondWindowTabIds = []; | 7 var recentlyClosedSecondWindowTabIds = []; |
8 var recentlyClosedTabIds = []; | 8 var recentlyClosedTabIds = []; |
9 var recentlyClosedWindowIds = []; | 9 var recentlyClosedWindowIds = []; |
10 var windowIds = []; | 10 var windowIds = []; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 assertFalse(actual.hasOwnProperty('window')); | 52 assertFalse(actual.hasOwnProperty('window')); |
53 assertEq(expected.tab.url, actual.tab.url); | 53 assertEq(expected.tab.url, actual.tab.url); |
54 } else { | 54 } else { |
55 assertTrue(actual.hasOwnProperty('window')); | 55 assertTrue(actual.hasOwnProperty('window')); |
56 assertFalse(actual.hasOwnProperty('tab')); | 56 assertFalse(actual.hasOwnProperty('tab')); |
57 assertEq(expected.window.tabsLength, actual.window.tabs.length); | 57 assertEq(expected.window.tabsLength, actual.window.tabs.length); |
58 } | 58 } |
59 }); | 59 }); |
60 } | 60 } |
61 | 61 |
62 function checkOnChangedEvent(expectedCallbackCount) { | |
63 var callbackCount = 0; | |
64 var done = chrome.test.listenForever(chrome.sessions.onChanged, function() { | |
65 callbackCount++; | |
66 } | |
67 ); | |
68 | |
69 return function() { | |
70 var retry = 0; | |
71 var checkEvent = function() { | |
72 if (callbackCount < expectedCallbackCount) { | |
73 retry++; | |
74 if (retry % 10 == 0) | |
75 console.log("Waiting for " + | |
76 (expectedCallbackCount - callbackCount) + | |
77 " more onChanged events"); | |
78 window.setTimeout(checkEvent, 100); | |
not at google - send to devlin
2014/03/28 18:44:48
last nit: declare this 100 as a var up in the chec
| |
79 } else { | |
80 assertEq(callbackCount, expectedCallbackCount); | |
81 done(); | |
82 } | |
83 }; | |
84 window.setTimeout(checkEvent, 100); | |
85 }; | |
86 } | |
87 | |
62 chrome.test.runTests([ | 88 chrome.test.runTests([ |
63 // After setupWindows | 89 // After setupWindows |
64 // | 90 // |
65 // Window1: a,b,c | 91 // Window1: a,b,c |
66 // Window2: a,b | 92 // Window2: a,b |
67 // Window3: a,b | 93 // Window3: a,b |
68 // | 94 // |
69 // After retrieveClosedTabs: | 95 // After retrieveClosedTabs: |
70 // | 96 // |
71 // Window1: c | 97 // Window1: c |
(...skipping 29 matching lines...) Expand all Loading... | |
101 assertEq(callArgs.length + 1, win.length); | 127 assertEq(callArgs.length + 1, win.length); |
102 }) | 128 }) |
103 ); | 129 ); |
104 } | 130 } |
105 ); | 131 ); |
106 }, | 132 }, |
107 | 133 |
108 function retrieveClosedTabs() { | 134 function retrieveClosedTabs() { |
109 // Check that the recently closed list contains what we expect | 135 // Check that the recently closed list contains what we expect |
110 // after removing tabs. | 136 // after removing tabs. |
137 var checkEvent = checkOnChangedEvent(2); | |
138 | |
111 callForEach( | 139 callForEach( |
112 chrome.tabs.remove, | 140 chrome.tabs.remove, |
113 firstWindowTabIds.slice(0, 2).reverse(), | 141 firstWindowTabIds.slice(0, 2).reverse(), |
114 function each() { | 142 function each() { |
115 }, | 143 }, |
116 function done() { | 144 function done() { |
117 chrome.sessions.getRecentlyClosed( | 145 chrome.sessions.getRecentlyClosed( |
118 {maxResults: 2}, | 146 {maxResults: 2}, |
119 callbackPass(function(entries) { | 147 callbackPass(function(entries) { |
120 var expectedEntries = [ | 148 var expectedEntries = [ |
121 { tab: { url: pages[0] } }, | 149 { tab: { url: pages[0] } }, |
122 { tab: { url: pages[1] } } | 150 { tab: { url: pages[1] } } |
123 ]; | 151 ]; |
124 checkEntries(expectedEntries, entries); | 152 checkEntries(expectedEntries, entries); |
125 entries.forEach(function(entry) { | 153 entries.forEach(function(entry) { |
126 recentlyClosedTabIds.push(entry.tab.sessionId); | 154 recentlyClosedTabIds.push(entry.tab.sessionId); |
127 }); | 155 }); |
156 checkEvent(); | |
128 }) | 157 }) |
129 ); | 158 ); |
130 } | 159 } |
131 ); | 160 ); |
132 }, | 161 }, |
133 | 162 |
134 function retrieveClosedWindows() { | 163 function retrieveClosedWindows() { |
135 // Check that the recently closed list contains what we expect | 164 // Check that the recently closed list contains what we expect |
136 // after removing windows. | 165 // after removing windows. |
166 var checkEvent = checkOnChangedEvent(2); | |
167 | |
137 callForEach( | 168 callForEach( |
138 chrome.windows.remove, | 169 chrome.windows.remove, |
139 windowIds.slice(1, 3).reverse(), | 170 windowIds.slice(1, 3).reverse(), |
140 function each() { | 171 function each() { |
141 }, | 172 }, |
142 function done() { | 173 function done() { |
143 chrome.sessions.getRecentlyClosed( | 174 chrome.sessions.getRecentlyClosed( |
144 {maxResults: 2}, | 175 {maxResults: 2}, |
145 callbackPass(function(entries) { | 176 callbackPass(function(entries) { |
146 var expectedEntries = [ | 177 var expectedEntries = [ |
147 { window: { tabsLength: 2 } }, | 178 { window: { tabsLength: 2 } }, |
148 { window: { tabsLength: 2 } } | 179 { window: { tabsLength: 2 } } |
149 ]; | 180 ]; |
150 checkEntries(expectedEntries, entries); | 181 checkEntries(expectedEntries, entries); |
151 entries[0].window.tabs.forEach(function(tab) { | 182 entries[0].window.tabs.forEach(function(tab) { |
152 recentlyClosedSecondWindowTabIds.push(tab.sessionId); | 183 recentlyClosedSecondWindowTabIds.push(tab.sessionId); |
153 }); | 184 }); |
154 entries.forEach(function(entry) { | 185 entries.forEach(function(entry) { |
155 recentlyClosedWindowIds.push(entry.window.sessionId); | 186 recentlyClosedWindowIds.push(entry.window.sessionId); |
156 }); | 187 }); |
188 checkEvent(); | |
157 }) | 189 }) |
158 ); | 190 ); |
159 } | 191 } |
160 ); | 192 ); |
161 }, | 193 }, |
162 | 194 |
163 function retrieveClosedEntries() { | 195 function retrieveClosedEntries() { |
164 // Check that the recently closed list contains what we expect | 196 // Check that the recently closed list contains what we expect |
165 // after removing tabs and windows. | 197 // after removing tabs and windows. |
166 chrome.sessions.getRecentlyClosed( | 198 chrome.sessions.getRecentlyClosed( |
(...skipping 23 matching lines...) Expand all Loading... | |
190 { tab: { url: pages[1] } } | 222 { tab: { url: pages[1] } } |
191 ]; | 223 ]; |
192 checkEntries(expectedEntries, entries); | 224 checkEntries(expectedEntries, entries); |
193 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, | 225 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, |
194 entries.length); | 226 entries.length); |
195 }) | 227 }) |
196 ); | 228 ); |
197 }, | 229 }, |
198 | 230 |
199 function restoreClosedTabs() { | 231 function restoreClosedTabs() { |
232 var checkEvent = checkOnChangedEvent(2); | |
233 | |
200 chrome.windows.get(windowIds[0], {"populate": true}, | 234 chrome.windows.get(windowIds[0], {"populate": true}, |
201 callbackPass(function(win) { | 235 callbackPass(function(win) { |
202 var tabCountBeforeRestore = win.tabs.length; | 236 var tabCountBeforeRestore = win.tabs.length; |
203 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab_session) { | 237 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab_session) { |
204 assertEq(pages[0], tab_session.tab.url); | 238 assertEq(pages[0], tab_session.tab.url); |
205 }); | 239 }); |
206 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab_session) { | 240 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab_session) { |
207 assertEq(pages[1], tab_session.tab.url); | 241 assertEq(pages[1], tab_session.tab.url); |
208 }); | 242 }); |
209 chrome.windows.get(windowIds[0], {"populate": true}, | 243 chrome.windows.get(windowIds[0], {"populate": true}, |
210 callbackPass(function(win){ | 244 callbackPass(function(win){ |
211 assertEq(tabCountBeforeRestore + 2, win.tabs.length); | 245 assertEq(tabCountBeforeRestore + 2, win.tabs.length); |
212 win.tabs.forEach(function(tab, i) { | 246 win.tabs.forEach(function(tab, i) { |
213 assertEq(pages[i++], tab.url); | 247 assertEq(pages[i++], tab.url); |
214 }); | 248 }); |
249 checkEvent(); | |
215 }) | 250 }) |
216 ); | 251 ); |
217 }) | 252 }) |
218 ); | 253 ); |
219 }, | 254 }, |
220 | 255 |
221 function restoreTabInClosedWindow() { | 256 function restoreTabInClosedWindow() { |
257 var checkEvent = checkOnChangedEvent(1); | |
258 | |
222 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 259 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
223 var windowCountBeforeRestore = win.length; | 260 var windowCountBeforeRestore = win.length; |
224 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], | 261 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], |
225 callbackPass(function(tab_session) { | 262 callbackPass(function(tab_session) { |
226 assertEq(pages[0], tab_session.tab.url); | 263 assertEq(pages[0], tab_session.tab.url); |
227 chrome.windows.getAll({"populate": true}, | 264 chrome.windows.getAll({"populate": true}, |
228 callbackPass(function(win) { | 265 callbackPass(function(win) { |
229 assertEq(windowCountBeforeRestore + 1, win.length); | 266 assertEq(windowCountBeforeRestore + 1, win.length); |
230 assertEq(1, win[win.length - 1].tabs.length); | 267 assertEq(1, win[win.length - 1].tabs.length); |
231 assertEq(pages[0], win[win.length - 1].tabs[0].url); | 268 assertEq(pages[0], win[win.length - 1].tabs[0].url); |
269 checkEvent(); | |
232 }) | 270 }) |
233 ); | 271 ); |
234 }) | 272 }) |
235 ); | 273 ); |
236 })); | 274 })); |
237 }, | 275 }, |
238 | 276 |
239 function restoreClosedWindows() { | 277 function restoreClosedWindows() { |
278 var checkEvent = checkOnChangedEvent(1); | |
279 | |
240 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 280 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
241 var windowCountBeforeRestore = win.length; | 281 var windowCountBeforeRestore = win.length; |
242 chrome.sessions.restore(recentlyClosedWindowIds[0], | 282 chrome.sessions.restore(recentlyClosedWindowIds[0], |
243 function(win_session) { | 283 function(win_session) { |
244 assertEq(1, win_session.window.tabs.length); | 284 assertEq(1, win_session.window.tabs.length); |
285 checkEvent(); | |
245 }); | 286 }); |
246 function done() { | 287 function done() { |
247 chrome.windows.getAll({"populate": true}, | 288 chrome.windows.getAll({"populate": true}, |
248 callbackPass(function(win) { | 289 callbackPass(function(win) { |
249 assertEq(windowCountBeforeRestore + 1, win.length); | 290 assertEq(windowCountBeforeRestore + 1, win.length); |
250 }) | 291 }) |
251 ); | 292 ); |
252 } | 293 } |
253 })); | 294 })); |
254 }, | 295 }, |
(...skipping 23 matching lines...) Expand all Loading... | |
278 callbackPass(function(win) { | 319 callbackPass(function(win) { |
279 assertEq(windowCountBeforeRestore, win.length); | 320 assertEq(windowCountBeforeRestore, win.length); |
280 }) | 321 }) |
281 ); | 322 ); |
282 }) | 323 }) |
283 ); | 324 ); |
284 })); | 325 })); |
285 }, | 326 }, |
286 | 327 |
287 function restoreMostRecentEntry() { | 328 function restoreMostRecentEntry() { |
329 var checkEvent = checkOnChangedEvent(1); | |
330 | |
288 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 331 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
289 var windowCountBeforeRestore = win.length; | 332 var windowCountBeforeRestore = win.length; |
290 chrome.sessions.restore(callbackPass(function(win_session) { | 333 chrome.sessions.restore(callbackPass(function(win_session) { |
291 assertEq(2, win_session.window.tabs.length); | 334 assertEq(2, win_session.window.tabs.length); |
292 chrome.windows.getAll({"populate": true}, | 335 chrome.windows.getAll({"populate": true}, |
293 callbackPass(function(win) { | 336 callbackPass(function(win) { |
294 assertEq(windowCountBeforeRestore + 1, win.length); | 337 assertEq(windowCountBeforeRestore + 1, win.length); |
338 checkEvent(); | |
295 }) | 339 }) |
296 ); | 340 ); |
297 })); | 341 })); |
298 })); | 342 })); |
299 }, | 343 }, |
300 | 344 |
301 function checkRecentlyClosedListEmpty() { | 345 function checkRecentlyClosedListEmpty() { |
302 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 346 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
303 var windowCountBeforeRestore = win.length; | 347 var windowCountBeforeRestore = win.length; |
304 chrome.sessions.restore( | 348 chrome.sessions.restore( |
305 callbackFail("There are no recently closed sessions.", function() { | 349 callbackFail("There are no recently closed sessions.", function() { |
306 chrome.windows.getAll({"populate": true}, | 350 chrome.windows.getAll({"populate": true}, |
307 callbackPass(function(win) { | 351 callbackPass(function(win) { |
308 assertEq(windowCountBeforeRestore, win.length); | 352 assertEq(windowCountBeforeRestore, win.length); |
309 }) | 353 }) |
310 ); | 354 ); |
311 }) | 355 }) |
312 ); | 356 ); |
313 })); | 357 })); |
314 } | 358 } |
315 ]); | 359 ]); |
OLD | NEW |