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
3 // found in the LICENSE file.
6 #include "base/memory/ref_counted.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"
17 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
18 #include "device/bluetooth/bluetooth_adapter_factory.h"
19 #include "device/bluetooth/bluetooth_device.h"
20 #include "device/bluetooth/bluetooth_device_chromeos.h"
21 #include "device/bluetooth/bluetooth_socket.h"
22 #include "device/bluetooth/bluetooth_socket_chromeos.h"
23 #include "device/bluetooth/bluetooth_socket_thread.h"
24 #include "device/bluetooth/bluetooth_uuid.h"
25 #include "net/base/io_buffer.h"
26 #include "net/base/net_errors.h"
27 #include "testing/gtest/include/gtest/gtest.h"
29 using device::BluetoothAdapter
;
30 using device::BluetoothDevice
;
31 using device::BluetoothSocket
;
32 using device::BluetoothSocketThread
;
33 using device::BluetoothUUID
;
37 void DoNothingDBusErrorCallback(const std::string
& error_name
,
38 const std::string
& error_message
) {}
44 class BluetoothSocketChromeOSTest
: public testing::Test
{
46 BluetoothSocketChromeOSTest()
47 : success_callback_count_(0),
48 error_callback_count_(0),
50 last_bytes_received_(0),
51 last_reason_(BluetoothSocket::kSystemError
) {}
53 void SetUp() override
{
54 scoped_ptr
<DBusThreadManagerSetter
> dbus_setter
=
55 DBusThreadManager::GetSetterForTesting();
57 dbus_setter
->SetBluetoothAdapterClient(
58 scoped_ptr
<BluetoothAdapterClient
>(new FakeBluetoothAdapterClient
));
59 dbus_setter
->SetBluetoothAgentManagerClient(
60 scoped_ptr
<BluetoothAgentManagerClient
>(
61 new FakeBluetoothAgentManagerClient
));
62 dbus_setter
->SetBluetoothDeviceClient(
63 scoped_ptr
<BluetoothDeviceClient
>(new FakeBluetoothDeviceClient
));
64 dbus_setter
->SetBluetoothGattServiceClient(
65 scoped_ptr
<BluetoothGattServiceClient
>(
66 new FakeBluetoothGattServiceClient
));
67 dbus_setter
->SetBluetoothInputClient(
68 scoped_ptr
<BluetoothInputClient
>(new FakeBluetoothInputClient
));
69 dbus_setter
->SetBluetoothProfileManagerClient(
70 scoped_ptr
<BluetoothProfileManagerClient
>(
71 new FakeBluetoothProfileManagerClient
));
73 BluetoothSocketThread::Get();
75 // Grab a pointer to the adapter.
76 device::BluetoothAdapterFactory::GetAdapter(
77 base::Bind(&BluetoothSocketChromeOSTest::AdapterCallback
,
78 base::Unretained(this)));
79 ASSERT_TRUE(adapter_
.get() != nullptr);
80 ASSERT_TRUE(adapter_
->IsInitialized());
81 ASSERT_TRUE(adapter_
->IsPresent());
83 // Turn on the adapter.
86 base::Bind(&base::DoNothing
),
87 base::Bind(&base::DoNothing
));
88 ASSERT_TRUE(adapter_
->IsPowered());
91 void TearDown() override
{
93 BluetoothSocketThread::CleanupForTesting();
94 DBusThreadManager::Shutdown();
97 void AdapterCallback(scoped_refptr
<BluetoothAdapter
> adapter
) {
101 void SuccessCallback() {
102 ++success_callback_count_
;
103 message_loop_
.Quit();
106 void ErrorCallback(const std::string
& message
) {
107 ++error_callback_count_
;
108 last_message_
= message
;
110 if (message_loop_
.is_running())
111 message_loop_
.Quit();
114 void ConnectToServiceSuccessCallback(scoped_refptr
<BluetoothSocket
> socket
) {
115 ++success_callback_count_
;
116 last_socket_
= socket
;
118 message_loop_
.Quit();
121 void SendSuccessCallback(int bytes_sent
) {
122 ++success_callback_count_
;
123 last_bytes_sent_
= bytes_sent
;
125 message_loop_
.Quit();
128 void ReceiveSuccessCallback(int bytes_received
,
129 scoped_refptr
<net::IOBuffer
> io_buffer
) {
130 ++success_callback_count_
;
131 last_bytes_received_
= bytes_received
;
132 last_io_buffer_
= io_buffer
;
134 message_loop_
.Quit();
137 void ReceiveErrorCallback(BluetoothSocket::ErrorReason reason
,
138 const std::string
& error_message
) {
139 ++error_callback_count_
;
140 last_reason_
= reason
;
141 last_message_
= error_message
;
143 message_loop_
.Quit();
146 void CreateServiceSuccessCallback(scoped_refptr
<BluetoothSocket
> socket
) {
147 ++success_callback_count_
;
148 last_socket_
= socket
;
150 if (message_loop_
.is_running())
151 message_loop_
.Quit();
154 void AcceptSuccessCallback(const BluetoothDevice
* device
,
155 scoped_refptr
<BluetoothSocket
> socket
) {
156 ++success_callback_count_
;
157 last_device_
= device
;
158 last_socket_
= socket
;
160 message_loop_
.Quit();
163 void ImmediateSuccessCallback() {
164 ++success_callback_count_
;
168 base::MessageLoop message_loop_
;
170 scoped_refptr
<BluetoothAdapter
> adapter_
;
172 unsigned int success_callback_count_
;
173 unsigned int error_callback_count_
;
175 std::string last_message_
;
176 scoped_refptr
<BluetoothSocket
> last_socket_
;
177 int last_bytes_sent_
;
178 int last_bytes_received_
;
179 scoped_refptr
<net::IOBuffer
> last_io_buffer_
;
180 BluetoothSocket::ErrorReason last_reason_
;
181 const BluetoothDevice
* last_device_
;
184 TEST_F(BluetoothSocketChromeOSTest
, Connect
) {
185 BluetoothDevice
* device
= adapter_
->GetDevice(
186 FakeBluetoothDeviceClient::kPairedDeviceAddress
);
187 ASSERT_TRUE(device
!= nullptr);
189 device
->ConnectToService(
190 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
191 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback
,
192 base::Unretained(this)),
193 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
194 base::Unretained(this)));
197 EXPECT_EQ(1U, success_callback_count_
);
198 EXPECT_EQ(0U, error_callback_count_
);
199 EXPECT_TRUE(last_socket_
.get() != nullptr);
201 // Take ownership of the socket for the remainder of the test.
202 scoped_refptr
<BluetoothSocket
> socket
= last_socket_
;
203 last_socket_
= nullptr;
204 success_callback_count_
= 0;
205 error_callback_count_
= 0;
207 // Send data to the socket, expect all of the data to be sent.
208 scoped_refptr
<net::StringIOBuffer
> write_buffer(
209 new net::StringIOBuffer("test"));
211 socket
->Send(write_buffer
.get(), write_buffer
->size(),
212 base::Bind(&BluetoothSocketChromeOSTest::SendSuccessCallback
,
213 base::Unretained(this)),
214 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
215 base::Unretained(this)));
218 EXPECT_EQ(1U, success_callback_count_
);
219 EXPECT_EQ(0U, error_callback_count_
);
220 EXPECT_EQ(last_bytes_sent_
, write_buffer
->size());
222 success_callback_count_
= 0;
223 error_callback_count_
= 0;
225 // Receive data from the socket, and fetch the buffer from the callback; since
226 // the fake is an echo server, we expect to receive what we wrote.
229 base::Bind(&BluetoothSocketChromeOSTest::ReceiveSuccessCallback
,
230 base::Unretained(this)),
231 base::Bind(&BluetoothSocketChromeOSTest::ReceiveErrorCallback
,
232 base::Unretained(this)));
235 EXPECT_EQ(1U, success_callback_count_
);
236 EXPECT_EQ(0U, error_callback_count_
);
237 EXPECT_EQ(4, last_bytes_received_
);
238 EXPECT_TRUE(last_io_buffer_
.get() != nullptr);
240 // Take ownership of the received buffer.
241 scoped_refptr
<net::IOBuffer
> read_buffer
= last_io_buffer_
;
242 last_io_buffer_
= nullptr;
243 success_callback_count_
= 0;
244 error_callback_count_
= 0;
246 std::string data
= std::string(read_buffer
->data(), last_bytes_received_
);
247 EXPECT_EQ("test", data
);
249 read_buffer
= nullptr;
251 // Receive data again; the socket will have been closed, this should cause a
252 // disconnected error to be returned via the error callback.
255 base::Bind(&BluetoothSocketChromeOSTest::ReceiveSuccessCallback
,
256 base::Unretained(this)),
257 base::Bind(&BluetoothSocketChromeOSTest::ReceiveErrorCallback
,
258 base::Unretained(this)));
261 EXPECT_EQ(0U, success_callback_count_
);
262 EXPECT_EQ(1U, error_callback_count_
);
263 EXPECT_EQ(BluetoothSocket::kDisconnected
, last_reason_
);
264 EXPECT_EQ(net::ErrorToString(net::OK
), last_message_
);
266 success_callback_count_
= 0;
267 error_callback_count_
= 0;
269 // Send data again; since the socket is closed we should get a system error
270 // equivalent to the connection reset error.
271 write_buffer
= new net::StringIOBuffer("second test");
273 socket
->Send(write_buffer
.get(), write_buffer
->size(),
274 base::Bind(&BluetoothSocketChromeOSTest::SendSuccessCallback
,
275 base::Unretained(this)),
276 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
277 base::Unretained(this)));
280 EXPECT_EQ(0U, success_callback_count_
);
281 EXPECT_EQ(1U, error_callback_count_
);
282 EXPECT_EQ(net::ErrorToString(net::ERR_CONNECTION_RESET
), last_message_
);
284 success_callback_count_
= 0;
285 error_callback_count_
= 0;
287 // Close our end of the socket.
288 socket
->Disconnect(base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback
,
289 base::Unretained(this)));
292 EXPECT_EQ(1U, success_callback_count_
);
295 TEST_F(BluetoothSocketChromeOSTest
, Listen
) {
296 adapter_
->CreateRfcommService(
297 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
298 BluetoothAdapter::ServiceOptions(),
299 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback
,
300 base::Unretained(this)),
301 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
302 base::Unretained(this)));
306 EXPECT_EQ(1U, success_callback_count_
);
307 EXPECT_EQ(0U, error_callback_count_
);
308 EXPECT_TRUE(last_socket_
.get() != nullptr);
310 // Take ownership of the socket for the remainder of the test.
311 scoped_refptr
<BluetoothSocket
> server_socket
= last_socket_
;
312 last_socket_
= nullptr;
313 success_callback_count_
= 0;
314 error_callback_count_
= 0;
316 // Simulate an incoming connection by just calling the ConnectProfile method
317 // of the underlying fake device client (from the BlueZ point of view,
318 // outgoing and incoming look the same).
320 // This is done before the Accept() call to simulate a pending call at the
321 // point that Accept() is called.
322 FakeBluetoothDeviceClient
* fake_bluetooth_device_client
=
323 static_cast<FakeBluetoothDeviceClient
*>(
324 DBusThreadManager::Get()->GetBluetoothDeviceClient());
325 BluetoothDevice
* device
= adapter_
->GetDevice(
326 FakeBluetoothDeviceClient::kPairedDeviceAddress
);
327 ASSERT_TRUE(device
!= nullptr);
328 fake_bluetooth_device_client
->ConnectProfile(
329 static_cast<BluetoothDeviceChromeOS
*>(device
)->object_path(),
330 FakeBluetoothProfileManagerClient::kRfcommUuid
,
331 base::Bind(&base::DoNothing
),
332 base::Bind(&DoNothingDBusErrorCallback
));
334 message_loop_
.RunUntilIdle();
336 server_socket
->Accept(
337 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback
,
338 base::Unretained(this)),
339 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
340 base::Unretained(this)));
344 EXPECT_EQ(1U, success_callback_count_
);
345 EXPECT_EQ(0U, error_callback_count_
);
346 EXPECT_TRUE(last_socket_
.get() != nullptr);
348 // Take ownership of the client socket for the remainder of the test.
349 scoped_refptr
<BluetoothSocket
> client_socket
= last_socket_
;
350 last_socket_
= nullptr;
351 success_callback_count_
= 0;
352 error_callback_count_
= 0;
354 // Close our end of the client socket.
355 client_socket
->Disconnect(
356 base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback
,
357 base::Unretained(this)));
361 EXPECT_EQ(1U, success_callback_count_
);
362 client_socket
= nullptr;
363 success_callback_count_
= 0;
364 error_callback_count_
= 0;
366 // Run a second connection test, this time calling Accept() before the
367 // incoming connection comes in.
368 server_socket
->Accept(
369 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback
,
370 base::Unretained(this)),
371 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
372 base::Unretained(this)));
374 message_loop_
.RunUntilIdle();
376 fake_bluetooth_device_client
->ConnectProfile(
377 static_cast<BluetoothDeviceChromeOS
*>(device
)->object_path(),
378 FakeBluetoothProfileManagerClient::kRfcommUuid
,
379 base::Bind(&base::DoNothing
),
380 base::Bind(&DoNothingDBusErrorCallback
));
384 EXPECT_EQ(1U, success_callback_count_
);
385 EXPECT_EQ(0U, error_callback_count_
);
386 EXPECT_TRUE(last_socket_
.get() != nullptr);
388 // Take ownership of the client socket for the remainder of the test.
389 client_socket
= last_socket_
;
390 last_socket_
= nullptr;
391 success_callback_count_
= 0;
392 error_callback_count_
= 0;
394 // Close our end of the client socket.
395 client_socket
->Disconnect(
396 base::Bind(&BluetoothSocketChromeOSTest::SuccessCallback
,
397 base::Unretained(this)));
401 EXPECT_EQ(1U, success_callback_count_
);
402 client_socket
= nullptr;
403 success_callback_count_
= 0;
404 error_callback_count_
= 0;
406 // Now close the server socket.
407 server_socket
->Disconnect(
408 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback
,
409 base::Unretained(this)));
411 message_loop_
.RunUntilIdle();
413 EXPECT_EQ(1U, success_callback_count_
);
416 TEST_F(BluetoothSocketChromeOSTest
, ListenBeforeAdapterStart
) {
417 // Start off with an invisible adapter, register the profile, then make
418 // the adapter visible.
419 FakeBluetoothAdapterClient
* fake_bluetooth_adapter_client
=
420 static_cast<FakeBluetoothAdapterClient
*>(
421 DBusThreadManager::Get()->GetBluetoothAdapterClient());
422 fake_bluetooth_adapter_client
->SetVisible(false);
424 adapter_
->CreateRfcommService(
425 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
426 BluetoothAdapter::ServiceOptions(),
427 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback
,
428 base::Unretained(this)),
429 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
430 base::Unretained(this)));
433 EXPECT_EQ(1U, success_callback_count_
);
434 EXPECT_EQ(0U, error_callback_count_
);
435 EXPECT_TRUE(last_socket_
.get() != nullptr);
437 // Take ownership of the socket for the remainder of the test.
438 scoped_refptr
<BluetoothSocket
> socket
= last_socket_
;
439 last_socket_
= nullptr;
440 success_callback_count_
= 0;
441 error_callback_count_
= 0;
443 // But there shouldn't be a profile registered yet.
444 FakeBluetoothProfileManagerClient
* fake_bluetooth_profile_manager_client
=
445 static_cast<FakeBluetoothProfileManagerClient
*>(
446 DBusThreadManager::Get()->GetBluetoothProfileManagerClient());
447 FakeBluetoothProfileServiceProvider
* profile_service_provider
=
448 fake_bluetooth_profile_manager_client
->GetProfileServiceProvider(
449 FakeBluetoothProfileManagerClient::kRfcommUuid
);
450 EXPECT_TRUE(profile_service_provider
== nullptr);
452 // Make the adapter visible. This should register a profile.
453 fake_bluetooth_adapter_client
->SetVisible(true);
455 message_loop_
.RunUntilIdle();
457 profile_service_provider
=
458 fake_bluetooth_profile_manager_client
->GetProfileServiceProvider(
459 FakeBluetoothProfileManagerClient::kRfcommUuid
);
460 EXPECT_TRUE(profile_service_provider
!= nullptr);
462 // Cleanup the socket.
464 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback
,
465 base::Unretained(this)));
467 message_loop_
.RunUntilIdle();
469 EXPECT_EQ(1U, success_callback_count_
);
472 TEST_F(BluetoothSocketChromeOSTest
, ListenAcrossAdapterRestart
) {
473 // The fake adapter starts off visible by default.
474 FakeBluetoothAdapterClient
* fake_bluetooth_adapter_client
=
475 static_cast<FakeBluetoothAdapterClient
*>(
476 DBusThreadManager::Get()->GetBluetoothAdapterClient());
478 adapter_
->CreateRfcommService(
479 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
480 BluetoothAdapter::ServiceOptions(),
481 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback
,
482 base::Unretained(this)),
483 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
484 base::Unretained(this)));
487 EXPECT_EQ(1U, success_callback_count_
);
488 EXPECT_EQ(0U, error_callback_count_
);
489 EXPECT_TRUE(last_socket_
.get() != nullptr);
491 // Take ownership of the socket for the remainder of the test.
492 scoped_refptr
<BluetoothSocket
> socket
= last_socket_
;
493 last_socket_
= nullptr;
494 success_callback_count_
= 0;
495 error_callback_count_
= 0;
497 // Make sure the profile was registered with the daemon.
498 FakeBluetoothProfileManagerClient
* fake_bluetooth_profile_manager_client
=
499 static_cast<FakeBluetoothProfileManagerClient
*>(
500 DBusThreadManager::Get()->GetBluetoothProfileManagerClient());
501 FakeBluetoothProfileServiceProvider
* profile_service_provider
=
502 fake_bluetooth_profile_manager_client
->GetProfileServiceProvider(
503 FakeBluetoothProfileManagerClient::kRfcommUuid
);
504 EXPECT_TRUE(profile_service_provider
!= nullptr);
506 // Make the adapter invisible, and fiddle with the profile fake to unregister
507 // the profile since this doesn't happen automatically.
508 fake_bluetooth_adapter_client
->SetVisible(false);
510 message_loop_
.RunUntilIdle();
512 // Then make the adapter visible again. This should re-register the profile.
513 fake_bluetooth_adapter_client
->SetVisible(true);
515 message_loop_
.RunUntilIdle();
517 profile_service_provider
=
518 fake_bluetooth_profile_manager_client
->GetProfileServiceProvider(
519 FakeBluetoothProfileManagerClient::kRfcommUuid
);
520 EXPECT_TRUE(profile_service_provider
!= nullptr);
522 // Cleanup the socket.
524 base::Bind(&BluetoothSocketChromeOSTest::ImmediateSuccessCallback
,
525 base::Unretained(this)));
527 message_loop_
.RunUntilIdle();
529 EXPECT_EQ(1U, success_callback_count_
);
532 TEST_F(BluetoothSocketChromeOSTest
, PairedConnectFails
) {
533 BluetoothDevice
* device
= adapter_
->GetDevice(
534 FakeBluetoothDeviceClient::kPairedUnconnectableDeviceAddress
);
535 ASSERT_TRUE(device
!= nullptr);
537 device
->ConnectToService(
538 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
539 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback
,
540 base::Unretained(this)),
541 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
542 base::Unretained(this)));
545 EXPECT_EQ(0U, success_callback_count_
);
546 EXPECT_EQ(1U, error_callback_count_
);
547 EXPECT_TRUE(last_socket_
.get() == nullptr);
549 device
->ConnectToService(
550 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
551 base::Bind(&BluetoothSocketChromeOSTest::ConnectToServiceSuccessCallback
,
552 base::Unretained(this)),
553 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
554 base::Unretained(this)));
557 EXPECT_EQ(0U, success_callback_count_
);
558 EXPECT_EQ(2U, error_callback_count_
);
559 EXPECT_TRUE(last_socket_
.get() == nullptr);
562 TEST_F(BluetoothSocketChromeOSTest
, SocketListenTwice
) {
563 adapter_
->CreateRfcommService(
564 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
565 BluetoothAdapter::ServiceOptions(),
566 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback
,
567 base::Unretained(this)),
568 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
569 base::Unretained(this)));
573 EXPECT_EQ(1U, success_callback_count_
);
574 EXPECT_EQ(0U, error_callback_count_
);
575 EXPECT_TRUE(last_socket_
.get() != nullptr);
577 // Take control of this socket.
578 scoped_refptr
<BluetoothSocket
> server_socket
;
579 server_socket
.swap(last_socket_
);
581 server_socket
->Accept(
582 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback
,
583 base::Unretained(this)),
584 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
585 base::Unretained(this)));
587 server_socket
->Close();
589 server_socket
= nullptr;
591 message_loop_
.RunUntilIdle();
593 EXPECT_EQ(1U, success_callback_count_
);
594 EXPECT_EQ(1U, error_callback_count_
);
596 adapter_
->CreateRfcommService(
597 BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid
),
598 BluetoothAdapter::ServiceOptions(),
599 base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback
,
600 base::Unretained(this)),
601 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
602 base::Unretained(this)));
606 EXPECT_EQ(2U, success_callback_count_
);
607 EXPECT_EQ(1U, error_callback_count_
);
608 EXPECT_TRUE(last_socket_
.get() != nullptr);
610 // Take control of this socket.
611 server_socket
.swap(last_socket_
);
613 server_socket
->Accept(
614 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback
,
615 base::Unretained(this)),
616 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback
,
617 base::Unretained(this)));
619 server_socket
->Close();
621 server_socket
= nullptr;
623 message_loop_
.RunUntilIdle();
625 EXPECT_EQ(2U, success_callback_count_
);
626 EXPECT_EQ(2U, error_callback_count_
);
629 } // namespace chromeos