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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_browsertest.cc

Issue 242483003: Move CaptivePortalDetector to src/components/captive_portal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move CaptivePortalDetector to a component Created 6 years, 8 months 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
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "net/base/net_errors.h" 46 #include "net/base/net_errors.h"
47 #include "net/http/transport_security_state.h" 47 #include "net/http/transport_security_state.h"
48 #include "net/url_request/url_request.h" 48 #include "net/url_request/url_request.h"
49 #include "net/url_request/url_request_context.h" 49 #include "net/url_request/url_request_context.h"
50 #include "net/url_request/url_request_context_getter.h" 50 #include "net/url_request/url_request_context_getter.h"
51 #include "net/url_request/url_request_filter.h" 51 #include "net/url_request/url_request_filter.h"
52 #include "net/url_request/url_request_job.h" 52 #include "net/url_request/url_request_job.h"
53 #include "net/url_request/url_request_status.h" 53 #include "net/url_request/url_request_status.h"
54 #include "testing/gtest/include/gtest/gtest.h" 54 #include "testing/gtest/include/gtest/gtest.h"
55 55
56 using captive_portal::CaptivePortalDetector;
mmenke 2014/04/21 14:32:43 If we're going to share the captive_portal namespa
stevenjb 2014/04/21 16:42:27 Done.
56 using content::BrowserThread; 57 using content::BrowserThread;
57 using content::URLRequestFailedJob; 58 using content::URLRequestFailedJob;
58 using content::URLRequestMockHTTPJob; 59 using content::URLRequestMockHTTPJob;
59 using content::WebContents; 60 using content::WebContents;
60 61
61 namespace captive_portal { 62 namespace captive_portal {
62 63
63 namespace { 64 namespace {
64 65
65 // Path of the fake login page, when using the TestServer. 66 // Path of the fake login page, when using the TestServer.
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 public: 679 public:
679 explicit CaptivePortalObserver(Profile* profile); 680 explicit CaptivePortalObserver(Profile* profile);
680 681
681 // Runs the message loop until until at exactly |update_count| capitive portal 682 // Runs the message loop until until at exactly |update_count| capitive portal
682 // results have been received, since this creation of |this|. Expects no 683 // results have been received, since this creation of |this|. Expects no
683 // additional captive portal results. 684 // additional captive portal results.
684 void WaitForResults(int num_results_to_wait_for); 685 void WaitForResults(int num_results_to_wait_for);
685 686
686 int num_results_received() const { return num_results_received_; } 687 int num_results_received() const { return num_results_received_; }
687 688
688 Result captive_portal_result() const { 689 CaptivePortalResult captive_portal_result() const {
689 return captive_portal_result_; 690 return captive_portal_result_;
690 } 691 }
691 692
692 private: 693 private:
693 // Records results and exits the message loop, if needed. 694 // Records results and exits the message loop, if needed.
694 virtual void Observe(int type, 695 virtual void Observe(int type,
695 const content::NotificationSource& source, 696 const content::NotificationSource& source,
696 const content::NotificationDetails& details) OVERRIDE; 697 const content::NotificationDetails& details) OVERRIDE;
697 698
698 // Number of times OnPortalResult has been called since construction. 699 // Number of times OnPortalResult has been called since construction.
699 int num_results_received_; 700 int num_results_received_;
700 701
701 // If WaitForResults was called, the total number of updates for which to 702 // If WaitForResults was called, the total number of updates for which to
702 // wait. Value doesn't matter when |waiting_for_result_| is false. 703 // wait. Value doesn't matter when |waiting_for_result_| is false.
703 int num_results_to_wait_for_; 704 int num_results_to_wait_for_;
704 705
705 bool waiting_for_result_; 706 bool waiting_for_result_;
706 707
707 Profile* profile_; 708 Profile* profile_;
708 709
709 CaptivePortalService* captive_portal_service_; 710 CaptivePortalService* captive_portal_service_;
710 711
711 // Last result received. 712 // Last result received.
712 Result captive_portal_result_; 713 CaptivePortalResult captive_portal_result_;
713 714
714 content::NotificationRegistrar registrar_; 715 content::NotificationRegistrar registrar_;
715 716
716 DISALLOW_COPY_AND_ASSIGN(CaptivePortalObserver); 717 DISALLOW_COPY_AND_ASSIGN(CaptivePortalObserver);
717 }; 718 };
718 719
719 CaptivePortalObserver::CaptivePortalObserver(Profile* profile) 720 CaptivePortalObserver::CaptivePortalObserver(Profile* profile)
720 : num_results_received_(0), 721 : num_results_received_(0),
721 num_results_to_wait_for_(0), 722 num_results_to_wait_for_(0),
722 waiting_for_result_(false), 723 waiting_for_result_(false),
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // active tab will end up being navigated. It should be 1, except for the 829 // active tab will end up being navigated. It should be 1, except for the
829 // Link Doctor page, which acts like two navigations. 830 // Link Doctor page, which acts like two navigations.
830 void NavigateToPageExpectNoTest(Browser* browser, 831 void NavigateToPageExpectNoTest(Browser* browser,
831 const GURL& url, 832 const GURL& url,
832 int expected_navigations); 833 int expected_navigations);
833 834
834 // Navigates |browser|'s active tab to an SSL tab that takes a while to load, 835 // Navigates |browser|'s active tab to an SSL tab that takes a while to load,
835 // triggering a captive portal check, which is expected to give the result 836 // triggering a captive portal check, which is expected to give the result
836 // |expected_result|. The page finishes loading, with a timeout, after the 837 // |expected_result|. The page finishes loading, with a timeout, after the
837 // captive portal check. 838 // captive portal check.
838 void SlowLoadNoCaptivePortal(Browser* browser, Result expected_result); 839 void SlowLoadNoCaptivePortal(Browser* browser,
840 CaptivePortalResult expected_result);
839 841
840 // Navigates |browser|'s active tab to an SSL timeout, expecting a captive 842 // Navigates |browser|'s active tab to an SSL timeout, expecting a captive
841 // portal check to be triggered and return a result which will indicates 843 // portal check to be triggered and return a result which will indicates
842 // there's no detected captive portal. 844 // there's no detected captive portal.
843 void FastTimeoutNoCaptivePortal(Browser* browser, Result expected_result); 845 void FastTimeoutNoCaptivePortal(Browser* browser,
846 CaptivePortalResult expected_result);
844 847
845 // Navigates the active tab to a slow loading SSL page, which will then 848 // Navigates the active tab to a slow loading SSL page, which will then
846 // trigger a captive portal test. The test is expected to find a captive 849 // trigger a captive portal test. The test is expected to find a captive
847 // portal. The slow loading page will continue to load after the function 850 // portal. The slow loading page will continue to load after the function
848 // returns, until URLRequestTimeoutOnDemandJob::FailJobs() is called, 851 // returns, until URLRequestTimeoutOnDemandJob::FailJobs() is called,
849 // at which point it will timeout. 852 // at which point it will timeout.
850 // 853 //
851 // When |expect_login_tab| is false, no login tab is expected to be opened, 854 // When |expect_login_tab| is false, no login tab is expected to be opened,
852 // because one already exists, and the function returns once the captive 855 // because one already exists, and the function returns once the captive
853 // portal test is complete. 856 // portal test is complete.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 EXPECT_EQ(0, portal_observer.num_results_received()); 1047 EXPECT_EQ(0, portal_observer.num_results_received());
1045 EXPECT_FALSE(CheckPending(browser)); 1048 EXPECT_FALSE(CheckPending(browser));
1046 EXPECT_EQ(1, browser->tab_strip_model()->count()); 1049 EXPECT_EQ(1, browser->tab_strip_model()->count());
1047 EXPECT_EQ(expected_navigations, navigation_observer.num_navigations()); 1050 EXPECT_EQ(expected_navigations, navigation_observer.num_navigations());
1048 EXPECT_EQ(0, NumLoadingTabs()); 1051 EXPECT_EQ(0, NumLoadingTabs());
1049 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, 1052 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE,
1050 GetStateOfTabReloaderAt(browser, 0)); 1053 GetStateOfTabReloaderAt(browser, 0));
1051 } 1054 }
1052 1055
1053 void CaptivePortalBrowserTest::SlowLoadNoCaptivePortal( 1056 void CaptivePortalBrowserTest::SlowLoadNoCaptivePortal(
1054 Browser* browser, Result expected_result) { 1057 Browser* browser,
1058 CaptivePortalResult expected_result) {
1055 CaptivePortalTabReloader* tab_reloader = 1059 CaptivePortalTabReloader* tab_reloader =
1056 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents()); 1060 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents());
1057 ASSERT_TRUE(tab_reloader); 1061 ASSERT_TRUE(tab_reloader);
1058 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta()); 1062 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta());
1059 1063
1060 MultiNavigationObserver navigation_observer; 1064 MultiNavigationObserver navigation_observer;
1061 CaptivePortalObserver portal_observer(browser->profile()); 1065 CaptivePortalObserver portal_observer(browser->profile());
1062 ui_test_utils::NavigateToURLWithDisposition(browser, 1066 ui_test_utils::NavigateToURLWithDisposition(browser,
1063 GURL(kMockHttpsUrl), 1067 GURL(kMockHttpsUrl),
1064 CURRENT_TAB, 1068 CURRENT_TAB,
(...skipping 18 matching lines...) Expand all
1083 ASSERT_EQ(1, browser->tab_strip_model()->count()); 1087 ASSERT_EQ(1, browser->tab_strip_model()->count());
1084 EXPECT_EQ(1, portal_observer.num_results_received()); 1088 EXPECT_EQ(1, portal_observer.num_results_received());
1085 EXPECT_FALSE(CheckPending(browser)); 1089 EXPECT_FALSE(CheckPending(browser));
1086 EXPECT_EQ(0, NumLoadingTabs()); 1090 EXPECT_EQ(0, NumLoadingTabs());
1087 1091
1088 // Set a slow SSL load time to prevent the timer from triggering. 1092 // Set a slow SSL load time to prevent the timer from triggering.
1089 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1)); 1093 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromDays(1));
1090 } 1094 }
1091 1095
1092 void CaptivePortalBrowserTest::FastTimeoutNoCaptivePortal( 1096 void CaptivePortalBrowserTest::FastTimeoutNoCaptivePortal(
1093 Browser* browser, Result expected_result) { 1097 Browser* browser,
1098 CaptivePortalResult expected_result) {
1094 ASSERT_NE(expected_result, RESULT_BEHIND_CAPTIVE_PORTAL); 1099 ASSERT_NE(expected_result, RESULT_BEHIND_CAPTIVE_PORTAL);
1095 1100
1096 // Set the load time to be large, so the timer won't trigger. The value is 1101 // Set the load time to be large, so the timer won't trigger. The value is
1097 // not restored at the end of the function. 1102 // not restored at the end of the function.
1098 CaptivePortalTabReloader* tab_reloader = 1103 CaptivePortalTabReloader* tab_reloader =
1099 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents()); 1104 GetTabReloader(browser->tab_strip_model()->GetActiveWebContents());
1100 ASSERT_TRUE(tab_reloader); 1105 ASSERT_TRUE(tab_reloader);
1101 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); 1106 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1));
1102 1107
1103 MultiNavigationObserver navigation_observer; 1108 MultiNavigationObserver navigation_observer;
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 base::Bind(&AddHstsHost, 2198 base::Bind(&AddHstsHost,
2194 make_scoped_refptr(browser()->profile()->GetRequestContext()), 2199 make_scoped_refptr(browser()->profile()->GetRequestContext()),
2195 http_timeout_url.host())); 2200 http_timeout_url.host()));
2196 2201
2197 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); 2202 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1);
2198 Login(browser(), 1, 0); 2203 Login(browser(), 1, 0);
2199 FailLoadsAfterLogin(browser(), 1); 2204 FailLoadsAfterLogin(browser(), 1);
2200 } 2205 }
2201 2206
2202 } // namespace captive_portal 2207 } // namespace captive_portal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698