Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ssl/security_state_tab_helper.h" | 5 #include "chrome/browser/ssl/security_state_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 enum CertificateStatus { VALID_CERTIFICATE, INVALID_CERTIFICATE }; | 61 enum CertificateStatus { VALID_CERTIFICATE, INVALID_CERTIFICATE }; |
| 62 | 62 |
| 63 const base::FilePath::CharType kDocRoot[] = | 63 const base::FilePath::CharType kDocRoot[] = |
| 64 FILE_PATH_LITERAL("chrome/test/data"); | 64 FILE_PATH_LITERAL("chrome/test/data"); |
| 65 | 65 |
| 66 // Inject a script into the page. Used by tests that check for visible | 66 // Inject a script into the page. Used by tests that check for visible |
| 67 // password fields to wait for notifications about these | 67 // password fields to wait for notifications about these |
| 68 // fields. Notifications about visible password fields are queued at the | 68 // fields. Notifications about visible password fields are queued at the |
| 69 // end of the event loop, so waiting for a dummy script to run ensures | 69 // end of the event loop, so waiting for a dummy script to run ensures |
| 70 // that these notifcations have been sent. | 70 // that these notifcations have been sent. |
| 71 void InjectScript(content::WebContents* contents) { | 71 void InjectScript(const content::ToRenderFrameHost& adapter) { |
| 72 bool js_result = false; | 72 bool js_result = false; |
| 73 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 73 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 74 contents, "window.domAutomationController.send(true);", &js_result)); | 74 adapter, "window.domAutomationController.send(true);", &js_result)); |
| 75 EXPECT_TRUE(js_result); | 75 EXPECT_TRUE(js_result); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // A WebContentsObserver useful for testing the DidChangeVisibleSecurityState() | 78 // A WebContentsObserver useful for testing the DidChangeVisibleSecurityState() |
| 79 // method: it keeps track of the latest security style and explanation that was | 79 // method: it keeps track of the latest security style and explanation that was |
| 80 // fired. | 80 // fired. |
| 81 class SecurityStyleTestObserver : public content::WebContentsObserver { | 81 class SecurityStyleTestObserver : public content::WebContentsObserver { |
| 82 public: | 82 public: |
| 83 explicit SecurityStyleTestObserver(content::WebContents* web_contents) | 83 explicit SecurityStyleTestObserver(content::WebContents* web_contents) |
| 84 : content::WebContentsObserver(web_contents), | 84 : content::WebContentsObserver(web_contents), |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1130 ASSERT_TRUE(contents); | 1130 ASSERT_TRUE(contents); |
| 1131 | 1131 |
| 1132 SecurityStateTabHelper* helper = | 1132 SecurityStateTabHelper* helper = |
| 1133 SecurityStateTabHelper::FromWebContents(contents); | 1133 SecurityStateTabHelper::FromWebContents(contents); |
| 1134 ASSERT_TRUE(helper); | 1134 ASSERT_TRUE(helper); |
| 1135 | 1135 |
| 1136 ui_test_utils::NavigateToURL( | 1136 ui_test_utils::NavigateToURL( |
| 1137 browser(), | 1137 browser(), |
| 1138 GetURLWithNonLocalHostname(embedded_test_server(), | 1138 GetURLWithNonLocalHostname(embedded_test_server(), |
| 1139 "/password/simple_password_in_iframe.html")); | 1139 "/password/simple_password_in_iframe.html")); |
| 1140 InjectScript(contents); | 1140 // Inject a dummy script into each frame to ensure that password notifications |
|
estark
2017/02/10 00:55:34
note: this test was not marked as flaky. I'm guess
meacer
2017/02/10 01:07:40
Would it make sense to move this code to InjectScr
estark
2017/02/10 01:45:13
Done.
| |
| 1141 // from any subframe have been sent. | |
| 1142 for (const auto& frame : contents->GetAllFrames()) { | |
| 1143 InjectScript(content::ToRenderFrameHost(frame)); | |
| 1144 } | |
| 1141 security_state::SecurityInfo security_info; | 1145 security_state::SecurityInfo security_info; |
| 1142 helper->GetSecurityInfo(&security_info); | 1146 helper->GetSecurityInfo(&security_info); |
| 1143 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); | 1147 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); |
| 1144 | 1148 |
| 1145 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); | 1149 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| 1146 ASSERT_TRUE(entry); | 1150 ASSERT_TRUE(entry); |
| 1147 EXPECT_TRUE(entry->GetSSL().content_status & | 1151 EXPECT_TRUE(entry->GetSSL().content_status & |
| 1148 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | 1152 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
| 1149 } | 1153 } |
| 1150 | 1154 |
| 1151 // Tests that when a visible password field is detected inside an iframe | 1155 // Tests that when a visible password field is detected inside an iframe |
| 1152 // on an HTTP page load, and when the command-line flag is set, the | 1156 // on an HTTP page load, and when the command-line flag is set, the |
| 1153 // security level is downgraded to HTTP_SHOW_WARNING, even if the iframe | 1157 // security level is downgraded to HTTP_SHOW_WARNING, even if the iframe |
| 1154 // itself was loaded over HTTPS. | 1158 // itself was loaded over HTTPS. |
| 1155 #if defined(OS_LINUX) | |
| 1156 // Flaky on Linux. See https://crbug.com/662485. | |
| 1157 #define MAYBE_PasswordSecurityLevelDowngradedFromHttpsIframe \ | |
| 1158 DISABLED_PasswordSecurityLevelDowngradedFromHttpsIframe | |
| 1159 #else | |
| 1160 #define MAYBE_PasswordSecurityLevelDowngradedFromHttpsIframe \ | |
| 1161 PasswordSecurityLevelDowngradedFromHttpsIframe | |
| 1162 #endif | |
| 1163 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch, | 1159 IN_PROC_BROWSER_TEST_F(SecurityStateTabHelperTestWithPasswordCcSwitch, |
| 1164 MAYBE_PasswordSecurityLevelDowngradedFromHttpsIframe) { | 1160 PasswordSecurityLevelDowngradedFromHttpsIframe) { |
| 1165 content::WebContents* contents = | 1161 content::WebContents* contents = |
| 1166 browser()->tab_strip_model()->GetActiveWebContents(); | 1162 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1167 ASSERT_TRUE(contents); | 1163 ASSERT_TRUE(contents); |
| 1168 | 1164 |
| 1169 SecurityStateTabHelper* helper = | 1165 SecurityStateTabHelper* helper = |
| 1170 SecurityStateTabHelper::FromWebContents(contents); | 1166 SecurityStateTabHelper::FromWebContents(contents); |
| 1171 ASSERT_TRUE(helper); | 1167 ASSERT_TRUE(helper); |
| 1172 | 1168 |
| 1173 // Navigate to an HTTP URL, which loads an iframe using the host and port of | 1169 // Navigate to an HTTP URL, which loads an iframe using the host and port of |
| 1174 // |https_server_|. | 1170 // |https_server_|. |
| 1175 std::string replacement_path; | 1171 std::string replacement_path; |
| 1176 GetFilePathWithHostAndPortReplacement( | 1172 GetFilePathWithHostAndPortReplacement( |
| 1177 "/password/simple_password_in_https_iframe.html", | 1173 "/password/simple_password_in_https_iframe.html", |
| 1178 https_server_.host_port_pair(), &replacement_path); | 1174 https_server_.host_port_pair(), &replacement_path); |
| 1179 ui_test_utils::NavigateToURL( | 1175 ui_test_utils::NavigateToURL( |
| 1180 browser(), | 1176 browser(), |
| 1181 GetURLWithNonLocalHostname(embedded_test_server(), replacement_path)); | 1177 GetURLWithNonLocalHostname(embedded_test_server(), replacement_path)); |
| 1182 InjectScript(contents); | 1178 // Inject a dummy script into each frame to ensure that password notifications |
| 1179 // from any subframe have been sent. | |
|
meacer
2017/02/10 01:07:40
nit: any subframe or all subframes? They sound dif
estark
2017/02/10 01:45:13
Probably should have been "all subframes", but n/a
| |
| 1180 for (const auto& frame : contents->GetAllFrames()) { | |
| 1181 InjectScript(content::ToRenderFrameHost(frame)); | |
| 1182 } | |
| 1183 security_state::SecurityInfo security_info; | 1183 security_state::SecurityInfo security_info; |
| 1184 helper->GetSecurityInfo(&security_info); | 1184 helper->GetSecurityInfo(&security_info); |
| 1185 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); | 1185 EXPECT_EQ(security_state::HTTP_SHOW_WARNING, security_info.security_level); |
| 1186 | 1186 |
| 1187 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); | 1187 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
| 1188 ASSERT_TRUE(entry); | 1188 ASSERT_TRUE(entry); |
| 1189 EXPECT_TRUE(entry->GetSSL().content_status & | 1189 EXPECT_TRUE(entry->GetSSL().content_status & |
| 1190 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | 1190 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2158 SecurityStateTabHelper* helper = | 2158 SecurityStateTabHelper* helper = |
| 2159 SecurityStateTabHelper::FromWebContents(web_contents); | 2159 SecurityStateTabHelper::FromWebContents(web_contents); |
| 2160 ASSERT_TRUE(helper); | 2160 ASSERT_TRUE(helper); |
| 2161 security_state::SecurityInfo security_info; | 2161 security_state::SecurityInfo security_info; |
| 2162 helper->GetSecurityInfo(&security_info); | 2162 helper->GetSecurityInfo(&security_info); |
| 2163 EXPECT_EQ(security_state::SECURE, security_info.security_level); | 2163 EXPECT_EQ(security_state::SECURE, security_info.security_level); |
| 2164 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); | 2164 EXPECT_EQ(kTestSCTStatuses, security_info.sct_verify_statuses); |
| 2165 } | 2165 } |
| 2166 | 2166 |
| 2167 } // namespace | 2167 } // namespace |
| OLD | NEW |