| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "google_apis/gcm/engine/connection_factory_impl.h" | 5 #include "google_apis/gcm/engine/connection_factory_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 void ConnectionsComplete(); | 265 void ConnectionsComplete(); |
| 266 | 266 |
| 267 TestConnectionFactoryImpl factory_; | 267 TestConnectionFactoryImpl factory_; |
| 268 base::MessageLoop message_loop_; | 268 base::MessageLoop message_loop_; |
| 269 scoped_ptr<base::RunLoop> run_loop_; | 269 scoped_ptr<base::RunLoop> run_loop_; |
| 270 | 270 |
| 271 GURL connected_server_; | 271 GURL connected_server_; |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 ConnectionFactoryImplTest::ConnectionFactoryImplTest() | 274 ConnectionFactoryImplTest::ConnectionFactoryImplTest() |
| 275 : factory_(base::Bind(&ConnectionFactoryImplTest::ConnectionsComplete, | 275 : factory_(base::Bind(&ConnectionFactoryImplTest::ConnectionsComplete, |
| 276 base::Unretained(this))), | 276 base::Unretained(this))), |
| 277 run_loop_(new base::RunLoop()) { | 277 run_loop_(new base::RunLoop()) { |
| 278 factory()->SetConnectionListener(this); | 278 factory()->SetConnectionListener(this); |
| 279 factory()->Initialize( | 279 factory()->Initialize( |
| 280 ConnectionFactory::BuildLoginRequestCallback(), | 280 ConnectionFactory::BuildLoginRequestCallback(), |
| 281 ConnectionHandler::ProtoReceivedCallback(), | 281 ConnectionHandler::ProtoReceivedCallback(), |
| 282 ConnectionHandler::ProtoSentCallback()); | 282 ConnectionHandler::ProtoSentCallback()); |
| 283 } | 283 } |
| 284 ConnectionFactoryImplTest::~ConnectionFactoryImplTest() {} | 284 ConnectionFactoryImplTest::~ConnectionFactoryImplTest() {} |
| 285 | 285 |
| 286 void ConnectionFactoryImplTest::WaitForConnections() { | 286 void ConnectionFactoryImplTest::WaitForConnections() { |
| 287 run_loop_->Run(); | 287 run_loop_->Run(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 base::TimeTicks initial_backoff = factory()->NextRetryAttempt(); | 426 base::TimeTicks initial_backoff = factory()->NextRetryAttempt(); |
| 427 EXPECT_FALSE(initial_backoff.is_null()); | 427 EXPECT_FALSE(initial_backoff.is_null()); |
| 428 | 428 |
| 429 factory()->SetDelayLogin(true); | 429 factory()->SetDelayLogin(true); |
| 430 factory()->SetConnectResult(net::OK); | 430 factory()->SetConnectResult(net::OK); |
| 431 factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_WIFI); | 431 factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_WIFI); |
| 432 WaitForConnections(); | 432 WaitForConnections(); |
| 433 EXPECT_FALSE(factory()->IsEndpointReachable()); | 433 EXPECT_FALSE(factory()->IsEndpointReachable()); |
| 434 | 434 |
| 435 // Pump the loop, to ensure the pending backoff retry has no effect. | 435 // Pump the loop, to ensure the pending backoff retry has no effect. |
| 436 base::MessageLoop::current()->PostDelayedTask( | 436 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 437 FROM_HERE, | 437 FROM_HERE, |
| 438 base::MessageLoop::QuitClosure(), | 438 base::MessageLoop::QuitClosure(), |
| 439 base::TimeDelta::FromMilliseconds(1)); | 439 base::TimeDelta::FromMilliseconds(1)); |
| 440 WaitForConnections(); | 440 WaitForConnections(); |
| 441 } | 441 } |
| 442 | 442 |
| 443 // Fail after successful connection via signal reset. | 443 // Fail after successful connection via signal reset. |
| 444 TEST_F(ConnectionFactoryImplTest, FailViaSignalReset) { | 444 TEST_F(ConnectionFactoryImplTest, FailViaSignalReset) { |
| 445 factory()->SetConnectResult(net::OK); | 445 factory()->SetConnectResult(net::OK); |
| 446 factory()->Connect(); | 446 factory()->Connect(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 // Now trigger force a re-connection. | 564 // Now trigger force a re-connection. |
| 565 factory()->SetConnectResult(net::OK); | 565 factory()->SetConnectResult(net::OK); |
| 566 factory()->Connect(); | 566 factory()->Connect(); |
| 567 WaitForConnections(); | 567 WaitForConnections(); |
| 568 | 568 |
| 569 // Re-connection should succeed. | 569 // Re-connection should succeed. |
| 570 EXPECT_TRUE(factory()->IsEndpointReachable()); | 570 EXPECT_TRUE(factory()->IsEndpointReachable()); |
| 571 } | 571 } |
| 572 | 572 |
| 573 } // namespace gcm | 573 } // namespace gcm |
| OLD | NEW |