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

Side by Side Diff: device/bluetooth/bluetooth_adapter_unittest.cc

Issue 1412023002: bluetooth: mac: Only test Low Energy discovery sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@btm-key-strings-
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "device/bluetooth/bluetooth_adapter.h" 8 #include "device/bluetooth/bluetooth_adapter.h"
9 #include "device/bluetooth/bluetooth_device.h" 9 #include "device/bluetooth/bluetooth_device.h"
10 #include "device/bluetooth/bluetooth_discovery_session.h" 10 #include "device/bluetooth/bluetooth_discovery_session.h"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 450 }
451 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 451 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
452 452
453 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms. 453 // TODO(scheib): Enable BluetoothTest fixture tests on all platforms.
454 #if defined(OS_ANDROID) 454 #if defined(OS_ANDROID)
455 // Starts and Stops a discovery session. 455 // Starts and Stops a discovery session.
456 TEST_F(BluetoothTest, DiscoverySession) { 456 TEST_F(BluetoothTest, DiscoverySession) {
457 InitWithFakeAdapter(); 457 InitWithFakeAdapter();
458 EXPECT_FALSE(adapter_->IsDiscovering()); 458 EXPECT_FALSE(adapter_->IsDiscovering());
459 459
460 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 460 StartLowEnergyDiscoverySession();
461 GetErrorCallback());
462 EXPECT_EQ(1, callback_count_); 461 EXPECT_EQ(1, callback_count_);
463 EXPECT_EQ(0, error_callback_count_); 462 EXPECT_EQ(0, error_callback_count_);
464 EXPECT_TRUE(adapter_->IsDiscovering()); 463 EXPECT_TRUE(adapter_->IsDiscovering());
465 ASSERT_EQ((size_t)1, discovery_sessions_.size()); 464 ASSERT_EQ((size_t)1, discovery_sessions_.size());
466 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); 465 EXPECT_TRUE(discovery_sessions_[0]->IsActive());
467 466
468 ResetEventCounts(); 467 ResetEventCounts();
469 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); 468 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback());
470 EXPECT_EQ(1, callback_count_); 469 EXPECT_EQ(1, callback_count_);
471 EXPECT_EQ(0, error_callback_count_); 470 EXPECT_EQ(0, error_callback_count_);
472 EXPECT_FALSE(adapter_->IsDiscovering()); 471 EXPECT_FALSE(adapter_->IsDiscovering());
473 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); 472 EXPECT_FALSE(discovery_sessions_[0]->IsActive());
474 } 473 }
475 #endif // defined(OS_ANDROID) 474 #endif // defined(OS_ANDROID)
476 475
477 #if defined(OS_ANDROID) || defined(OS_MACOSX) 476 #if defined(OS_ANDROID) || defined(OS_MACOSX)
478 // Discovers a device. 477 // Discovers a device.
479 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) { 478 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) {
480 if (!PlatformSupportsLowEnergy()) { 479 if (!PlatformSupportsLowEnergy()) {
481 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 480 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
482 return; 481 return;
483 } 482 }
484 InitWithFakeAdapter(); 483 InitWithFakeAdapter();
485 TestBluetoothAdapterObserver observer(adapter_); 484 TestBluetoothAdapterObserver observer(adapter_);
486 485
487 // Start discovery and find a device. 486 // Start discovery and find a device.
488 scoped_ptr<BluetoothDiscoveryFilter> discovery_filter( 487 StartLowEnergyDiscoverySession();
489 new BluetoothDiscoveryFilter(
490 BluetoothDiscoveryFilter::Transport::TRANSPORT_LE));
491 adapter_->StartDiscoverySessionWithFilter(discovery_filter.Pass(),
492 GetDiscoverySessionCallback(),
493 GetErrorCallback());
494 DiscoverLowEnergyDevice(1); 488 DiscoverLowEnergyDevice(1);
495 EXPECT_EQ(1, observer.device_added_count()); 489 EXPECT_EQ(1, observer.device_added_count());
496 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 490 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
497 EXPECT_TRUE(device); 491 EXPECT_TRUE(device);
498 } 492 }
499 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 493 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
500 494
501 #if defined(OS_ANDROID) || defined(OS_MACOSX) 495 #if defined(OS_ANDROID) || defined(OS_MACOSX)
502 // Discovers the same device multiple times. 496 // Discovers the same device multiple times.
503 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) { 497 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceTwice) {
504 if (!PlatformSupportsLowEnergy()) { 498 if (!PlatformSupportsLowEnergy()) {
505 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 499 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
506 return; 500 return;
507 } 501 }
508 InitWithFakeAdapter(); 502 InitWithFakeAdapter();
509 TestBluetoothAdapterObserver observer(adapter_); 503 TestBluetoothAdapterObserver observer(adapter_);
510 504
511 // Start discovery and find a device. 505 // Start discovery and find a device.
512 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 506 StartLowEnergyDiscoverySession();
513 GetErrorCallback());
514 DiscoverLowEnergyDevice(1); 507 DiscoverLowEnergyDevice(1);
515 EXPECT_EQ(1, observer.device_added_count()); 508 EXPECT_EQ(1, observer.device_added_count());
516 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address()); 509 BluetoothDevice* device = adapter_->GetDevice(observer.last_device_address());
517 EXPECT_TRUE(device); 510 EXPECT_TRUE(device);
518 511
519 // Find the same device again. This should not create a new device object. 512 // Find the same device again. This should not create a new device object.
520 observer.Reset(); 513 observer.Reset();
521 DiscoverLowEnergyDevice(1); 514 DiscoverLowEnergyDevice(1);
522 base::RunLoop().RunUntilIdle(); 515 base::RunLoop().RunUntilIdle();
523 EXPECT_EQ(0, observer.device_added_count()); 516 EXPECT_EQ(0, observer.device_added_count());
524 EXPECT_EQ(1u, adapter_->GetDevices().size()); 517 EXPECT_EQ(1u, adapter_->GetDevices().size());
525 } 518 }
526 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 519 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
527 520
528 #if defined(OS_ANDROID) || defined(OS_MACOSX) 521 #if defined(OS_ANDROID) || defined(OS_MACOSX)
529 // Discovers a device, and then again with new Service UUIDs. 522 // Discovers a device, and then again with new Service UUIDs.
530 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) { 523 TEST_F(BluetoothTest, DiscoverLowEnergyDeviceWithUpdatedUUIDs) {
531 if (!PlatformSupportsLowEnergy()) { 524 if (!PlatformSupportsLowEnergy()) {
532 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 525 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
533 return; 526 return;
534 } 527 }
535 InitWithFakeAdapter(); 528 InitWithFakeAdapter();
536 TestBluetoothAdapterObserver observer(adapter_); 529 TestBluetoothAdapterObserver observer(adapter_);
537 530
538 // Start discovery and find a device. 531 // Start discovery and find a device.
539 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 532 StartLowEnergyDiscoverySession();
540 GetErrorCallback());
541 BluetoothDevice* device = DiscoverLowEnergyDevice(1); 533 BluetoothDevice* device = DiscoverLowEnergyDevice(1);
542 534
543 // Check the initial UUIDs: 535 // Check the initial UUIDs:
544 EXPECT_TRUE( 536 EXPECT_TRUE(
545 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess))); 537 ContainsValue(device->GetUUIDs(), BluetoothUUID(kTestUUIDGenericAccess)));
546 EXPECT_FALSE(ContainsValue(device->GetUUIDs(), 538 EXPECT_FALSE(ContainsValue(device->GetUUIDs(),
547 BluetoothUUID(kTestUUIDImmediateAlert))); 539 BluetoothUUID(kTestUUIDImmediateAlert)));
548 540
549 // Discover same device again with updated UUIDs: 541 // Discover same device again with updated UUIDs:
550 observer.Reset(); 542 observer.Reset();
(...skipping 26 matching lines...) Expand all
577 // Discovers multiple devices when addresses vary. 569 // Discovers multiple devices when addresses vary.
578 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) { 570 TEST_F(BluetoothTest, DiscoverMultipleLowEnergyDevices) {
579 if (!PlatformSupportsLowEnergy()) { 571 if (!PlatformSupportsLowEnergy()) {
580 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 572 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
581 return; 573 return;
582 } 574 }
583 InitWithFakeAdapter(); 575 InitWithFakeAdapter();
584 TestBluetoothAdapterObserver observer(adapter_); 576 TestBluetoothAdapterObserver observer(adapter_);
585 577
586 // Start discovery and find a device. 578 // Start discovery and find a device.
587 adapter_->StartDiscoverySession(GetDiscoverySessionCallback(), 579 StartLowEnergyDiscoverySession();
588 GetErrorCallback());
589 DiscoverLowEnergyDevice(1); 580 DiscoverLowEnergyDevice(1);
590 DiscoverLowEnergyDevice(4); 581 DiscoverLowEnergyDevice(4);
591 EXPECT_EQ(2, observer.device_added_count()); 582 EXPECT_EQ(2, observer.device_added_count());
592 EXPECT_EQ(2u, adapter_->GetDevices().size()); 583 EXPECT_EQ(2u, adapter_->GetDevices().size());
593 } 584 }
594 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 585 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
595 586
596 } // namespace device 587 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/bluetooth_device_unittest.cc » ('j') | device/bluetooth/test/bluetooth_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698