Index: google_apis/gcm/engine/connection_factory_impl_unittest.cc |
diff --git a/google_apis/gcm/engine/connection_factory_impl_unittest.cc b/google_apis/gcm/engine/connection_factory_impl_unittest.cc |
index a6c05ebe8c6c225014506a83e6df3a1bedc52425..ed23da9f07e1367a29c9f02e9bdf8ee6c60af54c 100644 |
--- a/google_apis/gcm/engine/connection_factory_impl_unittest.cc |
+++ b/google_apis/gcm/engine/connection_factory_impl_unittest.cc |
@@ -132,6 +132,9 @@ class TestConnectionFactoryImpl : public ConnectionFactoryImpl { |
// Force a login handshake to be delayed. |
void SetDelayLogin(bool delay_login); |
+ // Simulate a socket error. |
+ void SetSocketError(); |
+ |
base::SimpleTestTickClock* tick_clock() { return &tick_clock_; } |
private: |
@@ -184,6 +187,7 @@ TestConnectionFactoryImpl::~TestConnectionFactoryImpl() { |
void TestConnectionFactoryImpl::ConnectImpl() { |
ASSERT_GT(num_expected_attempts_, 0); |
+ ASSERT_FALSE(GetConnectionHandler()->CanSendMessage()); |
scoped_ptr<mcs_proto::LoginRequest> request(BuildLoginRequest(0, 0, "")); |
GetConnectionHandler()->Init(*request, NULL); |
OnConnectDone(connect_result_); |
@@ -255,6 +259,10 @@ void TestConnectionFactoryImpl::SetDelayLogin(bool delay_login) { |
fake_handler_->set_fail_login(delay_login_); |
} |
+void TestConnectionFactoryImpl::SetSocketError() { |
+ fake_handler_->set_had_error(true); |
+} |
+ |
} // namespace |
class ConnectionFactoryImplTest |
@@ -561,4 +569,26 @@ TEST_F(ConnectionFactoryImplTest, NetworkChangeBeforeFirstConnection) { |
EXPECT_TRUE(factory()->IsEndpointReachable()); |
} |
+// Test that if the client attempts to reconnect while a connection is already |
+// open, we don't crash. |
+TEST_F(ConnectionFactoryImplTest, ConnectionResetRace) { |
+ // Initial successful connection. |
+ factory()->SetConnectResult(net::OK); |
+ factory()->Connect(); |
+ WaitForConnections(); |
+ EXPECT_TRUE(factory()->IsEndpointReachable()); |
+ |
+ // Trigger a connection error under the hood. |
+ factory()->SetSocketError(); |
+ EXPECT_FALSE(factory()->IsEndpointReachable()); |
+ |
+ // Now trigger force a re-connection. |
+ factory()->SetConnectResult(net::OK); |
+ factory()->Connect(); |
+ WaitForConnections(); |
+ |
+ // Re-connection should succeed. |
+ EXPECT_TRUE(factory()->IsEndpointReachable()); |
+} |
+ |
} // namespace gcm |