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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 | 1020 |
1021 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1021 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
1022 // Calls CreateGattConnection then simulates multiple connections from platform. | 1022 // Calls CreateGattConnection then simulates multiple connections from platform. |
1023 TEST_F(BluetoothTest, | 1023 TEST_F(BluetoothTest, |
1024 BluetoothGattConnection_ConnectWithMultipleOSConnections) { | 1024 BluetoothGattConnection_ConnectWithMultipleOSConnections) { |
1025 if (!PlatformSupportsLowEnergy()) { | 1025 if (!PlatformSupportsLowEnergy()) { |
1026 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1026 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
1027 return; | 1027 return; |
1028 } | 1028 } |
1029 InitWithFakeAdapter(); | 1029 InitWithFakeAdapter(); |
| 1030 TestBluetoothAdapterObserver observer(adapter_); |
1030 StartLowEnergyDiscoverySession(); | 1031 StartLowEnergyDiscoverySession(); |
1031 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 1032 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
1032 | 1033 |
1033 // CreateGattConnection, & multiple connections from platform only invoke | 1034 // CreateGattConnection, & multiple connections from platform only invoke |
1034 // callbacks once: | 1035 // callbacks once: |
1035 ResetEventCounts(); | 1036 ResetEventCounts(); |
1036 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 1037 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
1037 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 1038 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
1038 SimulateGattConnection(device); | 1039 SimulateGattConnection(device); |
1039 SimulateGattConnection(device); | 1040 SimulateGattConnection(device); |
1040 base::RunLoop().RunUntilIdle(); | 1041 base::RunLoop().RunUntilIdle(); |
1041 | 1042 |
| 1043 #if defined(OS_ANDROID) |
| 1044 // Android incorrectly starts second discovery for devices that are already |
| 1045 // connected. |
| 1046 // TODO(crbug.com/718168): Remove once Android is fixed. |
| 1047 EXPECT_EQ(2, gatt_discovery_attempts_); |
| 1048 EXPECT_EQ(2, observer.device_changed_count()); |
| 1049 #else // !defined(OS_ANDROID) |
| 1050 EXPECT_EQ(1, gatt_discovery_attempts_); |
| 1051 EXPECT_EQ(1, observer.device_changed_count()); |
| 1052 #endif // defined(OS_ANDROID) |
1042 EXPECT_EQ(1, gatt_connection_attempts_); | 1053 EXPECT_EQ(1, gatt_connection_attempts_); |
1043 EXPECT_EQ(1, callback_count_); | 1054 EXPECT_EQ(1, callback_count_); |
1044 EXPECT_EQ(0, error_callback_count_); | 1055 EXPECT_EQ(0, error_callback_count_); |
1045 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); | 1056 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); |
1046 | 1057 |
1047 // Become disconnected: | 1058 // Become disconnected: |
1048 SimulateGattDisconnection(device); | 1059 SimulateGattDisconnection(device); |
1049 base::RunLoop().RunUntilIdle(); | 1060 base::RunLoop().RunUntilIdle(); |
1050 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); | 1061 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); |
1051 } | 1062 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 ->GetPrimaryServicesByUUID(BluetoothUUID( | 1621 ->GetPrimaryServicesByUUID(BluetoothUUID( |
1611 BluetoothTestBase::kTestUUIDGenericAttribute)) | 1622 BluetoothTestBase::kTestUUIDGenericAttribute)) |
1612 .empty()); | 1623 .empty()); |
1613 | 1624 |
1614 EXPECT_NE(services[0]->GetIdentifier(), services[1]->GetIdentifier()); | 1625 EXPECT_NE(services[0]->GetIdentifier(), services[1]->GetIdentifier()); |
1615 } | 1626 } |
1616 } | 1627 } |
1617 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1628 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
1618 | 1629 |
1619 } // namespace device | 1630 } // namespace device |
OLD | NEW |