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 doneListening = chrome.test.listenForever( | |
65 chrome.sessions.onChanged, | |
66 function() { | |
67 callbackCount++; | |
68 if (callbackCount == expectedCallbackCount) | |
69 doneListening(); | |
70 } | |
71 ); | |
72 } | |
not at google - send to devlin
2014/03/21 10:52:59
this doesn't actually make any assertions. yes it
wjywbs
2014/03/21 19:45:33
I haven't found a good way yet. I looked at the ot
| |
73 | |
62 chrome.test.runTests([ | 74 chrome.test.runTests([ |
63 // After setupWindows | 75 // After setupWindows |
64 // | 76 // |
65 // Window1: a,b,c | 77 // Window1: a,b,c |
66 // Window2: a,b | 78 // Window2: a,b |
67 // Window3: a,b | 79 // Window3: a,b |
68 // | 80 // |
69 // After retrieveClosedTabs: | 81 // After retrieveClosedTabs: |
70 // | 82 // |
71 // Window1: c | 83 // Window1: c |
(...skipping 29 matching lines...) Expand all Loading... | |
101 assertEq(callArgs.length + 1, win.length); | 113 assertEq(callArgs.length + 1, win.length); |
102 }) | 114 }) |
103 ); | 115 ); |
104 } | 116 } |
105 ); | 117 ); |
106 }, | 118 }, |
107 | 119 |
108 function retrieveClosedTabs() { | 120 function retrieveClosedTabs() { |
109 // Check that the recently closed list contains what we expect | 121 // Check that the recently closed list contains what we expect |
110 // after removing tabs. | 122 // after removing tabs. |
123 checkOnChangedEvent(2); | |
124 | |
111 callForEach( | 125 callForEach( |
112 chrome.tabs.remove, | 126 chrome.tabs.remove, |
113 firstWindowTabIds.slice(0, 2).reverse(), | 127 firstWindowTabIds.slice(0, 2).reverse(), |
114 function each() { | 128 function each() { |
115 }, | 129 }, |
116 function done() { | 130 function done() { |
117 chrome.sessions.getRecentlyClosed( | 131 chrome.sessions.getRecentlyClosed( |
118 {maxResults: 2}, | 132 {maxResults: 2}, |
119 callbackPass(function(entries) { | 133 callbackPass(function(entries) { |
120 var expectedEntries = [ | 134 var expectedEntries = [ |
121 { tab: { url: pages[0] } }, | 135 { tab: { url: pages[0] } }, |
122 { tab: { url: pages[1] } } | 136 { tab: { url: pages[1] } } |
123 ]; | 137 ]; |
124 checkEntries(expectedEntries, entries); | 138 checkEntries(expectedEntries, entries); |
125 entries.forEach(function(entry) { | 139 entries.forEach(function(entry) { |
126 recentlyClosedTabIds.push(entry.tab.sessionId); | 140 recentlyClosedTabIds.push(entry.tab.sessionId); |
127 }); | 141 }); |
128 }) | 142 }) |
129 ); | 143 ); |
130 } | 144 } |
131 ); | 145 ); |
132 }, | 146 }, |
133 | 147 |
134 function retrieveClosedWindows() { | 148 function retrieveClosedWindows() { |
135 // Check that the recently closed list contains what we expect | 149 // Check that the recently closed list contains what we expect |
136 // after removing windows. | 150 // after removing windows. |
151 checkOnChangedEvent(2); | |
152 | |
137 callForEach( | 153 callForEach( |
138 chrome.windows.remove, | 154 chrome.windows.remove, |
139 windowIds.slice(1, 3).reverse(), | 155 windowIds.slice(1, 3).reverse(), |
140 function each() { | 156 function each() { |
141 }, | 157 }, |
142 function done() { | 158 function done() { |
143 chrome.sessions.getRecentlyClosed( | 159 chrome.sessions.getRecentlyClosed( |
144 {maxResults: 2}, | 160 {maxResults: 2}, |
145 callbackPass(function(entries) { | 161 callbackPass(function(entries) { |
146 var expectedEntries = [ | 162 var expectedEntries = [ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 { tab: { url: pages[1] } } | 206 { tab: { url: pages[1] } } |
191 ]; | 207 ]; |
192 checkEntries(expectedEntries, entries); | 208 checkEntries(expectedEntries, entries); |
193 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, | 209 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, |
194 entries.length); | 210 entries.length); |
195 }) | 211 }) |
196 ); | 212 ); |
197 }, | 213 }, |
198 | 214 |
199 function restoreClosedTabs() { | 215 function restoreClosedTabs() { |
216 checkOnChangedEvent(2); | |
217 | |
200 chrome.windows.get(windowIds[0], {"populate": true}, | 218 chrome.windows.get(windowIds[0], {"populate": true}, |
201 callbackPass(function(win) { | 219 callbackPass(function(win) { |
202 var tabCountBeforeRestore = win.tabs.length; | 220 var tabCountBeforeRestore = win.tabs.length; |
203 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab_session) { | 221 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab_session) { |
204 assertEq(pages[0], tab_session.tab.url); | 222 assertEq(pages[0], tab_session.tab.url); |
205 }); | 223 }); |
206 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab_session) { | 224 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab_session) { |
207 assertEq(pages[1], tab_session.tab.url); | 225 assertEq(pages[1], tab_session.tab.url); |
208 }); | 226 }); |
209 chrome.windows.get(windowIds[0], {"populate": true}, | 227 chrome.windows.get(windowIds[0], {"populate": true}, |
210 callbackPass(function(win){ | 228 callbackPass(function(win){ |
211 assertEq(tabCountBeforeRestore + 2, win.tabs.length); | 229 assertEq(tabCountBeforeRestore + 2, win.tabs.length); |
212 win.tabs.forEach(function(tab, i) { | 230 win.tabs.forEach(function(tab, i) { |
213 assertEq(pages[i++], tab.url); | 231 assertEq(pages[i++], tab.url); |
214 }); | 232 }); |
215 }) | 233 }) |
216 ); | 234 ); |
217 }) | 235 }) |
218 ); | 236 ); |
219 }, | 237 }, |
220 | 238 |
221 function restoreTabInClosedWindow() { | 239 function restoreTabInClosedWindow() { |
240 checkOnChangedEvent(1); | |
241 | |
222 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 242 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
223 var windowCountBeforeRestore = win.length; | 243 var windowCountBeforeRestore = win.length; |
224 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], | 244 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], |
225 callbackPass(function(tab_session) { | 245 callbackPass(function(tab_session) { |
226 assertEq(pages[0], tab_session.tab.url); | 246 assertEq(pages[0], tab_session.tab.url); |
227 chrome.windows.getAll({"populate": true}, | 247 chrome.windows.getAll({"populate": true}, |
228 callbackPass(function(win) { | 248 callbackPass(function(win) { |
229 assertEq(windowCountBeforeRestore + 1, win.length); | 249 assertEq(windowCountBeforeRestore + 1, win.length); |
230 assertEq(1, win[win.length - 1].tabs.length); | 250 assertEq(1, win[win.length - 1].tabs.length); |
231 assertEq(pages[0], win[win.length - 1].tabs[0].url); | 251 assertEq(pages[0], win[win.length - 1].tabs[0].url); |
232 }) | 252 }) |
233 ); | 253 ); |
234 }) | 254 }) |
235 ); | 255 ); |
236 })); | 256 })); |
237 }, | 257 }, |
238 | 258 |
239 function restoreClosedWindows() { | 259 function restoreClosedWindows() { |
260 checkOnChangedEvent(1); | |
261 | |
240 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 262 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
241 var windowCountBeforeRestore = win.length; | 263 var windowCountBeforeRestore = win.length; |
242 chrome.sessions.restore(recentlyClosedWindowIds[0], | 264 chrome.sessions.restore(recentlyClosedWindowIds[0], |
243 function(win_session) { | 265 function(win_session) { |
244 assertEq(1, win_session.window.tabs.length); | 266 assertEq(1, win_session.window.tabs.length); |
245 }); | 267 }); |
246 function done() { | 268 function done() { |
247 chrome.windows.getAll({"populate": true}, | 269 chrome.windows.getAll({"populate": true}, |
248 callbackPass(function(win) { | 270 callbackPass(function(win) { |
249 assertEq(windowCountBeforeRestore + 1, win.length); | 271 assertEq(windowCountBeforeRestore + 1, win.length); |
(...skipping 28 matching lines...) Expand all Loading... | |
278 callbackPass(function(win) { | 300 callbackPass(function(win) { |
279 assertEq(windowCountBeforeRestore, win.length); | 301 assertEq(windowCountBeforeRestore, win.length); |
280 }) | 302 }) |
281 ); | 303 ); |
282 }) | 304 }) |
283 ); | 305 ); |
284 })); | 306 })); |
285 }, | 307 }, |
286 | 308 |
287 function restoreMostRecentEntry() { | 309 function restoreMostRecentEntry() { |
310 checkOnChangedEvent(1); | |
311 | |
288 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 312 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
289 var windowCountBeforeRestore = win.length; | 313 var windowCountBeforeRestore = win.length; |
290 chrome.sessions.restore(callbackPass(function(win_session) { | 314 chrome.sessions.restore(callbackPass(function(win_session) { |
291 assertEq(2, win_session.window.tabs.length); | 315 assertEq(2, win_session.window.tabs.length); |
292 chrome.windows.getAll({"populate": true}, | 316 chrome.windows.getAll({"populate": true}, |
293 callbackPass(function(win) { | 317 callbackPass(function(win) { |
294 assertEq(windowCountBeforeRestore + 1, win.length); | 318 assertEq(windowCountBeforeRestore + 1, win.length); |
295 }) | 319 }) |
296 ); | 320 ); |
297 })); | 321 })); |
298 })); | 322 })); |
299 }, | 323 }, |
300 | 324 |
301 function checkRecentlyClosedListEmpty() { | 325 function checkRecentlyClosedListEmpty() { |
302 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 326 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
303 var windowCountBeforeRestore = win.length; | 327 var windowCountBeforeRestore = win.length; |
304 chrome.sessions.restore( | 328 chrome.sessions.restore( |
305 callbackFail("There are no recently closed sessions.", function() { | 329 callbackFail("There are no recently closed sessions.", function() { |
306 chrome.windows.getAll({"populate": true}, | 330 chrome.windows.getAll({"populate": true}, |
307 callbackPass(function(win) { | 331 callbackPass(function(win) { |
308 assertEq(windowCountBeforeRestore, win.length); | 332 assertEq(windowCountBeforeRestore, win.length); |
309 }) | 333 }) |
310 ); | 334 ); |
311 }) | 335 }) |
312 ); | 336 ); |
313 })); | 337 })); |
314 } | 338 } |
315 ]); | 339 ]); |
OLD | NEW |