Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: chrome/test/data/extensions/api_test/sessions/sessions.js

Issue 201393002: Add onChanged callback for chrome.sessions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
not at google - send to devlin 2014/03/26 21:12:38 I keep reading this as a function body, because th
66 function() {
67 callbackCount++;
68 }
69 );
70
71 var checkEvent = function() {
72 if (callbackCount < expectedCallbackCount)
73 window.setTimeout(checkEvent, 100);
74 else {
75 assertEq(callbackCount, expectedCallbackCount);
76 doneListening();
77 }
78 };
79 window.setTimeout(checkEvent, 1000);
not at google - send to devlin 2014/03/26 21:12:38 It would be nice to notify the user why this test
80 }
81
62 chrome.test.runTests([ 82 chrome.test.runTests([
63 // After setupWindows 83 // After setupWindows
64 // 84 //
65 // Window1: a,b,c 85 // Window1: a,b,c
66 // Window2: a,b 86 // Window2: a,b
67 // Window3: a,b 87 // Window3: a,b
68 // 88 //
69 // After retrieveClosedTabs: 89 // After retrieveClosedTabs:
70 // 90 //
71 // Window1: c 91 // Window1: c
(...skipping 29 matching lines...) Expand all
101 assertEq(callArgs.length + 1, win.length); 121 assertEq(callArgs.length + 1, win.length);
102 }) 122 })
103 ); 123 );
104 } 124 }
105 ); 125 );
106 }, 126 },
107 127
108 function retrieveClosedTabs() { 128 function retrieveClosedTabs() {
109 // Check that the recently closed list contains what we expect 129 // Check that the recently closed list contains what we expect
110 // after removing tabs. 130 // after removing tabs.
131 checkOnChangedEvent(2);
132
111 callForEach( 133 callForEach(
112 chrome.tabs.remove, 134 chrome.tabs.remove,
113 firstWindowTabIds.slice(0, 2).reverse(), 135 firstWindowTabIds.slice(0, 2).reverse(),
114 function each() { 136 function each() {
115 }, 137 },
116 function done() { 138 function done() {
117 chrome.sessions.getRecentlyClosed( 139 chrome.sessions.getRecentlyClosed(
118 {maxResults: 2}, 140 {maxResults: 2},
119 callbackPass(function(entries) { 141 callbackPass(function(entries) {
120 var expectedEntries = [ 142 var expectedEntries = [
121 { tab: { url: pages[0] } }, 143 { tab: { url: pages[0] } },
122 { tab: { url: pages[1] } } 144 { tab: { url: pages[1] } }
123 ]; 145 ];
124 checkEntries(expectedEntries, entries); 146 checkEntries(expectedEntries, entries);
125 entries.forEach(function(entry) { 147 entries.forEach(function(entry) {
126 recentlyClosedTabIds.push(entry.tab.sessionId); 148 recentlyClosedTabIds.push(entry.tab.sessionId);
127 }); 149 });
128 }) 150 })
129 ); 151 );
130 } 152 }
131 ); 153 );
132 }, 154 },
133 155
134 function retrieveClosedWindows() { 156 function retrieveClosedWindows() {
135 // Check that the recently closed list contains what we expect 157 // Check that the recently closed list contains what we expect
136 // after removing windows. 158 // after removing windows.
159 checkOnChangedEvent(2);
160
137 callForEach( 161 callForEach(
138 chrome.windows.remove, 162 chrome.windows.remove,
139 windowIds.slice(1, 3).reverse(), 163 windowIds.slice(1, 3).reverse(),
140 function each() { 164 function each() {
141 }, 165 },
142 function done() { 166 function done() {
143 chrome.sessions.getRecentlyClosed( 167 chrome.sessions.getRecentlyClosed(
144 {maxResults: 2}, 168 {maxResults: 2},
145 callbackPass(function(entries) { 169 callbackPass(function(entries) {
146 var expectedEntries = [ 170 var expectedEntries = [
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 { tab: { url: pages[1] } } 214 { tab: { url: pages[1] } }
191 ]; 215 ];
192 checkEntries(expectedEntries, entries); 216 checkEntries(expectedEntries, entries);
193 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length, 217 assertEq(recentlyClosedTabIds.length + recentlyClosedWindowIds.length,
194 entries.length); 218 entries.length);
195 }) 219 })
196 ); 220 );
197 }, 221 },
198 222
199 function restoreClosedTabs() { 223 function restoreClosedTabs() {
224 checkOnChangedEvent(2);
225
200 chrome.windows.get(windowIds[0], {"populate": true}, 226 chrome.windows.get(windowIds[0], {"populate": true},
201 callbackPass(function(win) { 227 callbackPass(function(win) {
202 var tabCountBeforeRestore = win.tabs.length; 228 var tabCountBeforeRestore = win.tabs.length;
203 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab_session) { 229 chrome.sessions.restore(recentlyClosedTabIds[0], function(tab_session) {
204 assertEq(pages[0], tab_session.tab.url); 230 assertEq(pages[0], tab_session.tab.url);
205 }); 231 });
206 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab_session) { 232 chrome.sessions.restore(recentlyClosedTabIds[1], function(tab_session) {
207 assertEq(pages[1], tab_session.tab.url); 233 assertEq(pages[1], tab_session.tab.url);
208 }); 234 });
209 chrome.windows.get(windowIds[0], {"populate": true}, 235 chrome.windows.get(windowIds[0], {"populate": true},
210 callbackPass(function(win){ 236 callbackPass(function(win){
211 assertEq(tabCountBeforeRestore + 2, win.tabs.length); 237 assertEq(tabCountBeforeRestore + 2, win.tabs.length);
212 win.tabs.forEach(function(tab, i) { 238 win.tabs.forEach(function(tab, i) {
213 assertEq(pages[i++], tab.url); 239 assertEq(pages[i++], tab.url);
214 }); 240 });
215 }) 241 })
216 ); 242 );
217 }) 243 })
218 ); 244 );
219 }, 245 },
220 246
221 function restoreTabInClosedWindow() { 247 function restoreTabInClosedWindow() {
248 checkOnChangedEvent(1);
249
222 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { 250 chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
223 var windowCountBeforeRestore = win.length; 251 var windowCountBeforeRestore = win.length;
224 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0], 252 chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0],
225 callbackPass(function(tab_session) { 253 callbackPass(function(tab_session) {
226 assertEq(pages[0], tab_session.tab.url); 254 assertEq(pages[0], tab_session.tab.url);
227 chrome.windows.getAll({"populate": true}, 255 chrome.windows.getAll({"populate": true},
228 callbackPass(function(win) { 256 callbackPass(function(win) {
229 assertEq(windowCountBeforeRestore + 1, win.length); 257 assertEq(windowCountBeforeRestore + 1, win.length);
230 assertEq(1, win[win.length - 1].tabs.length); 258 assertEq(1, win[win.length - 1].tabs.length);
231 assertEq(pages[0], win[win.length - 1].tabs[0].url); 259 assertEq(pages[0], win[win.length - 1].tabs[0].url);
232 }) 260 })
233 ); 261 );
234 }) 262 })
235 ); 263 );
236 })); 264 }));
237 }, 265 },
238 266
239 function restoreClosedWindows() { 267 function restoreClosedWindows() {
268 checkOnChangedEvent(1);
269
240 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { 270 chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
241 var windowCountBeforeRestore = win.length; 271 var windowCountBeforeRestore = win.length;
242 chrome.sessions.restore(recentlyClosedWindowIds[0], 272 chrome.sessions.restore(recentlyClosedWindowIds[0],
243 function(win_session) { 273 function(win_session) {
244 assertEq(1, win_session.window.tabs.length); 274 assertEq(1, win_session.window.tabs.length);
245 }); 275 });
246 function done() { 276 function done() {
247 chrome.windows.getAll({"populate": true}, 277 chrome.windows.getAll({"populate": true},
248 callbackPass(function(win) { 278 callbackPass(function(win) {
249 assertEq(windowCountBeforeRestore + 1, win.length); 279 assertEq(windowCountBeforeRestore + 1, win.length);
(...skipping 28 matching lines...) Expand all
278 callbackPass(function(win) { 308 callbackPass(function(win) {
279 assertEq(windowCountBeforeRestore, win.length); 309 assertEq(windowCountBeforeRestore, win.length);
280 }) 310 })
281 ); 311 );
282 }) 312 })
283 ); 313 );
284 })); 314 }));
285 }, 315 },
286 316
287 function restoreMostRecentEntry() { 317 function restoreMostRecentEntry() {
318 checkOnChangedEvent(1);
319
288 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { 320 chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
289 var windowCountBeforeRestore = win.length; 321 var windowCountBeforeRestore = win.length;
290 chrome.sessions.restore(callbackPass(function(win_session) { 322 chrome.sessions.restore(callbackPass(function(win_session) {
291 assertEq(2, win_session.window.tabs.length); 323 assertEq(2, win_session.window.tabs.length);
292 chrome.windows.getAll({"populate": true}, 324 chrome.windows.getAll({"populate": true},
293 callbackPass(function(win) { 325 callbackPass(function(win) {
294 assertEq(windowCountBeforeRestore + 1, win.length); 326 assertEq(windowCountBeforeRestore + 1, win.length);
295 }) 327 })
296 ); 328 );
297 })); 329 }));
298 })); 330 }));
299 }, 331 },
300 332
301 function checkRecentlyClosedListEmpty() { 333 function checkRecentlyClosedListEmpty() {
302 chrome.windows.getAll({"populate": true}, callbackPass(function(win) { 334 chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
303 var windowCountBeforeRestore = win.length; 335 var windowCountBeforeRestore = win.length;
304 chrome.sessions.restore( 336 chrome.sessions.restore(
305 callbackFail("There are no recently closed sessions.", function() { 337 callbackFail("There are no recently closed sessions.", function() {
306 chrome.windows.getAll({"populate": true}, 338 chrome.windows.getAll({"populate": true},
307 callbackPass(function(win) { 339 callbackPass(function(win) {
308 assertEq(windowCountBeforeRestore, win.length); 340 assertEq(windowCountBeforeRestore, win.length);
309 }) 341 })
310 ); 342 );
311 }) 343 })
312 ); 344 );
313 })); 345 }));
314 } 346 }
315 ]); 347 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698