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" | 8 #include "chromeos/dbus/dbus_thread_manager.h" |
9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 9 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 10 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 dbus_setter->SetBluetoothProfileManagerClient( | 69 dbus_setter->SetBluetoothProfileManagerClient( |
70 scoped_ptr<BluetoothProfileManagerClient>( | 70 scoped_ptr<BluetoothProfileManagerClient>( |
71 new FakeBluetoothProfileManagerClient)); | 71 new FakeBluetoothProfileManagerClient)); |
72 | 72 |
73 BluetoothSocketThread::Get(); | 73 BluetoothSocketThread::Get(); |
74 | 74 |
75 // Grab a pointer to the adapter. | 75 // Grab a pointer to the adapter. |
76 device::BluetoothAdapterFactory::GetAdapter( | 76 device::BluetoothAdapterFactory::GetAdapter( |
77 base::Bind(&BluetoothSocketChromeOSTest::AdapterCallback, | 77 base::Bind(&BluetoothSocketChromeOSTest::AdapterCallback, |
78 base::Unretained(this))); | 78 base::Unretained(this))); |
79 ASSERT_TRUE(adapter_.get() != NULL); | 79 ASSERT_TRUE(adapter_.get() != nullptr); |
80 ASSERT_TRUE(adapter_->IsInitialized()); | 80 ASSERT_TRUE(adapter_->IsInitialized()); |
81 ASSERT_TRUE(adapter_->IsPresent()); | 81 ASSERT_TRUE(adapter_->IsPresent()); |
82 | 82 |
83 // Turn on the adapter. | 83 // Turn on the adapter. |
84 adapter_->SetPowered( | 84 adapter_->SetPowered( |
85 true, | 85 true, |
86 base::Bind(&base::DoNothing), | 86 base::Bind(&base::DoNothing), |
87 base::Bind(&base::DoNothing)); | 87 base::Bind(&base::DoNothing)); |
88 ASSERT_TRUE(adapter_->IsPowered()); | 88 ASSERT_TRUE(adapter_->IsPowered()); |
89 } | 89 } |
90 | 90 |
91 void TearDown() override { | 91 void TearDown() override { |
92 adapter_ = NULL; | 92 adapter_ = nullptr; |
93 BluetoothSocketThread::CleanupForTesting(); | 93 BluetoothSocketThread::CleanupForTesting(); |
94 DBusThreadManager::Shutdown(); | 94 DBusThreadManager::Shutdown(); |
95 } | 95 } |
96 | 96 |
97 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { | 97 void AdapterCallback(scoped_refptr<BluetoothAdapter> adapter) { |
98 adapter_ = adapter; | 98 adapter_ = adapter; |
99 } | 99 } |
100 | 100 |
101 void SuccessCallback() { | 101 void SuccessCallback() { |
102 ++success_callback_count_; | 102 ++success_callback_count_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 int last_bytes_sent_; | 177 int last_bytes_sent_; |
178 int last_bytes_received_; | 178 int last_bytes_received_; |
179 scoped_refptr<net::IOBuffer> last_io_buffer_; | 179 scoped_refptr<net::IOBuffer> last_io_buffer_; |
180 BluetoothSocket::ErrorReason last_reason_; | 180 BluetoothSocket::ErrorReason last_reason_; |
181 const BluetoothDevice* last_device_; | 181 const BluetoothDevice* last_device_; |
182 }; | 182 }; |
183 | 183 |
184 TEST_F(BluetoothSocketChromeOSTest, Connect) { | 184 TEST_F(BluetoothSocketChromeOSTest, Connect) { |
185 BluetoothDevice* device = adapter_->GetDevice( | 185 BluetoothDevice* device = adapter_->GetDevice( |
186 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 186 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
187 ASSERT_TRUE(device != NULL); | 187 ASSERT_TRUE(device != nullptr); |
188 | 188 |
189 device->ConnectToService( | 189 device->ConnectToService( |
190 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 190 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
191 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, | 191 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, |
192 base::Unretained(this)), | 192 base::Unretained(this)), |
193 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 193 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
194 base::Unretained(this))); | 194 base::Unretained(this))); |
195 message_loop_.Run(); | 195 message_loop_.Run(); |
196 | 196 |
197 EXPECT_EQ(1U, success_callback_count_); | 197 EXPECT_EQ(1U, success_callback_count_); |
198 EXPECT_EQ(0U, error_callback_count_); | 198 EXPECT_EQ(0U, error_callback_count_); |
199 EXPECT_TRUE(last_socket_.get() != NULL); | 199 EXPECT_TRUE(last_socket_.get() != nullptr); |
200 | 200 |
201 // Take ownership of the socket for the remainder of the test. | 201 // Take ownership of the socket for the remainder of the test. |
202 scoped_refptr<BluetoothSocket> socket = last_socket_; | 202 scoped_refptr<BluetoothSocket> socket = last_socket_; |
203 last_socket_ = NULL; | 203 last_socket_ = nullptr; |
204 success_callback_count_ = 0; | 204 success_callback_count_ = 0; |
205 error_callback_count_ = 0; | 205 error_callback_count_ = 0; |
206 | 206 |
207 // Send data to the socket, expect all of the data to be sent. | 207 // Send data to the socket, expect all of the data to be sent. |
208 scoped_refptr<net::StringIOBuffer> write_buffer( | 208 scoped_refptr<net::StringIOBuffer> write_buffer( |
209 new net::StringIOBuffer("test")); | 209 new net::StringIOBuffer("test")); |
210 | 210 |
211 socket->Send(write_buffer.get(), write_buffer->size(), | 211 socket->Send(write_buffer.get(), write_buffer->size(), |
212 base::Bind(&BluetoothSocketChromeOSTest::SendSuccessCallback, | 212 base::Bind(&BluetoothSocketChromeOSTest::SendSuccessCallback, |
213 base::Unretained(this)), | 213 base::Unretained(this)), |
(...skipping 14 matching lines...) Expand all Loading... |
228 4096, | 228 4096, |
229 base::Bind(&BluetoothSocketChromeOSTest::ReceiveSuccessCallback, | 229 base::Bind(&BluetoothSocketChromeOSTest::ReceiveSuccessCallback, |
230 base::Unretained(this)), | 230 base::Unretained(this)), |
231 base::Bind(&BluetoothSocketChromeOSTest::ReceiveErrorCallback, | 231 base::Bind(&BluetoothSocketChromeOSTest::ReceiveErrorCallback, |
232 base::Unretained(this))); | 232 base::Unretained(this))); |
233 message_loop_.Run(); | 233 message_loop_.Run(); |
234 | 234 |
235 EXPECT_EQ(1U, success_callback_count_); | 235 EXPECT_EQ(1U, success_callback_count_); |
236 EXPECT_EQ(0U, error_callback_count_); | 236 EXPECT_EQ(0U, error_callback_count_); |
237 EXPECT_EQ(4, last_bytes_received_); | 237 EXPECT_EQ(4, last_bytes_received_); |
238 EXPECT_TRUE(last_io_buffer_.get() != NULL); | 238 EXPECT_TRUE(last_io_buffer_.get() != nullptr); |
239 | 239 |
240 // Take ownership of the received buffer. | 240 // Take ownership of the received buffer. |
241 scoped_refptr<net::IOBuffer> read_buffer = last_io_buffer_; | 241 scoped_refptr<net::IOBuffer> read_buffer = last_io_buffer_; |
242 last_io_buffer_ = NULL; | 242 last_io_buffer_ = nullptr; |
243 success_callback_count_ = 0; | 243 success_callback_count_ = 0; |
244 error_callback_count_ = 0; | 244 error_callback_count_ = 0; |
245 | 245 |
246 std::string data = std::string(read_buffer->data(), last_bytes_received_); | 246 std::string data = std::string(read_buffer->data(), last_bytes_received_); |
247 EXPECT_EQ("test", data); | 247 EXPECT_EQ("test", data); |
248 | 248 |
249 read_buffer = NULL; | 249 read_buffer = nullptr; |
250 | 250 |
251 // Receive data again; the socket will have been closed, this should cause a | 251 // Receive data again; the socket will have been closed, this should cause a |
252 // disconnected error to be returned via the error callback. | 252 // disconnected error to be returned via the error callback. |
253 socket->Receive( | 253 socket->Receive( |
254 4096, | 254 4096, |
255 base::Bind(&BluetoothSocketChromeOSTest::ReceiveSuccessCallback, | 255 base::Bind(&BluetoothSocketChromeOSTest::ReceiveSuccessCallback, |
256 base::Unretained(this)), | 256 base::Unretained(this)), |
257 base::Bind(&BluetoothSocketChromeOSTest::ReceiveErrorCallback, | 257 base::Bind(&BluetoothSocketChromeOSTest::ReceiveErrorCallback, |
258 base::Unretained(this))); | 258 base::Unretained(this))); |
259 message_loop_.Run(); | 259 message_loop_.Run(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 BluetoothAdapter::ServiceOptions(), | 298 BluetoothAdapter::ServiceOptions(), |
299 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 299 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
300 base::Unretained(this)), | 300 base::Unretained(this)), |
301 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 301 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
302 base::Unretained(this))); | 302 base::Unretained(this))); |
303 | 303 |
304 message_loop_.Run(); | 304 message_loop_.Run(); |
305 | 305 |
306 EXPECT_EQ(1U, success_callback_count_); | 306 EXPECT_EQ(1U, success_callback_count_); |
307 EXPECT_EQ(0U, error_callback_count_); | 307 EXPECT_EQ(0U, error_callback_count_); |
308 EXPECT_TRUE(last_socket_.get() != NULL); | 308 EXPECT_TRUE(last_socket_.get() != nullptr); |
309 | 309 |
310 // Take ownership of the socket for the remainder of the test. | 310 // Take ownership of the socket for the remainder of the test. |
311 scoped_refptr<BluetoothSocket> server_socket = last_socket_; | 311 scoped_refptr<BluetoothSocket> server_socket = last_socket_; |
312 last_socket_ = NULL; | 312 last_socket_ = nullptr; |
313 success_callback_count_ = 0; | 313 success_callback_count_ = 0; |
314 error_callback_count_ = 0; | 314 error_callback_count_ = 0; |
315 | 315 |
316 // Simulate an incoming connection by just calling the ConnectProfile method | 316 // Simulate an incoming connection by just calling the ConnectProfile method |
317 // of the underlying fake device client (from the BlueZ point of view, | 317 // of the underlying fake device client (from the BlueZ point of view, |
318 // outgoing and incoming look the same). | 318 // outgoing and incoming look the same). |
319 // | 319 // |
320 // This is done before the Accept() call to simulate a pending call at the | 320 // This is done before the Accept() call to simulate a pending call at the |
321 // point that Accept() is called. | 321 // point that Accept() is called. |
322 FakeBluetoothDeviceClient* fake_bluetooth_device_client = | 322 FakeBluetoothDeviceClient* fake_bluetooth_device_client = |
323 static_cast<FakeBluetoothDeviceClient*>( | 323 static_cast<FakeBluetoothDeviceClient*>( |
324 DBusThreadManager::Get()->GetBluetoothDeviceClient()); | 324 DBusThreadManager::Get()->GetBluetoothDeviceClient()); |
325 BluetoothDevice* device = adapter_->GetDevice( | 325 BluetoothDevice* device = adapter_->GetDevice( |
326 FakeBluetoothDeviceClient::kPairedDeviceAddress); | 326 FakeBluetoothDeviceClient::kPairedDeviceAddress); |
327 ASSERT_TRUE(device != NULL); | 327 ASSERT_TRUE(device != nullptr); |
328 fake_bluetooth_device_client->ConnectProfile( | 328 fake_bluetooth_device_client->ConnectProfile( |
329 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), | 329 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), |
330 FakeBluetoothProfileManagerClient::kRfcommUuid, | 330 FakeBluetoothProfileManagerClient::kRfcommUuid, |
331 base::Bind(&base::DoNothing), | 331 base::Bind(&base::DoNothing), |
332 base::Bind(&DoNothingDBusErrorCallback)); | 332 base::Bind(&DoNothingDBusErrorCallback)); |
333 | 333 |
334 message_loop_.RunUntilIdle(); | 334 message_loop_.RunUntilIdle(); |
335 | 335 |
336 server_socket->Accept( | 336 server_socket->Accept( |
337 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | 337 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
338 base::Unretained(this)), | 338 base::Unretained(this)), |
339 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 339 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
340 base::Unretained(this))); | 340 base::Unretained(this))); |
341 | 341 |
342 message_loop_.Run(); | 342 message_loop_.Run(); |
343 | 343 |
344 EXPECT_EQ(1U, success_callback_count_); | 344 EXPECT_EQ(1U, success_callback_count_); |
345 EXPECT_EQ(0U, error_callback_count_); | 345 EXPECT_EQ(0U, error_callback_count_); |
346 EXPECT_TRUE(last_socket_.get() != NULL); | 346 EXPECT_TRUE(last_socket_.get() != nullptr); |
347 | 347 |
348 // Take ownership of the client socket for the remainder of the test. | 348 // Take ownership of the client socket for the remainder of the test. |
349 scoped_refptr<BluetoothSocket> client_socket = last_socket_; | 349 scoped_refptr<BluetoothSocket> client_socket = last_socket_; |
350 last_socket_ = NULL; | 350 last_socket_ = nullptr; |
351 success_callback_count_ = 0; | 351 success_callback_count_ = 0; |
352 error_callback_count_ = 0; | 352 error_callback_count_ = 0; |
353 | 353 |
354 // Close our end of the client socket. | 354 // Close our end of the client socket. |
355 client_socket->Disconnect( | 355 client_socket->Disconnect( |
356 base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback, | 356 base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback, |
357 base::Unretained(this))); | 357 base::Unretained(this))); |
358 | 358 |
359 message_loop_.Run(); | 359 message_loop_.Run(); |
360 | 360 |
361 EXPECT_EQ(1U, success_callback_count_); | 361 EXPECT_EQ(1U, success_callback_count_); |
362 client_socket = NULL; | 362 client_socket = nullptr; |
363 success_callback_count_ = 0; | 363 success_callback_count_ = 0; |
364 error_callback_count_ = 0; | 364 error_callback_count_ = 0; |
365 | 365 |
366 // Run a second connection test, this time calling Accept() before the | 366 // Run a second connection test, this time calling Accept() before the |
367 // incoming connection comes in. | 367 // incoming connection comes in. |
368 server_socket->Accept( | 368 server_socket->Accept( |
369 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | 369 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
370 base::Unretained(this)), | 370 base::Unretained(this)), |
371 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 371 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
372 base::Unretained(this))); | 372 base::Unretained(this))); |
373 | 373 |
374 message_loop_.RunUntilIdle(); | 374 message_loop_.RunUntilIdle(); |
375 | 375 |
376 fake_bluetooth_device_client->ConnectProfile( | 376 fake_bluetooth_device_client->ConnectProfile( |
377 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), | 377 static_cast<BluetoothDeviceChromeOS*>(device)->object_path(), |
378 FakeBluetoothProfileManagerClient::kRfcommUuid, | 378 FakeBluetoothProfileManagerClient::kRfcommUuid, |
379 base::Bind(&base::DoNothing), | 379 base::Bind(&base::DoNothing), |
380 base::Bind(&DoNothingDBusErrorCallback)); | 380 base::Bind(&DoNothingDBusErrorCallback)); |
381 | 381 |
382 message_loop_.Run(); | 382 message_loop_.Run(); |
383 | 383 |
384 EXPECT_EQ(1U, success_callback_count_); | 384 EXPECT_EQ(1U, success_callback_count_); |
385 EXPECT_EQ(0U, error_callback_count_); | 385 EXPECT_EQ(0U, error_callback_count_); |
386 EXPECT_TRUE(last_socket_.get() != NULL); | 386 EXPECT_TRUE(last_socket_.get() != nullptr); |
387 | 387 |
388 // Take ownership of the client socket for the remainder of the test. | 388 // Take ownership of the client socket for the remainder of the test. |
389 client_socket = last_socket_; | 389 client_socket = last_socket_; |
390 last_socket_ = NULL; | 390 last_socket_ = nullptr; |
391 success_callback_count_ = 0; | 391 success_callback_count_ = 0; |
392 error_callback_count_ = 0; | 392 error_callback_count_ = 0; |
393 | 393 |
394 // Close our end of the client socket. | 394 // Close our end of the client socket. |
395 client_socket->Disconnect( | 395 client_socket->Disconnect( |
396 base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback, | 396 base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback, |
397 base::Unretained(this))); | 397 base::Unretained(this))); |
398 | 398 |
399 message_loop_.Run(); | 399 message_loop_.Run(); |
400 | 400 |
401 EXPECT_EQ(1U, success_callback_count_); | 401 EXPECT_EQ(1U, success_callback_count_); |
402 client_socket = NULL; | 402 client_socket = nullptr; |
403 success_callback_count_ = 0; | 403 success_callback_count_ = 0; |
404 error_callback_count_ = 0; | 404 error_callback_count_ = 0; |
405 | 405 |
406 // Now close the server socket. | 406 // Now close the server socket. |
407 server_socket->Disconnect( | 407 server_socket->Disconnect( |
408 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, | 408 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, |
409 base::Unretained(this))); | 409 base::Unretained(this))); |
410 | 410 |
411 message_loop_.RunUntilIdle(); | 411 message_loop_.RunUntilIdle(); |
412 | 412 |
(...skipping 12 matching lines...) Expand all Loading... |
425 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 425 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
426 BluetoothAdapter::ServiceOptions(), | 426 BluetoothAdapter::ServiceOptions(), |
427 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 427 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
428 base::Unretained(this)), | 428 base::Unretained(this)), |
429 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 429 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
430 base::Unretained(this))); | 430 base::Unretained(this))); |
431 message_loop_.Run(); | 431 message_loop_.Run(); |
432 | 432 |
433 EXPECT_EQ(1U, success_callback_count_); | 433 EXPECT_EQ(1U, success_callback_count_); |
434 EXPECT_EQ(0U, error_callback_count_); | 434 EXPECT_EQ(0U, error_callback_count_); |
435 EXPECT_TRUE(last_socket_.get() != NULL); | 435 EXPECT_TRUE(last_socket_.get() != nullptr); |
436 | 436 |
437 // Take ownership of the socket for the remainder of the test. | 437 // Take ownership of the socket for the remainder of the test. |
438 scoped_refptr<BluetoothSocket> socket = last_socket_; | 438 scoped_refptr<BluetoothSocket> socket = last_socket_; |
439 last_socket_ = NULL; | 439 last_socket_ = nullptr; |
440 success_callback_count_ = 0; | 440 success_callback_count_ = 0; |
441 error_callback_count_ = 0; | 441 error_callback_count_ = 0; |
442 | 442 |
443 // But there shouldn't be a profile registered yet. | 443 // But there shouldn't be a profile registered yet. |
444 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 444 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = |
445 static_cast<FakeBluetoothProfileManagerClient*>( | 445 static_cast<FakeBluetoothProfileManagerClient*>( |
446 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); | 446 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); |
447 FakeBluetoothProfileServiceProvider* profile_service_provider = | 447 FakeBluetoothProfileServiceProvider* profile_service_provider = |
448 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 448 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
449 FakeBluetoothProfileManagerClient::kRfcommUuid); | 449 FakeBluetoothProfileManagerClient::kRfcommUuid); |
450 EXPECT_TRUE(profile_service_provider == NULL); | 450 EXPECT_TRUE(profile_service_provider == nullptr); |
451 | 451 |
452 // Make the adapter visible. This should register a profile. | 452 // Make the adapter visible. This should register a profile. |
453 fake_bluetooth_adapter_client->SetVisible(true); | 453 fake_bluetooth_adapter_client->SetVisible(true); |
454 | 454 |
455 message_loop_.RunUntilIdle(); | 455 message_loop_.RunUntilIdle(); |
456 | 456 |
457 profile_service_provider = | 457 profile_service_provider = |
458 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 458 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
459 FakeBluetoothProfileManagerClient::kRfcommUuid); | 459 FakeBluetoothProfileManagerClient::kRfcommUuid); |
460 EXPECT_TRUE(profile_service_provider != NULL); | 460 EXPECT_TRUE(profile_service_provider != nullptr); |
461 | 461 |
462 // Cleanup the socket. | 462 // Cleanup the socket. |
463 socket->Disconnect( | 463 socket->Disconnect( |
464 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, | 464 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, |
465 base::Unretained(this))); | 465 base::Unretained(this))); |
466 | 466 |
467 message_loop_.RunUntilIdle(); | 467 message_loop_.RunUntilIdle(); |
468 | 468 |
469 EXPECT_EQ(1U, success_callback_count_); | 469 EXPECT_EQ(1U, success_callback_count_); |
470 } | 470 } |
471 | 471 |
472 TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { | 472 TEST_F(BluetoothSocketChromeOSTest, ListenAcrossAdapterRestart) { |
473 // The fake adapter starts off visible by default. | 473 // The fake adapter starts off visible by default. |
474 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = | 474 FakeBluetoothAdapterClient* fake_bluetooth_adapter_client = |
475 static_cast<FakeBluetoothAdapterClient*>( | 475 static_cast<FakeBluetoothAdapterClient*>( |
476 DBusThreadManager::Get()->GetBluetoothAdapterClient()); | 476 DBusThreadManager::Get()->GetBluetoothAdapterClient()); |
477 | 477 |
478 adapter_->CreateRfcommService( | 478 adapter_->CreateRfcommService( |
479 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 479 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
480 BluetoothAdapter::ServiceOptions(), | 480 BluetoothAdapter::ServiceOptions(), |
481 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 481 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
482 base::Unretained(this)), | 482 base::Unretained(this)), |
483 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 483 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
484 base::Unretained(this))); | 484 base::Unretained(this))); |
485 message_loop_.Run(); | 485 message_loop_.Run(); |
486 | 486 |
487 EXPECT_EQ(1U, success_callback_count_); | 487 EXPECT_EQ(1U, success_callback_count_); |
488 EXPECT_EQ(0U, error_callback_count_); | 488 EXPECT_EQ(0U, error_callback_count_); |
489 EXPECT_TRUE(last_socket_.get() != NULL); | 489 EXPECT_TRUE(last_socket_.get() != nullptr); |
490 | 490 |
491 // Take ownership of the socket for the remainder of the test. | 491 // Take ownership of the socket for the remainder of the test. |
492 scoped_refptr<BluetoothSocket> socket = last_socket_; | 492 scoped_refptr<BluetoothSocket> socket = last_socket_; |
493 last_socket_ = NULL; | 493 last_socket_ = nullptr; |
494 success_callback_count_ = 0; | 494 success_callback_count_ = 0; |
495 error_callback_count_ = 0; | 495 error_callback_count_ = 0; |
496 | 496 |
497 // Make sure the profile was registered with the daemon. | 497 // Make sure the profile was registered with the daemon. |
498 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = | 498 FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client = |
499 static_cast<FakeBluetoothProfileManagerClient*>( | 499 static_cast<FakeBluetoothProfileManagerClient*>( |
500 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); | 500 DBusThreadManager::Get()->GetBluetoothProfileManagerClient()); |
501 FakeBluetoothProfileServiceProvider* profile_service_provider = | 501 FakeBluetoothProfileServiceProvider* profile_service_provider = |
502 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 502 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
503 FakeBluetoothProfileManagerClient::kRfcommUuid); | 503 FakeBluetoothProfileManagerClient::kRfcommUuid); |
504 EXPECT_TRUE(profile_service_provider != NULL); | 504 EXPECT_TRUE(profile_service_provider != nullptr); |
505 | 505 |
506 // Make the adapter invisible, and fiddle with the profile fake to unregister | 506 // Make the adapter invisible, and fiddle with the profile fake to unregister |
507 // the profile since this doesn't happen automatically. | 507 // the profile since this doesn't happen automatically. |
508 fake_bluetooth_adapter_client->SetVisible(false); | 508 fake_bluetooth_adapter_client->SetVisible(false); |
509 | 509 |
510 message_loop_.RunUntilIdle(); | 510 message_loop_.RunUntilIdle(); |
511 | 511 |
512 // Then make the adapter visible again. This should re-register the profile. | 512 // Then make the adapter visible again. This should re-register the profile. |
513 fake_bluetooth_adapter_client->SetVisible(true); | 513 fake_bluetooth_adapter_client->SetVisible(true); |
514 | 514 |
515 message_loop_.RunUntilIdle(); | 515 message_loop_.RunUntilIdle(); |
516 | 516 |
517 profile_service_provider = | 517 profile_service_provider = |
518 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( | 518 fake_bluetooth_profile_manager_client->GetProfileServiceProvider( |
519 FakeBluetoothProfileManagerClient::kRfcommUuid); | 519 FakeBluetoothProfileManagerClient::kRfcommUuid); |
520 EXPECT_TRUE(profile_service_provider != NULL); | 520 EXPECT_TRUE(profile_service_provider != nullptr); |
521 | 521 |
522 // Cleanup the socket. | 522 // Cleanup the socket. |
523 socket->Disconnect( | 523 socket->Disconnect( |
524 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, | 524 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback, |
525 base::Unretained(this))); | 525 base::Unretained(this))); |
526 | 526 |
527 message_loop_.RunUntilIdle(); | 527 message_loop_.RunUntilIdle(); |
528 | 528 |
529 EXPECT_EQ(1U, success_callback_count_); | 529 EXPECT_EQ(1U, success_callback_count_); |
530 } | 530 } |
531 | 531 |
532 TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { | 532 TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { |
533 BluetoothDevice* device = adapter_->GetDevice( | 533 BluetoothDevice* device = adapter_->GetDevice( |
534 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); | 534 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress); |
535 ASSERT_TRUE(device != NULL); | 535 ASSERT_TRUE(device != nullptr); |
536 | 536 |
537 device->ConnectToService( | 537 device->ConnectToService( |
538 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 538 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
539 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, | 539 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, |
540 base::Unretained(this)), | 540 base::Unretained(this)), |
541 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 541 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
542 base::Unretained(this))); | 542 base::Unretained(this))); |
543 message_loop_.Run(); | 543 message_loop_.Run(); |
544 | 544 |
545 EXPECT_EQ(0U, success_callback_count_); | 545 EXPECT_EQ(0U, success_callback_count_); |
546 EXPECT_EQ(1U, error_callback_count_); | 546 EXPECT_EQ(1U, error_callback_count_); |
547 EXPECT_TRUE(last_socket_.get() == NULL); | 547 EXPECT_TRUE(last_socket_.get() == nullptr); |
548 | 548 |
549 device->ConnectToService( | 549 device->ConnectToService( |
550 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 550 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
551 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, | 551 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback, |
552 base::Unretained(this)), | 552 base::Unretained(this)), |
553 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 553 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
554 base::Unretained(this))); | 554 base::Unretained(this))); |
555 message_loop_.Run(); | 555 message_loop_.Run(); |
556 | 556 |
557 EXPECT_EQ(0U, success_callback_count_); | 557 EXPECT_EQ(0U, success_callback_count_); |
558 EXPECT_EQ(2U, error_callback_count_); | 558 EXPECT_EQ(2U, error_callback_count_); |
559 EXPECT_TRUE(last_socket_.get() == NULL); | 559 EXPECT_TRUE(last_socket_.get() == nullptr); |
560 } | 560 } |
561 | 561 |
562 TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { | 562 TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { |
563 adapter_->CreateRfcommService( | 563 adapter_->CreateRfcommService( |
564 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 564 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
565 BluetoothAdapter::ServiceOptions(), | 565 BluetoothAdapter::ServiceOptions(), |
566 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 566 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
567 base::Unretained(this)), | 567 base::Unretained(this)), |
568 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 568 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
569 base::Unretained(this))); | 569 base::Unretained(this))); |
570 | 570 |
571 message_loop_.Run(); | 571 message_loop_.Run(); |
572 | 572 |
573 EXPECT_EQ(1U, success_callback_count_); | 573 EXPECT_EQ(1U, success_callback_count_); |
574 EXPECT_EQ(0U, error_callback_count_); | 574 EXPECT_EQ(0U, error_callback_count_); |
575 EXPECT_TRUE(last_socket_.get() != NULL); | 575 EXPECT_TRUE(last_socket_.get() != nullptr); |
576 | 576 |
577 // Take control of this socket. | 577 // Take control of this socket. |
578 scoped_refptr<BluetoothSocket> server_socket; | 578 scoped_refptr<BluetoothSocket> server_socket; |
579 server_socket.swap(last_socket_); | 579 server_socket.swap(last_socket_); |
580 | 580 |
581 server_socket->Accept( | 581 server_socket->Accept( |
582 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | 582 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
583 base::Unretained(this)), | 583 base::Unretained(this)), |
584 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 584 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
585 base::Unretained(this))); | 585 base::Unretained(this))); |
586 | 586 |
587 server_socket->Close(); | 587 server_socket->Close(); |
588 | 588 |
589 server_socket = NULL; | 589 server_socket = nullptr; |
590 | 590 |
591 message_loop_.RunUntilIdle(); | 591 message_loop_.RunUntilIdle(); |
592 | 592 |
593 EXPECT_EQ(1U, success_callback_count_); | 593 EXPECT_EQ(1U, success_callback_count_); |
594 EXPECT_EQ(1U, error_callback_count_); | 594 EXPECT_EQ(1U, error_callback_count_); |
595 | 595 |
596 adapter_->CreateRfcommService( | 596 adapter_->CreateRfcommService( |
597 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), | 597 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
598 BluetoothAdapter::ServiceOptions(), | 598 BluetoothAdapter::ServiceOptions(), |
599 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, | 599 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
600 base::Unretained(this)), | 600 base::Unretained(this)), |
601 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 601 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
602 base::Unretained(this))); | 602 base::Unretained(this))); |
603 | 603 |
604 message_loop_.Run(); | 604 message_loop_.Run(); |
605 | 605 |
606 EXPECT_EQ(2U, success_callback_count_); | 606 EXPECT_EQ(2U, success_callback_count_); |
607 EXPECT_EQ(1U, error_callback_count_); | 607 EXPECT_EQ(1U, error_callback_count_); |
608 EXPECT_TRUE(last_socket_.get() != NULL); | 608 EXPECT_TRUE(last_socket_.get() != nullptr); |
609 | 609 |
610 // Take control of this socket. | 610 // Take control of this socket. |
611 server_socket.swap(last_socket_); | 611 server_socket.swap(last_socket_); |
612 | 612 |
613 server_socket->Accept( | 613 server_socket->Accept( |
614 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | 614 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
615 base::Unretained(this)), | 615 base::Unretained(this)), |
616 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 616 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
617 base::Unretained(this))); | 617 base::Unretained(this))); |
618 | 618 |
619 server_socket->Close(); | 619 server_socket->Close(); |
620 | 620 |
621 server_socket = NULL; | 621 server_socket = nullptr; |
622 | 622 |
623 message_loop_.RunUntilIdle(); | 623 message_loop_.RunUntilIdle(); |
624 | 624 |
625 EXPECT_EQ(2U, success_callback_count_); | 625 EXPECT_EQ(2U, success_callback_count_); |
626 EXPECT_EQ(2U, error_callback_count_); | 626 EXPECT_EQ(2U, error_callback_count_); |
627 } | 627 } |
628 | 628 |
629 } // namespace chromeos | 629 } // namespace chromeos |
OLD | NEW |