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) || defined(OS_LINUX) |
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_MACOSX) | |
ortuno
2017/04/03 02:47:24
#if !defined(OS_LINUX) && !defined(OS_CHROMEOS)
S
xiaoyinh(OOO Sep 11-29)
2017/04/03 21:28:22
Done.
| |
181 // TODO(crbug.com/706043): Remove #if once StartLowEnergyDiscoverySession is | |
182 // implemented for bluez. | |
179 StartLowEnergyDiscoverySession(); | 183 StartLowEnergyDiscoverySession(); |
184 #endif // defined(OS_MACOSX) | |
180 | 185 |
181 // Receive Advertisement with service data. | 186 // Receive Advertisement with service data. |
ortuno
2017/04/03 02:47:24
optional: Could we add a test for when the service
xiaoyinh(OOO Sep 11-29)
2017/04/03 21:28:22
Thanks for the suggestion. I added another device
ortuno
2017/04/03 22:39:34
Looks great. Thanks.
| |
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 SimulateLowEnergyDevice(3); |
193 | 198 |
199 // TODO(crbug.com/707039): Remove #if once the BlueZ caching behavior is | |
200 // changed. | |
201 #if defined(OS_MACOSX) | |
ortuno
2017/04/03 02:47:24
To avoid having this #if for future platforms:
#i
xiaoyinh(OOO Sep 11-29)
2017/04/03 21:28:22
Done.
| |
194 EXPECT_TRUE(device->GetServiceData().empty()); | 202 EXPECT_TRUE(device->GetServiceData().empty()); |
195 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); | 203 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); |
196 EXPECT_EQ(nullptr, | 204 EXPECT_EQ(nullptr, |
197 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 205 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
206 #else | |
207 // On ChromeOS and Linux, BlueZ persists all service data meaning if | |
208 // a device stops advertising service data for a UUID, BlueZ will | |
209 // still return the cached value for that UUID. | |
210 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | |
211 device->GetServiceData()); | |
212 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | |
213 device->GetServiceDataUUIDs()); | |
214 EXPECT_EQ(std::vector<uint8_t>({1}), | |
215 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | |
216 #endif | |
198 | 217 |
199 // Receive Advertisement with new service data. | 218 // Receive Advertisement with new service data. |
200 SimulateLowEnergyDevice(2); | 219 SimulateLowEnergyDevice(2); |
201 | 220 |
202 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, | 221 EXPECT_EQ(ServiceDataMap( |
203 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), | 222 {{BluetoothUUID(kTestUUIDHeartRate), std::vector<uint8_t>({})}, |
223 {BluetoothUUID(kTestUUIDImmediateAlert), {0, 2}}}), | |
204 device->GetServiceData()); | 224 device->GetServiceData()); |
205 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), | 225 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), |
206 BluetoothUUID(kTestUUIDImmediateAlert)}), | 226 BluetoothUUID(kTestUUIDImmediateAlert)}), |
207 device->GetServiceDataUUIDs()); | 227 device->GetServiceDataUUIDs()); |
208 EXPECT_EQ(std::vector<uint8_t>({2}), | 228 EXPECT_EQ(std::vector<uint8_t>({}), |
209 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 229 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
210 EXPECT_EQ( | 230 EXPECT_EQ( |
211 std::vector<uint8_t>({0}), | 231 std::vector<uint8_t>({0, 2}), |
212 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); | 232 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); |
213 | 233 |
234 #if defined(OS_MACOSX) | |
ortuno
2017/04/03 02:47:24
#if !defined(OS_LINUX) && !defined(OS_CHROMEOS)
xiaoyinh(OOO Sep 11-29)
2017/04/03 21:28:22
Done.
| |
235 // TODO(crbug.com/706043): Remove #if once StartLowEnergyDiscoverySession is | |
236 // implemented for bluez. | |
214 // Stop discovery. | 237 // Stop discovery. |
215 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), | 238 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
216 GetErrorCallback(Call::NOT_EXPECTED)); | 239 GetErrorCallback(Call::NOT_EXPECTED)); |
217 ASSERT_FALSE(adapter_->IsDiscovering()); | 240 ASSERT_FALSE(adapter_->IsDiscovering()); |
218 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 241 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
219 | 242 |
220 EXPECT_TRUE(device->GetServiceData().empty()); | 243 EXPECT_TRUE(device->GetServiceData().empty()); |
221 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); | 244 EXPECT_TRUE(device->GetServiceDataUUIDs().empty()); |
222 EXPECT_EQ(nullptr, | 245 EXPECT_EQ(nullptr, |
223 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 246 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
224 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( | 247 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( |
225 BluetoothUUID(kTestUUIDImmediateAlert))); | 248 BluetoothUUID(kTestUUIDImmediateAlert))); |
249 #endif // defined(OS_MACOSX) | |
226 } | 250 } |
227 #endif // defined(OS_MACOSX) | 251 #endif // defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(OS_LINUX) |
228 | 252 |
229 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 253 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
230 // Tests that the Advertisement Data fields are correctly updated during | 254 // Tests that the Advertisement Data fields are correctly updated during |
231 // discovery. | 255 // discovery. |
232 TEST_F(BluetoothTest, AdvertisementData_Discovery) { | 256 TEST_F(BluetoothTest, AdvertisementData_Discovery) { |
233 if (!PlatformSupportsLowEnergy()) { | 257 if (!PlatformSupportsLowEnergy()) { |
234 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 258 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
235 return; | 259 return; |
236 } | 260 } |
237 InitWithFakeAdapter(); | 261 InitWithFakeAdapter(); |
(...skipping 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1613 .empty()); | 1637 .empty()); |
1614 EXPECT_TRUE(device_ | 1638 EXPECT_TRUE(device_ |
1615 ->GetCharacteristicsByUUID( | 1639 ->GetCharacteristicsByUUID( |
1616 service_instance_id2, | 1640 service_instance_id2, |
1617 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) | 1641 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) |
1618 .empty()); | 1642 .empty()); |
1619 } | 1643 } |
1620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1644 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
1621 | 1645 |
1622 } // namespace device | 1646 } // namespace device |
OLD | NEW |