diff options
Diffstat (limited to 'device/bluetooth/bluetooth_socket_chromeos_unittest.cc')
-rw-r--r-- | device/bluetooth/bluetooth_socket_chromeos_unittest.cc | 119 |
1 files changed, 56 insertions, 63 deletions
diff --git a/device/bluetooth/bluetooth_socket_chromeos_unittest.cc b/device/bluetooth/bluetooth_socket_chromeos_unittest.cc index 0bdc3be..747b857 100644 --- a/device/bluetooth/bluetooth_socket_chromeos_unittest.cc +++ b/device/bluetooth/bluetooth_socket_chromeos_unittest.cc @@ -5,6 +5,14 @@ #include "base/bind.h" #include "base/memory/ref_counted.h" #include "base/message_loop/message_loop.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/fake_bluetooth_adapter_client.h" +#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" +#include "chromeos/dbus/fake_bluetooth_device_client.h" +#include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" +#include "chromeos/dbus/fake_bluetooth_input_client.h" +#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" +#include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" #include "device/bluetooth/bluetooth_adapter.h" #include "device/bluetooth/bluetooth_adapter_chromeos.h" #include "device/bluetooth/bluetooth_adapter_factory.h" @@ -14,14 +22,6 @@ #include "device/bluetooth/bluetooth_socket_chromeos.h" #include "device/bluetooth/bluetooth_socket_thread.h" #include "device/bluetooth/bluetooth_uuid.h" -#include "device/bluetooth/dbus/bluez_dbus_manager.h" -#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" -#include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" -#include "device/bluetooth/dbus/fake_bluetooth_device_client.h" -#include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" -#include "device/bluetooth/dbus/fake_bluetooth_input_client.h" -#include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" -#include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "testing/gtest/include/gtest/gtest.h" @@ -51,27 +51,24 @@ class BluetoothSocketChromeOSTest : public testing::Test { last_reason_(BluetoothSocket::kSystemError) {} void SetUp() override { - scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = - bluez::BluezDBusManager::GetSetterForTesting(); + scoped_ptr<DBusThreadManagerSetter> dbus_setter = + DBusThreadManager::GetSetterForTesting(); dbus_setter->SetBluetoothAdapterClient( - scoped_ptr<bluez::BluetoothAdapterClient>( - new bluez::FakeBluetoothAdapterClient)); + scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); dbus_setter->SetBluetoothAgentManagerClient( - scoped_ptr<bluez::BluetoothAgentManagerClient>( - new bluez::FakeBluetoothAgentManagerClient)); + scoped_ptr<BluetoothAgentManagerClient>( + new FakeBluetoothAgentManagerClient)); dbus_setter->SetBluetoothDeviceClient( - scoped_ptr<bluez::BluetoothDeviceClient>( - new bluez::FakeBluetoothDeviceClient)); + scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient)); dbus_setter->SetBluetoothGattServiceClient( - scoped_ptr<bluez::BluetoothGattServiceClient>( - new bluez::FakeBluetoothGattServiceClient)); + scoped_ptr<BluetoothGattServiceClient>( + new FakeBluetoothGattServiceClient)); dbus_setter->SetBluetoothInputClient( - scoped_ptr<bluez::BluetoothInputClient>( - new bluez::FakeBluetoothInputClient)); + scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); dbus_setter->SetBluetoothProfileManagerClient( - scoped_ptr<bluez::BluetoothProfileManagerClient>( - new bluez::FakeBluetoothProfileManagerClient)); + scoped_ptr<BluetoothProfileManagerClient>( + new FakeBluetoothProfileManagerClient)); BluetoothSocketThread::Get(); @@ -94,7 +91,7 @@ class BluetoothSocketChromeOSTest : public testing::Test { void TearDown() override { adapter_ = nullptr; BluetoothSocketThread::CleanupForTesting(); - bluez::BluezDBusManager::Shutdown(); + DBusThreadManager::Shutdown(); } void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { @@ -185,12 +182,12 @@ class BluetoothSocketChromeOSTest : public testing::Test { }; TEST_F(BluetoothSocketChromeOSTest, Connect) { - BluetoothDevice* device = adapter_->GetDevice( - bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); + BluetoothDevice* device = + adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); ASSERT_TRUE(device != nullptr); device->ConnectToService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, base::Unretained(this)), base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, @@ -297,7 +294,7 @@ TEST_F(BluetoothSocketChromeOSTest, Connect) { TEST_F(BluetoothSocketChromeOSTest, Listen) { adapter_->CreateRfcommService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), BluetoothAdapter::ServiceOptions(), base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, base::Unretained(this)), @@ -322,15 +319,15 @@ TEST_F(BluetoothSocketChromeOSTest, Listen) { // // This is done before the Accept() call to simulate a pending call at the // point that Accept() is called. - bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client = - static_cast<bluez::FakeBluetoothDeviceClient*>( - bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()); - BluetoothDevice* device = adapter_->GetDevice( - bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); + FakeBluetoothDeviceClient* fake_bluetooth_device_client = + static_cast<FakeBluetoothDeviceClient*>( + DBusThreadManager::Get()->GetBluetoothDeviceClient()); + BluetoothDevice* device = + adapter_->GetDevice(FakeBluetoothDeviceClient::kPairedDeviceAddress); ASSERT_TRUE(device != nullptr); fake_bluetooth_device_client->ConnectProfile( static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), - bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, + FakeBluetoothProfileManagerClient::kRfcommUuid, base::Bind(&base::DoNothing), base::Bind(&DoNothingDBusErrorCallback)); message_loop_.RunUntilIdle(); @@ -377,7 +374,7 @@ TEST_F(BluetoothSocketChromeOSTest, Listen) { fake_bluetooth_device_client->ConnectProfile( static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), - bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, + FakeBluetoothProfileManagerClient::kRfcommUuid, base::Bind(&base::DoNothing), base::Bind(&DoNothingDBusErrorCallback)); message_loop_.Run(); @@ -417,13 +414,13 @@ TEST_F(BluetoothSocketChromeOSTest, Listen) { TEST_F(BluetoothSocketChromeOSTest, ListenBeforeAdapterStart) { // Start off with an invisible adapter, register the profile, then make // the adapter visible. - bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = - static_cast<bluez::FakeBluetoothAdapterClient*>( - bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()); + FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = + static_cast<FakeBluetoothAdapterClient*>( + DBusThreadManager::Get()->GetBluetoothAdapterClient()); fake_bluetooth_adapter_client->SetVisible(false); adapter_->CreateRfcommService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), BluetoothAdapter::ServiceOptions(), base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, base::Unretained(this)), @@ -442,14 +439,12 @@ TEST_F(BluetoothSocketChromeOSTest, ListenBeforeAdapterStart) { error_callback_count_ = 0; // But there shouldn't be a profile registered yet. - bluez::FakeBluetoothProfileManagerClient* - fake_bluetooth_profile_manager_client = - static_cast<bluez::FakeBluetoothProfileManagerClient*>( - bluez::BluezDBusManager::Get() - ->GetBluetoothProfileManagerClient()); - bluez::FakeBluetoothProfileServiceProvider* profile_service_provider = + FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = + static_cast<FakeBluetoothProfileManagerClient*>( + DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); + FakeBluetoothProfileServiceProvider* profile_service_provider = fake_bluetooth_profile_manager_client->GetProfileServiceProvider( - bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); + FakeBluetoothProfileManagerClient::kRfcommUuid); EXPECT_TRUE(profile_service_provider == nullptr); // Make the adapter visible. This should register a profile. @@ -459,7 +454,7 @@ TEST_F(BluetoothSocketChromeOSTest, ListenBeforeAdapterStart) { profile_service_provider = fake_bluetooth_profile_manager_client->GetProfileServiceProvider( - bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); + FakeBluetoothProfileManagerClient::kRfcommUuid); EXPECT_TRUE(profile_service_provider != nullptr); // Cleanup the socket. @@ -474,12 +469,12 @@ TEST_F(BluetoothSocketChromeOSTest, ListenBeforeAdapterStart) { TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { // The fake adapter starts off visible by default. - bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = - static_cast<bluez::FakeBluetoothAdapterClient*>( - bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()); + FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = + static_cast<FakeBluetoothAdapterClient*>( + DBusThreadManager::Get()->GetBluetoothAdapterClient()); adapter_->CreateRfcommService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), BluetoothAdapter::ServiceOptions(), base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, base::Unretained(this)), @@ -498,14 +493,12 @@ TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { error_callback_count_ = 0; // Make sure the profile was registered with the daemon. - bluez::FakeBluetoothProfileManagerClient* - fake_bluetooth_profile_manager_client = - static_cast<bluez::FakeBluetoothProfileManagerClient*>( - bluez::BluezDBusManager::Get() - ->GetBluetoothProfileManagerClient()); - bluez::FakeBluetoothProfileServiceProvider* profile_service_provider = + FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = + static_cast<FakeBluetoothProfileManagerClient*>( + DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); + FakeBluetoothProfileServiceProvider* profile_service_provider = fake_bluetooth_profile_manager_client->GetProfileServiceProvider( - bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); + FakeBluetoothProfileManagerClient::kRfcommUuid); EXPECT_TRUE(profile_service_provider != nullptr); // Make the adapter invisible, and fiddle with the profile fake to unregister @@ -521,7 +514,7 @@ TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { profile_service_provider = fake_bluetooth_profile_manager_client->GetProfileServiceProvider( - bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); + FakeBluetoothProfileManagerClient::kRfcommUuid); EXPECT_TRUE(profile_service_provider != nullptr); // Cleanup the socket. @@ -536,11 +529,11 @@ TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { BluetoothDevice* device = adapter_->GetDevice( - bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); + FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); ASSERT_TRUE(device != nullptr); device->ConnectToService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, base::Unretained(this)), base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, @@ -552,7 +545,7 @@ TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { EXPECT_TRUE(last_socket_.get() == nullptr); device->ConnectToService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, base::Unretained(this)), base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, @@ -566,7 +559,7 @@ TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { adapter_->CreateRfcommService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), BluetoothAdapter::ServiceOptions(), base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, base::Unretained(this)), @@ -599,7 +592,7 @@ TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { EXPECT_EQ(1U, error_callback_count_); adapter_->CreateRfcommService( - BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), + BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), BluetoothAdapter::ServiceOptions(), base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, base::Unretained(this)), |