summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc')
-rw-r--r--chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc209
1 files changed, 209 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc
index 2a3d520..8b3f1b4 100644
--- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc
+++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_unittest.cc
@@ -103,6 +103,56 @@ TEST_F(BluetoothAdapterTest, DefaultAdapterWithAddress) {
EXPECT_EQ(adapter_address, adapter->address());
}
+TEST_F(BluetoothAdapterTest, DefaultAdapterWithoutAddress) {
+ const dbus::ObjectPath adapter_path("/fake/hci0");
+ const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
+
+ // Create the default adapter instance;
+ // BluetoothManagerClient::DefaultAdapter will be called once, passing
+ // a callback to obtain the adapter path.
+ BluetoothManagerClient::AdapterCallback adapter_callback;
+ EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
+ .WillOnce(SaveArg<0>(&adapter_callback));
+
+ scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter();
+
+ // Call the adapter callback;
+ // BluetoothAdapterClient::GetProperties will be called once to obtain
+ // the property set.
+ MockBluetoothAdapterClient::Properties adapter_properties;
+
+ EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
+ .WillRepeatedly(Return(&adapter_properties));
+
+ // BluetoothAdapter::Observer::AdapterPresentChanged must not be called
+ // yet.
+ MockBluetoothAdapter::Observer adapter_observer;
+ adapter->AddObserver(&adapter_observer);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _))
+ .Times(0);
+
+ adapter_callback.Run(adapter_path, true);
+
+ // Adapter should not be present yet.
+ EXPECT_FALSE(adapter->IsPresent());
+
+ // Tell the adapter the address now;
+ // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
+ adapter_properties.address.ReplaceValue(adapter_address);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true))
+ .Times(1);
+
+ static_cast<BluetoothAdapterClient::Observer*>(adapter.get())
+ ->AdapterPropertyChanged(adapter_path,
+ adapter_properties.address.name());
+
+ // Adapter should be present with the given address.
+ EXPECT_TRUE(adapter->IsPresent());
+ EXPECT_EQ(adapter_address, adapter->address());
+}
+
TEST_F(BluetoothAdapterTest, DefaultAdapterBecomesPresentWithAddress) {
const dbus::ObjectPath adapter_path("/fake/hci0");
const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
@@ -178,6 +228,49 @@ TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithAddress) {
EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
.WillRepeatedly(Return(&new_adapter_properties));
+ // BluetoothAdapter::Observer::AdapterPresentChanged must be called once
+ // with false to indicate the old adapter being removed and once with true
+ // to announce the new adapter.
+ MockBluetoothAdapter::Observer adapter_observer;
+ adapter->AddObserver(&adapter_observer);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false))
+ .Times(1);
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true))
+ .Times(1);
+
+ static_cast<BluetoothManagerClient::Observer*>(adapter.get())
+ ->DefaultAdapterChanged(new_adapter_path);
+
+ // Adapter should be present with the new address.
+ EXPECT_TRUE(adapter->IsPresent());
+ EXPECT_EQ(new_adapter_address, adapter->address());
+}
+
+TEST_F(BluetoothAdapterTest, DefaultAdapterBecomesPresentWithoutAddress) {
+ const dbus::ObjectPath adapter_path("/fake/hci0");
+ const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
+
+ // Create the default adapter instance;
+ // BluetoothManagerClient::DefaultAdapter will be called once, passing
+ // a callback to obtain the adapter path.
+ BluetoothManagerClient::AdapterCallback adapter_callback;
+ EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
+ .WillOnce(SaveArg<0>(&adapter_callback));
+
+ scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter();
+
+ // Call the adapter callback; make out it failed.
+ adapter_callback.Run(dbus::ObjectPath(""), false);
+
+ // Tell the adapter the default adapter changed;
+ // BluetoothAdapterClient::GetProperties will be called once to obtain
+ // the property set.
+ MockBluetoothAdapterClient::Properties adapter_properties;
+
+ EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
+ .WillRepeatedly(Return(&adapter_properties));
+
// BluetoothAdapter::Observer::AdapterPresentChanged must not be called.
MockBluetoothAdapter::Observer adapter_observer;
adapter->AddObserver(&adapter_observer);
@@ -186,8 +279,86 @@ TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithAddress) {
.Times(0);
static_cast<BluetoothManagerClient::Observer*>(adapter.get())
+ ->DefaultAdapterChanged(adapter_path);
+
+ // Adapter should not be present yet.
+ EXPECT_FALSE(adapter->IsPresent());
+
+ // Tell the adapter the address now;
+ // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
+ adapter_properties.address.ReplaceValue(adapter_address);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true))
+ .Times(1);
+
+ static_cast<BluetoothAdapterClient::Observer*>(adapter.get())
+ ->AdapterPropertyChanged(adapter_path,
+ adapter_properties.address.name());
+
+ // Adapter should be present with the new address.
+ EXPECT_TRUE(adapter->IsPresent());
+ EXPECT_EQ(adapter_address, adapter->address());
+}
+
+TEST_F(BluetoothAdapterTest, DefaultAdapterReplacedWithoutAddress) {
+ const dbus::ObjectPath initial_adapter_path("/fake/hci0");
+ const dbus::ObjectPath new_adapter_path("/fake/hci1");
+ const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
+ const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
+
+ // Create the default adapter instance;
+ // BluetoothManagerClient::DefaultAdapter will be called once, passing
+ // a callback to obtain the adapter path.
+ BluetoothManagerClient::AdapterCallback adapter_callback;
+ EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
+ .WillOnce(SaveArg<0>(&adapter_callback));
+
+ scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter();
+
+ // Call the adapter callback;
+ // BluetoothAdapterClient::GetProperties will be called once to obtain
+ // the property set.
+ MockBluetoothAdapterClient::Properties initial_adapter_properties;
+ initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
+
+ EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
+ .WillRepeatedly(Return(&initial_adapter_properties));
+
+ adapter_callback.Run(initial_adapter_path, true);
+
+ // Tell the adapter the default adapter changed;
+ // BluetoothAdapterClient::GetProperties will be called once to obtain
+ // the property set.
+ MockBluetoothAdapterClient::Properties new_adapter_properties;
+
+ EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
+ .WillRepeatedly(Return(&new_adapter_properties));
+
+ // BluetoothAdapter::Observer::AdapterPresentChanged must be called to
+ // indicate the adapter has gone away.
+ MockBluetoothAdapter::Observer adapter_observer;
+ adapter->AddObserver(&adapter_observer);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), false))
+ .Times(1);
+
+ static_cast<BluetoothManagerClient::Observer*>(adapter.get())
->DefaultAdapterChanged(new_adapter_path);
+ // Adapter should be now marked not present.
+ EXPECT_FALSE(adapter->IsPresent());
+
+ // Tell the adapter the address now;
+ // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
+ new_adapter_properties.address.ReplaceValue(new_adapter_address);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), true))
+ .Times(1);
+
+ static_cast<BluetoothAdapterClient::Observer*>(adapter.get())
+ ->AdapterPropertyChanged(new_adapter_path,
+ new_adapter_properties.address.name());
+
// Adapter should be present with the new address.
EXPECT_TRUE(adapter->IsPresent());
EXPECT_EQ(new_adapter_address, adapter->address());
@@ -233,4 +404,42 @@ TEST_F(BluetoothAdapterTest, DefaultAdapterRemoved) {
EXPECT_FALSE(adapter->IsPresent());
}
+TEST_F(BluetoothAdapterTest, DefaultAdapterWithoutAddressRemoved) {
+ const dbus::ObjectPath adapter_path("/fake/hci0");
+
+ // Create the default adapter instance;
+ // BluetoothManagerClient::DefaultAdapter will be called once, passing
+ // a callback to obtain the adapter path.
+ BluetoothManagerClient::AdapterCallback adapter_callback;
+ EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
+ .WillOnce(SaveArg<0>(&adapter_callback));
+
+ scoped_refptr<BluetoothAdapter> adapter = BluetoothAdapter::DefaultAdapter();
+
+ // Call the adapter callback;
+ // BluetoothAdapterClient::GetProperties will be called once to obtain
+ // the property set.
+ MockBluetoothAdapterClient::Properties adapter_properties;
+
+ EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
+ .WillRepeatedly(Return(&adapter_properties));
+
+ adapter_callback.Run(adapter_path, true);
+
+ // Report that the adapter has been removed;
+ // BluetoothAdapter::Observer::AdapterPresentChanged must not be called
+ // since we never should have announced it in the first place.
+ MockBluetoothAdapter::Observer adapter_observer;
+ adapter->AddObserver(&adapter_observer);
+
+ EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter.get(), _))
+ .Times(0);
+
+ static_cast<BluetoothManagerClient::Observer*>(adapter.get())
+ ->AdapterRemoved(adapter_path);
+
+ // Adapter should be still no longer present.
+ EXPECT_FALSE(adapter->IsPresent());
+}
+
} // namespace chromeos