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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_apitest.cc

Issue 11117011: Keep browser process alive while there are platform apps with background pages running. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: And another test Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <string.h> 5 #include <string.h>
6 6
7 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 event_router()->DeviceAdded(mock_adapter_, device1_.get()); 323 event_router()->DeviceAdded(mock_adapter_, device1_.get());
324 324
325 discovery_started.Reply("go"); 325 discovery_started.Reply("go");
326 ExtensionTestMessageListener discovery_stopped("ready", true); 326 ExtensionTestMessageListener discovery_stopped("ready", true);
327 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); 327 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied());
328 328
329 event_router()->DeviceAdded(mock_adapter_, device2_.get()); 329 event_router()->DeviceAdded(mock_adapter_, device2_.get());
330 discovery_stopped.Reply("go"); 330 discovery_stopped.Reply("go");
331 331
332 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 332 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
333 CloseShellWindowsAndWaitForAppToExit();
333 } 334 }
334 335
335 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) { 336 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, DiscoveryInProgress) {
336 // Fake that the adapter is discovering 337 // Fake that the adapter is discovering
337 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(true)); 338 EXPECT_CALL(*mock_adapter_, IsDiscovering()).WillOnce(testing::Return(true));
338 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 339 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
339 340
340 // Cache a device before the extension starts discovering 341 // Cache a device before the extension starts discovering
341 event_router()->DeviceAdded(mock_adapter_, device1_.get()); 342 event_router()->DeviceAdded(mock_adapter_, device1_.get());
342 343
(...skipping 10 matching lines...) Expand all
353 354
354 discovery_started.Reply("go"); 355 discovery_started.Reply("go");
355 ExtensionTestMessageListener discovery_stopped("ready", true); 356 ExtensionTestMessageListener discovery_stopped("ready", true);
356 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied()); 357 EXPECT_TRUE(discovery_stopped.WaitUntilSatisfied());
357 358
358 // This should never be received. 359 // This should never be received.
359 event_router()->DeviceAdded(mock_adapter_, device2_.get()); 360 event_router()->DeviceAdded(mock_adapter_, device2_.get());
360 discovery_stopped.Reply("go"); 361 discovery_stopped.Reply("go");
361 362
362 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 363 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
364 CloseShellWindowsAndWaitForAppToExit();
363 } 365 }
364 366
365 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) { 367 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Events) {
366 ResultCatcher catcher; 368 ResultCatcher catcher;
367 catcher.RestrictToProfile(browser()->profile()); 369 catcher.RestrictToProfile(browser()->profile());
368 370
369 // Load and wait for setup 371 // Load and wait for setup
370 ExtensionTestMessageListener listener("ready", true); 372 ExtensionTestMessageListener listener("ready", true);
371 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bluetooth/events"))); 373 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("bluetooth/events")));
372 EXPECT_TRUE(listener.WaitUntilSatisfied()); 374 EXPECT_TRUE(listener.WaitUntilSatisfied());
373 375
374 event_router()->AdapterPoweredChanged(mock_adapter_, true); 376 event_router()->AdapterPoweredChanged(mock_adapter_, true);
375 event_router()->AdapterPoweredChanged(mock_adapter_, false); 377 event_router()->AdapterPoweredChanged(mock_adapter_, false);
376 event_router()->AdapterPresentChanged(mock_adapter_, true); 378 event_router()->AdapterPresentChanged(mock_adapter_, true);
377 event_router()->AdapterPresentChanged(mock_adapter_, false); 379 event_router()->AdapterPresentChanged(mock_adapter_, false);
378 event_router()->AdapterDiscoveringChanged(mock_adapter_, true); 380 event_router()->AdapterDiscoveringChanged(mock_adapter_, true);
379 event_router()->AdapterDiscoveringChanged(mock_adapter_, false); 381 event_router()->AdapterDiscoveringChanged(mock_adapter_, false);
380 382
381 listener.Reply("go"); 383 listener.Reply("go");
382 384
383 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 385 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
386 CloseShellWindowsAndWaitForAppToExit();
384 } 387 }
385 388
386 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { 389 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) {
387 ResultCatcher catcher; 390 ResultCatcher catcher;
388 catcher.RestrictToProfile(browser()->profile()); 391 catcher.RestrictToProfile(browser()->profile());
389 392
390 BluetoothAdapter::ConstDeviceList devices; 393 BluetoothAdapter::ConstDeviceList devices;
391 devices.push_back(device1_.get()); 394 devices.push_back(device1_.get());
392 devices.push_back(device2_.get()); 395 devices.push_back(device2_.get());
393 396
(...skipping 13 matching lines...) Expand all
407 410
408 // Load and wait for setup 411 // Load and wait for setup
409 ExtensionTestMessageListener listener("ready", true); 412 ExtensionTestMessageListener listener("ready", true);
410 ASSERT_TRUE( 413 ASSERT_TRUE(
411 LoadExtension(test_data_dir_.AppendASCII("bluetooth/get_devices"))); 414 LoadExtension(test_data_dir_.AppendASCII("bluetooth/get_devices")));
412 EXPECT_TRUE(listener.WaitUntilSatisfied()); 415 EXPECT_TRUE(listener.WaitUntilSatisfied());
413 416
414 listener.Reply("go"); 417 listener.Reply("go");
415 418
416 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 419 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
420 CloseShellWindowsAndWaitForAppToExit();
417 } 421 }
418 422
419 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) { 423 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) {
420 ResultCatcher catcher; 424 ResultCatcher catcher;
421 catcher.RestrictToProfile(browser()->profile()); 425 catcher.RestrictToProfile(browser()->profile());
422 426
423 BluetoothAdapter::ConstDeviceList devices; 427 BluetoothAdapter::ConstDeviceList devices;
424 devices.push_back(device1_.get()); 428 devices.push_back(device1_.get());
425 429
426 // Save the callback to delay execution so that we can force the calls to 430 // Save the callback to delay execution so that we can force the calls to
427 // happen concurrently. This will be called after the listener is satisfied. 431 // happen concurrently. This will be called after the listener is satisfied.
428 BluetoothDevice::ProvidesServiceCallback callback; 432 BluetoothDevice::ProvidesServiceCallback* callback =
433 new BluetoothDevice::ProvidesServiceCallback;
429 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) 434 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_))
430 .WillOnce(testing::SaveArg<1>(&callback)); 435 .WillOnce(testing::SaveArg<1>(callback));
431 436
432 EXPECT_CALL(*mock_adapter_, GetDevices()) 437 EXPECT_CALL(*mock_adapter_, GetDevices())
433 .WillOnce(testing::Return(devices)); 438 .WillOnce(testing::Return(devices));
434 439
435 // Load and wait for setup 440 // Load and wait for setup
436 ExtensionTestMessageListener listener("ready", true); 441 ExtensionTestMessageListener listener("ready", true);
437 ASSERT_TRUE(LoadExtension( 442 ASSERT_TRUE(LoadExtension(
438 test_data_dir_.AppendASCII("bluetooth/get_devices_concurrently"))); 443 test_data_dir_.AppendASCII("bluetooth/get_devices_concurrently")));
439 EXPECT_TRUE(listener.WaitUntilSatisfied()); 444 EXPECT_TRUE(listener.WaitUntilSatisfied());
440 445
441 callback.Run(false); 446 callback->Run(false);
447 delete callback;
442 listener.Reply("go"); 448 listener.Reply("go");
443 449
444 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 450 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
451 CloseShellWindowsAndWaitForAppToExit();
445 } 452 }
446 453
447 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesError) { 454 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesError) {
448 ResultCatcher catcher; 455 ResultCatcher catcher;
449 catcher.RestrictToProfile(browser()->profile()); 456 catcher.RestrictToProfile(browser()->profile());
450 457
451 // Load and wait for setup 458 // Load and wait for setup
452 ExtensionTestMessageListener listener("ready", true); 459 ExtensionTestMessageListener listener("ready", true);
453 ASSERT_TRUE(LoadExtension( 460 ASSERT_TRUE(LoadExtension(
454 test_data_dir_.AppendASCII("bluetooth/get_devices_error"))); 461 test_data_dir_.AppendASCII("bluetooth/get_devices_error")));
455 EXPECT_TRUE(listener.WaitUntilSatisfied()); 462 EXPECT_TRUE(listener.WaitUntilSatisfied());
456 463
457 listener.Reply("go"); 464 listener.Reply("go");
458 465
459 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 466 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
467 CloseShellWindowsAndWaitForAppToExit();
460 } 468 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/app_window/app_window_apitest.cc ('k') | chrome/browser/extensions/api/dns/dns_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698