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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { | 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 ~TestBackoffEntry() override; |
87 | 87 |
88 virtual base::TimeTicks ImplGetTimeNow() const override; | 88 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 ~TestConnectionFactoryImpl() override; |
111 | 111 |
112 void InitializeFactory(); | 112 void InitializeFactory(); |
113 | 113 |
114 // Overridden stubs. | 114 // Overridden stubs. |
115 virtual void ConnectImpl() override; | 115 void ConnectImpl() override; |
116 virtual void InitHandler() override; | 116 void InitHandler() override; |
117 virtual scoped_ptr<net::BackoffEntry> CreateBackoffEntry( | 117 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 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 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 public: | 259 public: |
260 ConnectionFactoryImplTest(); | 260 ConnectionFactoryImplTest(); |
261 virtual ~ConnectionFactoryImplTest(); | 261 virtual ~ConnectionFactoryImplTest(); |
262 | 262 |
263 TestConnectionFactoryImpl* factory() { return &factory_; } | 263 TestConnectionFactoryImpl* factory() { return &factory_; } |
264 GURL& connected_server() { return connected_server_; } | 264 GURL& connected_server() { return connected_server_; } |
265 | 265 |
266 void WaitForConnections(); | 266 void WaitForConnections(); |
267 | 267 |
268 // ConnectionFactory::ConnectionListener | 268 // ConnectionFactory::ConnectionListener |
269 virtual void OnConnected(const GURL& current_server, | 269 void OnConnected(const GURL& current_server, |
270 const net::IPEndPoint& ip_endpoint) override; | 270 const net::IPEndPoint& ip_endpoint) override; |
271 virtual void OnDisconnected() override; | 271 void OnDisconnected() override; |
272 | 272 |
273 private: | 273 private: |
274 void ConnectionsComplete(); | 274 void ConnectionsComplete(); |
275 | 275 |
276 TestConnectionFactoryImpl factory_; | 276 TestConnectionFactoryImpl factory_; |
277 base::MessageLoop message_loop_; | 277 base::MessageLoop message_loop_; |
278 scoped_ptr<base::RunLoop> run_loop_; | 278 scoped_ptr<base::RunLoop> run_loop_; |
279 | 279 |
280 GURL connected_server_; | 280 GURL connected_server_; |
281 }; | 281 }; |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // When the network returns, attempt to connect. | 541 // When the network returns, attempt to connect. |
542 factory()->SetConnectResult(net::OK); | 542 factory()->SetConnectResult(net::OK); |
543 factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_4G); | 543 factory()->OnNetworkChanged(net::NetworkChangeNotifier::CONNECTION_4G); |
544 WaitForConnections(); | 544 WaitForConnections(); |
545 | 545 |
546 EXPECT_TRUE(factory()->IsEndpointReachable()); | 546 EXPECT_TRUE(factory()->IsEndpointReachable()); |
547 EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); | 547 EXPECT_TRUE(factory()->NextRetryAttempt().is_null()); |
548 } | 548 } |
549 | 549 |
550 } // namespace gcm | 550 } // namespace gcm |
OLD | NEW |