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_helper.h" | 5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/captive_portal/captive_portal_service.h" | 9 #include "chrome/browser/captive_portal/captive_portal_service.h" |
10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 content::Details<CaptivePortalService::Results> details_results(&results); | 197 content::Details<CaptivePortalService::Results> details_results(&results); |
198 | 198 |
199 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result, | 199 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result, |
200 result)).Times(1); | 200 result)).Times(1); |
201 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 201 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
202 source_profile, | 202 source_profile, |
203 details_results); | 203 details_results); |
204 } | 204 } |
205 | 205 |
206 // Simulates a redirect. Uses OnRedirect rather than Observe, for simplicity. | 206 // Simulates a redirect. Uses OnRedirect rather than Observe, for simplicity. |
207 void OnRedirect(ResourceType::Type type, const GURL& new_url, int child_id) { | 207 void OnRedirect(ResourceType type, const GURL& new_url, int child_id) { |
208 tab_helper().OnRedirect(child_id, type, new_url); | 208 tab_helper().OnRedirect(child_id, type, new_url); |
209 } | 209 } |
210 | 210 |
211 MockCaptivePortalTabReloader& mock_reloader() { return *mock_reloader_; } | 211 MockCaptivePortalTabReloader& mock_reloader() { return *mock_reloader_; } |
212 | 212 |
213 void SetIsLoginTab() { | 213 void SetIsLoginTab() { |
214 tab_helper().SetIsLoginTab(); | 214 tab_helper().SetIsLoginTab(); |
215 } | 215 } |
216 | 216 |
217 content::RenderViewHost* render_view_host1() { | 217 content::RenderViewHost* render_view_host1() { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 476 |
477 // Simulates an HTTP to HTTPS redirect, which then times out. | 477 // Simulates an HTTP to HTTPS redirect, which then times out. |
478 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) { | 478 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) { |
479 GURL http_url(kHttpUrl); | 479 GURL http_url(kHttpUrl); |
480 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); | 480 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); |
481 tab_helper().DidStartProvisionalLoadForFrame( | 481 tab_helper().DidStartProvisionalLoadForFrame( |
482 main_render_frame1(), http_url, false, false); | 482 main_render_frame1(), http_url, false, false); |
483 | 483 |
484 GURL https_url(kHttpsUrl); | 484 GURL https_url(kHttpsUrl); |
485 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1); | 485 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1); |
486 OnRedirect(ResourceType::MAIN_FRAME, https_url, | 486 OnRedirect(content::RESOURCE_TYPE_MAIN_FRAME, |
| 487 https_url, |
487 render_view_host1()->GetProcess()->GetID()); | 488 render_view_host1()->GetProcess()->GetID()); |
488 | 489 |
489 tab_helper().DidFailProvisionalLoad(main_render_frame1(), | 490 tab_helper().DidFailProvisionalLoad(main_render_frame1(), |
490 https_url, | 491 https_url, |
491 net::ERR_TIMED_OUT, | 492 net::ERR_TIMED_OUT, |
492 base::string16()); | 493 base::string16()); |
493 | 494 |
494 // Provisional load starts for the error page. | 495 // Provisional load starts for the error page. |
495 tab_helper().DidStartProvisionalLoadForFrame( | 496 tab_helper().DidStartProvisionalLoadForFrame( |
496 main_render_frame1(), GURL(kErrorPageUrl), true, false); | 497 main_render_frame1(), GURL(kErrorPageUrl), true, false); |
497 | 498 |
498 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1); | 499 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1); |
499 tab_helper().DidCommitProvisionalLoadForFrame(main_render_frame1(), | 500 tab_helper().DidCommitProvisionalLoadForFrame(main_render_frame1(), |
500 GURL(kErrorPageUrl), | 501 GURL(kErrorPageUrl), |
501 content::PAGE_TRANSITION_LINK); | 502 content::PAGE_TRANSITION_LINK); |
502 } | 503 } |
503 | 504 |
504 // Simulates an HTTPS to HTTP redirect. | 505 // Simulates an HTTPS to HTTP redirect. |
505 TEST_F(CaptivePortalTabHelperTest, HttpsToHttpRedirect) { | 506 TEST_F(CaptivePortalTabHelperTest, HttpsToHttpRedirect) { |
506 GURL https_url(kHttpsUrl); | 507 GURL https_url(kHttpsUrl); |
507 EXPECT_CALL(mock_reloader(), | 508 EXPECT_CALL(mock_reloader(), |
508 OnLoadStart(https_url.SchemeIsSecure())).Times(1); | 509 OnLoadStart(https_url.SchemeIsSecure())).Times(1); |
509 tab_helper().DidStartProvisionalLoadForFrame( | 510 tab_helper().DidStartProvisionalLoadForFrame( |
510 main_render_frame1(), https_url, false, false); | 511 main_render_frame1(), https_url, false, false); |
511 | 512 |
512 GURL http_url(kHttpUrl); | 513 GURL http_url(kHttpUrl); |
513 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1); | 514 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1); |
514 OnRedirect(ResourceType::MAIN_FRAME, http_url, | 515 OnRedirect(content::RESOURCE_TYPE_MAIN_FRAME, http_url, |
515 render_view_host1()->GetProcess()->GetID()); | 516 render_view_host1()->GetProcess()->GetID()); |
516 | 517 |
517 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); | 518 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); |
518 tab_helper().DidCommitProvisionalLoadForFrame( | 519 tab_helper().DidCommitProvisionalLoadForFrame( |
519 main_render_frame1(), http_url, content::PAGE_TRANSITION_LINK); | 520 main_render_frame1(), http_url, content::PAGE_TRANSITION_LINK); |
520 } | 521 } |
521 | 522 |
522 // Simulates an HTTPS to HTTPS redirect. | 523 // Simulates an HTTPS to HTTPS redirect. |
523 TEST_F(CaptivePortalTabHelperTest, HttpToHttpRedirect) { | 524 TEST_F(CaptivePortalTabHelperTest, HttpToHttpRedirect) { |
524 GURL http_url(kHttpUrl); | 525 GURL http_url(kHttpUrl); |
525 EXPECT_CALL(mock_reloader(), | 526 EXPECT_CALL(mock_reloader(), |
526 OnLoadStart(http_url.SchemeIsSecure())).Times(1); | 527 OnLoadStart(http_url.SchemeIsSecure())).Times(1); |
527 tab_helper().DidStartProvisionalLoadForFrame( | 528 tab_helper().DidStartProvisionalLoadForFrame( |
528 main_render_frame1(), http_url, false, false); | 529 main_render_frame1(), http_url, false, false); |
529 | 530 |
530 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1); | 531 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1); |
531 OnRedirect(ResourceType::MAIN_FRAME, http_url, | 532 OnRedirect(content::RESOURCE_TYPE_MAIN_FRAME, http_url, |
532 render_view_host1()->GetProcess()->GetID()); | 533 render_view_host1()->GetProcess()->GetID()); |
533 | 534 |
534 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); | 535 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); |
535 tab_helper().DidCommitProvisionalLoadForFrame( | 536 tab_helper().DidCommitProvisionalLoadForFrame( |
536 main_render_frame1(), http_url, content::PAGE_TRANSITION_LINK); | 537 main_render_frame1(), http_url, content::PAGE_TRANSITION_LINK); |
537 } | 538 } |
538 | 539 |
539 // Tests that a subframe redirect doesn't reset the timer to kick off a captive | 540 // Tests that a subframe redirect doesn't reset the timer to kick off a captive |
540 // portal probe for the main frame if the main frame request is taking too long. | 541 // portal probe for the main frame if the main frame request is taking too long. |
541 TEST_F(CaptivePortalTabHelperTest, SubframeRedirect) { | 542 TEST_F(CaptivePortalTabHelperTest, SubframeRedirect) { |
542 GURL http_url(kHttpUrl); | 543 GURL http_url(kHttpUrl); |
543 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); | 544 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); |
544 tab_helper().DidStartProvisionalLoadForFrame( | 545 tab_helper().DidStartProvisionalLoadForFrame( |
545 main_render_frame1(), http_url, false, false); | 546 main_render_frame1(), http_url, false, false); |
546 | 547 |
547 GURL https_url(kHttpsUrl); | 548 GURL https_url(kHttpsUrl); |
548 OnRedirect(ResourceType::SUB_FRAME, https_url, | 549 OnRedirect(content::RESOURCE_TYPE_SUB_FRAME, |
| 550 https_url, |
549 render_view_host1()->GetProcess()->GetID()); | 551 render_view_host1()->GetProcess()->GetID()); |
550 | 552 |
551 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); | 553 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); |
552 tab_helper().DidCommitProvisionalLoadForFrame( | 554 tab_helper().DidCommitProvisionalLoadForFrame( |
553 main_render_frame1(), GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK); | 555 main_render_frame1(), GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK); |
554 } | 556 } |
555 | 557 |
556 // Simulates a redirect, for another RenderViewHost. | 558 // Simulates a redirect, for another RenderViewHost. |
557 TEST_F(CaptivePortalTabHelperTest, OtherRenderViewHostRedirect) { | 559 TEST_F(CaptivePortalTabHelperTest, OtherRenderViewHostRedirect) { |
558 GURL http_url(kHttpUrl); | 560 GURL http_url(kHttpUrl); |
559 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); | 561 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); |
560 tab_helper().DidStartProvisionalLoadForFrame( | 562 tab_helper().DidStartProvisionalLoadForFrame( |
561 main_render_frame1(), http_url, false, false); | 563 main_render_frame1(), http_url, false, false); |
562 | 564 |
563 // Another RenderViewHost sees a redirect. None of the reloader's functions | 565 // Another RenderViewHost sees a redirect. None of the reloader's functions |
564 // should be called. | 566 // should be called. |
565 GURL https_url(kHttpsUrl); | 567 GURL https_url(kHttpsUrl); |
566 OnRedirect(ResourceType::MAIN_FRAME, https_url, | 568 OnRedirect(content::RESOURCE_TYPE_MAIN_FRAME, |
| 569 https_url, |
567 render_view_host2()->GetProcess()->GetID()); | 570 render_view_host2()->GetProcess()->GetID()); |
568 | 571 |
569 tab_helper().DidFailProvisionalLoad(main_render_frame1(), | 572 tab_helper().DidFailProvisionalLoad(main_render_frame1(), |
570 https_url, | 573 https_url, |
571 net::ERR_TIMED_OUT, | 574 net::ERR_TIMED_OUT, |
572 base::string16()); | 575 base::string16()); |
573 | 576 |
574 // Provisional load starts for the error page. | 577 // Provisional load starts for the error page. |
575 tab_helper().DidStartProvisionalLoadForFrame( | 578 tab_helper().DidStartProvisionalLoadForFrame( |
576 main_render_frame1(), GURL(kErrorPageUrl), true, false); | 579 main_render_frame1(), GURL(kErrorPageUrl), true, false); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 EXPECT_FALSE(tab_helper().IsLoginTab()); | 632 EXPECT_FALSE(tab_helper().IsLoginTab()); |
630 | 633 |
631 ObservePortalResult(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | 634 ObservePortalResult(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
632 captive_portal::RESULT_NO_RESPONSE); | 635 captive_portal::RESULT_NO_RESPONSE); |
633 EXPECT_FALSE(tab_helper().IsLoginTab()); | 636 EXPECT_FALSE(tab_helper().IsLoginTab()); |
634 | 637 |
635 ObservePortalResult(captive_portal::RESULT_NO_RESPONSE, | 638 ObservePortalResult(captive_portal::RESULT_NO_RESPONSE, |
636 captive_portal::RESULT_INTERNET_CONNECTED); | 639 captive_portal::RESULT_INTERNET_CONNECTED); |
637 EXPECT_FALSE(tab_helper().IsLoginTab()); | 640 EXPECT_FALSE(tab_helper().IsLoginTab()); |
638 } | 641 } |
OLD | NEW |