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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 #include "components/security_interstitials/core/metrics_helper.h" | 56 #include "components/security_interstitials/core/metrics_helper.h" |
57 #include "components/security_state/security_state_model.h" | 57 #include "components/security_state/security_state_model.h" |
58 #include "components/security_state/switches.h" | 58 #include "components/security_state/switches.h" |
59 #include "components/ssl_errors/error_classification.h" | 59 #include "components/ssl_errors/error_classification.h" |
60 #include "components/variations/variations_associated_data.h" | 60 #include "components/variations/variations_associated_data.h" |
61 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 61 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
62 #include "content/public/browser/browser_context.h" | 62 #include "content/public/browser/browser_context.h" |
63 #include "content/public/browser/interstitial_page.h" | 63 #include "content/public/browser/interstitial_page.h" |
64 #include "content/public/browser/navigation_controller.h" | 64 #include "content/public/browser/navigation_controller.h" |
65 #include "content/public/browser/navigation_entry.h" | 65 #include "content/public/browser/navigation_entry.h" |
66 #include "content/public/browser/notification_details.h" | |
66 #include "content/public/browser/notification_service.h" | 67 #include "content/public/browser/notification_service.h" |
67 #include "content/public/browser/render_frame_host.h" | 68 #include "content/public/browser/render_frame_host.h" |
68 #include "content/public/browser/render_view_host.h" | 69 #include "content/public/browser/render_view_host.h" |
69 #include "content/public/browser/render_widget_host_view.h" | 70 #include "content/public/browser/render_widget_host_view.h" |
70 #include "content/public/browser/restore_type.h" | 71 #include "content/public/browser/restore_type.h" |
71 #include "content/public/browser/ssl_status.h" | 72 #include "content/public/browser/ssl_status.h" |
72 #include "content/public/browser/web_contents.h" | 73 #include "content/public/browser/web_contents.h" |
73 #include "content/public/browser/web_contents_observer.h" | 74 #include "content/public/browser/web_contents_observer.h" |
74 #include "content/public/common/browser_side_navigation_policy.h" | 75 #include "content/public/common/browser_side_navigation_policy.h" |
75 #include "content/public/common/content_switches.h" | 76 #include "content/public/common/content_switches.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 net::NetworkDelegate* network_delegate) const override { | 251 net::NetworkDelegate* network_delegate) const override { |
251 if (request->url().path() == "/favicon.ico") | 252 if (request->url().path() == "/favicon.ico") |
252 return new HungJob(request, network_delegate); | 253 return new HungJob(request, network_delegate); |
253 return nullptr; | 254 return nullptr; |
254 } | 255 } |
255 | 256 |
256 private: | 257 private: |
257 DISALLOW_COPY_AND_ASSIGN(FaviconFilter); | 258 DISALLOW_COPY_AND_ASSIGN(FaviconFilter); |
258 }; | 259 }; |
259 | 260 |
261 std::string encodeQueryStr(const std::string& query) { | |
jam
2016/10/05 16:36:02
nit: per style guide, begin with capital. also, st
estark
2016/10/05 16:53:04
Done.
| |
262 url::RawCanonOutputT<char> buffer; | |
263 url::EncodeURIComponent(query.data(), query.size(), &buffer); | |
264 return std::string(buffer.data(), buffer.length()); | |
265 } | |
266 | |
260 } // namespace | 267 } // namespace |
261 | 268 |
262 class SSLUITest | 269 class SSLUITest |
263 : public certificate_reporting_test_utils::CertificateReportingTest { | 270 : public certificate_reporting_test_utils::CertificateReportingTest { |
264 public: | 271 public: |
265 SSLUITest() | 272 SSLUITest() |
266 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS), | 273 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS), |
267 https_server_expired_(net::EmbeddedTestServer::TYPE_HTTPS), | 274 https_server_expired_(net::EmbeddedTestServer::TYPE_HTTPS), |
268 https_server_mismatched_(net::EmbeddedTestServer::TYPE_HTTPS), | 275 https_server_mismatched_(net::EmbeddedTestServer::TYPE_HTTPS), |
269 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS, | 276 wss_server_expired_(net::SpawnedTestServer::TYPE_WSS, |
(...skipping 1783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2053 | 2060 |
2054 GURL https_url = https_server_.GetURL("/server-redirect?"); | 2061 GURL https_url = https_server_.GetURL("/server-redirect?"); |
2055 GURL http_url = embedded_test_server()->GetURL("/ssl/google.html"); | 2062 GURL http_url = embedded_test_server()->GetURL("/ssl/google.html"); |
2056 | 2063 |
2057 ui_test_utils::NavigateToURL(browser(), | 2064 ui_test_utils::NavigateToURL(browser(), |
2058 GURL(https_url.spec() + http_url.spec())); | 2065 GURL(https_url.spec() + http_url.spec())); |
2059 CheckUnauthenticatedState( | 2066 CheckUnauthenticatedState( |
2060 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); | 2067 browser()->tab_strip_model()->GetActiveWebContents(), AuthState::NONE); |
2061 } | 2068 } |
2062 | 2069 |
2070 class SSLUITestWaitForDOMNotification : public SSLUITestIgnoreCertErrors, | |
2071 public content::NotificationObserver { | |
2072 public: | |
2073 SSLUITestWaitForDOMNotification() : SSLUITestIgnoreCertErrors() {} | |
2074 | |
2075 ~SSLUITestWaitForDOMNotification() override { registrar_.RemoveAll(); }; | |
2076 | |
2077 void SetUpOnMainThread() override { | |
2078 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, | |
2079 content::NotificationService::AllSources()); | |
2080 } | |
2081 | |
2082 void set_expected_notification(const std::string& expected_notification) { | |
2083 expected_notification_ = expected_notification; | |
2084 } | |
2085 | |
2086 // content::NotificationObserver | |
2087 void Observe(int type, | |
2088 const content::NotificationSource& source, | |
2089 const content::NotificationDetails& details) override { | |
2090 if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { | |
2091 content::Details<std::string> dom_op_result(details); | |
2092 if (*dom_op_result.ptr() == expected_notification_) { | |
2093 base::MessageLoopForUI::current()->QuitWhenIdle(); | |
2094 } | |
2095 } | |
2096 } | |
2097 | |
2098 private: | |
2099 content::NotificationRegistrar registrar_; | |
2100 std::string expected_notification_; | |
2101 | |
2102 DISALLOW_COPY_AND_ASSIGN(SSLUITestWaitForDOMNotification); | |
2103 }; | |
2104 | |
2105 // Tests that a mixed resource which includes HTTP in the redirect chain | |
2106 // is marked as mixed content, even if the end result is HTTPS. | |
2107 IN_PROC_BROWSER_TEST_F(SSLUITestWaitForDOMNotification, | |
2108 TestMixedContentWithHTTPInRedirectChain) { | |
2109 ASSERT_TRUE(embedded_test_server()->Start()); | |
2110 ASSERT_TRUE(https_server_.Start()); | |
2111 | |
2112 host_resolver()->AddRule("*", embedded_test_server()->GetURL("/").host()); | |
2113 | |
2114 ui_test_utils::NavigateToURL(browser(), | |
2115 https_server_.GetURL("/ssl/blank_page.html")); | |
2116 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
2117 CheckAuthenticatedState(tab, AuthState::NONE); | |
2118 | |
2119 // Construct a URL which will be dynamically added to the page as an | |
2120 // image. The URL redirects through HTTP, though it ends up at an | |
2121 // HTTPS resource. | |
2122 GURL http_url = embedded_test_server()->GetURL("/server-redirect?"); | |
2123 GURL::Replacements http_url_replacements; | |
2124 // Be sure to use a non-localhost name for the mixed content request, | |
2125 // since local hostnames are not considered mixed content. | |
2126 http_url_replacements.SetHostStr("example.test"); | |
2127 std::string http_url_query = | |
2128 encodeQueryStr(https_server_.GetURL("/ssl/google_files/logo.gif").spec()); | |
2129 http_url_replacements.SetQueryStr(http_url_query); | |
2130 http_url = http_url.ReplaceComponents(http_url_replacements); | |
2131 | |
2132 GURL https_url = https_server_.GetURL("/server-redirect?"); | |
2133 GURL::Replacements https_url_replacements; | |
2134 std::string https_url_query = encodeQueryStr(http_url.spec()); | |
2135 https_url_replacements.SetQueryStr(https_url_query); | |
2136 https_url = https_url.ReplaceComponents(https_url_replacements); | |
2137 | |
2138 // Load the image. It starts at |https_server_|, which redirects to an | |
2139 // embedded_test_server() HTTP URL, which redirects back to | |
2140 // |https_server_| for the final HTTPS image. Because the redirect | |
2141 // chain passes through HTTP, the page should be marked as mixed | |
2142 // content. | |
2143 set_expected_notification("\"mixed-image-loaded\""); | |
2144 ASSERT_TRUE(content::ExecuteScript( | |
2145 tab, | |
2146 "var loaded = function () {" | |
2147 " window.domAutomationController.setAutomationId(0);" | |
2148 " window.domAutomationController.send('mixed-image-loaded');" | |
2149 "};" | |
2150 "var img = document.createElement('img');" | |
2151 "img.onload = loaded;" | |
2152 "img.src = '" + | |
2153 https_url.spec() + "';" | |
2154 "document.body.appendChild(img);")); | |
2155 | |
2156 content::RunMessageLoop(); | |
2157 CheckAuthenticatedState(tab, AuthState::DISPLAYED_INSECURE_CONTENT); | |
2158 } | |
2159 | |
2063 // Visits a page to which we could not connect (bad port) over http and https | 2160 // Visits a page to which we could not connect (bad port) over http and https |
2064 // and make sure the security style is correct. | 2161 // and make sure the security style is correct. |
2065 IN_PROC_BROWSER_TEST_F(SSLUITest, TestConnectToBadPort) { | 2162 IN_PROC_BROWSER_TEST_F(SSLUITest, TestConnectToBadPort) { |
2066 ui_test_utils::NavigateToURL(browser(), GURL("http://localhost:17")); | 2163 ui_test_utils::NavigateToURL(browser(), GURL("http://localhost:17")); |
2067 CheckUnauthenticatedState( | 2164 CheckUnauthenticatedState( |
2068 browser()->tab_strip_model()->GetActiveWebContents(), | 2165 browser()->tab_strip_model()->GetActiveWebContents(), |
2069 AuthState::SHOWING_ERROR); | 2166 AuthState::SHOWING_ERROR); |
2070 | 2167 |
2071 // Same thing over HTTPS. | 2168 // Same thing over HTTPS. |
2072 ui_test_utils::NavigateToURL(browser(), GURL("https://localhost:17")); | 2169 ui_test_utils::NavigateToURL(browser(), GURL("https://localhost:17")); |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3282 | 3379 |
3283 // Visit a page over https that contains a frame with a redirect. | 3380 // Visit a page over https that contains a frame with a redirect. |
3284 | 3381 |
3285 // XMLHttpRequest insecure content in synchronous mode. | 3382 // XMLHttpRequest insecure content in synchronous mode. |
3286 | 3383 |
3287 // XMLHttpRequest insecure content in asynchronous mode. | 3384 // XMLHttpRequest insecure content in asynchronous mode. |
3288 | 3385 |
3289 // XMLHttpRequest over bad ssl in synchronous mode. | 3386 // XMLHttpRequest over bad ssl in synchronous mode. |
3290 | 3387 |
3291 // XMLHttpRequest over OK ssl in synchronous mode. | 3388 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |