Chromium Code Reviews| Index: device/bluetooth/bluez/bluetooth_bluez_unittest.cc |
| diff --git a/device/bluetooth/bluez/bluetooth_bluez_unittest.cc b/device/bluetooth/bluez/bluetooth_bluez_unittest.cc |
| index 8d9e0ae414b13e7e9deab783680e20e7d5a24cca..5aa229868afef5dc1d0317b17add59021311b89b 100644 |
| --- a/device/bluetooth/bluez/bluetooth_bluez_unittest.cc |
| +++ b/device/bluetooth/bluez/bluetooth_bluez_unittest.cc |
| @@ -4486,4 +4486,48 @@ TEST_F(BluetoothBlueZTest, Shutdown_OnStopDiscoveryError) { |
| EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
| } |
| +TEST_F(BluetoothBlueZTest, ServiceDataChanged) { |
| + // Simulate a change of service data of a device. |
| + GetAdapter(); |
| + |
| + BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
|
ortuno
2016/10/05 06:27:09
Just save a pointer to the device:
BluetoothDevic
puthik_chromium
2016/10/06 01:49:56
Done.
|
| + ASSERT_EQ(2U, devices.size()); |
| + |
| + int idx = GetDeviceIndexByAddress( |
| + devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| + ASSERT_NE(-1, idx); |
| + ASSERT_EQ(bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress, |
| + devices[idx]->GetAddress()); |
| + ASSERT_EQ( |
| + base::UTF8ToUTF16(bluez::FakeBluetoothDeviceClient::kPairedDeviceAlias), |
| + devices[idx]->GetNameForDisplay()); |
| + |
| + // Install an observer; expect the DeviceChanged method to be called |
| + // when we change the service data. |
| + TestBluetoothAdapterObserver observer(adapter_); |
| + |
| + bluez::FakeBluetoothDeviceClient::Properties* properties = |
| + fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| + bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| + |
| + static BluetoothUUID kUuid("1f08"); |
|
ortuno
2016/10/05 06:27:09
nit: Can you use kGapUuid?
puthik_chromium
2016/10/06 01:49:56
Sure
|
| + static std::vector<uint8_t> kData = {1, 2, 3, 4, 5}; |
| + std::unordered_map<std::string, std::vector<uint8_t>> service_data; |
|
ortuno
2016/10/05 06:27:09
You could do:
std::unordered_map<std::string, std
puthik_chromium
2016/10/06 01:49:56
Done.
|
| + service_data[kUuid.canonical_value()] = kData; |
| + |
| + properties->service_data.set_valid(true); |
| + properties->service_data.ReplaceValue(service_data); |
|
ortuno
2016/10/05 06:27:10
Could you make this test a bit more thorough? i.e.
puthik_chromium
2016/10/06 01:49:56
Done.
|
| + |
| + EXPECT_EQ(1, observer.device_changed_count()); |
| + EXPECT_EQ(devices[idx], observer.last_device()); |
| + |
| + BluetoothDevice::UUIDSet uuids = devices[idx]->GetServiceDataUUIDs(); |
|
ortuno
2016/10/05 06:27:09
Also test GetServiceData. You can use initializer
puthik_chromium
2016/10/06 01:49:56
Done.
puthik_chromium
2016/10/06 01:49:56
Done.
|
| + EXPECT_EQ(1u, uuids.size()); |
| + EXPECT_EQ(kUuid.canonical_value(), uuids.begin()->canonical_value()); |
|
ortuno
2016/10/05 06:27:09
Using initializer lists will make testing easier a
puthik_chromium
2016/10/06 01:49:56
Done
|
| + const std::vector<uint8_t>* data = devices[idx]->GetServiceDataForUUID(kUuid); |
| + EXPECT_EQ(kData.size(), data->size()); |
| + for (size_t i = 0; i < kData.size(); i++) |
| + EXPECT_EQ(kData[i], (*data)[i]); |
|
ortuno
2016/10/05 06:27:10
Same here:
EXPECT_EQ({1, 2, 3}, *GetServiceDataFo
puthik_chromium
2016/10/06 01:49:56
Done
|
| +} |
| + |
| } // namespace bluez |