| 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 safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
| 6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
| 7 // service. | 7 // service. |
| 8 | 8 |
| 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 112 |
| 113 class MockSubresourceFilterDriver | 113 class MockSubresourceFilterDriver |
| 114 : public subresource_filter::ContentSubresourceFilterDriver { | 114 : public subresource_filter::ContentSubresourceFilterDriver { |
| 115 public: | 115 public: |
| 116 explicit MockSubresourceFilterDriver( | 116 explicit MockSubresourceFilterDriver( |
| 117 content::RenderFrameHost* render_frame_host) | 117 content::RenderFrameHost* render_frame_host) |
| 118 : subresource_filter::ContentSubresourceFilterDriver(render_frame_host) {} | 118 : subresource_filter::ContentSubresourceFilterDriver(render_frame_host) {} |
| 119 | 119 |
| 120 ~MockSubresourceFilterDriver() override = default; | 120 ~MockSubresourceFilterDriver() override = default; |
| 121 | 121 |
| 122 MOCK_METHOD3(ActivateForProvisionalLoad, | 122 MOCK_METHOD2(ActivateForNextCommittedLoad, |
| 123 void(subresource_filter::ActivationLevel, const GURL&, bool)); | 123 void(subresource_filter::ActivationLevel, bool)); |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterDriver); | 126 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterDriver); |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 class NeverCompletingHttpResponse : public net::test_server::HttpResponse { | 129 class NeverCompletingHttpResponse : public net::test_server::HttpResponse { |
| 130 public: | 130 public: |
| 131 ~NeverCompletingHttpResponse() override {} | 131 ~NeverCompletingHttpResponse() override {} |
| 132 | 132 |
| 133 void SendResponse( | 133 void SendResponse( |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); | 934 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); |
| 935 | 935 |
| 936 SBFullHashResult malware_full_hash; | 936 SBFullHashResult malware_full_hash; |
| 937 GenUrlFullHashResultWithMetadata(bad_url, | 937 GenUrlFullHashResultWithMetadata(bad_url, |
| 938 PHISH, | 938 PHISH, |
| 939 ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 939 ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 940 &malware_full_hash); | 940 &malware_full_hash); |
| 941 SetupResponseForUrl(bad_url, malware_full_hash); | 941 SetupResponseForUrl(bad_url, malware_full_hash); |
| 942 | 942 |
| 943 WebContents* main_contents = | 943 WebContents* main_contents = |
| 944 browser()->tab_strip_model()->GetActiveWebContents(); | 944 browser()->tab_strip_model()->GetActiveWebContents(); |
| 945 | 945 |
| 946 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) | 946 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 947 .Times(1); | 947 .Times(1); |
| 948 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(0); | 948 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(0); |
| 949 ui_test_utils::NavigateToURL(browser(), bad_url); | 949 ui_test_utils::NavigateToURL(browser(), bad_url); |
| 950 Mock::VerifyAndClearExpectations(&observer_); | 950 Mock::VerifyAndClearExpectations(&observer_); |
| 951 ASSERT_TRUE(got_hit_report()); | 951 ASSERT_TRUE(got_hit_report()); |
| 952 | 952 |
| 953 content::WaitForInterstitialAttach(main_contents); | 953 content::WaitForInterstitialAttach(main_contents); |
| 954 EXPECT_TRUE(ShowingInterstitialPage()); | 954 EXPECT_TRUE(ShowingInterstitialPage()); |
| 955 testing::Mock::VerifyAndClearExpectations(driver()); | 955 testing::Mock::VerifyAndClearExpectations(driver()); |
| 956 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(1); | 956 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(1); |
| 957 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); | 957 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); |
| 958 ASSERT_TRUE(interstitial_page); | 958 ASSERT_TRUE(interstitial_page); |
| 959 interstitial_page->Proceed(); | 959 interstitial_page->Proceed(); |
| 960 content::WaitForInterstitialDetach(main_contents); | 960 content::WaitForInterstitialDetach(main_contents); |
| 961 EXPECT_FALSE(ShowingInterstitialPage()); | 961 EXPECT_FALSE(ShowingInterstitialPage()); |
| 962 testing::Mock::VerifyAndClearExpectations(driver()); | 962 testing::Mock::VerifyAndClearExpectations(driver()); |
| 963 } | 963 } |
| 964 | 964 |
| 965 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, SocEngReportingBlacklistEmpty) { | 965 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, SocEngReportingBlacklistEmpty) { |
| 966 // Tests that URLS which doesn't belong to the SOCIAL_ENGINEERING_ADS threat | 966 // Tests that URLS which doesn't belong to the SOCIAL_ENGINEERING_ADS threat |
| 967 // type aren't seen by the Subresource Filter. | 967 // type aren't seen by the Subresource Filter. |
| 968 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 968 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle |
| 969 scoped_feature_toggle( | 969 scoped_feature_toggle( |
| 970 base::FeatureList::OVERRIDE_ENABLE_FEATURE, | 970 base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 971 subresource_filter::kActivationLevelEnabled, | 971 subresource_filter::kActivationLevelEnabled, |
| 972 subresource_filter::kActivationScopeNoSites, | 972 subresource_filter::kActivationScopeNoSites, |
| 973 subresource_filter::kActivationListSocialEngineeringAdsInterstitial); | 973 subresource_filter::kActivationListSocialEngineeringAdsInterstitial); |
| 974 | 974 |
| 975 GURL bad_url = embedded_test_server()->base_url().Resolve(kMalwarePage); | 975 GURL bad_url = embedded_test_server()->base_url().Resolve(kMalwarePage); |
| 976 | 976 |
| 977 SBFullHashResult malware_full_hash; | 977 SBFullHashResult malware_full_hash; |
| 978 GenUrlFullHashResult(bad_url, MALWARE, &malware_full_hash); | 978 GenUrlFullHashResult(bad_url, MALWARE, &malware_full_hash); |
| 979 SetupResponseForUrl(bad_url, malware_full_hash); | 979 SetupResponseForUrl(bad_url, malware_full_hash); |
| 980 | 980 |
| 981 WebContents* main_contents = | 981 WebContents* main_contents = |
| 982 browser()->tab_strip_model()->GetActiveWebContents(); | 982 browser()->tab_strip_model()->GetActiveWebContents(); |
| 983 | 983 |
| 984 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) | 984 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 985 .Times(1); | 985 .Times(1); |
| 986 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(0); | 986 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(0); |
| 987 ui_test_utils::NavigateToURL(browser(), bad_url); | 987 ui_test_utils::NavigateToURL(browser(), bad_url); |
| 988 testing::Mock::VerifyAndClearExpectations(driver()); | 988 testing::Mock::VerifyAndClearExpectations(driver()); |
| 989 ASSERT_TRUE(got_hit_report()); | 989 ASSERT_TRUE(got_hit_report()); |
| 990 | 990 |
| 991 content::WaitForInterstitialAttach(main_contents); | 991 content::WaitForInterstitialAttach(main_contents); |
| 992 EXPECT_TRUE(ShowingInterstitialPage()); | 992 EXPECT_TRUE(ShowingInterstitialPage()); |
| 993 testing::Mock::VerifyAndClearExpectations(driver()); | 993 testing::Mock::VerifyAndClearExpectations(driver()); |
| 994 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(0); | 994 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(0); |
| 995 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); | 995 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); |
| 996 ASSERT_TRUE(interstitial_page); | 996 ASSERT_TRUE(interstitial_page); |
| 997 interstitial_page->Proceed(); | 997 interstitial_page->Proceed(); |
| 998 content::WaitForInterstitialDetach(main_contents); | 998 content::WaitForInterstitialDetach(main_contents); |
| 999 EXPECT_FALSE(ShowingInterstitialPage()); | 999 EXPECT_FALSE(ShowingInterstitialPage()); |
| 1000 testing::Mock::VerifyAndClearExpectations(driver()); | 1000 testing::Mock::VerifyAndClearExpectations(driver()); |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, | 1003 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, |
| 1004 SubResourceHitWithMainFrameReferrer) { | 1004 SubResourceHitWithMainFrameReferrer) { |
| (...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2147 // Filter. | 2147 // Filter. |
| 2148 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); | 2148 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); |
| 2149 MarkUrlForPhishingUnexpired(bad_url, | 2149 MarkUrlForPhishingUnexpired(bad_url, |
| 2150 ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 2150 ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
| 2151 | 2151 |
| 2152 WebContents* main_contents = | 2152 WebContents* main_contents = |
| 2153 browser()->tab_strip_model()->GetActiveWebContents(); | 2153 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2154 | 2154 |
| 2155 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) | 2155 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 2156 .Times(1); | 2156 .Times(1); |
| 2157 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(0); | 2157 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(0); |
| 2158 ui_test_utils::NavigateToURL(browser(), bad_url); | 2158 ui_test_utils::NavigateToURL(browser(), bad_url); |
| 2159 Mock::VerifyAndClearExpectations(&observer_); | 2159 Mock::VerifyAndClearExpectations(&observer_); |
| 2160 ASSERT_TRUE(got_hit_report()); | 2160 ASSERT_TRUE(got_hit_report()); |
| 2161 | 2161 |
| 2162 content::WaitForInterstitialAttach(main_contents); | 2162 content::WaitForInterstitialAttach(main_contents); |
| 2163 EXPECT_TRUE(ShowingInterstitialPage()); | 2163 EXPECT_TRUE(ShowingInterstitialPage()); |
| 2164 testing::Mock::VerifyAndClearExpectations(driver()); | 2164 testing::Mock::VerifyAndClearExpectations(driver()); |
| 2165 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(1); | 2165 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(1); |
| 2166 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); | 2166 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); |
| 2167 ASSERT_TRUE(interstitial_page); | 2167 ASSERT_TRUE(interstitial_page); |
| 2168 interstitial_page->Proceed(); | 2168 interstitial_page->Proceed(); |
| 2169 content::WaitForInterstitialDetach(main_contents); | 2169 content::WaitForInterstitialDetach(main_contents); |
| 2170 EXPECT_FALSE(ShowingInterstitialPage()); | 2170 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2171 testing::Mock::VerifyAndClearExpectations(driver()); | 2171 testing::Mock::VerifyAndClearExpectations(driver()); |
| 2172 } | 2172 } |
| 2173 | 2173 |
| 2174 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, | 2174 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, |
| 2175 SocEngReportingBlacklistEmpty) { | 2175 SocEngReportingBlacklistEmpty) { |
| 2176 // Tests that URLS which doesn't belong to the SOCIAL_ENGINEERING_ADS threat | 2176 // Tests that URLS which doesn't belong to the SOCIAL_ENGINEERING_ADS threat |
| 2177 // type aren't seen by the Subresource Filter. | 2177 // type aren't seen by the Subresource Filter. |
| 2178 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle | 2178 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle |
| 2179 scoped_feature_toggle( | 2179 scoped_feature_toggle( |
| 2180 base::FeatureList::OVERRIDE_ENABLE_FEATURE, | 2180 base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 2181 subresource_filter::kActivationLevelEnabled, | 2181 subresource_filter::kActivationLevelEnabled, |
| 2182 subresource_filter::kActivationScopeNoSites, | 2182 subresource_filter::kActivationScopeNoSites, |
| 2183 subresource_filter::kActivationListSocialEngineeringAdsInterstitial); | 2183 subresource_filter::kActivationListSocialEngineeringAdsInterstitial); |
| 2184 | 2184 |
| 2185 GURL bad_url = embedded_test_server()->base_url().Resolve(kMalwarePage); | 2185 GURL bad_url = embedded_test_server()->base_url().Resolve(kMalwarePage); |
| 2186 MarkUrlForMalwareUnexpired(bad_url); | 2186 MarkUrlForMalwareUnexpired(bad_url); |
| 2187 | 2187 |
| 2188 WebContents* main_contents = | 2188 WebContents* main_contents = |
| 2189 browser()->tab_strip_model()->GetActiveWebContents(); | 2189 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2190 | 2190 |
| 2191 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) | 2191 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) |
| 2192 .Times(1); | 2192 .Times(1); |
| 2193 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(0); | 2193 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(0); |
| 2194 ui_test_utils::NavigateToURL(browser(), bad_url); | 2194 ui_test_utils::NavigateToURL(browser(), bad_url); |
| 2195 testing::Mock::VerifyAndClearExpectations(driver()); | 2195 testing::Mock::VerifyAndClearExpectations(driver()); |
| 2196 ASSERT_TRUE(got_hit_report()); | 2196 ASSERT_TRUE(got_hit_report()); |
| 2197 | 2197 |
| 2198 content::WaitForInterstitialAttach(main_contents); | 2198 content::WaitForInterstitialAttach(main_contents); |
| 2199 EXPECT_TRUE(ShowingInterstitialPage()); | 2199 EXPECT_TRUE(ShowingInterstitialPage()); |
| 2200 testing::Mock::VerifyAndClearExpectations(driver()); | 2200 testing::Mock::VerifyAndClearExpectations(driver()); |
| 2201 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(_, _, _)).Times(0); | 2201 EXPECT_CALL(*driver(), ActivateForNextCommittedLoad(_, _)).Times(0); |
| 2202 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); | 2202 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); |
| 2203 ASSERT_TRUE(interstitial_page); | 2203 ASSERT_TRUE(interstitial_page); |
| 2204 interstitial_page->Proceed(); | 2204 interstitial_page->Proceed(); |
| 2205 content::WaitForInterstitialDetach(main_contents); | 2205 content::WaitForInterstitialDetach(main_contents); |
| 2206 EXPECT_FALSE(ShowingInterstitialPage()); | 2206 EXPECT_FALSE(ShowingInterstitialPage()); |
| 2207 testing::Mock::VerifyAndClearExpectations(driver()); | 2207 testing::Mock::VerifyAndClearExpectations(driver()); |
| 2208 } | 2208 } |
| 2209 | 2209 |
| 2210 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, | 2210 IN_PROC_BROWSER_TEST_F(V4SafeBrowsingServiceTest, |
| 2211 SubResourceHitWithMainFrameReferrer) { | 2211 SubResourceHitWithMainFrameReferrer) { |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2657 } | 2657 } |
| 2658 | 2658 |
| 2659 INSTANTIATE_TEST_CASE_P( | 2659 INSTANTIATE_TEST_CASE_P( |
| 2660 MaybeSetMetadata, | 2660 MaybeSetMetadata, |
| 2661 V4SafeBrowsingServiceMetadataTest, | 2661 V4SafeBrowsingServiceMetadataTest, |
| 2662 testing::Values(ThreatPatternType::NONE, | 2662 testing::Values(ThreatPatternType::NONE, |
| 2663 ThreatPatternType::MALWARE_LANDING, | 2663 ThreatPatternType::MALWARE_LANDING, |
| 2664 ThreatPatternType::MALWARE_DISTRIBUTION)); | 2664 ThreatPatternType::MALWARE_DISTRIBUTION)); |
| 2665 | 2665 |
| 2666 } // namespace safe_browsing | 2666 } // namespace safe_browsing |
| OLD | NEW |