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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 EXPECT_EQ(1, gatt_connection_attempts_); | 388 EXPECT_EQ(1, gatt_connection_attempts_); |
389 EXPECT_EQ(1, gatt_disconnection_attempts_); | 389 EXPECT_EQ(1, gatt_disconnection_attempts_); |
390 SimulateGattDisconnection(device); | 390 SimulateGattDisconnection(device); |
391 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); | 391 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); |
392 for (BluetoothGattConnection* connection : gatt_connections_) | 392 for (BluetoothGattConnection* connection : gatt_connections_) |
393 EXPECT_FALSE(connection->IsConnected()); | 393 EXPECT_FALSE(connection->IsConnected()); |
394 } | 394 } |
395 #endif // defined(OS_ANDROID) | 395 #endif // defined(OS_ANDROID) |
396 | 396 |
397 #if defined(OS_ANDROID) | 397 #if defined(OS_ANDROID) |
| 398 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services |
| 399 // have been cleaned up. |
| 400 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { |
| 401 InitWithFakeAdapter(); |
| 402 StartLowEnergyDiscoverySession(); |
| 403 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 404 EXPECT_FALSE(device->IsConnected()); |
| 405 |
| 406 // Connect to the device |
| 407 ResetEventCounts(); |
| 408 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 409 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 410 TestBluetoothAdapterObserver observer(adapter_); |
| 411 SimulateGattConnection(device); |
| 412 EXPECT_TRUE(device->IsConnected()); |
| 413 |
| 414 // Discover services |
| 415 std::vector<std::string> services; |
| 416 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); |
| 417 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); |
| 418 SimulateGattServicesDiscovered(device, services); |
| 419 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
| 420 EXPECT_EQ(2u, device->GetGattServices().size()); |
| 421 EXPECT_EQ(1, observer.gatt_services_discovered_count()); |
| 422 |
| 423 // Disconnect from the device |
| 424 device->DisconnectGatt(); |
| 425 SimulateGattDisconnection(device); |
| 426 EXPECT_FALSE(device->IsConnected()); |
| 427 EXPECT_FALSE(device->IsGattServicesDiscoveryComplete()); |
| 428 EXPECT_EQ(0u, device->GetGattServices().size()); |
| 429 |
| 430 // Verify that the device can be connected to again |
| 431 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 432 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 433 SimulateGattConnection(device); |
| 434 EXPECT_TRUE(device->IsConnected()); |
| 435 |
| 436 // Verify that service discovery can be done again |
| 437 std::vector<std::string> services2; |
| 438 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); |
| 439 SimulateGattServicesDiscovered(device, services2); |
| 440 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
| 441 EXPECT_EQ(1u, device->GetGattServices().size()); |
| 442 EXPECT_EQ(2, observer.gatt_services_discovered_count()); |
| 443 } |
| 444 #endif // defined(OS_ANDROID) |
| 445 |
| 446 #if defined(OS_ANDROID) |
398 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies | 447 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies |
399 // multiple errors should only invoke callbacks once. | 448 // multiple errors should only invoke callbacks once. |
400 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { | 449 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { |
401 InitWithFakeAdapter(); | 450 InitWithFakeAdapter(); |
402 StartLowEnergyDiscoverySession(); | 451 StartLowEnergyDiscoverySession(); |
403 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 452 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
404 | 453 |
405 ResetEventCounts(); | 454 ResetEventCounts(); |
406 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), | 455 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), |
407 GetConnectErrorCallback(Call::EXPECTED)); | 456 GetConnectErrorCallback(Call::EXPECTED)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 ResetEventCounts(); | 524 ResetEventCounts(); |
476 SimulateGattConnection(device); | 525 SimulateGattConnection(device); |
477 EXPECT_EQ(1, gatt_discovery_attempts_); | 526 EXPECT_EQ(1, gatt_discovery_attempts_); |
478 | 527 |
479 SimulateGattServicesDiscoveryError(device); | 528 SimulateGattServicesDiscoveryError(device); |
480 EXPECT_EQ(0u, device->GetGattServices().size()); | 529 EXPECT_EQ(0u, device->GetGattServices().size()); |
481 } | 530 } |
482 #endif // defined(OS_ANDROID) | 531 #endif // defined(OS_ANDROID) |
483 | 532 |
484 } // namespace device | 533 } // namespace device |
OLD | NEW |