OLD | NEW |
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 4468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4479 } | 4479 } |
4480 adapter_->Shutdown(); | 4480 adapter_->Shutdown(); |
4481 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); | 4481 adapter_bluez->OnStopDiscoveryError(GetDiscoveryErrorCallback(), "", ""); |
4482 | 4482 |
4483 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, | 4483 // 1 error reported to RemoveDiscoverySession because of OnStopDiscoveryError, |
4484 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. | 4484 // and kNumberOfDiscoverySessions errors queued with AddDiscoverySession. |
4485 EXPECT_EQ(0, callback_count_); | 4485 EXPECT_EQ(0, callback_count_); |
4486 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); | 4486 EXPECT_EQ(1 + kNumberOfDiscoverySessions, error_callback_count_); |
4487 } | 4487 } |
4488 | 4488 |
| 4489 TEST_F(BluetoothBlueZTest, ServiceDataChanged) { |
| 4490 // Simulate a change of service data of a device. |
| 4491 GetAdapter(); |
| 4492 |
| 4493 BluetoothDevice* device = adapter_->GetDevice( |
| 4494 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 4495 |
| 4496 // Install an observer; expect the DeviceChanged method to be called |
| 4497 // when we change the service data. |
| 4498 TestBluetoothAdapterObserver observer(adapter_); |
| 4499 |
| 4500 bluez::FakeBluetoothDeviceClient::Properties* properties = |
| 4501 fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath( |
| 4502 bluez::FakeBluetoothDeviceClient::kPairedDevicePath)); |
| 4503 |
| 4504 properties->service_data.set_valid(true); |
| 4505 |
| 4506 // Check that ServiceDataChanged is correctly invoke. |
| 4507 properties->service_data.ReplaceValue({{kGapUuid, {1, 2, 3}}}); |
| 4508 EXPECT_EQ(1, observer.device_changed_count()); |
| 4509 EXPECT_EQ(device, observer.last_device()); |
| 4510 EXPECT_EQ( |
| 4511 BluetoothDevice::ServiceDataMap({{BluetoothUUID(kGapUuid), {1, 2, 3}}}), |
| 4512 device->GetServiceData()); |
| 4513 EXPECT_EQ(BluetoothDevice::UUIDSet({BluetoothUUID(kGapUuid)}), |
| 4514 device->GetServiceDataUUIDs()); |
| 4515 EXPECT_EQ(std::vector<uint8_t>({1, 2, 3}), |
| 4516 *(device->GetServiceDataForUUID(BluetoothUUID(kGapUuid)))); |
| 4517 |
| 4518 // Check that we can update service data with same uuid / add more uuid. |
| 4519 properties->service_data.ReplaceValue( |
| 4520 {{kGapUuid, {3, 2, 1}}, {kGattUuid, {1}}}); |
| 4521 EXPECT_EQ(2, observer.device_changed_count()); |
| 4522 EXPECT_EQ(device, observer.last_device()); |
| 4523 |
| 4524 EXPECT_EQ( |
| 4525 BluetoothDevice::ServiceDataMap({{BluetoothUUID(kGapUuid), {3, 2, 1}}, |
| 4526 {BluetoothUUID(kGattUuid), {1}}}), |
| 4527 device->GetServiceData()); |
| 4528 EXPECT_EQ(BluetoothDevice::UUIDSet( |
| 4529 {BluetoothUUID(kGapUuid), BluetoothUUID(kGattUuid)}), |
| 4530 device->GetServiceDataUUIDs()); |
| 4531 EXPECT_EQ(std::vector<uint8_t>({3, 2, 1}), |
| 4532 *(device->GetServiceDataForUUID(BluetoothUUID(kGapUuid)))); |
| 4533 EXPECT_EQ(std::vector<uint8_t>({1}), |
| 4534 *(device->GetServiceDataForUUID(BluetoothUUID(kGattUuid)))); |
| 4535 |
| 4536 // Check that we can remove uuid / change uuid with same data. |
| 4537 properties->service_data.ReplaceValue({{kPnpUuid, {3, 2, 1}}}); |
| 4538 EXPECT_EQ(3, observer.device_changed_count()); |
| 4539 EXPECT_EQ(device, observer.last_device()); |
| 4540 |
| 4541 EXPECT_EQ( |
| 4542 BluetoothDevice::ServiceDataMap({{BluetoothUUID(kPnpUuid), {3, 2, 1}}}), |
| 4543 device->GetServiceData()); |
| 4544 EXPECT_EQ(BluetoothDevice::UUIDSet({BluetoothUUID(kPnpUuid)}), |
| 4545 device->GetServiceDataUUIDs()); |
| 4546 EXPECT_EQ(std::vector<uint8_t>({3, 2, 1}), |
| 4547 *(device->GetServiceDataForUUID(BluetoothUUID(kPnpUuid)))); |
| 4548 EXPECT_EQ(nullptr, device->GetServiceDataForUUID(BluetoothUUID(kGapUuid))); |
| 4549 EXPECT_EQ(nullptr, device->GetServiceDataForUUID(BluetoothUUID(kGattUuid))); |
| 4550 } |
| 4551 |
4489 } // namespace bluez | 4552 } // namespace bluez |
OLD | NEW |