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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // Verify that service discovery can be done again | 436 // Verify that service discovery can be done again |
437 std::vector<std::string> services2; | 437 std::vector<std::string> services2; |
438 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); | 438 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); |
439 SimulateGattServicesDiscovered(device, services2); | 439 SimulateGattServicesDiscovered(device, services2); |
440 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); | 440 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); |
441 EXPECT_EQ(1u, device->GetGattServices().size()); | 441 EXPECT_EQ(1u, device->GetGattServices().size()); |
442 EXPECT_EQ(2, observer.gatt_services_discovered_count()); | 442 EXPECT_EQ(2, observer.gatt_services_discovered_count()); |
443 } | 443 } |
444 #endif // defined(OS_ANDROID) | 444 #endif // defined(OS_ANDROID) |
445 | 445 |
446 #if defined(OS_ANDROID) | 446 #if defined(OS_ANDROID) || defined(OS_MACOSX) |
447 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies | 447 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies |
448 // multiple errors should only invoke callbacks once. | 448 // multiple errors should only invoke callbacks once. |
449 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { | 449 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { |
450 InitWithFakeAdapter(); | 450 InitWithFakeAdapter(); |
451 StartLowEnergyDiscoverySession(); | 451 StartLowEnergyDiscoverySession(); |
452 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 452 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
453 | 453 |
454 ResetEventCounts(); | 454 ResetEventCounts(); |
455 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), | 455 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), |
456 GetConnectErrorCallback(Call::EXPECTED)); | 456 GetConnectErrorCallback(Call::EXPECTED)); |
457 EXPECT_EQ(1, gatt_connection_attempts_); | 457 EXPECT_EQ(1, gatt_connection_attempts_); |
458 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED); | 458 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED); |
459 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); | 459 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); |
| 460 #if defined(OS_ANDROID) |
460 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback | 461 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback |
461 // only with the first error, but our android framework doesn't yet | 462 // only with the first error, but our android framework doesn't yet |
462 // support sending different errors. | 463 // support sending different errors. |
463 // http://crbug.com/578191 | 464 // http://crbug.com/578191 |
464 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); | 465 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); |
| 466 #else |
| 467 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_); |
| 468 #endif |
465 for (BluetoothGattConnection* connection : gatt_connections_) | 469 for (BluetoothGattConnection* connection : gatt_connections_) |
466 EXPECT_FALSE(connection->IsConnected()); | 470 EXPECT_FALSE(connection->IsConnected()); |
467 } | 471 } |
468 #endif // defined(OS_ANDROID) | 472 #endif // defined(OS_ANDROID) || defined(OS_MACOSX) |
469 | 473 |
470 #if defined(OS_ANDROID) | 474 #if defined(OS_ANDROID) |
471 TEST_F(BluetoothTest, GattServices_ObserversCalls) { | 475 TEST_F(BluetoothTest, GattServices_ObserversCalls) { |
472 InitWithFakeAdapter(); | 476 InitWithFakeAdapter(); |
473 StartLowEnergyDiscoverySession(); | 477 StartLowEnergyDiscoverySession(); |
474 BluetoothDevice* device = DiscoverLowEnergyDevice(3); | 478 BluetoothDevice* device = DiscoverLowEnergyDevice(3); |
475 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), | 479 device->CreateGattConnection(GetGattConnectionCallback(Call::EXPECTED), |
476 GetConnectErrorCallback(Call::NOT_EXPECTED)); | 480 GetConnectErrorCallback(Call::NOT_EXPECTED)); |
477 TestBluetoothAdapterObserver observer(adapter_); | 481 TestBluetoothAdapterObserver observer(adapter_); |
478 ResetEventCounts(); | 482 ResetEventCounts(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 ResetEventCounts(); | 532 ResetEventCounts(); |
529 SimulateGattConnection(device); | 533 SimulateGattConnection(device); |
530 EXPECT_EQ(1, gatt_discovery_attempts_); | 534 EXPECT_EQ(1, gatt_discovery_attempts_); |
531 | 535 |
532 SimulateGattServicesDiscoveryError(device); | 536 SimulateGattServicesDiscoveryError(device); |
533 EXPECT_EQ(0u, device->GetGattServices().size()); | 537 EXPECT_EQ(0u, device->GetGattServices().size()); |
534 } | 538 } |
535 #endif // defined(OS_ANDROID) | 539 #endif // defined(OS_ANDROID) |
536 | 540 |
537 } // namespace device | 541 } // namespace device |
OLD | NEW |