| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" | 5 #include "components/proximity_auth/ble/bluetooth_low_energy_characteristics_fin
der.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "components/proximity_auth/ble/remote_attribute.h" | 10 #include "components/proximity_auth/ble/remote_attribute.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 const char kDeviceName[] = "Device name"; | 30 const char kDeviceName[] = "Device name"; |
| 31 const char kBluetoothAddress[] = "11:22:33:44:55:66"; | 31 const char kBluetoothAddress[] = "11:22:33:44:55:66"; |
| 32 | 32 |
| 33 const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF"; | 33 const char kServiceUUID[] = "DEADBEEF-CAFE-FEED-FOOD-D15EA5EBEEEF"; |
| 34 const char kToPeripheralCharUUID[] = "FBAE09F2-0482-11E5-8418-1697F925EC7B"; | 34 const char kToPeripheralCharUUID[] = "FBAE09F2-0482-11E5-8418-1697F925EC7B"; |
| 35 const char kFromPeripheralCharUUID[] = "5539ED10-0483-11E5-8418-1697F925EC7B"; | 35 const char kFromPeripheralCharUUID[] = "5539ED10-0483-11E5-8418-1697F925EC7B"; |
| 36 | 36 |
| 37 const char kToPeripheralCharID[] = "to peripheral id"; | 37 const char kToPeripheralCharID[] = "to peripheral id"; |
| 38 const char kFromPeripheralCharID[] = "from peripheral id"; | 38 const char kFromPeripheralCharID[] = "from peripheral id"; |
| 39 | 39 |
| 40 const device::BluetoothGattCharacteristic::Properties | 40 const device::BluetoothRemoteGattCharacteristic::Properties |
| 41 kCharacteristicProperties = | 41 kCharacteristicProperties = |
| 42 device::BluetoothGattCharacteristic::PROPERTY_BROADCAST | | 42 device::BluetoothRemoteGattCharacteristic::PROPERTY_BROADCAST | |
| 43 device::BluetoothGattCharacteristic::PROPERTY_READ | | 43 device::BluetoothRemoteGattCharacteristic::PROPERTY_READ | |
| 44 device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE | | 44 device::BluetoothRemoteGattCharacteristic:: |
| 45 device::BluetoothGattCharacteristic::PROPERTY_INDICATE; | 45 PROPERTY_WRITE_WITHOUT_RESPONSE | |
| 46 device::BluetoothRemoteGattCharacteristic::PROPERTY_INDICATE; |
| 46 | 47 |
| 47 const char kOtherCharUUID[] = "09731422-048A-11E5-8418-1697F925EC7B"; | 48 const char kOtherCharUUID[] = "09731422-048A-11E5-8418-1697F925EC7B"; |
| 48 const char kOtherCharID[] = "other id"; | 49 const char kOtherCharID[] = "other id"; |
| 49 } // namespace | 50 } // namespace |
| 50 | 51 |
| 51 class ProximityAuthBluetoothLowEnergyCharacteristicFinderTest | 52 class ProximityAuthBluetoothLowEnergyCharacteristicFinderTest |
| 52 : public testing::Test { | 53 : public testing::Test { |
| 53 protected: | 54 protected: |
| 54 ProximityAuthBluetoothLowEnergyCharacteristicFinderTest() | 55 ProximityAuthBluetoothLowEnergyCharacteristicFinderTest() |
| 55 : adapter_(new NiceMock<device::MockBluetoothAdapter>), | 56 : adapter_(new NiceMock<device::MockBluetoothAdapter>), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 75 false)), | 76 false)), |
| 76 remote_service_({device::BluetoothUUID(kServiceUUID), ""}), | 77 remote_service_({device::BluetoothUUID(kServiceUUID), ""}), |
| 77 to_peripheral_char_({device::BluetoothUUID(kToPeripheralCharUUID), ""}), | 78 to_peripheral_char_({device::BluetoothUUID(kToPeripheralCharUUID), ""}), |
| 78 from_peripheral_char_( | 79 from_peripheral_char_( |
| 79 {device::BluetoothUUID(kFromPeripheralCharUUID), ""}) { | 80 {device::BluetoothUUID(kFromPeripheralCharUUID), ""}) { |
| 80 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); | 81 device::BluetoothAdapterFactory::SetAdapterForTesting(adapter_); |
| 81 | 82 |
| 82 // The default behavior for |device_| is to have no services discovered. Can | 83 // The default behavior for |device_| is to have no services discovered. Can |
| 83 // be overrided later. | 84 // be overrided later. |
| 84 ON_CALL(*device_, GetGattServices()) | 85 ON_CALL(*device_, GetGattServices()) |
| 85 .WillByDefault(Return(std::vector<device::BluetoothGattService*>())); | 86 .WillByDefault( |
| 87 Return(std::vector<device::BluetoothRemoteGattService*>())); |
| 86 } | 88 } |
| 87 | 89 |
| 88 void SetUp() { | 90 void SetUp() { |
| 89 EXPECT_CALL(*adapter_, AddObserver(_)); | 91 EXPECT_CALL(*adapter_, AddObserver(_)); |
| 90 EXPECT_CALL(*adapter_, RemoveObserver(_)); | 92 EXPECT_CALL(*adapter_, RemoveObserver(_)); |
| 91 } | 93 } |
| 92 | 94 |
| 93 MOCK_METHOD3(OnCharacteristicsFound, | 95 MOCK_METHOD3(OnCharacteristicsFound, |
| 94 void(const RemoteAttribute&, | 96 void(const RemoteAttribute&, |
| 95 const RemoteAttribute&, | 97 const RemoteAttribute&, |
| 96 const RemoteAttribute&)); | 98 const RemoteAttribute&)); |
| 97 MOCK_METHOD2(OnCharacteristicsFinderError, | 99 MOCK_METHOD2(OnCharacteristicsFinderError, |
| 98 void(const RemoteAttribute&, const RemoteAttribute&)); | 100 void(const RemoteAttribute&, const RemoteAttribute&)); |
| 99 | 101 |
| 100 scoped_ptr<device::MockBluetoothGattCharacteristic> | 102 scoped_ptr<device::MockBluetoothGattCharacteristic> |
| 101 ExpectToFindCharacteristic(const device::BluetoothUUID& uuid, | 103 ExpectToFindCharacteristic(const device::BluetoothUUID& uuid, |
| 102 const std::string& id, | 104 const std::string& id, |
| 103 bool valid) { | 105 bool valid) { |
| 104 scoped_ptr<device::MockBluetoothGattCharacteristic> characteristic( | 106 scoped_ptr<device::MockBluetoothGattCharacteristic> characteristic( |
| 105 new NiceMock<device::MockBluetoothGattCharacteristic>( | 107 new NiceMock<device::MockBluetoothGattCharacteristic>( |
| 106 service_.get(), id, uuid, true, kCharacteristicProperties, | 108 service_.get(), id, uuid, true, kCharacteristicProperties, |
| 107 device::BluetoothGattCharacteristic::PERMISSION_NONE)); | 109 device::BluetoothRemoteGattCharacteristic::PERMISSION_NONE)); |
| 108 | 110 |
| 109 ON_CALL(*characteristic.get(), GetUUID()).WillByDefault(Return(uuid)); | 111 ON_CALL(*characteristic.get(), GetUUID()).WillByDefault(Return(uuid)); |
| 110 if (valid) | 112 if (valid) |
| 111 ON_CALL(*characteristic.get(), GetIdentifier()).WillByDefault(Return(id)); | 113 ON_CALL(*characteristic.get(), GetIdentifier()).WillByDefault(Return(id)); |
| 112 ON_CALL(*characteristic.get(), GetService()) | 114 ON_CALL(*characteristic.get(), GetService()) |
| 113 .WillByDefault(Return(service_.get())); | 115 .WillByDefault(Return(service_.get())); |
| 114 return characteristic; | 116 return characteristic; |
| 115 } | 117 } |
| 116 | 118 |
| 117 scoped_refptr<device::MockBluetoothAdapter> adapter_; | 119 scoped_refptr<device::MockBluetoothAdapter> adapter_; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 EXPECT_CALL(*this, OnCharacteristicsFinderError(_, _)).Times(0); | 260 EXPECT_CALL(*this, OnCharacteristicsFinderError(_, _)).Times(0); |
| 259 | 261 |
| 260 scoped_ptr<device::MockBluetoothGattCharacteristic> from_char = | 262 scoped_ptr<device::MockBluetoothGattCharacteristic> from_char = |
| 261 ExpectToFindCharacteristic(device::BluetoothUUID(kFromPeripheralCharUUID), | 263 ExpectToFindCharacteristic(device::BluetoothUUID(kFromPeripheralCharUUID), |
| 262 kFromPeripheralCharID, true); | 264 kFromPeripheralCharID, true); |
| 263 | 265 |
| 264 scoped_ptr<device::MockBluetoothGattCharacteristic> to_char = | 266 scoped_ptr<device::MockBluetoothGattCharacteristic> to_char = |
| 265 ExpectToFindCharacteristic(device::BluetoothUUID(kToPeripheralCharUUID), | 267 ExpectToFindCharacteristic(device::BluetoothUUID(kToPeripheralCharUUID), |
| 266 kToPeripheralCharID, true); | 268 kToPeripheralCharID, true); |
| 267 | 269 |
| 268 std::vector<device::BluetoothGattService*> services; | 270 std::vector<device::BluetoothRemoteGattService*> services; |
| 269 services.push_back(service_.get()); | 271 services.push_back(service_.get()); |
| 270 ON_CALL(*device_, GetGattServices()).WillByDefault(Return(services)); | 272 ON_CALL(*device_, GetGattServices()).WillByDefault(Return(services)); |
| 271 | 273 |
| 272 std::vector<device::BluetoothGattCharacteristic*> characteristics; | 274 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; |
| 273 characteristics.push_back(from_char.get()); | 275 characteristics.push_back(from_char.get()); |
| 274 characteristics.push_back(to_char.get()); | 276 characteristics.push_back(to_char.get()); |
| 275 ON_CALL(*service_, GetCharacteristics()) | 277 ON_CALL(*service_, GetCharacteristics()) |
| 276 .WillByDefault(Return(characteristics)); | 278 .WillByDefault(Return(characteristics)); |
| 277 | 279 |
| 278 BluetoothLowEnergyCharacteristicsFinder characteristic_finder( | 280 BluetoothLowEnergyCharacteristicsFinder characteristic_finder( |
| 279 adapter_, device_.get(), remote_service_, to_peripheral_char_, | 281 adapter_, device_.get(), remote_service_, to_peripheral_char_, |
| 280 from_peripheral_char_, success_callback_, error_callback_); | 282 from_peripheral_char_, success_callback_, error_callback_); |
| 281 device::BluetoothAdapter::Observer* observer = | 283 device::BluetoothAdapter::Observer* observer = |
| 282 static_cast<device::BluetoothAdapter::Observer*>(&characteristic_finder); | 284 static_cast<device::BluetoothAdapter::Observer*>(&characteristic_finder); |
| 283 | 285 |
| 284 EXPECT_EQ(kToPeripheralCharID, found_to_char.id); | 286 EXPECT_EQ(kToPeripheralCharID, found_to_char.id); |
| 285 EXPECT_EQ(kFromPeripheralCharID, found_from_char.id); | 287 EXPECT_EQ(kFromPeripheralCharID, found_from_char.id); |
| 286 | 288 |
| 287 EXPECT_CALL(*service_, GetUUID()) | 289 EXPECT_CALL(*service_, GetUUID()) |
| 288 .WillOnce(Return(device::BluetoothUUID(kServiceUUID))); | 290 .WillOnce(Return(device::BluetoothUUID(kServiceUUID))); |
| 289 observer->GattDiscoveryCompleteForService(adapter_.get(), service_.get()); | 291 observer->GattDiscoveryCompleteForService(adapter_.get(), service_.get()); |
| 290 } | 292 } |
| 291 | 293 |
| 292 } // namespace proximity_auth | 294 } // namespace proximity_auth |
| OLD | NEW |