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 // This test creates a fake safebrowsing service, where we can inject known- | 5 // This test creates a fake safebrowsing service, where we can inject known- |
6 // threat urls. It then uses a real browser to go to these urls, and sends | 6 // threat urls. It then uses a real browser to go to these urls, and sends |
7 // "goback" or "proceed" commands and verifies they work. | 7 // "goback" or "proceed" commands and verifies they work. |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/test/base/in_process_browser_test.h" | 36 #include "chrome/test/base/in_process_browser_test.h" |
37 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
38 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
39 #include "components/safe_browsing_db/database_manager.h" | 39 #include "components/safe_browsing_db/database_manager.h" |
40 #include "components/safe_browsing_db/safe_browsing_prefs.h" | 40 #include "components/safe_browsing_db/safe_browsing_prefs.h" |
41 #include "components/safe_browsing_db/test_database_manager.h" | 41 #include "components/safe_browsing_db/test_database_manager.h" |
42 #include "components/safe_browsing_db/util.h" | 42 #include "components/safe_browsing_db/util.h" |
43 #include "components/security_interstitials/core/controller_client.h" | 43 #include "components/security_interstitials/core/controller_client.h" |
44 #include "components/security_interstitials/core/metrics_helper.h" | 44 #include "components/security_interstitials/core/metrics_helper.h" |
45 #include "components/security_state/core/security_state.h" | 45 #include "components/security_state/core/security_state.h" |
| 46 #include "components/strings/grit/components_strings.h" |
46 #include "content/public/browser/interstitial_page.h" | 47 #include "content/public/browser/interstitial_page.h" |
47 #include "content/public/browser/navigation_controller.h" | 48 #include "content/public/browser/navigation_controller.h" |
48 #include "content/public/browser/navigation_entry.h" | 49 #include "content/public/browser/navigation_entry.h" |
49 #include "content/public/browser/notification_types.h" | 50 #include "content/public/browser/notification_types.h" |
50 #include "content/public/browser/render_frame_host.h" | 51 #include "content/public/browser/render_frame_host.h" |
51 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
52 #include "content/public/browser/security_style_explanations.h" | 53 #include "content/public/browser/security_style_explanations.h" |
53 #include "content/public/browser/web_contents.h" | 54 #include "content/public/browser/web_contents.h" |
54 #include "content/public/test/browser_test_utils.h" | 55 #include "content/public/test/browser_test_utils.h" |
55 #include "content/public/test/test_browser_thread.h" | 56 #include "content/public/test/test_browser_thread.h" |
56 #include "content/public/test/test_utils.h" | 57 #include "content/public/test/test_utils.h" |
57 #include "net/cert/cert_verify_result.h" | 58 #include "net/cert/cert_verify_result.h" |
58 #include "net/cert/mock_cert_verifier.h" | 59 #include "net/cert/mock_cert_verifier.h" |
59 #include "net/test/embedded_test_server/embedded_test_server.h" | 60 #include "net/test/embedded_test_server/embedded_test_server.h" |
60 #include "net/test/url_request/url_request_mock_http_job.h" | 61 #include "net/test/url_request/url_request_mock_http_job.h" |
| 62 #include "ui/base/l10n/l10n_util.h" |
61 | 63 |
62 using chrome_browser_interstitials::SecurityInterstitialIDNTest; | 64 using chrome_browser_interstitials::SecurityInterstitialIDNTest; |
63 using content::BrowserThread; | 65 using content::BrowserThread; |
64 using content::InterstitialPage; | 66 using content::InterstitialPage; |
65 using content::NavigationController; | 67 using content::NavigationController; |
66 using content::RenderFrameHost; | 68 using content::RenderFrameHost; |
67 using content::WebContents; | 69 using content::WebContents; |
68 | 70 |
69 namespace safe_browsing { | 71 namespace safe_browsing { |
70 | 72 |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1112 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1111 AssertNoInterstitial(true); | 1113 AssertNoInterstitial(true); |
1112 } | 1114 } |
1113 | 1115 |
1114 namespace { | 1116 namespace { |
1115 | 1117 |
1116 class SecurityStyleTestObserver : public content::WebContentsObserver { | 1118 class SecurityStyleTestObserver : public content::WebContentsObserver { |
1117 public: | 1119 public: |
1118 explicit SecurityStyleTestObserver(content::WebContents* web_contents) | 1120 explicit SecurityStyleTestObserver(content::WebContents* web_contents) |
1119 : content::WebContentsObserver(web_contents), | 1121 : content::WebContentsObserver(web_contents), |
1120 latest_security_style_(blink::WebSecurityStyleUnknown) {} | 1122 latest_security_style_(blink::WebSecurityStyleUnknown), |
| 1123 latest_security_style_explanations_() {} |
1121 | 1124 |
1122 blink::WebSecurityStyle latest_security_style() const { | 1125 blink::WebSecurityStyle latest_security_style() const { |
1123 return latest_security_style_; | 1126 return latest_security_style_; |
1124 } | 1127 } |
1125 | 1128 |
| 1129 content::SecurityStyleExplanations latest_security_style_explanations() |
| 1130 const { |
| 1131 return latest_security_style_explanations_; |
| 1132 } |
| 1133 |
1126 // WebContentsObserver: | 1134 // WebContentsObserver: |
1127 void DidChangeVisibleSecurityState() override { | 1135 void DidChangeVisibleSecurityState() override { |
1128 content::SecurityStyleExplanations security_style_explanations; | |
1129 latest_security_style_ = web_contents()->GetDelegate()->GetSecurityStyle( | 1136 latest_security_style_ = web_contents()->GetDelegate()->GetSecurityStyle( |
1130 web_contents(), &security_style_explanations); | 1137 web_contents(), &latest_security_style_explanations_); |
1131 } | 1138 } |
1132 | 1139 |
1133 private: | 1140 private: |
1134 blink::WebSecurityStyle latest_security_style_; | 1141 blink::WebSecurityStyle latest_security_style_; |
| 1142 content::SecurityStyleExplanations latest_security_style_explanations_; |
1135 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver); | 1143 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver); |
1136 }; | 1144 }; |
1137 | 1145 |
1138 } // namespace | 1146 } // namespace |
1139 | 1147 |
1140 // Test that the security indicator gets updated on a Safe Browsing | 1148 // Test that the security indicator gets updated on a Safe Browsing |
1141 // interstitial triggered by a subresource. Regression test for | 1149 // interstitial triggered by a subresource. Regression test for |
1142 // https://crbug.com/659713. | 1150 // https://crbug.com/659713. |
1143 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1151 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1144 SecurityStateDowngradedForSubresourceInterstitial) { | 1152 SecurityStateDowngradedForSubresourceInterstitial) { |
1145 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1153 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1146 ASSERT_TRUE(error_tab); | 1154 ASSERT_TRUE(error_tab); |
1147 SecurityStyleTestObserver observer(error_tab); | 1155 SecurityStyleTestObserver observer(error_tab); |
1148 // The security indicator should be downgraded while the interstitial shows. | 1156 // The security indicator should be downgraded while the interstitial shows. |
1149 SetupThreatIframeWarningAndNavigate(); | 1157 SetupThreatIframeWarningAndNavigate(); |
1150 ExpectSecurityIndicatorDowngrade(error_tab, 0u); | 1158 ExpectSecurityIndicatorDowngrade(error_tab, 0u); |
1151 EXPECT_EQ(blink::WebSecurityStyleAuthenticationBroken, | 1159 EXPECT_EQ(blink::WebSecurityStyleAuthenticationBroken, |
1152 observer.latest_security_style()); | 1160 observer.latest_security_style()); |
| 1161 // Security style summary for Developer Tools should contain a warning. |
| 1162 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SAFEBROWSING_WARNING), |
| 1163 observer.latest_security_style_explanations().summary); |
1153 | 1164 |
1154 // The security indicator should still be downgraded post-interstitial. | 1165 // The security indicator should still be downgraded post-interstitial. |
1155 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1166 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1156 AssertNoInterstitial(true); | 1167 AssertNoInterstitial(true); |
1157 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1168 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1158 ASSERT_TRUE(post_tab); | 1169 ASSERT_TRUE(post_tab); |
1159 ExpectSecurityIndicatorDowngrade(post_tab, 0u); | 1170 ExpectSecurityIndicatorDowngrade(post_tab, 0u); |
1160 } | 1171 } |
1161 | 1172 |
1162 // Test that the security indicator does not stay downgraded after | 1173 // Test that the security indicator does not stay downgraded after |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 AssertNoInterstitial(true); | 1271 AssertNoInterstitial(true); |
1261 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1272 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1262 ASSERT_TRUE(post_tab); | 1273 ASSERT_TRUE(post_tab); |
1263 ExpectSecurityIndicatorDowngrade(post_tab, 0u); | 1274 ExpectSecurityIndicatorDowngrade(post_tab, 0u); |
1264 } | 1275 } |
1265 | 1276 |
1266 // Test that the security indicator is downgraded even if the website has valid | 1277 // Test that the security indicator is downgraded even if the website has valid |
1267 // HTTPS (meaning that the SB state overrides the HTTPS state). | 1278 // HTTPS (meaning that the SB state overrides the HTTPS state). |
1268 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1279 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1269 SecurityState_ValidHTTPS) { | 1280 SecurityState_ValidHTTPS) { |
| 1281 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1282 ASSERT_TRUE(error_tab); |
| 1283 SecurityStyleTestObserver observer(error_tab); |
| 1284 |
1270 // The security indicator should be downgraded while the interstitial shows. | 1285 // The security indicator should be downgraded while the interstitial shows. |
1271 SetupWarningAndNavigateToValidHTTPS(); | 1286 SetupWarningAndNavigateToValidHTTPS(); |
1272 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
1273 ASSERT_TRUE(error_tab); | |
1274 ExpectSecurityIndicatorDowngrade(error_tab, 0u); | 1287 ExpectSecurityIndicatorDowngrade(error_tab, 0u); |
1275 | 1288 |
| 1289 // Security style summary for Developer Tools should contain a warning. |
| 1290 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SAFEBROWSING_WARNING), |
| 1291 observer.latest_security_style_explanations().summary); |
| 1292 |
1276 // The security indicator should still be downgraded post-interstitial. | 1293 // The security indicator should still be downgraded post-interstitial. |
1277 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1294 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1278 AssertNoInterstitial(true); | 1295 AssertNoInterstitial(true); |
1279 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1296 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1280 ASSERT_TRUE(post_tab); | 1297 ASSERT_TRUE(post_tab); |
1281 ExpectSecurityIndicatorDowngrade(post_tab, 0u); | 1298 ExpectSecurityIndicatorDowngrade(post_tab, 0u); |
| 1299 |
| 1300 // Security style summary for Developer Tools should still contain a warning. |
| 1301 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SAFEBROWSING_WARNING), |
| 1302 observer.latest_security_style_explanations().summary); |
1282 } | 1303 } |
1283 | 1304 |
1284 // Test that the security indicator is still downgraded after two interstitials | 1305 // Test that the security indicator is still downgraded after two interstitials |
1285 // are shown in a row (one for Safe Browsing, one for invalid HTTPS). | 1306 // are shown in a row (one for Safe Browsing, one for invalid HTTPS). |
1286 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1307 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1287 SecurityState_InvalidHTTPS) { | 1308 SecurityState_InvalidHTTPS) { |
1288 // The security indicator should be downgraded while the interstitial shows. | 1309 // The security indicator should be downgraded while the interstitial shows. |
1289 SetupWarningAndNavigateToInvalidHTTPS(); | 1310 SetupWarningAndNavigateToInvalidHTTPS(); |
1290 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1311 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1291 ASSERT_TRUE(error_tab); | 1312 ASSERT_TRUE(error_tab); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 | 1371 |
1351 INSTANTIATE_TEST_CASE_P( | 1372 INSTANTIATE_TEST_CASE_P( |
1352 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1373 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1353 SafeBrowsingBlockingPageIDNTest, | 1374 SafeBrowsingBlockingPageIDNTest, |
1354 testing::Combine(testing::Values(false, true), | 1375 testing::Combine(testing::Values(false, true), |
1355 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1376 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1356 SB_THREAT_TYPE_URL_PHISHING, | 1377 SB_THREAT_TYPE_URL_PHISHING, |
1357 SB_THREAT_TYPE_URL_UNWANTED))); | 1378 SB_THREAT_TYPE_URL_UNWANTED))); |
1358 | 1379 |
1359 } // namespace safe_browsing | 1380 } // namespace safe_browsing |
OLD | NEW |