| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) | 111 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 112 | 112 |
| 113 // TODO(scheib): Test with a device with no name. http://crbug.com/506415 | 113 // TODO(scheib): Test with a device with no name. http://crbug.com/506415 |
| 114 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which | 114 // BluetoothDevice::GetAddressWithLocalizedDeviceTypeName() will run, which |
| 115 // requires string resources to be loaded. For that, something like | 115 // requires string resources to be loaded. For that, something like |
| 116 // InitSharedInstance must be run. See unittest files that call that. It will | 116 // InitSharedInstance must be run. See unittest files that call that. It will |
| 117 // also require build configuration to generate string resources into a .pak | 117 // also require build configuration to generate string resources into a .pak |
| 118 // file. | 118 // file. |
| 119 | 119 |
| 120 #if defined(OS_ANDROID) | 120 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 121 // Basic CreateGattConnection test. | 121 // Basic CreateGattConnection test. |
| 122 TEST_F(BluetoothTest, CreateGattConnection) { | 122 TEST_F(BluetoothTest, CreateGattConnection) { |
| 123 InitWithFakeAdapter(); | 123 InitWithFakeAdapter(); |
| 124 StartLowEnergyDiscoverySession(); | 124 StartLowEnergyDiscoverySession(); |
| 125 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 125 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 126 | 126 |
| 127 ResetEventCounts(); | 127 ResetEventCounts(); |
| 128 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 128 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 129 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 129 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 130 SimulateGattConnection(device); | 130 SimulateGattConnection(device); |
| 131 ASSERT_EQ(1u, gatt_connections_.size()); | 131 ASSERT_EQ(1u, gatt_connections_.size()); |
| 132 EXPECT_TRUE(device->IsGattConnected()); | 132 EXPECT_TRUE(device->IsGattConnected()); |
| 133 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); | 133 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); |
| 134 } | 134 } |
| 135 #endif // defined(OS_ANDROID) | 135 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 136 | 136 |
| 137 #if defined(OS_ANDROID) | 137 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 138 // Creates BluetoothGattConnection instances and tests that the interface | 138 // Creates BluetoothGattConnection instances and tests that the interface |
| 139 // functions even when some Disconnect and the BluetoothDevice is destroyed. | 139 // functions even when some Disconnect and the BluetoothDevice is destroyed. |
| 140 TEST_F(BluetoothTest, BluetoothGattConnection) { | 140 TEST_F(BluetoothTest, BluetoothGattConnection) { |
| 141 InitWithFakeAdapter(); | 141 InitWithFakeAdapter(); |
| 142 StartLowEnergyDiscoverySession(); | 142 StartLowEnergyDiscoverySession(); |
| 143 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 143 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 144 std::string device_address = device->GetAddress(); | 144 std::string device_address = device->GetAddress(); |
| 145 | 145 |
| 146 // CreateGattConnection | 146 // CreateGattConnection |
| 147 ResetEventCounts(); | 147 ResetEventCounts(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 gatt_disconnection_attempts_ = 0; | 186 gatt_disconnection_attempts_ = 0; |
| 187 DeleteDevice(device); | 187 DeleteDevice(device); |
| 188 EXPECT_EQ(1, gatt_disconnection_attempts_); | 188 EXPECT_EQ(1, gatt_disconnection_attempts_); |
| 189 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); | 189 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); |
| 190 EXPECT_FALSE(gatt_connections_[1]->IsConnected()); | 190 EXPECT_FALSE(gatt_connections_[1]->IsConnected()); |
| 191 | 191 |
| 192 // Test GetDeviceAddress after device deleted. | 192 // Test GetDeviceAddress after device deleted. |
| 193 EXPECT_EQ(device_address, gatt_connections_[0]->GetDeviceAddress()); | 193 EXPECT_EQ(device_address, gatt_connections_[0]->GetDeviceAddress()); |
| 194 EXPECT_EQ(device_address, gatt_connections_[1]->GetDeviceAddress()); | 194 EXPECT_EQ(device_address, gatt_connections_[1]->GetDeviceAddress()); |
| 195 } | 195 } |
| 196 #endif // defined(OS_ANDROID) | 196 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 197 | 197 |
| 198 #if defined(OS_ANDROID) | 198 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 199 // Calls CreateGattConnection then simulates multiple connections from platform. | 199 // Calls CreateGattConnection then simulates multiple connections from platform. |
| 200 TEST_F(BluetoothTest, | 200 TEST_F(BluetoothTest, |
| 201 BluetoothGattConnection_ConnectWithMultipleOSConnections) { | 201 BluetoothGattConnection_ConnectWithMultipleOSConnections) { |
| 202 InitWithFakeAdapter(); | 202 InitWithFakeAdapter(); |
| 203 StartLowEnergyDiscoverySession(); | 203 StartLowEnergyDiscoverySession(); |
| 204 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 204 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 205 | 205 |
| 206 // CreateGattConnection, & multiple connections from platform only invoke | 206 // CreateGattConnection, & multiple connections from platform only invoke |
| 207 // callbacks once: | 207 // callbacks once: |
| 208 ResetEventCounts(); | 208 ResetEventCounts(); |
| 209 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 209 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 210 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 210 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 211 SimulateGattConnection(device); | 211 SimulateGattConnection(device); |
| 212 SimulateGattConnection(device); | 212 SimulateGattConnection(device); |
| 213 EXPECT_EQ(1, gatt_connection_attempts_); | 213 EXPECT_EQ(1, gatt_connection_attempts_); |
| 214 EXPECT_EQ(1, callback_count_); | 214 EXPECT_EQ(1, callback_count_); |
| 215 EXPECT_EQ(0, error_callback_count_); | 215 EXPECT_EQ(0, error_callback_count_); |
| 216 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); | 216 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); |
| 217 | 217 |
| 218 // Become disconnected: | 218 // Become disconnected: |
| 219 SimulateGattDisconnection(device); | 219 SimulateGattDisconnection(device); |
| 220 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); | 220 EXPECT_FALSE(gatt_connections_[0]->IsConnected()); |
| 221 } | 221 } |
| 222 #endif // defined(OS_ANDROID) | 222 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 223 | 223 |
| 224 #if defined(OS_ANDROID) | 224 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 225 // Calls CreateGattConnection after already connected. | 225 // Calls CreateGattConnection after already connected. |
| 226 TEST_F(BluetoothTest, BluetoothGattConnection_AlreadyConnected) { | 226 TEST_F(BluetoothTest, BluetoothGattConnection_AlreadyConnected) { |
| 227 InitWithFakeAdapter(); | 227 InitWithFakeAdapter(); |
| 228 StartLowEnergyDiscoverySession(); | 228 StartLowEnergyDiscoverySession(); |
| 229 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 229 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 230 | 230 |
| 231 // Be already connected: | 231 // Be already connected: |
| 232 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 232 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 233 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 233 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 234 SimulateGattConnection(device); | 234 SimulateGattConnection(device); |
| 235 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); | 235 EXPECT_TRUE(gatt_connections_[0]->IsConnected()); |
| 236 | 236 |
| 237 // Then CreateGattConnection: | 237 // Then CreateGattConnection: |
| 238 ResetEventCounts(); | 238 ResetEventCounts(); |
| 239 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 239 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 240 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 240 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 241 EXPECT_EQ(0, gatt_connection_attempts_); | 241 EXPECT_EQ(0, gatt_connection_attempts_); |
| 242 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); | 242 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); |
| 243 } | 243 } |
| 244 #endif // defined(OS_ANDROID) | 244 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 245 | 245 |
| 246 #if defined(OS_ANDROID) | 246 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 247 // Creates BluetoothGattConnection after one exists that has disconnected. | 247 // Creates BluetoothGattConnection after one exists that has disconnected. |
| 248 TEST_F(BluetoothTest, | 248 TEST_F(BluetoothTest, |
| 249 BluetoothGattConnection_NewConnectionLeavesPreviousDisconnected) { | 249 BluetoothGattConnection_NewConnectionLeavesPreviousDisconnected) { |
| 250 InitWithFakeAdapter(); | 250 InitWithFakeAdapter(); |
| 251 StartLowEnergyDiscoverySession(); | 251 StartLowEnergyDiscoverySession(); |
| 252 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 252 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 253 | 253 |
| 254 // Create connection: | 254 // Create connection: |
| 255 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 255 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 256 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 256 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 257 SimulateGattConnection(device); | 257 SimulateGattConnection(device); |
| 258 | 258 |
| 259 // Disconnect connection: | 259 // Disconnect connection: |
| 260 gatt_connections_[0]->Disconnect(); | 260 gatt_connections_[0]->Disconnect(); |
| 261 SimulateGattDisconnection(device); | 261 SimulateGattDisconnection(device); |
| 262 | 262 |
| 263 // Create 2nd connection: | 263 // Create 2nd connection: |
| 264 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 264 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 265 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 265 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 266 SimulateGattConnection(device); | 266 SimulateGattConnection(device); |
| 267 | 267 |
| 268 EXPECT_FALSE(gatt_connections_[0]->IsConnected()) | 268 EXPECT_FALSE(gatt_connections_[0]->IsConnected()) |
| 269 << "The disconnected connection shouldn't become connected when another " | 269 << "The disconnected connection shouldn't become connected when another " |
| 270 "connection is created."; | 270 "connection is created."; |
| 271 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); | 271 EXPECT_TRUE(gatt_connections_[1]->IsConnected()); |
| 272 } | 272 } |
| 273 #endif // defined(OS_ANDROID) | 273 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 274 | 274 |
| 275 #if defined(OS_ANDROID) | 275 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 276 // Deletes BluetoothGattConnection causing disconnection. | 276 // Deletes BluetoothGattConnection causing disconnection. |
| 277 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectWhenObjectsDestroyed) { | 277 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectWhenObjectsDestroyed) { |
| 278 InitWithFakeAdapter(); | 278 InitWithFakeAdapter(); |
| 279 StartLowEnergyDiscoverySession(); | 279 StartLowEnergyDiscoverySession(); |
| 280 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 280 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 281 | 281 |
| 282 // Create multiple connections and simulate connection complete: | 282 // Create multiple connections and simulate connection complete: |
| 283 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 283 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 284 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 284 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 285 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 285 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 286 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 286 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 287 SimulateGattConnection(device); | 287 SimulateGattConnection(device); |
| 288 | 288 |
| 289 // Delete all CreateGattConnection objects, observe disconnection: | 289 // Delete all CreateGattConnection objects, observe disconnection: |
| 290 ResetEventCounts(); | 290 ResetEventCounts(); |
| 291 gatt_connections_.clear(); | 291 gatt_connections_.clear(); |
| 292 EXPECT_EQ(1, gatt_disconnection_attempts_); | 292 EXPECT_EQ(1, gatt_disconnection_attempts_); |
| 293 } | 293 } |
| 294 #endif // defined(OS_ANDROID) | 294 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 295 | 295 |
| 296 #if defined(OS_ANDROID) | 296 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 297 // Starts process of disconnecting and then calls BluetoothGattConnection. | 297 // Starts process of disconnecting and then calls BluetoothGattConnection. |
| 298 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectInProgress) { | 298 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectInProgress) { |
| 299 InitWithFakeAdapter(); | 299 InitWithFakeAdapter(); |
| 300 StartLowEnergyDiscoverySession(); | 300 StartLowEnergyDiscoverySession(); |
| 301 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 301 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 302 | 302 |
| 303 // Create multiple connections and simulate connection complete: | 303 // Create multiple connections and simulate connection complete: |
| 304 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 304 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 305 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 305 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 306 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 306 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 321 EXPECT_EQ(1, callback_count_); // Device is assumed still connected. | 321 EXPECT_EQ(1, callback_count_); // Device is assumed still connected. |
| 322 EXPECT_EQ(0, error_callback_count_); | 322 EXPECT_EQ(0, error_callback_count_); |
| 323 EXPECT_FALSE(gatt_connections_.front()->IsConnected()); | 323 EXPECT_FALSE(gatt_connections_.front()->IsConnected()); |
| 324 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); | 324 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); |
| 325 | 325 |
| 326 // Actually disconnect: | 326 // Actually disconnect: |
| 327 SimulateGattDisconnection(device); | 327 SimulateGattDisconnection(device); |
| 328 for (BluetoothGattConnection* connection : gatt_connections_) | 328 for (BluetoothGattConnection* connection : gatt_connections_) |
| 329 EXPECT_FALSE(connection->IsConnected()); | 329 EXPECT_FALSE(connection->IsConnected()); |
| 330 } | 330 } |
| 331 #endif // defined(OS_ANDROID) | 331 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 332 | 332 |
| 333 #if defined(OS_ANDROID) | 333 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 334 // Calls CreateGattConnection but receives notice that the device disconnected | 334 // Calls CreateGattConnection but receives notice that the device disconnected |
| 335 // before it ever connects. | 335 // before it ever connects. |
| 336 TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) { | 336 TEST_F(BluetoothTest, BluetoothGattConnection_SimulateDisconnect) { |
| 337 InitWithFakeAdapter(); | 337 InitWithFakeAdapter(); |
| 338 StartLowEnergyDiscoverySession(); | 338 StartLowEnergyDiscoverySession(); |
| 339 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 339 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 340 | 340 |
| 341 ResetEventCounts(); | 341 ResetEventCounts(); |
| 342 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), | 342 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), |
| 343 GetConnectErrorCallback(Call::EXPECTED)); | 343 GetConnectErrorCallback(Call::EXPECTED)); |
| 344 EXPECT_EQ(1, gatt_connection_attempts_); | 344 EXPECT_EQ(1, gatt_connection_attempts_); |
| 345 SimulateGattDisconnection(device); | 345 SimulateGattDisconnection(device); |
| 346 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); | 346 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); |
| 347 for (BluetoothGattConnection* connection : gatt_connections_) | 347 for (BluetoothGattConnection* connection : gatt_connections_) |
| 348 EXPECT_FALSE(connection->IsConnected()); | 348 EXPECT_FALSE(connection->IsConnected()); |
| 349 } | 349 } |
| 350 #endif // defined(OS_ANDROID) | 350 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 351 | 351 |
| 352 #if defined(OS_ANDROID) | 352 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 353 // Calls CreateGattConnection & DisconnectGatt, then simulates connection. | 353 // Calls CreateGattConnection & DisconnectGatt, then simulates connection. |
| 354 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) { | 354 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_SimulateConnect) { |
| 355 InitWithFakeAdapter(); | 355 InitWithFakeAdapter(); |
| 356 StartLowEnergyDiscoverySession(); | 356 StartLowEnergyDiscoverySession(); |
| 357 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 357 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 358 | 358 |
| 359 ResetEventCounts(); | 359 ResetEventCounts(); |
| 360 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 360 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
| 361 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 361 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
| 362 device->DisconnectGatt(); | 362 device->DisconnectGatt(); |
| 363 EXPECT_EQ(1, gatt_connection_attempts_); | 363 EXPECT_EQ(1, gatt_connection_attempts_); |
| 364 EXPECT_EQ(1, gatt_disconnection_attempts_); | 364 EXPECT_EQ(1, gatt_disconnection_attempts_); |
| 365 SimulateGattConnection(device); | 365 SimulateGattConnection(device); |
| 366 EXPECT_EQ(1, callback_count_); | 366 EXPECT_EQ(1, callback_count_); |
| 367 EXPECT_EQ(0, error_callback_count_); | 367 EXPECT_EQ(0, error_callback_count_); |
| 368 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); | 368 EXPECT_TRUE(gatt_connections_.back()->IsConnected()); |
| 369 ResetEventCounts(); | 369 ResetEventCounts(); |
| 370 SimulateGattDisconnection(device); | 370 SimulateGattDisconnection(device); |
| 371 EXPECT_EQ(0, callback_count_); | 371 EXPECT_EQ(0, callback_count_); |
| 372 EXPECT_EQ(0, error_callback_count_); | 372 EXPECT_EQ(0, error_callback_count_); |
| 373 } | 373 } |
| 374 #endif // defined(OS_ANDROID) | 374 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
| 375 | 375 |
| 376 #if defined(OS_ANDROID) | 376 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
| 377 // Calls CreateGattConnection & DisconnectGatt, then simulates disconnection. | 377 // Calls CreateGattConnection & DisconnectGatt, then simulates disconnection. |
| 378 TEST_F(BluetoothTest, | 378 TEST_F(BluetoothTest, |
| 379 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect) { | 379 BluetoothGattConnection_DisconnectGatt_SimulateDisconnect) { |
| 380 InitWithFakeAdapter(); | 380 InitWithFakeAdapter(); |
| 381 StartLowEnergyDiscoverySession(); | 381 StartLowEnergyDiscoverySession(); |
| 382 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 382 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 383 | 383 |
| 384 ResetEventCounts(); | 384 ResetEventCounts(); |
| 385 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), | 385 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), |
| 386 GetConnectErrorCallback(Call::EXPECTED)); | 386 GetConnectErrorCallback(Call::EXPECTED)); |
| 387 device->DisconnectGatt(); | 387 device->DisconnectGatt(); |
| 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) || defined(OS_MACOSX) |
| 396 | 396 |
| 397 #if defined(OS_ANDROID) | 397 #if defined(OS_ANDROID) |
| 398 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services | 398 // Calls CreateGattConnection & DisconnectGatt, then checks that gatt services |
| 399 // have been cleaned up. | 399 // have been cleaned up. |
| 400 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { | 400 TEST_F(BluetoothTest, BluetoothGattConnection_DisconnectGatt_Cleanup) { |
| 401 InitWithFakeAdapter(); | 401 InitWithFakeAdapter(); |
| 402 StartLowEnergyDiscoverySession(); | 402 StartLowEnergyDiscoverySession(); |
| 403 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 403 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
| 404 EXPECT_FALSE(device->IsConnected()); | 404 EXPECT_FALSE(device->IsConnected()); |
| 405 | 405 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 ResetEventCounts(); | 528 ResetEventCounts(); |
| 529 SimulateGattConnection(device); | 529 SimulateGattConnection(device); |
| 530 EXPECT_EQ(1, gatt_discovery_attempts_); | 530 EXPECT_EQ(1, gatt_discovery_attempts_); |
| 531 | 531 |
| 532 SimulateGattServicesDiscoveryError(device); | 532 SimulateGattServicesDiscoveryError(device); |
| 533 EXPECT_EQ(0u, device->GetGattServices().size()); | 533 EXPECT_EQ(0u, device->GetGattServices().size()); |
| 534 } | 534 } |
| 535 #endif // defined(OS_ANDROID) | 535 #endif // defined(OS_ANDROID) |
| 536 | 536 |
| 537 } // namespace device | 537 } // namespace device |
| OLD | NEW |