summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chromeos/dbus/fake_bluetooth_device_client.cc46
-rw-r--r--chromeos/dbus/fake_bluetooth_device_client.h8
-rw-r--r--device/bluetooth/bluetooth_device_experimental_chromeos.cc2
-rw-r--r--device/bluetooth/bluetooth_experimental_chromeos_unittest.cc43
4 files changed, 99 insertions, 0 deletions
diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/chromeos/dbus/fake_bluetooth_device_client.cc
index 3c6e440..4d3e189 100644
--- a/chromeos/dbus/fake_bluetooth_device_client.cc
+++ b/chromeos/dbus/fake_bluetooth_device_client.cc
@@ -112,6 +112,14 @@ const char FakeBluetoothDeviceClient::kUnconnectableDeviceName[] =
"Unconnectable Device";
const uint32 FakeBluetoothDeviceClient::kUnconnectableDeviceClass = 0x7a020c;
+const char FakeBluetoothDeviceClient::kUnpairableDevicePath[] =
+ "/fake/hci0/devA";
+const char FakeBluetoothDeviceClient::kUnpairableDeviceAddress[] =
+ "20:7D:74:00:00:03";
+const char FakeBluetoothDeviceClient::kUnpairableDeviceName[] =
+ "Unpairable Device";
+const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540;
+
FakeBluetoothDeviceClient::Properties::Properties(
const PropertyChangedCallback& callback)
: ExperimentalBluetoothDeviceClient::Properties(
@@ -372,6 +380,15 @@ void FakeBluetoothDeviceClient::Pair(
callback,
error_callback));
+ } else if (object_path == dbus::ObjectPath(kUnpairableDevicePath)) {
+ // Fails the pairing with an org.bluez.Error.Failed error.
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&FakeBluetoothDeviceClient::FailSimulatedPairing,
+ base::Unretained(this),
+ object_path, error_callback),
+ base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
+
} else {
error_callback.Run(kNoResponseError, "No pairing fake");
}
@@ -652,6 +669,27 @@ void FakeBluetoothDeviceClient::DiscoverySimulationTimer() {
DeviceAdded(dbus::ObjectPath(kUnconnectableDevicePath)));
}
+ if (std::find(device_list_.begin(), device_list_.end(),
+ dbus::ObjectPath(kUnpairableDevicePath)) ==
+ device_list_.end()) {
+ Properties* properties = new Properties(base::Bind(
+ &FakeBluetoothDeviceClient::OnPropertyChanged,
+ base::Unretained(this),
+ dbus::ObjectPath(kUnpairableDevicePath)));
+ properties->address.ReplaceValue(kUnpairableDeviceAddress);
+ properties->bluetooth_class.ReplaceValue(kUnpairableDeviceClass);
+ properties->name.ReplaceValue("Fake Unpairable Device");
+ properties->alias.ReplaceValue(kUnpairableDeviceName);
+ properties->adapter.ReplaceValue(
+ dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
+
+ properties_map_[dbus::ObjectPath(kUnpairableDevicePath)] = properties;
+ device_list_.push_back(dbus::ObjectPath(kUnpairableDevicePath));
+ FOR_EACH_OBSERVER(
+ ExperimentalBluetoothDeviceClient::Observer, observers_,
+ DeviceAdded(dbus::ObjectPath(kUnpairableDevicePath)));
+ }
+
} else if (discovery_simulation_step_ == 13) {
RemoveDevice(dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath),
dbus::ObjectPath(kVanishingDevicePath));
@@ -717,6 +755,14 @@ void FakeBluetoothDeviceClient::RejectSimulatedPairing(
"Rejected");
}
+void FakeBluetoothDeviceClient::FailSimulatedPairing(
+ const dbus::ObjectPath& object_path,
+ const ErrorCallback& error_callback) {
+ VLOG(1) << "FailSimulatedPairing: " << object_path.value();
+
+ error_callback.Run(bluetooth_adapter::kErrorFailed, "Failed");
+}
+
void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded(
const dbus::ObjectPath& object_path,
Properties* properties) {
diff --git a/chromeos/dbus/fake_bluetooth_device_client.h b/chromeos/dbus/fake_bluetooth_device_client.h
index f5ac24c..9ce85b2 100644
--- a/chromeos/dbus/fake_bluetooth_device_client.h
+++ b/chromeos/dbus/fake_bluetooth_device_client.h
@@ -131,6 +131,11 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient
static const char kUnconnectableDeviceAddress[];
static const uint32 kUnconnectableDeviceClass;
+ static const char kUnpairableDevicePath[];
+ static const char kUnpairableDeviceName[];
+ static const char kUnpairableDeviceAddress[];
+ static const uint32 kUnpairableDeviceClass;
+
private:
// Property callback passed when we create Properties* structures.
void OnPropertyChanged(const dbus::ObjectPath& object_path,
@@ -151,6 +156,9 @@ class CHROMEOS_EXPORT FakeBluetoothDeviceClient
void RejectSimulatedPairing(
const dbus::ObjectPath& object_path,
const ErrorCallback& error_callback);
+ void FailSimulatedPairing(
+ const dbus::ObjectPath& object_path,
+ const ErrorCallback& error_callback);
void AddInputDeviceIfNeeded(
const dbus::ObjectPath& object_path,
Properties* properties);
diff --git a/device/bluetooth/bluetooth_device_experimental_chromeos.cc b/device/bluetooth/bluetooth_device_experimental_chromeos.cc
index fb45ad0..35478d9 100644
--- a/device/bluetooth/bluetooth_device_experimental_chromeos.cc
+++ b/device/bluetooth/bluetooth_device_experimental_chromeos.cc
@@ -682,6 +682,8 @@ void BluetoothDeviceExperimentalChromeOS::OnPairError(
ConnectErrorCode error_code = ERROR_UNKNOWN;
if (error_name == bluetooth_adapter::kErrorConnectionAttemptFailed) {
error_code = ERROR_FAILED;
+ } else if (error_name == bluetooth_adapter::kErrorFailed) {
+ error_code = ERROR_FAILED;
} else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) {
error_code = ERROR_AUTH_FAILED;
} else if (error_name == bluetooth_adapter::kErrorAuthenticationCanceled) {
diff --git a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc
index afd8325..0dc3ad5 100644
--- a/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc
+++ b/device/bluetooth/bluetooth_experimental_chromeos_unittest.cc
@@ -1559,6 +1559,49 @@ TEST_F(BluetoothExperimentalChromeOSTest, PairWeirdDevice) {
EXPECT_TRUE(properties->trusted.value());
}
+TEST_F(BluetoothExperimentalChromeOSTest, PairUnpairableDeviceFails) {
+ base::MessageLoop message_loop(base::MessageLoop::TYPE_DEFAULT);
+ fake_bluetooth_device_client_->SetSimulationIntervalMs(10);
+
+ GetAdapter();
+ DiscoverDevice(FakeBluetoothDeviceClient::kUnconnectableDeviceAddress);
+
+ BluetoothDevice* device = adapter_->GetDevice(
+ FakeBluetoothDeviceClient::kUnpairableDeviceAddress);
+ ASSERT_TRUE(device != NULL);
+ ASSERT_FALSE(device->IsPaired());
+
+ TestObserver observer(adapter_);
+ adapter_->AddObserver(&observer);
+
+ TestPairingDelegate pairing_delegate;
+ device->Connect(
+ &pairing_delegate,
+ base::Bind(&BluetoothExperimentalChromeOSTest::Callback,
+ base::Unretained(this)),
+ base::Bind(&BluetoothExperimentalChromeOSTest::ConnectErrorCallback,
+ base::Unretained(this)));
+
+ EXPECT_EQ(0, pairing_delegate.call_count_);
+ EXPECT_TRUE(device->IsConnecting());
+
+ // Run the loop to get the error..
+ message_loop.Run();
+
+ EXPECT_EQ(0, callback_count_);
+ EXPECT_EQ(1, error_callback_count_);
+
+ EXPECT_EQ(BluetoothDevice::ERROR_FAILED, last_connect_error_);
+
+ EXPECT_FALSE(device->IsConnected());
+ EXPECT_FALSE(device->IsConnecting());
+ EXPECT_FALSE(device->IsPaired());
+
+ // Pairing dialog should be dismissed
+ EXPECT_EQ(1, pairing_delegate.call_count_);
+ EXPECT_EQ(1, pairing_delegate.dismiss_count_);
+}
+
TEST_F(BluetoothExperimentalChromeOSTest, PairingFails) {
base::MessageLoop message_loop(base::MessageLoop::TYPE_DEFAULT);
fake_bluetooth_device_client_->SetSimulationIntervalMs(10);