| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | |
| 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | |
| 11 #include "chromeos/dbus/fake_bluetooth_device_client.h" | |
| 12 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" | |
| 13 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
| 14 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" | |
| 15 #include "chromeos/dbus/fake_bluetooth_profile_service_provider.h" | |
| 16 #include "device/bluetooth/bluetooth_adapter.h" | 8 #include "device/bluetooth/bluetooth_adapter.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_chromeos.h" | 9 #include "device/bluetooth/bluetooth_adapter_chromeos.h" |
| 18 #include "device/bluetooth/bluetooth_adapter_factory.h" | 10 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 19 #include "device/bluetooth/bluetooth_device.h" | 11 #include "device/bluetooth/bluetooth_device.h" |
| 20 #include "device/bluetooth/bluetooth_device_chromeos.h" | 12 #include "device/bluetooth/bluetooth_device_chromeos.h" |
| 21 #include "device/bluetooth/bluetooth_socket.h" | 13 #include "device/bluetooth/bluetooth_socket.h" |
| 22 #include "device/bluetooth/bluetooth_socket_chromeos.h" | 14 #include "device/bluetooth/bluetooth_socket_chromeos.h" |
| 23 #include "device/bluetooth/bluetooth_socket_thread.h" | 15 #include "device/bluetooth/bluetooth_socket_thread.h" |
| 24 #include "device/bluetooth/bluetooth_uuid.h" | 16 #include "device/bluetooth/bluetooth_uuid.h" |
| 17 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
| 18 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h" |
| 19 #include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h" |
| 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 21 #include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h" |
| 22 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
| 23 #include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h" |
| 24 #include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h" |
| 25 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using device::BluetoothAdapter; | 29 using device::BluetoothAdapter; |
| 30 using device::BluetoothDevice; | 30 using device::BluetoothDevice; |
| 31 using device::BluetoothSocket; | 31 using device::BluetoothSocket; |
| 32 using device::BluetoothSocketThread; | 32 using device::BluetoothSocketThread; |
| 33 using device::BluetoothUUID; | 33 using device::BluetoothUUID; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 void DoNothingDBusErrorCallback(const std::string& error_name, | 37 void DoNothingDBusErrorCallback(const std::string& error_name, |
| 38 const std::string& error_message) {} | 38 const std::string& error_message) {} |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 namespace chromeos { | 42 namespace chromeos { |
| 43 | 43 |
| 44 class BluetoothSocketChromeOSTest : public testing::Test { | 44 class BluetoothSocketChromeOSTest : public testing::Test { |
| 45 public: | 45 public: |
| 46 BluetoothSocketChromeOSTest() | 46 BluetoothSocketChromeOSTest() |
| 47 : success_callback_count_(0), | 47 : success_callback_count_(0), |
| 48 error_callback_count_(0), | 48 error_callback_count_(0), |
| 49 last_bytes_sent_(0), | 49 last_bytes_sent_(0), |
| 50 last_bytes_received_(0), | 50 last_bytes_received_(0), |
| 51 last_reason_(BluetoothSocket::kSystemError) {} | 51 last_reason_(BluetoothSocket::kSystemError) {} |
| 52 | 52 |
| 53 void SetUp() override { | 53 void SetUp() override { |
| 54 scoped_ptr<DBusThreadManagerSetter> dbus_setter = | 54 scoped_ptr<bluez::BluezDBusManagerSetter> dbus_setter = |
| 55 DBusThreadManager::GetSetterForTesting(); | 55 bluez::BluezDBusManager::GetSetterForTesting(); |
| 56 | 56 |
| 57 dbus_setter->SetBluetoothAdapterClient( | 57 dbus_setter->SetBluetoothAdapterClient( |
| 58 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); | 58 scoped_ptr<bluez::BluetoothAdapterClient>( |
| 59 new bluez::FakeBluetoothAdapterClient)); |
| 59 dbus_setter->SetBluetoothAgentManagerClient( | 60 dbus_setter->SetBluetoothAgentManagerClient( |
| 60 scoped_ptr<BluetoothAgentManagerClient>( | 61 scoped_ptr<bluez::BluetoothAgentManagerClient>( |
| 61 new FakeBluetoothAgentManagerClient)); | 62 new bluez::FakeBluetoothAgentManagerClient)); |
| 62 dbus_setter->SetBluetoothDeviceClient( | 63 dbus_setter->SetBluetoothDeviceClient( |
| 63 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient)); | 64 scoped_ptr<bluez::BluetoothDeviceClient>( |
| 65 new bluez::FakeBluetoothDeviceClient)); |
| 64 dbus_setter->SetBluetoothGattServiceClient( | 66 dbus_setter->SetBluetoothGattServiceClient( |
| 65 scoped_ptr<BluetoothGattServiceClient>( | 67 scoped_ptr<bluez::BluetoothGattServiceClient>( |
| 66 new FakeBluetoothGattServiceClient)); | 68 new bluez::FakeBluetoothGattServiceClient)); |
| 67 dbus_setter->SetBluetoothInputClient( | 69 dbus_setter->SetBluetoothInputClient( |
| 68 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); | 70 scoped_ptr<bluez::BluetoothInputClient>( |
| 71 new bluez::FakeBluetoothInputClient)); |
| 69 dbus_setter->SetBluetoothProfileManagerClient( | 72 dbus_setter->SetBluetoothProfileManagerClient( |
| 70 scoped_ptr<BluetoothProfileManagerClient>( | 73 scoped_ptr<bluez::BluetoothProfileManagerClient>( |
| 71 new FakeBluetoothProfileManagerClient)); | 74 new bluez::FakeBluetoothProfileManagerClient)); |
| 72 | 75 |
| 73 BluetoothSocketThread::Get(); | 76 BluetoothSocketThread::Get(); |
| 74 | 77 |
| 75 // Grab a pointer to the adapter. | 78 // Grab a pointer to the adapter. |
| 76 device::BluetoothAdapterFactory::GetAdapter( | 79 device::BluetoothAdapterFactory::GetAdapter( |
| 77 base::Bind(&BluetoothSocketChromeOSTest::AdapterCallback, | 80 base::Bind(&BluetoothSocketChromeOSTest::AdapterCallback, |
| 78 base::Unretained(this))); | 81 base::Unretained(this))); |
| 79 ASSERT_TRUE(adapter_.get() != nullptr); | 82 ASSERT_TRUE(adapter_.get() != nullptr); |
| 80 ASSERT_TRUE(adapter_->IsInitialized()); | 83 ASSERT_TRUE(adapter_->IsInitialized()); |
| 81 ASSERT_TRUE(adapter_->IsPresent()); | 84 ASSERT_TRUE(adapter_->IsPresent()); |
| 82 | 85 |
| 83 // Turn on the adapter. | 86 // Turn on the adapter. |
| 84 adapter_->SetPowered( | 87 adapter_->SetPowered( |
| 85 true, | 88 true, |
| 86 base::Bind(&base::DoNothing), | 89 base::Bind(&base::DoNothing), |
| 87 base::Bind(&base::DoNothing)); | 90 base::Bind(&base::DoNothing)); |
| 88 ASSERT_TRUE(adapter_->IsPowered()); | 91 ASSERT_TRUE(adapter_->IsPowered()); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void TearDown() override { | 94 void TearDown() override { |
| 92 adapter_ = nullptr; | 95 adapter_ = nullptr; |
| 93 BluetoothSocketThread::CleanupForTesting(); | 96 BluetoothSocketThread::CleanupForTesting(); |
| 94 DBusThreadManager::Shutdown(); | 97 bluez::BluezDBusManager::Shutdown(); |
| 95 } | 98 } |
| 96 | 99 |
| 97 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { | 100 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { |
| 98 adapter_ = adapter; | 101 adapter_ = adapter; |
| 99 } | 102 } |
| 100 | 103 |
| 101 void SuccessCallback() { | 104 void SuccessCallback() { |
| 102 ++success_callback_count_; | 105 ++success_callback_count_; |
| 103 message_loop_.Quit(); | 106 message_loop_.Quit(); |
| 104 } | 107 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 scoped_refptr<BluetoothSocket> last_socket_; | 179 scoped_refptr<BluetoothSocket> last_socket_; |
| 177 int last_bytes_sent_; | 180 int last_bytes_sent_; |
| 178 int last_bytes_received_; | 181 int last_bytes_received_; |
| 179 scoped_refptr<net::IOBuffer> last_io_buffer_; | 182 scoped_refptr<net::IOBuffer> last_io_buffer_; |
| 180 BluetoothSocket::ErrorReason last_reason_; | 183 BluetoothSocket::ErrorReason last_reason_; |
| 181 const BluetoothDevice* last_device_; | 184 const BluetoothDevice* last_device_; |
| 182 }; | 185 }; |
| 183 | 186 |
| 184 TEST_F(BluetoothSocketChromeOSTest, Connect) { | 187 TEST_F(BluetoothSocketChromeOSTest, Connect) { |
| 185 BluetoothDevice* device = adapter_->GetDevice( | 188 BluetoothDevice* device = adapter_->GetDevice( |
| 186 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 189 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 187 ASSERT_TRUE(device != nullptr); | 190 ASSERT_TRUE(device != nullptr); |
| 188 | 191 |
| 189 device->ConnectToService( | 192 device->ConnectToService( |
| 190 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 193 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 191 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, | 194 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, |
| 192 base::Unretained(this)), | 195 base::Unretained(this)), |
| 193 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 196 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 194 base::Unretained(this))); | 197 base::Unretained(this))); |
| 195 message_loop_.Run(); | 198 message_loop_.Run(); |
| 196 | 199 |
| 197 EXPECT_EQ(1U, success_callback_count_); | 200 EXPECT_EQ(1U, success_callback_count_); |
| 198 EXPECT_EQ(0U, error_callback_count_); | 201 EXPECT_EQ(0U, error_callback_count_); |
| 199 EXPECT_TRUE(last_socket_.get() != nullptr); | 202 EXPECT_TRUE(last_socket_.get() != nullptr); |
| 200 | 203 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // Close our end of the socket. | 290 // Close our end of the socket. |
| 288 socket->Disconnect(base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback, | 291 socket->Disconnect(base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback, |
| 289 base::Unretained(this))); | 292 base::Unretained(this))); |
| 290 | 293 |
| 291 message_loop_.Run(); | 294 message_loop_.Run(); |
| 292 EXPECT_EQ(1U, success_callback_count_); | 295 EXPECT_EQ(1U, success_callback_count_); |
| 293 } | 296 } |
| 294 | 297 |
| 295 TEST_F(BluetoothSocketChromeOSTest, Listen) { | 298 TEST_F(BluetoothSocketChromeOSTest, Listen) { |
| 296 adapter_->CreateRfcommService( | 299 adapter_->CreateRfcommService( |
| 297 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 300 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 298 BluetoothAdapter::ServiceOptions(), | 301 BluetoothAdapter::ServiceOptions(), |
| 299 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 302 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
| 300 base::Unretained(this)), | 303 base::Unretained(this)), |
| 301 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 304 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 302 base::Unretained(this))); | 305 base::Unretained(this))); |
| 303 | 306 |
| 304 message_loop_.Run(); | 307 message_loop_.Run(); |
| 305 | 308 |
| 306 EXPECT_EQ(1U, success_callback_count_); | 309 EXPECT_EQ(1U, success_callback_count_); |
| 307 EXPECT_EQ(0U, error_callback_count_); | 310 EXPECT_EQ(0U, error_callback_count_); |
| 308 EXPECT_TRUE(last_socket_.get() != nullptr); | 311 EXPECT_TRUE(last_socket_.get() != nullptr); |
| 309 | 312 |
| 310 // Take ownership of the socket for the remainder of the test. | 313 // Take ownership of the socket for the remainder of the test. |
| 311 scoped_refptr<BluetoothSocket> server_socket = last_socket_; | 314 scoped_refptr<BluetoothSocket> server_socket = last_socket_; |
| 312 last_socket_ = nullptr; | 315 last_socket_ = nullptr; |
| 313 success_callback_count_ = 0; | 316 success_callback_count_ = 0; |
| 314 error_callback_count_ = 0; | 317 error_callback_count_ = 0; |
| 315 | 318 |
| 316 // Simulate an incoming connection by just calling the ConnectProfile method | 319 // Simulate an incoming connection by just calling the ConnectProfile method |
| 317 // of the underlying fake device client (from the BlueZ point of view, | 320 // of the underlying fake device client (from the BlueZ point of view, |
| 318 // outgoing and incoming look the same). | 321 // outgoing and incoming look the same). |
| 319 // | 322 // |
| 320 // This is done before the Accept() call to simulate a pending call at the | 323 // This is done before the Accept() call to simulate a pending call at the |
| 321 // point that Accept() is called. | 324 // point that Accept() is called. |
| 322 FakeBluetoothDeviceClient* fake_bluetooth_device_client = | 325 bluez::FakeBluetoothDeviceClient* fake_bluetooth_device_client = |
| 323 static_cast<FakeBluetoothDeviceClient*>( | 326 static_cast<bluez::FakeBluetoothDeviceClient*>( |
| 324 DBusThreadManager::Get()->GetBluetoothDeviceClient()); | 327 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()); |
| 325 BluetoothDevice* device = adapter_->GetDevice( | 328 BluetoothDevice* device = adapter_->GetDevice( |
| 326 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 329 bluez::FakeBluetoothDeviceClient::kPairedDeviceAddress); |
| 327 ASSERT_TRUE(device != nullptr); | 330 ASSERT_TRUE(device != nullptr); |
| 328 fake_bluetooth_device_client->ConnectProfile( | 331 fake_bluetooth_device_client->ConnectProfile( |
| 329 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), | 332 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), |
| 330 FakeBluetoothProfileManagerClient::kRfcommUuid, | 333 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, |
| 331 base::Bind(&base::DoNothing), | 334 base::Bind(&base::DoNothing), base::Bind(&DoNothingDBusErrorCallback)); |
| 332 base::Bind(&DoNothingDBusErrorCallback)); | |
| 333 | 335 |
| 334 message_loop_.RunUntilIdle(); | 336 message_loop_.RunUntilIdle(); |
| 335 | 337 |
| 336 server_socket->Accept( | 338 server_socket->Accept( |
| 337 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | 339 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
| 338 base::Unretained(this)), | 340 base::Unretained(this)), |
| 339 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 341 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 340 base::Unretained(this))); | 342 base::Unretained(this))); |
| 341 | 343 |
| 342 message_loop_.Run(); | 344 message_loop_.Run(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 368 server_socket->Accept( | 370 server_socket->Accept( |
| 369 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | 371 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
| 370 base::Unretained(this)), | 372 base::Unretained(this)), |
| 371 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 373 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 372 base::Unretained(this))); | 374 base::Unretained(this))); |
| 373 | 375 |
| 374 message_loop_.RunUntilIdle(); | 376 message_loop_.RunUntilIdle(); |
| 375 | 377 |
| 376 fake_bluetooth_device_client->ConnectProfile( | 378 fake_bluetooth_device_client->ConnectProfile( |
| 377 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), | 379 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), |
| 378 FakeBluetoothProfileManagerClient::kRfcommUuid, | 380 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid, |
| 379 base::Bind(&base::DoNothing), | 381 base::Bind(&base::DoNothing), base::Bind(&DoNothingDBusErrorCallback)); |
| 380 base::Bind(&DoNothingDBusErrorCallback)); | |
| 381 | 382 |
| 382 message_loop_.Run(); | 383 message_loop_.Run(); |
| 383 | 384 |
| 384 EXPECT_EQ(1U, success_callback_count_); | 385 EXPECT_EQ(1U, success_callback_count_); |
| 385 EXPECT_EQ(0U, error_callback_count_); | 386 EXPECT_EQ(0U, error_callback_count_); |
| 386 EXPECT_TRUE(last_socket_.get() != nullptr); | 387 EXPECT_TRUE(last_socket_.get() != nullptr); |
| 387 | 388 |
| 388 // Take ownership of the client socket for the remainder of the test. | 389 // Take ownership of the client socket for the remainder of the test. |
| 389 client_socket = last_socket_; | 390 client_socket = last_socket_; |
| 390 last_socket_ = nullptr; | 391 last_socket_ = nullptr; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 409 base::Unretained(this))); | 410 base::Unretained(this))); |
| 410 | 411 |
| 411 message_loop_.RunUntilIdle(); | 412 message_loop_.RunUntilIdle(); |
| 412 | 413 |
| 413 EXPECT_EQ(1U, success_callback_count_); | 414 EXPECT_EQ(1U, success_callback_count_); |
| 414 } | 415 } |
| 415 | 416 |
| 416 TEST_F(BluetoothSocketChromeOSTest, ListenBeforeAdapterStart) { | 417 TEST_F(BluetoothSocketChromeOSTest, ListenBeforeAdapterStart) { |
| 417 // Start off with an invisible adapter, register the profile, then make | 418 // Start off with an invisible adapter, register the profile, then make |
| 418 // the adapter visible. | 419 // the adapter visible. |
| 419 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = | 420 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = |
| 420 static_cast<FakeBluetoothAdapterClient*>( | 421 static_cast<bluez::FakeBluetoothAdapterClient*>( |
| 421 DBusThreadManager::Get()->GetBluetoothAdapterClient()); | 422 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()); |
| 422 fake_bluetooth_adapter_client->SetVisible(false); | 423 fake_bluetooth_adapter_client->SetVisible(false); |
| 423 | 424 |
| 424 adapter_->CreateRfcommService( | 425 adapter_->CreateRfcommService( |
| 425 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 426 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 426 BluetoothAdapter::ServiceOptions(), | 427 BluetoothAdapter::ServiceOptions(), |
| 427 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 428 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
| 428 base::Unretained(this)), | 429 base::Unretained(this)), |
| 429 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 430 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 430 base::Unretained(this))); | 431 base::Unretained(this))); |
| 431 message_loop_.Run(); | 432 message_loop_.Run(); |
| 432 | 433 |
| 433 EXPECT_EQ(1U, success_callback_count_); | 434 EXPECT_EQ(1U, success_callback_count_); |
| 434 EXPECT_EQ(0U, error_callback_count_); | 435 EXPECT_EQ(0U, error_callback_count_); |
| 435 EXPECT_TRUE(last_socket_.get() != nullptr); | 436 EXPECT_TRUE(last_socket_.get() != nullptr); |
| 436 | 437 |
| 437 // Take ownership of the socket for the remainder of the test. | 438 // Take ownership of the socket for the remainder of the test. |
| 438 scoped_refptr<BluetoothSocket> socket = last_socket_; | 439 scoped_refptr<BluetoothSocket> socket = last_socket_; |
| 439 last_socket_ = nullptr; | 440 last_socket_ = nullptr; |
| 440 success_callback_count_ = 0; | 441 success_callback_count_ = 0; |
| 441 error_callback_count_ = 0; | 442 error_callback_count_ = 0; |
| 442 | 443 |
| 443 // But there shouldn't be a profile registered yet. | 444 // But there shouldn't be a profile registered yet. |
| 444 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 445 bluez::FakeBluetoothProfileManagerClient* |
| 445 static_cast<FakeBluetoothProfileManagerClient*>( | 446 fake_bluetooth_profile_manager_client = |
| 446 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); | 447 static_cast<bluez::FakeBluetoothProfileManagerClient*>( |
| 447 FakeBluetoothProfileServiceProvider* profile_service_provider = | 448 bluez::BluezDBusManager::Get() |
| 449 ->GetBluetoothProfileManagerClient()); |
| 450 bluez::FakeBluetoothProfileServiceProvider* profile_service_provider = |
| 448 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 451 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
| 449 FakeBluetoothProfileManagerClient::kRfcommUuid); | 452 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); |
| 450 EXPECT_TRUE(profile_service_provider == nullptr); | 453 EXPECT_TRUE(profile_service_provider == nullptr); |
| 451 | 454 |
| 452 // Make the adapter visible. This should register a profile. | 455 // Make the adapter visible. This should register a profile. |
| 453 fake_bluetooth_adapter_client->SetVisible(true); | 456 fake_bluetooth_adapter_client->SetVisible(true); |
| 454 | 457 |
| 455 message_loop_.RunUntilIdle(); | 458 message_loop_.RunUntilIdle(); |
| 456 | 459 |
| 457 profile_service_provider = | 460 profile_service_provider = |
| 458 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 461 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
| 459 FakeBluetoothProfileManagerClient::kRfcommUuid); | 462 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); |
| 460 EXPECT_TRUE(profile_service_provider != nullptr); | 463 EXPECT_TRUE(profile_service_provider != nullptr); |
| 461 | 464 |
| 462 // Cleanup the socket. | 465 // Cleanup the socket. |
| 463 socket->Disconnect( | 466 socket->Disconnect( |
| 464 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, | 467 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, |
| 465 base::Unretained(this))); | 468 base::Unretained(this))); |
| 466 | 469 |
| 467 message_loop_.RunUntilIdle(); | 470 message_loop_.RunUntilIdle(); |
| 468 | 471 |
| 469 EXPECT_EQ(1U, success_callback_count_); | 472 EXPECT_EQ(1U, success_callback_count_); |
| 470 } | 473 } |
| 471 | 474 |
| 472 TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { | 475 TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { |
| 473 // The fake adapter starts off visible by default. | 476 // The fake adapter starts off visible by default. |
| 474 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = | 477 bluez::FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = |
| 475 static_cast<FakeBluetoothAdapterClient*>( | 478 static_cast<bluez::FakeBluetoothAdapterClient*>( |
| 476 DBusThreadManager::Get()->GetBluetoothAdapterClient()); | 479 bluez::BluezDBusManager::Get()->GetBluetoothAdapterClient()); |
| 477 | 480 |
| 478 adapter_->CreateRfcommService( | 481 adapter_->CreateRfcommService( |
| 479 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 482 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 480 BluetoothAdapter::ServiceOptions(), | 483 BluetoothAdapter::ServiceOptions(), |
| 481 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 484 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
| 482 base::Unretained(this)), | 485 base::Unretained(this)), |
| 483 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 486 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 484 base::Unretained(this))); | 487 base::Unretained(this))); |
| 485 message_loop_.Run(); | 488 message_loop_.Run(); |
| 486 | 489 |
| 487 EXPECT_EQ(1U, success_callback_count_); | 490 EXPECT_EQ(1U, success_callback_count_); |
| 488 EXPECT_EQ(0U, error_callback_count_); | 491 EXPECT_EQ(0U, error_callback_count_); |
| 489 EXPECT_TRUE(last_socket_.get() != nullptr); | 492 EXPECT_TRUE(last_socket_.get() != nullptr); |
| 490 | 493 |
| 491 // Take ownership of the socket for the remainder of the test. | 494 // Take ownership of the socket for the remainder of the test. |
| 492 scoped_refptr<BluetoothSocket> socket = last_socket_; | 495 scoped_refptr<BluetoothSocket> socket = last_socket_; |
| 493 last_socket_ = nullptr; | 496 last_socket_ = nullptr; |
| 494 success_callback_count_ = 0; | 497 success_callback_count_ = 0; |
| 495 error_callback_count_ = 0; | 498 error_callback_count_ = 0; |
| 496 | 499 |
| 497 // Make sure the profile was registered with the daemon. | 500 // Make sure the profile was registered with the daemon. |
| 498 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 501 bluez::FakeBluetoothProfileManagerClient* |
| 499 static_cast<FakeBluetoothProfileManagerClient*>( | 502 fake_bluetooth_profile_manager_client = |
| 500 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); | 503 static_cast<bluez::FakeBluetoothProfileManagerClient*>( |
| 501 FakeBluetoothProfileServiceProvider* profile_service_provider = | 504 bluez::BluezDBusManager::Get() |
| 505 ->GetBluetoothProfileManagerClient()); |
| 506 bluez::FakeBluetoothProfileServiceProvider* profile_service_provider = |
| 502 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 507 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
| 503 FakeBluetoothProfileManagerClient::kRfcommUuid); | 508 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); |
| 504 EXPECT_TRUE(profile_service_provider != nullptr); | 509 EXPECT_TRUE(profile_service_provider != nullptr); |
| 505 | 510 |
| 506 // Make the adapter invisible, and fiddle with the profile fake to unregister | 511 // Make the adapter invisible, and fiddle with the profile fake to unregister |
| 507 // the profile since this doesn't happen automatically. | 512 // the profile since this doesn't happen automatically. |
| 508 fake_bluetooth_adapter_client->SetVisible(false); | 513 fake_bluetooth_adapter_client->SetVisible(false); |
| 509 | 514 |
| 510 message_loop_.RunUntilIdle(); | 515 message_loop_.RunUntilIdle(); |
| 511 | 516 |
| 512 // Then make the adapter visible again. This should re-register the profile. | 517 // Then make the adapter visible again. This should re-register the profile. |
| 513 fake_bluetooth_adapter_client->SetVisible(true); | 518 fake_bluetooth_adapter_client->SetVisible(true); |
| 514 | 519 |
| 515 message_loop_.RunUntilIdle(); | 520 message_loop_.RunUntilIdle(); |
| 516 | 521 |
| 517 profile_service_provider = | 522 profile_service_provider = |
| 518 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 523 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
| 519 FakeBluetoothProfileManagerClient::kRfcommUuid); | 524 bluez::FakeBluetoothProfileManagerClient::kRfcommUuid); |
| 520 EXPECT_TRUE(profile_service_provider != nullptr); | 525 EXPECT_TRUE(profile_service_provider != nullptr); |
| 521 | 526 |
| 522 // Cleanup the socket. | 527 // Cleanup the socket. |
| 523 socket->Disconnect( | 528 socket->Disconnect( |
| 524 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, | 529 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, |
| 525 base::Unretained(this))); | 530 base::Unretained(this))); |
| 526 | 531 |
| 527 message_loop_.RunUntilIdle(); | 532 message_loop_.RunUntilIdle(); |
| 528 | 533 |
| 529 EXPECT_EQ(1U, success_callback_count_); | 534 EXPECT_EQ(1U, success_callback_count_); |
| 530 } | 535 } |
| 531 | 536 |
| 532 TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { | 537 TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { |
| 533 BluetoothDevice* device = adapter_->GetDevice( | 538 BluetoothDevice* device = adapter_->GetDevice( |
| 534 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); | 539 bluez::FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); |
| 535 ASSERT_TRUE(device != nullptr); | 540 ASSERT_TRUE(device != nullptr); |
| 536 | 541 |
| 537 device->ConnectToService( | 542 device->ConnectToService( |
| 538 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 543 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 539 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, | 544 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, |
| 540 base::Unretained(this)), | 545 base::Unretained(this)), |
| 541 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 546 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 542 base::Unretained(this))); | 547 base::Unretained(this))); |
| 543 message_loop_.Run(); | 548 message_loop_.Run(); |
| 544 | 549 |
| 545 EXPECT_EQ(0U, success_callback_count_); | 550 EXPECT_EQ(0U, success_callback_count_); |
| 546 EXPECT_EQ(1U, error_callback_count_); | 551 EXPECT_EQ(1U, error_callback_count_); |
| 547 EXPECT_TRUE(last_socket_.get() == nullptr); | 552 EXPECT_TRUE(last_socket_.get() == nullptr); |
| 548 | 553 |
| 549 device->ConnectToService( | 554 device->ConnectToService( |
| 550 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 555 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 551 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, | 556 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, |
| 552 base::Unretained(this)), | 557 base::Unretained(this)), |
| 553 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 558 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 554 base::Unretained(this))); | 559 base::Unretained(this))); |
| 555 message_loop_.Run(); | 560 message_loop_.Run(); |
| 556 | 561 |
| 557 EXPECT_EQ(0U, success_callback_count_); | 562 EXPECT_EQ(0U, success_callback_count_); |
| 558 EXPECT_EQ(2U, error_callback_count_); | 563 EXPECT_EQ(2U, error_callback_count_); |
| 559 EXPECT_TRUE(last_socket_.get() == nullptr); | 564 EXPECT_TRUE(last_socket_.get() == nullptr); |
| 560 } | 565 } |
| 561 | 566 |
| 562 TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { | 567 TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { |
| 563 adapter_->CreateRfcommService( | 568 adapter_->CreateRfcommService( |
| 564 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 569 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 565 BluetoothAdapter::ServiceOptions(), | 570 BluetoothAdapter::ServiceOptions(), |
| 566 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 571 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
| 567 base::Unretained(this)), | 572 base::Unretained(this)), |
| 568 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 573 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 569 base::Unretained(this))); | 574 base::Unretained(this))); |
| 570 | 575 |
| 571 message_loop_.Run(); | 576 message_loop_.Run(); |
| 572 | 577 |
| 573 EXPECT_EQ(1U, success_callback_count_); | 578 EXPECT_EQ(1U, success_callback_count_); |
| 574 EXPECT_EQ(0U, error_callback_count_); | 579 EXPECT_EQ(0U, error_callback_count_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 587 server_socket->Close(); | 592 server_socket->Close(); |
| 588 | 593 |
| 589 server_socket = nullptr; | 594 server_socket = nullptr; |
| 590 | 595 |
| 591 message_loop_.RunUntilIdle(); | 596 message_loop_.RunUntilIdle(); |
| 592 | 597 |
| 593 EXPECT_EQ(1U, success_callback_count_); | 598 EXPECT_EQ(1U, success_callback_count_); |
| 594 EXPECT_EQ(1U, error_callback_count_); | 599 EXPECT_EQ(1U, error_callback_count_); |
| 595 | 600 |
| 596 adapter_->CreateRfcommService( | 601 adapter_->CreateRfcommService( |
| 597 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 602 BluetoothUUID(bluez::FakeBluetoothProfileManagerClient::kRfcommUuid), |
| 598 BluetoothAdapter::ServiceOptions(), | 603 BluetoothAdapter::ServiceOptions(), |
| 599 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 604 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
| 600 base::Unretained(this)), | 605 base::Unretained(this)), |
| 601 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 606 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 602 base::Unretained(this))); | 607 base::Unretained(this))); |
| 603 | 608 |
| 604 message_loop_.Run(); | 609 message_loop_.Run(); |
| 605 | 610 |
| 606 EXPECT_EQ(2U, success_callback_count_); | 611 EXPECT_EQ(2U, success_callback_count_); |
| 607 EXPECT_EQ(1U, error_callback_count_); | 612 EXPECT_EQ(1U, error_callback_count_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 620 | 625 |
| 621 server_socket = nullptr; | 626 server_socket = nullptr; |
| 622 | 627 |
| 623 message_loop_.RunUntilIdle(); | 628 message_loop_.RunUntilIdle(); |
| 624 | 629 |
| 625 EXPECT_EQ(2U, success_callback_count_); | 630 EXPECT_EQ(2U, success_callback_count_); |
| 626 EXPECT_EQ(2U, error_callback_count_); | 631 EXPECT_EQ(2U, error_callback_count_); |
| 627 } | 632 } |
| 628 | 633 |
| 629 } // namespace chromeos | 634 } // namespace chromeos |
| OLD | NEW |