Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_blocking_page_test.cc

Issue 2542533004: Override DevTools security summary when a Safe Browsing warning shows. (Closed)
Patch Set: Parameters for the securityStatusChanged event and related objects are not optional Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
53 #include "content/public/browser/security_style_explanations.h"
52 #include "content/public/browser/web_contents.h" 54 #include "content/public/browser/web_contents.h"
53 #include "content/public/test/browser_test_utils.h" 55 #include "content/public/test/browser_test_utils.h"
54 #include "content/public/test/test_browser_thread.h" 56 #include "content/public/test/test_browser_thread.h"
55 #include "content/public/test/test_utils.h" 57 #include "content/public/test/test_utils.h"
56 #include "net/cert/cert_verify_result.h" 58 #include "net/cert/cert_verify_result.h"
57 #include "net/cert/mock_cert_verifier.h" 59 #include "net/cert/mock_cert_verifier.h"
58 #include "net/test/embedded_test_server/embedded_test_server.h" 60 #include "net/test/embedded_test_server/embedded_test_server.h"
59 #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"
60 63
61 using chrome_browser_interstitials::SecurityInterstitialIDNTest; 64 using chrome_browser_interstitials::SecurityInterstitialIDNTest;
62 using content::BrowserThread; 65 using content::BrowserThread;
63 using content::InterstitialPage; 66 using content::InterstitialPage;
64 using content::NavigationController; 67 using content::NavigationController;
65 using content::RenderFrameHost; 68 using content::RenderFrameHost;
66 using content::WebContents; 69 using content::WebContents;
67 70
68 namespace safe_browsing { 71 namespace safe_browsing {
69 72
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1112 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1110 AssertNoInterstitial(true); 1113 AssertNoInterstitial(true);
1111 } 1114 }
1112 1115
1113 namespace { 1116 namespace {
1114 1117
1115 class SecurityStyleTestObserver : public content::WebContentsObserver { 1118 class SecurityStyleTestObserver : public content::WebContentsObserver {
1116 public: 1119 public:
1117 explicit SecurityStyleTestObserver(content::WebContents* web_contents) 1120 explicit SecurityStyleTestObserver(content::WebContents* web_contents)
1118 : content::WebContentsObserver(web_contents), 1121 : content::WebContentsObserver(web_contents),
1119 latest_security_style_(blink::WebSecurityStyleUnknown) {} 1122 latest_security_style_(blink::WebSecurityStyleUnknown),
1123 latest_security_style_explanations_() {}
1120 1124
1121 blink::WebSecurityStyle latest_security_style() const { 1125 blink::WebSecurityStyle latest_security_style() const {
1122 return latest_security_style_; 1126 return latest_security_style_;
1123 } 1127 }
1124 1128
1129 content::SecurityStyleExplanations latest_security_style_explanations()
1130 const {
1131 return latest_security_style_explanations_;
1132 }
1133
1125 // WebContentsObserver: 1134 // WebContentsObserver:
1126 void SecurityStyleChanged(blink::WebSecurityStyle security_style, 1135 void SecurityStyleChanged(blink::WebSecurityStyle security_style,
1127 const content::SecurityStyleExplanations& 1136 const content::SecurityStyleExplanations&
1128 security_style_explanations) override { 1137 security_style_explanations) override {
1129 latest_security_style_ = security_style; 1138 latest_security_style_ = security_style;
1139 latest_security_style_explanations_ = security_style_explanations;
1130 } 1140 }
1131 1141
1132 private: 1142 private:
1133 blink::WebSecurityStyle latest_security_style_; 1143 blink::WebSecurityStyle latest_security_style_;
1144 content::SecurityStyleExplanations latest_security_style_explanations_;
1134 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver); 1145 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver);
1135 }; 1146 };
1136 1147
1137 } // namespace 1148 } // namespace
1138 1149
1139 // Test that the security indicator gets updated on a Safe Browsing 1150 // Test that the security indicator gets updated on a Safe Browsing
1140 // interstitial triggered by a subresource. Regression test for 1151 // interstitial triggered by a subresource. Regression test for
1141 // https://crbug.com/659713. 1152 // https://crbug.com/659713.
1142 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1153 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1143 SecurityStateDowngradedForSubresourceInterstitial) { 1154 SecurityStateDowngradedForSubresourceInterstitial) {
1144 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1155 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1145 ASSERT_TRUE(error_tab); 1156 ASSERT_TRUE(error_tab);
1146 SecurityStyleTestObserver observer(error_tab); 1157 SecurityStyleTestObserver observer(error_tab);
1147 // The security indicator should be downgraded while the interstitial shows. 1158 // The security indicator should be downgraded while the interstitial shows.
1148 SetupThreatIframeWarningAndNavigate(); 1159 SetupThreatIframeWarningAndNavigate();
1149 ExpectSecurityIndicatorDowngrade(error_tab, 0u); 1160 ExpectSecurityIndicatorDowngrade(error_tab, 0u);
1150 EXPECT_EQ(blink::WebSecurityStyleAuthenticationBroken, 1161 EXPECT_EQ(blink::WebSecurityStyleAuthenticationBroken,
1151 observer.latest_security_style()); 1162 observer.latest_security_style());
1163 // Security style summary for Developer Tools should contain a warning.
1164 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SAFEBROWSING_WARNING),
1165 observer.latest_security_style_explanations().summary_override);
1152 1166
1153 // The security indicator should still be downgraded post-interstitial. 1167 // The security indicator should still be downgraded post-interstitial.
1154 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1168 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1155 AssertNoInterstitial(true); 1169 AssertNoInterstitial(true);
1156 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1170 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents();
1157 ASSERT_TRUE(post_tab); 1171 ASSERT_TRUE(post_tab);
1158 ExpectSecurityIndicatorDowngrade(post_tab, 0u); 1172 ExpectSecurityIndicatorDowngrade(post_tab, 0u);
1159 } 1173 }
1160 1174
1161 // Test that the security indicator does not stay downgraded after 1175 // Test that the security indicator does not stay downgraded after
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 AssertNoInterstitial(true); 1273 AssertNoInterstitial(true);
1260 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1274 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents();
1261 ASSERT_TRUE(post_tab); 1275 ASSERT_TRUE(post_tab);
1262 ExpectSecurityIndicatorDowngrade(post_tab, 0u); 1276 ExpectSecurityIndicatorDowngrade(post_tab, 0u);
1263 } 1277 }
1264 1278
1265 // Test that the security indicator is downgraded even if the website has valid 1279 // Test that the security indicator is downgraded even if the website has valid
1266 // HTTPS (meaning that the SB state overrides the HTTPS state). 1280 // HTTPS (meaning that the SB state overrides the HTTPS state).
1267 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1281 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1268 SecurityState_ValidHTTPS) { 1282 SecurityState_ValidHTTPS) {
1283 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1284 ASSERT_TRUE(error_tab);
1285 SecurityStyleTestObserver observer(error_tab);
1286
1269 // The security indicator should be downgraded while the interstitial shows. 1287 // The security indicator should be downgraded while the interstitial shows.
1270 SetupWarningAndNavigateToValidHTTPS(); 1288 SetupWarningAndNavigateToValidHTTPS();
1271 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1272 ASSERT_TRUE(error_tab);
1273 ExpectSecurityIndicatorDowngrade(error_tab, 0u); 1289 ExpectSecurityIndicatorDowngrade(error_tab, 0u);
1274 1290
1291 // Security style summary for Developer Tools should contain a warning.
1292 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SAFEBROWSING_WARNING),
1293 observer.latest_security_style_explanations().summary_override);
1294
1275 // The security indicator should still be downgraded post-interstitial. 1295 // The security indicator should still be downgraded post-interstitial.
1276 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); 1296 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link"));
1277 AssertNoInterstitial(true); 1297 AssertNoInterstitial(true);
1278 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1298 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents();
1279 ASSERT_TRUE(post_tab); 1299 ASSERT_TRUE(post_tab);
1280 ExpectSecurityIndicatorDowngrade(post_tab, 0u); 1300 ExpectSecurityIndicatorDowngrade(post_tab, 0u);
1301
1302 // Security style summary for Developer Tools should still contain a warning.
1303 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_SAFEBROWSING_WARNING),
1304 observer.latest_security_style_explanations().summary_override);
1281 } 1305 }
1282 1306
1283 // Test that the security indicator is still downgraded after two interstitials 1307 // Test that the security indicator is still downgraded after two interstitials
1284 // are shown in a row (one for Safe Browsing, one for invalid HTTPS). 1308 // are shown in a row (one for Safe Browsing, one for invalid HTTPS).
1285 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, 1309 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest,
1286 SecurityState_InvalidHTTPS) { 1310 SecurityState_InvalidHTTPS) {
1287 // The security indicator should be downgraded while the interstitial shows. 1311 // The security indicator should be downgraded while the interstitial shows.
1288 SetupWarningAndNavigateToInvalidHTTPS(); 1312 SetupWarningAndNavigateToInvalidHTTPS();
1289 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); 1313 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents();
1290 ASSERT_TRUE(error_tab); 1314 ASSERT_TRUE(error_tab);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 1373
1350 INSTANTIATE_TEST_CASE_P( 1374 INSTANTIATE_TEST_CASE_P(
1351 SafeBrowsingBlockingPageIDNTestWithThreatType, 1375 SafeBrowsingBlockingPageIDNTestWithThreatType,
1352 SafeBrowsingBlockingPageIDNTest, 1376 SafeBrowsingBlockingPageIDNTest,
1353 testing::Combine(testing::Values(false, true), 1377 testing::Combine(testing::Values(false, true),
1354 testing::Values(SB_THREAT_TYPE_URL_MALWARE, 1378 testing::Values(SB_THREAT_TYPE_URL_MALWARE,
1355 SB_THREAT_TYPE_URL_PHISHING, 1379 SB_THREAT_TYPE_URL_PHISHING,
1356 SB_THREAT_TYPE_URL_UNWANTED))); 1380 SB_THREAT_TYPE_URL_UNWANTED)));
1357 1381
1358 } // namespace safe_browsing 1382 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698