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

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

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

Powered by Google App Engine
This is Rietveld 408576698