| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return delay; | 73 return delay; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ReadContinuation( | 76 void ReadContinuation( |
| 77 scoped_ptr<google::protobuf::MessageLite> message) { | 77 scoped_ptr<google::protobuf::MessageLite> message) { |
| 78 } | 78 } |
| 79 | 79 |
| 80 void WriteContinuation() { | 80 void WriteContinuation() { |
| 81 } | 81 } |
| 82 | 82 |
| 83 class TestBackoffEntry : public net::BackoffEntry { | |
| 84 public: | |
| 85 explicit TestBackoffEntry(base::SimpleTestTickClock* tick_clock); | |
| 86 ~TestBackoffEntry() override; | |
| 87 | |
| 88 base::TimeTicks ImplGetTimeNow() const override; | |
| 89 | |
| 90 private: | |
| 91 base::SimpleTestTickClock* tick_clock_; | |
| 92 }; | |
| 93 | |
| 94 TestBackoffEntry::TestBackoffEntry(base::SimpleTestTickClock* tick_clock) | |
| 95 : BackoffEntry(&kTestBackoffPolicy), | |
| 96 tick_clock_(tick_clock) { | |
| 97 } | |
| 98 | |
| 99 TestBackoffEntry::~TestBackoffEntry() {} | |
| 100 | |
| 101 base::TimeTicks TestBackoffEntry::ImplGetTimeNow() const { | |
| 102 return tick_clock_->NowTicks(); | |
| 103 } | |
| 104 | |
| 105 // A connection factory that stubs out network requests and overrides the | 83 // A connection factory that stubs out network requests and overrides the |
| 106 // backoff policy. | 84 // backoff policy. |
| 107 class TestConnectionFactoryImpl : public ConnectionFactoryImpl { | 85 class TestConnectionFactoryImpl : public ConnectionFactoryImpl { |
| 108 public: | 86 public: |
| 109 TestConnectionFactoryImpl(const base::Closure& finished_callback); | 87 TestConnectionFactoryImpl(const base::Closure& finished_callback); |
| 110 ~TestConnectionFactoryImpl() override; | 88 ~TestConnectionFactoryImpl() override; |
| 111 | 89 |
| 112 void InitializeFactory(); | 90 void InitializeFactory(); |
| 113 | 91 |
| 114 // Overridden stubs. | 92 // Overridden stubs. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 184 } |
| 207 | 185 |
| 208 void TestConnectionFactoryImpl::InitHandler() { | 186 void TestConnectionFactoryImpl::InitHandler() { |
| 209 EXPECT_NE(connect_result_, net::ERR_UNEXPECTED); | 187 EXPECT_NE(connect_result_, net::ERR_UNEXPECTED); |
| 210 if (!delay_login_) | 188 if (!delay_login_) |
| 211 ConnectionHandlerCallback(net::OK); | 189 ConnectionHandlerCallback(net::OK); |
| 212 } | 190 } |
| 213 | 191 |
| 214 scoped_ptr<net::BackoffEntry> TestConnectionFactoryImpl::CreateBackoffEntry( | 192 scoped_ptr<net::BackoffEntry> TestConnectionFactoryImpl::CreateBackoffEntry( |
| 215 const net::BackoffEntry::Policy* const policy) { | 193 const net::BackoffEntry::Policy* const policy) { |
| 216 return scoped_ptr<net::BackoffEntry>(new TestBackoffEntry(&tick_clock_)); | 194 return make_scoped_ptr(new net::BackoffEntry(&kTestBackoffPolicy, |
| 195 &tick_clock_)); |
| 217 } | 196 } |
| 218 | 197 |
| 219 scoped_ptr<ConnectionHandler> | 198 scoped_ptr<ConnectionHandler> |
| 220 TestConnectionFactoryImpl::CreateConnectionHandler( | 199 TestConnectionFactoryImpl::CreateConnectionHandler( |
| 221 base::TimeDelta read_timeout, | 200 base::TimeDelta read_timeout, |
| 222 const ConnectionHandler::ProtoReceivedCallback& read_callback, | 201 const ConnectionHandler::ProtoReceivedCallback& read_callback, |
| 223 const ConnectionHandler::ProtoSentCallback& write_callback, | 202 const ConnectionHandler::ProtoSentCallback& write_callback, |
| 224 const ConnectionHandler::ConnectionChangedCallback& connection_callback) { | 203 const ConnectionHandler::ConnectionChangedCallback& connection_callback) { |
| 225 return scoped_handler_.Pass(); | 204 return scoped_handler_.Pass(); |
| 226 } | 205 } |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 // Now trigger force a re-connection. | 564 // Now trigger force a re-connection. |
| 586 factory()->SetConnectResult(net::OK); | 565 factory()->SetConnectResult(net::OK); |
| 587 factory()->Connect(); | 566 factory()->Connect(); |
| 588 WaitForConnections(); | 567 WaitForConnections(); |
| 589 | 568 |
| 590 // Re-connection should succeed. | 569 // Re-connection should succeed. |
| 591 EXPECT_TRUE(factory()->IsEndpointReachable()); | 570 EXPECT_TRUE(factory()->IsEndpointReachable()); |
| 592 } | 571 } |
| 593 | 572 |
| 594 } // namespace gcm | 573 } // namespace gcm |
| OLD | NEW |