| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "content/public/browser/notification_types.h" | 51 #include "content/public/browser/notification_types.h" |
| 52 #include "content/public/browser/render_frame_host.h" | 52 #include "content/public/browser/render_frame_host.h" |
| 53 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 54 #include "content/public/common/url_constants.h" | 54 #include "content/public/common/url_constants.h" |
| 55 #include "content/public/test/browser_test_utils.h" | 55 #include "content/public/test/browser_test_utils.h" |
| 56 #include "net/base/net_errors.h" | 56 #include "net/base/net_errors.h" |
| 57 #include "net/base/test_data_directory.h" | 57 #include "net/base/test_data_directory.h" |
| 58 #include "net/cert/x509_certificate.h" | 58 #include "net/cert/x509_certificate.h" |
| 59 #include "net/http/transport_security_state.h" | 59 #include "net/http/transport_security_state.h" |
| 60 #include "net/test/cert_test_util.h" | 60 #include "net/test/cert_test_util.h" |
| 61 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 61 #include "net/test/url_request/url_request_failed_job.h" | 62 #include "net/test/url_request/url_request_failed_job.h" |
| 62 #include "net/test/url_request/url_request_mock_http_job.h" | 63 #include "net/test/url_request/url_request_mock_http_job.h" |
| 63 #include "net/url_request/url_request.h" | 64 #include "net/url_request/url_request.h" |
| 64 #include "net/url_request/url_request_context.h" | 65 #include "net/url_request/url_request_context.h" |
| 65 #include "net/url_request/url_request_context_getter.h" | 66 #include "net/url_request/url_request_context_getter.h" |
| 66 #include "net/url_request/url_request_filter.h" | 67 #include "net/url_request/url_request_filter.h" |
| 67 #include "net/url_request/url_request_interceptor.h" | 68 #include "net/url_request/url_request_interceptor.h" |
| 68 #include "net/url_request/url_request_job.h" | 69 #include "net/url_request/url_request_job.h" |
| 69 #include "net/url_request/url_request_status.h" | 70 #include "net/url_request/url_request_status.h" |
| 70 #include "testing/gtest/include/gtest/gtest.h" | 71 #include "testing/gtest/include/gtest/gtest.h" |
| 71 | 72 |
| 72 using captive_portal::CaptivePortalResult; | 73 using captive_portal::CaptivePortalResult; |
| 73 using content::BrowserThread; | 74 using content::BrowserThread; |
| 74 using content::WebContents; | 75 using content::WebContents; |
| 75 using net::URLRequestFailedJob; | 76 using net::URLRequestFailedJob; |
| 76 using net::URLRequestMockHTTPJob; | 77 using net::URLRequestMockHTTPJob; |
| 77 | 78 |
| 78 namespace { | 79 namespace { |
| 79 | 80 |
| 80 // Path of the fake login page, when using the TestServer. | 81 // Path of the fake login page, when using the TestServer. |
| 81 const char* const kTestServerLoginPath = "files/captive_portal/login.html"; | 82 const char* const kTestServerLoginPath = "/captive_portal/login.html"; |
| 82 | 83 |
| 83 // Path of a page with an iframe that has a mock SSL timeout, when using the | 84 // Path of a page with an iframe that has a mock SSL timeout, when using the |
| 84 // TestServer. | 85 // TestServer. |
| 85 const char* const kTestServerIframeTimeoutPath = | 86 const char* const kTestServerIframeTimeoutPath = |
| 86 "files/captive_portal/iframe_timeout.html"; | 87 "/captive_portal/iframe_timeout.html"; |
| 87 | 88 |
| 88 // The following URLs each have two different behaviors, depending on whether | 89 // The following URLs each have two different behaviors, depending on whether |
| 89 // URLRequestMockCaptivePortalJobFactory is currently simulating the presence | 90 // URLRequestMockCaptivePortalJobFactory is currently simulating the presence |
| 90 // of a captive portal or not. They use different domains so that HSTS can be | 91 // of a captive portal or not. They use different domains so that HSTS can be |
| 91 // applied to them independently. | 92 // applied to them independently. |
| 92 | 93 |
| 93 // A mock URL for the CaptivePortalService's |test_url|. When behind a captive | 94 // A mock URL for the CaptivePortalService's |test_url|. When behind a captive |
| 94 // portal, this URL returns a mock login page. When connected to the Internet, | 95 // portal, this URL returns a mock login page. When connected to the Internet, |
| 95 // it returns a 204 response. Uses the name of the login file so that reloading | 96 // it returns a 204 response. Uses the name of the login file so that reloading |
| 96 // it will not request a different URL. | 97 // it will not request a different URL. |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 request, | 534 request, |
| 534 network_delegate, | 535 network_delegate, |
| 535 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")), | 536 root_http.Append(FILE_PATH_LITERAL("captive_portal/page204.html")), |
| 536 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 537 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 537 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 538 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 538 } | 539 } |
| 539 } | 540 } |
| 540 | 541 |
| 541 // Creates a server-side redirect for use with the TestServer. | 542 // Creates a server-side redirect for use with the TestServer. |
| 542 std::string CreateServerRedirect(const std::string& dest_url) { | 543 std::string CreateServerRedirect(const std::string& dest_url) { |
| 543 const char* const kServerRedirectBase = "server-redirect?"; | 544 const char* const kServerRedirectBase = "/server-redirect?"; |
| 544 return kServerRedirectBase + dest_url; | 545 return kServerRedirectBase + dest_url; |
| 545 } | 546 } |
| 546 | 547 |
| 547 // Returns the total number of loading tabs across all Browsers, for all | 548 // Returns the total number of loading tabs across all Browsers, for all |
| 548 // Profiles. | 549 // Profiles. |
| 549 int NumLoadingTabs() { | 550 int NumLoadingTabs() { |
| 550 int num_loading_tabs = 0; | 551 int num_loading_tabs = 0; |
| 551 for (TabContentsIterator it; !it.done(); it.Next()) { | 552 for (TabContentsIterator it; !it.done(); it.Next()) { |
| 552 if (it->IsLoading()) | 553 if (it->IsLoading()) |
| 553 ++num_loading_tabs; | 554 ++num_loading_tabs; |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 // Make sure there's no check for a captive portal on HTTPS errors other than | 1821 // Make sure there's no check for a captive portal on HTTPS errors other than |
| 1821 // timeouts, when they preempt the slow load timer. | 1822 // timeouts, when they preempt the slow load timer. |
| 1822 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpsNonTimeoutError) { | 1823 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpsNonTimeoutError) { |
| 1823 GURL url = URLRequestFailedJob::GetMockHttpsUrl(net::ERR_UNEXPECTED); | 1824 GURL url = URLRequestFailedJob::GetMockHttpsUrl(net::ERR_UNEXPECTED); |
| 1824 NavigateToPageExpectNoTest(browser(), url, 1); | 1825 NavigateToPageExpectNoTest(browser(), url, 1); |
| 1825 } | 1826 } |
| 1826 | 1827 |
| 1827 // Make sure no captive portal test triggers on HTTPS timeouts of iframes. | 1828 // Make sure no captive portal test triggers on HTTPS timeouts of iframes. |
| 1828 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpsIframeTimeout) { | 1829 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpsIframeTimeout) { |
| 1829 // Use an HTTPS server for the top level page. | 1830 // Use an HTTPS server for the top level page. |
| 1830 net::SpawnedTestServer https_server( | 1831 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 1831 net::SpawnedTestServer::TYPE_HTTPS, net::SpawnedTestServer::kLocalhost, | 1832 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1832 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1833 ASSERT_TRUE(https_server.Start()); | 1833 ASSERT_TRUE(https_server.Start()); |
| 1834 | 1834 |
| 1835 GURL url = https_server.GetURL(kTestServerIframeTimeoutPath); | 1835 GURL url = https_server.GetURL(kTestServerIframeTimeoutPath); |
| 1836 NavigateToPageExpectNoTest(browser(), url, 1); | 1836 NavigateToPageExpectNoTest(browser(), url, 1); |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 // Check the captive portal result when the test request reports a network | 1839 // Check the captive portal result when the test request reports a network |
| 1840 // error. The check is triggered by a slow loading page, and the page | 1840 // error. The check is triggered by a slow loading page, and the page |
| 1841 // errors out only after getting a captive portal result. | 1841 // errors out only after getting a captive portal result. |
| 1842 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RequestFails) { | 1842 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RequestFails) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1860 EnableCaptivePortalDetection(browser()->profile(), false); | 1860 EnableCaptivePortalDetection(browser()->profile(), false); |
| 1861 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED); | 1861 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED); |
| 1862 } | 1862 } |
| 1863 | 1863 |
| 1864 // Checks that we look for a captive portal on HTTPS timeouts and don't reload | 1864 // Checks that we look for a captive portal on HTTPS timeouts and don't reload |
| 1865 // the error tab when the captive portal probe gets a 204 response, indicating | 1865 // the error tab when the captive portal probe gets a 204 response, indicating |
| 1866 // there is no captive portal. | 1866 // there is no captive portal. |
| 1867 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, InternetConnected) { | 1867 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, InternetConnected) { |
| 1868 // Can't just use SetBehindCaptivePortal(false), since then there wouldn't | 1868 // Can't just use SetBehindCaptivePortal(false), since then there wouldn't |
| 1869 // be a timeout. | 1869 // be a timeout. |
| 1870 ASSERT_TRUE(test_server()->Start()); | 1870 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1871 SetUpCaptivePortalService(browser()->profile(), | 1871 SetUpCaptivePortalService(browser()->profile(), |
| 1872 test_server()->GetURL("nocontent")); | 1872 embedded_test_server()->GetURL("/nocontent")); |
| 1873 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED); | 1873 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_INTERNET_CONNECTED); |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 // Checks that no login page is opened when the HTTP test URL redirects to an | 1876 // Checks that no login page is opened when the HTTP test URL redirects to an |
| 1877 // SSL certificate error. | 1877 // SSL certificate error. |
| 1878 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RedirectSSLCertError) { | 1878 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, RedirectSSLCertError) { |
| 1879 // Need an HTTP TestServer to handle a dynamically created server redirect. | 1879 // Need an HTTP TestServer to handle a dynamically created server redirect. |
| 1880 ASSERT_TRUE(test_server()->Start()); | 1880 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1881 | 1881 |
| 1882 net::SpawnedTestServer::SSLOptions ssl_options; | 1882 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 1883 ssl_options.server_certificate = | 1883 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 1884 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 1884 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1885 net::SpawnedTestServer https_server( | |
| 1886 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, | |
| 1887 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1888 ASSERT_TRUE(https_server.Start()); | 1885 ASSERT_TRUE(https_server.Start()); |
| 1889 | 1886 |
| 1890 GURL ssl_login_url = https_server.GetURL(kTestServerLoginPath); | 1887 GURL ssl_login_url = https_server.GetURL(kTestServerLoginPath); |
| 1891 | 1888 |
| 1892 CaptivePortalService* captive_portal_service = | 1889 CaptivePortalService* captive_portal_service = |
| 1893 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); | 1890 CaptivePortalServiceFactory::GetForProfile(browser()->profile()); |
| 1894 ASSERT_TRUE(captive_portal_service); | 1891 ASSERT_TRUE(captive_portal_service); |
| 1895 SetUpCaptivePortalService( | 1892 SetUpCaptivePortalService(browser()->profile(), |
| 1896 browser()->profile(), | 1893 embedded_test_server()->GetURL( |
| 1897 test_server()->GetURL(CreateServerRedirect(ssl_login_url.spec()))); | 1894 CreateServerRedirect(ssl_login_url.spec()))); |
| 1898 | 1895 |
| 1899 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_NO_RESPONSE); | 1896 SlowLoadNoCaptivePortal(browser(), captive_portal::RESULT_NO_RESPONSE); |
| 1900 } | 1897 } |
| 1901 | 1898 |
| 1902 // A slow SSL load triggers a captive portal check. The user logs on before | 1899 // A slow SSL load triggers a captive portal check. The user logs on before |
| 1903 // the SSL page times out. We wait for the timeout and subsequent reload. | 1900 // the SSL page times out. We wait for the timeout and subsequent reload. |
| 1904 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, Login) { | 1901 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, Login) { |
| 1905 // Load starts, detect captive portal and open up a login tab. | 1902 // Load starts, detect captive portal and open up a login tab. |
| 1906 SlowLoadBehindCaptivePortal(browser(), true); | 1903 SlowLoadBehindCaptivePortal(browser(), true); |
| 1907 | 1904 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1958 // This most likely won't happen, but should still work: | 1955 // This most likely won't happen, but should still work: |
| 1959 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { | 1956 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, LoginFastTimeout) { |
| 1960 FastTimeoutBehindCaptivePortal(browser(), true); | 1957 FastTimeoutBehindCaptivePortal(browser(), true); |
| 1961 Login(browser(), 0, 1); | 1958 Login(browser(), 0, 1); |
| 1962 } | 1959 } |
| 1963 | 1960 |
| 1964 // A cert error triggers a captive portal check and results in opening a login | 1961 // A cert error triggers a captive portal check and results in opening a login |
| 1965 // tab. | 1962 // tab. |
| 1966 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | 1963 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
| 1967 ShowCaptivePortalInterstitialOnCertError) { | 1964 ShowCaptivePortalInterstitialOnCertError) { |
| 1968 net::SpawnedTestServer::SSLOptions https_options; | 1965 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 1969 https_options.server_certificate = | 1966 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 1970 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 1967 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 1971 net::SpawnedTestServer https_server( | |
| 1972 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 1973 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 1974 ASSERT_TRUE(https_server.Start()); | 1968 ASSERT_TRUE(https_server.Start()); |
| 1975 | 1969 |
| 1976 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 1970 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 1977 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 1971 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 1978 | 1972 |
| 1979 // The path does not matter. | 1973 // The path does not matter. |
| 1980 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 1974 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
| 1981 int cert_error_tab_index = tab_strip_model->active_index(); | 1975 int cert_error_tab_index = tab_strip_model->active_index(); |
| 1982 // The interstitial should trigger a captive portal check when it opens, just | 1976 // The interstitial should trigger a captive portal check when it opens, just |
| 1983 // like navigating to kMockHttpsQuickTimeoutUrl. | 1977 // like navigating to kMockHttpsQuickTimeoutUrl. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 | 2040 |
| 2047 // Tests this scenario: | 2041 // Tests this scenario: |
| 2048 // - Portal probe requests are ignored, so that no captive portal result can | 2042 // - Portal probe requests are ignored, so that no captive portal result can |
| 2049 // arrive. | 2043 // arrive. |
| 2050 // - A cert error triggers an interstitial timer with a very long timeout. | 2044 // - A cert error triggers an interstitial timer with a very long timeout. |
| 2051 // - No captive portal results arrive, causing the tab to appear as loading | 2045 // - No captive portal results arrive, causing the tab to appear as loading |
| 2052 // indefinitely (because probe requests are ignored). | 2046 // indefinitely (because probe requests are ignored). |
| 2053 // - Stopping the page load shouldn't result in any interstitials. | 2047 // - Stopping the page load shouldn't result in any interstitials. |
| 2054 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | 2048 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
| 2055 InterstitialTimerStopNavigationWhileLoading) { | 2049 InterstitialTimerStopNavigationWhileLoading) { |
| 2056 net::SpawnedTestServer::SSLOptions https_options; | 2050 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2057 https_options.server_certificate = | 2051 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 2058 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 2052 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2059 net::SpawnedTestServer https_server( | |
| 2060 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 2061 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 2062 ASSERT_TRUE(https_server.Start()); | 2053 ASSERT_TRUE(https_server.Start()); |
| 2063 // The path does not matter. | 2054 // The path does not matter. |
| 2064 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 2055 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
| 2065 | 2056 |
| 2066 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2057 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 2067 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2058 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 2068 | 2059 |
| 2069 CaptivePortalObserver portal_observer1(browser()->profile()); | 2060 CaptivePortalObserver portal_observer1(browser()->profile()); |
| 2070 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2061 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
| 2071 | 2062 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 EXPECT_FALSE(CheckPending(browser())); | 2094 EXPECT_FALSE(CheckPending(browser())); |
| 2104 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2095 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2105 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2096 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
| 2106 GetStateOfTabReloaderAt(browser(), 0)); | 2097 GetStateOfTabReloaderAt(browser(), 0)); |
| 2107 } | 2098 } |
| 2108 | 2099 |
| 2109 // Same as above, but instead of stopping, the loading page is reloaded. The end | 2100 // Same as above, but instead of stopping, the loading page is reloaded. The end |
| 2110 // result is the same. (i.e. page load stops, no interstitials shown) | 2101 // result is the same. (i.e. page load stops, no interstitials shown) |
| 2111 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | 2102 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
| 2112 InterstitialTimerReloadWhileLoading) { | 2103 InterstitialTimerReloadWhileLoading) { |
| 2113 net::SpawnedTestServer::SSLOptions https_options; | 2104 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2114 https_options.server_certificate = | 2105 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 2115 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 2106 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2116 net::SpawnedTestServer https_server( | |
| 2117 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 2118 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 2119 ASSERT_TRUE(https_server.Start()); | 2107 ASSERT_TRUE(https_server.Start()); |
| 2120 // The path does not matter. | 2108 // The path does not matter. |
| 2121 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 2109 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
| 2122 | 2110 |
| 2123 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2111 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 2124 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2112 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 2125 | 2113 |
| 2126 CaptivePortalObserver portal_observer(browser()->profile()); | 2114 CaptivePortalObserver portal_observer(browser()->profile()); |
| 2127 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2115 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
| 2128 | 2116 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2151 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2164 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2152 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
| 2165 GetStateOfTabReloaderAt(browser(), 0)); | 2153 GetStateOfTabReloaderAt(browser(), 0)); |
| 2166 } | 2154 } |
| 2167 | 2155 |
| 2168 // Same as |InterstitialTimerReloadWhileLoading_NoSSLError|, but instead of | 2156 // Same as |InterstitialTimerReloadWhileLoading_NoSSLError|, but instead of |
| 2169 // reloading, the page is navigated away. The new page should load, and no | 2157 // reloading, the page is navigated away. The new page should load, and no |
| 2170 // interstitials should be shown. | 2158 // interstitials should be shown. |
| 2171 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, | 2159 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, |
| 2172 InterstitialTimerNavigateAwayWhileLoading) { | 2160 InterstitialTimerNavigateAwayWhileLoading) { |
| 2173 net::SpawnedTestServer::SSLOptions https_options; | 2161 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2174 https_options.server_certificate = | 2162 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 2175 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 2163 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2176 net::SpawnedTestServer https_server( | |
| 2177 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 2178 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 2179 ASSERT_TRUE(https_server.Start()); | 2164 ASSERT_TRUE(https_server.Start()); |
| 2180 // The path does not matter. | 2165 // The path does not matter. |
| 2181 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 2166 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
| 2182 | 2167 |
| 2183 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2168 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 2184 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2169 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 2185 | 2170 |
| 2186 CaptivePortalObserver portal_observer(browser()->profile()); | 2171 CaptivePortalObserver portal_observer(browser()->profile()); |
| 2187 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2172 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
| 2188 | 2173 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2233 } | 2218 } |
| 2234 | 2219 |
| 2235 // Same as above, but the hanging load is interrupted by a navigation to the | 2220 // Same as above, but the hanging load is interrupted by a navigation to the |
| 2236 // same page, this time committing the navigation. This should end up with an | 2221 // same page, this time committing the navigation. This should end up with an |
| 2237 // SSL interstitial when not behind a captive portal. This ensures that a new | 2222 // SSL interstitial when not behind a captive portal. This ensures that a new |
| 2238 // |SSLErrorHandler| is created on a new navigation, even though the tab's | 2223 // |SSLErrorHandler| is created on a new navigation, even though the tab's |
| 2239 // WebContents doesn't change. | 2224 // WebContents doesn't change. |
| 2240 IN_PROC_BROWSER_TEST_F( | 2225 IN_PROC_BROWSER_TEST_F( |
| 2241 CaptivePortalBrowserTest, | 2226 CaptivePortalBrowserTest, |
| 2242 InterstitialTimerNavigateWhileLoading_EndWithSSLInterstitial) { | 2227 InterstitialTimerNavigateWhileLoading_EndWithSSLInterstitial) { |
| 2243 net::SpawnedTestServer::SSLOptions https_options; | 2228 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2244 https_options.server_certificate = | 2229 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 2245 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 2230 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2246 net::SpawnedTestServer https_server( | |
| 2247 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 2248 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 2249 ASSERT_TRUE(https_server.Start()); | 2231 ASSERT_TRUE(https_server.Start()); |
| 2250 // The path does not matter. | 2232 // The path does not matter. |
| 2251 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 2233 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
| 2252 factory_.SetBehindCaptivePortal(false); | 2234 factory_.SetBehindCaptivePortal(false); |
| 2253 | 2235 |
| 2254 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2236 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 2255 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2237 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 2256 | 2238 |
| 2257 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2239 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
| 2258 // Page appears loading. Turn on response to probe request again, and navigate | 2240 // Page appears loading. Turn on response to probe request again, and navigate |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2284 EXPECT_FALSE(CheckPending(browser())); | 2266 EXPECT_FALSE(CheckPending(browser())); |
| 2285 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 2267 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2286 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2268 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
| 2287 GetStateOfTabReloaderAt(browser(), 0)); | 2269 GetStateOfTabReloaderAt(browser(), 0)); |
| 2288 } | 2270 } |
| 2289 | 2271 |
| 2290 // Same as above, but this time behind a captive portal. | 2272 // Same as above, but this time behind a captive portal. |
| 2291 IN_PROC_BROWSER_TEST_F( | 2273 IN_PROC_BROWSER_TEST_F( |
| 2292 CaptivePortalBrowserTest, | 2274 CaptivePortalBrowserTest, |
| 2293 InterstitialTimerNavigateWhileLoading_EndWithCaptivePortalInterstitial) { | 2275 InterstitialTimerNavigateWhileLoading_EndWithCaptivePortalInterstitial) { |
| 2294 net::SpawnedTestServer::SSLOptions https_options; | 2276 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2295 https_options.server_certificate = | 2277 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 2296 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 2278 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2297 net::SpawnedTestServer https_server( | |
| 2298 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 2299 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 2300 ASSERT_TRUE(https_server.Start()); | 2279 ASSERT_TRUE(https_server.Start()); |
| 2301 // The path does not matter. | 2280 // The path does not matter. |
| 2302 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); | 2281 GURL cert_error_url = https_server.GetURL(kTestServerLoginPath); |
| 2303 factory_.SetBehindCaptivePortal(true); | 2282 factory_.SetBehindCaptivePortal(true); |
| 2304 | 2283 |
| 2305 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2284 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 2306 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2285 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 2307 int initial_tab_count = tab_strip_model->count(); | 2286 int initial_tab_count = tab_strip_model->count(); |
| 2308 | 2287 |
| 2309 FastErrorWithInterstitialTimer(browser(), cert_error_url); | 2288 FastErrorWithInterstitialTimer(browser(), cert_error_url); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2342 GetStateOfTabReloaderAt(browser(), 0)); | 2321 GetStateOfTabReloaderAt(browser(), 0)); |
| 2343 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, | 2322 EXPECT_EQ(CaptivePortalTabReloader::STATE_NONE, |
| 2344 GetStateOfTabReloaderAt(browser(), 1)); | 2323 GetStateOfTabReloaderAt(browser(), 1)); |
| 2345 EXPECT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(1))); | 2324 EXPECT_TRUE(IsLoginTab(tab_strip_model->GetWebContentsAt(1))); |
| 2346 } | 2325 } |
| 2347 | 2326 |
| 2348 // A cert error triggers a captive portal check and results in opening a login | 2327 // A cert error triggers a captive portal check and results in opening a login |
| 2349 // tab. The user then logs in and the page with the error is reloaded. | 2328 // tab. The user then logs in and the page with the error is reloaded. |
| 2350 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { | 2329 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, SSLCertErrorLogin) { |
| 2351 // Need an HTTP TestServer to handle a dynamically created server redirect. | 2330 // Need an HTTP TestServer to handle a dynamically created server redirect. |
| 2352 ASSERT_TRUE(test_server()->Start()); | 2331 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2353 | 2332 |
| 2354 net::SpawnedTestServer::SSLOptions https_options; | 2333 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2355 https_options.server_certificate = | 2334 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 2356 net::SpawnedTestServer::SSLOptions::CERT_MISMATCHED_NAME; | 2335 https_server.ServeFilesFromSourceDirectory("chrome/test/data"); |
| 2357 net::SpawnedTestServer https_server( | |
| 2358 net::SpawnedTestServer::TYPE_HTTPS, https_options, | |
| 2359 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
| 2360 ASSERT_TRUE(https_server.Start()); | 2336 ASSERT_TRUE(https_server.Start()); |
| 2361 | 2337 |
| 2362 // Set SSL interstitial delay to zero so that a captive portal result can not | 2338 // Set SSL interstitial delay to zero so that a captive portal result can not |
| 2363 // arrive during this window, so an SSL interstitial is displayed instead | 2339 // arrive during this window, so an SSL interstitial is displayed instead |
| 2364 // of a captive portal error page. | 2340 // of a captive portal error page. |
| 2365 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); | 2341 SSLErrorHandler::SetInterstitialDelayForTest(base::TimeDelta()); |
| 2366 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 2342 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 2367 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); | 2343 WebContents* broken_tab_contents = tab_strip_model->GetActiveWebContents(); |
| 2368 | 2344 |
| 2369 // Setting the delay to zero above has a race condition: A captive portal | 2345 // Setting the delay to zero above has a race condition: A captive portal |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2767 IsLoginTab(active_browser->tab_strip_model()->GetWebContentsAt(1))); | 2743 IsLoginTab(active_browser->tab_strip_model()->GetWebContentsAt(1))); |
| 2768 | 2744 |
| 2769 // Simulate logging in. | 2745 // Simulate logging in. |
| 2770 Login(active_browser, 0, 1); | 2746 Login(active_browser, 0, 1); |
| 2771 } | 2747 } |
| 2772 | 2748 |
| 2773 // An HTTP page redirects to an HTTPS page loads slowly before timing out. A | 2749 // An HTTP page redirects to an HTTPS page loads slowly before timing out. A |
| 2774 // captive portal is found, and then the user logs in before the original page | 2750 // captive portal is found, and then the user logs in before the original page |
| 2775 // times out. | 2751 // times out. |
| 2776 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpToHttpsRedirectLogin) { | 2752 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpToHttpsRedirectLogin) { |
| 2777 ASSERT_TRUE(test_server()->Start()); | 2753 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2778 SlowLoadBehindCaptivePortal( | 2754 SlowLoadBehindCaptivePortal( |
| 2779 browser(), | 2755 browser(), true, |
| 2780 true, | 2756 embedded_test_server()->GetURL(CreateServerRedirect(kMockHttpsUrl)), 1, |
| 2781 test_server()->GetURL(CreateServerRedirect(kMockHttpsUrl)), | |
| 2782 1, | |
| 2783 1); | 2757 1); |
| 2784 Login(browser(), 1, 0); | 2758 Login(browser(), 1, 0); |
| 2785 FailLoadsAfterLogin(browser(), 1); | 2759 FailLoadsAfterLogin(browser(), 1); |
| 2786 } | 2760 } |
| 2787 | 2761 |
| 2788 // An HTTPS page redirects to an HTTP page. | 2762 // An HTTPS page redirects to an HTTP page. |
| 2789 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpsToHttpRedirect) { | 2763 IN_PROC_BROWSER_TEST_F(CaptivePortalBrowserTest, HttpsToHttpRedirect) { |
| 2790 // Use an HTTPS server for the top level page. | 2764 // Use an HTTPS server for the top level page. |
| 2791 net::SpawnedTestServer https_server( | 2765 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 2792 net::SpawnedTestServer::TYPE_HTTPS, net::SpawnedTestServer::kLocalhost, | 2766 https_server.AddDefaultHandlers( |
| 2793 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 2767 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 2794 ASSERT_TRUE(https_server.Start()); | 2768 ASSERT_TRUE(https_server.Start()); |
| 2795 | 2769 |
| 2796 GURL http_timeout_url = | 2770 GURL http_timeout_url = |
| 2797 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_TIMED_OUT); | 2771 URLRequestFailedJob::GetMockHttpUrl(net::ERR_CONNECTION_TIMED_OUT); |
| 2798 | 2772 |
| 2799 // 2 navigations due to the Link Doctor. | 2773 // 2 navigations due to the Link Doctor. |
| 2800 NavigateToPageExpectNoTest( | 2774 NavigateToPageExpectNoTest( |
| 2801 browser(), | 2775 browser(), |
| 2802 https_server.GetURL(CreateServerRedirect(http_timeout_url.spec())), | 2776 https_server.GetURL(CreateServerRedirect(http_timeout_url.spec())), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2864 | 2838 |
| 2865 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, | 2839 EXPECT_EQ(CaptivePortalTabReloader::STATE_NEEDS_RELOAD, |
| 2866 GetStateOfTabReloaderAt(browser(), broken_tab_index)); | 2840 GetStateOfTabReloaderAt(browser(), broken_tab_index)); |
| 2867 | 2841 |
| 2868 WaitForInterstitialAttach(broken_tab_contents); | 2842 WaitForInterstitialAttach(broken_tab_contents); |
| 2869 portal_observer.WaitForResults(1); | 2843 portal_observer.WaitForResults(1); |
| 2870 | 2844 |
| 2871 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, | 2845 EXPECT_EQ(SSLBlockingPage::kTypeForTesting, |
| 2872 GetInterstitialType(broken_tab_contents)); | 2846 GetInterstitialType(broken_tab_contents)); |
| 2873 } | 2847 } |
| OLD | NEW |