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

Side by Side Diff: components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.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 "base/macros.h" 5 #include "base/macros.h"
6 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "components/safe_browsing_db/util.h" 8 #include "components/safe_browsing_db/util.h"
9 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver.h" 9 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver.h"
10 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" 10 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
11 #include "components/subresource_filter/core/browser/subresource_filter_client.h " 11 #include "components/subresource_filter/core/browser/subresource_filter_client.h "
12 #include "components/subresource_filter/core/browser/subresource_filter_features .h" 12 #include "components/subresource_filter/core/browser/subresource_filter_features .h"
13 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" 13 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/test_renderer_host.h" 15 #include "content/public/test/test_renderer_host.h"
16 #include "content/public/test/web_contents_tester.h" 16 #include "content/public/test/web_contents_tester.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 20
21 namespace { 21 namespace {
22 22
23 const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc"; 23 const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc";
24 const char kTestUrl[] = "https://test.com"; 24 const char kTestUrl[] = "https://test.com";
25 const char kExampleUrl[] = "https://example.com"; 25 const char kExampleUrl[] = "https://example.com";
26 26
27 struct ActivationListTestData {
28 bool should_add;
29 const char* const activation_list;
30 safe_browsing::SBThreatType threat_type;
31 safe_browsing::ThreatPatternType threat_type_metadata;
32 };
33
34 const ActivationListTestData kActivationListTestData[] = {
35 {false, "", safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
36 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
37 {false, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
38 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
39 safe_browsing::ThreatPatternType::NONE},
40 {false, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
41 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
42 safe_browsing::ThreatPatternType::MALWARE_LANDING},
43 {false, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
44 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
45 safe_browsing::ThreatPatternType::MALWARE_DISTRIBUTION},
46 {true, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
47 safe_browsing::SB_THREAT_TYPE_URL_MALWARE,
48 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
49 {false, subresource_filter::kActivationListPhishingInterstitial,
50 safe_browsing::SB_THREAT_TYPE_API_ABUSE,
51 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
52 {false, subresource_filter::kActivationListPhishingInterstitial,
53 safe_browsing::SB_THREAT_TYPE_BLACKLISTED_RESOURCE,
54 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
55 {false, subresource_filter::kActivationListPhishingInterstitial,
56 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL,
57 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
58 {false, subresource_filter::kActivationListPhishingInterstitial,
59 safe_browsing::SB_THREAT_TYPE_BINARY_MALWARE_URL,
60 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
61 {false, subresource_filter::kActivationListPhishingInterstitial,
62 safe_browsing::SB_THREAT_TYPE_URL_UNWANTED,
63 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
64 {false, subresource_filter::kActivationListPhishingInterstitial,
65 safe_browsing::SB_THREAT_TYPE_URL_MALWARE,
66 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
67 {false, subresource_filter::kActivationListPhishingInterstitial,
68 safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
69 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
70 {false, subresource_filter::kActivationListPhishingInterstitial,
71 safe_browsing::SB_THREAT_TYPE_SAFE,
72 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
73 {true, subresource_filter::kActivationListPhishingInterstitial,
74 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL,
75 safe_browsing::ThreatPatternType::NONE},
76 };
77
27 } // namespace 78 } // namespace
79
28 namespace subresource_filter { 80 namespace subresource_filter {
29 81
30 class MockSubresourceFilterDriver : public ContentSubresourceFilterDriver { 82 class MockSubresourceFilterDriver : public ContentSubresourceFilterDriver {
31 public: 83 public:
32 explicit MockSubresourceFilterDriver( 84 explicit MockSubresourceFilterDriver(
33 content::RenderFrameHost* render_frame_host) 85 content::RenderFrameHost* render_frame_host)
34 : ContentSubresourceFilterDriver(render_frame_host) {} 86 : ContentSubresourceFilterDriver(render_frame_host) {}
35 87
36 ~MockSubresourceFilterDriver() override = default; 88 ~MockSubresourceFilterDriver() override = default;
37 89
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 143
92 MockSubresourceFilterClient* client() { return client_; } 144 MockSubresourceFilterClient* client() { return client_; }
93 MockSubresourceFilterDriver* driver() { return driver_; } 145 MockSubresourceFilterDriver* driver() { return driver_; }
94 146
95 MockSubresourceFilterDriver* subframe_driver() { return subframe_driver_; } 147 MockSubresourceFilterDriver* subframe_driver() { return subframe_driver_; }
96 content::RenderFrameHost* subframe_rfh() { return subframe_rfh_; } 148 content::RenderFrameHost* subframe_rfh() { return subframe_rfh_; }
97 149
98 void BlacklistURLWithRedirects(const GURL& url, 150 void BlacklistURLWithRedirects(const GURL& url,
99 const std::vector<GURL>& redirects) { 151 const std::vector<GURL>& redirects) {
100 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 152 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
101 url, redirects, 153 url, redirects, safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
102 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS); 154 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
103 } 155 }
104 156
105 void ActivateAndExpectForFrameHostForUrl(MockSubresourceFilterDriver* driver, 157 void ActivateAndExpectForFrameHostForUrl(MockSubresourceFilterDriver* driver,
106 content::RenderFrameHost* rfh, 158 content::RenderFrameHost* rfh,
107 const GURL& url, 159 const GURL& url,
108 bool should_activate) { 160 bool should_activate) {
109 EXPECT_CALL(*driver, ActivateForProvisionalLoad(::testing::_)) 161 EXPECT_CALL(*driver, ActivateForProvisionalLoad(::testing::_))
110 .Times(should_activate); 162 .Times(should_activate);
111 factory()->ReadyToCommitMainFrameNavigation(rfh, url); 163 factory()->ReadyToCommitMainFrameNavigation(rfh, url);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 MockSubresourceFilterDriver* driver_; 203 MockSubresourceFilterDriver* driver_;
152 204
153 content::RenderFrameHost* subframe_rfh_; 205 content::RenderFrameHost* subframe_rfh_;
154 MockSubresourceFilterDriver* subframe_driver_; 206 MockSubresourceFilterDriver* subframe_driver_;
155 207
156 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); 208 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest);
157 }; 209 };
158 210
159 class ContentSubresourceFilterDriverFactoryThreatTypeTest 211 class ContentSubresourceFilterDriverFactoryThreatTypeTest
160 : public ContentSubresourceFilterDriverFactoryTest, 212 : public ContentSubresourceFilterDriverFactoryTest,
161 public ::testing::WithParamInterface<safe_browsing::ThreatPatternType> { 213 public ::testing::WithParamInterface<ActivationListTestData> {
162 public: 214 public:
163 ContentSubresourceFilterDriverFactoryThreatTypeTest() {} 215 ContentSubresourceFilterDriverFactoryThreatTypeTest() {}
164 ~ContentSubresourceFilterDriverFactoryThreatTypeTest() override {} 216 ~ContentSubresourceFilterDriverFactoryThreatTypeTest() override {}
165 217
218 void VerifyEntitiesNotInTheBlacklist(
219 const GURL& test_url,
220 const std::vector<GURL>& redirects,
221 const ActivationListTestData& test_data) {
222 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
223 test_url, std::vector<GURL>(), test_data.threat_type,
224 test_data.threat_type_metadata);
225 EXPECT_EQ(test_data.should_add ? 1 : 0U,
226 factory()->activation_set().size());
227 EXPECT_EQ(test_data.should_add,
228 factory()->ShouldActivateForURL(GURL(test_url)));
229 EXPECT_EQ(test_data.should_add, factory()->ShouldActivateForURL(
230 GURL(test_url.GetWithEmptyPath())));
231 EXPECT_EQ(test_data.should_add,
232 factory()->ShouldActivateForURL(
233 GURL("http://" + test_url.host() + "/path?q=q")));
234 factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
235 test_url, redirects, test_data.threat_type,
236 test_data.threat_type_metadata);
237 for (const auto& redirect : redirects) {
238 EXPECT_EQ(test_data.should_add,
239 factory()->ShouldActivateForURL(redirect));
240 EXPECT_EQ(test_data.should_add,
241 factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
242 EXPECT_EQ(test_data.should_add, factory()->ShouldActivateForURL(
243 GURL("http://" + redirect.host())));
244 EXPECT_EQ(test_data.should_add,
245 factory()->ShouldActivateForURL(
246 GURL("http://" + redirect.host() + "/path?q=q")));
247 }
248 }
249
166 private: 250 private:
167 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryThreatTypeTest); 251 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryThreatTypeTest);
168 }; 252 };
169 253
170 TEST_F(ContentSubresourceFilterDriverFactoryTest, SocEngHitEmptyRedirects) { 254 TEST_F(ContentSubresourceFilterDriverFactoryTest, SocEngHitEmptyRedirects) {
255 base::FieldTrialList field_trial_list(nullptr);
256 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
257 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
258 kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
259
171 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>()); 260 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>());
172 EXPECT_EQ(1U, factory()->activation_set().size()); 261 EXPECT_EQ(1U, factory()->activation_set().size());
173 262
174 EXPECT_TRUE(factory()->ShouldActivateForURL(GURL(kExampleUrl))); 263 EXPECT_TRUE(factory()->ShouldActivateForURL(GURL(kExampleUrl)));
175 EXPECT_TRUE(factory()->ShouldActivateForURL(GURL("http://example.com"))); 264 EXPECT_TRUE(factory()->ShouldActivateForURL(GURL("http://example.com")));
176 EXPECT_TRUE( 265 EXPECT_TRUE(
177 factory()->ShouldActivateForURL(GURL("http://example.com/42?q=42!"))); 266 factory()->ShouldActivateForURL(GURL("http://example.com/42?q=42!")));
178 EXPECT_TRUE( 267 EXPECT_TRUE(
179 factory()->ShouldActivateForURL(GURL("https://example.com/42?q=42!"))); 268 factory()->ShouldActivateForURL(GURL("https://example.com/42?q=42!")));
180 EXPECT_TRUE( 269 EXPECT_TRUE(
181 factory()->ShouldActivateForURL(GURL("http://example.com/awesomepath"))); 270 factory()->ShouldActivateForURL(GURL("http://example.com/awesomepath")));
182 const GURL whitelisted("http://example.com/page?q=whitelisted"); 271 const GURL whitelisted("http://example.com/page?q=whitelisted");
183 EXPECT_TRUE(factory()->ShouldActivateForURL(whitelisted)); 272 EXPECT_TRUE(factory()->ShouldActivateForURL(whitelisted));
184 factory()->AddHostOfURLToWhitelistSet(whitelisted); 273 factory()->AddHostOfURLToWhitelistSet(whitelisted);
185 EXPECT_FALSE(factory()->ShouldActivateForURL(whitelisted)); 274 EXPECT_FALSE(factory()->ShouldActivateForURL(whitelisted));
186 } 275 }
187 276
188 TEST_F(ContentSubresourceFilterDriverFactoryTest, SocEngHitWithRedirects) { 277 TEST_F(ContentSubresourceFilterDriverFactoryTest, SocEngHitWithRedirects) {
278 base::FieldTrialList field_trial_list(nullptr);
279 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
280 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
281 kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
282
189 std::vector<GURL> redirects; 283 std::vector<GURL> redirects;
190 redirects.push_back(GURL("https://example1.com")); 284 redirects.push_back(GURL("https://example1.com"));
191 redirects.push_back(GURL("https://example2.com")); 285 redirects.push_back(GURL("https://example2.com"));
192 redirects.push_back(GURL("https://example3.com")); 286 redirects.push_back(GURL("https://example3.com"));
193 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), redirects); 287 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), redirects);
194 EXPECT_EQ(4U, factory()->activation_set().size()); 288 EXPECT_EQ(4U, factory()->activation_set().size());
195 EXPECT_TRUE(factory()->ShouldActivateForURL(GURL(kExampleUrl))); 289 EXPECT_TRUE(factory()->ShouldActivateForURL(GURL(kExampleUrl)));
196 290
197 for (const auto& redirect : redirects) { 291 for (const auto& redirect : redirects) {
198 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect)); 292 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect));
199 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect.GetWithEmptyPath())); 293 EXPECT_TRUE(factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
200 EXPECT_TRUE( 294 EXPECT_TRUE(
201 factory()->ShouldActivateForURL(GURL("http://" + redirect.host()))); 295 factory()->ShouldActivateForURL(GURL("http://" + redirect.host())));
202 EXPECT_TRUE(factory()->ShouldActivateForURL( 296 EXPECT_TRUE(factory()->ShouldActivateForURL(
203 GURL("http://" + redirect.host() + "/path?q=q"))); 297 GURL("http://" + redirect.host() + "/path?q=q")));
204 } 298 }
205 const GURL whitelisted("http://example.com/page?q=42"); 299 const GURL whitelisted("http://example.com/page?q=42");
206 EXPECT_TRUE(factory()->ShouldActivateForURL(whitelisted)); 300 EXPECT_TRUE(factory()->ShouldActivateForURL(whitelisted));
207 factory()->AddHostOfURLToWhitelistSet(whitelisted); 301 factory()->AddHostOfURLToWhitelistSet(whitelisted);
208 EXPECT_FALSE(factory()->ShouldActivateForURL(whitelisted)); 302 EXPECT_FALSE(factory()->ShouldActivateForURL(whitelisted));
209 } 303 }
210 304
211 TEST_F(ContentSubresourceFilterDriverFactoryTest, 305 TEST_F(ContentSubresourceFilterDriverFactoryTest,
212 ActivateForFrameHostNotNeeded) { 306 ActivateForFrameHostNotNeeded) {
213 base::FieldTrialList field_trial_list(nullptr); 307 base::FieldTrialList field_trial_list(nullptr);
214 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 308 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
215 base::FeatureList::OVERRIDE_DISABLE_FEATURE, kActivationStateEnabled, 309 base::FeatureList::OVERRIDE_DISABLE_FEATURE, kActivationStateEnabled,
216 kActivationScopeNoSites); 310 kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
217 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl), 311 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl),
218 false /* should_activate */); 312 false /* should_activate */);
219 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>()); 313 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>());
220 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), 314 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(),
221 GURL("https://not-example.com"), 315 GURL("https://not-example.com"),
222 false /* should_activate */); 316 false /* should_activate */);
223 } 317 }
224 318
225 TEST_F(ContentSubresourceFilterDriverFactoryTest, ActivateForFrameHostNeeded) { 319 TEST_F(ContentSubresourceFilterDriverFactoryTest, ActivateForFrameHostNeeded) {
226 base::FieldTrialList field_trial_list(nullptr); 320 base::FieldTrialList field_trial_list(nullptr);
227 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 321 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
228 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 322 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
229 kActivationScopeActivationList); 323 kActivationScopeActivationList,
324 kActivationListSocialEngineeringAdsInterstitial);
230 325
231 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>()); 326 BlacklistURLWithRedirects(GURL(kExampleUrlWithParams), std::vector<GURL>());
232 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl), 327 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl),
233 false /* should_activate */); 328 false /* should_activate */);
234 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kExampleUrl), 329 ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kExampleUrl),
235 true /* should_activate */); 330 true /* should_activate */);
236 } 331 }
237 332
238 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, NonSocEngHit) { 333 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, NonSocEngHit) {
334 const ActivationListTestData& test_data = GetParam();
335 base::FieldTrialList field_trial_list(nullptr);
336 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
337 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
338 kActivationScopeNoSites, test_data.activation_list);
339
239 std::vector<GURL> redirects; 340 std::vector<GURL> redirects;
240 redirects.push_back(GURL("https://example1.com")); 341 redirects.push_back(GURL("https://example1.com"));
241 redirects.push_back(GURL("https://example2.com")); 342 redirects.push_back(GURL("https://example2.com"));
242 redirects.push_back(GURL("https://example3.com")); 343 redirects.push_back(GURL("https://example3.com"));
243 344
244 const GURL test_url("https://example.com/nonsoceng?q=engsocnon"); 345 const GURL test_url("https://example.com/nonsoceng?q=engsocnon");
245 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( 346 VerifyEntitiesNotInTheBlacklist(test_url, redirects, test_data);
246 GURL(test_url), std::vector<GURL>(), GetParam());
247 EXPECT_EQ(0U, factory()->activation_set().size());
248 EXPECT_FALSE(factory()->ShouldActivateForURL(GURL(test_url)));
249 EXPECT_FALSE(
250 factory()->ShouldActivateForURL(GURL(test_url.GetWithEmptyPath())));
251 EXPECT_FALSE(factory()->ShouldActivateForURL(
252 GURL("http://" + test_url.host() + "/path?q=q")));
253 for (const auto& redirect : redirects) {
254 EXPECT_FALSE(factory()->ShouldActivateForURL(redirect));
255 EXPECT_FALSE(factory()->ShouldActivateForURL(redirect.GetWithEmptyPath()));
256 EXPECT_FALSE(
257 factory()->ShouldActivateForURL(GURL("http://" + redirect.host())));
258 EXPECT_FALSE(factory()->ShouldActivateForURL(
259 GURL("http://" + redirect.host() + "/path?q=q")));
260 }
261 }; 347 };
262 348
263 TEST_F(ContentSubresourceFilterDriverFactoryTest, 349 TEST_F(ContentSubresourceFilterDriverFactoryTest,
264 ActivationPromptNotShownForNonMainFrames) { 350 ActivationPromptNotShownForNonMainFrames) {
265 base::FieldTrialList field_trial_list(nullptr); 351 base::FieldTrialList field_trial_list(nullptr);
266 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 352 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
267 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 353 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
268 kActivationScopeActivationList); 354 kActivationScopeActivationList,
355 kActivationListSocialEngineeringAdsInterstitial);
269 NavigateToUrlAndExpectActivationAndPromptSubFrame(GURL(kExampleUrl), 356 NavigateToUrlAndExpectActivationAndPromptSubFrame(GURL(kExampleUrl),
270 false /* should_prompt */); 357 false /* should_prompt */);
271 } 358 }
272 359
273 TEST_F(ContentSubresourceFilterDriverFactoryTest, 360 TEST_F(ContentSubresourceFilterDriverFactoryTest,
274 DidStartProvisionalLoadScopeAllSitesStateDryRun) { 361 DidStartProvisionalLoadScopeAllSitesStateDryRun) {
275 base::FieldTrialList field_trial_list(nullptr); 362 base::FieldTrialList field_trial_list(nullptr);
276 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 363 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
277 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun, 364 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun,
278 kActivationScopeAllSites); 365 kActivationScopeAllSites,
366 kActivationListSocialEngineeringAdsInterstitial);
279 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams), 367 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams),
280 true /* should_activate */, 368 true /* should_activate */,
281 ActivationState::DRYRUN); 369 ActivationState::DRYRUN);
282 factory()->AddHostOfURLToWhitelistSet(GURL(kExampleUrlWithParams)); 370 factory()->AddHostOfURLToWhitelistSet(GURL(kExampleUrlWithParams));
283 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams), 371 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams),
284 false /* should_activate */, 372 false /* should_activate */,
285 ActivationState::DISABLED); 373 ActivationState::DISABLED);
286 } 374 }
287 375
288 TEST_F(ContentSubresourceFilterDriverFactoryTest, 376 TEST_F(ContentSubresourceFilterDriverFactoryTest,
289 DidStartProvisionalLoadScopeAllSitesStateEnabled) { 377 DidStartProvisionalLoadScopeAllSitesStateEnabled) {
290 base::FieldTrialList field_trial_list(nullptr); 378 base::FieldTrialList field_trial_list(nullptr);
291 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 379 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
292 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled, 380 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
293 kActivationScopeAllSites); 381 kActivationScopeAllSites,
382 kActivationListSocialEngineeringAdsInterstitial);
294 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams), 383 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams),
295 true /* should_activate */, 384 true /* should_activate */,
296 ActivationState::ENABLED); 385 ActivationState::ENABLED);
297 factory()->AddHostOfURLToWhitelistSet(GURL(kExampleUrlWithParams)); 386 factory()->AddHostOfURLToWhitelistSet(GURL(kExampleUrlWithParams));
298 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams), 387 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams),
299 false /* should_activate */, 388 false /* should_activate */,
300 ActivationState::DISABLED); 389 ActivationState::DISABLED);
301 } 390 }
302 391
303 TEST_F(ContentSubresourceFilterDriverFactoryTest, 392 TEST_F(ContentSubresourceFilterDriverFactoryTest,
304 DidStartProvisionalLoadScopeNoSites) { 393 DidStartProvisionalLoadScopeNoSites) {
305 base::FieldTrialList field_trial_list(nullptr); 394 base::FieldTrialList field_trial_list(nullptr);
306 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 395 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
307 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun, 396 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun,
308 kActivationScopeNoSites); 397 kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
309 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams), 398 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams),
310 false /* should_activate */, 399 false /* should_activate */,
311 ActivationState::DISABLED); 400 ActivationState::DISABLED);
312 } 401 }
313 402
314 TEST_F(ContentSubresourceFilterDriverFactoryTest, 403 TEST_F(ContentSubresourceFilterDriverFactoryTest,
315 DidStartProvisionalLoadScopeActivationList) { 404 DidStartProvisionalLoadScopeActivationList) {
316 base::FieldTrialList field_trial_list(nullptr); 405 base::FieldTrialList field_trial_list(nullptr);
317 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 406 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
318 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDisabled, 407 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDisabled,
319 kActivationScopeActivationList); 408 kActivationScopeActivationList,
409 kActivationListSocialEngineeringAdsInterstitial);
320 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams), 410 NavigateToUrlAndExpectActivationAndPrompt(GURL(kExampleUrlWithParams),
321 false /* should_activate */, 411 false /* should_activate */,
322 ActivationState::DISABLED); 412 ActivationState::DISABLED);
323 } 413 }
324 414
325 INSTANTIATE_TEST_CASE_P( 415 INSTANTIATE_TEST_CASE_P(NoSonEngHit,
326 NoSonEngHit, 416 ContentSubresourceFilterDriverFactoryThreatTypeTest,
327 ContentSubresourceFilterDriverFactoryThreatTypeTest, 417 ::testing::ValuesIn(kActivationListTestData));
328 ::testing::Values(
329 safe_browsing::ThreatPatternType::NONE,
330 safe_browsing::ThreatPatternType::MALWARE_LANDING,
331 safe_browsing::ThreatPatternType::MALWARE_DISTRIBUTION,
332 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_LANDING));
333 418
334 } // namespace subresource_filter 419 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698