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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
770 captive_portal_result_ = results->result; | 828 captive_portal_result_ = results->result; |
771 ++num_results_received_; | 829 ++num_results_received_; |
772 | 830 |
773 if (waiting_for_result_ && | 831 if (waiting_for_result_ && |
774 num_results_to_wait_for_ == num_results_received_) { | 832 num_results_to_wait_for_ == num_results_received_) { |
775 waiting_for_result_ = false; | 833 waiting_for_result_ = false; |
776 base::MessageLoop::current()->Quit(); | 834 base::MessageLoop::current()->Quit(); |
777 } | 835 } |
778 } | 836 } |
779 | 837 |
838 // This observer waits for the SSLErrorHandler to fire an interstitial timer for | |
839 // the given web contents. | |
840 class SSLInterstitialTimerObserver { | |
841 public: | |
842 explicit SSLInterstitialTimerObserver(content::WebContents* web_contents); | |
843 ~SSLInterstitialTimerObserver(); | |
844 | |
845 // Waits until the interstitial delay timer in SSLErrorHandler is fired. | |
846 void WaitForTimerFired(); | |
847 | |
848 void OnTimerFired(content::WebContents* web_contents); | |
Bernhard Bauer
2014/12/18 18:10:05
Could this be private?
meacer
2014/12/19 02:42:24
Done.
| |
849 | |
850 private: | |
851 const content::WebContents* web_contents_; | |
852 SSLErrorHandler::TimerFiredCallback callback_; | |
853 | |
854 DISALLOW_COPY_AND_ASSIGN(SSLInterstitialTimerObserver); | |
855 }; | |
856 | |
857 SSLInterstitialTimerObserver::SSLInterstitialTimerObserver( | |
858 content::WebContents* web_contents) | |
859 : web_contents_(web_contents) { | |
860 callback_ = base::Bind(&SSLInterstitialTimerObserver::OnTimerFired, | |
861 base::Unretained(this)); | |
862 SSLErrorHandler::SetInterstitialTimerFiredCallbackForTest(&callback_); | |
863 } | |
864 | |
865 SSLInterstitialTimerObserver::~SSLInterstitialTimerObserver() { | |
866 SSLErrorHandler::SetInterstitialTimerFiredCallbackForTest(NULL); | |
Bernhard Bauer
2014/12/18 18:10:05
nullptr
meacer
2014/12/19 02:42:24
Done.
| |
867 } | |
868 | |
869 void SSLInterstitialTimerObserver::WaitForTimerFired() { | |
870 content::RunMessageLoop(); | |
871 } | |
872 | |
873 void SSLInterstitialTimerObserver::OnTimerFired( | |
874 content::WebContents* web_contents) { | |
875 if (web_contents_ == web_contents) | |
876 base::MessageLoopForUI::current()->Quit(); | |
Bernhard Bauer
2014/12/18 18:10:05
Don't directly quit message loops. Instead, use a
meacer
2014/12/19 02:42:24
I was following the pattern in this file. Done.
| |
877 } | |
878 | |
780 // Adds an HSTS rule for |host|, so that all HTTP requests sent to it will | 879 // Adds an HSTS rule for |host|, so that all HTTP requests sent to it will |
781 // be switched to HTTPS requests. | 880 // be switched to HTTPS requests. |
782 void AddHstsHost(net::URLRequestContextGetter* context_getter, | 881 void AddHstsHost(net::URLRequestContextGetter* context_getter, |
783 const std::string& host) { | 882 const std::string& host) { |
784 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 883 ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
785 net::TransportSecurityState* transport_security_state = | 884 net::TransportSecurityState* transport_security_state = |
786 context_getter->GetURLRequestContext()->transport_security_state(); | 885 context_getter->GetURLRequestContext()->transport_security_state(); |
787 if (!transport_security_state) { | 886 if (!transport_security_state) { |
788 FAIL(); | 887 FAIL(); |
789 return; | 888 return; |
(...skipping 11 matching lines...) Expand all Loading... | |
801 CaptivePortalBrowserTest(); | 900 CaptivePortalBrowserTest(); |
802 | 901 |
803 // InProcessBrowserTest: | 902 // InProcessBrowserTest: |
804 void SetUpOnMainThread() override; | 903 void SetUpOnMainThread() override; |
805 void TearDownOnMainThread() override; | 904 void TearDownOnMainThread() override; |
806 | 905 |
807 // Sets the captive portal checking preference. Does not affect the command | 906 // Sets the captive portal checking preference. Does not affect the command |
808 // line flag, which is set in SetUpCommandLine. | 907 // line flag, which is set in SetUpCommandLine. |
809 void EnableCaptivePortalDetection(Profile* profile, bool enabled); | 908 void EnableCaptivePortalDetection(Profile* profile, bool enabled); |
810 | 909 |
910 // Enables or disables actual captive portal probes. Should only be called | |
911 // after captive portal service setup is done. When disabled, probe requests | |
912 // are silently ignored, never receiving a response. | |
913 void RespondToProbeRequests(bool enabled); | |
914 | |
811 // Sets up the captive portal service for the given profile so that | 915 // Sets up the captive portal service for the given profile so that |
812 // all checks go to |test_url|. Also disables all timers. | 916 // all checks go to |test_url|. Also disables all timers. |
813 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); | 917 void SetUpCaptivePortalService(Profile* profile, const GURL& test_url); |
814 | 918 |
815 // Returns true if |browser|'s profile is currently running a captive portal | 919 // Returns true if |browser|'s profile is currently running a captive portal |
816 // check. | 920 // check. |
817 bool CheckPending(Browser* browser); | 921 bool CheckPending(Browser* browser); |
818 | 922 |
923 // Returns the type of the interstitial being shown. | |
924 const void* GetInterstitialType(WebContents* contents) const; | |
925 | |
819 // Returns the CaptivePortalTabReloader::State of |web_contents|. | 926 // Returns the CaptivePortalTabReloader::State of |web_contents|. |
820 CaptivePortalTabReloader::State GetStateOfTabReloader( | 927 CaptivePortalTabReloader::State GetStateOfTabReloader( |
821 WebContents* web_contents) const; | 928 WebContents* web_contents) const; |
822 | 929 |
823 // Returns the CaptivePortalTabReloader::State of the indicated tab. | 930 // Returns the CaptivePortalTabReloader::State of the indicated tab. |
824 CaptivePortalTabReloader::State GetStateOfTabReloaderAt(Browser* browser, | 931 CaptivePortalTabReloader::State GetStateOfTabReloaderAt(Browser* browser, |
825 int index) const; | 932 int index) const; |
826 | 933 |
827 // Returns the number of tabs with the given state, across all profiles. | 934 // Returns the number of tabs with the given state, across all profiles. |
828 int NumTabsWithState(CaptivePortalTabReloader::State state) const; | 935 int NumTabsWithState(CaptivePortalTabReloader::State state) const; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 | 997 |
891 // Just like SlowLoadBehindCaptivePortal, except the navigated tab has | 998 // Just like SlowLoadBehindCaptivePortal, except the navigated tab has |
892 // a connection timeout rather having its time trigger, and the function | 999 // a connection timeout rather having its time trigger, and the function |
893 // waits until that timeout occurs. | 1000 // waits until that timeout occurs. |
894 void FastTimeoutBehindCaptivePortal(Browser* browser, | 1001 void FastTimeoutBehindCaptivePortal(Browser* browser, |
895 bool expect_open_login_tab); | 1002 bool expect_open_login_tab); |
896 | 1003 |
897 // Much as above, but accepts a URL parameter and can be used for errors that | 1004 // 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 | 1005 // trigger captive portal checks other than timeouts. |error_url| should |
899 // result in an error rather than hanging. | 1006 // result in an error rather than hanging. |
900 void FastErrorBehindCaptivePortal(Browser* browser, | 1007 // If |delay_portal_response_until_interstital| is true, captive portal probe |
901 bool expect_open_login_tab, | 1008 // request are ignored until the interstitial is shown, at which point a |
902 const GURL& error_url); | 1009 // captive portal result is sent. This allows testing in conjunction with the |
1010 // certificate error interstitial. | |
1011 void FastErrorBehindCaptivePortal( | |
1012 Browser* browser, | |
1013 bool expect_open_login_tab, | |
1014 const GURL& error_url, | |
1015 bool delay_portal_response_until_interstital); | |
1016 | |
1017 // Navigates the active tab to an SSL error page which triggers an | |
1018 // interstitial timer. Also disables captive portal checks indefinitely, so | |
1019 // the page appears to be hanging. | |
1020 void FastErrorWithInterstitialTimer(Browser* browser, | |
1021 const GURL& cert_error_url); | |
903 | 1022 |
904 // Navigates the login tab without logging in. The login tab must be the | 1023 // 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. | 1024 // 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 | 1025 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks |
907 // that nothing has gone wrong prior to the function call. | 1026 // that nothing has gone wrong prior to the function call. |
908 void NavigateLoginTab(Browser* browser, | 1027 void NavigateLoginTab(Browser* browser, |
909 int num_loading_tabs, | 1028 int num_loading_tabs, |
910 int num_timed_out_tabs); | 1029 int num_timed_out_tabs); |
911 | 1030 |
912 // Simulates a login by updating the URLRequestMockCaptivePortalJob's | 1031 // Simulates a login by updating the URLRequestMockCaptivePortalJob's |
913 // behind captive portal state, and navigating the login tab. Waits for | 1032 // behind captive portal state, and navigating the login tab. Waits for |
914 // all broken but not loading tabs to be reloaded. | 1033 // all broken but not loading tabs to be reloaded. |
915 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks | 1034 // |num_loading_tabs| and |num_timed_out_tabs| are used as extra checks |
916 // that nothing has gone wrong prior to the function call. | 1035 // that nothing has gone wrong prior to the function call. |
917 void Login(Browser* browser, int num_loading_tabs, int num_timed_out_tabs); | 1036 void Login(Browser* browser, int num_loading_tabs, int num_timed_out_tabs); |
918 | 1037 |
1038 // Simulates a login when the broken tab shows an SSL or captive portal | |
1039 // interstitial. Can't use Login() in those cases because the interstitial | |
1040 // tab looks like a cross between a hung tab (Load was never committed) and a | |
1041 // tab at an error page (The load was stopped). | |
1042 void LoginCertError(Browser* browser); | |
1043 | |
919 // Makes the slow SSL loads of all active tabs time out at once, and waits for | 1044 // 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. | 1045 // 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. | 1046 // There should be no timed out tabs when this is called. |
922 void FailLoadsAfterLogin(Browser* browser, int num_loading_tabs); | 1047 void FailLoadsAfterLogin(Browser* browser, int num_loading_tabs); |
923 | 1048 |
924 // Makes the slow SSL loads of all active tabs time out at once, and waits for | 1049 // 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 | 1050 // 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. | 1051 // active tab. There should be no timed out tabs when this is called. |
927 void FailLoadsWithoutLogin(Browser* browser, int num_loading_tabs); | 1052 void FailLoadsWithoutLogin(Browser* browser, int num_loading_tabs); |
928 | 1053 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
971 CaptivePortalService::get_state_for_testing()); | 1096 CaptivePortalService::get_state_for_testing()); |
972 | 1097 |
973 CaptivePortalService::set_state_for_testing( | 1098 CaptivePortalService::set_state_for_testing( |
974 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); | 1099 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); |
975 EnableCaptivePortalDetection(browser()->profile(), true); | 1100 EnableCaptivePortalDetection(browser()->profile(), true); |
976 | 1101 |
977 // Set the captive portal service to use URLRequestMockCaptivePortalJob's | 1102 // Set the captive portal service to use URLRequestMockCaptivePortalJob's |
978 // mock URL, by default. | 1103 // mock URL, by default. |
979 SetUpCaptivePortalService(browser()->profile(), | 1104 SetUpCaptivePortalService(browser()->profile(), |
980 GURL(kMockCaptivePortalTestUrl)); | 1105 GURL(kMockCaptivePortalTestUrl)); |
1106 | |
1107 // Set SSL interstitial delay long enough so that a captive portal result | |
1108 // is guaranteed to arrive during this window, and a captive portal | |
1109 // error page is displayed instead of an SSL interstitial. | |
1110 SSLErrorHandler::SetInterstitialDisplayDelayForTest( | |
1111 base::TimeDelta::FromHours(1)); | |
981 } | 1112 } |
982 | 1113 |
983 void CaptivePortalBrowserTest::TearDownOnMainThread() { | 1114 void CaptivePortalBrowserTest::TearDownOnMainThread() { |
984 // No test should have a captive portal check pending on quit. | 1115 // No test should have a captive portal check pending on quit. |
985 EXPECT_FALSE(CheckPending(browser())); | 1116 EXPECT_FALSE(CheckPending(browser())); |
986 } | 1117 } |
987 | 1118 |
988 void CaptivePortalBrowserTest::EnableCaptivePortalDetection( | 1119 void CaptivePortalBrowserTest::EnableCaptivePortalDetection( |
989 Profile* profile, bool enabled) { | 1120 Profile* profile, bool enabled) { |
990 profile->GetPrefs()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); | 1121 profile->GetPrefs()->SetBoolean(prefs::kAlternateErrorPagesEnabled, enabled); |
991 } | 1122 } |
992 | 1123 |
1124 void CaptivePortalBrowserTest::RespondToProbeRequests(bool enabled) { | |
1125 if (enabled) { | |
1126 EXPECT_EQ(CaptivePortalService::IGNORE_REQUESTS_FOR_TESTING, | |
1127 CaptivePortalService::get_state_for_testing()); | |
1128 CaptivePortalService::set_state_for_testing( | |
1129 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); | |
1130 } else { | |
1131 EXPECT_EQ(CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING, | |
1132 CaptivePortalService::get_state_for_testing()); | |
1133 CaptivePortalService::set_state_for_testing( | |
1134 CaptivePortalService::IGNORE_REQUESTS_FOR_TESTING); | |
1135 } | |
1136 } | |
1137 | |
993 void CaptivePortalBrowserTest::SetUpCaptivePortalService(Profile* profile, | 1138 void CaptivePortalBrowserTest::SetUpCaptivePortalService(Profile* profile, |
994 const GURL& test_url) { | 1139 const GURL& test_url) { |
995 CaptivePortalService* captive_portal_service = | 1140 CaptivePortalService* captive_portal_service = |
996 CaptivePortalServiceFactory::GetForProfile(profile); | 1141 CaptivePortalServiceFactory::GetForProfile(profile); |
997 captive_portal_service->set_test_url(test_url); | 1142 captive_portal_service->set_test_url(test_url); |
998 | 1143 |
999 // Don't use any non-zero timers. Timers are checked in unit tests. | 1144 // Don't use any non-zero timers. Timers are checked in unit tests. |
1000 CaptivePortalService::RecheckPolicy* recheck_policy = | 1145 CaptivePortalService::RecheckPolicy* recheck_policy = |
1001 &captive_portal_service->recheck_policy(); | 1146 &captive_portal_service->recheck_policy(); |
1002 recheck_policy->initial_backoff_no_portal_ms = 0; | 1147 recheck_policy->initial_backoff_no_portal_ms = 0; |
1003 recheck_policy->initial_backoff_portal_ms = 0; | 1148 recheck_policy->initial_backoff_portal_ms = 0; |
1004 recheck_policy->backoff_policy.maximum_backoff_ms = 0; | 1149 recheck_policy->backoff_policy.maximum_backoff_ms = 0; |
1005 } | 1150 } |
1006 | 1151 |
1007 bool CaptivePortalBrowserTest::CheckPending(Browser* browser) { | 1152 bool CaptivePortalBrowserTest::CheckPending(Browser* browser) { |
1008 CaptivePortalService* captive_portal_service = | 1153 CaptivePortalService* captive_portal_service = |
1009 CaptivePortalServiceFactory::GetForProfile(browser->profile()); | 1154 CaptivePortalServiceFactory::GetForProfile(browser->profile()); |
1010 | 1155 |
1011 return captive_portal_service->DetectionInProgress() || | 1156 return captive_portal_service->DetectionInProgress() || |
1012 captive_portal_service->TimerRunning(); | 1157 captive_portal_service->TimerRunning(); |
1013 } | 1158 } |
1014 | 1159 |
1160 const void* CaptivePortalBrowserTest::GetInterstitialType( | |
1161 WebContents* contents) const { | |
1162 if (!contents->ShowingInterstitialPage()) | |
1163 return NULL; | |
Bernhard Bauer
2014/12/18 18:10:05
nullptr?
meacer
2014/12/19 02:42:24
Done.
| |
1164 SecurityInterstitialPage* blocking_page = | |
1165 static_cast<SecurityInterstitialPage*>( | |
1166 contents->GetInterstitialPage()->GetDelegateForTesting()); | |
1167 DCHECK(blocking_page); | |
Bernhard Bauer
2014/12/18 18:10:06
This DCHECK is kind of unnecessary; If |blocking_p
meacer
2014/12/19 02:42:24
Done.
| |
1168 return blocking_page->GetTypeForTesting(); | |
1169 } | |
1170 | |
1015 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( | 1171 CaptivePortalTabReloader::State CaptivePortalBrowserTest::GetStateOfTabReloader( |
1016 WebContents* web_contents) const { | 1172 WebContents* web_contents) const { |
1017 return GetTabReloader(web_contents)->state(); | 1173 return GetTabReloader(web_contents)->state(); |
1018 } | 1174 } |
1019 | 1175 |
1020 CaptivePortalTabReloader::State | 1176 CaptivePortalTabReloader::State |
1021 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, | 1177 CaptivePortalBrowserTest::GetStateOfTabReloaderAt(Browser* browser, |
1022 int index) const { | 1178 int index) const { |
1023 return GetStateOfTabReloader( | 1179 return GetStateOfTabReloader( |
1024 browser->tab_strip_model()->GetWebContentsAt(index)); | 1180 browser->tab_strip_model()->GetWebContentsAt(index)); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 | 1393 |
1238 // Reset the load time to be large, so the timer won't trigger on a reload. | 1394 // Reset the load time to be large, so the timer won't trigger on a reload. |
1239 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1395 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1240 } | 1396 } |
1241 | 1397 |
1242 void CaptivePortalBrowserTest::FastTimeoutBehindCaptivePortal( | 1398 void CaptivePortalBrowserTest::FastTimeoutBehindCaptivePortal( |
1243 Browser* browser, | 1399 Browser* browser, |
1244 bool expect_open_login_tab) { | 1400 bool expect_open_login_tab) { |
1245 FastErrorBehindCaptivePortal(browser, | 1401 FastErrorBehindCaptivePortal(browser, |
1246 expect_open_login_tab, | 1402 expect_open_login_tab, |
1247 GURL(kMockHttpsQuickTimeoutUrl)); | 1403 GURL(kMockHttpsQuickTimeoutUrl), |
1404 false); | |
1248 } | 1405 } |
1249 | 1406 |
1250 void CaptivePortalBrowserTest::FastErrorBehindCaptivePortal( | 1407 void CaptivePortalBrowserTest::FastErrorBehindCaptivePortal( |
1251 Browser* browser, | 1408 Browser* browser, |
1252 bool expect_open_login_tab, | 1409 bool expect_open_login_tab, |
1253 const GURL& error_url) { | 1410 const GURL& error_url, |
1411 bool delay_portal_response_until_interstital) { | |
1254 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1412 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 | 1413 // Calling this on a tab that's waiting for a load to manually be timed out |
1256 // will result in a hang. | 1414 // will result in a hang. |
1257 ASSERT_FALSE(tab_strip_model->GetActiveWebContents()->IsLoading()); | 1415 ASSERT_FALSE(tab_strip_model->GetActiveWebContents()->IsLoading()); |
1258 | 1416 |
1259 // Set the load time to be large, so the timer won't trigger. The value is | 1417 // 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. | 1418 // not restored at the end of the function. |
1261 CaptivePortalTabReloader* tab_reloader = | 1419 CaptivePortalTabReloader* tab_reloader = |
1262 GetTabReloader(tab_strip_model->GetActiveWebContents()); | 1420 GetTabReloader(tab_strip_model->GetActiveWebContents()); |
1263 ASSERT_TRUE(tab_reloader); | 1421 ASSERT_TRUE(tab_reloader); |
1264 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); | 1422 SetSlowSSLLoadTime(tab_reloader, base::TimeDelta::FromHours(1)); |
1265 | 1423 |
1266 // Number of tabs expected to be open after the captive portal checks | 1424 // Number of tabs expected to be open after the captive portal checks |
1267 // have completed. | 1425 // have completed. |
1268 int initial_tab_count = tab_strip_model->count(); | 1426 int initial_tab_count = tab_strip_model->count(); |
1269 int initial_active_index = tab_strip_model->active_index(); | 1427 int initial_active_index = tab_strip_model->active_index(); |
1270 int initial_loading_tabs = NumLoadingTabs(); | 1428 int initial_loading_tabs = NumLoadingTabs(); |
1271 int expected_broken_tabs = NumBrokenTabs(); | 1429 int expected_broken_tabs = NumBrokenTabs(); |
1272 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != | 1430 if (CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL != |
1273 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())) { | 1431 GetStateOfTabReloader(tab_strip_model->GetActiveWebContents())) { |
1274 ++expected_broken_tabs; | 1432 ++expected_broken_tabs; |
1275 } | 1433 } |
1276 | 1434 |
1435 CaptivePortalService* captive_portal_service = | |
1436 CaptivePortalServiceFactory::GetForProfile(browser->profile()); | |
1437 if (delay_portal_response_until_interstital) | |
1438 RespondToProbeRequests(false); | |
1439 | |
1277 MultiNavigationObserver navigation_observer; | 1440 MultiNavigationObserver navigation_observer; |
1278 CaptivePortalObserver portal_observer(browser->profile()); | 1441 CaptivePortalObserver portal_observer(browser->profile()); |
1279 ui_test_utils::NavigateToURLWithDisposition(browser, | 1442 ui_test_utils::NavigateToURLWithDisposition(browser, |
1280 error_url, | 1443 error_url, |
1281 CURRENT_TAB, | 1444 CURRENT_TAB, |
1282 ui_test_utils::BROWSER_TEST_NONE); | 1445 ui_test_utils::BROWSER_TEST_NONE); |
1446 | |
1447 if (delay_portal_response_until_interstital) { | |
1448 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1449 GetStateOfTabReloaderAt(browser, initial_active_index)); | |
1450 // Once the interstitial is attached, probe for captive portal. | |
1451 WaitForInterstitialAttach(tab_strip_model->GetActiveWebContents()); | |
1452 RespondToProbeRequests(true); | |
1453 captive_portal_service->DetectCaptivePortal(); | |
1454 } | |
1455 | |
1283 portal_observer.WaitForResults(1); | 1456 portal_observer.WaitForResults(1); |
1284 | 1457 |
1285 if (expect_open_login_tab) { | 1458 if (expect_open_login_tab) { |
1286 navigation_observer.WaitForNavigations(2); | 1459 navigation_observer.WaitForNavigations(2); |
1287 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count()); | 1460 ASSERT_EQ(initial_tab_count + 1, tab_strip_model->count()); |
1288 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index()); | 1461 EXPECT_EQ(initial_tab_count, tab_strip_model->active_index()); |
1289 // Make sure that the originally active tab and the captive portal tab have | 1462 // Make sure that the originally active tab and the captive portal tab have |
1290 // each loaded once. | 1463 // each loaded once. |
1291 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1464 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1292 tab_strip_model->GetWebContentsAt(initial_active_index))); | 1465 tab_strip_model->GetWebContentsAt(initial_active_index))); |
(...skipping 15 matching lines...) Expand all Loading... | |
1308 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); | 1481 EXPECT_EQ(expected_broken_tabs, NumBrokenTabs()); |
1309 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | 1482 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, |
1310 portal_observer.captive_portal_result()); | 1483 portal_observer.captive_portal_result()); |
1311 EXPECT_EQ(1, portal_observer.num_results_received()); | 1484 EXPECT_EQ(1, portal_observer.num_results_received()); |
1312 EXPECT_FALSE(CheckPending(browser)); | 1485 EXPECT_FALSE(CheckPending(browser)); |
1313 | 1486 |
1314 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, | 1487 EXPECT_EQ(CaptivePortalTabReloader::STATE_BROKEN_BY_PORTAL, |
1315 GetStateOfTabReloaderAt(browser, initial_active_index)); | 1488 GetStateOfTabReloaderAt(browser, initial_active_index)); |
1316 } | 1489 } |
1317 | 1490 |
1491 void CaptivePortalBrowserTest::FastErrorWithInterstitialTimer( | |
1492 Browser* browser, | |
1493 const GURL& cert_error_url) { | |
1494 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
1495 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
1496 | |
1497 // Disable captive portal checks indefinitely. | |
1498 RespondToProbeRequests(false); | |
1499 | |
1500 SSLInterstitialTimerObserver interstitial_timer_observer(broken_tab_contents); | |
1501 ui_test_utils::NavigateToURLWithDisposition(browser, | |
1502 cert_error_url, | |
1503 CURRENT_TAB, | |
1504 ui_test_utils::BROWSER_TEST_NONE); | |
1505 interstitial_timer_observer.WaitForTimerFired(); | |
1506 | |
1507 // The tab should be in loading state, waiting for the interstitial timer to | |
1508 // expire or a captive portal result to arrive. Since captive portal checks | |
1509 // are disabled and timer set to expire after a very long time, the tab should | |
1510 // hang indefinitely. | |
1511 EXPECT_TRUE(broken_tab_contents->IsLoading()); | |
1512 EXPECT_EQ(1, NumLoadingTabs()); | |
1513 } | |
1514 | |
1318 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, | 1515 void CaptivePortalBrowserTest::NavigateLoginTab(Browser* browser, |
1319 int num_loading_tabs, | 1516 int num_loading_tabs, |
1320 int num_timed_out_tabs) { | 1517 int num_timed_out_tabs) { |
1321 MultiNavigationObserver navigation_observer; | 1518 MultiNavigationObserver navigation_observer; |
1322 CaptivePortalObserver portal_observer(browser->profile()); | 1519 CaptivePortalObserver portal_observer(browser->profile()); |
1323 | 1520 |
1324 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1521 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
1325 int initial_tab_count = tab_strip_model->count(); | 1522 int initial_tab_count = tab_strip_model->count(); |
1326 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); | 1523 EXPECT_EQ(num_loading_tabs, NumLoadingTabs()); |
1327 EXPECT_EQ(num_timed_out_tabs, NumBrokenTabs() - NumLoadingTabs()); | 1524 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()); | 1597 EXPECT_EQ(initial_tab_count, tab_strip_model->count()); |
1401 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 1598 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
1402 GetStateOfTabReloaderAt(browser, login_tab_index)); | 1599 GetStateOfTabReloaderAt(browser, login_tab_index)); |
1403 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | 1600 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); |
1404 | 1601 |
1405 // Make sure there were no unexpected navigations of the login tab. | 1602 // Make sure there were no unexpected navigations of the login tab. |
1406 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 1603 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( |
1407 tab_strip_model->GetWebContentsAt(login_tab_index))); | 1604 tab_strip_model->GetWebContentsAt(login_tab_index))); |
1408 } | 1605 } |
1409 | 1606 |
1607 void CaptivePortalBrowserTest::LoginCertError(Browser* browser) { | |
1608 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | |
1609 | |
1610 MultiNavigationObserver navigation_observer; | |
1611 CaptivePortalObserver portal_observer(browser->profile()); | |
1612 | |
1613 TabStripModel* tab_strip_model = browser->tab_strip_model(); | |
1614 | |
1615 // Verify that the login page is on top. | |
1616 int login_tab_index = tab_strip_model->active_index(); | |
1617 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1618 GetStateOfTabReloaderAt(browser, login_tab_index)); | |
1619 ASSERT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | |
1620 | |
1621 // Trigger a navigation. | |
1622 content::RenderFrameHost* render_frame_host = | |
1623 tab_strip_model->GetActiveWebContents()->GetMainFrame(); | |
1624 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); | |
Bernhard Bauer
2014/12/18 18:10:05
Could you use content::ExecuteScript() here?
meacer
2014/12/19 02:42:24
Done here and two other places.
| |
1625 | |
1626 // The captive portal tab navigation will trigger a captive portal check, | |
1627 // and reloading the original tab will bring up the interstitial page again, | |
1628 // triggering a second captive portal check. | |
1629 portal_observer.WaitForResults(2); | |
1630 | |
1631 // Wait for both tabs to finish loading. | |
1632 navigation_observer.WaitForNavigations(2); | |
1633 EXPECT_EQ(2, portal_observer.num_results_received()); | |
1634 EXPECT_FALSE(CheckPending(browser)); | |
1635 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED, | |
1636 portal_observer.captive_portal_result()); | |
1637 | |
1638 // Check state of tabs. While the first tab is still displaying an | |
1639 // interstitial page, since no portal was found, it should be in STATE_NONE, | |
1640 // as should the login tab. | |
1641 ASSERT_EQ(2, tab_strip_model->count()); | |
1642 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1643 GetStateOfTabReloaderAt(browser, 0)); | |
1644 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
1645 GetStateOfTabReloaderAt(browser, login_tab_index)); | |
1646 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(login_tab_index))); | |
1647 | |
1648 // Make sure only one navigation was for the login tab. | |
1649 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | |
1650 tab_strip_model->GetWebContentsAt(login_tab_index))); | |
1651 } | |
1652 | |
1410 void CaptivePortalBrowserTest::FailLoadsAfterLogin(Browser* browser, | 1653 void CaptivePortalBrowserTest::FailLoadsAfterLogin(Browser* browser, |
1411 int num_loading_tabs) { | 1654 int num_loading_tabs) { |
1412 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); | 1655 ASSERT_EQ(num_loading_tabs, NumLoadingTabs()); |
1413 ASSERT_EQ(num_loading_tabs, NumNeedReloadTabs()); | 1656 ASSERT_EQ(num_loading_tabs, NumNeedReloadTabs()); |
1414 EXPECT_EQ(0, NumBrokenTabs()); | 1657 EXPECT_EQ(0, NumBrokenTabs()); |
1415 | 1658 |
1416 TabStripModel* tab_strip_model = browser->tab_strip_model(); | 1659 TabStripModel* tab_strip_model = browser->tab_strip_model(); |
1417 int initial_num_tabs = tab_strip_model->count(); | 1660 int initial_num_tabs = tab_strip_model->count(); |
1418 int initial_active_tab = tab_strip_model->active_index(); | 1661 int initial_active_tab = tab_strip_model->active_index(); |
1419 | 1662 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1698 } | 1941 } |
1699 | 1942 |
1700 // Checks the unlikely case that the tab times out before the timer triggers. | 1943 // Checks the unlikely case that the tab times out before the timer triggers. |
1701 // This most likely won't happen, but should still work: | 1944 // This most likely won't happen, but should still work: |
1702 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { | 1945 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { |
1703 FastTimeoutBehindCaptivePortal(browser(), true); | 1946 FastTimeoutBehindCaptivePortal(browser(), true); |
1704 Login(browser(), 0, 1); | 1947 Login(browser(), 0, 1); |
1705 } | 1948 } |
1706 | 1949 |
1707 // A cert error triggers a captive portal check and results in opening a login | 1950 // 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. | 1951 // tab. |
1709 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { | 1952 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
1710 // Need an HTTP TestServer to handle a dynamically created server redirect. | 1953 ShowCaptivePortalInterstitialOnCertError) { |
1711 ASSERT_TRUE(test_server()->Start()); | |
1712 | |
1713 net::SpawnedTestServer::SSLOptions https_options; | 1954 net::SpawnedTestServer::SSLOptions https_options; |
1714 https_options.server_certificate = | 1955 https_options.server_certificate = |
1715 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 1956 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; |
1716 net::SpawnedTestServer https_server( | 1957 net::SpawnedTestServer https_server( |
1717 net::SpawnedTestServer::TYPE_HTTPS, https_options, | 1958 net::SpawnedTestServer::TYPE_HTTPS, https_options, |
1718 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 1959 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
1719 ASSERT_TRUE(https_server.Start()); | 1960 ASSERT_TRUE(https_server.Start()); |
1720 | 1961 |
1721 // The path does not matter. | 1962 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
1722 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 1963 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
1964 | |
1965 // The path does not matter. | |
1966 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
1967 int cert_error_tab_index = tab_strip_model->active_index(); | |
1723 // The interstitial should trigger a captive portal check when it opens, just | 1968 // The interstitial should trigger a captive portal check when it opens, just |
1724 // like navigating to kMockHttpsQuickTimeoutUrl. | 1969 // like navigating to kMockHttpsQuickTimeoutUrl. |
1725 FastErrorBehindCaptivePortal(browser(), true, cert_error_url); | 1970 FastErrorBehindCaptivePortal(browser(), true, cert_error_url, false); |
1726 | 1971 EXPECT_EQ(CaptivePortalBlockingPage::kTypeForTesting, |
1727 // Simulate logging in. Can't use Login() because the interstitial tab looks | 1972 GetInterstitialType(broken_tab_contents)); |
1728 // like a cross between a hung tab (Load was never committed) and a tab at an | 1973 |
1729 // error page (The load was stopped). | 1974 // Switch to the interstitial and click the |Connect| button. Should switch |
1730 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | 1975 // active tab to the captive portal landing page. |
1976 int login_tab_index = tab_strip_model->active_index(); | |
1977 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | |
1978 // Wait for the interstitial to load all the JavaScript code. Otherwise, | |
1979 // trying to click on a button will fail. | |
1980 EXPECT_TRUE(WaitForInterstitialReady( | |
1981 broken_tab_contents->GetInterstitialPage())); | |
1982 content::RenderViewHost* rvh = | |
1983 broken_tab_contents->GetInterstitialPage()->GetRenderViewHostForTesting(); | |
1984 const char kClickConnectButtonJS[] = | |
1985 "document.getElementById('primary-button').click();"; | |
1986 EXPECT_TRUE( | |
1987 content::ExecuteScript(rvh->GetMainFrame(), kClickConnectButtonJS)); | |
1988 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | |
1989 | |
1990 // For completeness, close the login tab and try clicking |Connect| again. | |
1991 // A new login tab should open. | |
1992 EXPECT_EQ(1, login_tab_index); | |
1993 content::WebContentsDestroyedWatcher destroyed_watcher( | |
1994 tab_strip_model->GetActiveWebContents()); | |
1995 EXPECT_TRUE( | |
1996 tab_strip_model->CloseWebContentsAt(tab_strip_model->active_index(), 0)); | |
1997 destroyed_watcher.Wait(); | |
1731 MultiNavigationObserver navigation_observer; | 1998 MultiNavigationObserver navigation_observer; |
1999 EXPECT_TRUE( | |
2000 content::ExecuteScript(rvh->GetMainFrame(), kClickConnectButtonJS)); | |
2001 navigation_observer.WaitForNavigations(1); | |
2002 EXPECT_EQ(login_tab_index, tab_strip_model->active_index()); | |
2003 | |
2004 LoginCertError(browser()); | |
2005 | |
2006 // Once logged in, broken tab should reload and display the SSL interstitial. | |
2007 WaitForInterstitialAttach(broken_tab_contents); | |
2008 tab_strip_model->ActivateTabAt(cert_error_tab_index, false); | |
2009 | |
2010 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
2011 GetInterstitialType(tab_strip_model->GetActiveWebContents())); | |
2012 | |
2013 // Trigger another captive portal check while the SSL interstitial is showing. | |
2014 // At this point the user is logged in to the captive portal, so the captive | |
2015 // portal interstitial shouldn't get recreated. | |
1732 CaptivePortalObserver portal_observer(browser()->profile()); | 2016 CaptivePortalObserver portal_observer(browser()->profile()); |
1733 | 2017 CaptivePortalService* captive_portal_service = |
1734 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2018 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); |
1735 content::RenderFrameHost* render_frame_host = | 2019 captive_portal_service->DetectCaptivePortal(); |
1736 tab_strip_model->GetActiveWebContents()->GetMainFrame(); | 2020 portal_observer.WaitForResults(1); |
1737 render_frame_host->ExecuteJavaScript(base::ASCIIToUTF16("submitForm()")); | 2021 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
1738 | 2022 GetInterstitialType(broken_tab_contents)); |
1739 // The captive portal tab navigation will trigger a captive portal check, | 2023 |
1740 // and reloading the original tab will bring up the interstitial page again, | 2024 // A captive portal appears. Trigger a final captive portal check. The |
1741 // triggering a second captive portal check. | 2025 // captive portal interstitial should still not get recreated. |
1742 portal_observer.WaitForResults(2); | 2026 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(true); |
1743 | 2027 CaptivePortalObserver final_portal_observer(browser()->profile()); |
1744 // Wait for both tabs to finish loading. | 2028 captive_portal_service->DetectCaptivePortal(); |
1745 navigation_observer.WaitForNavigations(2); | 2029 final_portal_observer.WaitForResults(1); |
1746 EXPECT_EQ(2, portal_observer.num_results_received()); | 2030 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
1747 EXPECT_FALSE(CheckPending(browser())); | 2031 GetInterstitialType(broken_tab_contents)); |
1748 EXPECT_EQ(captive_portal::RESULT_INTERNET_CONNECTED, | 2032 } |
1749 portal_observer.captive_portal_result()); | 2033 |
1750 | 2034 // Tests this scenario: |
1751 // Check state of tabs. While the first tab is still displaying an | 2035 // - 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, | 2036 // arrive. |
1753 // as should the login tab. | 2037 // - A cert error triggers an interstitial timer with a very long timeout. |
1754 ASSERT_EQ(2, tab_strip_model->count()); | 2038 // - No captive portal results arrive, causing the tab to appear as loading |
1755 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2039 // indefinitely (because probe requests are ignored). |
1756 GetStateOfTabReloaderAt(browser(), 0)); | 2040 // - Stopping the page load shouldn't result in any interstitials. |
1757 EXPECT_FALSE(IsLoginTab(tab_strip_model->GetWebContentsAt(1))); | 2041 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
1758 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2042 InterstitialTimerStopNavigationWhileLoading) { |
1759 GetStateOfTabReloaderAt(browser(), 1)); | 2043 net::SpawnedTestServer::SSLOptions https_options; |
1760 | 2044 https_options.server_certificate = |
1761 // Make sure only one navigation was for the login tab. | 2045 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; |
1762 EXPECT_EQ(1, navigation_observer.NumNavigationsForTab( | 2046 net::SpawnedTestServer https_server( |
1763 tab_strip_model->GetWebContentsAt(1))); | 2047 net::SpawnedTestServer::TYPE_HTTPS, https_options, |
2048 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2049 ASSERT_TRUE(https_server.Start()); | |
2050 // The path does not matter. | |
2051 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2052 | |
2053 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2054 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2055 | |
2056 CaptivePortalObserver portal_observer1(browser()->profile()); | |
2057 FastErrorWithInterstitialTimer(browser(), cert_error_url); | |
2058 | |
2059 // Page appears loading. Stop the navigation. There should be no interstitial. | |
2060 MultiNavigationObserver test_navigation_observer; | |
2061 broken_tab_contents->Stop(); | |
2062 test_navigation_observer.WaitForNavigations(1); | |
2063 | |
2064 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2065 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2066 EXPECT_EQ(0, portal_observer1.num_results_received()); | |
2067 EXPECT_EQ(0, NumLoadingTabs()); | |
2068 EXPECT_FALSE(CheckPending(browser())); | |
2069 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2070 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2071 GetStateOfTabReloaderAt(browser(), 0)); | |
2072 | |
2073 // Re-enable captive portal checks and fire one. The result should be ignored. | |
2074 RespondToProbeRequests(true); | |
2075 CaptivePortalObserver portal_observer2(browser()->profile()); | |
2076 CaptivePortalService* captive_portal_service = | |
2077 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | |
2078 captive_portal_service->DetectCaptivePortal(); | |
2079 portal_observer2.WaitForResults(1); | |
2080 | |
2081 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2082 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2083 EXPECT_EQ(1, portal_observer2.num_results_received()); | |
2084 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | |
2085 portal_observer2.captive_portal_result()); | |
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 | |
2093 // Same as above, but instead of stopping, the loading page is reloaded. The end | |
2094 // result is the same. (i.e. page load stops, no interstitials shown) | |
2095 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2096 InterstitialTimerReloadWhileLoading) { | |
2097 net::SpawnedTestServer::SSLOptions https_options; | |
2098 https_options.server_certificate = | |
2099 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2100 net::SpawnedTestServer https_server( | |
2101 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2102 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2103 ASSERT_TRUE(https_server.Start()); | |
2104 // The path does not matter. | |
2105 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2106 | |
2107 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2108 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2109 | |
2110 CaptivePortalObserver portal_observer(browser()->profile()); | |
2111 FastErrorWithInterstitialTimer(browser(), cert_error_url); | |
2112 | |
2113 // Page appears loading. Reloading it cancels the page load. Since the load is | |
2114 // stopped, no cert error occurs and SSLErrorHandler isn't instantiated. | |
2115 MultiNavigationObserver test_navigation_observer; | |
2116 chrome::Reload(browser(), CURRENT_TAB); | |
2117 test_navigation_observer.WaitForNavigations(2); | |
2118 | |
2119 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2120 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2121 EXPECT_EQ(0, portal_observer.num_results_received()); | |
2122 EXPECT_EQ(2, test_navigation_observer.num_navigations()); | |
2123 EXPECT_EQ(0, NumLoadingTabs()); | |
2124 EXPECT_FALSE(CheckPending(browser())); | |
2125 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2126 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2127 GetStateOfTabReloaderAt(browser(), 0)); | |
2128 | |
2129 // Re-enable captive portal checks and fire one. The result should be ignored. | |
2130 RespondToProbeRequests(true); | |
2131 CaptivePortalObserver portal_observer2(browser()->profile()); | |
2132 CaptivePortalService* captive_portal_service = | |
2133 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | |
2134 captive_portal_service->DetectCaptivePortal(); | |
2135 portal_observer2.WaitForResults(1); | |
2136 | |
2137 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2138 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2139 EXPECT_EQ(1, portal_observer2.num_results_received()); | |
2140 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | |
2141 portal_observer2.captive_portal_result()); | |
2142 EXPECT_EQ(0, NumLoadingTabs()); | |
2143 EXPECT_FALSE(CheckPending(browser())); | |
2144 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2145 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2146 GetStateOfTabReloaderAt(browser(), 0)); | |
2147 } | |
2148 | |
2149 // Same as above, but instead of reloading, the page is navigated away. The new | |
2150 // page should load, and no interstitials should be shown. | |
2151 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2152 InterstitialTimerNavigateAwayWhileLoading) { | |
2153 net::SpawnedTestServer::SSLOptions https_options; | |
2154 https_options.server_certificate = | |
2155 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2156 net::SpawnedTestServer https_server( | |
2157 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2158 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2159 ASSERT_TRUE(https_server.Start()); | |
2160 // The path does not matter. | |
2161 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2162 | |
2163 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2164 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2165 | |
2166 CaptivePortalObserver portal_observer(browser()->profile()); | |
2167 FastErrorWithInterstitialTimer(browser(), cert_error_url); | |
2168 | |
2169 // Page appears loading. Navigating away shouldn't result in any interstitial. | |
2170 // Can't use ui_test_utils::NavigateToURLWithDisposition because it waits for | |
2171 // a load stop notification before starting a new navigation. | |
2172 MultiNavigationObserver test_navigation_observer; | |
2173 browser()->OpenURL(content::OpenURLParams( | |
2174 URLRequestMockHTTPJob::GetMockUrl( | |
2175 base::FilePath(FILE_PATH_LITERAL("title2.html"))), | |
2176 content::Referrer(), | |
2177 CURRENT_TAB, | |
2178 ui::PAGE_TRANSITION_TYPED, false)); | |
2179 // Expect two navigations: First one for stopping the hanging page, second one | |
2180 // for completing the load of the above navigation. | |
2181 test_navigation_observer.WaitForNavigations(2); | |
2182 | |
2183 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2184 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2185 EXPECT_EQ(0, portal_observer.num_results_received()); | |
2186 EXPECT_EQ(2, test_navigation_observer.num_navigations()); | |
2187 EXPECT_EQ(0, NumLoadingTabs()); | |
2188 EXPECT_FALSE(CheckPending(browser())); | |
2189 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2190 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2191 GetStateOfTabReloaderAt(browser(), 0)); | |
2192 | |
2193 // Re-enable captive portal checks and fire one. The result should be ignored. | |
2194 RespondToProbeRequests(true); | |
2195 CaptivePortalObserver portal_observer2(browser()->profile()); | |
2196 CaptivePortalService* captive_portal_service = | |
2197 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | |
2198 captive_portal_service->DetectCaptivePortal(); | |
2199 portal_observer2.WaitForResults(1); | |
2200 | |
2201 EXPECT_FALSE(broken_tab_contents->ShowingInterstitialPage()); | |
2202 EXPECT_FALSE(broken_tab_contents->IsLoading()); | |
2203 EXPECT_EQ(1, portal_observer2.num_results_received()); | |
2204 EXPECT_EQ(captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL, | |
2205 portal_observer2.captive_portal_result()); | |
2206 EXPECT_EQ(0, NumLoadingTabs()); | |
2207 EXPECT_FALSE(CheckPending(browser())); | |
2208 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
2209 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | |
2210 GetStateOfTabReloaderAt(browser(), 0)); | |
2211 } | |
2212 | |
2213 // A cert error triggers a captive portal check and results in opening a login | |
2214 // tab. The user then logs in and the page with the error is reloaded. | |
2215 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { | |
2216 // Need an HTTP TestServer to handle a dynamically created server redirect. | |
2217 ASSERT_TRUE(test_server()->Start()); | |
2218 | |
2219 net::SpawnedTestServer::SSLOptions https_options; | |
2220 https_options.server_certificate = | |
2221 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | |
2222 net::SpawnedTestServer https_server( | |
2223 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
2224 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
2225 ASSERT_TRUE(https_server.Start()); | |
2226 | |
2227 // Set SSL interstitial delay to zero so that a captive portal result can not | |
2228 // arrive during this window, so an SSL interstitial is displayed instead | |
2229 // of a captive portal error page. | |
2230 SSLErrorHandler::SetInterstitialDisplayDelayForTest(base::TimeDelta()); | |
2231 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2232 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2233 | |
2234 // Setting the delay to zero above has a race condition: A captive portal | |
2235 // result triggered by a cert error can arrive before the SSL interstitial | |
2236 // display timer is fired, even though it's set to zero. | |
2237 // To avoid this, disable captive portal checks until the SSL interstitial is | |
2238 // displayed. Once it's displayed, enable portal checks and fire one. | |
2239 bool delay_portal_response_until_interstital = true; | |
2240 | |
2241 // The path does not matter. | |
2242 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | |
2243 // A captive portal check is triggered in FastErrorBehindCaptivePortal. | |
2244 FastErrorBehindCaptivePortal( | |
2245 browser(), | |
2246 true, | |
2247 cert_error_url, | |
2248 delay_portal_response_until_interstital); | |
2249 | |
2250 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
2251 GetInterstitialType(broken_tab_contents)); | |
2252 | |
2253 LoginCertError(browser()); | |
1764 } | 2254 } |
1765 | 2255 |
1766 // Tries navigating both the tab that encounters an SSL timeout and the | 2256 // Tries navigating both the tab that encounters an SSL timeout and the |
1767 // login tab twice, only logging in the second time. | 2257 // login tab twice, only logging in the second time. |
1768 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginExtraNavigations) { | 2258 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginExtraNavigations) { |
1769 FastTimeoutBehindCaptivePortal(browser(), true); | 2259 FastTimeoutBehindCaptivePortal(browser(), true); |
1770 | 2260 |
1771 // Activate the timed out tab and navigate it to a timeout again. | 2261 // Activate the timed out tab and navigate it to a timeout again. |
1772 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2262 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
1773 tab_strip_model->ActivateTabAt(0, true); | 2263 tab_strip_model->ActivateTabAt(0, true); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2206 content::BrowserThread::PostTask( | 2696 content::BrowserThread::PostTask( |
2207 content::BrowserThread::IO, FROM_HERE, | 2697 content::BrowserThread::IO, FROM_HERE, |
2208 base::Bind(&AddHstsHost, | 2698 base::Bind(&AddHstsHost, |
2209 make_scoped_refptr(browser()->profile()->GetRequestContext()), | 2699 make_scoped_refptr(browser()->profile()->GetRequestContext()), |
2210 http_timeout_url.host())); | 2700 http_timeout_url.host())); |
2211 | 2701 |
2212 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); | 2702 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); |
2213 Login(browser(), 1, 0); | 2703 Login(browser(), 1, 0); |
2214 FailLoadsAfterLogin(browser(), 1); | 2704 FailLoadsAfterLogin(browser(), 1); |
2215 } | 2705 } |
2706 | |
2707 // A slow SSL load starts. The reloader triggers a captive portal check, finds a | |
2708 // captive portal. The SSL commits with a cert error, triggering another captive | |
2709 // portal check. | |
2710 // The second check finds no captive portal. The reloader triggers a reload at | |
2711 // the same time SSL error handler tries to show an interstitial. Should result | |
2712 // in an SSL interstitial. | |
2713 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | |
2714 InterstitialTimerCertErrorAfterSlowLoad) { | |
2715 // Use a url that triggers a slow load, instead of creating an https server. | |
2716 GURL cert_error_url = GURL(kMockHttpsUrl); | |
2717 | |
2718 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
2719 int broken_tab_index = tab_strip_model->active_index(); | |
2720 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | |
2721 SlowLoadBehindCaptivePortal(browser(), true, cert_error_url, 1, 1); | |
2722 | |
2723 // No longer behind a captive portal. Committing the SSL page should trigger | |
2724 // an SSL interstitial which triggers a new captive portal check. Since there | |
2725 // is no captive portal anymore, should end up with an SSL interstitial. | |
2726 URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal(false); | |
2727 | |
2728 CaptivePortalObserver portal_observer(browser()->profile()); | |
2729 MultiNavigationObserver navigation_observer; | |
2730 URLRequestTimeoutOnDemandJob::FailJobsWithCertError(1); | |
2731 navigation_observer.WaitForNavigations(1); | |
2732 | |
2733 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | |
2734 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | |
2735 | |
2736 WaitForInterstitialAttach(broken_tab_contents); | |
2737 portal_observer.WaitForResults(1); | |
2738 | |
2739 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | |
2740 GetInterstitialType(broken_tab_contents)); | |
2741 } | |
OLD | NEW |