OLD | NEW |
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 "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "chrome/browser/captive_portal/captive_portal_service.h" | 9 #include "chrome/browser/captive_portal/captive_portal_service.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Simulates a slow SSL load when the Internet is connected. | 128 // Simulates a slow SSL load when the Internet is connected. |
129 TEST_F(CaptivePortalTabReloaderTest, InternetConnected) { | 129 TEST_F(CaptivePortalTabReloaderTest, InternetConnected) { |
130 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 130 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
131 | 131 |
132 tab_reloader().OnLoadStart(true); | 132 tab_reloader().OnLoadStart(true); |
133 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 133 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
134 tab_reloader().state()); | 134 tab_reloader().state()); |
135 EXPECT_TRUE(tab_reloader().TimerRunning()); | 135 EXPECT_TRUE(tab_reloader().TimerRunning()); |
136 | 136 |
137 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 137 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
138 MessageLoop::current()->RunUntilIdle(); | 138 base::MessageLoop::current()->RunUntilIdle(); |
139 EXPECT_FALSE(tab_reloader().TimerRunning()); | 139 EXPECT_FALSE(tab_reloader().TimerRunning()); |
140 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 140 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
141 tab_reloader().state()); | 141 tab_reloader().state()); |
142 | 142 |
143 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 143 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, |
144 RESULT_INTERNET_CONNECTED); | 144 RESULT_INTERNET_CONNECTED); |
145 | 145 |
146 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 146 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
147 EXPECT_FALSE(tab_reloader().TimerRunning()); | 147 EXPECT_FALSE(tab_reloader().TimerRunning()); |
148 | 148 |
(...skipping 27 matching lines...) Expand all Loading... |
176 // Simulates a slow SSL load when captive portal checks return no response. | 176 // Simulates a slow SSL load when captive portal checks return no response. |
177 TEST_F(CaptivePortalTabReloaderTest, NoResponse) { | 177 TEST_F(CaptivePortalTabReloaderTest, NoResponse) { |
178 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 178 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
179 | 179 |
180 tab_reloader().OnLoadStart(true); | 180 tab_reloader().OnLoadStart(true); |
181 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 181 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
182 tab_reloader().state()); | 182 tab_reloader().state()); |
183 EXPECT_TRUE(tab_reloader().TimerRunning()); | 183 EXPECT_TRUE(tab_reloader().TimerRunning()); |
184 | 184 |
185 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 185 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
186 MessageLoop::current()->RunUntilIdle(); | 186 base::MessageLoop::current()->RunUntilIdle(); |
187 EXPECT_FALSE(tab_reloader().TimerRunning()); | 187 EXPECT_FALSE(tab_reloader().TimerRunning()); |
188 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 188 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
189 tab_reloader().state()); | 189 tab_reloader().state()); |
190 | 190 |
191 tab_reloader().OnCaptivePortalResults(RESULT_NO_RESPONSE, RESULT_NO_RESPONSE); | 191 tab_reloader().OnCaptivePortalResults(RESULT_NO_RESPONSE, RESULT_NO_RESPONSE); |
192 | 192 |
193 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 193 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
194 EXPECT_FALSE(tab_reloader().TimerRunning()); | 194 EXPECT_FALSE(tab_reloader().TimerRunning()); |
195 | 195 |
196 tab_reloader().OnLoadCommitted(net::OK); | 196 tab_reloader().OnLoadCommitted(net::OK); |
(...skipping 20 matching lines...) Expand all Loading... |
217 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 217 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
218 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 218 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
219 } | 219 } |
220 | 220 |
221 // Simulate the normal login process. The user logs in before the error page | 221 // Simulate the normal login process. The user logs in before the error page |
222 // in the original tab commits. | 222 // in the original tab commits. |
223 TEST_F(CaptivePortalTabReloaderTest, Login) { | 223 TEST_F(CaptivePortalTabReloaderTest, Login) { |
224 tab_reloader().OnLoadStart(true); | 224 tab_reloader().OnLoadStart(true); |
225 | 225 |
226 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 226 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
227 MessageLoop::current()->RunUntilIdle(); | 227 base::MessageLoop::current()->RunUntilIdle(); |
228 EXPECT_FALSE(tab_reloader().TimerRunning()); | 228 EXPECT_FALSE(tab_reloader().TimerRunning()); |
229 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 229 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
230 tab_reloader().state()); | 230 tab_reloader().state()); |
231 | 231 |
232 // The captive portal service detects a captive portal. The TabReloader | 232 // The captive portal service detects a captive portal. The TabReloader |
233 // should try and create a new login tab in response. | 233 // should try and create a new login tab in response. |
234 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 234 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
235 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 235 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, |
236 RESULT_BEHIND_CAPTIVE_PORTAL); | 236 RESULT_BEHIND_CAPTIVE_PORTAL); |
237 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 237 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
238 tab_reloader().state()); | 238 tab_reloader().state()); |
239 EXPECT_FALSE(tab_reloader().TimerRunning()); | 239 EXPECT_FALSE(tab_reloader().TimerRunning()); |
240 | 240 |
241 // The user logs on from another tab, and a captive portal check is triggered. | 241 // The user logs on from another tab, and a captive portal check is triggered. |
242 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 242 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
243 RESULT_INTERNET_CONNECTED); | 243 RESULT_INTERNET_CONNECTED); |
244 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 244 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
245 tab_reloader().state()); | 245 tab_reloader().state()); |
246 | 246 |
247 // The error page commits, which should start an asynchronous reload. | 247 // The error page commits, which should start an asynchronous reload. |
248 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 248 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
249 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 249 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
250 tab_reloader().state()); | 250 tab_reloader().state()); |
251 | 251 |
252 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 252 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
253 MessageLoop::current()->RunUntilIdle(); | 253 base::MessageLoop::current()->RunUntilIdle(); |
254 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 254 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
255 } | 255 } |
256 | 256 |
257 // Simulate the normal login process. The user logs in after the tab finishes | 257 // Simulate the normal login process. The user logs in after the tab finishes |
258 // loading the error page. | 258 // loading the error page. |
259 TEST_F(CaptivePortalTabReloaderTest, LoginLate) { | 259 TEST_F(CaptivePortalTabReloaderTest, LoginLate) { |
260 tab_reloader().OnLoadStart(true); | 260 tab_reloader().OnLoadStart(true); |
261 | 261 |
262 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 262 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
263 MessageLoop::current()->RunUntilIdle(); | 263 base::MessageLoop::current()->RunUntilIdle(); |
264 EXPECT_FALSE(tab_reloader().TimerRunning()); | 264 EXPECT_FALSE(tab_reloader().TimerRunning()); |
265 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 265 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
266 tab_reloader().state()); | 266 tab_reloader().state()); |
267 | 267 |
268 // The captive portal service detects a captive portal. The TabReloader | 268 // The captive portal service detects a captive portal. The TabReloader |
269 // should try and create a new login tab in response. | 269 // should try and create a new login tab in response. |
270 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 270 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
271 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 271 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, |
272 RESULT_BEHIND_CAPTIVE_PORTAL); | 272 RESULT_BEHIND_CAPTIVE_PORTAL); |
273 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 273 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 // The user logs in from another tab before the tab errors out. | 370 // The user logs in from another tab before the tab errors out. |
371 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 371 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
372 RESULT_INTERNET_CONNECTED); | 372 RESULT_INTERNET_CONNECTED); |
373 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 373 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
374 tab_reloader().state()); | 374 tab_reloader().state()); |
375 | 375 |
376 // The error page commits, which should trigger a reload. | 376 // The error page commits, which should trigger a reload. |
377 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 377 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
378 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); | 378 tab_reloader().OnLoadCommitted(net::ERR_SSL_PROTOCOL_ERROR); |
379 MessageLoop::current()->RunUntilIdle(); | 379 base::MessageLoop::current()->RunUntilIdle(); |
380 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 380 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
381 } | 381 } |
382 | 382 |
383 // Simulate the case that a user has already logged in before the tab receives a | 383 // Simulate the case that a user has already logged in before the tab receives a |
384 // captive portal result, but a RESULT_BEHIND_CAPTIVE_PORTAL was received | 384 // captive portal result, but a RESULT_BEHIND_CAPTIVE_PORTAL was received |
385 // before the tab started loading. | 385 // before the tab started loading. |
386 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedIn) { | 386 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedIn) { |
387 tab_reloader().OnLoadStart(true); | 387 tab_reloader().OnLoadStart(true); |
388 | 388 |
389 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 389 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
390 MessageLoop::current()->RunUntilIdle(); | 390 base::MessageLoop::current()->RunUntilIdle(); |
391 EXPECT_FALSE(tab_reloader().TimerRunning()); | 391 EXPECT_FALSE(tab_reloader().TimerRunning()); |
392 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 392 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
393 tab_reloader().state()); | 393 tab_reloader().state()); |
394 | 394 |
395 // The user has already logged in. Since the last result found a captive | 395 // The user has already logged in. Since the last result found a captive |
396 // portal, the tab will be reloaded if a timeout is committed. | 396 // portal, the tab will be reloaded if a timeout is committed. |
397 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 397 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
398 RESULT_INTERNET_CONNECTED); | 398 RESULT_INTERNET_CONNECTED); |
399 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 399 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
400 tab_reloader().state()); | 400 tab_reloader().state()); |
401 | 401 |
402 // The error page commits, which should start an asynchronous reload. | 402 // The error page commits, which should start an asynchronous reload. |
403 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 403 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
404 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 404 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
405 tab_reloader().state()); | 405 tab_reloader().state()); |
406 | 406 |
407 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 407 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
408 MessageLoop::current()->RunUntilIdle(); | 408 base::MessageLoop::current()->RunUntilIdle(); |
409 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 409 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
410 } | 410 } |
411 | 411 |
412 // Same as above, except the result is received even before the timer triggers, | 412 // Same as above, except the result is received even before the timer triggers, |
413 // due to a captive portal test request from some external source, like a login | 413 // due to a captive portal test request from some external source, like a login |
414 // tab. | 414 // tab. |
415 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedInBeforeTimerTriggers) { | 415 TEST_F(CaptivePortalTabReloaderTest, AlreadyLoggedInBeforeTimerTriggers) { |
416 tab_reloader().OnLoadStart(true); | 416 tab_reloader().OnLoadStart(true); |
417 | 417 |
418 // The user has already logged in. Since the last result indicated there is | 418 // The user has already logged in. Since the last result indicated there is |
419 // a captive portal, the tab will be reloaded if it times out. | 419 // a captive portal, the tab will be reloaded if it times out. |
420 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 420 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
421 RESULT_INTERNET_CONNECTED); | 421 RESULT_INTERNET_CONNECTED); |
422 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 422 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
423 tab_reloader().state()); | 423 tab_reloader().state()); |
424 EXPECT_FALSE(tab_reloader().TimerRunning()); | 424 EXPECT_FALSE(tab_reloader().TimerRunning()); |
425 | 425 |
426 // The error page commits, which should start an asynchronous reload. | 426 // The error page commits, which should start an asynchronous reload. |
427 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 427 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
428 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 428 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
429 tab_reloader().state()); | 429 tab_reloader().state()); |
430 | 430 |
431 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 431 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
432 MessageLoop::current()->RunUntilIdle(); | 432 base::MessageLoop::current()->RunUntilIdle(); |
433 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 433 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
434 } | 434 } |
435 | 435 |
436 // Simulate the user logging in while the timer is still running. May happen | 436 // Simulate the user logging in while the timer is still running. May happen |
437 // if the tab is reloaded just before logging in on another tab. | 437 // if the tab is reloaded just before logging in on another tab. |
438 TEST_F(CaptivePortalTabReloaderTest, LoginWhileTimerRunning) { | 438 TEST_F(CaptivePortalTabReloaderTest, LoginWhileTimerRunning) { |
439 tab_reloader().OnLoadStart(true); | 439 tab_reloader().OnLoadStart(true); |
440 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 440 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
441 tab_reloader().state()); | 441 tab_reloader().state()); |
442 EXPECT_TRUE(tab_reloader().TimerRunning()); | 442 EXPECT_TRUE(tab_reloader().TimerRunning()); |
443 | 443 |
444 // The user has already logged in. | 444 // The user has already logged in. |
445 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 445 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
446 RESULT_INTERNET_CONNECTED); | 446 RESULT_INTERNET_CONNECTED); |
447 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 447 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
448 tab_reloader().state()); | 448 tab_reloader().state()); |
449 | 449 |
450 // The error page commits, which should start an asynchronous reload. | 450 // The error page commits, which should start an asynchronous reload. |
451 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 451 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
452 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 452 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
453 tab_reloader().state()); | 453 tab_reloader().state()); |
454 | 454 |
455 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 455 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
456 MessageLoop::current()->RunUntilIdle(); | 456 base::MessageLoop::current()->RunUntilIdle(); |
457 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 457 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
458 } | 458 } |
459 | 459 |
460 // Simulate a captive portal being detected while the time is still running. | 460 // Simulate a captive portal being detected while the time is still running. |
461 // The captive portal check triggered by the timer detects the captive portal | 461 // The captive portal check triggered by the timer detects the captive portal |
462 // again, and then the user logs in. | 462 // again, and then the user logs in. |
463 TEST_F(CaptivePortalTabReloaderTest, BehindPortalResultWhileTimerRunning) { | 463 TEST_F(CaptivePortalTabReloaderTest, BehindPortalResultWhileTimerRunning) { |
464 tab_reloader().OnLoadStart(true); | 464 tab_reloader().OnLoadStart(true); |
465 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 465 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
466 tab_reloader().state()); | 466 tab_reloader().state()); |
467 EXPECT_TRUE(tab_reloader().TimerRunning()); | 467 EXPECT_TRUE(tab_reloader().TimerRunning()); |
468 | 468 |
469 // The user is behind a captive portal, but since the tab hasn't timed out, | 469 // The user is behind a captive portal, but since the tab hasn't timed out, |
470 // the message is ignored. | 470 // the message is ignored. |
471 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 471 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, |
472 RESULT_BEHIND_CAPTIVE_PORTAL); | 472 RESULT_BEHIND_CAPTIVE_PORTAL); |
473 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 473 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
474 tab_reloader().state()); | 474 tab_reloader().state()); |
475 | 475 |
476 // The rest proceeds as normal. | 476 // The rest proceeds as normal. |
477 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 477 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
478 MessageLoop::current()->RunUntilIdle(); | 478 base::MessageLoop::current()->RunUntilIdle(); |
479 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 479 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
480 tab_reloader().state()); | 480 tab_reloader().state()); |
481 | 481 |
482 // The captive portal service detects a captive portal, and this time the | 482 // The captive portal service detects a captive portal, and this time the |
483 // tab tries to create a login tab. | 483 // tab tries to create a login tab. |
484 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 484 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
485 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 485 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
486 RESULT_BEHIND_CAPTIVE_PORTAL); | 486 RESULT_BEHIND_CAPTIVE_PORTAL); |
487 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 487 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
488 tab_reloader().state()); | 488 tab_reloader().state()); |
489 EXPECT_FALSE(tab_reloader().TimerRunning()); | 489 EXPECT_FALSE(tab_reloader().TimerRunning()); |
490 | 490 |
491 // The user logs on from another tab, and a captive portal check is triggered. | 491 // The user logs on from another tab, and a captive portal check is triggered. |
492 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 492 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
493 RESULT_INTERNET_CONNECTED); | 493 RESULT_INTERNET_CONNECTED); |
494 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 494 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
495 tab_reloader().state()); | 495 tab_reloader().state()); |
496 | 496 |
497 // The error page commits, which should start an asynchronous reload. | 497 // The error page commits, which should start an asynchronous reload. |
498 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 498 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
499 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 499 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
500 tab_reloader().state()); | 500 tab_reloader().state()); |
501 | 501 |
502 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 502 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
503 MessageLoop::current()->RunUntilIdle(); | 503 base::MessageLoop::current()->RunUntilIdle(); |
504 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 504 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
505 } | 505 } |
506 | 506 |
507 // The CaptivePortalService detects the user has logged in to a captive portal | 507 // The CaptivePortalService detects the user has logged in to a captive portal |
508 // while the timer is still running, but the original load succeeds, so no | 508 // while the timer is still running, but the original load succeeds, so no |
509 // reload is done. | 509 // reload is done. |
510 TEST_F(CaptivePortalTabReloaderTest, LogInWhileTimerRunningNoError) { | 510 TEST_F(CaptivePortalTabReloaderTest, LogInWhileTimerRunningNoError) { |
511 tab_reloader().OnLoadStart(true); | 511 tab_reloader().OnLoadStart(true); |
512 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 512 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
513 tab_reloader().state()); | 513 tab_reloader().state()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 // be reloaded, despite still having a provisional load. | 552 // be reloaded, despite still having a provisional load. |
553 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 553 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
554 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 554 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
555 RESULT_INTERNET_CONNECTED); | 555 RESULT_INTERNET_CONNECTED); |
556 } | 556 } |
557 | 557 |
558 // Simulate an HTTP redirect to HTTPS, when the Internet is connected. | 558 // Simulate an HTTP redirect to HTTPS, when the Internet is connected. |
559 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectInternetConnected) { | 559 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectInternetConnected) { |
560 tab_reloader().OnLoadStart(false); | 560 tab_reloader().OnLoadStart(false); |
561 // There should be no captive portal check pending. | 561 // There should be no captive portal check pending. |
562 MessageLoop::current()->RunUntilIdle(); | 562 base::MessageLoop::current()->RunUntilIdle(); |
563 | 563 |
564 // HTTP to HTTPS redirect. | 564 // HTTP to HTTPS redirect. |
565 tab_reloader().OnRedirect(true); | 565 tab_reloader().OnRedirect(true); |
566 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 566 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
567 tab_reloader().state()); | 567 tab_reloader().state()); |
568 EXPECT_TRUE(tab_reloader().TimerRunning()); | 568 EXPECT_TRUE(tab_reloader().TimerRunning()); |
569 | 569 |
570 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 570 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
571 MessageLoop::current()->RunUntilIdle(); | 571 base::MessageLoop::current()->RunUntilIdle(); |
572 EXPECT_FALSE(tab_reloader().TimerRunning()); | 572 EXPECT_FALSE(tab_reloader().TimerRunning()); |
573 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 573 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
574 tab_reloader().state()); | 574 tab_reloader().state()); |
575 | 575 |
576 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 576 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, |
577 RESULT_INTERNET_CONNECTED); | 577 RESULT_INTERNET_CONNECTED); |
578 | 578 |
579 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 579 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
580 EXPECT_FALSE(tab_reloader().TimerRunning()); | 580 EXPECT_FALSE(tab_reloader().TimerRunning()); |
581 | 581 |
582 tab_reloader().OnLoadCommitted(net::OK); | 582 tab_reloader().OnLoadCommitted(net::OK); |
583 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 583 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
584 } | 584 } |
585 | 585 |
586 // Simulate an HTTP redirect to HTTPS and subsequent Login, when the user logs | 586 // Simulate an HTTP redirect to HTTPS and subsequent Login, when the user logs |
587 // in before the original page commits. | 587 // in before the original page commits. |
588 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectLogin) { | 588 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpsRedirectLogin) { |
589 tab_reloader().OnLoadStart(false); | 589 tab_reloader().OnLoadStart(false); |
590 // There should be no captive portal check pending. | 590 // There should be no captive portal check pending. |
591 MessageLoop::current()->RunUntilIdle(); | 591 base::MessageLoop::current()->RunUntilIdle(); |
592 | 592 |
593 // HTTP to HTTPS redirect. | 593 // HTTP to HTTPS redirect. |
594 tab_reloader().OnRedirect(true); | 594 tab_reloader().OnRedirect(true); |
595 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 595 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
596 tab_reloader().state()); | 596 tab_reloader().state()); |
597 | 597 |
598 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); | 598 EXPECT_CALL(tab_reloader(), CheckForCaptivePortal()).Times(1); |
599 MessageLoop::current()->RunUntilIdle(); | 599 base::MessageLoop::current()->RunUntilIdle(); |
600 EXPECT_FALSE(tab_reloader().TimerRunning()); | 600 EXPECT_FALSE(tab_reloader().TimerRunning()); |
601 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, | 601 EXPECT_EQ(CaptivePortalTabReloader::STATE_MAYBE_BROKEN_BY_PORTAL, |
602 tab_reloader().state()); | 602 tab_reloader().state()); |
603 | 603 |
604 // The captive portal service detects a captive portal. The TabReloader | 604 // The captive portal service detects a captive portal. The TabReloader |
605 // should try and create a new login tab in response. | 605 // should try and create a new login tab in response. |
606 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); | 606 EXPECT_CALL(tab_reloader(), MaybeOpenCaptivePortalLoginTab()).Times(1); |
607 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, | 607 tab_reloader().OnCaptivePortalResults(RESULT_INTERNET_CONNECTED, |
608 RESULT_BEHIND_CAPTIVE_PORTAL); | 608 RESULT_BEHIND_CAPTIVE_PORTAL); |
609 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 609 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
610 tab_reloader().state()); | 610 tab_reloader().state()); |
611 EXPECT_FALSE(tab_reloader().TimerRunning()); | 611 EXPECT_FALSE(tab_reloader().TimerRunning()); |
612 | 612 |
613 // The user logs on from another tab, and a captive portal check is triggered. | 613 // The user logs on from another tab, and a captive portal check is triggered. |
614 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 614 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
615 RESULT_INTERNET_CONNECTED); | 615 RESULT_INTERNET_CONNECTED); |
616 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 616 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
617 tab_reloader().state()); | 617 tab_reloader().state()); |
618 | 618 |
619 // The error page commits, which should start an asynchronous reload. | 619 // The error page commits, which should start an asynchronous reload. |
620 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); | 620 tab_reloader().OnLoadCommitted(net::ERR_CONNECTION_TIMED_OUT); |
621 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 621 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
622 tab_reloader().state()); | 622 tab_reloader().state()); |
623 | 623 |
624 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); | 624 EXPECT_CALL(tab_reloader(), ReloadTab()).Times(1); |
625 MessageLoop::current()->RunUntilIdle(); | 625 base::MessageLoop::current()->RunUntilIdle(); |
626 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 626 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
627 } | 627 } |
628 | 628 |
629 // Simulate the case where an HTTPs page redirects to an HTTPS page, before | 629 // Simulate the case where an HTTPs page redirects to an HTTPS page, before |
630 // the timer triggers. | 630 // the timer triggers. |
631 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpRedirect) { | 631 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpRedirect) { |
632 tab_reloader().OnLoadStart(true); | 632 tab_reloader().OnLoadStart(true); |
633 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 633 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
634 tab_reloader().state()); | 634 tab_reloader().state()); |
635 | 635 |
636 tab_reloader().OnRedirect(false); | 636 tab_reloader().OnRedirect(false); |
637 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 637 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
638 EXPECT_FALSE(tab_reloader().TimerRunning()); | 638 EXPECT_FALSE(tab_reloader().TimerRunning()); |
639 | 639 |
640 // There should be no captive portal check pending after the redirect. | 640 // There should be no captive portal check pending after the redirect. |
641 MessageLoop::current()->RunUntilIdle(); | 641 base::MessageLoop::current()->RunUntilIdle(); |
642 | 642 |
643 // Logging in shouldn't do anything. | 643 // Logging in shouldn't do anything. |
644 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 644 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
645 RESULT_INTERNET_CONNECTED); | 645 RESULT_INTERNET_CONNECTED); |
646 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 646 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
647 } | 647 } |
648 | 648 |
649 // Check that an HTTPS to HTTPS redirect results in no timer running. | 649 // Check that an HTTPS to HTTPS redirect results in no timer running. |
650 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpsRedirect) { | 650 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpsRedirect) { |
651 tab_reloader().OnLoadStart(true); | 651 tab_reloader().OnLoadStart(true); |
652 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 652 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
653 tab_reloader().state()); | 653 tab_reloader().state()); |
654 | 654 |
655 tab_reloader().OnRedirect(true); | 655 tab_reloader().OnRedirect(true); |
656 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 656 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
657 tab_reloader().state()); | 657 tab_reloader().state()); |
658 EXPECT_FALSE(tab_reloader().TimerRunning()); | 658 EXPECT_FALSE(tab_reloader().TimerRunning()); |
659 // Nothing should happen. | 659 // Nothing should happen. |
660 MessageLoop::current()->RunUntilIdle(); | 660 base::MessageLoop::current()->RunUntilIdle(); |
661 } | 661 } |
662 | 662 |
663 // Check that an HTTPS to HTTP to HTTPS redirect results in no timer running. | 663 // Check that an HTTPS to HTTP to HTTPS redirect results in no timer running. |
664 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpToHttpsRedirect) { | 664 TEST_F(CaptivePortalTabReloaderTest, HttpsToHttpToHttpsRedirect) { |
665 tab_reloader().OnLoadStart(true); | 665 tab_reloader().OnLoadStart(true); |
666 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, | 666 EXPECT_EQ(CaptivePortalTabReloader::STATE_TIMER_RUNNING, |
667 tab_reloader().state()); | 667 tab_reloader().state()); |
668 | 668 |
669 tab_reloader().OnRedirect(false); | 669 tab_reloader().OnRedirect(false); |
670 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 670 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
671 EXPECT_FALSE(tab_reloader().TimerRunning()); | 671 EXPECT_FALSE(tab_reloader().TimerRunning()); |
672 | 672 |
673 tab_reloader().OnRedirect(true); | 673 tab_reloader().OnRedirect(true); |
674 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 674 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
675 tab_reloader().state()); | 675 tab_reloader().state()); |
676 EXPECT_FALSE(tab_reloader().TimerRunning()); | 676 EXPECT_FALSE(tab_reloader().TimerRunning()); |
677 // Nothing should happen. | 677 // Nothing should happen. |
678 MessageLoop::current()->RunUntilIdle(); | 678 base::MessageLoop::current()->RunUntilIdle(); |
679 } | 679 } |
680 | 680 |
681 // Check that an HTTP to HTTP redirect results in the timer not running. | 681 // Check that an HTTP to HTTP redirect results in the timer not running. |
682 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpRedirect) { | 682 TEST_F(CaptivePortalTabReloaderTest, HttpToHttpRedirect) { |
683 tab_reloader().OnLoadStart(false); | 683 tab_reloader().OnLoadStart(false); |
684 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 684 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
685 | 685 |
686 tab_reloader().OnRedirect(false); | 686 tab_reloader().OnRedirect(false); |
687 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 687 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
688 EXPECT_FALSE(tab_reloader().TimerRunning()); | 688 EXPECT_FALSE(tab_reloader().TimerRunning()); |
689 | 689 |
690 // There should be no captive portal check pending after the redirect. | 690 // There should be no captive portal check pending after the redirect. |
691 MessageLoop::current()->RunUntilIdle(); | 691 base::MessageLoop::current()->RunUntilIdle(); |
692 | 692 |
693 // Logging in shouldn't do anything. | 693 // Logging in shouldn't do anything. |
694 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, | 694 tab_reloader().OnCaptivePortalResults(RESULT_BEHIND_CAPTIVE_PORTAL, |
695 RESULT_INTERNET_CONNECTED); | 695 RESULT_INTERNET_CONNECTED); |
696 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); | 696 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, tab_reloader().state()); |
697 } | 697 } |
698 | 698 |
699 } // namespace captive_portal | 699 } // namespace captive_portal |
OLD | NEW |