summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_bluez_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'device/bluetooth/bluetooth_bluez_unittest.cc')
-rw-r--r--device/bluetooth/bluetooth_bluez_unittest.cc112
1 files changed, 112 insertions, 0 deletions
diff --git a/device/bluetooth/bluetooth_bluez_unittest.cc b/device/bluetooth/bluetooth_bluez_unittest.cc
index 309aec0..f99caab 100644
--- a/device/bluetooth/bluetooth_bluez_unittest.cc
+++ b/device/bluetooth/bluetooth_bluez_unittest.cc
@@ -2160,6 +2160,118 @@ TEST_F(BluetoothBlueZTest, DeviceClassChanged) {
EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType());
}
+TEST_F(BluetoothBlueZTest, DeviceAppearance) {
+ // Simulate a device with appearance.
+ GetAdapter();
+
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+ ASSERT_EQ(2U, devices.size());
+
+ int idx = GetDeviceIndexByAddress(
+ devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
+ ASSERT_NE(-1, idx);
+ ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType());
+
+ // Install an observer; expect the DeviceChanged method to be called when
+ // we change the appearance of the device.
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
+ bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
+
+ // Let the device come without bluetooth_class.
+ properties->appearance.ReplaceValue(0); // DeviceChanged method called
+ EXPECT_EQ(1, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+
+ // Set the device appearance as keyboard (961).
+ properties->appearance.ReplaceValue(961); // DeviceChanged method called
+ properties->appearance.set_valid(true);
+ EXPECT_EQ(2, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ EXPECT_EQ(961, devices[idx]->GetAppearance());
+ // When discovery is over, the value should be invalidated.
+ properties->appearance.set_valid(false);
+ // DeviceChanged method called by NotifyPropertyChanged()
+ properties->NotifyPropertyChanged(properties->appearance.name());
+ EXPECT_EQ(3, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ EXPECT_EQ((int) BluetoothDevice::kAppearanceNotPresent,
+ devices[idx]->GetAppearance());
+
+ // Change the device appearance to mouse (962).
+ properties->appearance.ReplaceValue(962); // DeviceChanged method called
+ properties->appearance.set_valid(true);
+ EXPECT_EQ(4, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ EXPECT_EQ(962, devices[idx]->GetAppearance());
+ // When discovery is over, the value should be invalidated.
+ properties->appearance.set_valid(false);
+ // DeviceChanged method called by NotifyPropertyChanged()
+ properties->NotifyPropertyChanged(properties->appearance.name());
+ EXPECT_EQ(5, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ EXPECT_EQ((int) BluetoothDevice::kAppearanceNotPresent,
+ devices[idx]->GetAppearance());
+}
+
+TEST_F(BluetoothBlueZTest, DeviceTypebyAppearanceNotBluetoothClass) {
+ // Test device type of a device with appearance but without bluetooth class.
+ GetAdapter();
+
+ BluetoothAdapter::DeviceList devices = adapter_->GetDevices();
+ ASSERT_EQ(2U, devices.size());
+
+ int idx = GetDeviceIndexByAddress(
+ devices, bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress);
+ ASSERT_NE(-1, idx);
+ ASSERT_EQ(BluetoothDevice::DEVICE_COMPUTER, devices[idx]->GetDeviceType());
+
+ // Install an observer; expect the DeviceChanged method to be called when
+ // we change the appearance of the device.
+ TestBluetoothAdapterObserver observer(adapter_);
+
+ bluez::FakeBluetoothDeviceClient::Properties* properties =
+ fake_bluetooth_device_client_->GetProperties(dbus::ObjectPath(
+ bluez::FakeBluetoothDeviceClient::kPairedDevicePath));
+
+ // Let the device come without bluetooth_class.
+ properties->bluetooth_class.ReplaceValue(0); // DeviceChanged method called
+ properties->appearance.ReplaceValue(0); // DeviceChanged method called
+ EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType());
+ EXPECT_EQ(2, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+
+ // Set the device appearance as keyboard.
+ properties->appearance.ReplaceValue(961); // DeviceChanged method called
+ properties->appearance.set_valid(true);
+ EXPECT_EQ(BluetoothDevice::DEVICE_KEYBOARD, devices[idx]->GetDeviceType());
+ EXPECT_EQ(3, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ // When discovery is over, the value should be invalidated.
+ properties->appearance.set_valid(false);
+ // DeviceChanged method called by NotifyPropertyChanged()
+ properties->NotifyPropertyChanged(properties->appearance.name());
+ EXPECT_EQ(4, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType());
+
+ // Change the device appearance to mouse.
+ properties->appearance.ReplaceValue(962); // DeviceChanged method called
+ properties->appearance.set_valid(true);
+ EXPECT_EQ(BluetoothDevice::DEVICE_MOUSE, devices[idx]->GetDeviceType());
+ EXPECT_EQ(5, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ // When discovery is over, the value should be invalidated.
+ properties->appearance.set_valid(false);
+ // DeviceChanged method called by NotifyPropertyChanged()
+ properties->NotifyPropertyChanged(properties->appearance.name());
+ EXPECT_EQ(6, observer.device_changed_count());
+ EXPECT_EQ(devices[idx], observer.last_device());
+ EXPECT_EQ(BluetoothDevice::DEVICE_UNKNOWN, devices[idx]->GetDeviceType());
+}
+
TEST_F(BluetoothBlueZTest, DeviceNameChanged) {
// Simulate a change of name of a device.
GetAdapter();