| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 void SuccessCallback() { | 101 void SuccessCallback() { |
| 102 ++success_callback_count_; | 102 ++success_callback_count_; |
| 103 message_loop_.Quit(); | 103 message_loop_.Quit(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ErrorCallback(const std::string& message) { | 106 void ErrorCallback(const std::string& message) { |
| 107 ++error_callback_count_; | 107 ++error_callback_count_; |
| 108 last_message_ = message; | 108 last_message_ = message; |
| 109 | 109 |
| 110 if (message_loop_.is_running()) | 110 message_loop_.Quit(); |
| 111 message_loop_.Quit(); | |
| 112 } | 111 } |
| 113 | 112 |
| 114 void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { | 113 void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { |
| 115 ++success_callback_count_; | 114 ++success_callback_count_; |
| 116 last_socket_ = socket; | 115 last_socket_ = socket; |
| 117 | 116 |
| 118 message_loop_.Quit(); | 117 message_loop_.Quit(); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void SendSuccessCallback(int bytes_sent) { | 120 void SendSuccessCallback(int bytes_sent) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 base::Unretained(this)), | 551 base::Unretained(this)), |
| 553 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | 552 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
| 554 base::Unretained(this))); | 553 base::Unretained(this))); |
| 555 message_loop_.Run(); | 554 message_loop_.Run(); |
| 556 | 555 |
| 557 EXPECT_EQ(0U, success_callback_count_); | 556 EXPECT_EQ(0U, success_callback_count_); |
| 558 EXPECT_EQ(2U, error_callback_count_); | 557 EXPECT_EQ(2U, error_callback_count_); |
| 559 EXPECT_TRUE(last_socket_.get() == NULL); | 558 EXPECT_TRUE(last_socket_.get() == NULL); |
| 560 } | 559 } |
| 561 | 560 |
| 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))); | |
| 570 | |
| 571 message_loop_.Run(); | |
| 572 | |
| 573 EXPECT_EQ(1U, success_callback_count_); | |
| 574 EXPECT_EQ(0U, error_callback_count_); | |
| 575 EXPECT_TRUE(last_socket_.get() != NULL); | |
| 576 | |
| 577 // Take control of this socket. | |
| 578 scoped_refptr<BluetoothSocket> server_socket; | |
| 579 server_socket.swap(last_socket_); | |
| 580 | |
| 581 server_socket->Accept( | |
| 582 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | |
| 583 base::Unretained(this)), | |
| 584 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | |
| 585 base::Unretained(this))); | |
| 586 | |
| 587 server_socket->Close(); | |
| 588 | |
| 589 server_socket = NULL; | |
| 590 | |
| 591 message_loop_.RunUntilIdle(); | |
| 592 | |
| 593 EXPECT_EQ(1U, success_callback_count_); | |
| 594 EXPECT_EQ(1U, error_callback_count_); | |
| 595 | |
| 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))); | |
| 603 | |
| 604 message_loop_.Run(); | |
| 605 | |
| 606 EXPECT_EQ(2U, success_callback_count_); | |
| 607 EXPECT_EQ(1U, error_callback_count_); | |
| 608 EXPECT_TRUE(last_socket_.get() != NULL); | |
| 609 | |
| 610 // Take control of this socket. | |
| 611 server_socket.swap(last_socket_); | |
| 612 | |
| 613 server_socket->Accept( | |
| 614 base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, | |
| 615 base::Unretained(this)), | |
| 616 base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, | |
| 617 base::Unretained(this))); | |
| 618 | |
| 619 server_socket->Close(); | |
| 620 | |
| 621 server_socket = NULL; | |
| 622 | |
| 623 message_loop_.RunUntilIdle(); | |
| 624 | |
| 625 EXPECT_EQ(2U, success_callback_count_); | |
| 626 EXPECT_EQ(2U, error_callback_count_); | |
| 627 } | |
| 628 | |
| 629 } // namespace chromeos | 561 } // namespace chromeos |
| OLD | NEW |