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