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

Side by Side Diff: components/subresource_filter/content/browser/subresource_filter_navigation_throttle_unittests.cc

Issue 2272323002: Allow Safe Browsing Saresource Filter to distinguish between different lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix safe_browsing_service_browsertest Created 4 years, 3 months 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 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 MockSubresourceFilterDriver* driver_; 121 MockSubresourceFilterDriver* driver_;
122 std::unique_ptr<content::NavigationHandle> handle_; 122 std::unique_ptr<content::NavigationHandle> handle_;
123 123
124 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterNavigationThrottleTest); 124 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterNavigationThrottleTest);
125 }; 125 };
126 126
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 kActivationListSocialEngineeringAdsInterstitial);
132 133
133 const GURL url(kExampleURL); 134 const GURL url(kExampleURL);
134 SetUpNavigationHandleForURL(url); 135 SetUpNavigationHandleForURL(url);
135 SimulateWillStart(); 136 SimulateWillStart();
136 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 137 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
137 url, std::vector<GURL>(), 138 url, std::vector<GURL>(), safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
138 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 139 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
139 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) 140 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED))
140 .Times(1); 141 .Times(1);
141 SimulateWillProcessResponse(); 142 SimulateWillProcessResponse();
142 ::testing::Mock::VerifyAndClearExpectations(driver()); 143 ::testing::Mock::VerifyAndClearExpectations(driver());
143 144
144 EXPECT_EQ(1U, factory()->activation_set().size()); 145 EXPECT_EQ(1U, factory()->activation_set().size());
145 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); 146 EXPECT_TRUE(factory()->ShouldActivateForURL(url));
146 } 147 }
147 148
148 TEST_F(SubresourceFilterNavigationThrottleTest, 149 TEST_F(SubresourceFilterNavigationThrottleTest,
149 RequestWithoutRedirectsNoActivation) { 150 RequestWithoutRedirectsNoActivation) {
150 base::FieldTrialList field_trial_list(nullptr); 151 base::FieldTrialList field_trial_list(nullptr);
151 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 152 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
152 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 153 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
153 kActivationScopeActivationList); 154 kActivationScopeActivationList,
155 kActivationListSocialEngineeringAdsInterstitial);
154 156
155 const GURL url_with_activation(kExampleURL); 157 const GURL url_with_activation(kExampleURL);
156 const GURL url_without_activation(kTestURL); 158 const GURL url_without_activation(kTestURL);
157 159
158 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 160 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
159 url_with_activation, std::vector<GURL>(), 161 url_with_activation, std::vector<GURL>(),
162 safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
160 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 163 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
161 164
162 SetUpNavigationHandleForURL(url_without_activation); 165 SetUpNavigationHandleForURL(url_without_activation);
163 SimulateWillStart(); 166 SimulateWillStart();
164 167
165 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0); 168 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0);
166 SimulateWillProcessResponse(); 169 SimulateWillProcessResponse();
167 ::testing::Mock::VerifyAndClearExpectations(driver()); 170 ::testing::Mock::VerifyAndClearExpectations(driver());
168 171
169 EXPECT_EQ(1U, factory()->activation_set().size()); 172 EXPECT_EQ(1U, factory()->activation_set().size());
170 EXPECT_TRUE(factory()->ShouldActivateForURL(url_with_activation)); 173 EXPECT_TRUE(factory()->ShouldActivateForURL(url_with_activation));
171 EXPECT_FALSE(factory()->ShouldActivateForURL(url_without_activation)); 174 EXPECT_FALSE(factory()->ShouldActivateForURL(url_without_activation));
172 } 175 }
173 176
174 TEST_F(SubresourceFilterNavigationThrottleTest, 177 TEST_F(SubresourceFilterNavigationThrottleTest,
175 RequestToNonWebURLNoActivation) { 178 RequestToNonWebURLNoActivation) {
176 base::FieldTrialList field_trial_list(nullptr); 179 base::FieldTrialList field_trial_list(nullptr);
177 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 180 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
178 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 181 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
179 kActivationScopeActivationList); 182 kActivationScopeActivationList,
183 kActivationListSocialEngineeringAdsInterstitial);
180 184
181 const GURL non_web_url(kNonWebURL); 185 const GURL non_web_url(kNonWebURL);
182 186
183 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 187 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
184 non_web_url, std::vector<GURL>(), 188 non_web_url, std::vector<GURL>(),
189 safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
185 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 190 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
186 191
187 SetUpNavigationHandleForURL(non_web_url); 192 SetUpNavigationHandleForURL(non_web_url);
188 SimulateWillStart(); 193 SimulateWillStart();
189 194
190 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0); 195 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_)).Times(0);
191 SimulateWillProcessResponse(); 196 SimulateWillProcessResponse();
192 ::testing::Mock::VerifyAndClearExpectations(driver()); 197 ::testing::Mock::VerifyAndClearExpectations(driver());
193 198
194 EXPECT_EQ(0U, factory()->activation_set().size()); 199 EXPECT_EQ(0U, factory()->activation_set().size());
195 EXPECT_FALSE(factory()->ShouldActivateForURL(non_web_url)); 200 EXPECT_FALSE(factory()->ShouldActivateForURL(non_web_url));
196 } 201 }
197 202
198 TEST_F(SubresourceFilterNavigationThrottleTest, 203 TEST_F(SubresourceFilterNavigationThrottleTest,
199 AddRedirectFromNavThrottleToServiceEmptyInitRedirects) { 204 AddRedirectFromNavThrottleToServiceEmptyInitRedirects) {
200 // Navigations |url| -> |redirect|. Safe Browsing classifies the |url| as 205 // Navigations |url| -> |redirect|. Safe Browsing classifies the |url| as
201 // containing deceptive content. 206 // containing deceptive content.
202 // Test checks that both |url| and |redirect| are in the activation set. 207 // Test checks that both |url| and |redirect| are in the activation set.
203 base::FieldTrialList field_trial_list(nullptr); 208 base::FieldTrialList field_trial_list(nullptr);
204 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 209 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
205 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 210 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
206 kActivationScopeActivationList); 211 kActivationScopeActivationList,
212 kActivationListSocialEngineeringAdsInterstitial);
207 213
208 const GURL url(kExampleURL); 214 const GURL url(kExampleURL);
209 const GURL redirect(kRedirectURLFirst); 215 const GURL redirect(kRedirectURLFirst);
210 216
211 SetUpNavigationHandleForURL(url); 217 SetUpNavigationHandleForURL(url);
212 SimulateWillStart(); 218 SimulateWillStart();
213 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 219 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
214 url, std::vector<GURL>(), 220 url, std::vector<GURL>(), safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
215 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 221 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
216 SimulateRedirects(redirect); 222 SimulateRedirects(redirect);
217 223
218 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) 224 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED))
219 .Times(1); 225 .Times(1);
220 SimulateWillProcessResponse(); 226 SimulateWillProcessResponse();
221 ::testing::Mock::VerifyAndClearExpectations(driver()); 227 ::testing::Mock::VerifyAndClearExpectations(driver());
222 228
223 EXPECT_EQ(2U, factory()->activation_set().size()); 229 EXPECT_EQ(2U, factory()->activation_set().size());
224 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); 230 EXPECT_TRUE(factory()->ShouldActivateForURL(url));
225 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect)); 231 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect));
226 } 232 }
227 233
228 TEST_F(SubresourceFilterNavigationThrottleTest, 234 TEST_F(SubresourceFilterNavigationThrottleTest,
229 AddRedirectFromNavThrottleToServiceNonEmptyInitRedirects) { 235 AddRedirectFromNavThrottleToServiceNonEmptyInitRedirects) {
230 // Navigations |redirects| -> |url| -> |redirect_after_sb_classification|. 236 // Navigations |redirects| -> |url| -> |redirect_after_sb_classification|.
231 // Safe Browsing classifies the |url| as containing deceptive content. 237 // Safe Browsing classifies the |url| as containing deceptive content.
232 // Test checks that |url|, |redirects| and |redirect_after_sb_classification| 238 // Test checks that |url|, |redirects| and |redirect_after_sb_classification|
233 // are in the activation set. 239 // are in the activation set.
234 base::FieldTrialList field_trial_list(nullptr); 240 base::FieldTrialList field_trial_list(nullptr);
235 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 241 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
236 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 242 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
237 kActivationScopeActivationList); 243 kActivationScopeActivationList,
244 kActivationListSocialEngineeringAdsInterstitial);
238 245
239 const GURL url(kExampleURL); 246 const GURL url(kExampleURL);
240 const GURL redirect_after_sb_classification(kTestURL); 247 const GURL redirect_after_sb_classification(kTestURL);
241 const GURL first_redirect(kRedirectURLFirst); 248 const GURL first_redirect(kRedirectURLFirst);
242 const GURL second_redirect(kRedirectURLSecond); 249 const GURL second_redirect(kRedirectURLSecond);
243 const GURL third_redirect(kRedirectURLThird); 250 const GURL third_redirect(kRedirectURLThird);
244 251
245 SetUpNavigationHandleForURL(url); 252 SetUpNavigationHandleForURL(url);
246 SimulateWillStart(); 253 SimulateWillStart();
247 254
248 std::vector<GURL> redirects = {first_redirect, second_redirect, 255 std::vector<GURL> redirects = {first_redirect, second_redirect,
249 third_redirect}; 256 third_redirect};
250 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 257 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
251 url, redirects, safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 258 url, redirects, safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
259 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
252 260
253 SimulateRedirects(redirect_after_sb_classification); 261 SimulateRedirects(redirect_after_sb_classification);
254 262
255 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) 263 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED))
256 .Times(1); 264 .Times(1);
257 SimulateWillProcessResponse(); 265 SimulateWillProcessResponse();
258 ::testing::Mock::VerifyAndClearExpectations(driver()); 266 ::testing::Mock::VerifyAndClearExpectations(driver());
259 267
260 EXPECT_EQ(redirects.size() + 2U, factory()->activation_set().size()); 268 EXPECT_EQ(redirects.size() + 2U, factory()->activation_set().size());
261 EXPECT_TRUE(factory()->ShouldActivateForURL(url)); 269 EXPECT_TRUE(factory()->ShouldActivateForURL(url));
262 EXPECT_TRUE(factory()->ShouldActivateForURL(first_redirect)); 270 EXPECT_TRUE(factory()->ShouldActivateForURL(first_redirect));
263 EXPECT_TRUE(factory()->ShouldActivateForURL(second_redirect)); 271 EXPECT_TRUE(factory()->ShouldActivateForURL(second_redirect));
264 EXPECT_TRUE(factory()->ShouldActivateForURL(third_redirect)); 272 EXPECT_TRUE(factory()->ShouldActivateForURL(third_redirect));
265 EXPECT_TRUE( 273 EXPECT_TRUE(
266 factory()->ShouldActivateForURL(redirect_after_sb_classification)); 274 factory()->ShouldActivateForURL(redirect_after_sb_classification));
267 } 275 }
268 276
269 TEST_F(SubresourceFilterNavigationThrottleTest, 277 TEST_F(SubresourceFilterNavigationThrottleTest,
270 RequestRedirectWithMatchRedirectTest) { 278 RequestRedirectWithMatchRedirectTest) {
271 base::FieldTrialList field_trial_list(nullptr); 279 base::FieldTrialList field_trial_list(nullptr);
272 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 280 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
273 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 281 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
274 kActivationScopeActivationList); 282 kActivationScopeActivationList,
283 kActivationListSocialEngineeringAdsInterstitial);
275 284
276 const GURL init_url(kExampleURL); 285 const GURL init_url(kExampleURL);
277 const GURL redirect_with_match(kRedirectURLFirst); 286 const GURL redirect_with_match(kRedirectURLFirst);
278 const GURL final_url(kRedirectURLSecond); 287 const GURL final_url(kRedirectURLSecond);
279 std::vector<GURL> redirects = {redirect_with_match}; 288 std::vector<GURL> redirects = {redirect_with_match};
280 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 289 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
281 init_url, redirects, 290 init_url, redirects, safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
282 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 291 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
283 292
284 SetUpNavigationHandleForURL(init_url); 293 SetUpNavigationHandleForURL(init_url);
285 SimulateWillStart(); 294 SimulateWillStart();
286 SimulateRedirects(redirect_with_match); 295 SimulateRedirects(redirect_with_match);
287 SimulateRedirects(final_url); 296 SimulateRedirects(final_url);
288 297
289 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED)) 298 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(ActivationState::ENABLED))
290 .Times(1); 299 .Times(1);
291 SimulateWillProcessResponse(); 300 SimulateWillProcessResponse();
292 ::testing::Mock::VerifyAndClearExpectations(driver()); 301 ::testing::Mock::VerifyAndClearExpectations(driver());
293 302
294 EXPECT_EQ(3U, factory()->activation_set().size()); 303 EXPECT_EQ(3U, factory()->activation_set().size());
295 EXPECT_TRUE(factory()->ShouldActivateForURL(init_url)); 304 EXPECT_TRUE(factory()->ShouldActivateForURL(init_url));
296 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect_with_match)); 305 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect_with_match));
297 EXPECT_TRUE(factory()->ShouldActivateForURL(final_url)); 306 EXPECT_TRUE(factory()->ShouldActivateForURL(final_url));
298 } 307 }
299 308
300 } // namespace subresource_filter 309 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698