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

Side by Side Diff: chrome/browser/chromeos/net/network_portal_detector_unittest.cc

Issue 11419070: Added detection timeouts and usage of Retry-After HTTP header. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/net/network_portal_detector.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/captive_portal/captive_portal_detector.h" 11 #include "chrome/browser/captive_portal/captive_portal_detector.h"
12 #include "chrome/browser/captive_portal/testing_utils.h" 12 #include "chrome/browser/captive_portal/testing_utils.h"
13 #include "chrome/browser/chromeos/cros/cros_library.h" 13 #include "chrome/browser/chromeos/cros/cros_library.h"
14 #include "chrome/browser/chromeos/cros/network_library.h" 14 #include "chrome/browser/chromeos/cros/network_library.h"
15 #include "chrome/browser/chromeos/cros/network_library_impl_base.h" 15 #include "chrome/browser/chromeos/cros/network_library_impl_base.h"
16 #include "chrome/browser/chromeos/net/network_portal_detector.h" 16 #include "chrome/browser/chromeos/net/network_portal_detector.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/url_request/test_url_fetcher_factory.h"
20 19
21 namespace chromeos { 20 namespace chromeos {
22 21
23 class NetworkPortalDetectorTest 22 class NetworkPortalDetectorTest
24 : public testing::Test, 23 : public testing::Test,
25 public captive_portal::CaptivePortalDetectorTestBase { 24 public captive_portal::CaptivePortalDetectorTestBase {
26 public: 25 public:
27 NetworkPortalDetectorTest() {} 26 NetworkPortalDetectorTest() {}
28 virtual ~NetworkPortalDetectorTest() {} 27 virtual ~NetworkPortalDetectorTest() {}
29 28
30 virtual void SetUp() { 29 virtual void SetUp() {
31 CrosLibrary::Initialize(true); 30 CrosLibrary::Initialize(true);
32 network_library_ = CrosLibrary::Get()->GetNetworkLibrary(); 31 network_library_ = CrosLibrary::Get()->GetNetworkLibrary();
33 DCHECK(network_library_); 32 DCHECK(network_library_);
34 33
35 ethernet_network_ = network_library_->FindNetworkByPath("eth1"); 34 ethernet_network_ = network_library_->FindNetworkByPath("eth1");
36 DCHECK(ethernet_network_); 35 DCHECK(ethernet_network_);
37 36
38 wifi_network_ = network_library_->FindNetworkByPath("wifi1"); 37 wifi1_network_ = network_library_->FindNetworkByPath("wifi1");
39 DCHECK(wifi_network_); 38 DCHECK(wifi1_network_);
39
40 wifi2_network_ = network_library_->FindNetworkByPath("wifi2");
41 DCHECK(wifi2_network_);
40 42
41 profile_.reset(new TestingProfile()); 43 profile_.reset(new TestingProfile());
42 network_portal_detector_.reset( 44 network_portal_detector_.reset(
43 new NetworkPortalDetector(profile_->GetRequestContext())); 45 new NetworkPortalDetector(profile_->GetRequestContext()));
44 network_portal_detector_->Init(); 46 network_portal_detector_->Init();
45 47
46 set_detector(network_portal_detector_->captive_portal_detector_.get()); 48 set_detector(network_portal_detector_->captive_portal_detector_.get());
49
50 // Prevents flakiness due to message loop delays.
51 set_time_ticks(base::TimeTicks::Now());
47 } 52 }
48 53
49 virtual void TearDown() { 54 virtual void TearDown() {
50 network_portal_detector_->Shutdown(); 55 network_portal_detector_->Shutdown();
51 CrosLibrary::Shutdown(); 56 CrosLibrary::Shutdown();
52 } 57 }
53 58
54 NetworkLibrary* network_library() { return network_library_; } 59 NetworkLibrary* network_library() { return network_library_; }
55 Network* ethernet_network() { return ethernet_network_; } 60 Network* ethernet_network() { return ethernet_network_; }
56 Network* wifi_network() { return wifi_network_; } 61 Network* wifi1_network() { return wifi1_network_; }
62 Network* wifi2_network() { return wifi2_network_; }
57 63
58 Profile* profile() { return profile_.get(); } 64 Profile* profile() { return profile_.get(); }
59 65
60 NetworkPortalDetector* network_portal_detector() { 66 NetworkPortalDetector* network_portal_detector() {
61 return network_portal_detector_.get(); 67 return network_portal_detector_.get();
62 } 68 }
63 69
64 net::TestURLFetcher* fetcher() { return factory_.GetFetcherByID(0); }
65
66 NetworkPortalDetector::State state() { 70 NetworkPortalDetector::State state() {
67 return network_portal_detector()->state(); 71 return network_portal_detector()->state();
68 } 72 }
69 73
70 bool is_state_idle() { 74 bool is_state_idle() {
71 return (NetworkPortalDetector::STATE_IDLE == state()); 75 return (NetworkPortalDetector::STATE_IDLE == state());
72 } 76 }
73 77
78 bool is_state_portal_detection_pending() {
79 return (NetworkPortalDetector::STATE_PORTAL_CHECK_PENDING == state());
80 }
81
74 bool is_state_checking_for_portal() { 82 bool is_state_checking_for_portal() {
75 return (NetworkPortalDetector::STATE_CHECKING_FOR_PORTAL == state()); 83 return (NetworkPortalDetector::STATE_CHECKING_FOR_PORTAL == state());
76 } 84 }
77 85
78 bool is_state_checking_for_portal_network_changed() { 86 void set_request_timeout(const base::TimeDelta& timeout) {
79 return (NetworkPortalDetector::STATE_CHECKING_FOR_PORTAL_NETWORK_CHANGED == 87 network_portal_detector()->set_request_timeout_for_testing(timeout);
80 state()); 88 }
89
90 const base::TimeDelta& next_attempt_delay() {
91 return network_portal_detector()->next_attempt_delay_for_testing();
92 }
93
94 int attempt_count() {
95 return network_portal_detector()->attempt_count_for_testing();
96 }
97
98 void set_min_time_between_attempts(const base::TimeDelta& delta) {
99 network_portal_detector()->set_min_time_between_attempts_for_testing(delta);
100 }
101
102 void set_time_ticks(const base::TimeTicks& time_ticks) {
103 network_portal_detector()->set_time_ticks_for_testing(time_ticks);
81 } 104 }
82 105
83 void SetConnected(Network* network) { 106 void SetConnected(Network* network) {
84 Network::TestApi test_api(network); 107 Network::TestApi test_api(network);
85 test_api.SetConnected(); 108 test_api.SetConnected();
86 static_cast<NetworkLibraryImplBase*>( 109 static_cast<NetworkLibraryImplBase*>(
87 network_library())->CallConnectToNetwork(network); 110 network_library())->CallConnectToNetwork(network);
88 MessageLoop::current()->RunUntilIdle(); 111 MessageLoop::current()->RunUntilIdle();
89 } 112 }
90 113
91 private: 114 private:
92 NetworkLibrary* network_library_; 115 NetworkLibrary* network_library_;
93 116
94 // Pointer to fake ethernet network. 117 // Pointer to a fake ethernet network.
95 Network* ethernet_network_; 118 Network* ethernet_network_;
96 119
97 // Pointer to fake wifi network. 120 // Pointer to a fake wifi1 network.
98 Network* wifi_network_; 121 Network* wifi1_network_;
122
123 // Pointer to a fake wifi2 network.
124 Network* wifi2_network_;
99 125
100 MessageLoop message_loop_; 126 MessageLoop message_loop_;
101 127
102 scoped_ptr<TestingProfile> profile_; 128 scoped_ptr<TestingProfile> profile_;
103 scoped_ptr<NetworkPortalDetector> network_portal_detector_; 129 scoped_ptr<NetworkPortalDetector> network_portal_detector_;
104
105 net::TestURLFetcherFactory factory_;
106 }; 130 };
107 131
108 TEST_F(NetworkPortalDetectorTest, NoPortal) { 132 TEST_F(NetworkPortalDetectorTest, NoPortal) {
109 ASSERT_TRUE(is_state_idle()); 133 ASSERT_TRUE(is_state_idle());
110 134
111 SetConnected(wifi_network()); 135 SetConnected(wifi1_network());
112 ASSERT_TRUE(is_state_checking_for_portal()); 136 ASSERT_TRUE(is_state_checking_for_portal());
113 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_UNKNOWN, 137 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_UNKNOWN,
114 network_portal_detector()->GetCaptivePortalState(wifi_network())); 138 network_portal_detector()->GetCaptivePortalState(wifi1_network()));
115 139
116 fetcher()->set_response_code(204); 140 CompleteURLFetch(net::OK, 204, NULL);
117 OnURLFetchComplete(fetcher());
118 141
119 ASSERT_TRUE(is_state_idle()); 142 ASSERT_TRUE(is_state_idle());
120 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE, 143 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE,
121 network_portal_detector()->GetCaptivePortalState( 144 network_portal_detector()->GetCaptivePortalState(
122 wifi_network())); 145 wifi1_network()));
123 } 146 }
124 147
125 TEST_F(NetworkPortalDetectorTest, Portal) { 148 TEST_F(NetworkPortalDetectorTest, Portal) {
126 ASSERT_TRUE(is_state_idle()); 149 ASSERT_TRUE(is_state_idle());
127 150
128 // Check HTTP 200 response code. 151 // Check HTTP 200 response code.
129 SetConnected(wifi_network()); 152 SetConnected(wifi1_network());
130 ASSERT_TRUE(is_state_checking_for_portal()); 153 ASSERT_TRUE(is_state_checking_for_portal());
131 154
132 fetcher()->set_response_code(200); 155 CompleteURLFetch(net::OK, 200, NULL);
133 OnURLFetchComplete(fetcher());
134
135 ASSERT_TRUE(is_state_idle());
136 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL,
137 network_portal_detector()->GetCaptivePortalState(wifi_network()));
138
139 // Check HTTP 301 response code.
140 SetConnected(ethernet_network());
141 ASSERT_TRUE(is_state_checking_for_portal());
142
143 fetcher()->set_response_code(301);
144 OnURLFetchComplete(fetcher());
145 156
146 ASSERT_TRUE(is_state_idle()); 157 ASSERT_TRUE(is_state_idle());
147 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL, 158 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL,
148 network_portal_detector()->GetCaptivePortalState( 159 network_portal_detector()->GetCaptivePortalState(
149 ethernet_network())); 160 wifi1_network()));
150 161
151 // Check HTTP 302 response code. 162 // Check HTTP 301 response code.
152 SetConnected(wifi_network()); 163 SetConnected(wifi2_network());
153 ASSERT_TRUE(is_state_checking_for_portal()); 164 ASSERT_TRUE(is_state_checking_for_portal());
154 165
155 fetcher()->set_response_code(302); 166 CompleteURLFetch(net::OK, 301, NULL);
156 OnURLFetchComplete(fetcher());
157 167
158 ASSERT_TRUE(is_state_idle()); 168 ASSERT_TRUE(is_state_idle());
159 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL, 169 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL,
170 network_portal_detector()->GetCaptivePortalState(
171 wifi2_network()));
172
173 // Check HTTP 302 response code.
174 SetConnected(ethernet_network());
175 ASSERT_TRUE(is_state_checking_for_portal());
176
177 CompleteURLFetch(net::OK, 302, NULL);
178
179 ASSERT_TRUE(is_state_idle());
180 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL,
160 network_portal_detector()->GetCaptivePortalState( 181 network_portal_detector()->GetCaptivePortalState(
161 ethernet_network())); 182 ethernet_network()));
162 } 183 }
163 184
164 TEST_F(NetworkPortalDetectorTest, TwoNetworks) { 185 TEST_F(NetworkPortalDetectorTest, TwoNetworks) {
165 ASSERT_TRUE(is_state_idle()); 186 ASSERT_TRUE(is_state_idle());
166 187
167 SetConnected(wifi_network()); 188 SetConnected(wifi1_network());
168 ASSERT_TRUE(is_state_checking_for_portal()); 189 ASSERT_TRUE(is_state_checking_for_portal());
169 190
170 // wifi is in portal state. 191 // wifi is in portal state.
171 fetcher()->set_response_code(200); 192 CompleteURLFetch(net::OK, 200, NULL);
172 OnURLFetchComplete(fetcher());
173 ASSERT_TRUE(is_state_idle()); 193 ASSERT_TRUE(is_state_idle());
174 194
175 SetConnected(ethernet_network()); 195 SetConnected(ethernet_network());
176 ASSERT_TRUE(is_state_checking_for_portal()); 196 ASSERT_TRUE(is_state_checking_for_portal());
177 197
178 // ethernet is in online state. 198 // ethernet is in online state.
179 fetcher()->set_response_code(204); 199 CompleteURLFetch(net::OK, 204, NULL);
180 OnURLFetchComplete(fetcher());
181 ASSERT_TRUE(is_state_idle()); 200 ASSERT_TRUE(is_state_idle());
182 201
183 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE, 202 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE,
184 network_portal_detector()->GetCaptivePortalState( 203 network_portal_detector()->GetCaptivePortalState(
185 ethernet_network())); 204 ethernet_network()));
186 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL, 205 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_PORTAL,
187 network_portal_detector()->GetCaptivePortalState(wifi_network())); 206 network_portal_detector()->GetCaptivePortalState(wifi1_network()));
188 } 207 }
189 208
190 TEST_F(NetworkPortalDetectorTest, NetworkChanged) { 209 TEST_F(NetworkPortalDetectorTest, NetworkChanged) {
191 ASSERT_TRUE(is_state_idle()); 210 ASSERT_TRUE(is_state_idle());
192 211
193 SetConnected(wifi_network()); 212 SetConnected(wifi1_network());
213
214 // WiFi is in portal state.
215 fetcher()->set_response_code(200);
194 ASSERT_TRUE(is_state_checking_for_portal()); 216 ASSERT_TRUE(is_state_checking_for_portal());
195 217
196 // Active network is changed during portal detection for wifi. 218 // Active network is changed during portal detection for wifi.
197 SetConnected(ethernet_network()); 219 SetConnected(ethernet_network());
198 ASSERT_TRUE(is_state_checking_for_portal_network_changed());
199 220
200 // WiFi is in portal state and URL fetch is completed, but 221 // Portal detection for wifi is cancelled, portal detection for
201 // NetworkPortalDetector should ignore results and retry portal 222 // ethernet is initiated.
202 // detection.
203 fetcher()->set_response_code(200);
204 OnURLFetchComplete(fetcher());
205 ASSERT_TRUE(is_state_checking_for_portal()); 223 ASSERT_TRUE(is_state_checking_for_portal());
206 224
207 // ethernet is in online state. 225 // ethernet is in online state.
208 fetcher()->set_response_code(204); 226 CompleteURLFetch(net::OK, 204, NULL);
209 OnURLFetchComplete(fetcher());
210 ASSERT_TRUE(is_state_idle()); 227 ASSERT_TRUE(is_state_idle());
211 228
212 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE, 229 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE,
213 network_portal_detector()->GetCaptivePortalState( 230 network_portal_detector()->GetCaptivePortalState(
214 ethernet_network())); 231 ethernet_network()));
215 232
216 // As active network was changed during portal detection, we can't 233 // As active network was changed during portal detection for wifi
217 // rely on URL fetcher response. So, state for wifi network must be 234 // network, it's state must be unknown.
218 // unknown.
219 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_UNKNOWN, 235 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_UNKNOWN,
220 network_portal_detector()->GetCaptivePortalState(wifi_network())); 236 network_portal_detector()->GetCaptivePortalState(wifi1_network()));
221 } 237 }
222 238
223 TEST_F(NetworkPortalDetectorTest, NetworkStateNotChanged) { 239 TEST_F(NetworkPortalDetectorTest, NetworkStateNotChanged) {
224 ASSERT_TRUE(is_state_idle()); 240 ASSERT_TRUE(is_state_idle());
225 241
226 SetConnected(wifi_network()); 242 SetConnected(wifi1_network());
227 ASSERT_TRUE(is_state_checking_for_portal()); 243 ASSERT_TRUE(is_state_checking_for_portal());
228 244
229 fetcher()->set_response_code(204); 245 CompleteURLFetch(net::OK, 204, NULL);
230 OnURLFetchComplete(fetcher());
231 246
232 ASSERT_TRUE(is_state_idle()); 247 ASSERT_TRUE(is_state_idle());
233 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE, 248 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE,
234 network_portal_detector()->GetCaptivePortalState(wifi_network())); 249 network_portal_detector()->GetCaptivePortalState(wifi1_network()));
235 SetConnected(wifi_network()); 250 SetConnected(wifi1_network());
236 ASSERT_TRUE(is_state_idle()); 251 ASSERT_TRUE(is_state_idle());
237 } 252 }
238 253
239 TEST_F(NetworkPortalDetectorTest, NetworkStateChanged) { 254 TEST_F(NetworkPortalDetectorTest, NetworkStateChanged) {
240 // TODO (ygorshenin): currently portal detection isn't invoked if 255 // TODO (ygorshenin): currently portal detection isn't invoked if
241 // previous detection results are PORTAL or ONLINE. We're planning 256 // previous detection results are PORTAL or ONLINE. We're planning
242 // to change this behaviour in future, so, there should be 257 // to change this behaviour in future, so, there should be
243 // corresponding test. 258 // corresponding test.
244 } 259 }
245 260
261 TEST_F(NetworkPortalDetectorTest, PortalDetectionTimeout) {
262 ASSERT_TRUE(is_state_idle());
263
264 // For instantaneous timeout.
265 set_request_timeout(base::TimeDelta::FromSeconds(0));
266
267 ASSERT_TRUE(is_state_idle());
268 ASSERT_EQ(0, attempt_count());
269
270 SetConnected(wifi1_network());
271 MessageLoop::current()->RunUntilIdle();
272
273 // First portal detection timeouts, next portal detection is
274 // scheduled.
275 ASSERT_TRUE(is_state_portal_detection_pending());
276 ASSERT_EQ(1, attempt_count());
277 ASSERT_EQ(base::TimeDelta::FromSeconds(3), next_attempt_delay());
278 }
279
280 TEST_F(NetworkPortalDetectorTest, PortalDetectionRetryAfter) {
281 ASSERT_TRUE(is_state_idle());
282
283 const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: 101\n\n";
284
285 ASSERT_TRUE(is_state_idle());
286 ASSERT_EQ(0, attempt_count());
287
288 SetConnected(wifi1_network());
289 CompleteURLFetch(net::OK, 503, retry_after);
290
291 // First portal detection completed, next portal detection is
292 // scheduled after 101 seconds.
293 ASSERT_TRUE(is_state_portal_detection_pending());
294 ASSERT_EQ(1, attempt_count());
295 ASSERT_EQ(base::TimeDelta::FromSeconds(101), next_attempt_delay());
296 }
297
298 TEST_F(NetworkPortalDetectorTest, PortalDetectorRetryAfterIsSmall) {
299 ASSERT_TRUE(is_state_idle());
300
301 const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: 1\n\n";
302
303 ASSERT_TRUE(is_state_idle());
304 ASSERT_EQ(0, attempt_count());
305
306 SetConnected(wifi1_network());
307 CompleteURLFetch(net::OK, 503, retry_after);
308
309 // First portal detection completed, next portal detection is
310 // scheduled after 3 seconds (due to minimum time between detection
311 // attemps).
312 ASSERT_TRUE(is_state_portal_detection_pending());
313 ASSERT_EQ(1, attempt_count());
314 ASSERT_EQ(base::TimeDelta::FromSeconds(3), next_attempt_delay());
315 }
316
317 TEST_F(NetworkPortalDetectorTest, FirstAttemptFailed) {
318 ASSERT_TRUE(is_state_idle());
319
320 set_min_time_between_attempts(base::TimeDelta());
321 const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: 0\n\n";
322
323 ASSERT_TRUE(is_state_idle());
324 ASSERT_EQ(0, attempt_count());
325
326 SetConnected(wifi1_network());
327
328 CompleteURLFetch(net::OK, 503, retry_after);
329 ASSERT_TRUE(is_state_portal_detection_pending());
330 ASSERT_EQ(1, attempt_count());
331 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
332
333 // To run CaptivePortalDetector::DetectCaptivePortal().
334 MessageLoop::current()->RunUntilIdle();
335
336 CompleteURLFetch(net::OK, 204, NULL);
337 ASSERT_TRUE(is_state_idle());
338 ASSERT_EQ(2, attempt_count());
339 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_ONLINE,
340 network_portal_detector()->GetCaptivePortalState(wifi1_network()));
341 }
342
343 TEST_F(NetworkPortalDetectorTest, AllAttemptsFailed) {
344 ASSERT_TRUE(is_state_idle());
345
346 set_min_time_between_attempts(base::TimeDelta());
347 const char* retry_after = "HTTP/1.1 503 OK\nRetry-After: 0\n\n";
348
349 ASSERT_TRUE(is_state_idle());
350 ASSERT_EQ(0, attempt_count());
351
352 SetConnected(wifi1_network());
353
354 CompleteURLFetch(net::OK, 503, retry_after);
355 ASSERT_TRUE(is_state_portal_detection_pending());
356 ASSERT_EQ(1, attempt_count());
357 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
358
359 // To run CaptivePortalDetector::DetectCaptivePortal().
360 MessageLoop::current()->RunUntilIdle();
361
362 CompleteURLFetch(net::OK, 503, retry_after);
363 ASSERT_TRUE(is_state_portal_detection_pending());
364 ASSERT_EQ(2, attempt_count());
365 ASSERT_EQ(base::TimeDelta::FromSeconds(0), next_attempt_delay());
366
367 // To run CaptivePortalDetector::DetectCaptivePortal().
368 MessageLoop::current()->RunUntilIdle();
369
370 CompleteURLFetch(net::OK, 503, retry_after);
371 ASSERT_TRUE(is_state_idle());
372 ASSERT_EQ(3, attempt_count());
373 ASSERT_EQ(NetworkPortalDetector::CAPTIVE_PORTAL_STATE_OFFLINE,
374 network_portal_detector()->GetCaptivePortalState(wifi1_network()));
375 }
376
246 } // namespace chromeos 377 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/net/network_portal_detector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698