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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 78 } |
79 | 79 |
80 void WriteContinuation() { | 80 void WriteContinuation() { |
81 } | 81 } |
82 | 82 |
83 class TestBackoffEntry : public net::BackoffEntry { | 83 class TestBackoffEntry : public net::BackoffEntry { |
84 public: | 84 public: |
85 explicit TestBackoffEntry(base::SimpleTestTickClock* tick_clock); | 85 explicit TestBackoffEntry(base::SimpleTestTickClock* tick_clock); |
86 virtual ~TestBackoffEntry(); | 86 virtual ~TestBackoffEntry(); |
87 | 87 |
88 virtual base::TimeTicks ImplGetTimeNow() const OVERRIDE; | 88 virtual base::TimeTicks ImplGetTimeNow() const override; |
89 | 89 |
90 private: | 90 private: |
91 base::SimpleTestTickClock* tick_clock_; | 91 base::SimpleTestTickClock* tick_clock_; |
92 }; | 92 }; |
93 | 93 |
94 TestBackoffEntry::TestBackoffEntry(base::SimpleTestTickClock* tick_clock) | 94 TestBackoffEntry::TestBackoffEntry(base::SimpleTestTickClock* tick_clock) |
95 : BackoffEntry(&kTestBackoffPolicy), | 95 : BackoffEntry(&kTestBackoffPolicy), |
96 tick_clock_(tick_clock) { | 96 tick_clock_(tick_clock) { |
97 } | 97 } |
98 | 98 |
99 TestBackoffEntry::~TestBackoffEntry() {} | 99 TestBackoffEntry::~TestBackoffEntry() {} |
100 | 100 |
101 base::TimeTicks TestBackoffEntry::ImplGetTimeNow() const { | 101 base::TimeTicks TestBackoffEntry::ImplGetTimeNow() const { |
102 return tick_clock_->NowTicks(); | 102 return tick_clock_->NowTicks(); |
103 } | 103 } |
104 | 104 |
105 // A connection factory that stubs out network requests and overrides the | 105 // A connection factory that stubs out network requests and overrides the |
106 // backoff policy. | 106 // backoff policy. |
107 class TestConnectionFactoryImpl : public ConnectionFactoryImpl { | 107 class TestConnectionFactoryImpl : public ConnectionFactoryImpl { |
108 public: | 108 public: |
109 TestConnectionFactoryImpl(const base::Closure& finished_callback); | 109 TestConnectionFactoryImpl(const base::Closure& finished_callback); |
110 virtual ~TestConnectionFactoryImpl(); | 110 virtual ~TestConnectionFactoryImpl(); |
111 | 111 |
112 void InitializeFactory(); | 112 void InitializeFactory(); |
113 | 113 |
114 // Overridden stubs. | 114 // Overridden stubs. |
115 virtual void ConnectImpl() OVERRIDE; | 115 virtual void ConnectImpl() override; |
116 virtual void InitHandler() OVERRIDE; | 116 virtual void InitHandler() override; |
117 virtual scoped_ptr<net::BackoffEntry> CreateBackoffEntry( | 117 virtual scoped_ptr<net::BackoffEntry> CreateBackoffEntry( |
118 const net::BackoffEntry::Policy* const policy) OVERRIDE; | 118 const net::BackoffEntry::Policy* const policy) override; |
119 virtual scoped_ptr<ConnectionHandler> CreateConnectionHandler( | 119 virtual scoped_ptr<ConnectionHandler> CreateConnectionHandler( |
120 base::TimeDelta read_timeout, | 120 base::TimeDelta read_timeout, |
121 const ConnectionHandler::ProtoReceivedCallback& read_callback, | 121 const ConnectionHandler::ProtoReceivedCallback& read_callback, |
122 const ConnectionHandler::ProtoSentCallback& write_callback, | 122 const ConnectionHandler::ProtoSentCallback& write_callback, |
123 const ConnectionHandler::ConnectionChangedCallback& connection_callback) | 123 const ConnectionHandler::ConnectionChangedCallback& connection_callback) |
124 OVERRIDE; | 124 override; |
125 virtual base::TimeTicks NowTicks() OVERRIDE; | 125 virtual base::TimeTicks NowTicks() override; |
126 | 126 |
127 // Helpers for verifying connection attempts are made. Connection results | 127 // Helpers for verifying connection attempts are made. Connection results |
128 // must be consumed. | 128 // must be consumed. |
129 void SetConnectResult(int connect_result); | 129 void SetConnectResult(int connect_result); |
130 void SetMultipleConnectResults(int connect_result, int num_expected_attempts); | 130 void SetMultipleConnectResults(int connect_result, int num_expected_attempts); |
131 | 131 |
132 // Force a login handshake to be delayed. | 132 // Force a login handshake to be delayed. |
133 void SetDelayLogin(bool delay_login); | 133 void SetDelayLogin(bool delay_login); |
134 | 134 |
135 base::SimpleTestTickClock* tick_clock() { return &tick_clock_; } | 135 base::SimpleTestTickClock* tick_clock() { return &tick_clock_; } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 ConnectionFactoryImplTest(); | 264 ConnectionFactoryImplTest(); |
265 virtual ~ConnectionFactoryImplTest(); | 265 virtual ~ConnectionFactoryImplTest(); |
266 | 266 |
267 TestConnectionFactoryImpl* factory() { return &factory_; } | 267 TestConnectionFactoryImpl* factory() { return &factory_; } |
268 GURL& connected_server() { return connected_server_; } | 268 GURL& connected_server() { return connected_server_; } |
269 | 269 |
270 void WaitForConnections(); | 270 void WaitForConnections(); |
271 | 271 |
272 // ConnectionFactory::ConnectionListener | 272 // ConnectionFactory::ConnectionListener |
273 virtual void OnConnected(const GURL& current_server, | 273 virtual void OnConnected(const GURL& current_server, |
274 const net::IPEndPoint& ip_endpoint) OVERRIDE; | 274 const net::IPEndPoint& ip_endpoint) override; |
275 virtual void OnDisconnected() OVERRIDE; | 275 virtual void OnDisconnected() override; |
276 | 276 |
277 private: | 277 private: |
278 void ConnectionsComplete(); | 278 void ConnectionsComplete(); |
279 | 279 |
280 TestConnectionFactoryImpl factory_; | 280 TestConnectionFactoryImpl factory_; |
281 base::MessageLoop message_loop_; | 281 base::MessageLoop message_loop_; |
282 scoped_ptr<base::RunLoop> run_loop_; | 282 scoped_ptr<base::RunLoop> run_loop_; |
283 | 283 |
284 GURL connected_server_; | 284 GURL connected_server_; |
285 }; | 285 }; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 // When the network returns, attempt to connect. | 545 // When the network returns, attempt to connect. |
546 factory()->SetConnectResult(net::OK); | 546 factory()->SetConnectResult(net::OK); |
547 factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_4G); | 547 factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_4G); |
548 WaitForConnections(); | 548 WaitForConnections(); |
549 | 549 |
550 EXPECT_TRUE(factory()->IsEndpointReachable()); | 550 EXPECT_TRUE(factory()->IsEndpointReachable()); |
551 EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); | 551 EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); |
552 } | 552 } |
553 | 553 |
554 } // namespace gcm | 554 } // namespace gcm |
OLD | NEW |