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

Side by Side Diff: device/bluetooth/bluez/bluetooth_bluez_unittest.cc

Issue 2244693002: bluetooth: Refactor how we update based on Advertising Data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias), 2155 base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias),
2156 devices[idx]->GetNameForDisplay()); 2156 devices[idx]->GetNameForDisplay());
2157 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType()); 2157 EXPECT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType());
2158 EXPECT_TRUE(devices[idx]->IsPaired()); 2158 EXPECT_TRUE(devices[idx]->IsPaired());
2159 EXPECT_FALSE(devices[idx]->IsConnected()); 2159 EXPECT_FALSE(devices[idx]->IsConnected());
2160 EXPECT_FALSE(devices[idx]->IsConnecting()); 2160 EXPECT_FALSE(devices[idx]->IsConnecting());
2161 2161
2162 // Non HID devices are always connectable. 2162 // Non HID devices are always connectable.
2163 EXPECT_TRUE(devices[idx]->IsConnectable()); 2163 EXPECT_TRUE(devices[idx]->IsConnectable());
2164 2164
2165 BluetoothDevice::UUIDList uuids = devices[idx]->GetUUIDs(); 2165 BluetoothDevice::UUIDSet uuids = devices[idx]->GetUUIDs();
2166 ASSERT_EQ(2U, uuids.size()); 2166 EXPECT_EQ(2U, uuids.size());
2167 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2167 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800")));
2168 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2168 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801")));
2169 2169
2170 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource()); 2170 EXPECT_EQ(BluetoothDevice::VENDOR_ID_USB, devices[idx]->GetVendorIDSource());
2171 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID()); 2171 EXPECT_EQ(0x05ac, devices[idx]->GetVendorID());
2172 EXPECT_EQ(0x030d, devices[idx]->GetProductID()); 2172 EXPECT_EQ(0x030d, devices[idx]->GetProductID());
2173 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID()); 2173 EXPECT_EQ(0x0306, devices[idx]->GetDeviceID());
2174 } 2174 }
2175 2175
2176 TEST_F(BluetoothBlueZTest, DeviceClassChanged) { 2176 TEST_F(BluetoothBlueZTest, DeviceClassChanged) {
2177 // Simulate a change of class of a device, as sometimes occurs 2177 // Simulate a change of class of a device, as sometimes occurs
2178 // during discovery. 2178 // during discovery.
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 2428
2429 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2429 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2430 ASSERT_EQ(2U, devices.size()); 2430 ASSERT_EQ(2U, devices.size());
2431 2431
2432 int idx = GetDeviceIndexByAddress( 2432 int idx = GetDeviceIndexByAddress(
2433 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2433 devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2434 ASSERT_NE(-1, idx); 2434 ASSERT_NE(-1, idx);
2435 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, 2435 ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress,
2436 devices[idx]->GetAddress()); 2436 devices[idx]->GetAddress());
2437 2437
2438 BluetoothDevice::UUIDList uuids = devices[idx]->GetUUIDs(); 2438 BluetoothDevice::UUIDSet uuids = devices[idx]->GetUUIDs();
2439 ASSERT_EQ(2U, uuids.size()); 2439 ASSERT_EQ(2U, uuids.size());
2440 ASSERT_EQ(uuids[0], BluetoothUUID("1800")); 2440 ASSERT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800")));
2441 ASSERT_EQ(uuids[1], BluetoothUUID("1801")); 2441 ASSERT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801")));
2442 2442
2443 // Install an observer; expect the DeviceChanged method to be called when 2443 // Install an observer; expect the DeviceChanged method to be called when
2444 // we change the class of the device. 2444 // we change the class of the device.
2445 TestBluetoothAdapterObserver observer(adapter_); 2445 TestBluetoothAdapterObserver observer(adapter_);
2446 2446
2447 bluez::FakeBluetoothDeviceClient::Properties* properties = 2447 bluez::FakeBluetoothDeviceClient::Properties* properties =
2448 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2448 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2449 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); 2449 bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
2450 2450
2451 std::vector<std::string> new_uuids; 2451 std::vector<std::string> new_uuids;
2452 new_uuids.push_back(uuids[0].canonical_value()); 2452 new_uuids.push_back(BluetoothUUID("1800").canonical_value());
2453 new_uuids.push_back(uuids[1].canonical_value()); 2453 new_uuids.push_back(BluetoothUUID("1801").canonical_value());
2454 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb"); 2454 new_uuids.push_back("0000110c-0000-1000-8000-00805f9b34fb");
2455 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb"); 2455 new_uuids.push_back("0000110e-0000-1000-8000-00805f9b34fb");
2456 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb"); 2456 new_uuids.push_back("0000110a-0000-1000-8000-00805f9b34fb");
2457 2457
2458 properties->uuids.ReplaceValue(new_uuids); 2458 properties->uuids.ReplaceValue(new_uuids);
2459 2459
2460 EXPECT_EQ(1, observer.device_changed_count()); 2460 EXPECT_EQ(1, observer.device_changed_count());
2461 EXPECT_EQ(devices[idx], observer.last_device()); 2461 EXPECT_EQ(devices[idx], observer.last_device());
2462 2462
2463 // Fetching the value should give the new one. 2463 // Fetching the value should give the new one.
2464 uuids = devices[idx]->GetUUIDs(); 2464 uuids = devices[idx]->GetUUIDs();
2465 ASSERT_EQ(5U, uuids.size()); 2465 EXPECT_EQ(5U, uuids.size());
2466 EXPECT_EQ(uuids[0], BluetoothUUID("1800")); 2466 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1800")));
2467 EXPECT_EQ(uuids[1], BluetoothUUID("1801")); 2467 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1801")));
2468 EXPECT_EQ(uuids[2], BluetoothUUID("110c")); 2468 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("110c")));
2469 EXPECT_EQ(uuids[3], BluetoothUUID("110e")); 2469 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("110e")));
2470 EXPECT_EQ(uuids[4], BluetoothUUID("110a")); 2470 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("110a")));
2471 } 2471 }
2472 2472
2473 TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIInvalidated) { 2473 TEST_F(BluetoothBlueZTest, DeviceInquiryRSSIInvalidated) {
2474 // Simulate invalidation of inquiry RSSI of a device, as it occurs 2474 // Simulate invalidation of inquiry RSSI of a device, as it occurs
2475 // when discovery is finished. 2475 // when discovery is finished.
2476 GetAdapter(); 2476 GetAdapter();
2477 2477
2478 BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); 2478 BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
2479 ASSERT_EQ(2U, devices.size()); 2479 ASSERT_EQ(2U, devices.size());
2480 2480
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 EXPECT_TRUE(device->IsConnected()); 2683 EXPECT_TRUE(device->IsConnected());
2684 EXPECT_FALSE(device->IsConnecting()); 2684 EXPECT_FALSE(device->IsConnecting());
2685 2685
2686 // Make sure the trusted property has been set to true. 2686 // Make sure the trusted property has been set to true.
2687 bluez::FakeBluetoothDeviceClient::Properties* properties = 2687 bluez::FakeBluetoothDeviceClient::Properties* properties =
2688 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2688 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2689 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath)); 2689 bluez::FakeBluetoothDeviceClient::kConnectUnpairablePath));
2690 EXPECT_TRUE(properties->trusted.value()); 2690 EXPECT_TRUE(properties->trusted.value());
2691 2691
2692 // Verify is a HID device and is not connectable. 2692 // Verify is a HID device and is not connectable.
2693 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 2693 BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
2694 ASSERT_EQ(1U, uuids.size()); 2694 EXPECT_EQ(1U, uuids.size());
2695 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2695 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1124")));
2696 EXPECT_FALSE(device->IsConnectable()); 2696 EXPECT_FALSE(device->IsConnectable());
2697 } 2697 }
2698 2698
2699 TEST_F(BluetoothBlueZTest, ConnectConnectedDevice) { 2699 TEST_F(BluetoothBlueZTest, ConnectConnectedDevice) {
2700 GetAdapter(); 2700 GetAdapter();
2701 2701
2702 BluetoothDevice* device = adapter_->GetDevice( 2702 BluetoothDevice* device = adapter_->GetDevice(
2703 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); 2703 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
2704 ASSERT_TRUE(device != nullptr); 2704 ASSERT_TRUE(device != nullptr);
2705 ASSERT_TRUE(device->IsPaired()); 2705 ASSERT_TRUE(device->IsPaired());
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
2931 // mode (IsConnectable). 2931 // mode (IsConnectable).
2932 EXPECT_EQ(7, observer.device_changed_count()); 2932 EXPECT_EQ(7, observer.device_changed_count());
2933 EXPECT_EQ(device, observer.last_device()); 2933 EXPECT_EQ(device, observer.last_device());
2934 2934
2935 EXPECT_TRUE(device->IsConnected()); 2935 EXPECT_TRUE(device->IsConnected());
2936 EXPECT_FALSE(device->IsConnecting()); 2936 EXPECT_FALSE(device->IsConnecting());
2937 2937
2938 EXPECT_TRUE(device->IsPaired()); 2938 EXPECT_TRUE(device->IsPaired());
2939 2939
2940 // Verify is a HID device and is connectable. 2940 // Verify is a HID device and is connectable.
2941 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 2941 BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
2942 ASSERT_EQ(1U, uuids.size()); 2942 EXPECT_EQ(1U, uuids.size());
2943 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2943 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1124")));
2944 EXPECT_TRUE(device->IsConnectable()); 2944 EXPECT_TRUE(device->IsConnectable());
2945 2945
2946 // Make sure the trusted property has been set to true. 2946 // Make sure the trusted property has been set to true.
2947 bluez::FakeBluetoothDeviceClient::Properties* properties = 2947 bluez::FakeBluetoothDeviceClient::Properties* properties =
2948 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 2948 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
2949 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath)); 2949 bluez::FakeBluetoothDeviceClient::kLegacyAutopairPath));
2950 EXPECT_TRUE(properties->trusted.value()); 2950 EXPECT_TRUE(properties->trusted.value());
2951 } 2951 }
2952 2952
2953 TEST_F(BluetoothBlueZTest, PairDisplayPinCode) { 2953 TEST_F(BluetoothBlueZTest, PairDisplayPinCode) {
(...skipping 30 matching lines...) Expand all
2984 // mode (IsConnectable). 2984 // mode (IsConnectable).
2985 EXPECT_EQ(7, observer.device_changed_count()); 2985 EXPECT_EQ(7, observer.device_changed_count());
2986 EXPECT_EQ(device, observer.last_device()); 2986 EXPECT_EQ(device, observer.last_device());
2987 2987
2988 EXPECT_TRUE(device->IsConnected()); 2988 EXPECT_TRUE(device->IsConnected());
2989 EXPECT_FALSE(device->IsConnecting()); 2989 EXPECT_FALSE(device->IsConnecting());
2990 2990
2991 EXPECT_TRUE(device->IsPaired()); 2991 EXPECT_TRUE(device->IsPaired());
2992 2992
2993 // Verify is a HID device and is connectable. 2993 // Verify is a HID device and is connectable.
2994 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 2994 BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
2995 ASSERT_EQ(1U, uuids.size()); 2995 EXPECT_EQ(1U, uuids.size());
2996 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 2996 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1124")));
2997 EXPECT_TRUE(device->IsConnectable()); 2997 EXPECT_TRUE(device->IsConnectable());
2998 2998
2999 // Make sure the trusted property has been set to true. 2999 // Make sure the trusted property has been set to true.
3000 bluez::FakeBluetoothDeviceClient::Properties* properties = 3000 bluez::FakeBluetoothDeviceClient::Properties* properties =
3001 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3001 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3002 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath)); 3002 bluez::FakeBluetoothDeviceClient::kDisplayPinCodePath));
3003 EXPECT_TRUE(properties->trusted.value()); 3003 EXPECT_TRUE(properties->trusted.value());
3004 } 3004 }
3005 3005
3006 TEST_F(BluetoothBlueZTest, PairDisplayPasskey) { 3006 TEST_F(BluetoothBlueZTest, PairDisplayPasskey) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3057 // mode (IsConnectable). 3057 // mode (IsConnectable).
3058 EXPECT_EQ(7, observer.device_changed_count()); 3058 EXPECT_EQ(7, observer.device_changed_count());
3059 EXPECT_EQ(device, observer.last_device()); 3059 EXPECT_EQ(device, observer.last_device());
3060 3060
3061 EXPECT_TRUE(device->IsConnected()); 3061 EXPECT_TRUE(device->IsConnected());
3062 EXPECT_FALSE(device->IsConnecting()); 3062 EXPECT_FALSE(device->IsConnecting());
3063 3063
3064 EXPECT_TRUE(device->IsPaired()); 3064 EXPECT_TRUE(device->IsPaired());
3065 3065
3066 // Verify is a HID device. 3066 // Verify is a HID device.
3067 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 3067 BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
3068 ASSERT_EQ(1U, uuids.size()); 3068 EXPECT_EQ(1U, uuids.size());
3069 EXPECT_EQ(uuids[0], BluetoothUUID("1124")); 3069 EXPECT_TRUE(base::ContainsKey(uuids, BluetoothUUID("1124")));
3070 3070
3071 // And usually not connectable. 3071 // And usually not connectable.
3072 EXPECT_FALSE(device->IsConnectable()); 3072 EXPECT_FALSE(device->IsConnectable());
3073 3073
3074 // Make sure the trusted property has been set to true. 3074 // Make sure the trusted property has been set to true.
3075 bluez::FakeBluetoothDeviceClient::Properties* properties = 3075 bluez::FakeBluetoothDeviceClient::Properties* properties =
3076 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3076 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3077 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath)); 3077 bluez::FakeBluetoothDeviceClient::kDisplayPasskeyPath));
3078 EXPECT_TRUE(properties->trusted.value()); 3078 EXPECT_TRUE(properties->trusted.value());
3079 } 3079 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 // two for trusted (after pairing and connection). 3112 // two for trusted (after pairing and connection).
3113 EXPECT_EQ(6, observer.device_changed_count()); 3113 EXPECT_EQ(6, observer.device_changed_count());
3114 EXPECT_EQ(device, observer.last_device()); 3114 EXPECT_EQ(device, observer.last_device());
3115 3115
3116 EXPECT_TRUE(device->IsConnected()); 3116 EXPECT_TRUE(device->IsConnected());
3117 EXPECT_FALSE(device->IsConnecting()); 3117 EXPECT_FALSE(device->IsConnecting());
3118 3118
3119 EXPECT_TRUE(device->IsPaired()); 3119 EXPECT_TRUE(device->IsPaired());
3120 3120
3121 // Verify is not a HID device. 3121 // Verify is not a HID device.
3122 BluetoothDevice::UUIDList uuids = device->GetUUIDs(); 3122 BluetoothDevice::UUIDSet uuids = device->GetUUIDs();
3123 ASSERT_EQ(0U, uuids.size()); 3123 EXPECT_EQ(0U, uuids.size());
3124 3124
3125 // Non HID devices are always connectable. 3125 // Non HID devices are always connectable.
3126 EXPECT_TRUE(device->IsConnectable()); 3126 EXPECT_TRUE(device->IsConnectable());
3127 3127
3128 // Make sure the trusted property has been set to true. 3128 // Make sure the trusted property has been set to true.
3129 bluez::FakeBluetoothDeviceClient::Properties* properties = 3129 bluez::FakeBluetoothDeviceClient::Properties* properties =
3130 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( 3130 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
3131 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath)); 3131 bluez::FakeBluetoothDeviceClient::kRequestPinCodePath));
3132 EXPECT_TRUE(properties->trusted.value()); 3132 EXPECT_TRUE(properties->trusted.value());
3133 } 3133 }
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after
4507 adapter_->Shutdown(); 4507 adapter_->Shutdown();
4508 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); 4508 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", "");
4509 4509
4510 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, 4510 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError,
4511 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. 4511 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession.
4512 EXPECT_EQ(0, callback_count_); 4512 EXPECT_EQ(0, callback_count_);
4513 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); 4513 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_);
4514 } 4514 }
4515 4515
4516 } // namespace bluez 4516 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698