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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 base::RunLoop().RunUntilIdle(); | 427 base::RunLoop().RunUntilIdle(); |
428 ASSERT_FALSE(device->IsGattConnected()); | 428 ASSERT_FALSE(device->IsGattConnected()); |
429 | 429 |
430 EXPECT_EQ(1, observer.device_changed_count()); | 430 EXPECT_EQ(1, observer.device_changed_count()); |
431 EXPECT_TRUE(device->GetUUIDs().empty()); | 431 EXPECT_TRUE(device->GetUUIDs().empty()); |
432 } | 432 } |
433 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 433 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
434 | 434 |
435 #if defined(OS_MACOSX) | 435 #if defined(OS_MACOSX) |
436 // Tests that receiving 2 notifications in a row from macOS that services has | 436 // Tests that receiving 2 notifications in a row from macOS that services has |
437 // changed is handled correctly. Each notification should generate a notfication | 437 // changed is handled correctly. Each notification should generate a |
438 // that the gatt device has changed, and each notification should ask to macOS | 438 // notification that the gatt device has changed, and each notification should |
439 // to scan for services. Only after the second service scan is received, the | 439 // ask to macOS to scan for services. Only after the second service scan is |
440 // device changed notification should be sent and the characteristic discovery | 440 // received, the device changed notification should be sent and the |
441 // procedure should be started. | 441 // characteristic discovery procedure should be started. |
442 // Android: This test doesn't apply to Android because there is no services | 442 // Android: This test doesn't apply to Android because there is no services |
443 // changed event that could arrive during a discovery procedure. | 443 // changed event that could arrive during a discovery procedure. |
444 TEST_F(BluetoothTest, TwoPendingServiceDiscoveryRequests) { | 444 TEST_F(BluetoothTest, TwoPendingServiceDiscoveryRequests) { |
445 if (!PlatformSupportsLowEnergy()) { | 445 if (!PlatformSupportsLowEnergy()) { |
446 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 446 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
447 return; | 447 return; |
448 } | 448 } |
449 | 449 |
450 InitWithFakeAdapter(); | 450 InitWithFakeAdapter(); |
451 TestBluetoothAdapterObserver observer(adapter_); | 451 TestBluetoothAdapterObserver observer(adapter_); |
452 | 452 |
453 BluetoothDevice* device = SimulateLowEnergyDevice(1); | 453 BluetoothDevice* device = SimulateLowEnergyDevice(1); |
454 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 454 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
455 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 455 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
456 SimulateGattConnection(device); | 456 SimulateGattConnection(device); |
457 EXPECT_EQ(1, observer.device_changed_count()); | 457 EXPECT_EQ(1, observer.device_changed_count()); |
458 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); | 458 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); |
459 | 459 |
460 observer.Reset(); | 460 observer.Reset(); |
461 SimulateGattServicesChanged(device); | 461 SimulateGattServicesChanged(device); |
462 EXPECT_EQ(1, observer.device_changed_count()); | 462 EXPECT_EQ(1, observer.device_changed_count()); |
463 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); | 463 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); |
464 | 464 |
465 // Fist system call to | 465 // Fist system call to |
466 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] | 466 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] |
467 observer.Reset(); | 467 observer.Reset(); |
468 SimulateDidDiscoverServices(device, {kTestUUIDHeartRate}); | 468 AddServicesToDevice(device, {kTestUUIDHeartRate}); |
469 SimulateDidDiscoverServices(device); | |
469 EXPECT_EQ(0, observer.device_changed_count()); | 470 EXPECT_EQ(0, observer.device_changed_count()); |
470 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); | 471 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); |
471 EXPECT_EQ(gatt_characteristic_discovery_attempts_, 0); | 472 EXPECT_EQ(gatt_characteristic_discovery_attempts_, 0); |
472 | 473 |
473 // Second system call to | 474 // Second system call to |
474 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] | 475 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] |
475 SimulateGattServicesDiscovered( | 476 SimulateGattServicesDiscovered( |
scheib
2017/04/18 04:43:21
Why does the above use SimulateDidDiscoverServices
jlebel
2017/04/29 22:08:07
Done.
| |
476 device, std::vector<std::string>({kTestUUIDImmediateAlert})); | 477 device, std::vector<std::string>({kTestUUIDImmediateAlert})); |
477 EXPECT_EQ(1, observer.device_changed_count()); | 478 EXPECT_EQ(1, observer.device_changed_count()); |
478 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 479 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
479 // Characteristics are discovered once for each service. | 480 // Characteristics are discovered once for each service. |
480 EXPECT_EQ(gatt_characteristic_discovery_attempts_, 2); | 481 EXPECT_EQ(gatt_characteristic_discovery_attempts_, 2); |
481 | 482 |
482 EXPECT_EQ(2u, device->GetGattServices().size()); | 483 EXPECT_EQ(2u, device->GetGattServices().size()); |
483 } | 484 } |
484 | 485 |
485 // Simulate an unexpected call to -[id<CBPeripheralDelegate> | 486 // Simulate an unexpected call to -[id<CBPeripheralDelegate> |
(...skipping 18 matching lines...) Expand all Loading... | |
504 // Legitimate system call to | 505 // Legitimate system call to |
505 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] | 506 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] |
506 observer.Reset(); | 507 observer.Reset(); |
507 SimulateGattServicesDiscovered( | 508 SimulateGattServicesDiscovered( |
508 device, std::vector<std::string>({kTestUUIDHeartRate})); | 509 device, std::vector<std::string>({kTestUUIDHeartRate})); |
509 EXPECT_EQ(1, observer.device_changed_count()); | 510 EXPECT_EQ(1, observer.device_changed_count()); |
510 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 511 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
511 EXPECT_EQ(gatt_characteristic_discovery_attempts_, 1); | 512 EXPECT_EQ(gatt_characteristic_discovery_attempts_, 1); |
512 EXPECT_EQ(1u, device->GetGattServices().size()); | 513 EXPECT_EQ(1u, device->GetGattServices().size()); |
513 | 514 |
514 // Unexpected system call to | 515 // Unexpected system call to |
scheib
2017/04/18 04:43:21
explain here why another didDiscoverServices is un
jlebel
2017/04/29 22:08:07
Done.
| |
515 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] | 516 // -[id<CBPeripheralDelegate> peripheral:didDiscoverServices:] |
516 SimulateDidDiscoverServices(device, {kTestUUIDImmediateAlert}); | 517 AddServicesToDevice(device, {kTestUUIDImmediateAlert}); |
518 SimulateDidDiscoverServices(device); | |
517 EXPECT_EQ(1, observer.device_changed_count()); | 519 EXPECT_EQ(1, observer.device_changed_count()); |
518 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 520 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
519 | 521 |
520 EXPECT_EQ(1u, device->GetGattServices().size()); | 522 EXPECT_EQ(1u, device->GetGattServices().size()); |
521 } | 523 } |
522 #endif // defined(OS_MACOSX) | 524 #endif // defined(OS_MACOSX) |
523 | 525 |
524 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 526 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
525 // Tests Advertisement Data is updated correctly when we start discovery | 527 // Tests Advertisement Data is updated correctly when we start discovery |
526 // during a connection. | 528 // during a connection. |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1613 .empty()); | 1615 .empty()); |
1614 EXPECT_TRUE(device_ | 1616 EXPECT_TRUE(device_ |
1615 ->GetCharacteristicsByUUID( | 1617 ->GetCharacteristicsByUUID( |
1616 service_instance_id2, | 1618 service_instance_id2, |
1617 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) | 1619 BluetoothUUID(characteristic_uuid_not_exist_in_setup)) |
1618 .empty()); | 1620 .empty()); |
1619 } | 1621 } |
1620 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 1622 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
1621 | 1623 |
1622 } // namespace device | 1624 } // namespace device |
OLD | NEW |