Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Unified Diff: google_apis/gcm/engine/connection_factory_impl_unittest.cc

Issue 793883003: [GCM] Fix gcm network change handling before connect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix leak Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl.cc ('k') | google_apis/gcm/engine/mcs_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 af04fb7473c8b05b53b4bcecde41fe77591e1ae3..74db418be8717516d7dd4a2ad89c6151534cc47c 100644
--- a/google_apis/gcm/engine/connection_factory_impl_unittest.cc
+++ b/google_apis/gcm/engine/connection_factory_impl_unittest.cc
@@ -148,8 +148,12 @@ class TestConnectionFactoryImpl : public ConnectionFactoryImpl {
bool delay_login_;
// Callback to invoke when all connection attempts have been made.
base::Closure finished_callback_;
+ // A temporary scoped pointer to make sure we don't leak the handler in the
+ // cases it's never consumed by the ConnectionFactory.
+ scoped_ptr<FakeConnectionHandler> scoped_handler_;
// The current fake connection handler..
FakeConnectionHandler* fake_handler_;
+ // Dummy GCM Stats recorder.
FakeGCMStatsRecorder dummy_recorder_;
};
@@ -166,7 +170,10 @@ TestConnectionFactoryImpl::TestConnectionFactoryImpl(
connections_fulfilled_(true),
delay_login_(false),
finished_callback_(finished_callback),
- fake_handler_(NULL) {
+ scoped_handler_(
+ new FakeConnectionHandler(base::Bind(&ReadContinuation),
+ base::Bind(&WriteContinuation))),
+ fake_handler_(scoped_handler_.get()) {
// Set a non-null time.
tick_clock_.Advance(base::TimeDelta::FromMilliseconds(1));
}
@@ -211,10 +218,7 @@ TestConnectionFactoryImpl::CreateConnectionHandler(
const ConnectionHandler::ProtoReceivedCallback& read_callback,
const ConnectionHandler::ProtoSentCallback& write_callback,
const ConnectionHandler::ConnectionChangedCallback& connection_callback) {
- fake_handler_ = new FakeConnectionHandler(
- base::Bind(&ReadContinuation),
- base::Bind(&WriteContinuation));
- return make_scoped_ptr<ConnectionHandler>(fake_handler_);
+ return scoped_handler_.Pass();
}
base::TimeTicks TestConnectionFactoryImpl::NowTicks() {
@@ -315,8 +319,7 @@ void ConnectionFactoryImplTest::OnDisconnected() {
// Verify building a connection handler works.
TEST_F(ConnectionFactoryImplTest, Initialize) {
- ConnectionHandler* handler = factory()->GetConnectionHandler();
- ASSERT_TRUE(handler);
+ ASSERT_FALSE(factory()->GetConnectionHandler());
EXPECT_FALSE(factory()->IsEndpointReachable());
EXPECT_FALSE(connected_server().is_valid());
}
@@ -325,6 +328,7 @@ TEST_F(ConnectionFactoryImplTest, Initialize) {
TEST_F(ConnectionFactoryImplTest, ConnectSuccess) {
factory()->SetConnectResult(net::OK);
factory()->Connect();
+ ASSERT_TRUE(factory()->GetConnectionHandler());
EXPECT_TRUE(factory()->NextRetryAttempt().is_null());
EXPECT_EQ(factory()->GetCurrentEndpoint(), BuildEndpoints()[0]);
EXPECT_TRUE(factory()->IsEndpointReachable());
@@ -547,4 +551,14 @@ TEST_F(ConnectionFactoryImplTest, DISABLED_SuppressConnectWhenNoNetwork) {
EXPECT_TRUE(factory()->NextRetryAttempt().is_null());
}
+// Receiving a network change event before the initial connection should have
+// no effect.
+TEST_F(ConnectionFactoryImplTest, NetworkChangeBeforeFirstConnection) {
+ factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_4G);
+ factory()->SetConnectResult(net::OK);
+ factory()->Connect();
+ EXPECT_TRUE(factory()->NextRetryAttempt().is_null());
+ EXPECT_TRUE(factory()->IsEndpointReachable());
+}
+
} // namespace gcm
« no previous file with comments | « google_apis/gcm/engine/connection_factory_impl.cc ('k') | google_apis/gcm/engine/mcs_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698