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

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: adding DEVICE_BLUETOOTH_EXPORT to BluetoothDeviceMac Created 4 years, 8 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 // Verify that service discovery can be done again 485 // Verify that service discovery can be done again
486 std::vector<std::string> services2; 486 std::vector<std::string> services2;
487 services2.push_back("00000002-0000-1000-8000-00805f9b34fb"); 487 services2.push_back("00000002-0000-1000-8000-00805f9b34fb");
488 SimulateGattServicesDiscovered(device, services2); 488 SimulateGattServicesDiscovered(device, services2);
489 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete()); 489 EXPECT_TRUE(device->IsGattServicesDiscoveryComplete());
490 EXPECT_EQ(1u, device->GetGattServices().size()); 490 EXPECT_EQ(1u, device->GetGattServices().size());
491 EXPECT_EQ(2, observer.gatt_services_discovered_count()); 491 EXPECT_EQ(2, observer.gatt_services_discovered_count());
492 } 492 }
493 #endif // defined(OS_ANDROID) 493 #endif // defined(OS_ANDROID)
494 494
495 #if defined(OS_ANDROID) 495 #if defined(OS_ANDROID) || defined(OS_MACOSX)
496 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies 496 // Calls CreateGattConnection, but simulate errors connecting. Also, verifies
497 // multiple errors should only invoke callbacks once. 497 // multiple errors should only invoke callbacks once.
498 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) { 498 TEST_F(BluetoothTest, BluetoothGattConnection_ErrorAfterConnection) {
499 if (!PlatformSupportsLowEnergy()) { 499 if (!PlatformSupportsLowEnergy()) {
500 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 500 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
501 return; 501 return;
502 } 502 }
503 InitWithFakeAdapter(); 503 InitWithFakeAdapter();
504 StartLowEnergyDiscoverySession(); 504 StartLowEnergyDiscoverySession();
505 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 505 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
506 506
507 ResetEventCounts(); 507 ResetEventCounts();
508 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED), 508 device->CreateGattConnection(GetGattConnectionCallback(Call::NOT_EXPECTED),
509 GetConnectErrorCallback(Call::EXPECTED)); 509 GetConnectErrorCallback(Call::EXPECTED));
510 EXPECT_EQ(1, gatt_connection_attempts_); 510 EXPECT_EQ(1, gatt_connection_attempts_);
511 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED); 511 SimulateGattConnectionError(device, BluetoothDevice::ERROR_AUTH_FAILED);
512 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); 512 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED);
513 #if defined(OS_ANDROID)
513 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback 514 // TODO: Change to ERROR_AUTH_FAILED. We should be getting a callback
514 // only with the first error, but our android framework doesn't yet 515 // only with the first error, but our android framework doesn't yet
515 // support sending different errors. 516 // support sending different errors.
516 // http://crbug.com/578191 517 // http://crbug.com/578191
517 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_); 518 EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_code_);
519 #else
520 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_);
521 #endif
518 for (BluetoothGattConnection* connection : gatt_connections_) 522 for (BluetoothGattConnection* connection : gatt_connections_)
519 EXPECT_FALSE(connection->IsConnected()); 523 EXPECT_FALSE(connection->IsConnected());
520 } 524 }
521 #endif // defined(OS_ANDROID) 525 #endif // defined(OS_ANDROID) || defined(OS_MACOSX)
522 526
523 #if defined(OS_ANDROID) || defined(OS_WIN) 527 #if defined(OS_ANDROID) || defined(OS_WIN)
524 TEST_F(BluetoothTest, GattServices_ObserversCalls) { 528 TEST_F(BluetoothTest, GattServices_ObserversCalls) {
525 if (!PlatformSupportsLowEnergy()) { 529 if (!PlatformSupportsLowEnergy()) {
526 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test."; 530 LOG(WARNING) << "Low Energy Bluetooth unavailable, skipping unit test.";
527 return; 531 return;
528 } 532 }
529 InitWithFakeAdapter(); 533 InitWithFakeAdapter();
530 StartLowEnergyDiscoverySession(); 534 StartLowEnergyDiscoverySession();
531 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 535 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 ResetEventCounts(); 597 ResetEventCounts();
594 SimulateGattConnection(device); 598 SimulateGattConnection(device);
595 EXPECT_EQ(1, gatt_discovery_attempts_); 599 EXPECT_EQ(1, gatt_discovery_attempts_);
596 600
597 SimulateGattServicesDiscoveryError(device); 601 SimulateGattServicesDiscoveryError(device);
598 EXPECT_EQ(0u, device->GetGattServices().size()); 602 EXPECT_EQ(0u, device->GetGattServices().size());
599 } 603 }
600 #endif // defined(OS_ANDROID) 604 #endif // defined(OS_ANDROID)
601 605
602 } // namespace device 606 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_device_mac.mm ('k') | device/bluetooth/bluetooth_low_energy_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698