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 ef1618329882ac570fae39f9c112f609eccbc9a0..6b2fde2edff0fbb167d84db8c158907b87b4eeca 100644 |
--- a/google_apis/gcm/engine/connection_factory_impl_unittest.cc |
+++ b/google_apis/gcm/engine/connection_factory_impl_unittest.cc |
@@ -387,8 +387,8 @@ TEST_F(ConnectionFactoryImplTest, MultipleFailuresThenSucceed) { |
EXPECT_TRUE(connected_server().is_valid()); |
} |
-// IP events should trigger canary connections. |
-TEST_F(ConnectionFactoryImplTest, FailThenIPEvent) { |
+// Network change events should trigger canary connections. |
+TEST_F(ConnectionFactoryImplTest, FailThenNetworkChangeEvent) { |
factory()->SetConnectResult(net::ERR_CONNECTION_FAILED); |
factory()->Connect(); |
WaitForConnections(); |
@@ -396,26 +396,7 @@ TEST_F(ConnectionFactoryImplTest, FailThenIPEvent) { |
EXPECT_FALSE(initial_backoff.is_null()); |
factory()->SetConnectResult(net::ERR_FAILED); |
- factory()->OnIPAddressChanged(); |
- WaitForConnections(); |
- |
- // Backoff should increase. |
- base::TimeTicks next_backoff = factory()->NextRetryAttempt(); |
- EXPECT_GT(next_backoff, initial_backoff); |
- EXPECT_FALSE(factory()->IsEndpointReachable()); |
-} |
- |
-// Connection type events should trigger canary connections. |
-TEST_F(ConnectionFactoryImplTest, FailThenConnectionTypeEvent) { |
- factory()->SetConnectResult(net::ERR_CONNECTION_FAILED); |
- factory()->Connect(); |
- WaitForConnections(); |
- base::TimeTicks initial_backoff = factory()->NextRetryAttempt(); |
- EXPECT_FALSE(initial_backoff.is_null()); |
- |
- factory()->SetConnectResult(net::ERR_FAILED); |
- factory()->OnConnectionTypeChanged( |
- net::NetworkChangeNotifier::CONNECTION_WIFI); |
+ factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_WIFI); |
WaitForConnections(); |
// Backoff should increase. |
@@ -434,8 +415,7 @@ TEST_F(ConnectionFactoryImplTest, CanarySucceedsThenDisconnects) { |
EXPECT_FALSE(initial_backoff.is_null()); |
factory()->SetConnectResult(net::OK); |
- factory()->OnConnectionTypeChanged( |
- net::NetworkChangeNotifier::CONNECTION_WIFI); |
+ factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_WIFI); |
fgorski
2014/06/19 20:01:49
nit: can we try other stuff than wifi here? CONNEC
Nicolas Zea
2014/06/19 21:50:04
Well, the code doesn't care what type of connectio
|
WaitForConnections(); |
EXPECT_TRUE(factory()->IsEndpointReachable()); |
EXPECT_TRUE(connected_server().is_valid()); |
@@ -460,8 +440,7 @@ TEST_F(ConnectionFactoryImplTest, CanarySucceedsRetryDuringLogin) { |
factory()->SetDelayLogin(true); |
factory()->SetConnectResult(net::OK); |
- factory()->OnConnectionTypeChanged( |
- net::NetworkChangeNotifier::CONNECTION_WIFI); |
+ factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_WIFI); |
WaitForConnections(); |
EXPECT_FALSE(factory()->IsEndpointReachable()); |
@@ -545,4 +524,29 @@ TEST_F(ConnectionFactoryImplTest, SignalResetRestoresBackoff) { |
EXPECT_FALSE(connected_server().is_valid()); |
} |
+// When the network is disconnected, close the socket and suppress further |
+// connection attempts until the network returns. |
+TEST_F(ConnectionFactoryImplTest, SuppressConnectWhenNoNetwork) { |
+ factory()->SetConnectResult(net::OK); |
+ factory()->Connect(); |
+ EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); |
+ EXPECT_TRUE(factory()->IsEndpointReachable()); |
+ |
+ // Advance clock so the login window reset isn't encountered. |
+ factory()->tick_clock()->Advance(base::TimeDelta::FromSeconds(11)); |
+ |
+ // Will trigger reset, but will not attempt a new connection. |
+ factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_NONE); |
+ EXPECT_FALSE(factory()->IsEndpointReachable()); |
+ EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); |
+ |
+ // When the network returns, attempt to connect. |
+ factory()->SetConnectResult(net::OK); |
+ factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_WIFI); |
+ WaitForConnections(); |
+ |
+ EXPECT_TRUE(factory()->IsEndpointReachable()); |
+ EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); |
+} |
+ |
} // namespace gcm |