OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "components/subresource_filter/content/browser/subresource_filter_navig
ation_throttle.h" | 5 #include "components/subresource_filter/content/browser/subresource_filter_navig
ation_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 TEST_F(SubresourceFilterNavigationThrottleTest, RequestWithoutRedirects) { | 127 TEST_F(SubresourceFilterNavigationThrottleTest, RequestWithoutRedirects) { |
128 base::FieldTrialList field_trial_list(nullptr); | 128 base::FieldTrialList field_trial_list(nullptr); |
129 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 129 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
130 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, | 130 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, |
131 kActivationScopeActivationList); | 131 kActivationScopeActivationList); |
132 | 132 |
133 const GURL url(kExampleURL); | 133 const GURL url(kExampleURL); |
134 SetUpNavigationHandleForURL(url); | 134 SetUpNavigationHandleForURL(url); |
135 SimulateWillStart(); | 135 SimulateWillStart(); |
136 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 136 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
137 url, std::vector<GURL>(), | 137 url, std::vector<GURL>(), safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
138 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 138 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
139 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) | 139 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) |
140 .Times(1); | 140 .Times(1); |
141 SimulateWillProcessResponse(); | 141 SimulateWillProcessResponse(); |
142 ::testing::Mock::VerifyAndClearExpectations(driver()); | 142 ::testing::Mock::VerifyAndClearExpectations(driver()); |
143 | 143 |
144 EXPECT_EQ(1U, factory()->activation_set().size()); | 144 EXPECT_EQ(1U, factory()->activation_set().size()); |
145 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); | 145 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); |
146 } | 146 } |
147 | 147 |
148 TEST_F(SubresourceFilterNavigationThrottleTest, | 148 TEST_F(SubresourceFilterNavigationThrottleTest, |
149 RequestWithoutRedirectsNoActivation) { | 149 RequestWithoutRedirectsNoActivation) { |
150 base::FieldTrialList field_trial_list(nullptr); | 150 base::FieldTrialList field_trial_list(nullptr); |
151 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 151 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
152 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, | 152 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, |
153 kActivationScopeActivationList); | 153 kActivationScopeActivationList); |
154 | 154 |
155 const GURL url_with_activation(kExampleURL); | 155 const GURL url_with_activation(kExampleURL); |
156 const GURL url_without_activation(kTestURL); | 156 const GURL url_without_activation(kTestURL); |
157 | 157 |
158 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 158 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
159 url_with_activation, std::vector<GURL>(), | 159 url_with_activation, std::vector<GURL>(), |
| 160 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
160 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 161 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
161 | 162 |
162 SetUpNavigationHandleForURL(url_without_activation); | 163 SetUpNavigationHandleForURL(url_without_activation); |
163 SimulateWillStart(); | 164 SimulateWillStart(); |
164 | 165 |
165 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0); | 166 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0); |
166 SimulateWillProcessResponse(); | 167 SimulateWillProcessResponse(); |
167 ::testing::Mock::VerifyAndClearExpectations(driver()); | 168 ::testing::Mock::VerifyAndClearExpectations(driver()); |
168 | 169 |
169 EXPECT_EQ(1U, factory()->activation_set().size()); | 170 EXPECT_EQ(1U, factory()->activation_set().size()); |
170 EXPECT_TRUE(factory()->ShouldActivateForURL(url_with_activation)); | 171 EXPECT_TRUE(factory()->ShouldActivateForURL(url_with_activation)); |
171 EXPECT_FALSE(factory()->ShouldActivateForURL(url_without_activation)); | 172 EXPECT_FALSE(factory()->ShouldActivateForURL(url_without_activation)); |
172 } | 173 } |
173 | 174 |
174 TEST_F(SubresourceFilterNavigationThrottleTest, | 175 TEST_F(SubresourceFilterNavigationThrottleTest, |
175 RequestToNonWebURLNoActivation) { | 176 RequestToNonWebURLNoActivation) { |
176 base::FieldTrialList field_trial_list(nullptr); | 177 base::FieldTrialList field_trial_list(nullptr); |
177 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 178 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
178 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, | 179 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, |
179 kActivationScopeActivationList); | 180 kActivationScopeActivationList); |
180 | 181 |
181 const GURL non_web_url(kNonWebURL); | 182 const GURL non_web_url(kNonWebURL); |
182 | 183 |
183 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 184 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
184 non_web_url, std::vector<GURL>(), | 185 non_web_url, std::vector<GURL>(), |
| 186 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
185 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 187 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
186 | 188 |
187 SetUpNavigationHandleForURL(non_web_url); | 189 SetUpNavigationHandleForURL(non_web_url); |
188 SimulateWillStart(); | 190 SimulateWillStart(); |
189 | 191 |
190 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0); | 192 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0); |
191 SimulateWillProcessResponse(); | 193 SimulateWillProcessResponse(); |
192 ::testing::Mock::VerifyAndClearExpectations(driver()); | 194 ::testing::Mock::VerifyAndClearExpectations(driver()); |
193 | 195 |
194 EXPECT_EQ(0U, factory()->activation_set().size()); | 196 EXPECT_EQ(0U, factory()->activation_set().size()); |
195 EXPECT_FALSE(factory()->ShouldActivateForURL(non_web_url)); | 197 EXPECT_FALSE(factory()->ShouldActivateForURL(non_web_url)); |
196 } | 198 } |
197 | 199 |
198 TEST_F(SubresourceFilterNavigationThrottleTest, | 200 TEST_F(SubresourceFilterNavigationThrottleTest, |
199 AddRedirectFromNavThrottleToServiceEmptyInitRedirects) { | 201 AddRedirectFromNavThrottleToServiceEmptyInitRedirects) { |
200 // Navigations |url| -> |redirect|. Safe Browsing classifies the |url| as | 202 // Navigations |url| -> |redirect|. Safe Browsing classifies the |url| as |
201 // containing deceptive content. | 203 // containing deceptive content. |
202 // Test checks that both |url| and |redirect| are in the activation set. | 204 // Test checks that both |url| and |redirect| are in the activation set. |
203 base::FieldTrialList field_trial_list(nullptr); | 205 base::FieldTrialList field_trial_list(nullptr); |
204 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 206 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
205 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, | 207 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, |
206 kActivationScopeActivationList); | 208 kActivationScopeActivationList); |
207 | 209 |
208 const GURL url(kExampleURL); | 210 const GURL url(kExampleURL); |
209 const GURL redirect(kRedirectURLFirst); | 211 const GURL redirect(kRedirectURLFirst); |
210 | 212 |
211 SetUpNavigationHandleForURL(url); | 213 SetUpNavigationHandleForURL(url); |
212 SimulateWillStart(); | 214 SimulateWillStart(); |
213 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 215 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
214 url, std::vector<GURL>(), | 216 url, std::vector<GURL>(), safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
215 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 217 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
216 SimulateRedirects(redirect); | 218 SimulateRedirects(redirect); |
217 | 219 |
218 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) | 220 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) |
219 .Times(1); | 221 .Times(1); |
220 SimulateWillProcessResponse(); | 222 SimulateWillProcessResponse(); |
221 ::testing::Mock::VerifyAndClearExpectations(driver()); | 223 ::testing::Mock::VerifyAndClearExpectations(driver()); |
222 | 224 |
223 EXPECT_EQ(2U, factory()->activation_set().size()); | 225 EXPECT_EQ(2U, factory()->activation_set().size()); |
224 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); | 226 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); |
(...skipping 16 matching lines...) Expand all Loading... |
241 const GURL first_redirect(kRedirectURLFirst); | 243 const GURL first_redirect(kRedirectURLFirst); |
242 const GURL second_redirect(kRedirectURLSecond); | 244 const GURL second_redirect(kRedirectURLSecond); |
243 const GURL third_redirect(kRedirectURLThird); | 245 const GURL third_redirect(kRedirectURLThird); |
244 | 246 |
245 SetUpNavigationHandleForURL(url); | 247 SetUpNavigationHandleForURL(url); |
246 SimulateWillStart(); | 248 SimulateWillStart(); |
247 | 249 |
248 std::vector<GURL> redirects = {first_redirect, second_redirect, | 250 std::vector<GURL> redirects = {first_redirect, second_redirect, |
249 third_redirect}; | 251 third_redirect}; |
250 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 252 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
251 url, redirects, safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 253 url, redirects, safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 254 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
252 | 255 |
253 SimulateRedirects(redirect_after_sb_classification); | 256 SimulateRedirects(redirect_after_sb_classification); |
254 | 257 |
255 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) | 258 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) |
256 .Times(1); | 259 .Times(1); |
257 SimulateWillProcessResponse(); | 260 SimulateWillProcessResponse(); |
258 ::testing::Mock::VerifyAndClearExpectations(driver()); | 261 ::testing::Mock::VerifyAndClearExpectations(driver()); |
259 | 262 |
260 EXPECT_EQ(redirects.size() + 2U, factory()->activation_set().size()); | 263 EXPECT_EQ(redirects.size() + 2U, factory()->activation_set().size()); |
261 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); | 264 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); |
262 EXPECT_TRUE(factory()->ShouldActivateForURL(first_redirect)); | 265 EXPECT_TRUE(factory()->ShouldActivateForURL(first_redirect)); |
263 EXPECT_TRUE(factory()->ShouldActivateForURL(second_redirect)); | 266 EXPECT_TRUE(factory()->ShouldActivateForURL(second_redirect)); |
264 EXPECT_TRUE(factory()->ShouldActivateForURL(third_redirect)); | 267 EXPECT_TRUE(factory()->ShouldActivateForURL(third_redirect)); |
265 EXPECT_TRUE( | 268 EXPECT_TRUE( |
266 factory()->ShouldActivateForURL(redirect_after_sb_classification)); | 269 factory()->ShouldActivateForURL(redirect_after_sb_classification)); |
267 } | 270 } |
268 | 271 |
269 TEST_F(SubresourceFilterNavigationThrottleTest, | 272 TEST_F(SubresourceFilterNavigationThrottleTest, |
270 RequestRedirectWithMatchRedirectTest) { | 273 RequestRedirectWithMatchRedirectTest) { |
271 base::FieldTrialList field_trial_list(nullptr); | 274 base::FieldTrialList field_trial_list(nullptr); |
272 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 275 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
273 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, | 276 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, |
274 kActivationScopeActivationList); | 277 kActivationScopeActivationList); |
275 | 278 |
276 const GURL init_url(kExampleURL); | 279 const GURL init_url(kExampleURL); |
277 const GURL redirect_with_match(kRedirectURLFirst); | 280 const GURL redirect_with_match(kRedirectURLFirst); |
278 const GURL final_url(kRedirectURLSecond); | 281 const GURL final_url(kRedirectURLSecond); |
279 std::vector<GURL> redirects = {redirect_with_match}; | 282 std::vector<GURL> redirects = {redirect_with_match}; |
280 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 283 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
281 init_url, redirects, | 284 init_url, redirects, safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
282 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); | 285 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); |
283 | 286 |
284 SetUpNavigationHandleForURL(init_url); | 287 SetUpNavigationHandleForURL(init_url); |
285 SimulateWillStart(); | 288 SimulateWillStart(); |
286 SimulateRedirects(redirect_with_match); | 289 SimulateRedirects(redirect_with_match); |
287 SimulateRedirects(final_url); | 290 SimulateRedirects(final_url); |
288 | 291 |
289 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) | 292 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) |
290 .Times(1); | 293 .Times(1); |
291 SimulateWillProcessResponse(); | 294 SimulateWillProcessResponse(); |
292 ::testing::Mock::VerifyAndClearExpectations(driver()); | 295 ::testing::Mock::VerifyAndClearExpectations(driver()); |
293 | 296 |
294 EXPECT_EQ(3U, factory()->activation_set().size()); | 297 EXPECT_EQ(3U, factory()->activation_set().size()); |
295 EXPECT_TRUE(factory()->ShouldActivateForURL(init_url)); | 298 EXPECT_TRUE(factory()->ShouldActivateForURL(init_url)); |
296 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect_with_match)); | 299 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect_with_match)); |
297 EXPECT_TRUE(factory()->ShouldActivateForURL(final_url)); | 300 EXPECT_TRUE(factory()->ShouldActivateForURL(final_url)); |
298 } | 301 } |
299 | 302 |
300 } // namespace subresource_filter | 303 } // namespace subresource_filter |
OLD | NEW |