Index: device/bluetooth/bluetooth_socket_chromeos_unittest.cc |
diff --git a/device/bluetooth/bluetooth_socket_chromeos_unittest.cc b/device/bluetooth/bluetooth_socket_chromeos_unittest.cc |
index 8381cdd0b986dc8fe05087c02047f18d4ea06137..7630167e97e5243de279d4e32dea1b654929149d 100644 |
--- a/device/bluetooth/bluetooth_socket_chromeos_unittest.cc |
+++ b/device/bluetooth/bluetooth_socket_chromeos_unittest.cc |
@@ -107,7 +107,8 @@ class BluetoothSocketChromeOSTest : public testing::Test { |
++error_callback_count_; |
last_message_ = message; |
- message_loop_.Quit(); |
+ if (message_loop_.is_running()) |
+ message_loop_.Quit(); |
} |
void ConnectToServiceSuccessCallback(scoped_refptr<BluetoothSocket> socket) { |
@@ -558,4 +559,71 @@ TEST_F(BluetoothSocketChromeOSTest, PairedConnectFails) { |
EXPECT_TRUE(last_socket_.get() == NULL); |
} |
+TEST_F(BluetoothSocketChromeOSTest, SocketListenTwice) { |
+ adapter_->CreateRfcommService( |
+ BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
+ BluetoothAdapter::ServiceOptions(), |
+ base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ |
+ message_loop_.Run(); |
+ |
+ EXPECT_EQ(1U, success_callback_count_); |
+ EXPECT_EQ(0U, error_callback_count_); |
+ EXPECT_TRUE(last_socket_.get() != NULL); |
+ |
+ // Take control of this socket. |
+ scoped_refptr<BluetoothSocket> server_socket; |
+ server_socket.swap(last_socket_); |
+ |
+ server_socket->Accept( |
+ base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ |
+ server_socket->Close(); |
+ |
+ server_socket = NULL; |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(1U, success_callback_count_); |
+ EXPECT_EQ(1U, error_callback_count_); |
+ |
+ adapter_->CreateRfcommService( |
+ BluetoothUUID(FakeBluetoothProfileManagerClient::kRfcommUuid), |
+ BluetoothAdapter::ServiceOptions(), |
+ base::Bind(&BluetoothSocketChromeOSTest::CreateServiceSuccessCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ |
+ message_loop_.Run(); |
+ |
+ EXPECT_EQ(2U, success_callback_count_); |
+ EXPECT_EQ(1U, error_callback_count_); |
+ EXPECT_TRUE(last_socket_.get() != NULL); |
+ |
+ // Take control of this socket. |
+ server_socket.swap(last_socket_); |
+ |
+ server_socket->Accept( |
+ base::Bind(&BluetoothSocketChromeOSTest::AcceptSuccessCallback, |
+ base::Unretained(this)), |
+ base::Bind(&BluetoothSocketChromeOSTest::ErrorCallback, |
+ base::Unretained(this))); |
+ |
+ server_socket->Close(); |
+ |
+ server_socket = NULL; |
+ |
+ message_loop_.RunUntilIdle(); |
+ |
+ EXPECT_EQ(2U, success_callback_count_); |
+ EXPECT_EQ(2U, error_callback_count_); |
+} |
+ |
} // namespace chromeos |