OLD | NEW |
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void RequestPinCode(BluetoothDevice* device) override {} | 132 void RequestPinCode(BluetoothDevice* device) override {} |
133 void RequestPasskey(BluetoothDevice* device) override {} | 133 void RequestPasskey(BluetoothDevice* device) override {} |
134 void DisplayPinCode(BluetoothDevice* device, | 134 void DisplayPinCode(BluetoothDevice* device, |
135 const std::string& pincode) override {} | 135 const std::string& pincode) override {} |
136 void DisplayPasskey(BluetoothDevice* device, uint32 passkey) override {} | 136 void DisplayPasskey(BluetoothDevice* device, uint32 passkey) override {} |
137 void KeysEntered(BluetoothDevice* device, uint32 entered) override {} | 137 void KeysEntered(BluetoothDevice* device, uint32 entered) override {} |
138 void ConfirmPasskey(BluetoothDevice* device, uint32 passkey) override {} | 138 void ConfirmPasskey(BluetoothDevice* device, uint32 passkey) override {} |
139 void AuthorizePairing(BluetoothDevice* device) override {} | 139 void AuthorizePairing(BluetoothDevice* device) override {} |
140 }; | 140 }; |
141 | 141 |
142 | |
143 TEST(BluetoothAdapterTest, NoDefaultPairingDelegate) { | 142 TEST(BluetoothAdapterTest, NoDefaultPairingDelegate) { |
144 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter(); | 143 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter(); |
145 | 144 |
146 // Verify that when there is no registered pairing delegate, NULL is returned. | 145 // Verify that when there is no registered pairing delegate, NULL is returned. |
147 EXPECT_TRUE(adapter->DefaultPairingDelegate() == NULL); | 146 EXPECT_TRUE(adapter->DefaultPairingDelegate() == NULL); |
148 } | 147 } |
149 | 148 |
150 TEST(BluetoothAdapterTest, OneDefaultPairingDelegate) { | 149 TEST(BluetoothAdapterTest, OneDefaultPairingDelegate) { |
151 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter(); | 150 scoped_refptr<BluetoothAdapter> adapter = new TestBluetoothAdapter(); |
152 | 151 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 EXPECT_FALSE(adapter_->IsDiscovering()); | 457 EXPECT_FALSE(adapter_->IsDiscovering()); |
459 | 458 |
460 StartLowEnergyDiscoverySession(); | 459 StartLowEnergyDiscoverySession(); |
461 EXPECT_EQ(1, callback_count_); | 460 EXPECT_EQ(1, callback_count_); |
462 EXPECT_EQ(0, error_callback_count_); | 461 EXPECT_EQ(0, error_callback_count_); |
463 EXPECT_TRUE(adapter_->IsDiscovering()); | 462 EXPECT_TRUE(adapter_->IsDiscovering()); |
464 ASSERT_EQ((size_t)1, discovery_sessions_.size()); | 463 ASSERT_EQ((size_t)1, discovery_sessions_.size()); |
465 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); | 464 EXPECT_TRUE(discovery_sessions_[0]->IsActive()); |
466 | 465 |
467 ResetEventCounts(); | 466 ResetEventCounts(); |
468 discovery_sessions_[0]->Stop(GetCallback(), GetErrorCallback()); | 467 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 468 GetErrorCallback(Call::NOT_EXPECTED)); |
469 EXPECT_EQ(1, callback_count_); | 469 EXPECT_EQ(1, callback_count_); |
470 EXPECT_EQ(0, error_callback_count_); | 470 EXPECT_EQ(0, error_callback_count_); |
471 EXPECT_FALSE(adapter_->IsDiscovering()); | 471 EXPECT_FALSE(adapter_->IsDiscovering()); |
472 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); | 472 EXPECT_FALSE(discovery_sessions_[0]->IsActive()); |
473 } | 473 } |
474 #endif // defined(OS_ANDROID) | 474 #endif // defined(OS_ANDROID) |
475 | 475 |
476 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 476 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
477 // Checks that discovery fails (instead of hanging) when permissions are denied. | 477 // Checks that discovery fails (instead of hanging) when permissions are denied. |
478 TEST_F(BluetoothTest, NoPermissions) { | 478 TEST_F(BluetoothTest, NoPermissions) { |
479 if (!PlatformSupportsLowEnergy()) { | 479 if (!PlatformSupportsLowEnergy()) { |
480 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 480 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
481 return; | 481 return; |
482 } | 482 } |
483 InitWithFakeAdapter(); | 483 InitWithFakeAdapter(); |
484 TestBluetoothAdapterObserver observer(adapter_); | 484 TestBluetoothAdapterObserver observer(adapter_); |
485 | 485 |
486 if (!DenyPermission()) { | 486 if (!DenyPermission()) { |
487 // Platform always gives permission to scan. | 487 // Platform always gives permission to scan. |
488 return; | 488 return; |
489 } | 489 } |
490 | 490 |
491 StartLowEnergyDiscoverySession(); | 491 StartLowEnergyDiscoverySessionExpectedToFail(); |
492 | 492 |
493 EXPECT_EQ(0, callback_count_); | 493 EXPECT_EQ(0, callback_count_); |
494 EXPECT_EQ(1, error_callback_count_); | 494 EXPECT_EQ(1, error_callback_count_); |
495 } | 495 } |
496 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 496 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
497 | 497 |
498 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 498 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
499 // Discovers a device. | 499 // Discovers a device. |
500 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) { | 500 TEST_F(BluetoothTest, DiscoverLowEnergyDevice) { |
501 if (!PlatformSupportsLowEnergy()) { | 501 if (!PlatformSupportsLowEnergy()) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // Start discovery and find a device. | 604 // Start discovery and find a device. |
605 StartLowEnergyDiscoverySession(); | 605 StartLowEnergyDiscoverySession(); |
606 DiscoverLowEnergyDevice(1); | 606 DiscoverLowEnergyDevice(1); |
607 DiscoverLowEnergyDevice(4); | 607 DiscoverLowEnergyDevice(4); |
608 EXPECT_EQ(2, observer.device_added_count()); | 608 EXPECT_EQ(2, observer.device_added_count()); |
609 EXPECT_EQ(2u, adapter_->GetDevices().size()); | 609 EXPECT_EQ(2u, adapter_->GetDevices().size()); |
610 } | 610 } |
611 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 611 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
612 | 612 |
613 } // namespace device | 613 } // namespace device |
OLD | NEW |