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 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 | 1008 |
1009 #if defined(OS_ANDROID) || defined(OS_MACOSX) | 1009 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
1010 // Calls CreateGattConnection then simulates multiple connections from platform. | 1010 // Calls CreateGattConnection then simulates multiple connections from platform. |
1011 TEST_F(BluetoothTest, | 1011 TEST_F(BluetoothTest, |
1012 BluetoothGattConnection_ConnectWithMultipleOSConnections) { | 1012 BluetoothGattConnection_ConnectWithMultipleOSConnections) { |
1013 if (!PlatformSupportsLowEnergy()) { | 1013 if (!PlatformSupportsLowEnergy()) { |
1014 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; | 1014 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; |
1015 return; | 1015 return; |
1016 } | 1016 } |
1017 InitWithFakeAdapter(); | 1017 InitWithFakeAdapter(); |
| 1018 TestBluetoothAdapterObserver observer(adapter_); |
1018 StartLowEnergyDiscoverySession(); | 1019 StartLowEnergyDiscoverySession(); |
1019 BluetoothDevice* device = SimulateLowEnergyDevice(3); | 1020 BluetoothDevice* device = SimulateLowEnergyDevice(3); |
1020 | 1021 |
1021 // CreateGattConnection, & multiple connections from platform only invoke | 1022 // CreateGattConnection, & multiple connections from platform only invoke |
1022 // callbacks once: | 1023 // callbacks once: |
1023 ResetEventCounts(); | 1024 ResetEventCounts(); |
1024 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 1025 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
1025 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 1026 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
1026 SimulateGattConnection(device); | 1027 SimulateGattConnection(device); |
1027 SimulateGattConnection(device); | 1028 SimulateGattConnection(device); |
1028 base::RunLoop().RunUntilIdle(); | 1029 base::RunLoop().RunUntilIdle(); |
1029 | 1030 |
| 1031 #if defined(OS_ANDROID) |
| 1032 // Android incorrectly starts second discovery for devices that are already |
| 1033 // connected. |
| 1034 // TODO(crbug.com/718168): Remove once Android is fixed. |
| 1035 EXPECT_EQ(2, gatt_discovery_attempts_); |
| 1036 EXPECT_EQ(2, observer.device_changed_count()); |
| 1037 #else // !defined(OS_ANDROID) |
| 1038 EXPECT_EQ(1, gatt_discovery_attempts_); |
| 1039 EXPECT_EQ(1, observer.device_changed_count()); |
| 1040 #endif // defined(OS_ANDROID) |
1030 EXPECT_EQ(1, gatt_connection_attempts_); | 1041 EXPECT_EQ(1, gatt_connection_attempts_); |
1031 EXPECT_EQ(1, callback_count_); | 1042 EXPECT_EQ(1, callback_count_); |
1032 EXPECT_EQ(0, error_callback_count_); | 1043 EXPECT_EQ(0, error_callback_count_); |
1033 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); | 1044 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); |
1034 | 1045 |
1035 // Become disconnected: | 1046 // Become disconnected: |
1036 SimulateGattDisconnection(device); | 1047 SimulateGattDisconnection(device); |
1037 base::RunLoop().RunUntilIdle(); | 1048 base::RunLoop().RunUntilIdle(); |
1038 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); | 1049 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); |
1039 } | 1050 } |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 ->GetPrimaryServicesByUUID(BluetoothUUID( | 1609 ->GetPrimaryServicesByUUID(BluetoothUUID( |
1599 BluetoothTestBase::kTestUUIDGenericAttribute)) | 1610 BluetoothTestBase::kTestUUIDGenericAttribute)) |
1600 .empty()); | 1611 .empty()); |
1601 | 1612 |
1602 EXPECT_NE(services[0]->GetIdentifier(), services[1]->GetIdentifier()); | 1613 EXPECT_NE(services[0]->GetIdentifier(), services[1]->GetIdentifier()); |
1603 } | 1614 } |
1604 } | 1615 } |
1605 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) | 1616 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) || defined(OS_WIN) |
1606 | 1617 |
1607 } // namespace device | 1618 } // namespace device |
OLD | NEW |