| 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 <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // |job_list_|. If so, exits the message loop on the UI thread, which | 231 // |job_list_|. If so, exits the message loop on the UI thread, which |
| 232 // should be spinning in a call to WaitForJobs. Does nothing if | 232 // should be spinning in a call to WaitForJobs. Does nothing if |
| 233 // |num_jobs_to_wait_for_| is 0. | 233 // |num_jobs_to_wait_for_| is 0. |
| 234 MaybeStopWaitingForJobsOnIOThread(); | 234 MaybeStopWaitingForJobsOnIOThread(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // static | 237 // static |
| 238 void URLRequestTimeoutOnDemandJob::WaitForJobs(int num_jobs) { | 238 void URLRequestTimeoutOnDemandJob::WaitForJobs(int num_jobs) { |
| 239 content::BrowserThread::PostTask( | 239 content::BrowserThread::PostTask( |
| 240 content::BrowserThread::IO, FROM_HERE, | 240 content::BrowserThread::IO, FROM_HERE, |
| 241 base::Bind(&URLRequestTimeoutOnDemandJob::WaitForJobsOnIOThread, | 241 base::BindOnce(&URLRequestTimeoutOnDemandJob::WaitForJobsOnIOThread, |
| 242 num_jobs)); | 242 num_jobs)); |
| 243 content::RunMessageLoop(); | 243 content::RunMessageLoop(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // static | 246 // static |
| 247 void URLRequestTimeoutOnDemandJob::FailJobs(int expected_num_jobs) { | 247 void URLRequestTimeoutOnDemandJob::FailJobs(int expected_num_jobs) { |
| 248 content::BrowserThread::PostTask( | 248 content::BrowserThread::PostTask( |
| 249 content::BrowserThread::IO, FROM_HERE, | 249 content::BrowserThread::IO, FROM_HERE, |
| 250 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, | 250 base::BindOnce(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, |
| 251 expected_num_jobs, FAIL_JOBS, net::SSLInfo())); | 251 expected_num_jobs, FAIL_JOBS, net::SSLInfo())); |
| 252 } | 252 } |
| 253 | 253 |
| 254 // static | 254 // static |
| 255 void URLRequestTimeoutOnDemandJob::FailJobsWithCertError( | 255 void URLRequestTimeoutOnDemandJob::FailJobsWithCertError( |
| 256 int expected_num_jobs, | 256 int expected_num_jobs, |
| 257 const net::SSLInfo& ssl_info) { | 257 const net::SSLInfo& ssl_info) { |
| 258 content::BrowserThread::PostTask( | 258 content::BrowserThread::PostTask( |
| 259 content::BrowserThread::IO, FROM_HERE, | 259 content::BrowserThread::IO, FROM_HERE, |
| 260 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, | 260 base::BindOnce(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, |
| 261 expected_num_jobs, FAIL_JOBS_WITH_CERT_ERROR, ssl_info)); | 261 expected_num_jobs, FAIL_JOBS_WITH_CERT_ERROR, ssl_info)); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // static | 264 // static |
| 265 void URLRequestTimeoutOnDemandJob::AbandonJobs(int expected_num_jobs) { | 265 void URLRequestTimeoutOnDemandJob::AbandonJobs(int expected_num_jobs) { |
| 266 content::BrowserThread::PostTask( | 266 content::BrowserThread::PostTask( |
| 267 content::BrowserThread::IO, FROM_HERE, | 267 content::BrowserThread::IO, FROM_HERE, |
| 268 base::Bind(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, | 268 base::BindOnce(&URLRequestTimeoutOnDemandJob::FailOrAbandonJobsOnIOThread, |
| 269 expected_num_jobs, ABANDON_JOBS, net::SSLInfo())); | 269 expected_num_jobs, ABANDON_JOBS, net::SSLInfo())); |
| 270 } | 270 } |
| 271 | 271 |
| 272 URLRequestTimeoutOnDemandJob::URLRequestTimeoutOnDemandJob( | 272 URLRequestTimeoutOnDemandJob::URLRequestTimeoutOnDemandJob( |
| 273 net::URLRequest* request, net::NetworkDelegate* network_delegate) | 273 net::URLRequest* request, net::NetworkDelegate* network_delegate) |
| 274 : net::URLRequestJob(request, network_delegate), | 274 : net::URLRequestJob(request, network_delegate), |
| 275 next_job_(NULL) { | 275 next_job_(NULL) { |
| 276 } | 276 } |
| 277 | 277 |
| 278 URLRequestTimeoutOnDemandJob::~URLRequestTimeoutOnDemandJob() { | 278 URLRequestTimeoutOnDemandJob::~URLRequestTimeoutOnDemandJob() { |
| 279 // All hanging jobs should have failed or been abandoned before being | 279 // All hanging jobs should have failed or been abandoned before being |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 // these are just references. | 422 // these are just references. |
| 423 std::vector<Interceptor*> interceptors_; | 423 std::vector<Interceptor*> interceptors_; |
| 424 bool behind_captive_portal_; | 424 bool behind_captive_portal_; |
| 425 | 425 |
| 426 DISALLOW_COPY_AND_ASSIGN(URLRequestMockCaptivePortalJobFactory); | 426 DISALLOW_COPY_AND_ASSIGN(URLRequestMockCaptivePortalJobFactory); |
| 427 }; | 427 }; |
| 428 | 428 |
| 429 void URLRequestMockCaptivePortalJobFactory::AddUrlHandlers() { | 429 void URLRequestMockCaptivePortalJobFactory::AddUrlHandlers() { |
| 430 content::BrowserThread::PostTask( | 430 content::BrowserThread::PostTask( |
| 431 content::BrowserThread::IO, FROM_HERE, | 431 content::BrowserThread::IO, FROM_HERE, |
| 432 base::Bind( | 432 base::BindOnce( |
| 433 &URLRequestMockCaptivePortalJobFactory::AddUrlHandlersOnIOThread, | 433 &URLRequestMockCaptivePortalJobFactory::AddUrlHandlersOnIOThread, |
| 434 base::Unretained(this))); | 434 base::Unretained(this))); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal( | 437 void URLRequestMockCaptivePortalJobFactory::SetBehindCaptivePortal( |
| 438 bool behind_captive_portal) { | 438 bool behind_captive_portal) { |
| 439 content::BrowserThread::PostTask( | 439 content::BrowserThread::PostTask( |
| 440 content::BrowserThread::IO, FROM_HERE, | 440 content::BrowserThread::IO, FROM_HERE, |
| 441 base::Bind(&URLRequestMockCaptivePortalJobFactory:: | 441 base::BindOnce(&URLRequestMockCaptivePortalJobFactory:: |
| 442 SetBehindCaptivePortalOnIOThread, | 442 SetBehindCaptivePortalOnIOThread, |
| 443 base::Unretained(this), behind_captive_portal)); | 443 base::Unretained(this), behind_captive_portal)); |
| 444 } | 444 } |
| 445 | 445 |
| 446 std::unique_ptr<net::URLRequestInterceptor> | 446 std::unique_ptr<net::URLRequestInterceptor> |
| 447 URLRequestMockCaptivePortalJobFactory::CreateInterceptor() { | 447 URLRequestMockCaptivePortalJobFactory::CreateInterceptor() { |
| 448 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 448 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 449 std::unique_ptr<Interceptor> interceptor( | 449 std::unique_ptr<Interceptor> interceptor( |
| 450 new Interceptor(behind_captive_portal_)); | 450 new Interceptor(behind_captive_portal_)); |
| 451 interceptors_.push_back(interceptor.get()); | 451 interceptors_.push_back(interceptor.get()); |
| 452 return std::move(interceptor); | 452 return std::move(interceptor); |
| 453 } | 453 } |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBrowserTest); | 1099 DISALLOW_COPY_AND_ASSIGN(CaptivePortalBrowserTest); |
| 1100 }; | 1100 }; |
| 1101 | 1101 |
| 1102 CaptivePortalBrowserTest::CaptivePortalBrowserTest() { | 1102 CaptivePortalBrowserTest::CaptivePortalBrowserTest() { |
| 1103 } | 1103 } |
| 1104 | 1104 |
| 1105 void CaptivePortalBrowserTest::SetUpOnMainThread() { | 1105 void CaptivePortalBrowserTest::SetUpOnMainThread() { |
| 1106 // Enable mock requests. | 1106 // Enable mock requests. |
| 1107 content::BrowserThread::PostTask( | 1107 content::BrowserThread::PostTask( |
| 1108 content::BrowserThread::IO, FROM_HERE, | 1108 content::BrowserThread::IO, FROM_HERE, |
| 1109 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 1109 base::BindOnce(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
| 1110 factory_.AddUrlHandlers(); | 1110 factory_.AddUrlHandlers(); |
| 1111 | 1111 |
| 1112 // Double-check that the captive portal service isn't enabled by default for | 1112 // Double-check that the captive portal service isn't enabled by default for |
| 1113 // browser tests. | 1113 // browser tests. |
| 1114 EXPECT_EQ(CaptivePortalService::DISABLED_FOR_TESTING, | 1114 EXPECT_EQ(CaptivePortalService::DISABLED_FOR_TESTING, |
| 1115 CaptivePortalService::get_state_for_testing()); | 1115 CaptivePortalService::get_state_for_testing()); |
| 1116 | 1116 |
| 1117 CaptivePortalService::set_state_for_testing( | 1117 CaptivePortalService::set_state_for_testing( |
| 1118 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); | 1118 CaptivePortalService::SKIP_OS_CHECK_FOR_TESTING); |
| 1119 EnableCaptivePortalDetection(browser()->profile(), true); | 1119 EnableCaptivePortalDetection(browser()->profile(), true); |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2794 // A captive portal is then detected, and a login tab opened, before logging | 2794 // A captive portal is then detected, and a login tab opened, before logging |
| 2795 // in. | 2795 // in. |
| 2796 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HstsLogin) { | 2796 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HstsLogin) { |
| 2797 GURL::Replacements replacements; | 2797 GURL::Replacements replacements; |
| 2798 replacements.SetSchemeStr("http"); | 2798 replacements.SetSchemeStr("http"); |
| 2799 GURL http_timeout_url = GURL(kMockHttpsUrl).ReplaceComponents(replacements); | 2799 GURL http_timeout_url = GURL(kMockHttpsUrl).ReplaceComponents(replacements); |
| 2800 | 2800 |
| 2801 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_TIMED_OUT); | 2801 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_TIMED_OUT); |
| 2802 content::BrowserThread::PostTask( | 2802 content::BrowserThread::PostTask( |
| 2803 content::BrowserThread::IO, FROM_HERE, | 2803 content::BrowserThread::IO, FROM_HERE, |
| 2804 base::Bind(&AddHstsHost, | 2804 base::BindOnce( |
| 2805 base::RetainedRef(browser()->profile()->GetRequestContext()), | 2805 &AddHstsHost, |
| 2806 http_timeout_url.host())); | 2806 base::RetainedRef(browser()->profile()->GetRequestContext()), |
| 2807 http_timeout_url.host())); |
| 2807 | 2808 |
| 2808 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); | 2809 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); |
| 2809 Login(browser(), 1, 0); | 2810 Login(browser(), 1, 0); |
| 2810 FailLoadsAfterLogin(browser(), 1); | 2811 FailLoadsAfterLogin(browser(), 1); |
| 2811 } | 2812 } |
| 2812 | 2813 |
| 2813 // A slow SSL load starts. The reloader triggers a captive portal check, finds a | 2814 // A slow SSL load starts. The reloader triggers a captive portal check, finds a |
| 2814 // captive portal. The SSL commits with a cert error, triggering another captive | 2815 // captive portal. The SSL commits with a cert error, triggering another captive |
| 2815 // portal check. | 2816 // portal check. |
| 2816 // The second check finds no captive portal. The reloader triggers a reload at | 2817 // The second check finds no captive portal. The reloader triggers a reload at |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2842 | 2843 |
| 2843 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2844 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
| 2844 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2845 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
| 2845 | 2846 |
| 2846 WaitForInterstitialAttach(broken_tab_contents); | 2847 WaitForInterstitialAttach(broken_tab_contents); |
| 2847 portal_observer.WaitForResults(1); | 2848 portal_observer.WaitForResults(1); |
| 2848 | 2849 |
| 2849 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2850 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
| 2850 GetInterstitialType(broken_tab_contents)); | 2851 GetInterstitialType(broken_tab_contents)); |
| 2851 } | 2852 } |
| OLD | NEW |