summaryrefslogtreecommitdiffstats
path: root/device/bluetooth/bluetooth_bluez_unittest.cc
diff options
context:
space:
mode:
authorjosephsih <josephsih@chromium.org>2016-02-24 02:17:23 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-24 10:18:54 +0000
commit098a1cd80c1398b4bea2c1bc83c5dca686b5b42d (patch)
tree8551038fb7319e42b419d444651827ead956a6a5 /device/bluetooth/bluetooth_bluez_unittest.cc
parent3f96177578cf0511174d42546a70660cc8d6eeeb (diff)
downloadchromium_src-098a1cd80c1398b4bea2c1bc83c5dca686b5b42d.zip
chromium_src-098a1cd80c1398b4bea2c1bc83c5dca686b5b42d.tar.gz
chromium_src-098a1cd80c1398b4bea2c1bc83c5dca686b5b42d.tar.bz2
Determine device type via bluetooth appearance in OOBE
In OOBE, the device type is determined exclusively based on the bluetooth class. However, some keyboards do not advertise the bluetooth class. Instead, the bluetooth appearance is advertised. This patch utilizes the bluetooth appearance to determine the device type if the bluetooth class information is missing. Note that this patch only takes effect on keyboard-less devices such as Mickey and Monroe. BUG=578337, 546616 TEST=Execute the steps below: 1. Let a keyboard-less device boot into OOBE. 2. Unfold Microsoft Universal Foldable Keyboard to power it on. 3. Press Func 1 key on the keyboard for a few seconds until its back light begins blinking. 4. Press "OS" key on the top right corner a few times until Android logo lights on. 3. Observe the pairing takes effect and asks the user to type the pin code. (Without this patch, the pairing never takes effect since the particular keyboard is not considered as a keyboard.) Review URL: https://codereview.chromium.org/1656253002 Cr-Commit-Position: refs/heads/master@{#377257}
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();