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

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

Issue 289006: Issue 21729: Add new event chrome.tabs.onStatusChange . (Closed)
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/test/data/extensions/api_test/isolated_world1/background.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // tabs api test 1 // tabs api test
2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Tabs 2 // browser_tests.exe --gtest_filter=ExtensionApiTest.Tabs
3 3
4 // We have a bunch of places where we need to remember some state from one 4 // We have a bunch of places where we need to remember some state from one
5 // test (or setup code) to subsequent tests. 5 // test (or setup code) to subsequent tests.
6 var firstWindowId = null; 6 var firstWindowId = null;
7 var secondWindowId = null; 7 var secondWindowId = null;
8 var firstTabIndex = null; 8 var firstTabIndex = null;
9 var testTabId = null; 9 var testTabId = null;
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 }, 114 },
115 115
116 function updateSelect() { 116 function updateSelect() {
117 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { 117 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
118 assertEq(false, tabs[1].selected); 118 assertEq(false, tabs[1].selected);
119 assertEq(true, tabs[2].selected); 119 assertEq(true, tabs[2].selected);
120 // Select tab[1]. 120 // Select tab[1].
121 chrome.tabs.update(tabs[1].id, {selected: true}, 121 chrome.tabs.update(tabs[1].id, {selected: true},
122 pass(function(tab1){ 122 pass(function(tab1){
123 // Check update of tab[1]. 123 // Check update of tab[1].
124 chrome.test.assertEq(true, tab1.selected); 124 chrome.test.assertEq(true, tab1.selected);
125 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { 125 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
126 assertEq(true, tabs[1].selected); 126 assertEq(true, tabs[1].selected);
127 assertEq(false, tabs[2].selected); 127 assertEq(false, tabs[2].selected);
128 // Select tab[2]. 128 // Select tab[2].
129 chrome.tabs.update(tabs[2].id, {selected: true}, 129 chrome.tabs.update(tabs[2].id, {selected: true},
130 pass(function(tab2){ 130 pass(function(tab2){
131 // Check update of tab[2]. 131 // Check update of tab[2].
132 chrome.test.assertEq(true, tab2.selected); 132 chrome.test.assertEq(true, tab2.selected);
133 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) { 133 chrome.tabs.getAllInWindow(firstWindowId, pass(function(tabs) {
134 assertEq(false, tabs[1].selected); 134 assertEq(false, tabs[1].selected);
135 assertEq(true, tabs[2].selected); 135 assertEq(true, tabs[2].selected);
136 })); 136 }));
137 })); 137 }));
138 })); 138 }));
139 })); 139 }));
140 })); 140 }));
141 }, 141 },
142 142
(...skipping 12 matching lines...) Expand all
155 155
156 // Create a bunch of tabs and record the resulting ids. 156 // Create a bunch of tabs and record the resulting ids.
157 function moveTabsSetup2() { 157 function moveTabsSetup2() {
158 var letters = ['a', 'b', 'c', 'd', 'e']; 158 var letters = ['a', 'b', 'c', 'd', 'e'];
159 for (var i in letters) { 159 for (var i in letters) {
160 chrome.tabs.create({"windowId": moveWindow1, 160 chrome.tabs.create({"windowId": moveWindow1,
161 "url": pageUrl(letters[i])}, 161 "url": pageUrl(letters[i])},
162 pass(function(tab) { 162 pass(function(tab) {
163 var letter = tab.url[tab.url.length-6]; 163 var letter = tab.url[tab.url.length-6];
164 moveTabIds[letter] = tab.id; 164 moveTabIds[letter] = tab.id;
165 165
166 // Assert on last callback that tabs were added in the order we created 166 // Assert on last callback that tabs were added in the order we created
167 // them. 167 // them.
168 if (letter == 'e') { 168 if (letter == 'e') {
169 chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) { 169 chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) {
170 assertEq(6, tabs.length); 170 assertEq(6, tabs.length);
171 assertEq("chrome://newtab/", tabs[0].url); 171 assertEq("chrome://newtab/", tabs[0].url);
172 assertEq(pageUrl("a"), tabs[1].url); 172 assertEq(pageUrl("a"), tabs[1].url);
173 assertEq(pageUrl("b"), tabs[2].url); 173 assertEq(pageUrl("b"), tabs[2].url);
174 assertEq(pageUrl("c"), tabs[3].url); 174 assertEq(pageUrl("c"), tabs[3].url);
175 assertEq(pageUrl("d"), tabs[4].url); 175 assertEq(pageUrl("d"), tabs[4].url);
(...skipping 12 matching lines...) Expand all
188 // 188 //
189 // After: 189 // After:
190 // Window1: (newtab),a,e,c 190 // Window1: (newtab),a,e,c
191 // Window2: b,(newtab),d 191 // Window2: b,(newtab),d
192 function moveTabs() { 192 function moveTabs() {
193 chrome.tabs.move(moveTabIds['b'], {"windowId": moveWindow2, "index": 0}, 193 chrome.tabs.move(moveTabIds['b'], {"windowId": moveWindow2, "index": 0},
194 pass(function(tabB) { 194 pass(function(tabB) {
195 chrome.test.assertEq(0, tabB.index); 195 chrome.test.assertEq(0, tabB.index);
196 chrome.tabs.move(moveTabIds['e'], {"index": 2}, 196 chrome.tabs.move(moveTabIds['e'], {"index": 2},
197 pass(function(tabE) { 197 pass(function(tabE) {
198 chrome.test.assertEq(2, tabE.index); 198 chrome.test.assertEq(2, tabE.index);
199 chrome.tabs.move(moveTabIds['d'], {"windowId": moveWindow2, 199 chrome.tabs.move(moveTabIds['d'], {"windowId": moveWindow2,
200 "index": 2}, pass(function(tabD) { 200 "index": 2}, pass(function(tabD) {
201 chrome.test.assertEq(2, tabD.index); 201 chrome.test.assertEq(2, tabD.index);
202 })); 202 }));
203 })); 203 }));
204 })); 204 }));
205 }, 205 },
206 206
207 // Check that the tab/window state is what we expect after doing moves. 207 // Check that the tab/window state is what we expect after doing moves.
208 function moveTabsCheck() { 208 function moveTabsCheck() {
209 chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) { 209 chrome.tabs.getAllInWindow(moveWindow1, pass(function(tabs) {
210 assertEq(4, tabs.length); 210 assertEq(4, tabs.length);
211 assertEq("chrome://newtab/", tabs[0].url); 211 assertEq("chrome://newtab/", tabs[0].url);
212 assertEq(pageUrl("a"), tabs[1].url); 212 assertEq(pageUrl("a"), tabs[1].url);
213 assertEq(pageUrl("e"), tabs[2].url); 213 assertEq(pageUrl("e"), tabs[2].url);
214 assertEq(pageUrl("c"), tabs[3].url); 214 assertEq(pageUrl("c"), tabs[3].url);
215 215
216 chrome.tabs.getAllInWindow(moveWindow2, pass(function(tabs) { 216 chrome.tabs.getAllInWindow(moveWindow2, pass(function(tabs) {
217 assertEq(3, tabs.length); 217 assertEq(3, tabs.length);
218 assertEq(pageUrl("b"), tabs[0].url); 218 assertEq(pageUrl("b"), tabs[0].url);
219 assertEq("chrome://newtab/", tabs[1].url); 219 assertEq("chrome://newtab/", tabs[1].url);
220 assertEq(pageUrl("d"), tabs[2].url); 220 assertEq(pageUrl("d"), tabs[2].url);
221 })); 221 }));
222 })); 222 }));
223 }, 223 },
224 224
225 function remove() { 225 function remove() {
226 chrome.tabs.remove(moveTabIds["d"], pass(function() { 226 chrome.tabs.remove(moveTabIds["d"], pass(function() {
227 chrome.tabs.getAllInWindow(moveWindow2, 227 chrome.tabs.getAllInWindow(moveWindow2,
228 pass(function(tabs) { 228 pass(function(tabs) {
229 assertEq(2, tabs.length); 229 assertEq(2, tabs.length);
230 assertEq(pageUrl("b"), tabs[0].url); 230 assertEq(pageUrl("b"), tabs[0].url);
231 assertEq("chrome://newtab/", tabs[1].url); 231 assertEq("chrome://newtab/", tabs[1].url);
(...skipping 14 matching lines...) Expand all
246 TODO(rafaelw): This test fails in at least three distinct ways. One where 246 TODO(rafaelw): This test fails in at least three distinct ways. One where
247 the function actually fails to get anything and logs a "Internal error 247 the function actually fails to get anything and logs a "Internal error
248 while trying to capture visible region of the current tab" error from the 248 while trying to capture visible region of the current tab" error from the
249 browser process. 249 browser process.
250 function captureVisibleTab() { 250 function captureVisibleTab() {
251 // Take First Capture 251 // Take First Capture
252 chrome.tabs.captureVisibleTab(moveWindow1, 252 chrome.tabs.captureVisibleTab(moveWindow1,
253 pass(function(window1Url) { 253 pass(function(window1Url) {
254 assertEq("string", typeof(window1Url)); 254 assertEq("string", typeof(window1Url));
255 assertTrue(window1Url.length > 0); 255 assertTrue(window1Url.length > 0);
256 256
257 // Take Second Capture 257 // Take Second Capture
258 chrome.tabs.captureVisibleTab(moveWindow2, 258 chrome.tabs.captureVisibleTab(moveWindow2,
259 pass(function(window2Url) { 259 pass(function(window2Url) {
260 assertEq("string", typeof(window2Url)); 260 assertEq("string", typeof(window2Url));
261 assertTrue(window2Url.length > 0); 261 assertTrue(window2Url.length > 0);
262 assertTrue(window1Url != window2Url); 262 assertTrue(window1Url != window2Url);
263 263
264 // Now pass null for windowId - it should come back with something 264 // Now pass null for windowId - it should come back with something
265 // equal to either the first or second window. This is nondeterministic 265 // equal to either the first or second window. This is nondeterministic
266 // depending on whether you let chrome stay focused, or click 266 // depending on whether you let chrome stay focused, or click
267 // focus away (or are running on the try/build servers). 267 // focus away (or are running on the try/build servers).
268 chrome.tabs.captureVisibleTab(null, pass(function(url) { 268 chrome.tabs.captureVisibleTab(null, pass(function(url) {
269 assertEq("string", typeof(url)); 269 assertEq("string", typeof(url));
270 assertTrue(url.length > 0); 270 assertTrue(url.length > 0);
271 assertTrue(url == window1Url || url == window2Url); 271 assertTrue(url == window1Url || url == window2Url);
272 })); 272 }));
273 })); 273 }));
274 })); 274 }));
275 }, */ 275 }, */
276 276
277 function tabsOnCreated() { 277 function tabsOnCreated() {
278 chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) { 278 chrome.test.listenOnce(chrome.tabs.onCreated, function(tab) {
279 assertEq(pageUrl("f"), tab.url); 279 assertEq(pageUrl("f"), tab.url);
280 }); 280 });
281 281
282 chrome.tabs.create({"windowId": moveWindow1, "url": pageUrl("f"), 282 chrome.tabs.create({"windowId": moveWindow1, "url": pageUrl("f"),
283 "selected": true}, pass(function(tab) {})); 283 "selected": true}, pass(function(tab) {}));
284 }, 284 },
285 285
286 function tabsOnUpdated() { 286 function tabsOnUpdatedIgnoreTabArg() {
287 // A third argument was added to the onUpdated event callback.
288 // Test that an event handler which ignores this argument works.
287 var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated, 289 var onUpdatedCompleted = chrome.test.listenForever(chrome.tabs.onUpdated,
288 function(tabid, info) { 290 function(tabid, changeInfo) {
289 if (tabid == moveTabIds['a'] && info.status == "complete") { 291 if (tabid == moveTabIds['a'] && changeInfo.status == "complete") {
290 onUpdatedCompleted(); 292 onUpdatedCompleted();
291 } 293 }
292 } 294 }
293 ); 295 );
294 296
295 chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, 297 chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass());
296 pass()); 298 },
299
300 function tabsOnUpdated() {
301 var onUpdatedCompleted = chrome.test.listenForever(
302 chrome.tabs.onUpdated,
303 function(tabid, changeInfo, tab) {
304 // |tab| contains the id of the tab it describes.
305 // Test that |tabid| matches this id.
306 assertEq(tabid, tab.id);
307
308 // If |changeInfo| has a status property, than
309 // it should match the status of the tab in |tab|.
310 if (changeInfo.status) {
311 assertEq(changeInfo.status, tab.status);
312 }
313
314 if (tabid == moveTabIds['a'] && changeInfo.status == "complete") {
315 onUpdatedCompleted();
316 }
317 }
318 );
319
320 chrome.tabs.update(moveTabIds['a'], {"url": pageUrl("f")}, pass());
297 }, 321 },
298 322
299 function tabsOnMoved() { 323 function tabsOnMoved() {
300 chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) { 324 chrome.test.listenOnce(chrome.tabs.onMoved, function(tabid, info) {
301 assertEq(moveTabIds['a'], tabid); 325 assertEq(moveTabIds['a'], tabid);
302 }); 326 });
303 327
304 chrome.tabs.move(moveTabIds['a'], {"index": 0}, pass()); 328 chrome.tabs.move(moveTabIds['a'], {"index": 0}, pass());
305 }, 329 },
306 330
307 function tabsOnSelectionChanged() { 331 function tabsOnSelectionChanged() {
308 chrome.test.listenOnce(chrome.tabs.onSelectionChanged, 332 chrome.test.listenOnce(chrome.tabs.onSelectionChanged,
309 function(tabid, info) { 333 function(tabid, info) {
310 assertEq(moveTabIds['c'], tabid); 334 assertEq(moveTabIds['c'], tabid);
311 } 335 }
312 ); 336 );
313 337
314 chrome.tabs.update(moveTabIds['c'], {"selected": true}, 338 chrome.tabs.update(moveTabIds['c'], {"selected": true},
315 pass()); 339 pass());
316 }, 340 },
317 341
318 function tabsOnRemoved() { 342 function tabsOnRemoved() {
319 chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) { 343 chrome.test.listenOnce(chrome.tabs.onRemoved, function(tabid) {
320 assertEq(moveTabIds['c'], tabid); 344 assertEq(moveTabIds['c'], tabid);
321 }); 345 });
322 346
323 chrome.tabs.remove(moveTabIds['c'], pass()); 347 chrome.tabs.remove(moveTabIds['c'], pass());
324 }, 348 },
325 349
326 function setupRelativeUrlTests() { 350 function setupRelativeUrlTests() {
327 chrome.windows.create({}, pass(function(win) { 351 chrome.windows.create({}, pass(function(win) {
328 assertTrue(win.id > 0); 352 assertTrue(win.id > 0);
329 firstWindowId = win.id; 353 firstWindowId = win.id;
330 354
331 chrome.windows.getAll({}, pass(function(windows) { 355 chrome.windows.getAll({}, pass(function(windows) {
332 for (var i = 0; i < windows.length; i++) { 356 for (var i = 0; i < windows.length; i++) {
333 if (windows[i].id != firstWindowId) { 357 if (windows[i].id != firstWindowId) {
334 chrome.windows.remove(windows[i].id, pass()); 358 chrome.windows.remove(windows[i].id, pass());
335 } 359 }
336 } 360 }
337 })); 361 }));
338 })); 362 }));
339 }, 363 },
340 364
341 function relativeUrlTabsCreate() { 365 function relativeUrlTabsCreate() {
342 // Will be called from relative.html 366 // Will be called from relative.html
343 window.relativePageLoaded = chrome.test.callbackAdded(); 367 window.relativePageLoaded = chrome.test.callbackAdded();
344 var createCompleted = chrome.test.callbackAdded(); 368 var createCompleted = chrome.test.callbackAdded();
345 369
346 chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'}, 370 chrome.tabs.create({windowId: firstWindowId, url: 'relative.html'},
347 function(tab){ 371 function(tab){
348 testTabId = tab.id; 372 testTabId = tab.id;
349 createCompleted(); 373 createCompleted();
350 } 374 }
351 ); 375 );
352 }, 376 },
353 377
354 function relativeUrlTabsUpdate() { 378 function relativeUrlTabsUpdate() {
355 // Will be called from relative.html 379 // Will be called from relative.html
356 window.relativePageLoaded = chrome.test.callbackAdded(); 380 window.relativePageLoaded = chrome.test.callbackAdded();
357 381
358 chrome.tabs.update(testTabId, {url: pageUrl("a")}, function(tab) { 382 chrome.tabs.update(testTabId, {url: pageUrl("a")}, function(tab) {
359 chrome.test.assertEq(pageUrl("a"), tab.url); 383 chrome.test.assertEq(pageUrl("a"), tab.url);
360 chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) { 384 chrome.tabs.update(tab.id, {url: "relative.html"}, function(tab) {
361 }); 385 });
362 }); 386 });
363 }, 387 },
364 388
365 function relativeUrlWindowsCreate() { 389 function relativeUrlWindowsCreate() {
366 // Will be called from relative.html 390 // Will be called from relative.html
367 window.relativePageLoaded = chrome.test.callbackAdded(); 391 window.relativePageLoaded = chrome.test.callbackAdded();
368 392
369 chrome.windows.create({url: "relative.html"}); 393 chrome.windows.create({url: "relative.html"});
370 }, 394 },
371 395
372 function windowsOnCreated() { 396 function windowsOnCreated() {
373 chrome.test.listenOnce(chrome.windows.onCreated, function(window) { 397 chrome.test.listenOnce(chrome.windows.onCreated, function(window) {
374 chrome.test.assertTrue(window.width > 0); 398 chrome.test.assertTrue(window.width > 0);
375 chrome.test.assertTrue(window.height > 0); 399 chrome.test.assertTrue(window.height > 0);
376 windowEventsWindow = window; 400 windowEventsWindow = window;
377 chrome.tabs.getAllInWindow(window.id, pass(function(tabs) { 401 chrome.tabs.getAllInWindow(window.id, pass(function(tabs) {
378 assertEq(pageUrl("a"), tabs[0].url); 402 assertEq(pageUrl("a"), tabs[0].url);
379 })); 403 }));
380 }); 404 });
381 405
(...skipping 11 matching lines...) Expand all
393 // TODO(asargent) We still need to add tests for the following: 417 // TODO(asargent) We still need to add tests for the following:
394 // Methods: 418 // Methods:
395 // -chrome.tabs.connect 419 // -chrome.tabs.connect
396 // Events: 420 // Events:
397 // -chrome.tabs.onAttached 421 // -chrome.tabs.onAttached
398 // -chrome.tabs.onDetched 422 // -chrome.tabs.onDetched
399 // 423 //
400 // Also, it would be an improvement to check the captureVisibleTab results 424 // Also, it would be an improvement to check the captureVisibleTab results
401 // against a known-good result. 425 // against a known-good result.
402 ]); 426 ]);
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/isolated_world1/background.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698