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

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

Issue 1685963003: Adding the last test related with connect/disconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connectdisconnect
Patch Set: Using FAILED instead of UNKNOWN error code Created 4 years, 10 months 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // Verify that service discovery can be done again 441 // Verify that service discovery can be done again
442 std::vector<std::string> services2; 442 std::vector<std::string> services2;
443 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); 443 services2.push_back("00000002-0000-1000-8000-00805f9b34fb");
444 SimulateGattServicesDiscovered(device, services2); 444 SimulateGattServicesDiscovered(device, services2);
445 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 445 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
446 EXPECT_EQ(1u, device->GetGattServices().size()); 446 EXPECT_EQ(1u, device->GetGattServices().size());
447 EXPECT_EQ(2, observer.gatt_services_discovered_count()); 447 EXPECT_EQ(2, observer.gatt_services_discovered_count());
448 } 448 }
449 #endif // defined(OS_ANDROID) 449 #endif // defined(OS_ANDROID)
450 450
451 #if defined(OS_ANDROID) 451 #if defined(OS_ANDROID) || defined(OS_MACOSX)
452 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies 452 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies
453 // multiple errors should only invoke callbacks once. 453 // multiple errors should only invoke callbacks once.
454 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { 454 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) {
455 InitWithFakeAdapter(); 455 InitWithFakeAdapter();
456 StartLowEnergyDiscoverySession(); 456 StartLowEnergyDiscoverySession();
457 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 457 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
458 458
459 ResetEventCounts(); 459 ResetEventCounts();
460 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), 460 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED),
461 GetConnectErrorCallback(Call::EXPECTED)); 461 GetConnectErrorCallback(Call::EXPECTED));
462 EXPECT_EQ(1, gatt_connection_attempts_); 462 EXPECT_EQ(1, gatt_connection_attempts_);
463 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED); 463 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED);
464 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); 464 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED);
465 #if defined(OS_ANDROID)
465 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback 466 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback
466 // only with the first error, but our android framework doesn't yet 467 // only with the first error, but our android framework doesn't yet
467 // support sending different errors. 468 // support sending different errors.
468 // http://crbug.com/578191 469 // http://crbug.com/578191
469 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 470 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
471 #else
472 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_);
473 #endif
470 for (BluetoothGattConnection* connection : gatt_connections_) 474 for (BluetoothGattConnection* connection : gatt_connections_)
471 EXPECT_FALSE(connection->IsConnected()); 475 EXPECT_FALSE(connection->IsConnected());
472 } 476 }
473 #endif // defined(OS_ANDROID) 477 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
474 478
475 #if defined(OS_ANDROID) || defined(OS_WIN) 479 #if defined(OS_ANDROID) || defined(OS_WIN)
476 TEST_F(BluetoothTest, GattServices_ObserversCalls) { 480 TEST_F(BluetoothTest, GattServices_ObserversCalls) {
477 if (!PlatformSupportsLowEnergy()) { 481 if (!PlatformSupportsLowEnergy()) {
478 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 482 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
479 return; 483 return;
480 } 484 }
481 InitWithFakeAdapter(); 485 InitWithFakeAdapter();
482 StartLowEnergyDiscoverySession(); 486 StartLowEnergyDiscoverySession();
483 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 487 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 ResetEventCounts(); 545 ResetEventCounts();
542 SimulateGattConnection(device); 546 SimulateGattConnection(device);
543 EXPECT_EQ(1, gatt_discovery_attempts_); 547 EXPECT_EQ(1, gatt_discovery_attempts_);
544 548
545 SimulateGattServicesDiscoveryError(device); 549 SimulateGattServicesDiscoveryError(device);
546 EXPECT_EQ(0u, device->GetGattServices().size()); 550 EXPECT_EQ(0u, device->GetGattServices().size());
547 } 551 }
548 #endif // defined(OS_ANDROID) 552 #endif // defined(OS_ANDROID)
549 553
550 } // namespace device 554 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698