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> |
11 | 11 |
12 #include "base/base_switches.h" | 12 #include "base/base_switches.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/task_scheduler/post_task.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "chrome/browser/captive_portal/captive_portal_service.h" | 24 #include "chrome/browser/captive_portal/captive_portal_service.h" |
25 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 25 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
26 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 26 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
27 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" | 27 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" |
28 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
29 #include "chrome/browser/net/url_request_mock_util.h" | 29 #include "chrome/browser/net/url_request_mock_util.h" |
30 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | 31 #include "chrome/browser/ssl/captive_portal_blocking_page.h" |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 for (auto* interceptor : interceptors_) | 475 for (auto* interceptor : interceptors_) |
476 interceptor->SetBehindCaptivePortal(behind_captive_portal); | 476 interceptor->SetBehindCaptivePortal(behind_captive_portal); |
477 } | 477 } |
478 | 478 |
479 net::URLRequestJob* | 479 net::URLRequestJob* |
480 URLRequestMockCaptivePortalJobFactory::Interceptor::MaybeInterceptRequest( | 480 URLRequestMockCaptivePortalJobFactory::Interceptor::MaybeInterceptRequest( |
481 net::URLRequest* request, | 481 net::URLRequest* request, |
482 net::NetworkDelegate* network_delegate) const { | 482 net::NetworkDelegate* network_delegate) const { |
483 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 483 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
484 | 484 |
| 485 const base::TaskTraits kTraits = base::TaskTraits().MayBlock(); |
| 486 |
485 // The PathService is threadsafe. | 487 // The PathService is threadsafe. |
486 base::FilePath root_http; | 488 base::FilePath root_http; |
487 PathService::Get(chrome::DIR_TEST_DATA, &root_http); | 489 PathService::Get(chrome::DIR_TEST_DATA, &root_http); |
488 | 490 |
489 if (request->url() == kMockHttpsUrl || | 491 if (request->url() == kMockHttpsUrl || |
490 request->url() == kMockHttpsUrl2) { | 492 request->url() == kMockHttpsUrl2) { |
491 if (behind_captive_portal_) | 493 if (behind_captive_portal_) |
492 return new URLRequestTimeoutOnDemandJob(request, network_delegate); | 494 return new URLRequestTimeoutOnDemandJob(request, network_delegate); |
493 // Once logged in to the portal, HTTPS requests return the page that was | 495 // Once logged in to the portal, HTTPS requests return the page that was |
494 // actually requested. | 496 // actually requested. |
495 return new URLRequestMockHTTPJob( | 497 return new URLRequestMockHTTPJob( |
496 request, | 498 request, network_delegate, |
497 network_delegate, | |
498 root_http.Append(FILE_PATH_LITERAL("title2.html")), | 499 root_http.Append(FILE_PATH_LITERAL("title2.html")), |
499 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 500 base::CreateTaskRunnerWithTraits(kTraits)); |
500 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
501 } else if (request->url() == kMockHttpsQuickTimeoutUrl) { | 501 } else if (request->url() == kMockHttpsQuickTimeoutUrl) { |
502 if (behind_captive_portal_) | 502 if (behind_captive_portal_) |
503 return new URLRequestFailedJob( | 503 return new URLRequestFailedJob( |
504 request, network_delegate, net::ERR_CONNECTION_TIMED_OUT); | 504 request, network_delegate, net::ERR_CONNECTION_TIMED_OUT); |
505 // Once logged in to the portal, HTTPS requests return the page that was | 505 // Once logged in to the portal, HTTPS requests return the page that was |
506 // actually requested. | 506 // actually requested. |
507 return new URLRequestMockHTTPJob( | 507 return new URLRequestMockHTTPJob( |
508 request, | 508 request, network_delegate, |
509 network_delegate, | |
510 root_http.Append(FILE_PATH_LITERAL("title2.html")), | 509 root_http.Append(FILE_PATH_LITERAL("title2.html")), |
511 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 510 base::CreateTaskRunnerWithTraits(kTraits)); |
512 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
513 } else { | 511 } else { |
514 // The URL should be the captive portal test URL. | 512 // The URL should be the captive portal test URL. |
515 EXPECT_TRUE(request->url() == kMockCaptivePortalTestUrl || | 513 EXPECT_TRUE(request->url() == kMockCaptivePortalTestUrl || |
516 request->url() == kMockCaptivePortal511Url); | 514 request->url() == kMockCaptivePortal511Url); |
517 | 515 |
518 if (behind_captive_portal_) { | 516 if (behind_captive_portal_) { |
519 // Prior to logging in to the portal, the HTTP test URLs are intercepted | 517 // Prior to logging in to the portal, the HTTP test URLs are intercepted |
520 // by the captive portal. | 518 // by the captive portal. |
521 if (request->url() == kMockCaptivePortal511Url) { | 519 if (request->url() == kMockCaptivePortal511Url) { |
522 return new URLRequestMockHTTPJob( | 520 return new URLRequestMockHTTPJob( |
523 request, | 521 request, network_delegate, |
524 network_delegate, | |
525 root_http.Append(FILE_PATH_LITERAL("captive_portal/page511.html")), | 522 root_http.Append(FILE_PATH_LITERAL("captive_portal/page511.html")), |
526 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 523 base::CreateTaskRunnerWithTraits(kTraits)); |
527 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
528 } | 524 } |
529 return new URLRequestMockHTTPJob( | 525 return new URLRequestMockHTTPJob( |
530 request, | 526 request, network_delegate, |
531 network_delegate, | |
532 root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html")), | 527 root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html")), |
533 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 528 base::CreateTaskRunnerWithTraits(kTraits)); |
534 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
535 } | 529 } |
536 | 530 |
537 // After logging in to the portal, the test URLs return a 204 response. | 531 // After logging in to the portal, the test URLs return a 204 response. |
538 return new URLRequestMockHTTPJob( | 532 return new URLRequestMockHTTPJob( |
539 request, | 533 request, network_delegate, |
540 network_delegate, | |
541 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")), | 534 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")), |
542 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 535 base::CreateTaskRunnerWithTraits(kTraits)); |
543 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
544 } | 536 } |
545 } | 537 } |
546 | 538 |
547 // Creates a server-side redirect for use with the TestServer. | 539 // Creates a server-side redirect for use with the TestServer. |
548 std::string CreateServerRedirect(const std::string& dest_url) { | 540 std::string CreateServerRedirect(const std::string& dest_url) { |
549 const char* const kServerRedirectBase = "/server-redirect?"; | 541 const char* const kServerRedirectBase = "/server-redirect?"; |
550 return kServerRedirectBase + dest_url; | 542 return kServerRedirectBase + dest_url; |
551 } | 543 } |
552 | 544 |
553 // Returns the total number of loading tabs across all Browsers, for all | 545 // Returns the total number of loading tabs across all Browsers, for all |
(...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2843 | 2835 |
2844 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2836 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
2845 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2837 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
2846 | 2838 |
2847 WaitForInterstitialAttach(broken_tab_contents); | 2839 WaitForInterstitialAttach(broken_tab_contents); |
2848 portal_observer.WaitForResults(1); | 2840 portal_observer.WaitForResults(1); |
2849 | 2841 |
2850 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2842 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
2851 GetInterstitialType(broken_tab_contents)); | 2843 GetInterstitialType(broken_tab_contents)); |
2852 } | 2844 } |
OLD | NEW |