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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | |
7 | 8 |
8 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/memory/scoped_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
14 #include "base/path_service.h" | 16 #include "base/path_service.h" |
15 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
16 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | |
17 #include "chrome/browser/captive_portal/captive_portal_service.h" | 20 #include "chrome/browser/captive_portal/captive_portal_service.h" |
18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 21 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
19 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 22 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
20 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 23 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
25 #include "chrome/browser/interstitials/security_interstitial_page.h" | |
22 #include "chrome/browser/net/url_request_mock_util.h" | 26 #include "chrome/browser/net/url_request_mock_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | |
29 #include "chrome/browser/ssl/ssl_blocking_page.h" | |
30 #include "chrome/browser/ssl/ssl_error_handler.h" | |
24 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_commands.h" | 32 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
27 #include "chrome/browser/ui/browser_navigator.h" | 34 #include "chrome/browser/ui/browser_navigator.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" | 35 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" |
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
30 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
31 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
33 #include "chrome/test/base/in_process_browser_test.h" | 40 #include "chrome/test/base/in_process_browser_test.h" |
34 #include "chrome/test/base/ui_test_utils.h" | 41 #include "chrome/test/base/ui_test_utils.h" |
35 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/interstitial_page.h" | |
44 #include "content/public/browser/interstitial_page_delegate.h" | |
36 #include "content/public/browser/navigation_controller.h" | 45 #include "content/public/browser/navigation_controller.h" |
46 #include "content/public/browser/navigation_entry.h" | |
37 #include "content/public/browser/notification_observer.h" | 47 #include "content/public/browser/notification_observer.h" |
38 #include "content/public/browser/notification_registrar.h" | 48 #include "content/public/browser/notification_registrar.h" |
39 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
40 #include "content/public/browser/notification_types.h" | 50 #include "content/public/browser/notification_types.h" |
41 #include "content/public/browser/render_frame_host.h" | 51 #include "content/public/browser/render_frame_host.h" |
52 #include "content/public/browser/render_view_host.h" | |
42 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
43 #include "content/public/common/url_constants.h" | 54 #include "content/public/common/url_constants.h" |
55 #include "content/public/test/browser_test_utils.h" | |
44 #include "net/base/net_errors.h" | 56 #include "net/base/net_errors.h" |
45 #include "net/http/transport_security_state.h" | 57 #include "net/http/transport_security_state.h" |
46 #include "net/test/url_request/url_request_failed_job.h" | 58 #include "net/test/url_request/url_request_failed_job.h" |
47 #include "net/test/url_request/url_request_mock_http_job.h" | 59 #include "net/test/url_request/url_request_mock_http_job.h" |
48 #include "net/url_request/url_request.h" | 60 #include "net/url_request/url_request.h" |
49 #include "net/url_request/url_request_context.h" | 61 #include "net/url_request/url_request_context.h" |
50 #include "net/url_request/url_request_context_getter.h" | 62 #include "net/url_request/url_request_context_getter.h" |
51 #include "net/url_request/url_request_filter.h" | 63 #include "net/url_request/url_request_filter.h" |
52 #include "net/url_request/url_request_job.h" | 64 #include "net/url_request/url_request_job.h" |
53 #include "net/url_request/url_request_status.h" | 65 #include "net/url_request/url_request_status.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 "https://mock.captive.portal.long.timeout2/title2.html"; | 114 "https://mock.captive.portal.long.timeout2/title2.html"; |
103 | 115 |
104 // Same as kMockHttpsUrl, except the timeout happens instantly. | 116 // Same as kMockHttpsUrl, except the timeout happens instantly. |
105 const char* const kMockHttpsQuickTimeoutUrl = | 117 const char* const kMockHttpsQuickTimeoutUrl = |
106 "https://mock.captive.portal.quick.timeout/title2.html"; | 118 "https://mock.captive.portal.quick.timeout/title2.html"; |
107 | 119 |
108 // Expected title of a tab once an HTTPS load completes, when not behind a | 120 // Expected title of a tab once an HTTPS load completes, when not behind a |
109 // captive portal. | 121 // captive portal. |
110 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; | 122 const char* const kInternetConnectedTitle = "Title Of Awesomeness"; |
111 | 123 |
124 // Wait until all resources have loaded in an interstitial page. | |
125 bool WaitForInterstitialReady(content::InterstitialPage* interstitial) { | |
126 content::RenderViewHost* rvh = interstitial->GetRenderViewHostForTesting(); | |
127 if (!rvh) | |
128 return false; | |
129 bool load_complete = false; | |
130 EXPECT_TRUE( | |
131 content::ExecuteScriptAndExtractBool( | |
132 rvh->GetMainFrame(), | |
133 "(function() {" | |
134 " var done = false;" | |
135 " function checkState() {" | |
136 " if (!done && document.readyState == 'complete') {" | |
137 " done = true;" | |
138 " window.domAutomationController.send(true);" | |
139 " }" | |
140 " }" | |
141 " checkState();" | |
142 " document.addEventListener('readystatechange', checkState);" | |
143 "})();", | |
144 &load_complete)); | |
145 return load_complete; | |
146 } | |
147 | |
112 // A URL request job that hangs until FailJobs() is called. Started jobs | 148 // A URL request job that hangs until FailJobs() is called. Started jobs |
113 // are stored in a static class variable containing a linked list so that | 149 // are stored in a static class variable containing a linked list so that |
114 // FailJobs() can locate them. | 150 // FailJobs() can locate them. |
115 class URLRequestTimeoutOnDemandJob : public net::URLRequestJob, | 151 class URLRequestTimeoutOnDemandJob : public net::URLRequestJob, |
116 public base::NonThreadSafe { | 152 public base::NonThreadSafe { |
117 public: | 153 public: |
118 // net::URLRequestJob: | 154 // net::URLRequestJob: |
119 void Start() override; | 155 void Start() override; |
120 | 156 |
121 // All the public static methods below can be called on any thread. | 157 // All the public static methods below can be called on any thread. |
122 | 158 |
123 // Waits for exactly |num_jobs|. | 159 // Waits for exactly |num_jobs|. |
124 static void WaitForJobs(int num_jobs); | 160 static void WaitForJobs(int num_jobs); |
125 | 161 |
126 // Fails all active URLRequestTimeoutOnDemandJobs with connection timeouts. | 162 // Fails all active URLRequestTimeoutOnDemandJobs with connection timeouts. |
127 // There are expected to be exactly |expected_num_jobs| waiting for | 163 // There are expected to be exactly |expected_num_jobs| waiting for |
128 // failure. The only way to gaurantee this is with an earlier call to | 164 // failure. The only way to guarantee this is with an earlier call to |
129 // WaitForJobs, so makes sure there has been a matching WaitForJobs call. | 165 // WaitForJobs, so makes sure there has been a matching WaitForJobs call. |
130 static void FailJobs(int expected_num_jobs); | 166 static void FailJobs(int expected_num_jobs); |
131 | 167 |
168 // Fails all active URLRequestTimeoutOnDemandJobs with SSL cert errors. | |
169 // |expected_num_jobs| behaves just as in FailJobs. | |
170 static void FailJobsWithCertError(int expected_num_jobs); | |
171 | |
132 // Abandon all active URLRequestTimeoutOnDemandJobs. |expected_num_jobs| | 172 // Abandon all active URLRequestTimeoutOnDemandJobs. |expected_num_jobs| |
133 // behaves just as in FailJobs. | 173 // behaves just as in FailJobs. |
134 static void AbandonJobs(int expected_num_jobs); | 174 static void AbandonJobs(int expected_num_jobs); |
135 | 175 |
136 private: | 176 private: |
137 friend class URLRequestMockCaptivePortalJobFactory; | 177 friend class URLRequestMockCaptivePortalJobFactory; |
138 | 178 |
139 // Operation to perform on jobs when removing them from |job_list_|. | 179 // Operation to perform on jobs when removing them from |job_list_|. |
140 enum EndJobOperation { | 180 enum EndJobOperation { |
141 FAIL_JOBS, | 181 FAIL_JOBS, |
142 ABANDON_JOBS, | 182 ABANDON_JOBS, |
183 FAIL_JOBS_WITH_CERT_ERROR | |
143 }; | 184 }; |
144 | 185 |
145 URLRequestTimeoutOnDemandJob(net::URLRequest* request, | 186 URLRequestTimeoutOnDemandJob(net::URLRequest* request, |
146 net::NetworkDelegate* network_delegate); | 187 net::NetworkDelegate* network_delegate); |
147 ~URLRequestTimeoutOnDemandJob() override; | 188 ~URLRequestTimeoutOnDemandJob() override; |
148 | 189 |
149 // Attempts to removes |this| from |jobs_|. Returns true if it was removed | 190 // Attempts to removes |this| from |jobs_|. Returns true if it was removed |
150 // from the list. | 191 // from the list. |
151 bool RemoveFromList(); | 192 bool RemoveFromList(); |
152 | 193 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 // static | 260 // static |
220 void URLRequestTimeoutOnDemandJob::FailJobs(int expected_num_jobs) { | 261 void URLRequestTimeoutOnDemandJob::FailJobs(int expected_num_jobs) { |
221 content::BrowserThread::PostTask( | 262 content::BrowserThread::PostTask( |
222 content::BrowserThread::IO, FROM_HERE, | 263 content::BrowserThread::IO, FROM_HERE, |
223 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, | 264 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, |
224 expected_num_jobs, | 265 expected_num_jobs, |
225 FAIL_JOBS)); | 266 FAIL_JOBS)); |
226 } | 267 } |
227 | 268 |
228 // static | 269 // static |
270 void URLRequestTimeoutOnDemandJob::FailJobsWithCertError( | |
271 int expected_num_jobs) { | |
272 content::BrowserThread::PostTask( | |
273 content::BrowserThread::IO, FROM_HERE, | |
274 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, | |
275 expected_num_jobs, | |
276 FAIL_JOBS_WITH_CERT_ERROR)); | |
277 } | |
278 | |
279 // static | |
229 void URLRequestTimeoutOnDemandJob::AbandonJobs(int expected_num_jobs) { | 280 void URLRequestTimeoutOnDemandJob::AbandonJobs(int expected_num_jobs) { |
230 content::BrowserThread::PostTask( | 281 content::BrowserThread::PostTask( |
231 content::BrowserThread::IO, FROM_HERE, | 282 content::BrowserThread::IO, FROM_HERE, |
232 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, | 283 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, |
233 expected_num_jobs, | 284 expected_num_jobs, |
234 ABANDON_JOBS)); | 285 ABANDON_JOBS)); |
235 } | 286 } |
236 | 287 |
237 URLRequestTimeoutOnDemandJob::URLRequestTimeoutOnDemandJob( | 288 URLRequestTimeoutOnDemandJob::URLRequestTimeoutOnDemandJob( |
238 net::URLRequest* request, net::NetworkDelegate* network_delegate) | 289 net::URLRequest* request, net::NetworkDelegate* network_delegate) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 while (job_list_) { | 357 while (job_list_) { |
307 ++num_jobs; | 358 ++num_jobs; |
308 URLRequestTimeoutOnDemandJob* job = job_list_; | 359 URLRequestTimeoutOnDemandJob* job = job_list_; |
309 // Since the error notification may result in the job's destruction, remove | 360 // Since the error notification may result in the job's destruction, remove |
310 // it from the job list before the error. | 361 // it from the job list before the error. |
311 EXPECT_TRUE(job->RemoveFromList()); | 362 EXPECT_TRUE(job->RemoveFromList()); |
312 if (end_job_operation == FAIL_JOBS) { | 363 if (end_job_operation == FAIL_JOBS) { |
313 job->NotifyStartError(net::URLRequestStatus( | 364 job->NotifyStartError(net::URLRequestStatus( |
314 net::URLRequestStatus::FAILED, | 365 net::URLRequestStatus::FAILED, |
315 net::ERR_CONNECTION_TIMED_OUT)); | 366 net::ERR_CONNECTION_TIMED_OUT)); |
367 } else if (end_job_operation == FAIL_JOBS_WITH_CERT_ERROR) { | |
368 ASSERT_TRUE(job->request()->url().SchemeIs(url::kHttpsScheme)); | |
369 net::SSLInfo info; | |
370 info.cert_status = net::CERT_STATUS_COMMON_NAME_INVALID; | |
371 info.cert = new net::X509Certificate( | |
372 "bad.host", "CA", base::Time::Max(), base::Time::Max()); | |
373 job->NotifySSLCertificateError(info, true); | |
316 } | 374 } |
317 } | 375 } |
318 | 376 |
319 EXPECT_EQ(expected_num_jobs, num_jobs_started_); | 377 EXPECT_EQ(expected_num_jobs, num_jobs_started_); |
320 EXPECT_EQ(expected_num_jobs, num_jobs); | 378 EXPECT_EQ(expected_num_jobs, num_jobs); |
321 | 379 |
322 num_jobs_started_ -= expected_num_jobs; | 380 num_jobs_started_ -= expected_num_jobs; |
323 } | 381 } |
324 | 382 |
325 // URLRequestCaptivePortalJobFactory emulates captive portal behavior. | 383 // URLRequestCaptivePortalJobFactory emulates captive portal behavior. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 base::MessageLoopForUI::current()->Quit(); | 740 base::MessageLoopForUI::current()->Quit(); |
683 } | 741 } |
684 } | 742 } |
685 | 743 |
686 // An observer for watching the CaptivePortalService. It tracks the last | 744 // An observer for watching the CaptivePortalService. It tracks the last |
687 // received result and the total number of received results. | 745 // received result and the total number of received results. |
688 class CaptivePortalObserver : public content::NotificationObserver { | 746 class CaptivePortalObserver : public content::NotificationObserver { |
689 public: | 747 public: |
690 explicit CaptivePortalObserver(Profile* profile); | 748 explicit CaptivePortalObserver(Profile* profile); |
691 | 749 |
692 // Runs the message loop until until at exactly |update_count| capitive portal | 750 // Runs the message loop until exactly |update_count| captive portal |
693 // results have been received, since this creation of |this|. Expects no | 751 // results have been received, since the creation of |this|. Expects no |
694 // additional captive portal results. | 752 // additional captive portal results. |
695 void WaitForResults(int num_results_to_wait_for); | 753 void WaitForResults(int num_results_to_wait_for); |
696 | 754 |
697 int num_results_received() const { return num_results_received_; } | 755 int num_results_received() const { return num_results_received_; } |
698 | 756 |
699 CaptivePortalResult captive_portal_result() const { | 757 CaptivePortalResult captive_portal_result() const { |
700 return captive_portal_result_; | 758 return captive_portal_result_; |
701 } | 759 } |
702 | 760 |
703 private: | 761 private: |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 CaptivePortalBrowserTest(); | 859 CaptivePortalBrowserTest(); |
802 | 860 |
803 // InProcessBrowserTest: | 861 // InProcessBrowserTest: |
804 void SetUpOnMainThread() override; | 862 void SetUpOnMainThread() override; |
805 void TearDownOnMainThread() override; | 863 void TearDownOnMainThread() override; |
806 | 864 |
807 // Sets the captive portal checking preference. Does not affect the command | 865 // Sets the captive portal checking preference. Does not affect the command |
808 // line flag, which is set in SetUpCommandLine. | 866 // line flag, which is set in SetUpCommandLine. |
809 void EnableCaptivePortalDetection(Profile* profile, bool enabled); | 867 void EnableCaptivePortalDetection(Profile* profile, bool enabled); |
810 | 868 |
869 // Enables or disables actual captive portal probes. Should only be called | |
870 // after captive portal service setup is done. When disabled, probe requests | |
871 // are silently ignored, never receiving a response. | |
872 void RespondToProbeRequests(bool enabled); | |
873 | |
811 // Sets up the captive portal service for the given profile so that | 874 // Sets up the captive portal service for the given profile so that |
812 // all checks go to |test_url|. Also disables all timers. | 875 // all checks go to |test_url|. Also disables all timers. |
813 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); | 876 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); |
814 | 877 |
815 // Returns true if |browser|'s profile is currently running a captive portal | 878 // Returns true if |browser|'s profile is currently running a captive portal |
816 // check. | 879 // check. |
817 bool CheckPending(Browser* browser); | 880 bool CheckPending(Browser* browser); |
818 | 881 |
882 // Returns the type of the interstitial being shown. | |
883 const void* GetInterstitialType(WebContents* contents) const; | |
884 | |
819 // Returns the CaptivePortalTabReloader::State of |web_contents|. | 885 // Returns the CaptivePortalTabReloader::State of |web_contents|. |
820 CaptivePortalTabReloader::State GetStateOfTabReloader( | 886 CaptivePortalTabReloader::State GetStateOfTabReloader( |
821 WebContents* web_contents) const; | 887 WebContents* web_contents) const; |
822 | 888 |
823 // Returns the CaptivePortalTabReloader::State of the indicated tab. | 889 // Returns the CaptivePortalTabReloader::State of the indicated tab. |
824 CaptivePortalTabReloader::State GetStateOfTabReloaderAt(Browser* browser, | 890 CaptivePortalTabReloader::State GetStateOfTabReloaderAt(Browser* browser, |
825 int index) const; | 891 int index) const; |
826 | 892 |
827 // Returns the number of tabs with the given state, across all profiles. | 893 // Returns the number of tabs with the given state, across all profiles. |
828 int NumTabsWithState(CaptivePortalTabReloader::State state) const; | 894 int NumTabsWithState(CaptivePortalTabReloader::State state) const; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 | 956 |
891 // Just like SlowLoadBehindCaptivePortal, except the navigated tab has | 957 // Just like SlowLoadBehindCaptivePortal, except the navigated tab has |
892 // a connection timeout rather having its time trigger, and the function | 958 // a connection timeout rather having its time trigger, and the function |
893 // waits until that timeout occurs. | 959 // waits until that timeout occurs. |
894 void FastTimeoutBehindCaptivePortal(Browser* browser, | 960 void FastTimeoutBehindCaptivePortal(Browser* browser, |
895 bool expect_open_login_tab); | 961 bool expect_open_login_tab); |
896 | 962 |
897 // Much as above, but accepts a URL parameter and can be used for errors that | 963 // Much as above, but accepts a URL parameter and can be used for errors that |
898 // trigger captive portal checks other than timeouts. |error_url| should | 964 // trigger captive portal checks other than timeouts. |error_url| should |
899 // result in an error rather than hanging. | 965 // result in an error rather than hanging. |
900 void FastErrorBehindCaptivePortal(Browser* browser, | 966 // If |delay_portal_response_until_interstital| is true, captive portal probe |
901 bool expect_open_login_tab, | 967 // request are ignored until the interstitial is shown, at which point a |
902 const GURL& error_url); | 968 // captive portal result is sent. This allows testing in conjunction with the |
969 // certificate error interstitial. | |
970 void FastErrorBehindCaptivePortal( | |
971 Browser* browser, | |
972 bool expect_open_login_tab, | |
973 const GURL& error_url, | |
974 bool delay_portal_response_until_interstital); | |
975 | |
976 // Navigates the active tab to an SSL error page which triggers an | |
977 // interstitial timer. Also disables captive portal checks indefinitely, so | |
978 // the page appears to be hanging. | |
979 void FastErrorWithInterstitialTimer(Browser* browser, | |
980 const GURL& cert_error_url); | |
903 | 981 |
904 // Navigates the login tab without logging in. The login tab must be the | 982 // Navigates the login tab without logging in. The login tab must be the |
905 // specified browser's active tab. Expects no other tab to change state. | 983 // specified browser's active tab. Expects no other tab to change state. |
906 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks | 984 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks |
907 // that nothing has gone wrong prior to the function call. | 985 // that nothing has gone wrong prior to the function call. |
908 void NavigateLoginTab(Browser* browser, | 986 void NavigateLoginTab(Browser* browser, |
909 int num_loading_tabs, | 987 int num_loading_tabs, |
910 int num_timed_out_tabs); | 988 int num_timed_out_tabs); |
911 | 989 |
912 // Simulates a login by updating the URLRequestMockCaptivePortalJob's | 990 // Simulates a login by updating the URLRequestMockCaptivePortalJob's |
913 // behind captive portal state, and navigating the login tab. Waits for | 991 // behind captive portal state, and navigating the login tab. Waits for |
914 // all broken but not loading tabs to be reloaded. | 992 // all broken but not loading tabs to be reloaded. |
915 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks | 993 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks |
916 // that nothing has gone wrong prior to the function call. | 994 // that nothing has gone wrong prior to the function call. |
917 void Login(Browser* browser, int num_loading_tabs, int num_timed_out_tabs); | 995 void Login(Browser* browser, int num_loading_tabs, int num_timed_out_tabs); |
918 | 996 |
997 // Simulates a login when the broken tab shows an SSL or captive portal | |
998 // interstitial. Can't use Login() in those cases because the interstitial | |
999 // tab looks like a cross between a hung tab (Load was never committed) and a | |
1000 // tab at an error page (The load was stopped). | |
1001 void LoginCertError(Browser* browser); | |
1002 | |
919 // Makes the slow SSL loads of all active tabs time out at once, and waits for | 1003 // Makes the slow SSL loads of all active tabs time out at once, and waits for |
920 // them to finish both that load and the automatic reload it should trigger. | 1004 // them to finish both that load and the automatic reload it should trigger. |
921 // There should be no timed out tabs when this is called. | 1005 // There should be no timed out tabs when this is called. |
922 void FailLoadsAfterLogin(Browser* browser, int num_loading_tabs); | 1006 void FailLoadsAfterLogin(Browser* browser, int num_loading_tabs); |
923 | 1007 |
924 // Makes the slow SSL loads of all active tabs time out at once, and waits for | 1008 // Makes the slow SSL loads of all active tabs time out at once, and waits for |
925 // them to finish displaying their error pages. The login tab should be the | 1009 // them to finish displaying their error pages. The login tab should be the |
926 // active tab. There should be no timed out tabs when this is called. | 1010 // active tab. There should be no timed out tabs when this is called. |
927 void FailLoadsWithoutLogin(Browser* browser, int num_loading_tabs); | 1011 void FailLoadsWithoutLogin(Browser* browser, int num_loading_tabs); |
928 | 1012 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 CaptivePortalService::get_state_for_testing()); | 1055 CaptivePortalService::get_state_for_testing()); |
972 | 1056 |
973 CaptivePortalService::set_state_for_testing( | 1057 CaptivePortalService::set_state_for_testing( |
974 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); | 1058 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); |
975 EnableCaptivePortalDetection(browser()->profile(), true); | 1059 EnableCaptivePortalDetection(browser()->profile(), true); |
976 | 1060 |
977 // Set the captive portal service to use URLRequestMockCaptivePortalJob's | 1061 // Set the captive portal service to use URLRequestMockCaptivePortalJob's |
978 // mock URL, by default. | 1062 // mock URL, by default. |
979 SetUpCaptivePortalService(browser()->profile(), | 1063 SetUpCaptivePortalService(browser()->profile(), |
980 GURL(kMockCaptivePortalTestUrl)); | 1064 GURL(kMockCaptivePortalTestUrl)); |
1065 | |
1066 // Set SSL interstitial delay long enough so that a captive portal result | |
1067 // is guaranteed to arrive during this window, and a captive portal | |
1068 // error page is displayed instead of an SSL interstitial. | |
1069 SSLErrorHandler::SetInterstitialDisplayDelayForTest( | |
1070 base::TimeDelta::FromHours(1)); | |
981 } | 1071 } |
982 | 1072 |
983 void CaptivePortalBrowserTest::TearDownOnMainThread() { | 1073 void CaptivePortalBrowserTest::TearDownOnMainThread() { |
984 // No test should have a captive portal check pending on quit. | 1074 // No test should have a captive portal check pending on quit. |
985 EXPECT_FALSE(CheckPending(browser())); | 1075 EXPECT_FALSE(CheckPending(browser())); |
986 } | 1076 } |
987 | 1077 |
988 void CaptivePortalBrowserTest::EnableCaptivePortalDetection( | 1078 void CaptivePortalBrowserTest::EnableCaptivePortalDetection( |
989 Profile* profile, bool enabled) { | 1079 Profile* profile, bool enabled) { |
990 profile->GetPrefs()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); | 1080 profile->GetPrefs()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); |
991 } | 1081 } |
992 | 1082 |
1083 void CaptivePortalBrowserTest::RespondToProbeRequests(bool enabled) { | |
1084 if (enabled) { | |
1085 EXPECT_EQ(CaptivePortalService::IGNORE_REQUESTS_FOR_TESTING, | |
1086 CaptivePortalService::get_state_for_testing()); | |
1087 CaptivePortalService::set_state_for_testing( | |
1088 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); | |
1089 } else { | |
1090 EXPECT_EQ(CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING, | |
1091 CaptivePortalService::get_state_for_testing()); | |
1092 CaptivePortalService::set_state_for_testing( | |
1093 CaptivePortalService::IGNORE_REQUESTS_FOR_TESTING); | |
1094 } | |
1095 } | |
1096 | |
993 void CaptivePortalBrowserTest::SetUpCaptivePortalService(Profile* profile, | 1097 void CaptivePortalBrowserTest::SetUpCaptivePortalService(Profile* profile, |
994 const GURL& test_url) { | 1098 const GURL& test_url) { |
995 CaptivePortalService* captive_portal_service = | 1099 CaptivePortalService* captive_portal_service = |
996 CaptivePortalServiceFactory::GetForProfile(profile); | 1100 CaptivePortalServiceFactory::GetForProfile(profile); |
997 captive_portal_service->set_test_url(test_url); | 1101 captive_portal_service->set_test_url(test_url); |
998 | 1102 |
999 // Don't use any non-zero timers. Timers are checked in unit tests. | 1103 // Don't use any non-zero timers. Timers are checked in unit tests. |
1000 CaptivePortalService::RecheckPolicy* recheck_policy = | 1104 CaptivePortalService::RecheckPolicy* recheck_policy = |
1001 &captive_portal_service->recheck_policy(); | 1105 &captive_portal_service->recheck_policy(); |
1002 recheck_policy->initial_backoff_no_portal_ms = 0; | 1106 recheck_policy->initial_backoff_no_portal_ms = 0; |
1003 recheck_policy->initial_backoff_portal_ms = 0; | 1107 recheck_policy->initial_backoff_portal_ms = 0; |
1004 recheck_policy->backoff_policy.maximum_backoff_ms = 0; | 1108 recheck_policy->backoff_policy.maximum_backoff_ms = 0; |
1005 } | 1109 } |
1006 | 1110 |
1007 bool CaptivePortalBrowserTest::CheckPending(Browser* browser) { | 1111 bool CaptivePortalBrowserTest::CheckPending(Browser* browser) { |
1008 CaptivePortalService* captive_portal_service = | 1112 CaptivePortalService* captive_portal_service = |
1009 CaptivePortalServiceFactory::GetForProfile(browser->profile()); | 1113 CaptivePortalServiceFactory::GetForProfile(browser->profile()); |
1010 | 1114 |
1011 return captive_portal_service->DetectionInProgress() || | 1115 return captive_portal_service->DetectionInProgress() || |
1012 captive_portal_service->TimerRunning(); | 1116 captive_portal_service->TimerRunning(); |
1013 } | 1117 } |
1014 | 1118 |
1119 const void* CaptivePortalBrowserTest::GetInterstitialType( | |
1120 WebContents* contents) const { | |
1121 if (!contents->ShowingInterstitialPage()) | |
1122 return NULL; | |
1123 SecurityInterstitialPage* blocking_page = | |
1124 static_cast<SecurityInterstitialPage*>( | |
1125 contents->GetInterstitialPage()->GetDelegateForTesting()); | |
1126 DCHECK(blocking_page); | |
1127 return blocking_page->GetTypeForTesting(); | |
1128 } | |
1129 | |
1015 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( | 1130 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( |
1016 WebContents* web_contents) const { | 1131 WebContents* web_contents) const { |
1017 return GetTabReloader(web_contents)->state(); | 1132 return GetTabReloader(web_contents)->state(); |
1018 } | 1133 } |
1019 | 1134 |
1020 CaptivePortalTabReloader::State | 1135 CaptivePortalTabReloader::State |
1021 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, | 1136 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, |
1022 int index) const { | 1137 int index) const { |
1023 return GetStateOfTabReloader( | 1138 return GetStateOfTabReloader( |
1024 browser->tab_strip_model()->GetWebContentsAt(index)); | 1139 browser->tab_strip_model()->GetWebContentsAt(index)); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 | 1352 |
1238 // Reset the load time to be large, so the timer won't trigger on a reload. | 1353 // Reset the load time to be large, so the timer won't trigger on a reload. |
1239 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1354 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1240 } | 1355 } |
1241 | 1356 |
1242 void CaptivePortalBrowserTest::FastTimeoutBehindCaptivePortal( | 1357 void CaptivePortalBrowserTest::FastTimeoutBehindCaptivePortal( |
1243 Browser* browser, | 1358 Browser* browser, |
1244 bool expect_open_login_tab) { | 1359 bool expect_open_login_tab) { |
1245 FastErrorBehindCaptivePortal(browser, | 1360 FastErrorBehindCaptivePortal(browser, |
1246 expect_open_login_tab, | 1361 expect_open_login_tab, |
1247 GURL(kMockHttpsQuickTimeoutUrl)); | 1362 GURL(kMockHttpsQuickTimeoutUrl), |
1363 false); | |
1248 } | 1364 } |
1249 | 1365 |
1250 void CaptivePortalBrowserTest::FastErrorBehindCaptivePortal( | 1366 void CaptivePortalBrowserTest::FastErrorBehindCaptivePortal( |
1251 Browser* browser, | 1367 Browser* browser, |
1252 bool expect_open_login_tab, | 1368 bool expect_open_login_tab, |
1253 const GURL& error_url) { | 1369 const GURL& error_url, |
1370 bool delay_portal_response_until_interstital) { | |
1254 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1371 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
1255 // Calling this on a tab that's waiting for a load to manually be timed out | 1372 // Calling this on a tab that's waiting for a load to manually be timed out |
1256 // will result in a hang. | 1373 // will result in a hang. |
1257 ASSERT_FALSE(tab_strip_model->GetActiveWebContents()->IsLoading()); | 1374 ASSERT_FALSE(tab_strip_model->GetActiveWebContents()->IsLoading()); |
1258 | 1375 |
1259 // Set the load time to be large, so the timer won't trigger. The value is | 1376 // Set the load time to be large, so the timer won't trigger. The value is |
1260 // not restored at the end of the function. | 1377 // not restored at the end of the function. |
1261 CaptivePortalTabReloader* tab_reloader = | 1378 CaptivePortalTabReloader* tab_reloader = |
1262 GetTabReloader(tab_strip_model->GetActiveWebContents()); | 1379 GetTabReloader(tab_strip_model->GetActiveWebContents()); |
1263 ASSERT_TRUE(tab_reloader); | 1380 ASSERT_TRUE(tab_reloader); |
1264 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1381 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1265 | 1382 |
1266 // Number of tabs expected to be open after the captive portal checks | 1383 // Number of tabs expected to be open after the captive portal checks |
1267 // have completed. | 1384 // have completed. |
1268 int initial_tab_count = tab_strip_model->count(); | 1385 int initial_tab_count = tab_strip_model->count(); |
1269 int initial_active_index = tab_strip_model->active_index(); | 1386 int initial_active_index = tab_strip_model->active_index(); |
1270 int initial_loading_tabs = NumLoadingTabs(); | 1387 int initial_loading_tabs = NumLoadingTabs(); |
1271 int expected_broken_tabs = NumBrokenTabs(); | 1388 int expected_broken_tabs = NumBrokenTabs(); |
1272 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != | 1389 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != |
1273 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())) { | 1390 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())) { |
1274 ++expected_broken_tabs; | 1391 ++expected_broken_tabs; |
1275 } | 1392 } |
1276 | 1393 |
1394 CaptivePortalService* captive_portal_service = | |
1395 CaptivePortalServiceFactory::GetForProfile(browser->profile()); | |
1396 if (delay_portal_response_until_interstital) | |
1397 RespondToProbeRequests(false); | |
1398 | |
1277 MultiNavigationObserver navigation_observer; | 1399 MultiNavigationObserver navigation_observer; |
1278 CaptivePortalObserver portal_observer(browser->profile()); | 1400 CaptivePortalObserver portal_observer(browser->profile()); |
1279 ui_test_utils::NavigateToURLWithDisposition(browser, | 1401 ui_test_utils::NavigateToURLWithDisposition(browser, |
1280 error_url, | 1402 error_url, |
1281 CURRENT_TAB, | 1403 CURRENT_TAB, |
1282 ui_test_utils::BROWSER_TEST_NONE); | 1404 ui_test_utils::BROWSER_TEST_NONE); |
1405 | |
1406 if (delay_portal_response_until_interstital) { | |
1407 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1408 GetStateOfTabReloaderAt(browser, initial_active_index)); | |
1409 // Once the interstitial is attached, probe for captive portal. | |
1410 WaitForInterstitialAttach(tab_strip_model->GetActiveWebContents()); | |
1411 RespondToProbeRequests(true); | |
1412 captive_portal_service->DetectCaptivePortal(); | |
1413 } | |
1414 | |
1283 portal_observer.WaitForResults(1); | 1415 portal_observer.WaitForResults(1); |
1284 | 1416 |
1285 if (expect_open_login_tab) { | 1417 if (expect_open_login_tab) { |
1286 navigation_observer.WaitForNavigations(2); | 1418 navigation_observer.WaitForNavigations(2); |
1287 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count()); | 1419 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count()); |
1288 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index()); | 1420 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index()); |
1289 // Make sure that the originally active tab and the captive portal tab have | 1421 // Make sure that the originally active tab and the captive portal tab have |
1290 // each loaded once. | 1422 // each loaded once. |
1291 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1423 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1292 tab_strip_model->GetWebContentsAt(initial_active_index))); | 1424 tab_strip_model->GetWebContentsAt(initial_active_index))); |
(...skipping 15 matching lines...) Expand all Loading... | |
1308 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); | 1440 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); |
1309 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | 1441 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
1310 portal_observer.captive_portal_result()); | 1442 portal_observer.captive_portal_result()); |
1311 EXPECT_EQ(1, portal_observer.num_results_received()); | 1443 EXPECT_EQ(1, portal_observer.num_results_received()); |
1312 EXPECT_FALSE(CheckPending(browser)); | 1444 EXPECT_FALSE(CheckPending(browser)); |
1313 | 1445 |
1314 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1446 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1315 GetStateOfTabReloaderAt(browser, initial_active_index)); | 1447 GetStateOfTabReloaderAt(browser, initial_active_index)); |
1316 } | 1448 } |
1317 | 1449 |
1450 void CaptivePortalBrowserTest::FastErrorWithInterstitialTimer( | |
1451 Browser* browser, | |
1452 const GURL& cert_error_url) { | |
1453 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
1454 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
1455 | |
1456 // Disable captive portal checks indefinitely. | |
1457 RespondToProbeRequests(false); | |
1458 | |
1459 content::WindowedNotificationObserver signal( | |
1460 chrome::NOTIFICATION_SSL_INTERSTITIAL_TIMER_FIRED, | |
1461 content::Source<WebContents>(broken_tab_contents)); | |
1462 ui_test_utils::NavigateToURLWithDisposition(browser, | |
1463 cert_error_url, | |
1464 CURRENT_TAB, | |
1465 ui_test_utils::BROWSER_TEST_NONE); | |
1466 signal.Wait(); | |
1467 ASSERT_EQ(broken_tab_contents, | |
1468 content::Source<WebContents>(signal.source()).ptr()); | |
1469 | |
1470 // The tab should be in loading state, waiting for the interstitial timer to | |
1471 // expire or a captive portal result to arrive. Since captive portal checks | |
1472 // are disabled and timer set to expire after a very long time, the tab should | |
1473 // hang indefinitely. | |
1474 EXPECT_TRUE(broken_tab_contents->IsLoading()); | |
1475 EXPECT_EQ(1, NumLoadingTabs()); | |
1476 } | |
1477 | |
1318 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, | 1478 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, |
1319 int num_loading_tabs, | 1479 int num_loading_tabs, |
1320 int num_timed_out_tabs) { | 1480 int num_timed_out_tabs) { |
1321 MultiNavigationObserver navigation_observer; | 1481 MultiNavigationObserver navigation_observer; |
1322 CaptivePortalObserver portal_observer(browser->profile()); | 1482 CaptivePortalObserver portal_observer(browser->profile()); |
1323 | 1483 |
1324 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1484 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
1325 int initial_tab_count = tab_strip_model->count(); | 1485 int initial_tab_count = tab_strip_model->count(); |
1326 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); | 1486 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); |
1327 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); | 1487 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1400 EXPECT_EQ(initial_tab_count, tab_strip_model->count()); | 1560 EXPECT_EQ(initial_tab_count, tab_strip_model->count()); |
1401 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1561 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1402 GetStateOfTabReloaderAt(browser, login_tab_index)); | 1562 GetStateOfTabReloaderAt(browser, login_tab_index)); |
1403 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | 1563 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); |
1404 | 1564 |
1405 // Make sure there were no unexpected navigations of the login tab. | 1565 // Make sure there were no unexpected navigations of the login tab. |
1406 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1566 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1407 tab_strip_model->GetWebContentsAt(login_tab_index))); | 1567 tab_strip_model->GetWebContentsAt(login_tab_index))); |
1408 } | 1568 } |
1409 | 1569 |
1570 void CaptivePortalBrowserTest::LoginCertError(Browser* browser) { | |
1571 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | |
1572 | |
1573 MultiNavigationObserver navigation_observer; | |
1574 CaptivePortalObserver portal_observer(browser->profile()); | |
1575 | |
1576 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
1577 | |
1578 // Verify that the login page is on top. | |
1579 int login_tab_index = tab_strip_model->active_index(); | |
1580 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1581 GetStateOfTabReloaderAt(browser, login_tab_index)); | |
1582 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | |
1583 | |
1584 // Trigger a navigation. | |
1585 content::RenderFrameHost* render_frame_host = | |
1586 tab_strip_model->GetActiveWebContents()->GetMainFrame(); | |
1587 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); | |
1588 | |
1589 // The captive portal tab navigation will trigger a captive portal check, | |
1590 // and reloading the original tab will bring up the interstitial page again, | |
1591 // triggering a second captive portal check. | |
1592 portal_observer.WaitForResults(2); | |
1593 | |
1594 // Wait for both tabs to finish loading. | |
1595 navigation_observer.WaitForNavigations(2); | |
1596 EXPECT_EQ(2, portal_observer.num_results_received()); | |
1597 EXPECT_FALSE(CheckPending(browser)); | |
1598 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED, | |
1599 portal_observer.captive_portal_result()); | |
1600 | |
1601 // Check state of tabs. While the first tab is still displaying an | |
1602 // interstitial page, since no portal was found, it should be in STATE_NONE, | |
1603 // as should the login tab. | |
1604 ASSERT_EQ(2, tab_strip_model->count()); | |
1605 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1606 GetStateOfTabReloaderAt(browser, 0)); | |
1607 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1608 GetStateOfTabReloaderAt(browser, login_tab_index)); | |
1609 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | |
1610 | |
1611 // Make sure only one navigation was for the login tab. | |
1612 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | |
1613 tab_strip_model->GetWebContentsAt(login_tab_index))); | |
1614 } | |
1615 | |
1410 void CaptivePortalBrowserTest::FailLoadsAfterLogin(Browser* browser, | 1616 void CaptivePortalBrowserTest::FailLoadsAfterLogin(Browser* browser, |
1411 int num_loading_tabs) { | 1617 int num_loading_tabs) { |
1412 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); | 1618 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); |
1413 ASSERT_EQ(num_loading_tabs, NumNeedReloadTabs()); | 1619 ASSERT_EQ(num_loading_tabs, NumNeedReloadTabs()); |
1414 EXPECT_EQ(0, NumBrokenTabs()); | 1620 EXPECT_EQ(0, NumBrokenTabs()); |
1415 | 1621 |
1416 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1622 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
1417 int initial_num_tabs = tab_strip_model->count(); | 1623 int initial_num_tabs = tab_strip_model->count(); |
1418 int initial_active_tab = tab_strip_model->active_index(); | 1624 int initial_active_tab = tab_strip_model->active_index(); |
1419 | 1625 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1698 } | 1904 } |
1699 | 1905 |
1700 // Checks the unlikely case that the tab times out before the timer triggers. | 1906 // Checks the unlikely case that the tab times out before the timer triggers. |
1701 // This most likely won't happen, but should still work: | 1907 // This most likely won't happen, but should still work: |
1702 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { | 1908 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { |
1703 FastTimeoutBehindCaptivePortal(browser(), true); | 1909 FastTimeoutBehindCaptivePortal(browser(), true); |
1704 Login(browser(), 0, 1); | 1910 Login(browser(), 0, 1); |
1705 } | 1911 } |
1706 | 1912 |
1707 // A cert error triggers a captive portal check and results in opening a login | 1913 // A cert error triggers a captive portal check and results in opening a login |
1708 // tab. The user then logs in and the page with the error is reloaded. | 1914 // tab. |
1709 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { | 1915 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
1710 // Need an HTTP TestServer to handle a dynamically created server redirect. | 1916 ShowCaptivePortalInterstitialOnCertError) { |
1711 ASSERT_TRUE(test_server()->Start()); | |
1712 | |
1713 net::SpawnedTestServer::SSLOptions https_options; | 1917 net::SpawnedTestServer::SSLOptions https_options; |
1714 https_options.server_certificate = | 1918 https_options.server_certificate = |
1715 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 1919 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; |
1716 net::SpawnedTestServer https_server( | 1920 net::SpawnedTestServer https_server( |
1717 net::SpawnedTestServer::TYPE_HTTPS, https_options, | 1921 net::SpawnedTestServer::TYPE_HTTPS, https_options, |
1718 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1922 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1719 ASSERT_TRUE(https_server.Start()); | 1923 ASSERT_TRUE(https_server.Start()); |
1720 | 1924 |
1721 // The path does not matter. | 1925 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
1722 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 1926 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
1927 | |
1928 // The path does not matter. | |
1929 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
1930 int cert_error_tab_index = tab_strip_model->active_index(); | |
1723 // The interstitial should trigger a captive portal check when it opens, just | 1931 // The interstitial should trigger a captive portal check when it opens, just |
1724 // like navigating to kMockHttpsQuickTimeoutUrl. | 1932 // like navigating to kMockHttpsQuickTimeoutUrl. |
1725 FastErrorBehindCaptivePortal(browser(), true, cert_error_url); | 1933 FastErrorBehindCaptivePortal(browser(), true, cert_error_url, false); |
1726 | 1934 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting, |
1727 // Simulate logging in. Can't use Login() because the interstitial tab looks | 1935 GetInterstitialType(broken_tab_contents)); |
1728 // like a cross between a hung tab (Load was never committed) and a tab at an | 1936 |
1729 // error page (The load was stopped). | 1937 // Switch to the interstitial and click the |Connect| button. Should switch |
1730 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | 1938 // active tab to the captive portal landing page. |
1939 int login_tab_index = tab_strip_model->active_index(); | |
1940 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | |
1941 // Wait for the interstitial to load all the JavaScript code. Otherwise, | |
1942 // trying to click on a button will fail. | |
1943 EXPECT_TRUE(WaitForInterstitialReady( | |
1944 broken_tab_contents->GetInterstitialPage())); | |
1945 content::RenderViewHost* rvh = | |
1946 broken_tab_contents->GetInterstitialPage()->GetRenderViewHostForTesting(); | |
1947 const char kClickConnectButtonJS[] = | |
1948 "document.getElementById('primary-button').click();"; | |
1949 EXPECT_TRUE( | |
1950 content::ExecuteScript(rvh->GetMainFrame(), kClickConnectButtonJS)); | |
1951 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | |
1952 | |
1953 // For completeness, close the login tab and try clicking |Connect| again. | |
1954 // A new login tab should open. | |
1955 EXPECT_EQ(1, login_tab_index); | |
1956 content::WebContentsDestroyedWatcher destroyed_watcher( | |
1957 tab_strip_model->GetActiveWebContents()); | |
1958 EXPECT_TRUE( | |
1959 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); | |
1960 destroyed_watcher.Wait(); | |
1731 MultiNavigationObserver navigation_observer; | 1961 MultiNavigationObserver navigation_observer; |
1962 EXPECT_TRUE( | |
1963 content::ExecuteScript(rvh->GetMainFrame(), kClickConnectButtonJS)); | |
1964 navigation_observer.WaitForNavigations(1); | |
1965 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | |
1966 | |
1967 LoginCertError(browser()); | |
1968 | |
1969 // Once logged in, broken tab should reload and display the SSL interstitial. | |
1970 WaitForInterstitialAttach(broken_tab_contents); | |
1971 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | |
1972 | |
1973 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
1974 GetInterstitialType(tab_strip_model->GetActiveWebContents())); | |
1975 | |
1976 // Trigger another captive portal check while the SSL interstitial is showing. | |
1977 // At this point the user is logged in to the captive portal, so the captive | |
1978 // portal interstitial shouldn't get recreated. | |
1732 CaptivePortalObserver portal_observer(browser()->profile()); | 1979 CaptivePortalObserver portal_observer(browser()->profile()); |
1733 | 1980 CaptivePortalService* captive_portal_service = |
1734 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 1981 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); |
1735 content::RenderFrameHost* render_frame_host = | 1982 captive_portal_service->DetectCaptivePortal(); |
1736 tab_strip_model->GetActiveWebContents()->GetMainFrame(); | 1983 portal_observer.WaitForResults(1); |
1737 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); | 1984 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
1738 | 1985 GetInterstitialType(broken_tab_contents)); |
1739 // The captive portal tab navigation will trigger a captive portal check, | 1986 |
1740 // and reloading the original tab will bring up the interstitial page again, | 1987 // A captive portal appears. Trigger a final captive portal check. The |
1741 // triggering a second captive portal check. | 1988 // captive portal interstitial should still not get recreated. |
1742 portal_observer.WaitForResults(2); | 1989 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(true); |
1743 | 1990 CaptivePortalObserver final_portal_observer(browser()->profile()); |
1744 // Wait for both tabs to finish loading. | 1991 captive_portal_service->DetectCaptivePortal(); |
1745 navigation_observer.WaitForNavigations(2); | 1992 final_portal_observer.WaitForResults(1); |
1746 EXPECT_EQ(2, portal_observer.num_results_received()); | 1993 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
1747 EXPECT_FALSE(CheckPending(browser())); | 1994 GetInterstitialType(broken_tab_contents)); |
1748 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED, | 1995 } |
1749 portal_observer.captive_portal_result()); | 1996 |
1750 | 1997 // Tests this scenario: |
1751 // Check state of tabs. While the first tab is still displaying an | 1998 // - Portal probe requests are ignored, so that no captive portal result can |
1752 // interstitial page, since no portal was found, it should be in STATE_NONE, | 1999 // arrive. |
1753 // as should the login tab. | 2000 // - A cert error triggers an interstitial timer with a very long timeout. |
1754 ASSERT_EQ(2, tab_strip_model->count()); | 2001 // - No captive portal results arrive, causing the tab to appear as loading |
1755 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2002 // indefinitely (because probe requests are ignored). |
1756 GetStateOfTabReloaderAt(browser(), 0)); | 2003 // - Stopping the page load shouldn't result in any interstitials. |
1757 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(1))); | 2004 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
1758 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2005 InterstitialTimerStopNavigationWhileLoading) { |
1759 GetStateOfTabReloaderAt(browser(), 1)); | 2006 net::SpawnedTestServer::SSLOptions https_options; |
1760 | 2007 https_options.server_certificate = |
1761 // Make sure only one navigation was for the login tab. | 2008 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; |
1762 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 2009 net::SpawnedTestServer https_server( |
1763 tab_strip_model->GetWebContentsAt(1))); | 2010 net::SpawnedTestServer::TYPE_HTTPS, https_options, |
2011 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2012 ASSERT_TRUE(https_server.Start()); | |
2013 // The path does not matter. | |
2014 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2015 | |
2016 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2017 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2018 | |
2019 CaptivePortalObserver portal_observer1(browser()->profile()); | |
2020 FastErrorWithInterstitialTimer(browser(), cert_error_url); | |
2021 | |
2022 // Page appears loading. Stop the navigation. There should be no interstitial. | |
2023 MultiNavigationObserver test_navigation_observer; | |
2024 broken_tab_contents->Stop(); | |
2025 test_navigation_observer.WaitForNavigations(1); | |
2026 | |
2027 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2028 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2029 EXPECT_EQ(0, portal_observer1.num_results_received()); | |
2030 EXPECT_EQ(0, NumLoadingTabs()); | |
2031 EXPECT_FALSE(CheckPending(browser())); | |
2032 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2033 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2034 GetStateOfTabReloaderAt(browser(), 0)); | |
2035 | |
2036 // Re-enable captive portal checks and fire one. The result should be ignored. | |
2037 RespondToProbeRequests(true); | |
2038 CaptivePortalObserver portal_observer2(browser()->profile()); | |
2039 CaptivePortalService* captive_portal_service = | |
2040 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | |
2041 captive_portal_service->DetectCaptivePortal(); | |
2042 portal_observer2.WaitForResults(1); | |
2043 | |
2044 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2045 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2046 EXPECT_EQ(1, portal_observer2.num_results_received()); | |
2047 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | |
2048 portal_observer2.captive_portal_result()); | |
2049 EXPECT_EQ(0, NumLoadingTabs()); | |
2050 EXPECT_FALSE(CheckPending(browser())); | |
2051 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2052 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2053 GetStateOfTabReloaderAt(browser(), 0)); | |
2054 } | |
2055 | |
2056 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
2057 // result is the same. (i.e. page load stops, no interstitials shown) | |
2058 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2059 InterstitialTimerReloadWhileLoading) { | |
2060 net::SpawnedTestServer::SSLOptions https_options; | |
2061 https_options.server_certificate = | |
2062 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2063 net::SpawnedTestServer https_server( | |
2064 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2065 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2066 ASSERT_TRUE(https_server.Start()); | |
2067 // The path does not matter. | |
2068 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2069 | |
2070 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2071 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2072 | |
2073 CaptivePortalObserver portal_observer(browser()->profile()); | |
2074 FastErrorWithInterstitialTimer(browser(), cert_error_url); | |
2075 | |
2076 // Page appears loading. Reloading should cancel the navigation and there | |
2077 // should be no interstitial. | |
2078 MultiNavigationObserver test_navigation_observer; | |
2079 chrome::Reload(browser(), CURRENT_TAB); | |
2080 test_navigation_observer.WaitForNavigations(2); | |
2081 | |
2082 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2083 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2084 EXPECT_EQ(0, portal_observer.num_results_received()); | |
2085 EXPECT_EQ(2, test_navigation_observer.num_navigations()); | |
2086 EXPECT_EQ(0, NumLoadingTabs()); | |
2087 EXPECT_FALSE(CheckPending(browser())); | |
2088 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2089 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2090 GetStateOfTabReloaderAt(browser(), 0)); | |
2091 | |
2092 // Re-enable captive portal checks and fire one. The result should be ignored. | |
2093 RespondToProbeRequests(true); | |
mmenke
2014/12/17 18:45:06
Think that's worth a comment in the test.
meacer
2014/12/17 23:16:38
Done.
| |
2094 CaptivePortalObserver portal_observer2(browser()->profile()); | |
2095 CaptivePortalService* captive_portal_service = | |
2096 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | |
2097 captive_portal_service->DetectCaptivePortal(); | |
2098 portal_observer2.WaitForResults(1); | |
2099 | |
2100 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2101 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2102 EXPECT_EQ(1, portal_observer2.num_results_received()); | |
2103 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | |
2104 portal_observer2.captive_portal_result()); | |
2105 EXPECT_EQ(0, NumLoadingTabs()); | |
2106 EXPECT_FALSE(CheckPending(browser())); | |
2107 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2108 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2109 GetStateOfTabReloaderAt(browser(), 0)); | |
2110 } | |
2111 | |
2112 // Same as above, but instead of reloading, the page is navigated away. The new | |
2113 // page should load, and no interstitials should be shown. | |
2114 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2115 InterstitialTimerNavigateAwayWhileLoading) { | |
2116 net::SpawnedTestServer::SSLOptions https_options; | |
2117 https_options.server_certificate = | |
2118 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2119 net::SpawnedTestServer https_server( | |
2120 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2121 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2122 ASSERT_TRUE(https_server.Start()); | |
2123 // The path does not matter. | |
2124 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2125 | |
2126 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2127 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2128 | |
2129 CaptivePortalObserver portal_observer(browser()->profile()); | |
2130 FastErrorWithInterstitialTimer(browser(), cert_error_url); | |
2131 | |
2132 // Page appears loading. Navigating away shouldn't result in any interstitial. | |
2133 // Can't use ui_test_utils::NavigateToURLWithDisposition because it waits for | |
2134 // a load stop notification before starting a new navigation. | |
2135 MultiNavigationObserver test_navigation_observer; | |
2136 browser()->OpenURL(content::OpenURLParams( | |
2137 URLRequestMockHTTPJob::GetMockUrl( | |
2138 base::FilePath(FILE_PATH_LITERAL("title2.html"))), | |
2139 content::Referrer(), | |
2140 CURRENT_TAB, | |
2141 ui::PAGE_TRANSITION_TYPED, false)); | |
2142 // Expect two navigations: First one for stopping the hanging page, second one | |
2143 // for completing the load of the above navigation. | |
2144 test_navigation_observer.WaitForNavigations(2); | |
2145 | |
2146 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2147 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2148 EXPECT_EQ(0, portal_observer.num_results_received()); | |
2149 EXPECT_EQ(2, test_navigation_observer.num_navigations()); | |
2150 EXPECT_EQ(0, NumLoadingTabs()); | |
2151 EXPECT_FALSE(CheckPending(browser())); | |
2152 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2153 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2154 GetStateOfTabReloaderAt(browser(), 0)); | |
2155 | |
2156 // Re-enable captive portal checks and fire one. The result should be ignored. | |
2157 RespondToProbeRequests(true); | |
2158 CaptivePortalObserver portal_observer2(browser()->profile()); | |
2159 CaptivePortalService* captive_portal_service = | |
2160 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | |
2161 captive_portal_service->DetectCaptivePortal(); | |
2162 portal_observer2.WaitForResults(1); | |
2163 | |
2164 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2165 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2166 EXPECT_EQ(1, portal_observer2.num_results_received()); | |
2167 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | |
2168 portal_observer2.captive_portal_result()); | |
2169 EXPECT_EQ(0, NumLoadingTabs()); | |
2170 EXPECT_FALSE(CheckPending(browser())); | |
2171 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2172 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2173 GetStateOfTabReloaderAt(browser(), 0)); | |
2174 } | |
2175 | |
2176 // A cert error triggers a captive portal check and results in opening a login | |
2177 // tab. The user then logs in and the page with the error is reloaded. | |
2178 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { | |
2179 // Need an HTTP TestServer to handle a dynamically created server redirect. | |
2180 ASSERT_TRUE(test_server()->Start()); | |
2181 | |
2182 net::SpawnedTestServer::SSLOptions https_options; | |
2183 https_options.server_certificate = | |
2184 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2185 net::SpawnedTestServer https_server( | |
2186 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2187 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2188 ASSERT_TRUE(https_server.Start()); | |
2189 | |
2190 // Set SSL interstitial delay to zero so that a captive portal result can not | |
2191 // arrive during this window, so an SSL interstitial is displayed instead | |
2192 // of a captive portal error page. | |
2193 SSLErrorHandler::SetInterstitialDisplayDelayForTest(base::TimeDelta()); | |
2194 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2195 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2196 | |
2197 // Setting the delay to zero above has a race condition: A captive portal | |
2198 // result triggered by a cert error can arrive before the SSL interstitial | |
2199 // display timer is fired, even though it's set to zero. | |
2200 // To avoid this, disable captive portal checks until the SSL interstitial is | |
2201 // displayed. Once it's displayed, enable portal checks and fire one. | |
2202 bool delay_portal_response_until_interstital = true; | |
2203 | |
2204 // The path does not matter. | |
2205 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2206 // A captive portal check is triggered in FastErrorBehindCaptivePortal. | |
2207 FastErrorBehindCaptivePortal( | |
2208 browser(), | |
2209 true, | |
2210 cert_error_url, | |
2211 delay_portal_response_until_interstital); | |
2212 | |
2213 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
2214 GetInterstitialType(broken_tab_contents)); | |
2215 | |
2216 LoginCertError(browser()); | |
1764 } | 2217 } |
1765 | 2218 |
1766 // Tries navigating both the tab that encounters an SSL timeout and the | 2219 // Tries navigating both the tab that encounters an SSL timeout and the |
1767 // login tab twice, only logging in the second time. | 2220 // login tab twice, only logging in the second time. |
1768 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginExtraNavigations) { | 2221 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginExtraNavigations) { |
1769 FastTimeoutBehindCaptivePortal(browser(), true); | 2222 FastTimeoutBehindCaptivePortal(browser(), true); |
1770 | 2223 |
1771 // Activate the timed out tab and navigate it to a timeout again. | 2224 // Activate the timed out tab and navigate it to a timeout again. |
1772 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2225 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
1773 tab_strip_model->ActivateTabAt(0, true); | 2226 tab_strip_model->ActivateTabAt(0, true); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2206 content::BrowserThread::PostTask( | 2659 content::BrowserThread::PostTask( |
2207 content::BrowserThread::IO, FROM_HERE, | 2660 content::BrowserThread::IO, FROM_HERE, |
2208 base::Bind(&AddHstsHost, | 2661 base::Bind(&AddHstsHost, |
2209 make_scoped_refptr(browser()->profile()->GetRequestContext()), | 2662 make_scoped_refptr(browser()->profile()->GetRequestContext()), |
2210 http_timeout_url.host())); | 2663 http_timeout_url.host())); |
2211 | 2664 |
2212 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); | 2665 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); |
2213 Login(browser(), 1, 0); | 2666 Login(browser(), 1, 0); |
2214 FailLoadsAfterLogin(browser(), 1); | 2667 FailLoadsAfterLogin(browser(), 1); |
2215 } | 2668 } |
2669 | |
2670 // A slow SSL load starts. The reloader triggers a captive portal check, finds a | |
2671 // captive portal. The SSL commits with a cert error, triggering another captive | |
2672 // portal check. | |
2673 // The second check finds no captive portal. The reloader triggers a reload at | |
2674 // the same time SSL error handler tries to show an interstitial. Should result | |
2675 // in an SSL interstitial. | |
2676 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2677 InterstitialTimerCertErrorAfterSlowLoad) { | |
2678 // Use a url that triggers a slow load, instead of creating an https server. | |
2679 GURL cert_error_url = GURL(kMockHttpsUrl); | |
2680 | |
2681 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2682 int broken_tab_index = tab_strip_model->active_index(); | |
2683 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2684 SlowLoadBehindCaptivePortal(browser(), true, cert_error_url, 1, 1); | |
2685 | |
2686 // No longer behind a captive portal. Committing the SSL page should trigger | |
2687 // an SSL interstitial which triggers a new captive portal check. Since there | |
2688 // is no captive portal anymore, should end up with an SSL interstitial. | |
2689 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | |
2690 | |
2691 CaptivePortalObserver portal_observer(browser()->profile()); | |
2692 MultiNavigationObserver navigation_observer; | |
2693 URLRequestTimeoutOnDemandJob::FailJobsWithCertError(1); | |
2694 navigation_observer.WaitForNavigations(1); | |
2695 | |
2696 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | |
2697 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | |
2698 | |
2699 WaitForInterstitialAttach(broken_tab_contents); | |
2700 portal_observer.WaitForResults(1); | |
2701 | |
2702 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
2703 GetInterstitialType(broken_tab_contents)); | |
2704 } | |
OLD | NEW |