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 26 matching lines...) Expand all Loading... |
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 "content/public/browser/interstitial_page.h" | 45 #include "content/public/browser/interstitial_page.h" |
46 #include "content/public/browser/navigation_controller.h" | 46 #include "content/public/browser/navigation_controller.h" |
| 47 #include "content/public/browser/navigation_entry.h" |
47 #include "content/public/browser/notification_types.h" | 48 #include "content/public/browser/notification_types.h" |
48 #include "content/public/browser/render_frame_host.h" | 49 #include "content/public/browser/render_frame_host.h" |
49 #include "content/public/browser/render_process_host.h" | 50 #include "content/public/browser/render_process_host.h" |
50 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
51 #include "content/public/test/browser_test_utils.h" | 52 #include "content/public/test/browser_test_utils.h" |
52 #include "content/public/test/test_browser_thread.h" | 53 #include "content/public/test/test_browser_thread.h" |
53 #include "content/public/test/test_utils.h" | 54 #include "content/public/test/test_utils.h" |
54 #include "net/cert/cert_verify_result.h" | 55 #include "net/cert/cert_verify_result.h" |
55 #include "net/cert/mock_cert_verifier.h" | 56 #include "net/cert/mock_cert_verifier.h" |
56 #include "net/test/embedded_test_server/embedded_test_server.h" | 57 #include "net/test/embedded_test_server/embedded_test_server.h" |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 ASSERT_TRUE(model_client); | 575 ASSERT_TRUE(model_client); |
575 security_state::SecurityStateModel::SecurityInfo security_info; | 576 security_state::SecurityStateModel::SecurityInfo security_info; |
576 model_client->GetSecurityInfo(&security_info); | 577 model_client->GetSecurityInfo(&security_info); |
577 EXPECT_EQ(security_state::SecurityStateModel::DANGEROUS, | 578 EXPECT_EQ(security_state::SecurityStateModel::DANGEROUS, |
578 security_info.security_level); | 579 security_info.security_level); |
579 EXPECT_TRUE(security_info.fails_malware_check); | 580 EXPECT_TRUE(security_info.fails_malware_check); |
580 // TODO(felt): Restore this check when https://crbug.com/641187 is fixed. | 581 // TODO(felt): Restore this check when https://crbug.com/641187 is fixed. |
581 // EXPECT_EQ(cert_status, model_client->GetSecurityInfo().cert_status); | 582 // EXPECT_EQ(cert_status, model_client->GetSecurityInfo().cert_status); |
582 } | 583 } |
583 | 584 |
| 585 void ExpectNoSecurityIndicatorDowngrade(content::WebContents* tab) { |
| 586 ChromeSecurityStateModelClient* model_client = |
| 587 ChromeSecurityStateModelClient::FromWebContents(tab); |
| 588 ASSERT_TRUE(model_client); |
| 589 security_state::SecurityStateModel::SecurityInfo security_info; |
| 590 model_client->GetSecurityInfo(&security_info); |
| 591 EXPECT_EQ(security_state::SecurityStateModel::NONE, |
| 592 security_info.security_level); |
| 593 EXPECT_FALSE(security_info.fails_malware_check); |
| 594 } |
| 595 |
584 protected: | 596 protected: |
585 TestThreatDetailsFactory details_factory_; | 597 TestThreatDetailsFactory details_factory_; |
586 | 598 |
587 private: | 599 private: |
588 // Adds a safebrowsing result of the current test threat to the fake | 600 // Adds a safebrowsing result of the current test threat to the fake |
589 // safebrowsing service, navigates to that page, and returns the url. | 601 // safebrowsing service, navigates to that page, and returns the url. |
590 // The various wrappers supply different URLs. | 602 // The various wrappers supply different URLs. |
591 GURL SetupWarningAndNavigateToURL(GURL url) { | 603 GURL SetupWarningAndNavigateToURL(GURL url) { |
592 SetURLThreatType(url, testing::get<0>(GetParam())); | 604 SetURLThreatType(url, testing::get<0>(GetParam())); |
593 ui_test_utils::NavigateToURL(browser(), url); | 605 ui_test_utils::NavigateToURL(browser(), url); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 observer.latest_security_style()); | 1100 observer.latest_security_style()); |
1089 | 1101 |
1090 // The security indicator should still be downgraded post-interstitial. | 1102 // The security indicator should still be downgraded post-interstitial. |
1091 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1103 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1092 AssertNoInterstitial(true); | 1104 AssertNoInterstitial(true); |
1093 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1105 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1094 ASSERT_TRUE(post_tab); | 1106 ASSERT_TRUE(post_tab); |
1095 ExpectSecurityIndicatorDowngrade(post_tab, 0u); | 1107 ExpectSecurityIndicatorDowngrade(post_tab, 0u); |
1096 } | 1108 } |
1097 | 1109 |
| 1110 // Test that the security indicator does not stay downgraded after |
| 1111 // clicking back from a Safe Browsing interstitial. Regression test for |
| 1112 // https://crbug.com/659709. |
| 1113 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
| 1114 SecurityStateGoBack) { |
| 1115 // Navigate to a page so that there is somewhere to go back to. |
| 1116 GURL start_url = |
| 1117 net::URLRequestMockHTTPJob::GetMockUrl("http://example.test"); |
| 1118 ui_test_utils::NavigateToURL(browser(), start_url); |
| 1119 |
| 1120 // The security indicator should be downgraded while the interstitial shows. |
| 1121 SetupWarningAndNavigate(); |
| 1122 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1123 ASSERT_TRUE(error_tab); |
| 1124 ExpectSecurityIndicatorDowngrade(error_tab, 0u); |
| 1125 |
| 1126 // Go back. |
| 1127 EXPECT_EQ(VISIBLE, GetVisibility("primary-button")); |
| 1128 EXPECT_EQ(HIDDEN, GetVisibility("details")); |
| 1129 EXPECT_EQ(HIDDEN, GetVisibility("proceed-link")); |
| 1130 EXPECT_EQ(HIDDEN, GetVisibility("error-code")); |
| 1131 EXPECT_TRUE(Click("details-button")); |
| 1132 EXPECT_EQ(VISIBLE, GetVisibility("details")); |
| 1133 EXPECT_EQ(VISIBLE, GetVisibility("proceed-link")); |
| 1134 EXPECT_EQ(HIDDEN, GetVisibility("error-code")); |
| 1135 EXPECT_TRUE(ClickAndWaitForDetach("primary-button")); |
| 1136 |
| 1137 // The security indicator should *not* still be downgraded after going back. |
| 1138 AssertNoInterstitial(true); |
| 1139 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
| 1140 ASSERT_TRUE(post_tab); |
| 1141 content::NavigationEntry* entry = post_tab->GetController().GetVisibleEntry(); |
| 1142 ASSERT_TRUE(entry); |
| 1143 EXPECT_EQ(start_url, entry->GetURL()); |
| 1144 ExpectNoSecurityIndicatorDowngrade(post_tab); |
| 1145 } |
| 1146 |
1098 // Test that the security indicator is downgraded after clicking through a | 1147 // Test that the security indicator is downgraded after clicking through a |
1099 // Safe Browsing interstitial. | 1148 // Safe Browsing interstitial. |
1100 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1149 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1101 SecurityState_HTTP) { | 1150 SecurityState_HTTP) { |
1102 // The security indicator should be downgraded while the interstitial shows. | 1151 // The security indicator should be downgraded while the interstitial shows. |
1103 SetupWarningAndNavigate(); | 1152 SetupWarningAndNavigate(); |
1104 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1153 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1105 ASSERT_TRUE(error_tab); | 1154 ASSERT_TRUE(error_tab); |
1106 ExpectSecurityIndicatorDowngrade(error_tab, 0u); | 1155 ExpectSecurityIndicatorDowngrade(error_tab, 0u); |
1107 | 1156 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 | 1248 |
1200 INSTANTIATE_TEST_CASE_P( | 1249 INSTANTIATE_TEST_CASE_P( |
1201 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1250 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1202 SafeBrowsingBlockingPageIDNTest, | 1251 SafeBrowsingBlockingPageIDNTest, |
1203 testing::Combine(testing::Values(false, true), | 1252 testing::Combine(testing::Values(false, true), |
1204 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1253 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1205 SB_THREAT_TYPE_URL_PHISHING, | 1254 SB_THREAT_TYPE_URL_PHISHING, |
1206 SB_THREAT_TYPE_URL_UNWANTED))); | 1255 SB_THREAT_TYPE_URL_UNWANTED))); |
1207 | 1256 |
1208 } // namespace safe_browsing | 1257 } // namespace safe_browsing |
OLD | NEW |