Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: device/bluetooth/bluetooth_device_unittest.cc

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Mac bustage Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 // Create multiple connections and simulate connection complete: 944 // Create multiple connections and simulate connection complete:
945 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 945 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
946 GetConnectErrorCallback(Call::NOT_EXPECTED)); 946 GetConnectErrorCallback(Call::NOT_EXPECTED));
947 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 947 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
948 GetConnectErrorCallback(Call::NOT_EXPECTED)); 948 GetConnectErrorCallback(Call::NOT_EXPECTED));
949 SimulateGattConnection(device); 949 SimulateGattConnection(device);
950 950
951 // Disconnect all CreateGattConnection objects & create a new connection. 951 // Disconnect all CreateGattConnection objects & create a new connection.
952 // But, don't yet simulate the device disconnecting: 952 // But, don't yet simulate the device disconnecting:
953 ResetEventCounts(); 953 ResetEventCounts();
954 for (BluetoothGattConnection* connection : gatt_connections_) 954 for (auto& connection : gatt_connections_)
955 connection->Disconnect(); 955 connection->Disconnect();
956 EXPECT_EQ(1, gatt_disconnection_attempts_); 956 EXPECT_EQ(1, gatt_disconnection_attempts_);
957 957
958 // Create a connection. 958 // Create a connection.
959 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), 959 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED),
960 GetConnectErrorCallback(Call::NOT_EXPECTED)); 960 GetConnectErrorCallback(Call::NOT_EXPECTED));
961 EXPECT_EQ(0, gatt_connection_attempts_); // No connection attempt. 961 EXPECT_EQ(0, gatt_connection_attempts_); // No connection attempt.
962 EXPECT_EQ(1, callback_count_); // Device is assumed still connected. 962 EXPECT_EQ(1, callback_count_); // Device is assumed still connected.
963 EXPECT_EQ(0, error_callback_count_); 963 EXPECT_EQ(0, error_callback_count_);
964 EXPECT_FALSE(gatt_connections_.front()->IsConnected()); 964 EXPECT_FALSE(gatt_connections_.front()->IsConnected());
965 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); 965 EXPECT_TRUE(gatt_connections_.back()->IsConnected());
966 966
967 // Actually disconnect: 967 // Actually disconnect:
968 SimulateGattDisconnection(device); 968 SimulateGattDisconnection(device);
969 for (BluetoothGattConnection* connection : gatt_connections_) 969 for (auto& connection : gatt_connections_)
970 EXPECT_FALSE(connection->IsConnected()); 970 EXPECT_FALSE(connection->IsConnected());
971 } 971 }
972 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 972 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
973 973
974 #if defined(OS_ANDROID) || defined(OS_MACOSX) 974 #if defined(OS_ANDROID) || defined(OS_MACOSX)
975 // Calls CreateGattConnection but receives notice that the device disconnected 975 // Calls CreateGattConnection but receives notice that the device disconnected
976 // before it ever connects. 976 // before it ever connects.
977 TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) { 977 TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) {
978 if (!PlatformSupportsLowEnergy()) { 978 if (!PlatformSupportsLowEnergy()) {
979 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 979 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
980 return; 980 return;
981 } 981 }
982 InitWithFakeAdapter(); 982 InitWithFakeAdapter();
983 StartLowEnergyDiscoverySession(); 983 StartLowEnergyDiscoverySession();
984 BluetoothDevice* device = SimulateLowEnergyDevice(3); 984 BluetoothDevice* device = SimulateLowEnergyDevice(3);
985 985
986 ResetEventCounts(); 986 ResetEventCounts();
987 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), 987 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED),
988 GetConnectErrorCallback(Call::EXPECTED)); 988 GetConnectErrorCallback(Call::EXPECTED));
989 EXPECT_EQ(1, gatt_connection_attempts_); 989 EXPECT_EQ(1, gatt_connection_attempts_);
990 SimulateGattDisconnection(device); 990 SimulateGattDisconnection(device);
991 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 991 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
992 for (BluetoothGattConnection* connection : gatt_connections_) 992 for (auto& connection : gatt_connections_)
993 EXPECT_FALSE(connection->IsConnected()); 993 EXPECT_FALSE(connection->IsConnected());
994 } 994 }
995 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 995 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
996 996
997 #if defined(OS_ANDROID) || defined(OS_MACOSX) 997 #if defined(OS_ANDROID) || defined(OS_MACOSX)
998 // Calls CreateGattConnection & DisconnectGatt, then simulates connection. 998 // Calls CreateGattConnection & DisconnectGatt, then simulates connection.
999 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) { 999 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) {
1000 if (!PlatformSupportsLowEnergy()) { 1000 if (!PlatformSupportsLowEnergy()) {
1001 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1001 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1002 return; 1002 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 BluetoothDevice* device = SimulateLowEnergyDevice(3); 1035 BluetoothDevice* device = SimulateLowEnergyDevice(3);
1036 1036
1037 ResetEventCounts(); 1037 ResetEventCounts();
1038 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), 1038 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED),
1039 GetConnectErrorCallback(Call::EXPECTED)); 1039 GetConnectErrorCallback(Call::EXPECTED));
1040 device->DisconnectGatt(); 1040 device->DisconnectGatt();
1041 EXPECT_EQ(1, gatt_connection_attempts_); 1041 EXPECT_EQ(1, gatt_connection_attempts_);
1042 EXPECT_EQ(1, gatt_disconnection_attempts_); 1042 EXPECT_EQ(1, gatt_disconnection_attempts_);
1043 SimulateGattDisconnection(device); 1043 SimulateGattDisconnection(device);
1044 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 1044 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
1045 for (BluetoothGattConnection* connection : gatt_connections_) 1045 for (auto& connection : gatt_connections_)
1046 EXPECT_FALSE(connection->IsConnected()); 1046 EXPECT_FALSE(connection->IsConnected());
1047 } 1047 }
1048 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 1048 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1049 1049
1050 #if defined(OS_ANDROID) || defined(OS_MACOSX) 1050 #if defined(OS_ANDROID) || defined(OS_MACOSX)
1051 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services 1051 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services
1052 // have been cleaned up. 1052 // have been cleaned up.
1053 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { 1053 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) {
1054 if (!PlatformSupportsLowEnergy()) { 1054 if (!PlatformSupportsLowEnergy()) {
1055 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1055 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); 1120 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED);
1121 #if defined(OS_ANDROID) 1121 #if defined(OS_ANDROID)
1122 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback 1122 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback
1123 // only with the first error, but our android framework doesn't yet 1123 // only with the first error, but our android framework doesn't yet
1124 // support sending different errors. 1124 // support sending different errors.
1125 // http://crbug.com/578191 1125 // http://crbug.com/578191
1126 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 1126 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
1127 #else 1127 #else
1128 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_); 1128 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_);
1129 #endif 1129 #endif
1130 for (BluetoothGattConnection* connection : gatt_connections_) 1130 for (auto& connection : gatt_connections_)
1131 EXPECT_FALSE(connection->IsConnected()); 1131 EXPECT_FALSE(connection->IsConnected());
1132 } 1132 }
1133 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) 1133 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
1134 1134
1135 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX) 1135 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_MACOSX)
1136 TEST_F(BluetoothTest, GattServices_ObserversCalls) { 1136 TEST_F(BluetoothTest, GattServices_ObserversCalls) {
1137 if (!PlatformSupportsLowEnergy()) { 1137 if (!PlatformSupportsLowEnergy()) {
1138 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 1138 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
1139 return; 1139 return;
1140 } 1140 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 1334
1335 BluetoothDevice* device2 = SimulateLowEnergyDevice(6); 1335 BluetoothDevice* device2 = SimulateLowEnergyDevice(6);
1336 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType()); 1336 EXPECT_EQ(BLUETOOTH_TRANSPORT_DUAL, device2->GetType());
1337 1337
1338 BluetoothDevice* device3 = SimulateClassicDevice(); 1338 BluetoothDevice* device3 = SimulateClassicDevice();
1339 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType()); 1339 EXPECT_EQ(BLUETOOTH_TRANSPORT_CLASSIC, device3->GetType());
1340 } 1340 }
1341 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX) 1341 #endif // defined(OS_CHROMEOS) || defined(OS_LINUX)
1342 1342
1343 } // namespace device 1343 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698