Chromium Code Reviews| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 // Tests that the Advertisement Data fields are correctly updated during | 126 // Tests that the Advertisement Data fields are correctly updated during |
| 127 // discovery. | 127 // discovery. |
| 128 TEST_F(BluetoothTest, AdvertisementData_Discovery) { | 128 TEST_F(BluetoothTest, AdvertisementData_Discovery) { |
| 129 if (!PlatformSupportsLowEnergy()) { | 129 if (!PlatformSupportsLowEnergy()) { |
| 130 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 130 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 InitWithFakeAdapter(); | 133 InitWithFakeAdapter(); |
| 134 TestBluetoothAdapterObserver observer(adapter_); | 134 TestBluetoothAdapterObserver observer(adapter_); |
| 135 | 135 |
| 136 // Start Discovery Session and receive Advertisement. No DeviceChanged event | 136 // Start Discovery Session and receive Advertisement, should |
| 137 // because the device is new. | 137 // not notify of device changed because the device is new. |
| 138 // - GetInquiryRSSI: Should return the packet's rssi. | |
| 138 // - GetUUIDs: Should return Advertised UUIDs. | 139 // - GetUUIDs: Should return Advertised UUIDs. |
| 139 // - GetServiceData: Should return advertised Service Data. | 140 // - GetServiceData: Should return advertised Service Data. |
| 141 // - GetInquiryTxPower: Should return the packet's advertised Tx Power. | |
| 140 StartLowEnergyDiscoverySession(); | 142 StartLowEnergyDiscoverySession(); |
| 141 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 143 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 142 | 144 |
| 143 EXPECT_EQ(0, observer.device_changed_count()); | 145 EXPECT_EQ(0, observer.device_changed_count()); |
| 146 | |
| 147 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 148 | |
| 144 EXPECT_EQ(2u, device->GetUUIDs().size()); | 149 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 150 | |
| 145 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 151 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 146 BluetoothUUID(kTestUUIDGenericAccess))); | 152 BluetoothUUID(kTestUUIDGenericAccess))); |
| 147 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 153 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 148 BluetoothUUID(kTestUUIDGenericAttribute))); | 154 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 149 | 155 |
| 150 #if defined(OS_MACOSX) | 156 #if defined(OS_MACOSX) |
| 151 // TODO(ortuno): Enable on Android once it supports Service Data. | 157 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 152 // http://crbug.com/639408 | 158 // http://crbug.com/639408 |
| 153 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 159 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 154 device->GetServiceData()); | 160 device->GetServiceData()); |
| 155 | 161 |
| 156 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 162 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 157 device->GetServiceDataUUIDs()); | 163 device->GetServiceDataUUIDs()); |
| 158 | 164 |
| 159 EXPECT_EQ(std::vector<uint8_t>({1}), | 165 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 160 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 166 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 161 #endif // defined(OS_MACOSX) | 167 #endif // defined(OS_MACOSX) |
| 162 | 168 |
| 163 // Receive Advertisement with no UUIDs or Service Data, should notify | 169 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); |
| 164 // device changed. | 170 |
| 171 // Receive Advertisement with no UUIDs, Service Data, or Tx Power, should | |
| 172 // notify device changed. | |
| 173 // - GetInquiryRSSI: Should return packet's rssi. | |
| 165 // - GetUUIDs: Should return no UUIDs. | 174 // - GetUUIDs: Should return no UUIDs. |
| 166 // - GetServiceData: Should return empty map. | 175 // - GetServiceData: Should return empty map. |
| 176 // - GetInquiryTxPower: Should return nullopt because of no Tx Power. | |
| 167 SimulateLowEnergyDevice(3); | 177 SimulateLowEnergyDevice(3); |
| 168 EXPECT_EQ(1, observer.device_changed_count()); | 178 EXPECT_EQ(1, observer.device_changed_count()); |
| 179 | |
| 180 EXPECT_EQ(kTestRSSI3, device->GetInquiryRSSI().value()); | |
| 181 | |
| 169 EXPECT_EQ(0u, device->GetUUIDs().size()); | 182 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 170 | |
| 171 #if defined(OS_MACOSX) | 183 #if defined(OS_MACOSX) |
| 172 // TODO(ortuno): Enable on Android once it supports Service Data. | 184 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 173 // http://crbug.com/639408 | 185 // http://crbug.com/639408 |
| 174 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 186 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 175 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 187 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 176 EXPECT_EQ(nullptr, | 188 EXPECT_EQ(nullptr, |
| 177 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 189 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 178 #endif // defined(OS_MACOSX) | 190 #endif // defined(OS_MACOSX) |
| 179 | 191 |
| 180 // Receive Advertisement with different UUIDs and Service Data, should notify | 192 EXPECT_FALSE(!!device->GetInquiryTxPower()); |
|
Jeffrey Yasskin
2016/08/24 04:32:02
Does just EXPECT_FALSE(device->GetInquiryTxPower()
ortuno
2016/08/24 21:29:09
Done.
| |
| 181 // device changed. | 193 |
| 194 // Receive Advertisement with different UUIDs, Service Data, and Tx Power, | |
| 195 // should notify device changed. | |
| 196 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 182 // - GetUUIDs: Should return latest Advertised UUIDs. | 197 // - GetUUIDs: Should return latest Advertised UUIDs. |
| 183 // - GetServiceData: Should return last advertised Service Data. | 198 // - GetServiceData: Should return last advertised Service Data. |
| 199 // - GetInquiryTxPower: Should return last advertised Tx Power. | |
| 184 SimulateLowEnergyDevice(2); | 200 SimulateLowEnergyDevice(2); |
| 185 EXPECT_EQ(2, observer.device_changed_count()); | 201 EXPECT_EQ(2, observer.device_changed_count()); |
| 202 | |
| 203 EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value()); | |
| 204 | |
| 186 EXPECT_EQ(2u, device->GetUUIDs().size()); | 205 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 206 | |
| 187 EXPECT_FALSE(base::ContainsKey(device->GetUUIDs(), | 207 EXPECT_FALSE(base::ContainsKey(device->GetUUIDs(), |
| 188 BluetoothUUID(kTestUUIDGenericAccess))); | 208 BluetoothUUID(kTestUUIDGenericAccess))); |
| 189 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 209 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 190 BluetoothUUID(kTestUUIDImmediateAlert))); | 210 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 191 | 211 |
| 192 #if defined(OS_MACOSX) | 212 #if defined(OS_MACOSX) |
| 193 // TODO(ortuno): Enable on Android once it supports Service Data. | 213 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 194 // http://crbug.com/639408 | 214 // http://crbug.com/639408 |
| 195 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, | 215 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, |
| 196 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), | 216 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), |
| 197 device->GetServiceData()); | 217 device->GetServiceData()); |
| 198 | 218 |
| 199 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), | 219 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), |
| 200 BluetoothUUID(kTestUUIDImmediateAlert)}), | 220 BluetoothUUID(kTestUUIDImmediateAlert)}), |
| 201 device->GetServiceDataUUIDs()); | 221 device->GetServiceDataUUIDs()); |
| 202 | 222 |
| 203 EXPECT_EQ(std::vector<uint8_t>({2}), | 223 EXPECT_EQ(std::vector<uint8_t>({2}), |
| 204 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 224 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 205 EXPECT_EQ( | 225 EXPECT_EQ( |
| 206 std::vector<uint8_t>({0}), | 226 std::vector<uint8_t>({0}), |
| 207 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); | 227 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); |
| 208 #endif // defined(OS_MACOSX) | 228 #endif // defined(OS_MACOSX) |
| 209 | 229 |
| 230 EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value()); | |
| 231 | |
| 210 // Stop discovery session, should notify of device changed. | 232 // Stop discovery session, should notify of device changed. |
| 233 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 234 // discovering. | |
| 211 // - GetUUIDs: Should not return any UUIDs. | 235 // - GetUUIDs: Should not return any UUIDs. |
| 212 // - GetServiceData: Should return empty map. | 236 // - GetServiceData: Should return empty map. |
| 237 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 238 // discovering. | |
| 213 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), | 239 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 214 GetErrorCallback(Call::NOT_EXPECTED)); | 240 GetErrorCallback(Call::NOT_EXPECTED)); |
| 215 ASSERT_FALSE(adapter_->IsDiscovering()); | 241 ASSERT_FALSE(adapter_->IsDiscovering()); |
| 216 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 242 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
| 217 | 243 |
| 218 EXPECT_EQ(3, observer.device_changed_count()); | 244 EXPECT_EQ(3, observer.device_changed_count()); |
| 245 | |
| 246 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 247 | |
| 219 EXPECT_EQ(0u, device->GetUUIDs().size()); | 248 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 220 | 249 |
| 221 #if defined(OS_MACOSX) | 250 #if defined(OS_MACOSX) |
| 222 // TODO(ortuno): Enable on Android once it supports Service Data. | 251 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 223 // http://crbug.com/639408 | 252 // http://crbug.com/639408 |
| 224 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 253 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 225 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 254 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 226 EXPECT_EQ(nullptr, | 255 EXPECT_EQ(nullptr, |
| 227 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 256 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 228 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( | 257 EXPECT_EQ(nullptr, device->GetServiceDataForUUID( |
| 229 BluetoothUUID(kTestUUIDImmediateAlert))); | 258 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 230 #endif // defined(OS_MACOSX) | 259 #endif // defined(OS_MACOSX) |
| 231 | 260 |
| 261 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 262 | |
| 232 // Discover the device again with different UUIDs, should notify of device | 263 // Discover the device again with different UUIDs, should notify of device |
| 233 // changed. | 264 // changed. |
| 265 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 234 // - GetUUIDs: Should return only the latest Advertised UUIDs. | 266 // - GetUUIDs: Should return only the latest Advertised UUIDs. |
| 235 // - GetServiceData: Should return last advertise Service Data. | 267 // - GetServiceData: Should return last advertise Service Data. |
| 268 // - GetInquiryTxPower: Should return last advertised Tx Power. | |
| 236 StartLowEnergyDiscoverySession(); | 269 StartLowEnergyDiscoverySession(); |
| 237 device = SimulateLowEnergyDevice(1); | 270 device = SimulateLowEnergyDevice(1); |
| 238 | 271 |
| 239 EXPECT_EQ(4, observer.device_changed_count()); | 272 EXPECT_EQ(4, observer.device_changed_count()); |
| 273 | |
| 274 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 275 | |
| 240 EXPECT_EQ(2u, device->GetUUIDs().size()); | 276 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 277 | |
| 241 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 278 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 242 BluetoothUUID(kTestUUIDGenericAccess))); | 279 BluetoothUUID(kTestUUIDGenericAccess))); |
| 243 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 280 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 244 BluetoothUUID(kTestUUIDGenericAttribute))); | 281 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 245 | 282 |
| 246 #if defined(OS_MACOSX) | 283 #if defined(OS_MACOSX) |
| 247 // TODO(ortuno): Enable on Android once it supports Service Data. | 284 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 248 // http://crbug.com/639408 | 285 // http://crbug.com/639408 |
| 249 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 286 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 250 device->GetServiceData()); | 287 device->GetServiceData()); |
| 251 | 288 |
| 252 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 289 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 253 device->GetServiceDataUUIDs()); | 290 device->GetServiceDataUUIDs()); |
| 254 | 291 |
| 255 EXPECT_EQ(std::vector<uint8_t>({1}), | 292 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 256 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 293 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 257 #endif // defined(OS_MACOSX) | 294 #endif // defined(OS_MACOSX) |
| 295 | |
| 296 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); | |
| 258 } | 297 } |
| 259 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 298 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 260 | 299 |
| 261 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 300 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 262 // Tests Advertisement Data is updated correctly during a connection. | 301 // Tests Advertisement Data is updated correctly during a connection. |
| 263 TEST_F(BluetoothTest, GetUUIDs_Connection) { | 302 TEST_F(BluetoothTest, GetUUIDs_Connection) { |
| 264 if (!PlatformSupportsLowEnergy()) { | 303 if (!PlatformSupportsLowEnergy()) { |
| 265 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 304 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 266 return; | 305 return; |
| 267 } | 306 } |
| 268 | 307 |
| 269 InitWithFakeAdapter(); | 308 InitWithFakeAdapter(); |
| 270 TestBluetoothAdapterObserver observer(adapter_); | 309 TestBluetoothAdapterObserver observer(adapter_); |
| 271 | 310 |
| 272 StartLowEnergyDiscoverySession(); | 311 StartLowEnergyDiscoverySession(); |
| 273 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 312 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 274 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), | 313 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 275 GetErrorCallback(Call::NOT_EXPECTED)); | 314 GetErrorCallback(Call::NOT_EXPECTED)); |
| 276 | 315 |
| 277 // Connect to the device. | 316 // Connect to the device. |
| 317 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 318 // discovering. | |
| 278 // - GetUUIDs: Should return no UUIDs because Services have not been | 319 // - GetUUIDs: Should return no UUIDs because Services have not been |
| 279 // discovered. | 320 // discovered. |
| 280 // - GetServiceData: Should return empty map because we are no longer | 321 // - GetServiceData: Should return empty map because we are no longer |
| 281 // discovering. | 322 // discovering. |
| 323 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 324 // discovering. | |
| 282 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 325 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 283 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 326 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 284 SimulateGattConnection(device); | 327 SimulateGattConnection(device); |
| 285 ASSERT_TRUE(device->IsConnected()); | 328 ASSERT_TRUE(device->IsConnected()); |
| 286 | 329 |
| 330 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 331 | |
| 287 EXPECT_EQ(0u, device->GetUUIDs().size()); | 332 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 333 | |
| 288 #if defined(OS_MACOSX) | 334 #if defined(OS_MACOSX) |
| 289 // TODO(ortuno): Enable on Android once it supports Service Data. | 335 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 290 // http://crbug.com/639408 | 336 // http://crbug.com/639408 |
| 291 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 337 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 292 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 338 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 293 #endif // defined(OS_MACOSX) | 339 #endif // defined(OS_MACOSX) |
| 294 | 340 |
| 341 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 342 | |
| 295 observer.Reset(); | 343 observer.Reset(); |
| 296 | 344 |
| 297 // Discover services, should notify of device changed. | 345 // Discover services, should notify of device changed. |
| 346 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 347 // discovering. | |
| 298 // - GetUUIDs: Should return the device's services' UUIDs. | 348 // - GetUUIDs: Should return the device's services' UUIDs. |
| 299 // - GetServiceData: Should return empty map. | 349 // - GetServiceData: Should return empty map. |
| 350 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 351 // discovering. | |
| 300 std::vector<std::string> services; | 352 std::vector<std::string> services; |
| 301 services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value()); | 353 services.push_back(BluetoothUUID(kTestUUIDGenericAccess).canonical_value()); |
| 302 SimulateGattServicesDiscovered(device, services); | 354 SimulateGattServicesDiscovered(device, services); |
| 303 | 355 |
| 304 EXPECT_EQ(1, observer.device_changed_count()); | 356 EXPECT_EQ(1, observer.device_changed_count()); |
| 357 | |
| 358 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 359 | |
| 305 EXPECT_EQ(1u, device->GetUUIDs().size()); | 360 EXPECT_EQ(1u, device->GetUUIDs().size()); |
| 306 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 361 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 307 BluetoothUUID(kTestUUIDGenericAccess))); | 362 BluetoothUUID(kTestUUIDGenericAccess))); |
| 308 | 363 |
| 309 #if defined(OS_MACOSX) | 364 #if defined(OS_MACOSX) |
| 310 // TODO(ortuno): Enable on Android once it supports Service Data. | 365 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 311 // http://crbug.com/639408 | 366 // http://crbug.com/639408 |
| 312 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 367 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 313 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 368 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 314 #endif // defined(OS_MACOSX) | 369 #endif // defined(OS_MACOSX) |
| 315 | 370 |
| 371 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 372 | |
| 316 #if defined(OS_MACOSX) | 373 #if defined(OS_MACOSX) |
| 317 // TODO(ortuno): Enable in Android and Windows. | 374 // TODO(ortuno): Enable in Android and Windows. |
| 318 // Android and Windows don't yet support service changed events. | 375 // Android and Windows don't yet support service changed events. |
| 319 // http://crbug.com/548280 | 376 // http://crbug.com/548280 |
| 320 // http://crbug.com/579202 | 377 // http://crbug.com/579202 |
| 321 | 378 |
| 322 observer.Reset(); | 379 observer.Reset(); |
| 323 | 380 |
| 324 // Notify of services changed, should notify of device changed. | 381 // Notify of services changed, should notify of device changed. |
| 382 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 383 // discovering. | |
| 325 // - GetUUIDs: Should return no UUIDs because we no longer know what services | 384 // - GetUUIDs: Should return no UUIDs because we no longer know what services |
| 326 // the device has. | 385 // the device has. |
| 327 // - GetServiceData: Should return empty map. | 386 // - GetServiceData: Should return empty map. |
| 387 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 388 // discovering. | |
| 328 | 389 |
| 329 SimulateGattServicesChanged(device); | 390 SimulateGattServicesChanged(device); |
| 330 | 391 |
| 331 ASSERT_FALSE(device->IsGattServicesDiscoveryComplete()); | 392 ASSERT_FALSE(device->IsGattServicesDiscoveryComplete()); |
| 332 EXPECT_EQ(1, observer.device_changed_count()); | 393 EXPECT_EQ(1, observer.device_changed_count()); |
| 394 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 333 EXPECT_EQ(0u, device->GetUUIDs().size()); | 395 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 334 | |
| 335 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 396 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 336 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 397 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 398 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 337 | 399 |
| 338 // Services discovered again, should notify of device changed. | 400 // Services discovered again, should notify of device changed. |
| 401 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 402 // discovering. | |
| 339 // - GetUUIDs: Should return Service UUIDs. | 403 // - GetUUIDs: Should return Service UUIDs. |
| 340 // - GetServiceData: Should return empty map. | 404 // - GetServiceData: Should return empty map. |
| 405 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 406 // discovering. | |
| 341 SimulateGattServicesDiscovered(device, {} /* services */); | 407 SimulateGattServicesDiscovered(device, {} /* services */); |
| 342 | 408 |
| 343 EXPECT_EQ(2, observer.device_changed_count()); | 409 EXPECT_EQ(2, observer.device_changed_count()); |
| 410 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 344 EXPECT_EQ(1u, device->GetUUIDs().size()); | 411 EXPECT_EQ(1u, device->GetUUIDs().size()); |
| 345 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 412 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 346 BluetoothUUID(kTestUUIDGenericAccess))); | 413 BluetoothUUID(kTestUUIDGenericAccess))); |
| 347 | 414 |
| 348 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 415 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 349 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 416 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 417 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 418 | |
| 350 #endif // defined(OS_MACOSX) | 419 #endif // defined(OS_MACOSX) |
| 351 | 420 |
| 352 observer.Reset(); | 421 observer.Reset(); |
| 353 | 422 |
| 354 // Disconnect, should notify device changed. | 423 // Disconnect, should notify device changed. |
| 424 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 425 // discovering. | |
| 355 // - GetUUIDs: Should return no UUIDs since we no longer know what services | 426 // - GetUUIDs: Should return no UUIDs since we no longer know what services |
| 356 // the device holds and notify of device changed. | 427 // the device holds and notify of device changed. |
| 357 // - GetServiceData: Should return empty map. | 428 // - GetServiceData: Should return empty map. |
| 429 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 430 // discovering. | |
| 358 gatt_connections_[0]->Disconnect(); | 431 gatt_connections_[0]->Disconnect(); |
| 359 SimulateGattDisconnection(device); | 432 SimulateGattDisconnection(device); |
| 360 ASSERT_FALSE(device->IsGattConnected()); | 433 ASSERT_FALSE(device->IsGattConnected()); |
| 361 | 434 |
| 435 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 362 EXPECT_EQ(1, observer.device_changed_count()); | 436 EXPECT_EQ(1, observer.device_changed_count()); |
| 363 EXPECT_EQ(0u, device->GetUUIDs().size()); | 437 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 364 | 438 |
| 365 #if defined(OS_MACOSX) | 439 #if defined(OS_MACOSX) |
| 366 // TODO(ortuno): Enable on Android once it supports Service Data. | 440 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 367 // http://crbug.com/639408 | 441 // http://crbug.com/639408 |
| 368 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 442 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 369 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 443 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 370 #endif // defined(OS_MACOSX) | 444 #endif // defined(OS_MACOSX) |
| 445 | |
| 446 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 371 } | 447 } |
| 372 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 448 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 373 | 449 |
| 374 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 450 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 375 // Tests Advertisement Data is updated correctly when we start discovery | 451 // Tests Advertisement Data is updated correctly when we start discovery |
| 376 // during a connection. | 452 // during a connection. |
| 377 TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) { | 453 TEST_F(BluetoothTest, GetUUIDs_DiscoveryDuringConnection) { |
| 378 if (!PlatformSupportsLowEnergy()) { | 454 if (!PlatformSupportsLowEnergy()) { |
| 379 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 455 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 380 return; | 456 return; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 401 // Connect. | 477 // Connect. |
| 402 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 478 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 403 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 479 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 404 SimulateGattConnection(device); | 480 SimulateGattConnection(device); |
| 405 ASSERT_TRUE(device->IsConnected()); | 481 ASSERT_TRUE(device->IsConnected()); |
| 406 | 482 |
| 407 observer.Reset(); | 483 observer.Reset(); |
| 408 | 484 |
| 409 // Start Discovery and receive advertisement during connection, | 485 // Start Discovery and receive advertisement during connection, |
| 410 // should notify of device changed. | 486 // should notify of device changed. |
| 487 // - GetInquiryRSSI: Should return the packet's rssi. | |
| 411 // - GetUUIDs: Should return only Advertised UUIDs since services haven't | 488 // - GetUUIDs: Should return only Advertised UUIDs since services haven't |
| 412 // been discovered yet. | 489 // been discovered yet. |
| 413 // - GetServiceData: Should return last advertised Service Data. | 490 // - GetServiceData: Should return last advertised Service Data. |
| 491 // - GetInquiryTxPower: Should return the packet's advertised Tx Power. | |
| 414 StartLowEnergyDiscoverySession(); | 492 StartLowEnergyDiscoverySession(); |
| 415 ASSERT_TRUE(adapter_->IsDiscovering()); | 493 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 416 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 494 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 417 device = SimulateLowEnergyDevice(1); | 495 device = SimulateLowEnergyDevice(1); |
| 418 | 496 |
| 419 EXPECT_EQ(1, observer.device_changed_count()); | 497 EXPECT_EQ(1, observer.device_changed_count()); |
| 498 | |
| 499 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 500 | |
| 420 EXPECT_EQ(2u, device->GetUUIDs().size()); | 501 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 502 | |
| 421 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 503 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 422 BluetoothUUID(kTestUUIDGenericAccess))); | 504 BluetoothUUID(kTestUUIDGenericAccess))); |
| 423 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 505 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 424 BluetoothUUID(kTestUUIDGenericAttribute))); | 506 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 425 | 507 |
| 426 #if defined(OS_MACOSX) | 508 #if defined(OS_MACOSX) |
| 427 // TODO(ortuno): Enable on Android once it supports Service Data. | 509 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 428 // http://crbug.com/639408 | 510 // http://crbug.com/639408 |
| 429 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 511 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 430 device->GetServiceData()); | 512 device->GetServiceData()); |
| 431 | 513 |
| 432 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 514 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 433 device->GetServiceDataUUIDs()); | 515 device->GetServiceDataUUIDs()); |
| 434 | 516 |
| 435 EXPECT_EQ(std::vector<uint8_t>({1}), | 517 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 436 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 518 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 437 #endif // defined(OS_MACOSX) | 519 #endif // defined(OS_MACOSX) |
| 438 | 520 |
| 521 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); | |
| 522 | |
| 439 // Discover services, should notify of device changed. | 523 // Discover services, should notify of device changed. |
| 524 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 440 // - GetUUIDs: Should return both Advertised UUIDs and Service UUIDs. | 525 // - GetUUIDs: Should return both Advertised UUIDs and Service UUIDs. |
| 441 // - GetServiceData: Should return same data as before since there was | 526 // - GetServiceData: Should return same data as before since there was |
| 442 // no new advertised data. | 527 // no new advertised data. |
| 528 // - GetInquiryTxPower: Should return the last packet's advertised Tx Power. | |
| 443 std::vector<std::string> services; | 529 std::vector<std::string> services; |
| 444 services.push_back(BluetoothUUID(kTestUUIDHeartRate).canonical_value()); | 530 services.push_back(BluetoothUUID(kTestUUIDHeartRate).canonical_value()); |
| 445 SimulateGattServicesDiscovered(device, services); | 531 SimulateGattServicesDiscovered(device, services); |
| 446 | 532 |
| 447 EXPECT_EQ(2, observer.device_changed_count()); | 533 EXPECT_EQ(2, observer.device_changed_count()); |
| 534 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 448 EXPECT_EQ(3u, device->GetUUIDs().size()); | 535 EXPECT_EQ(3u, device->GetUUIDs().size()); |
| 449 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 536 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 450 BluetoothUUID(kTestUUIDGenericAccess))); | 537 BluetoothUUID(kTestUUIDGenericAccess))); |
| 451 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 538 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 452 BluetoothUUID(kTestUUIDGenericAttribute))); | 539 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 453 EXPECT_TRUE( | 540 EXPECT_TRUE( |
| 454 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); | 541 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); |
| 455 | 542 |
| 456 #if defined(OS_MACOSX) | 543 #if defined(OS_MACOSX) |
| 457 // TODO(ortuno): Enable on Android once it supports Service Data. | 544 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 458 // http://crbug.com/639408 | 545 // http://crbug.com/639408 |
| 459 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 546 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 460 device->GetServiceData()); | 547 device->GetServiceData()); |
| 461 | 548 |
| 462 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 549 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 463 device->GetServiceDataUUIDs()); | 550 device->GetServiceDataUUIDs()); |
| 464 | 551 |
| 465 EXPECT_EQ(std::vector<uint8_t>({1}), | 552 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 466 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 553 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 467 #endif // defined(OS_MACOSX) | 554 #endif // defined(OS_MACOSX) |
| 555 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); | |
| 468 | 556 |
| 469 // Receive advertisement again, notify of device changed. | 557 // Receive advertisement again, notify of device changed. |
| 558 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 470 // - GetUUIDs: Should return only new Advertised UUIDs and Service UUIDs. | 559 // - GetUUIDs: Should return only new Advertised UUIDs and Service UUIDs. |
| 471 // - GetServiceData: Should return last advertised Service Data. | 560 // - GetServiceData: Should return last advertised Service Data. |
| 561 // - GetInquiryTxPower: Should return the last packet's advertised Tx Power. | |
| 472 device = SimulateLowEnergyDevice(2); | 562 device = SimulateLowEnergyDevice(2); |
| 473 | 563 |
| 474 EXPECT_EQ(3, observer.device_changed_count()); | 564 EXPECT_EQ(3, observer.device_changed_count()); |
| 475 EXPECT_EQ(3u, device->GetUUIDs().size()); | 565 EXPECT_EQ(3u, device->GetUUIDs().size()); |
| 566 EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value()); | |
| 476 EXPECT_TRUE( | 567 EXPECT_TRUE( |
| 477 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); | 568 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); |
| 478 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 569 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 479 BluetoothUUID(kTestUUIDImmediateAlert))); | 570 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 480 EXPECT_TRUE( | 571 EXPECT_TRUE( |
| 481 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); | 572 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); |
| 573 EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value()); | |
| 482 | 574 |
| 483 // Stop discovery session, should notify of device changed. | 575 // Stop discovery session, should notify of device changed. |
| 576 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 577 // discovering. | |
| 484 // - GetUUIDs: Should only return Service UUIDs. | 578 // - GetUUIDs: Should only return Service UUIDs. |
| 485 // - GetServiceData: Should return an empty map since we are no longer | 579 // - GetServiceData: Should return an empty map since we are no longer |
| 486 // discovering. | 580 // discovering. |
| 581 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 582 // discovering. | |
| 487 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), | 583 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 488 GetErrorCallback(Call::NOT_EXPECTED)); | 584 GetErrorCallback(Call::NOT_EXPECTED)); |
| 489 ASSERT_FALSE(adapter_->IsDiscovering()); | 585 ASSERT_FALSE(adapter_->IsDiscovering()); |
| 490 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); | 586 ASSERT_FALSE(discovery_sessions_[0]->IsActive()); |
| 491 | 587 |
| 492 EXPECT_EQ(4, observer.device_changed_count()); | 588 EXPECT_EQ(4, observer.device_changed_count()); |
| 589 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 493 EXPECT_EQ(1u, device->GetUUIDs().size()); | 590 EXPECT_EQ(1u, device->GetUUIDs().size()); |
| 494 EXPECT_TRUE( | 591 EXPECT_TRUE( |
| 495 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); | 592 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); |
| 496 | 593 |
| 497 #if defined(OS_MACOSX) | 594 #if defined(OS_MACOSX) |
| 498 // TODO(ortuno): Enable on Android once it supports Service Data. | 595 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 499 // http://crbug.com/639408 | 596 // http://crbug.com/639408 |
| 500 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 597 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 501 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 598 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 502 #endif // defined(OS_MACOSX) | 599 #endif // defined(OS_MACOSX) |
| 600 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 503 | 601 |
| 504 // Disconnect device, should notify of device changed. | 602 // Disconnect device, should notify of device changed. |
| 603 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 604 // discovering. | |
| 505 // - GetUUIDs: Should return no UUIDs. | 605 // - GetUUIDs: Should return no UUIDs. |
| 506 // - GetServiceData: Should still return an empty map. | 606 // - GetServiceData: Should still return an empty map. |
| 607 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 608 // discovering. | |
| 507 gatt_connections_[0]->Disconnect(); | 609 gatt_connections_[0]->Disconnect(); |
| 508 SimulateGattDisconnection(device); | 610 SimulateGattDisconnection(device); |
| 509 ASSERT_FALSE(device->IsGattConnected()); | 611 ASSERT_FALSE(device->IsGattConnected()); |
| 510 | 612 |
| 511 EXPECT_EQ(5, observer.device_changed_count()); | 613 EXPECT_EQ(5, observer.device_changed_count()); |
| 614 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 512 EXPECT_EQ(0u, device->GetUUIDs().size()); | 615 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 513 | 616 |
| 514 #if defined(OS_MACOSX) | 617 #if defined(OS_MACOSX) |
| 515 // TODO(ortuno): Enable on Android once it supports Service Data. | 618 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 516 // http://crbug.com/639408 | 619 // http://crbug.com/639408 |
| 517 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 620 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 518 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 621 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 519 #endif // defined(OS_MACOSX) | 622 #endif // defined(OS_MACOSX) |
| 623 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 520 } | 624 } |
| 521 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 625 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 522 | 626 |
| 523 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 627 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 524 TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) { | 628 TEST_F(BluetoothTest, AdvertisementData_ConnectionDuringDiscovery) { |
| 525 // Tests that the Advertisement Data is correctly updated when | 629 // Tests that the Advertisement Data is correctly updated when |
| 526 // the device connects during discovery. | 630 // the device connects during discovery. |
| 527 if (!PlatformSupportsLowEnergy()) { | 631 if (!PlatformSupportsLowEnergy()) { |
| 528 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 632 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 529 return; | 633 return; |
| 530 } | 634 } |
| 531 | 635 |
| 532 InitWithFakeAdapter(); | 636 InitWithFakeAdapter(); |
| 533 TestBluetoothAdapterObserver observer(adapter_); | 637 TestBluetoothAdapterObserver observer(adapter_); |
| 534 | 638 |
| 535 // Start discovery session and receive and advertisement. No device changed | 639 // Start discovery session and receive and advertisement. No device changed |
| 536 // notification because it's a new device. | 640 // notification because it's a new device. |
| 641 // - GetInquiryRSSI: Should return the packet's rssi. | |
|
Jeffrey Yasskin
2016/08/24 04:32:02
A some point in these tests, you've verified that
ortuno
2016/08/24 21:29:09
I've removed checks where checking advertisement d
| |
| 537 // - GetUUIDs: Should return Advertised UUIDs. | 642 // - GetUUIDs: Should return Advertised UUIDs. |
| 538 // - GetServiceData: Should return advertised Service Data. | 643 // - GetServiceData: Should return advertised Service Data. |
| 644 // - GetInquiryTxPower: Should return the packet's advertised Tx Power. | |
| 539 StartLowEnergyDiscoverySession(); | 645 StartLowEnergyDiscoverySession(); |
| 540 ASSERT_TRUE(adapter_->IsDiscovering()); | 646 ASSERT_TRUE(adapter_->IsDiscovering()); |
| 541 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); | 647 ASSERT_TRUE(discovery_sessions_[0]->IsActive()); |
| 542 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 648 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
| 543 | 649 |
| 544 EXPECT_EQ(0, observer.device_changed_count()); | 650 EXPECT_EQ(0, observer.device_changed_count()); |
| 651 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 545 EXPECT_EQ(2u, device->GetUUIDs().size()); | 652 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 546 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 653 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 547 BluetoothUUID(kTestUUIDGenericAccess))); | 654 BluetoothUUID(kTestUUIDGenericAccess))); |
| 548 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 655 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 549 BluetoothUUID(kTestUUIDGenericAttribute))); | 656 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 550 | 657 |
| 551 #if defined(OS_MACOSX) | 658 #if defined(OS_MACOSX) |
| 552 // TODO(ortuno): Enable on Android once it supports Service Data. | 659 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 553 // http://crbug.com/639408 | 660 // http://crbug.com/639408 |
| 554 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 661 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 555 device->GetServiceData()); | 662 device->GetServiceData()); |
| 556 | 663 |
| 557 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 664 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 558 device->GetServiceDataUUIDs()); | 665 device->GetServiceDataUUIDs()); |
| 559 | 666 |
| 560 EXPECT_EQ(std::vector<uint8_t>({1}), | 667 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 561 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 668 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 562 #endif // defined(OS_MACOSX) | 669 #endif // defined(OS_MACOSX) |
| 563 | 670 |
| 671 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); | |
| 672 | |
| 564 // Connect, should notify of device changed. | 673 // Connect, should notify of device changed. |
| 674 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 565 // - GetUUIDs: Should return Advertised UUIDs even before GATT Discovery. | 675 // - GetUUIDs: Should return Advertised UUIDs even before GATT Discovery. |
| 566 // - GetServiceData: Should still return the same Service Data. | 676 // - GetServiceData: Should still return the same Service Data. |
| 677 // - GetInquiryTxPower: Should return the last packet's advertised Tx Power. | |
| 567 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 678 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 568 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 679 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 569 SimulateGattConnection(device); | 680 SimulateGattConnection(device); |
| 570 ASSERT_TRUE(device->IsConnected()); | 681 ASSERT_TRUE(device->IsConnected()); |
| 571 | 682 |
| 572 observer.Reset(); | 683 observer.Reset(); |
| 573 EXPECT_EQ(2u, device->GetUUIDs().size()); | 684 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 685 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 574 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 686 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 575 BluetoothUUID(kTestUUIDGenericAccess))); | 687 BluetoothUUID(kTestUUIDGenericAccess))); |
| 576 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 688 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 577 BluetoothUUID(kTestUUIDGenericAttribute))); | 689 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 578 | 690 |
| 579 #if defined(OS_MACOSX) | 691 #if defined(OS_MACOSX) |
| 580 // TODO(ortuno): Enable on Android once it supports Service Data. | 692 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 581 // http://crbug.com/639408 | 693 // http://crbug.com/639408 |
| 582 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 694 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 583 device->GetServiceData()); | 695 device->GetServiceData()); |
| 584 | 696 |
| 585 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 697 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 586 device->GetServiceDataUUIDs()); | 698 device->GetServiceDataUUIDs()); |
| 587 | 699 |
| 588 EXPECT_EQ(std::vector<uint8_t>({1}), | 700 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 589 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 701 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 590 #endif // defined(OS_MACOSX) | 702 #endif // defined(OS_MACOSX) |
| 591 | 703 |
| 704 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); | |
| 705 | |
| 592 // Receive Advertisement with new UUIDs, should notify of device changed. | 706 // Receive Advertisement with new UUIDs, should notify of device changed. |
| 707 // - GetInquiryRSSI: Should return the packet's rssi. | |
| 593 // - GetUUIDs: Should return new Advertised UUIDs. | 708 // - GetUUIDs: Should return new Advertised UUIDs. |
| 594 // - GetServiceData: Should return new advertised Service Data. | 709 // - GetServiceData: Should return new advertised Service Data. |
| 710 // - GetInquiryTxPower: Should return the packet's advertised Tx Power. | |
| 595 device = SimulateLowEnergyDevice(2); | 711 device = SimulateLowEnergyDevice(2); |
| 596 | 712 |
| 597 EXPECT_EQ(1, observer.device_changed_count()); | 713 EXPECT_EQ(1, observer.device_changed_count()); |
| 714 EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value()); | |
| 598 EXPECT_EQ(2u, device->GetUUIDs().size()); | 715 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 599 EXPECT_TRUE( | 716 EXPECT_TRUE( |
| 600 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); | 717 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); |
| 601 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 718 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 602 BluetoothUUID(kTestUUIDImmediateAlert))); | 719 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 603 | 720 |
| 604 #if defined(OS_MACOSX) | 721 #if defined(OS_MACOSX) |
| 605 // TODO(ortuno): Enable on Android once it supports Service Data. | 722 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 606 // http://crbug.com/639408 | 723 // http://crbug.com/639408 |
| 607 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, | 724 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, |
| 608 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), | 725 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), |
| 609 device->GetServiceData()); | 726 device->GetServiceData()); |
| 610 | 727 |
| 611 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), | 728 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), |
| 612 BluetoothUUID(kTestUUIDImmediateAlert)}), | 729 BluetoothUUID(kTestUUIDImmediateAlert)}), |
| 613 device->GetServiceDataUUIDs()); | 730 device->GetServiceDataUUIDs()); |
| 614 | 731 |
| 615 EXPECT_EQ(std::vector<uint8_t>({2}), | 732 EXPECT_EQ(std::vector<uint8_t>({2}), |
| 616 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 733 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 617 EXPECT_EQ( | 734 EXPECT_EQ( |
| 618 std::vector<uint8_t>({0}), | 735 std::vector<uint8_t>({0}), |
| 619 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); | 736 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); |
| 620 #endif // defined(OS_MACOSX) | 737 #endif // defined(OS_MACOSX) |
| 738 EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value()); | |
| 621 | 739 |
| 622 // Discover Service, should notify of device changed. | 740 // Discover Service, should notify of device changed. |
| 741 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 623 // - GetUUIDs: Should return Advertised UUIDs and Service UUIDs. | 742 // - GetUUIDs: Should return Advertised UUIDs and Service UUIDs. |
| 624 // - GetServiceData: Should return same advertised Service Data. | 743 // - GetServiceData: Should return same advertised Service Data. |
| 744 // - GetInquiryTxPower: Should return the last packet's advertised Tx Power. | |
| 625 std::vector<std::string> services; | 745 std::vector<std::string> services; |
| 626 services.push_back(BluetoothUUID(kTestUUIDHeartRate).canonical_value()); | 746 services.push_back(BluetoothUUID(kTestUUIDHeartRate).canonical_value()); |
| 627 SimulateGattServicesDiscovered(device, services); | 747 SimulateGattServicesDiscovered(device, services); |
| 628 | 748 |
| 629 EXPECT_EQ(2, observer.device_changed_count()); | 749 EXPECT_EQ(2, observer.device_changed_count()); |
| 750 EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value()); | |
| 630 EXPECT_EQ(3u, device->GetUUIDs().size()); | 751 EXPECT_EQ(3u, device->GetUUIDs().size()); |
| 631 EXPECT_TRUE( | 752 EXPECT_TRUE( |
| 632 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); | 753 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); |
| 633 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 754 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 634 BluetoothUUID(kTestUUIDImmediateAlert))); | 755 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 635 EXPECT_TRUE( | 756 EXPECT_TRUE( |
| 636 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); | 757 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDHeartRate))); |
| 637 | 758 |
| 638 #if defined(OS_MACOSX) | 759 #if defined(OS_MACOSX) |
| 639 // TODO(ortuno): Enable on Android once it supports Service Data. | 760 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 640 // http://crbug.com/639408 | 761 // http://crbug.com/639408 |
| 641 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, | 762 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, |
| 642 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), | 763 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), |
| 643 device->GetServiceData()); | 764 device->GetServiceData()); |
| 644 | 765 |
| 645 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), | 766 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), |
| 646 BluetoothUUID(kTestUUIDImmediateAlert)}), | 767 BluetoothUUID(kTestUUIDImmediateAlert)}), |
| 647 device->GetServiceDataUUIDs()); | 768 device->GetServiceDataUUIDs()); |
| 648 | 769 |
| 649 EXPECT_EQ(std::vector<uint8_t>({2}), | 770 EXPECT_EQ(std::vector<uint8_t>({2}), |
| 650 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 771 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 651 EXPECT_EQ( | 772 EXPECT_EQ( |
| 652 std::vector<uint8_t>({0}), | 773 std::vector<uint8_t>({0}), |
| 653 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); | 774 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); |
| 654 #endif // defined(OS_MACOSX) | 775 #endif // defined(OS_MACOSX) |
| 655 | 776 |
| 777 EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value()); | |
| 778 | |
| 656 // Disconnect, should notify of device changed. | 779 // Disconnect, should notify of device changed. |
| 780 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 657 // - GetUUIDs: Should return only Advertised UUIDs. | 781 // - GetUUIDs: Should return only Advertised UUIDs. |
| 658 // - GetServiceData: Should still return same advertised Service Data. | 782 // - GetServiceData: Should still return same advertised Service Data. |
| 783 // - GetInquiryTxPower: Should return the last packet's advertised Tx Power. | |
| 659 gatt_connections_[0]->Disconnect(); | 784 gatt_connections_[0]->Disconnect(); |
| 660 SimulateGattDisconnection(device); | 785 SimulateGattDisconnection(device); |
| 661 ASSERT_FALSE(device->IsGattConnected()); | 786 ASSERT_FALSE(device->IsGattConnected()); |
| 662 | 787 |
| 663 EXPECT_EQ(3, observer.device_changed_count()); | 788 EXPECT_EQ(3, observer.device_changed_count()); |
| 789 EXPECT_EQ(kTestRSSI2, device->GetInquiryRSSI().value()); | |
| 664 EXPECT_EQ(2u, device->GetUUIDs().size()); | 790 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 665 EXPECT_TRUE( | 791 EXPECT_TRUE( |
| 666 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); | 792 base::ContainsKey(device->GetUUIDs(), BluetoothUUID(kTestUUIDLinkLoss))); |
| 667 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 793 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 668 BluetoothUUID(kTestUUIDImmediateAlert))); | 794 BluetoothUUID(kTestUUIDImmediateAlert))); |
| 669 | 795 |
| 670 #if defined(OS_MACOSX) | 796 #if defined(OS_MACOSX) |
| 671 // TODO(ortuno): Enable on Android once it supports Service Data. | 797 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 672 // http://crbug.com/639408 | 798 // http://crbug.com/639408 |
| 673 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, | 799 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {2}}, |
| 674 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), | 800 {BluetoothUUID(kTestUUIDImmediateAlert), {0}}}), |
| 675 device->GetServiceData()); | 801 device->GetServiceData()); |
| 676 | 802 |
| 677 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), | 803 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate), |
| 678 BluetoothUUID(kTestUUIDImmediateAlert)}), | 804 BluetoothUUID(kTestUUIDImmediateAlert)}), |
| 679 device->GetServiceDataUUIDs()); | 805 device->GetServiceDataUUIDs()); |
| 680 | 806 |
| 681 EXPECT_EQ(std::vector<uint8_t>({2}), | 807 EXPECT_EQ(std::vector<uint8_t>({2}), |
| 682 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 808 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 683 EXPECT_EQ( | 809 EXPECT_EQ( |
| 684 std::vector<uint8_t>({0}), | 810 std::vector<uint8_t>({0}), |
| 685 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); | 811 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDImmediateAlert))); |
| 686 #endif // defined(OS_MACOSX) | 812 #endif // defined(OS_MACOSX) |
| 687 | 813 |
| 814 EXPECT_EQ(kTestTxPower2, device->GetInquiryTxPower().value()); | |
| 815 | |
| 688 // Receive Advertisement with new UUIDs, should notify of device changed. | 816 // Receive Advertisement with new UUIDs, should notify of device changed. |
| 817 // - GetInquiryRSSI: Should return last packet's rssi. | |
| 689 // - GetUUIDs: Should return only new Advertised UUIDs. | 818 // - GetUUIDs: Should return only new Advertised UUIDs. |
| 690 // - GetServiceData: Should return only new advertised Service Data. | 819 // - GetServiceData: Should return only new advertised Service Data. |
| 820 // - GetInquiryTxPower: Should return the last packet's advertised Tx Power. | |
| 691 device = SimulateLowEnergyDevice(1); | 821 device = SimulateLowEnergyDevice(1); |
| 692 | 822 |
| 693 EXPECT_EQ(4, observer.device_changed_count()); | 823 EXPECT_EQ(4, observer.device_changed_count()); |
| 824 EXPECT_EQ(kTestRSSI1, device->GetInquiryRSSI().value()); | |
| 694 EXPECT_EQ(2u, device->GetUUIDs().size()); | 825 EXPECT_EQ(2u, device->GetUUIDs().size()); |
| 695 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 826 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 696 BluetoothUUID(kTestUUIDGenericAccess))); | 827 BluetoothUUID(kTestUUIDGenericAccess))); |
| 697 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), | 828 EXPECT_TRUE(base::ContainsKey(device->GetUUIDs(), |
| 698 BluetoothUUID(kTestUUIDGenericAttribute))); | 829 BluetoothUUID(kTestUUIDGenericAttribute))); |
| 699 | 830 |
| 700 #if defined(OS_MACOSX) | 831 #if defined(OS_MACOSX) |
| 701 // TODO(ortuno): Enable on Android once it supports Service Data. | 832 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 702 // http://crbug.com/639408 | 833 // http://crbug.com/639408 |
| 703 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), | 834 EXPECT_EQ(ServiceDataMap({{BluetoothUUID(kTestUUIDHeartRate), {1}}}), |
| 704 device->GetServiceData()); | 835 device->GetServiceData()); |
| 705 | 836 |
| 706 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), | 837 EXPECT_EQ(UUIDSet({BluetoothUUID(kTestUUIDHeartRate)}), |
| 707 device->GetServiceDataUUIDs()); | 838 device->GetServiceDataUUIDs()); |
| 708 | 839 |
| 709 EXPECT_EQ(std::vector<uint8_t>({1}), | 840 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 710 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 841 *device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 711 #endif // defined(OS_MACOSX) | 842 #endif // defined(OS_MACOSX) |
| 712 | 843 |
| 844 EXPECT_EQ(kTestTxPower1, device->GetInquiryTxPower().value()); | |
| 845 | |
| 713 // Stop discovery session, should notify of device changed. | 846 // Stop discovery session, should notify of device changed. |
| 847 // - GetInquiryRSSI: Should return nullopt because we are no longer | |
| 848 // discovering. | |
| 714 // - GetUUIDs: Should return no UUIDs. | 849 // - GetUUIDs: Should return no UUIDs. |
| 715 // - GetServiceData: Should return no UUIDs since we are no longer | 850 // - GetServiceData: Should return no UUIDs since we are no longer |
| 716 // discovering. | 851 // discovering. |
| 852 // - GetInquiryTxPower: Should return nullopt because we are no longer | |
| 853 // discovering. | |
| 717 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), | 854 discovery_sessions_[0]->Stop(GetCallback(Call::EXPECTED), |
| 718 GetErrorCallback(Call::NOT_EXPECTED)); | 855 GetErrorCallback(Call::NOT_EXPECTED)); |
| 719 EXPECT_EQ(5, observer.device_changed_count()); | 856 EXPECT_EQ(5, observer.device_changed_count()); |
| 857 EXPECT_FALSE(!!device->GetInquiryRSSI()); | |
| 720 EXPECT_EQ(0u, device->GetUUIDs().size()); | 858 EXPECT_EQ(0u, device->GetUUIDs().size()); |
| 721 | 859 |
| 722 #if defined(OS_MACOSX) | 860 #if defined(OS_MACOSX) |
| 723 // TODO(ortuno): Enable on Android once it supports Service Data. | 861 // TODO(ortuno): Enable on Android once it supports Service Data. |
| 724 // http://crbug.com/639408 | 862 // http://crbug.com/639408 |
| 725 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); | 863 EXPECT_EQ(ServiceDataMap(), device->GetServiceData()); |
| 726 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); | 864 EXPECT_EQ(UUIDSet(), device->GetServiceDataUUIDs()); |
| 727 EXPECT_EQ(nullptr, | 865 EXPECT_EQ(nullptr, |
| 728 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); | 866 device->GetServiceDataForUUID(BluetoothUUID(kTestUUIDHeartRate))); |
| 729 #endif // defined(OS_MACOSX) | 867 #endif // defined(OS_MACOSX) |
| 868 EXPECT_FALSE(!!device->GetInquiryTxPower()); | |
| 730 } | 869 } |
| 731 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 870 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 732 | 871 |
| 733 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 872 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 734 // GetName for Device with no name. | 873 // GetName for Device with no name. |
| 735 TEST_F(BluetoothTest, GetName_NullName) { | 874 TEST_F(BluetoothTest, GetName_NullName) { |
| 736 if (!PlatformSupportsLowEnergy()) { | 875 if (!PlatformSupportsLowEnergy()) { |
| 737 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 876 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
| 738 return; | 877 return; |
| 739 } | 878 } |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 | 1518 |
| 1380 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); | 1519 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); |
| 1381 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); | 1520 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); |
| 1382 | 1521 |
| 1383 BluetoothDevice* device3 = SimulateClassicDevice(); | 1522 BluetoothDevice* device3 = SimulateClassicDevice(); |
| 1384 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); | 1523 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); |
| 1385 } | 1524 } |
| 1386 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) | 1525 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) |
| 1387 | 1526 |
| 1388 } // namespace device | 1527 } // namespace device |
| OLD | NEW |