OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 }); | 59 }); |
60 } | 60 } |
61 | 61 |
62 chrome.test.runTests([ | 62 chrome.test.runTests([ |
63 // After setupWindows | 63 // After setupWindows |
64 // | 64 // |
65 // Window1: a,b,c | 65 // Window1: a,b,c |
66 // Window2: a,b | 66 // Window2: a,b |
67 // Window3: a,b | 67 // Window3: a,b |
68 // | 68 // |
69 // After retriveClosedTabs: | 69 // After retrieveClosedTabs: |
70 // | 70 // |
71 // Window1: c | 71 // Window1: c |
72 // Window2: a,b | 72 // Window2: a,b |
73 // Window3: a,b | 73 // Window3: a,b |
74 // ClosedList: a,b | 74 // ClosedList: a,b |
75 // | 75 // |
76 // After retriveClosedWindows: | 76 // After retrieveClosedWindows: |
77 // | 77 // |
78 // Window1: c | 78 // Window1: c |
79 // ClosedList: Window2,Window3,a,b | 79 // ClosedList: Window2,Window3,a,b |
80 function setupWindows() { | 80 function setupWindows() { |
81 var callArgs = [ | 81 var callArgs = [ |
82 pages, | 82 pages, |
83 pages.slice(0, 2), | 83 pages.slice(0, 2), |
84 pages.slice(0, 2) | 84 pages.slice(0, 2) |
85 ]; | 85 ]; |
86 callForEach( | 86 callForEach( |
(...skipping 20 matching lines...) Expand all Loading... |
107 | 107 |
108 function retrieveClosedTabs() { | 108 function retrieveClosedTabs() { |
109 // Check that the recently closed list contains what we expect | 109 // Check that the recently closed list contains what we expect |
110 // after removing tabs. | 110 // after removing tabs. |
111 callForEach( | 111 callForEach( |
112 chrome.tabs.remove, | 112 chrome.tabs.remove, |
113 firstWindowTabIds.slice(0, 2).reverse(), | 113 firstWindowTabIds.slice(0, 2).reverse(), |
114 function each() { | 114 function each() { |
115 }, | 115 }, |
116 function done() { | 116 function done() { |
117 chrome.sessionRestore.getRecentlyClosed( | 117 chrome.sessions.getRecentlyClosed( |
118 {maxResults: 2, entryType: "tab"}, | 118 {maxResults: 2, entryType: "tab"}, |
119 callbackPass(function(entries) { | 119 callbackPass(function(entries) { |
120 var expectedEntries = [ | 120 var expectedEntries = [ |
121 { tab: { url: pages[0] } }, | 121 { tab: { url: pages[0] } }, |
122 { tab: { url: pages[1] } } | 122 { tab: { url: pages[1] } } |
123 ]; | 123 ]; |
124 checkEntries(expectedEntries, entries); | 124 checkEntries(expectedEntries, entries); |
125 entries.forEach(function(entry) { | 125 entries.forEach(function(entry) { |
126 recentlyClosedTabIds.push(entry.id); | 126 recentlyClosedTabIds.push(entry.tab.sessionId); |
127 }); | 127 }); |
128 }) | 128 }) |
129 ); | 129 ); |
130 } | 130 } |
131 ); | 131 ); |
132 }, | 132 }, |
133 | 133 |
134 function retrieveClosedWindows() { | 134 function retrieveClosedWindows() { |
135 // Check that the recently closed list contains what we expect | 135 // Check that the recently closed list contains what we expect |
136 // after removing windows. | 136 // after removing windows. |
137 callForEach( | 137 callForEach( |
138 chrome.windows.remove, | 138 chrome.windows.remove, |
139 windowIds.slice(1, 3).reverse(), | 139 windowIds.slice(1, 3).reverse(), |
140 function each() { | 140 function each() { |
141 }, | 141 }, |
142 function done() { | 142 function done() { |
143 chrome.sessionRestore.getRecentlyClosed( | 143 chrome.sessions.getRecentlyClosed( |
144 {maxResults: 2, entryType: "window"}, | 144 {maxResults: 2, entryType: "window"}, |
145 callbackPass(function(entries) { | 145 callbackPass(function(entries) { |
146 var expectedEntries = [ | 146 var expectedEntries = [ |
147 { window: { tabsLength: 2 } }, | 147 { window: { tabsLength: 2 } }, |
148 { window: { tabsLength: 2 } } | 148 { window: { tabsLength: 2 } } |
149 ]; | 149 ]; |
150 checkEntries(expectedEntries, entries); | 150 checkEntries(expectedEntries, entries); |
151 entries[0].window.tabs.forEach(function(tab) { | 151 entries[0].window.tabs.forEach(function(tab) { |
152 recentlyClosedSecondWindowTabIds.push(tab.id); | 152 recentlyClosedSecondWindowTabIds.push(tab.sessionId); |
153 }); | 153 }); |
154 entries.forEach(function(entry) { | 154 entries.forEach(function(entry) { |
155 recentlyClosedWindowIds.push(entry.id); | 155 recentlyClosedWindowIds.push(entry.window.sessionId); |
156 }); | 156 }); |
157 }) | 157 }) |
158 ); | 158 ); |
159 } | 159 } |
160 ); | 160 ); |
161 }, | 161 }, |
162 | 162 |
163 function retrieveClosedEntries() { | 163 function retrieveClosedEntries() { |
164 // Check that the recently closed list contains what we expect | 164 // Check that the recently closed list contains what we expect |
165 // after removing tabs and windows. | 165 // after removing tabs and windows. |
166 chrome.sessionRestore.getRecentlyClosed( | 166 chrome.sessions.getRecentlyClosed( |
167 callbackPass(function(entries) { | 167 callbackPass(function(entries) { |
168 var expectedEntries = [ | 168 var expectedEntries = [ |
169 { window: { tabsLength: 2 } }, | 169 { window: { tabsLength: 2 } }, |
170 { window: { tabsLength: 2 } }, | 170 { window: { tabsLength: 2 } }, |
171 { tab: { url: pages[0] } }, | 171 { tab: { url: pages[0] } }, |
172 { tab: { url: pages[1] } } | 172 { tab: { url: pages[1] } } |
173 ]; | 173 ]; |
174 checkEntries(expectedEntries, entries); | 174 checkEntries(expectedEntries, entries); |
175 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, | 175 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, |
176 entries.length); | 176 entries.length); |
177 }) | 177 }) |
178 ); | 178 ); |
179 }, | 179 }, |
180 | 180 |
181 function retrieveMaxEntries() { | 181 function retrieveMaxEntries() { |
182 // Check that the recently closed list contains what we expect | 182 // Check that the recently closed list contains what we expect |
183 // after removing tabs and windows. | 183 // after removing tabs and windows. |
184 chrome.sessionRestore.getRecentlyClosed({maxResults: 25}, | 184 chrome.sessions.getRecentlyClosed({maxResults: 25}, |
185 callbackPass(function(entries) { | 185 callbackPass(function(entries) { |
186 var expectedEntries = [ | 186 var expectedEntries = [ |
187 { window: { tabsLength: 2 } }, | 187 { window: { tabsLength: 2 } }, |
188 { window: { tabsLength: 2 } }, | 188 { window: { tabsLength: 2 } }, |
189 { tab: { url: pages[0] } }, | 189 { tab: { url: pages[0] } }, |
190 { tab: { url: pages[1] } } | 190 { tab: { url: pages[1] } } |
191 ]; | 191 ]; |
192 checkEntries(expectedEntries, entries); | 192 checkEntries(expectedEntries, entries); |
193 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, | 193 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, |
194 entries.length); | 194 entries.length); |
195 }) | 195 }) |
196 ); | 196 ); |
197 }, | 197 }, |
198 | 198 |
199 function restoreClosedTabs() { | 199 function restoreClosedTabs() { |
200 chrome.windows.get(windowIds[0], {"populate": true}, | 200 chrome.windows.get(windowIds[0], {"populate": true}, |
201 callbackPass(function(win) { | 201 callbackPass(function(win) { |
202 var tabCountBeforeRestore = win.tabs.length; | 202 var tabCountBeforeRestore = win.tabs.length; |
203 callForEach( | 203 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab) { |
204 chrome.sessionRestore.restore, | 204 assertEq(pages[0], tab.url); |
205 recentlyClosedTabIds.slice(0, 2), | 205 }); |
206 function each() { | 206 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab) { |
207 }, | 207 assertEq(pages[1], tab.url); |
208 function done() { | 208 }); |
209 chrome.windows.get(windowIds[0], {"populate": true}, | 209 chrome.windows.get(windowIds[0], {"populate": true}, |
210 callbackPass(function(win){ | 210 callbackPass(function(win){ |
211 assertEq(tabCountBeforeRestore + 2, win.tabs.length); | 211 assertEq(tabCountBeforeRestore + 2, win.tabs.length); |
212 win.tabs.forEach(function(tab, i) { | 212 win.tabs.forEach(function(tab, i) { |
213 assertEq(pages[i++], tab.url); | 213 assertEq(pages[i++], tab.url); |
214 }); | 214 }); |
215 }) | 215 }) |
216 ); | |
217 } | |
218 ); | 216 ); |
219 }) | 217 }) |
220 ); | 218 ); |
221 }, | 219 }, |
222 | 220 |
223 function restoreTabInClosedWindow() { | 221 function restoreTabInClosedWindow() { |
224 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 222 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
225 var windowCountBeforeRestore = win.length; | 223 var windowCountBeforeRestore = win.length; |
226 chrome.sessionRestore.restore(recentlyClosedSecondWindowTabIds[0], | 224 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], |
227 callbackPass(function() { | 225 callbackPass(function(tab) { |
| 226 assertEq(pages[0], tab.url); |
228 chrome.windows.getAll({"populate": true}, | 227 chrome.windows.getAll({"populate": true}, |
229 callbackPass(function(win) { | 228 callbackPass(function(win) { |
230 assertEq(windowCountBeforeRestore + 1, win.length); | 229 assertEq(windowCountBeforeRestore + 1, win.length); |
231 assertEq(1, win[win.length - 1].tabs.length); | 230 assertEq(1, win[win.length - 1].tabs.length); |
232 assertEq(pages[0], win[win.length - 1].tabs[0].url); | 231 assertEq(pages[0], win[win.length - 1].tabs[0].url); |
233 }) | 232 }) |
234 ); | 233 ); |
235 }) | 234 }) |
236 ); | 235 ); |
237 })); | 236 })); |
238 }, | 237 }, |
239 | 238 |
240 function restoreClosedWindows() { | 239 function restoreClosedWindows() { |
241 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 240 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
242 var windowCountBeforeRestore = win.length; | 241 var windowCountBeforeRestore = win.length; |
243 callForEach( | 242 chrome.sessions.restore(recentlyClosedWindowIds[0], function(window) { |
244 chrome.sessionRestore.restore, | 243 assertEq(1, window.tabs.length); |
245 recentlyClosedWindowIds.slice(0, 1), | 244 }); |
246 function each() { | 245 function done() { |
247 }, | 246 chrome.windows.getAll({"populate": true}, |
248 function done() { | 247 callbackPass(function(win) { |
249 chrome.windows.getAll({"populate": true}, | 248 assertEq(windowCountBeforeRestore + 1, win.length); |
250 callbackPass(function(win) { | 249 }) |
251 assertEq(windowCountBeforeRestore + 1, win.length); | 250 ); |
252 }) | 251 } |
253 ); | |
254 } | |
255 ); | |
256 })); | 252 })); |
257 }, | 253 }, |
258 | 254 |
259 function restoreSameEntryTwice() { | 255 function restoreSameEntryTwice() { |
260 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 256 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
261 var windowCountBeforeRestore = win.length; | 257 var windowCountBeforeRestore = win.length; |
262 chrome.sessionRestore.restore(recentlyClosedWindowIds[0], | 258 chrome.sessions.restore(recentlyClosedWindowIds[0], |
263 callbackFail("Invalid session id.", function() { | 259 callbackFail("Invalid session id.", function() { |
264 chrome.windows.getAll({"populate": true}, | 260 chrome.windows.getAll({"populate": true}, |
265 callbackPass(function(win) { | 261 callbackPass(function(win) { |
266 assertEq(windowCountBeforeRestore, win.length); | 262 assertEq(windowCountBeforeRestore, win.length); |
267 }) | 263 }) |
268 ); | 264 ); |
269 }) | 265 }) |
270 ); | 266 ); |
271 })); | 267 })); |
272 }, | 268 }, |
273 | 269 |
274 function restoreInvalidEntries() { | 270 function restoreInvalidEntries() { |
275 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 271 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
276 var windowCountBeforeRestore = win.length; | 272 var windowCountBeforeRestore = win.length; |
277 chrome.sessionRestore.restore(-1, | 273 chrome.sessions.restore("-1", |
278 callbackFail("Invalid session id.", function() { | 274 callbackFail("Invalid session id.", function() { |
279 chrome.windows.getAll({"populate": true}, | 275 chrome.windows.getAll({"populate": true}, |
280 callbackPass(function(win) { | 276 callbackPass(function(win) { |
281 assertEq(windowCountBeforeRestore, win.length); | 277 assertEq(windowCountBeforeRestore, win.length); |
282 }) | 278 }) |
283 ); | 279 ); |
284 }) | 280 }) |
285 ); | 281 ); |
286 })); | 282 })); |
287 }, | 283 }, |
288 | 284 |
289 function restoreMostRecentEntry() { | 285 function restoreMostRecentEntry() { |
290 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 286 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
291 var windowCountBeforeRestore = win.length; | 287 var windowCountBeforeRestore = win.length; |
292 chrome.sessionRestore.restore(callbackPass(function() { | 288 chrome.sessions.restore(callbackPass(function(restoredWindow) { |
| 289 assertEq(2, restoredWindow.tabs.length); |
293 chrome.windows.getAll({"populate": true}, | 290 chrome.windows.getAll({"populate": true}, |
294 callbackPass(function(win) { | 291 callbackPass(function(win) { |
295 assertEq(windowCountBeforeRestore + 1, win.length); | 292 assertEq(windowCountBeforeRestore + 1, win.length); |
296 }) | 293 }) |
297 ); | 294 ); |
298 })); | 295 })); |
299 })); | 296 })); |
300 }, | 297 }, |
301 | 298 |
302 function checkRecentlyClosedListEmpty() { | 299 function checkRecentlyClosedListEmpty() { |
303 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { | 300 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { |
304 var windowCountBeforeRestore = win.length; | 301 var windowCountBeforeRestore = win.length; |
305 chrome.sessionRestore.restore( | 302 chrome.sessions.restore( |
306 callbackFail("There are no recently closed sessions.", function() { | 303 callbackFail("There are no recently closed sessions.", function() { |
307 chrome.windows.getAll({"populate": true}, | 304 chrome.windows.getAll({"populate": true}, |
308 callbackPass(function(win) { | 305 callbackPass(function(win) { |
309 assertEq(windowCountBeforeRestore, win.length); | 306 assertEq(windowCountBeforeRestore, win.length); |
310 }) | 307 }) |
311 ); | 308 ); |
312 }) | 309 }) |
313 ); | 310 ); |
314 })); | 311 })); |
315 } | 312 } |
316 | |
317 ]); | 313 ]); |
OLD | NEW |