| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/navigation_controller.h" | 36 #include "content/public/browser/navigation_controller.h" |
| 37 #include "content/public/browser/notification_observer.h" | 37 #include "content/public/browser/notification_observer.h" |
| 38 #include "content/public/browser/notification_registrar.h" | 38 #include "content/public/browser/notification_registrar.h" |
| 39 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 40 #include "content/public/browser/notification_types.h" | 40 #include "content/public/browser/notification_types.h" |
| 41 #include "content/public/browser/render_frame_host.h" | 41 #include "content/public/browser/render_frame_host.h" |
| 42 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
| 43 #include "content/public/common/url_constants.h" | 43 #include "content/public/common/url_constants.h" |
| 44 #include "content/test/net/url_request_failed_job.h" | 44 #include "content/test/net/url_request_failed_job.h" |
| 45 #include "content/test/net/url_request_mock_http_job.h" | |
| 46 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 47 #include "net/http/transport_security_state.h" | 46 #include "net/http/transport_security_state.h" |
| 47 #include "net/test/url_request/url_request_mock_http_job.h" |
| 48 #include "net/url_request/url_request.h" | 48 #include "net/url_request/url_request.h" |
| 49 #include "net/url_request/url_request_context.h" | 49 #include "net/url_request/url_request_context.h" |
| 50 #include "net/url_request/url_request_context_getter.h" | 50 #include "net/url_request/url_request_context_getter.h" |
| 51 #include "net/url_request/url_request_filter.h" | 51 #include "net/url_request/url_request_filter.h" |
| 52 #include "net/url_request/url_request_job.h" | 52 #include "net/url_request/url_request_job.h" |
| 53 #include "net/url_request/url_request_status.h" | 53 #include "net/url_request/url_request_status.h" |
| 54 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
| 55 | 55 |
| 56 using captive_portal::CaptivePortalResult; | 56 using captive_portal::CaptivePortalResult; |
| 57 using content::BrowserThread; | 57 using content::BrowserThread; |
| 58 using content::URLRequestFailedJob; | 58 using content::URLRequestFailedJob; |
| 59 using content::URLRequestMockHTTPJob; | 59 using net::URLRequestMockHTTPJob; |
| 60 using content::WebContents; | 60 using content::WebContents; |
| 61 | 61 |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 // Path of the fake login page, when using the TestServer. | 64 // Path of the fake login page, when using the TestServer. |
| 65 const char* const kTestServerLoginPath = "files/captive_portal/login.html"; | 65 const char* const kTestServerLoginPath = "files/captive_portal/login.html"; |
| 66 | 66 |
| 67 // Path of a page with an iframe that has a mock SSL timeout, when using the | 67 // Path of a page with an iframe that has a mock SSL timeout, when using the |
| 68 // TestServer. | 68 // TestServer. |
| 69 const char* const kTestServerIframeTimeoutPath = | 69 const char* const kTestServerIframeTimeoutPath = |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 | 420 |
| 421 if (request->url() == GURL(kMockHttpsUrl) || | 421 if (request->url() == GURL(kMockHttpsUrl) || |
| 422 request->url() == GURL(kMockHttpsUrl2)) { | 422 request->url() == GURL(kMockHttpsUrl2)) { |
| 423 if (behind_captive_portal_) | 423 if (behind_captive_portal_) |
| 424 return new URLRequestTimeoutOnDemandJob(request, network_delegate); | 424 return new URLRequestTimeoutOnDemandJob(request, network_delegate); |
| 425 // Once logged in to the portal, HTTPS requests return the page that was | 425 // Once logged in to the portal, HTTPS requests return the page that was |
| 426 // actually requested. | 426 // actually requested. |
| 427 return new URLRequestMockHTTPJob( | 427 return new URLRequestMockHTTPJob( |
| 428 request, | 428 request, |
| 429 network_delegate, | 429 network_delegate, |
| 430 root_http.Append(FILE_PATH_LITERAL("title2.html"))); | 430 root_http.Append(FILE_PATH_LITERAL("title2.html")), |
| 431 content::BrowserThread::GetBlockingPool()-> |
| 432 GetTaskRunnerWithShutdownBehavior( |
| 433 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 431 } else if (request->url() == GURL(kMockHttpsQuickTimeoutUrl)) { | 434 } else if (request->url() == GURL(kMockHttpsQuickTimeoutUrl)) { |
| 432 if (behind_captive_portal_) | 435 if (behind_captive_portal_) |
| 433 return new URLRequestFailedJob( | 436 return new URLRequestFailedJob( |
| 434 request, network_delegate, net::ERR_CONNECTION_TIMED_OUT); | 437 request, network_delegate, net::ERR_CONNECTION_TIMED_OUT); |
| 435 // Once logged in to the portal, HTTPS requests return the page that was | 438 // Once logged in to the portal, HTTPS requests return the page that was |
| 436 // actually requested. | 439 // actually requested. |
| 437 return new URLRequestMockHTTPJob( | 440 return new URLRequestMockHTTPJob( |
| 438 request, | 441 request, |
| 439 network_delegate, | 442 network_delegate, |
| 440 root_http.Append(FILE_PATH_LITERAL("title2.html"))); | 443 root_http.Append(FILE_PATH_LITERAL("title2.html")), |
| 444 content::BrowserThread::GetBlockingPool()-> |
| 445 GetTaskRunnerWithShutdownBehavior( |
| 446 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 441 } else { | 447 } else { |
| 442 // The URL should be the captive portal test URL. | 448 // The URL should be the captive portal test URL. |
| 443 EXPECT_TRUE(GURL(kMockCaptivePortalTestUrl) == request->url() || | 449 EXPECT_TRUE(GURL(kMockCaptivePortalTestUrl) == request->url() || |
| 444 GURL(kMockCaptivePortal511Url) == request->url()); | 450 GURL(kMockCaptivePortal511Url) == request->url()); |
| 445 | 451 |
| 446 if (behind_captive_portal_) { | 452 if (behind_captive_portal_) { |
| 447 // Prior to logging in to the portal, the HTTP test URLs are intercepted | 453 // Prior to logging in to the portal, the HTTP test URLs are intercepted |
| 448 // by the captive portal. | 454 // by the captive portal. |
| 449 if (GURL(kMockCaptivePortal511Url) == request->url()) { | 455 if (GURL(kMockCaptivePortal511Url) == request->url()) { |
| 450 return new URLRequestMockHTTPJob( | 456 return new URLRequestMockHTTPJob( |
| 451 request, | 457 request, |
| 452 network_delegate, | 458 network_delegate, |
| 453 root_http.Append(FILE_PATH_LITERAL("captive_portal/page511.html"))); | 459 root_http.Append(FILE_PATH_LITERAL("captive_portal/page511.html")), |
| 460 content::BrowserThread::GetBlockingPool()-> |
| 461 GetTaskRunnerWithShutdownBehavior( |
| 462 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 454 } | 463 } |
| 455 return new URLRequestMockHTTPJob( | 464 return new URLRequestMockHTTPJob( |
| 456 request, | 465 request, |
| 457 network_delegate, | 466 network_delegate, |
| 458 root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html"))); | 467 root_http.Append(FILE_PATH_LITERAL("captive_portal/login.html")), |
| 468 content::BrowserThread::GetBlockingPool()-> |
| 469 GetTaskRunnerWithShutdownBehavior( |
| 470 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 459 } | 471 } |
| 460 | 472 |
| 461 // After logging in to the portal, the test URLs return a 204 response. | 473 // After logging in to the portal, the test URLs return a 204 response. |
| 462 return new URLRequestMockHTTPJob( | 474 return new URLRequestMockHTTPJob( |
| 463 request, | 475 request, |
| 464 network_delegate, | 476 network_delegate, |
| 465 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html"))); | 477 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")), |
| 478 content::BrowserThread::GetBlockingPool()-> |
| 479 GetTaskRunnerWithShutdownBehavior( |
| 480 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 466 } | 481 } |
| 467 } | 482 } |
| 468 | 483 |
| 469 // Creates a server-side redirect for use with the TestServer. | 484 // Creates a server-side redirect for use with the TestServer. |
| 470 std::string CreateServerRedirect(const std::string& dest_url) { | 485 std::string CreateServerRedirect(const std::string& dest_url) { |
| 471 const char* const kServerRedirectBase = "server-redirect?"; | 486 const char* const kServerRedirectBase = "server-redirect?"; |
| 472 return kServerRedirectBase + dest_url; | 487 return kServerRedirectBase + dest_url; |
| 473 } | 488 } |
| 474 | 489 |
| 475 // Returns the total number of loading tabs across all Browsers, for all | 490 // Returns the total number of loading tabs across all Browsers, for all |
| (...skipping 1718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2194 content::BrowserThread::PostTask( | 2209 content::BrowserThread::PostTask( |
| 2195 content::BrowserThread::IO, FROM_HERE, | 2210 content::BrowserThread::IO, FROM_HERE, |
| 2196 base::Bind(&AddHstsHost, | 2211 base::Bind(&AddHstsHost, |
| 2197 make_scoped_refptr(browser()->profile()->GetRequestContext()), | 2212 make_scoped_refptr(browser()->profile()->GetRequestContext()), |
| 2198 http_timeout_url.host())); | 2213 http_timeout_url.host())); |
| 2199 | 2214 |
| 2200 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); | 2215 SlowLoadBehindCaptivePortal(browser(), true, http_timeout_url, 1, 1); |
| 2201 Login(browser(), 1, 0); | 2216 Login(browser(), 1, 0); |
| 2202 FailLoadsAfterLogin(browser(), 1); | 2217 FailLoadsAfterLogin(browser(), 1); |
| 2203 } | 2218 } |
| OLD | NEW |