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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 StartLowEnergyDiscoverySession(); | 465 StartLowEnergyDiscoverySession(); |
466 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 466 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
467 EXPECT_FALSE(device->IsConnected()); | 467 EXPECT_FALSE(device->IsConnected()); |
468 | 468 |
469 // Connect to the device | 469 // Connect to the device |
470 ResetEventCounts(); | 470 ResetEventCounts(); |
471 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 471 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
472 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 472 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
473 TestBluetoothAdapterObserver observer(adapter_); | 473 TestBluetoothAdapterObserver observer(adapter_); |
474 SimulateGattConnection(device); | 474 SimulateGattConnection(device); |
475 EXPECT_EQ(1, observer.device_changed_count()); | |
scheib
2016/05/24 23:34:34
These additions are fine, but I sought a simpler t
Jeffrey Yasskin
2016/05/25 00:08:12
Done.
| |
475 EXPECT_TRUE(device->IsConnected()); | 476 EXPECT_TRUE(device->IsConnected()); |
476 | 477 |
477 // Discover services | 478 // Discover services |
478 std::vector<std::string> services; | 479 std::vector<std::string> services; |
479 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 480 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
480 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | 481 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); |
481 SimulateGattServicesDiscovered(device, services); | 482 SimulateGattServicesDiscovered(device, services); |
482 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 483 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
483 EXPECT_EQ(2u, device->GetGattServices().size()); | 484 EXPECT_EQ(2u, device->GetGattServices().size()); |
484 EXPECT_EQ(1, observer.gatt_services_discovered_count()); | 485 EXPECT_EQ(1, observer.gatt_services_discovered_count()); |
485 | 486 |
486 // Disconnect from the device | 487 // Disconnect from the device |
487 device->DisconnectGatt(); | 488 device->DisconnectGatt(); |
488 SimulateGattDisconnection(device); | 489 SimulateGattDisconnection(device); |
490 EXPECT_EQ(2, observer.device_changed_count()); | |
489 EXPECT_FALSE(device->IsConnected()); | 491 EXPECT_FALSE(device->IsConnected()); |
490 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); | 492 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); |
491 EXPECT_EQ(0u, device->GetGattServices().size()); | 493 EXPECT_EQ(0u, device->GetGattServices().size()); |
492 | 494 |
493 // Verify that the device can be connected to again | 495 // Verify that the device can be connected to again |
494 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 496 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
495 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 497 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
496 SimulateGattConnection(device); | 498 SimulateGattConnection(device); |
499 EXPECT_EQ(3, observer.device_changed_count()); | |
497 EXPECT_TRUE(device->IsConnected()); | 500 EXPECT_TRUE(device->IsConnected()); |
498 | 501 |
499 // Verify that service discovery can be done again | 502 // Verify that service discovery can be done again |
500 std::vector<std::string> services2; | 503 std::vector<std::string> services2; |
501 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); | 504 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); |
502 SimulateGattServicesDiscovered(device, services2); | 505 SimulateGattServicesDiscovered(device, services2); |
503 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 506 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
504 EXPECT_EQ(1u, device->GetGattServices().size()); | 507 EXPECT_EQ(1u, device->GetGattServices().size()); |
505 EXPECT_EQ(2, observer.gatt_services_discovered_count()); | 508 EXPECT_EQ(2, observer.gatt_services_discovered_count()); |
506 } | 509 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 return; | 548 return; |
546 } | 549 } |
547 InitWithFakeAdapter(); | 550 InitWithFakeAdapter(); |
548 StartLowEnergyDiscoverySession(); | 551 StartLowEnergyDiscoverySession(); |
549 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 552 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
550 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 553 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
551 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 554 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
552 TestBluetoothAdapterObserver observer(adapter_); | 555 TestBluetoothAdapterObserver observer(adapter_); |
553 ResetEventCounts(); | 556 ResetEventCounts(); |
554 SimulateGattConnection(device); | 557 SimulateGattConnection(device); |
558 EXPECT_EQ(1, observer.device_changed_count()); | |
555 EXPECT_EQ(1, gatt_discovery_attempts_); | 559 EXPECT_EQ(1, gatt_discovery_attempts_); |
556 | 560 |
557 std::vector<std::string> services; | 561 std::vector<std::string> services; |
558 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); | 562 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
559 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); | 563 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); |
560 SimulateGattServicesDiscovered(device, services); | 564 SimulateGattServicesDiscovered(device, services); |
561 | 565 |
562 EXPECT_EQ(1, observer.gatt_services_discovered_count()); | 566 EXPECT_EQ(1, observer.gatt_services_discovered_count()); |
563 EXPECT_EQ(2, observer.gatt_service_added_count()); | 567 EXPECT_EQ(2, observer.gatt_service_added_count()); |
568 | |
569 SimulateGattDisconnection(device); | |
570 EXPECT_EQ(2, observer.device_changed_count()); | |
564 } | 571 } |
565 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) | 572 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) |
566 | 573 |
567 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) | 574 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) |
568 TEST_F(BluetoothTest, GetGattServices_and_GetGattService) { | 575 TEST_F(BluetoothTest, GetGattServices_and_GetGattService) { |
569 if (!PlatformSupportsLowEnergy()) { | 576 if (!PlatformSupportsLowEnergy()) { |
570 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 577 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
571 return; | 578 return; |
572 } | 579 } |
573 InitWithFakeAdapter(); | 580 InitWithFakeAdapter(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 ResetEventCounts(); | 618 ResetEventCounts(); |
612 SimulateGattConnection(device); | 619 SimulateGattConnection(device); |
613 EXPECT_EQ(1, gatt_discovery_attempts_); | 620 EXPECT_EQ(1, gatt_discovery_attempts_); |
614 | 621 |
615 SimulateGattServicesDiscoveryError(device); | 622 SimulateGattServicesDiscoveryError(device); |
616 EXPECT_EQ(0u, device->GetGattServices().size()); | 623 EXPECT_EQ(0u, device->GetGattServices().size()); |
617 } | 624 } |
618 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 625 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
619 | 626 |
620 } // namespace device | 627 } // namespace device |
OLD | NEW |