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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 for (auto resource : report.resources()) { | 564 for (auto resource : report.resources()) { |
565 if (actual_resource.parent_id() == resource.id()) { | 565 if (actual_resource.parent_id() == resource.id()) { |
566 EXPECT_EQ(expected_parent, resource.url()); | 566 EXPECT_EQ(expected_parent, resource.url()); |
567 break; | 567 break; |
568 } | 568 } |
569 } | 569 } |
570 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); | 570 EXPECT_EQ(expected_child_size, actual_resource.child_ids_size()); |
571 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); | 571 EXPECT_EQ(expected_tag_name, actual_resource.tag_name()); |
572 } | 572 } |
573 | 573 |
574 void ExpectSecurityIndicatorDowngrade(content::WebContents* tab) { | |
575 ChromeSecurityStateModelClient* model_client = | |
576 ChromeSecurityStateModelClient::FromWebContents(tab); | |
577 ASSERT_TRUE(model_client); | |
578 EXPECT_EQ(security_state::SecurityStateModel::SECURITY_ERROR, | |
579 model_client->GetSecurityInfo().security_level); | |
580 EXPECT_TRUE(model_client->GetSecurityInfo().fails_malware_check); | |
581 } | |
582 | |
574 protected: | 583 protected: |
575 TestThreatDetailsFactory details_factory_; | 584 TestThreatDetailsFactory details_factory_; |
576 | 585 |
577 private: | 586 private: |
578 // Adds a safebrowsing result of the current test threat to the fake | 587 // Adds a safebrowsing result of the current test threat to the fake |
579 // safebrowsing service, navigates to that page, and returns the url. | 588 // safebrowsing service, navigates to that page, and returns the url. |
580 // The various wrappers supply different URLs. | 589 // The various wrappers supply different URLs. |
581 GURL SetupWarningAndNavigateToURL(GURL url) { | 590 GURL SetupWarningAndNavigateToURL(GURL url) { |
582 SetURLThreatType(url, testing::get<0>(GetParam())); | 591 SetURLThreatType(url, testing::get<0>(GetParam())); |
583 ui_test_utils::NavigateToURL(browser(), url); | 592 ui_test_utils::NavigateToURL(browser(), url); |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1040 ui_test_utils::NavigateToURL(browser(), url); | 1049 ui_test_utils::NavigateToURL(browser(), url); |
1041 EXPECT_TRUE(WaitForReady()); | 1050 EXPECT_TRUE(WaitForReady()); |
1042 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1051 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1043 AssertNoInterstitial(true); | 1052 AssertNoInterstitial(true); |
1044 } | 1053 } |
1045 | 1054 |
1046 // Test that the security indicator is downgraded after clicking through a | 1055 // Test that the security indicator is downgraded after clicking through a |
1047 // Safe Browsing interstitial. | 1056 // Safe Browsing interstitial. |
1048 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1057 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1049 SecurityState_HTTP) { | 1058 SecurityState_HTTP) { |
1059 // The security indicator should be downgraded while the interstitial shows. | |
1050 SetupWarningAndNavigate(); | 1060 SetupWarningAndNavigate(); |
1061 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
1062 ASSERT_TRUE(error_tab); | |
1063 ExpectSecurityIndicatorDowngrade(error_tab); | |
1064 | |
1065 // The security indicator should still be downgraded post-interstitial. | |
1051 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1066 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1052 AssertNoInterstitial(true); | 1067 AssertNoInterstitial(true); |
1053 | 1068 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1054 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1069 ASSERT_TRUE(post_tab); |
1055 ASSERT_TRUE(tab); | 1070 ExpectSecurityIndicatorDowngrade(post_tab); |
1056 ChromeSecurityStateModelClient* model_client = | |
1057 ChromeSecurityStateModelClient::FromWebContents(tab); | |
1058 ASSERT_TRUE(model_client); | |
1059 EXPECT_EQ(security_state::SecurityStateModel::SECURITY_ERROR, | |
1060 model_client->GetSecurityInfo().security_level); | |
1061 EXPECT_TRUE(model_client->GetSecurityInfo().fails_malware_check); | |
1062 } | 1071 } |
1063 | 1072 |
1064 // Test that the security indicator is downgraded even if the website has valid | 1073 // Test that the security indicator is downgraded even if the website has valid |
1065 // HTTPS (meaning that the SB state overrides the HTTPS state). | 1074 // HTTPS (meaning that the SB state overrides the HTTPS state). |
1066 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1075 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1067 SecurityState_ValidHTTPS) { | 1076 SecurityState_ValidHTTPS) { |
1077 // The security indicator should be downgraded while the interstitial shows. | |
1068 SetupWarningAndNavigateToValidHTTPS(); | 1078 SetupWarningAndNavigateToValidHTTPS(); |
1079 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
1080 ASSERT_TRUE(error_tab); | |
1081 ExpectSecurityIndicatorDowngrade(error_tab); | |
1082 | |
1083 // The security indicator should still be downgraded post-interstitial. | |
1069 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1084 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1070 AssertNoInterstitial(true); | 1085 AssertNoInterstitial(true); |
1071 | 1086 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1072 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1087 ASSERT_TRUE(post_tab); |
1073 ASSERT_TRUE(tab); | 1088 ExpectSecurityIndicatorDowngrade(post_tab); |
1074 ChromeSecurityStateModelClient* model_client = | |
1075 ChromeSecurityStateModelClient::FromWebContents(tab); | |
1076 ASSERT_TRUE(model_client); | |
1077 EXPECT_EQ(security_state::SecurityStateModel::SECURITY_ERROR, | |
1078 model_client->GetSecurityInfo().security_level); | |
1079 EXPECT_TRUE(model_client->GetSecurityInfo().fails_malware_check); | |
1080 EXPECT_EQ(0u, model_client->GetSecurityInfo().cert_status); | 1089 EXPECT_EQ(0u, model_client->GetSecurityInfo().cert_status); |
1081 } | 1090 } |
1082 | 1091 |
1083 // Test that the security indicator is still downgraded after two interstitials | 1092 // Test that the security indicator is still downgraded after two interstitials |
1084 // are shown in a row (one for Safe Browsing, one for invalid HTTPS). | 1093 // are shown in a row (one for Safe Browsing, one for invalid HTTPS). |
1085 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, | 1094 IN_PROC_BROWSER_TEST_P(SafeBrowsingBlockingPageBrowserTest, |
1086 SecurityState_InvalidHTTPS) { | 1095 SecurityState_InvalidHTTPS) { |
1096 // The security indicator should be downgraded while the interstitial shows. | |
1087 SetupWarningAndNavigateToInvalidHTTPS(); | 1097 SetupWarningAndNavigateToInvalidHTTPS(); |
1098 WebContents* error_tab = browser()->tab_strip_model()->GetActiveWebContents(); | |
1099 ASSERT_TRUE(error_tab); | |
1100 ExpectSecurityIndicatorDowngrade(error_tab); | |
1101 | |
1102 // The security indicator should still be downgraded post-interstitial. | |
1088 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); | 1103 EXPECT_TRUE(ClickAndWaitForDetach("proceed-link")); |
1089 AssertNoInterstitial(true); | 1104 AssertNoInterstitial(true); |
1090 | 1105 WebContents* post_tab = browser()->tab_strip_model()->GetActiveWebContents(); |
1091 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 1106 ASSERT_TRUE(post_tab); |
1092 ASSERT_TRUE(tab); | 1107 ExpectSecurityIndicatorDowngrade(post_tab); |
1093 ChromeSecurityStateModelClient* model_client = | |
1094 ChromeSecurityStateModelClient::FromWebContents(tab); | |
1095 ASSERT_TRUE(model_client); | |
1096 EXPECT_EQ(security_state::SecurityStateModel::SECURITY_ERROR, | |
1097 model_client->GetSecurityInfo().security_level); | |
1098 EXPECT_TRUE(model_client->GetSecurityInfo().fails_malware_check); | |
1099 EXPECT_NE(0u, model_client->GetSecurityInfo().cert_status); | 1108 EXPECT_NE(0u, model_client->GetSecurityInfo().cert_status); |
felt
2016/08/25 06:10:33
Note: this line (which depends on having a model_c
| |
1100 } | 1109 } |
1101 | 1110 |
1102 INSTANTIATE_TEST_CASE_P( | 1111 INSTANTIATE_TEST_CASE_P( |
1103 SafeBrowsingBlockingPageBrowserTestWithThreatTypeAndIsolationSetting, | 1112 SafeBrowsingBlockingPageBrowserTestWithThreatTypeAndIsolationSetting, |
1104 SafeBrowsingBlockingPageBrowserTest, | 1113 SafeBrowsingBlockingPageBrowserTest, |
1105 testing::Combine( | 1114 testing::Combine( |
1106 testing::Values(SB_THREAT_TYPE_URL_MALWARE, // Threat types | 1115 testing::Values(SB_THREAT_TYPE_URL_MALWARE, // Threat types |
1107 SB_THREAT_TYPE_URL_PHISHING, | 1116 SB_THREAT_TYPE_URL_PHISHING, |
1108 SB_THREAT_TYPE_URL_UNWANTED), | 1117 SB_THREAT_TYPE_URL_UNWANTED), |
1109 testing::Bool())); // If isolate all sites for testing. | 1118 testing::Bool())); // If isolate all sites for testing. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 | 1156 |
1148 INSTANTIATE_TEST_CASE_P( | 1157 INSTANTIATE_TEST_CASE_P( |
1149 SafeBrowsingBlockingPageIDNTestWithThreatType, | 1158 SafeBrowsingBlockingPageIDNTestWithThreatType, |
1150 SafeBrowsingBlockingPageIDNTest, | 1159 SafeBrowsingBlockingPageIDNTest, |
1151 testing::Combine(testing::Values(false, true), | 1160 testing::Combine(testing::Values(false, true), |
1152 testing::Values(SB_THREAT_TYPE_URL_MALWARE, | 1161 testing::Values(SB_THREAT_TYPE_URL_MALWARE, |
1153 SB_THREAT_TYPE_URL_PHISHING, | 1162 SB_THREAT_TYPE_URL_PHISHING, |
1154 SB_THREAT_TYPE_URL_UNWANTED))); | 1163 SB_THREAT_TYPE_URL_UNWANTED))); |
1155 | 1164 |
1156 } // namespace safe_browsing | 1165 } // namespace safe_browsing |
OLD | NEW |