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

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

Issue 1412963004: bluetooth: android: Implement Characteristic GetIdentifier, fix Service IDs too. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "device/bluetooth/bluetooth_gatt_service.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 #if defined(OS_ANDROID) 13 #if defined(OS_ANDROID)
13 #include "device/bluetooth/test/bluetooth_test_android.h" 14 #include "device/bluetooth/test/bluetooth_test_android.h"
14 #elif defined(OS_MACOSX) 15 #elif defined(OS_MACOSX)
15 #include "device/bluetooth/test/bluetooth_test_mac.h" 16 #include "device/bluetooth/test/bluetooth_test_mac.h"
16 #endif 17 #endif
17 18
18 namespace device { 19 namespace device {
19 20
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED); 420 SimulateGattConnectionError(device, BluetoothDevice::ERROR_FAILED);
420 EXPECT_EQ(0, callback_count_); 421 EXPECT_EQ(0, callback_count_);
421 EXPECT_EQ(1, error_callback_count_); 422 EXPECT_EQ(1, error_callback_count_);
422 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_); 423 EXPECT_EQ(BluetoothDevice::ERROR_AUTH_FAILED, last_connect_error_code_);
423 for (BluetoothGattConnection* connection : gatt_connections_) 424 for (BluetoothGattConnection* connection : gatt_connections_)
424 EXPECT_FALSE(connection->IsConnected()); 425 EXPECT_FALSE(connection->IsConnected());
425 } 426 }
426 #endif // defined(OS_ANDROID) 427 #endif // defined(OS_ANDROID)
427 428
428 #if defined(OS_ANDROID) 429 #if defined(OS_ANDROID)
429 TEST_F(BluetoothTest, SimulateGattServicesDiscovered) { 430 TEST_F(BluetoothTest, GetGattServices_and_GetGattService) {
430 InitWithFakeAdapter(); 431 InitWithFakeAdapter();
431 StartLowEnergyDiscoverySession(); 432 StartLowEnergyDiscoverySession();
432 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 433 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
433 device->CreateGattConnection(GetGattConnectionCallback(), 434 device->CreateGattConnection(GetGattConnectionCallback(),
434 GetConnectErrorCallback()); 435 GetConnectErrorCallback());
435 ResetEventCounts(); 436 ResetEventCounts();
436 SimulateGattConnection(device); 437 SimulateGattConnection(device);
437 EXPECT_EQ(1, gatt_discovery_attempts_); 438 EXPECT_EQ(1, gatt_discovery_attempts_);
438 439
439 std::vector<std::string> services; 440 std::vector<std::string> services;
440 services.push_back("00000000-0000-1000-8000-00805f9b34fb"); 441 services.push_back("00000000-0000-1000-8000-00805f9b34fb");
441 // 2 duplicate UUIDs creating 2 instances. 442 // 2 duplicate UUIDs creating 2 instances.
442 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); 443 services.push_back("00000001-0000-1000-8000-00805f9b34fb");
443 services.push_back("00000001-0000-1000-8000-00805f9b34fb"); 444 services.push_back("00000001-0000-1000-8000-00805f9b34fb");
444 SimulateGattServicesDiscovered(device, services); 445 SimulateGattServicesDiscovered(device, services);
445 EXPECT_EQ(3u, device->GetGattServices().size()); 446 EXPECT_EQ(3u, device->GetGattServices().size());
447
448 // Test GetGattService:
449 std::string service_id1 = device->GetGattServices()[0]->GetIdentifier();
450 std::string service_id2 = device->GetGattServices()[1]->GetIdentifier();
451 std::string service_id3 = device->GetGattServices()[2]->GetIdentifier();
452 EXPECT_TRUE(device->GetGattService(service_id1));
453 EXPECT_TRUE(device->GetGattService(service_id2));
454 EXPECT_TRUE(device->GetGattService(service_id3));
446 } 455 }
447 #endif // defined(OS_ANDROID) 456 #endif // defined(OS_ANDROID)
448 457
449 #if defined(OS_ANDROID) 458 #if defined(OS_ANDROID)
450 TEST_F(BluetoothTest, SimulateGattServicesDiscoveryError) { 459 TEST_F(BluetoothTest, GetGattServices_DiscoveryError) {
451 InitWithFakeAdapter(); 460 InitWithFakeAdapter();
452 StartLowEnergyDiscoverySession(); 461 StartLowEnergyDiscoverySession();
453 BluetoothDevice* device = DiscoverLowEnergyDevice(3); 462 BluetoothDevice* device = DiscoverLowEnergyDevice(3);
454 device->CreateGattConnection(GetGattConnectionCallback(), 463 device->CreateGattConnection(GetGattConnectionCallback(),
455 GetConnectErrorCallback()); 464 GetConnectErrorCallback());
456 ResetEventCounts(); 465 ResetEventCounts();
457 SimulateGattConnection(device); 466 SimulateGattConnection(device);
458 EXPECT_EQ(1, gatt_discovery_attempts_); 467 EXPECT_EQ(1, gatt_discovery_attempts_);
459 468
460 SimulateGattServicesDiscoveryError(device); 469 SimulateGattServicesDiscoveryError(device);
461 EXPECT_EQ(0u, device->GetGattServices().size()); 470 EXPECT_EQ(0u, device->GetGattServices().size());
462 } 471 }
463 #endif // defined(OS_ANDROID) 472 #endif // defined(OS_ANDROID)
464 473
465 } // namespace device 474 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698