| 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 "device/bluetooth/bluetooth_device.h" | 5 #include "device/bluetooth/bluetooth_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return; | 160 return; |
| 161 } | 161 } |
| 162 InitWithFakeAdapter(); | 162 InitWithFakeAdapter(); |
| 163 StartLowEnergyDiscoverySession(); | 163 StartLowEnergyDiscoverySession(); |
| 164 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 164 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
| 165 ASSERT_TRUE(device); | 165 ASSERT_TRUE(device); |
| 166 UUIDSet uuids = device->GetUUIDs(); | 166 UUIDSet uuids = device->GetUUIDs(); |
| 167 EXPECT_EQ(0u, uuids.size()); | 167 EXPECT_EQ(0u, uuids.size()); |
| 168 } | 168 } |
| 169 | 169 |
| 170 #if defined(OS_MACOSX) | 170 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 171 // TODO(ortuno): Enable on Android once it supports Service Data. | 171 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 172 // http://crbug.com/639408 | 172 // http://crbug.com/639408 |
| 173 TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) { | 173 TEST_F(BluetoothTest, GetServiceDataUUIDs_GetServiceDataForUUID) { |
| 174 if (!PlatformSupportsLowEnergy()) { | 174 if (!PlatformSupportsLowEnergy()) { |
| 175 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 175 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 176 return; | 176 return; |
| 177 } | 177 } |
| 178 InitWithFakeAdapter(); | 178 InitWithFakeAdapter(); |
| 179 |
| 180 #if !defined(OS_CHROMEOS) |
| 181 // StartLowEnergyDiscoverySession is not yet implemented on ChromeOS|bluez. |
| 182 // http://crbug.com/706043 |
| 179 StartLowEnergyDiscoverySession(); | 183 StartLowEnergyDiscoverySession(); |
| 184 #endif |
| 180 | 185 |
| 181 // Receive Advertisement with service data. | 186 // Receive Advertisement with service data. |
| 182 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 187 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 183 | 188 |
| 184 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 189 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 185 device->GetServiceData()); | 190 device->GetServiceData()); |
| 186 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 191 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 187 device->GetServiceDataUUIDs()); | 192 device->GetServiceDataUUIDs()); |
| 188 EXPECT_EQ(std::vector<uint8_t>({1}), | 193 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 189 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 194 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 190 | 195 |
| 191 // Receive Advertisement with no service data. | 196 // Receive Advertisement with no service data. |
| 192 SimulateLowEnergyDevice(3); | 197 device = SimulateLowEnergyDevice(3); |
| 193 | 198 |
| 194 EXPECT_TRUE(device->GetServiceData().empty()); | 199 EXPECT_TRUE(device->GetServiceData().empty()); |
| 195 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); | 200 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); |
| 196 EXPECT_EQ(nullptr, | 201 EXPECT_EQ(nullptr, |
| 197 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 202 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 198 | 203 |
| 199 // Receive Advertisement with new service data. | 204 // Receive Advertisement with new service data. |
| 200 SimulateLowEnergyDevice(2); | 205 device = SimulateLowEnergyDevice(2); |
| 201 | 206 |
| 202 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, | 207 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, |
| 203 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), | 208 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), |
| 204 device->GetServiceData()); | 209 device->GetServiceData()); |
| 205 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), | 210 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), |
| 206 BluetoothUUID(kTestUUIDImmediateAlert)}), | 211 BluetoothUUID(kTestUUIDImmediateAlert)}), |
| 207 device->GetServiceDataUUIDs()); | 212 device->GetServiceDataUUIDs()); |
| 208 EXPECT_EQ(std::vector<uint8_t>({2}), | 213 EXPECT_EQ(std::vector<uint8_t>({2}), |
| 209 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 214 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 210 EXPECT_EQ( | 215 EXPECT_EQ( |
| 211 std::vector<uint8_t>({0}), | 216 std::vector<uint8_t>({0}), |
| 212 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); | 217 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); |
| 213 | 218 |
| 219 #if !defined(OS_CHROMEOS) |
| 214 // Stop discovery. | 220 // Stop discovery. |
| 215 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), | 221 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 216 GetErrorCallback(Call::NOT_EXPECTED)); | 222 GetErrorCallback(Call::NOT_EXPECTED)); |
| 217 ASSERT_FALSE(adapter_->IsDiscovering()); | 223 ASSERT_FALSE(adapter_->IsDiscovering()); |
| 218 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 224 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
| 219 | 225 |
| 220 EXPECT_TRUE(device->GetServiceData().empty()); | 226 EXPECT_TRUE(device->GetServiceData().empty()); |
| 221 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); | 227 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); |
| 222 EXPECT_EQ(nullptr, | 228 EXPECT_EQ(nullptr, |
| 223 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 229 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 224 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( | 230 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( |
| 225 BluetoothUUID(kTestUUIDImmediateAlert))); | 231 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 232 #endif |
| 226 } | 233 } |
| 227 #endif // defined(OS_MACOSX) | 234 #endif // defined(OS_MACOSX) |
| 228 | 235 |
| 229 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 236 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 230 // Tests that the Advertisement Data fields are correctly updated during | 237 // Tests that the Advertisement Data fields are correctly updated during |
| 231 // discovery. | 238 // discovery. |
| 232 TEST_F(BluetoothTest, AdvertisementData_Discovery) { | 239 TEST_F(BluetoothTest, AdvertisementData_Discovery) { |
| 233 if (!PlatformSupportsLowEnergy()) { | 240 if (!PlatformSupportsLowEnergy()) { |
| 234 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 241 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 235 return; | 242 return; |
| (...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 .empty()); | 1620 .empty()); |
| 1614 EXPECT_TRUE(device_ | 1621 EXPECT_TRUE(device_ |
| 1615 ->GetCharacteristicsByUUID( | 1622 ->GetCharacteristicsByUUID( |
| 1616 service_instance_id2, | 1623 service_instance_id2, |
| 1617 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) | 1624 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) |
| 1618 .empty()); | 1625 .empty()); |
| 1619 } | 1626 } |
| 1620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1627 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 1621 | 1628 |
| 1622 } // namespace device | 1629 } // namespace device |
| OLD | NEW |