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/content_subresource_filt
er_driver_factory.h" | 5 #include "components/subresource_filter/content/browser/content_subresource_filt
er_driver_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 struct ActivationListTestData { | 90 struct ActivationListTestData { |
91 ActivationDecision expected_activation_decision; | 91 ActivationDecision expected_activation_decision; |
92 ActivationList activation_list; | 92 ActivationList activation_list; |
93 safe_browsing::SBThreatType threat_type; | 93 safe_browsing::SBThreatType threat_type; |
94 safe_browsing::ThreatPatternType threat_type_metadata; | 94 safe_browsing::ThreatPatternType threat_type_metadata; |
95 }; | 95 }; |
96 | 96 |
97 const ActivationListTestData kActivationListTestData[] = { | 97 const ActivationListTestData kActivationListTestData[] = { |
98 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, ActivationList::NONE, | 98 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, ActivationList::NONE, |
99 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 99 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
100 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 100 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
101 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 101 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
102 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, | 102 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, |
103 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 103 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
104 safe_browsing::ThreatPatternType::NONE}, | 104 safe_browsing::ThreatPatternType::NONE}, |
105 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 105 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
106 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, | 106 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, |
107 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 107 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
108 safe_browsing::ThreatPatternType::MALWARE_LANDING}, | 108 safe_browsing::ThreatPatternType::MALWARE_LANDING}, |
109 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 109 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
110 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, | 110 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, |
111 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 111 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
112 safe_browsing::ThreatPatternType::MALWARE_DISTRIBUTION}, | 112 safe_browsing::ThreatPatternType::MALWARE_DISTRIBUTION}, |
113 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 113 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
114 ActivationList::PHISHING_INTERSTITIAL, | 114 ActivationList::PHISHING_INTERSTITIAL, |
115 safe_browsing::SB_THREAT_TYPE_API_ABUSE, | 115 safe_browsing::SB_THREAT_TYPE_API_ABUSE, |
116 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 116 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
117 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 117 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
118 ActivationList::PHISHING_INTERSTITIAL, | 118 ActivationList::PHISHING_INTERSTITIAL, |
119 safe_browsing::SB_THREAT_TYPE_BLACKLISTED_RESOURCE, | 119 safe_browsing::SB_THREAT_TYPE_BLACKLISTED_RESOURCE, |
120 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 120 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
121 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 121 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
122 ActivationList::PHISHING_INTERSTITIAL, | 122 ActivationList::PHISHING_INTERSTITIAL, |
123 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, | 123 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL, |
124 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 124 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
125 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 125 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
126 ActivationList::PHISHING_INTERSTITIAL, | 126 ActivationList::PHISHING_INTERSTITIAL, |
127 safe_browsing::SB_THREAT_TYPE_BINARY_MALWARE_URL, | 127 safe_browsing::SB_THREAT_TYPE_BINARY_MALWARE_URL, |
128 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 128 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
129 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 129 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
130 ActivationList::PHISHING_INTERSTITIAL, | 130 ActivationList::PHISHING_INTERSTITIAL, |
131 safe_browsing::SB_THREAT_TYPE_URL_UNWANTED, | 131 safe_browsing::SB_THREAT_TYPE_URL_UNWANTED, |
132 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 132 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
133 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 133 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
134 ActivationList::PHISHING_INTERSTITIAL, | 134 ActivationList::PHISHING_INTERSTITIAL, |
135 safe_browsing::SB_THREAT_TYPE_URL_MALWARE, | 135 safe_browsing::SB_THREAT_TYPE_URL_MALWARE, |
136 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 136 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
137 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 137 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
138 ActivationList::PHISHING_INTERSTITIAL, | 138 ActivationList::PHISHING_INTERSTITIAL, |
139 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, | 139 safe_browsing::SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL, |
140 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 140 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
141 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 141 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
142 ActivationList::PHISHING_INTERSTITIAL, safe_browsing::SB_THREAT_TYPE_SAFE, | 142 ActivationList::PHISHING_INTERSTITIAL, safe_browsing::SB_THREAT_TYPE_SAFE, |
143 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 143 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
144 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, | 144 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, |
145 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 145 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
146 safe_browsing::ThreatPatternType::NONE}, | 146 safe_browsing::ThreatPatternType::NONE}, |
147 {ActivationDecision::ACTIVATED, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, | 147 {ActivationDecision::ACTIVATED, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, |
148 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 148 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
149 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 149 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
150 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, | 150 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, |
151 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 151 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
152 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 152 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
153 }; | 153 }; |
154 | 154 |
155 struct ActivationScopeTestData { | 155 struct ActivationScopeTestData { |
156 ActivationDecision expected_activation_decision; | 156 ActivationDecision expected_activation_decision; |
157 bool url_matches_activation_list; | 157 bool url_matches_activation_list; |
158 ActivationScope activation_scope; | 158 ActivationScope activation_scope; |
159 }; | 159 }; |
160 | 160 |
161 const ActivationScopeTestData kActivationScopeTestData[] = { | 161 const ActivationScopeTestData kActivationScopeTestData[] = { |
162 {ActivationDecision::ACTIVATED, false /* url_matches_activation_list */, | 162 {ActivationDecision::ACTIVATED, false /* url_matches_activation_list */, |
163 ActivationScope::ALL_SITES}, | 163 ActivationScope::ALL_SITES}, |
164 {ActivationDecision::ACTIVATED, true /* url_matches_activation_list */, | 164 {ActivationDecision::ACTIVATED, true /* url_matches_activation_list */, |
165 ActivationScope::ALL_SITES}, | 165 ActivationScope::ALL_SITES}, |
166 {ActivationDecision::ACTIVATION_DISABLED, | 166 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
167 true /* url_matches_activation_list */, ActivationScope::NO_SITES}, | 167 true /* url_matches_activation_list */, ActivationScope::NO_SITES}, |
168 {ActivationDecision::ACTIVATED, true /* url_matches_activation_list */, | 168 {ActivationDecision::ACTIVATED, true /* url_matches_activation_list */, |
169 ActivationScope::ACTIVATION_LIST}, | 169 ActivationScope::ACTIVATION_LIST}, |
170 {ActivationDecision::ACTIVATION_LIST_NOT_MATCHED, | 170 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
171 false /* url_matches_activation_list */, ActivationScope::ACTIVATION_LIST}, | 171 false /* url_matches_activation_list */, ActivationScope::ACTIVATION_LIST}, |
172 }; | 172 }; |
173 | 173 |
174 struct ActivationLevelTestData { | 174 struct ActivationLevelTestData { |
175 ActivationDecision expected_activation_decision; | 175 ActivationDecision expected_activation_decision; |
176 ActivationLevel activation_level; | 176 ActivationLevel activation_level; |
177 }; | 177 }; |
178 | 178 |
179 const ActivationLevelTestData kActivationLevelTestData[] = { | 179 const ActivationLevelTestData kActivationLevelTestData[] = { |
180 {ActivationDecision::ACTIVATED, ActivationLevel::DRYRUN}, | 180 {ActivationDecision::ACTIVATED, ActivationLevel::DRYRUN}, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 ASSERT_NO_FATAL_FAILURE(test_ruleset_creator_.CreateRulesetWithRules( | 233 ASSERT_NO_FATAL_FAILURE(test_ruleset_creator_.CreateRulesetWithRules( |
234 rules, &test_ruleset_pair_)); | 234 rules, &test_ruleset_pair_)); |
235 ruleset_dealer_ = base::MakeUnique<VerifiedRulesetDealer::Handle>( | 235 ruleset_dealer_ = base::MakeUnique<VerifiedRulesetDealer::Handle>( |
236 base::MessageLoop::current()->task_runner()); | 236 base::MessageLoop::current()->task_runner()); |
237 ruleset_dealer_->SetRulesetFile( | 237 ruleset_dealer_->SetRulesetFile( |
238 testing::TestRuleset::Open(test_ruleset_pair_.indexed)); | 238 testing::TestRuleset::Open(test_ruleset_pair_.indexed)); |
239 client_ = | 239 client_ = |
240 base::MakeUnique<MockSubresourceFilterClient>(ruleset_dealer_.get()); | 240 base::MakeUnique<MockSubresourceFilterClient>(ruleset_dealer_.get()); |
241 ContentSubresourceFilterDriverFactory::CreateForWebContents( | 241 ContentSubresourceFilterDriverFactory::CreateForWebContents( |
242 RenderViewHostTestHarness::web_contents(), client()); | 242 RenderViewHostTestHarness::web_contents(), client()); |
243 ResetConfigurationToEnableFilteringOnSocialEngineeringSites(); | 243 ResetConfigurationToEnableFilteringOnPhishingSites(); |
244 | 244 |
245 // Add a subframe. | 245 // Add a subframe. |
246 content::RenderFrameHostTester* rfh_tester = | 246 content::RenderFrameHostTester* rfh_tester = |
247 content::RenderFrameHostTester::For(main_rfh()); | 247 content::RenderFrameHostTester::For(main_rfh()); |
248 rfh_tester->InitializeRenderFrameIfNeeded(); | 248 rfh_tester->InitializeRenderFrameIfNeeded(); |
249 rfh_tester->AppendChild(kSubframeName); | 249 rfh_tester->AppendChild(kSubframeName); |
250 | 250 |
251 Observe(content::RenderViewHostTestHarness::web_contents()); | 251 Observe(content::RenderViewHostTestHarness::web_contents()); |
252 } | 252 } |
253 | 253 |
254 void TearDown() override { | 254 void TearDown() override { |
255 ruleset_dealer_.reset(); | 255 ruleset_dealer_.reset(); |
256 base::RunLoop().RunUntilIdle(); | 256 base::RunLoop().RunUntilIdle(); |
257 RenderViewHostTestHarness::TearDown(); | 257 RenderViewHostTestHarness::TearDown(); |
258 } | 258 } |
259 | 259 |
260 void ResetConfiguration(Configuration config) { | 260 void ResetConfiguration(Configuration config) { |
261 scoped_configuration_.ResetConfiguration(std::move(config)); | 261 scoped_configuration_.ResetConfiguration(std::move(config)); |
262 } | 262 } |
263 | 263 |
| 264 void ResetConfiguration(std::vector<Configuration> configs) { |
| 265 scoped_configuration_.ResetConfiguration(std::move(configs)); |
| 266 } |
| 267 |
264 void ResetConfigurationToEnableFilteringOnAllSites() { | 268 void ResetConfigurationToEnableFilteringOnAllSites() { |
265 ResetConfiguration( | 269 ResetConfiguration( |
266 Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES)); | 270 Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES)); |
267 } | 271 } |
268 | 272 |
269 void ResetConfigurationToEnableFilteringOnSocialEngineeringSites() { | 273 void ResetConfigurationToEnableFilteringOnPhishingSites() { |
270 ResetConfiguration(Configuration( | 274 ResetConfiguration(Configuration::MakePresetForLiveRunOnPhishingSites()); |
271 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, | |
272 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | |
273 } | 275 } |
274 | 276 |
275 ContentSubresourceFilterDriverFactory* factory() { | 277 ContentSubresourceFilterDriverFactory* factory() { |
276 return ContentSubresourceFilterDriverFactory::FromWebContents( | 278 return ContentSubresourceFilterDriverFactory::FromWebContents( |
277 RenderViewHostTestHarness::web_contents()); | 279 RenderViewHostTestHarness::web_contents()); |
278 } | 280 } |
279 | 281 |
280 MockSubresourceFilterClient* client() { return client_.get(); } | 282 MockSubresourceFilterClient* client() { return client_.get(); } |
281 | 283 |
282 content::RenderFrameHost* GetSubframeRFH() { | 284 content::RenderFrameHost* GetSubframeRFH() { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return; | 476 return; |
475 | 477 |
476 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; | 478 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
477 factory()->throttle_manager()->MaybeAppendNavigationThrottles( | 479 factory()->throttle_manager()->MaybeAppendNavigationThrottles( |
478 navigation_handle, &throttles); | 480 navigation_handle, &throttles); |
479 for (auto& it : throttles) | 481 for (auto& it : throttles) |
480 navigation_handle->RegisterThrottleForTesting(std::move(it)); | 482 navigation_handle->RegisterThrottleForTesting(std::move(it)); |
481 } | 483 } |
482 | 484 |
483 private: | 485 private: |
484 static bool expected_measure_performance() { | |
485 const double rate = GetActiveConfigurations() | |
486 ->the_one_and_only() | |
487 .performance_measurement_rate; | |
488 // Note: The case when 0 < rate < 1 is not deterministic, don't test it. | |
489 EXPECT_TRUE(rate == 0 || rate == 1); | |
490 return rate == 1; | |
491 } | |
492 | |
493 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; | 486 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; |
494 testing::TestRulesetCreator test_ruleset_creator_; | 487 testing::TestRulesetCreator test_ruleset_creator_; |
495 testing::TestRulesetPair test_ruleset_pair_; | 488 testing::TestRulesetPair test_ruleset_pair_; |
496 | 489 |
497 std::unique_ptr<MockSubresourceFilterClient> client_; | 490 std::unique_ptr<MockSubresourceFilterClient> client_; |
498 std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_; | 491 std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_; |
499 | 492 |
500 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); | 493 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); |
501 }; | 494 }; |
502 | 495 |
(...skipping 30 matching lines...) Expand all Loading... |
533 private: | 526 private: |
534 DISALLOW_COPY_AND_ASSIGN( | 527 DISALLOW_COPY_AND_ASSIGN( |
535 ContentSubresourceFilterDriverFactoryActivationLevelTest); | 528 ContentSubresourceFilterDriverFactoryActivationLevelTest); |
536 }; | 529 }; |
537 | 530 |
538 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 531 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
539 NoActivationWhenActivationLevelIsDisabled) { | 532 NoActivationWhenActivationLevelIsDisabled) { |
540 Configuration config(ActivationLevel::DISABLED, | 533 Configuration config(ActivationLevel::DISABLED, |
541 ActivationScope::ACTIVATION_LIST, | 534 ActivationScope::ACTIVATION_LIST, |
542 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 535 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
543 config.activation_level = ActivationLevel::DISABLED; | 536 config.activation_options.activation_level = ActivationLevel::DISABLED; |
544 ResetConfiguration(std::move(config)); | 537 ResetConfiguration(std::move(config)); |
545 | 538 |
| 539 NavigateAndExpectActivation( |
| 540 {false}, {GURL(kExampleLoginUrl)}, EMPTY, |
| 541 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 542 |
546 const GURL url(kExampleUrlWithParams); | 543 const GURL url(kExampleUrlWithParams); |
547 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 544 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
548 ActivationDecision::ACTIVATION_DISABLED); | 545 ActivationDecision::ACTIVATION_DISABLED); |
| 546 |
549 factory()->client()->WhitelistInCurrentWebContents(url); | 547 factory()->client()->WhitelistInCurrentWebContents(url); |
550 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 548 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
551 ActivationDecision::ACTIVATION_DISABLED); | 549 ActivationDecision::URL_WHITELISTED); |
552 } | 550 } |
553 | 551 |
554 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { | 552 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { |
555 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 553 NavigateAndExpectActivation( |
556 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 554 {false}, {GURL(kExampleUrl)}, EMPTY, |
| 555 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
557 } | 556 } |
558 | 557 |
559 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 558 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
560 SpecialCaseNavigationAllSitesEnabled) { | 559 SpecialCaseNavigationAllSitesEnabled) { |
561 // Check that when the experiment is enabled for all site, the activation | 560 // Check that when the experiment is enabled for all site, the activation |
562 // signal is always sent. | 561 // signal is always sent. |
563 ResetConfigurationToEnableFilteringOnAllSites(); | 562 ResetConfigurationToEnableFilteringOnAllSites(); |
564 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); | 563 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); |
565 } | 564 } |
566 | 565 |
567 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 566 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
568 SpecialCaseNavigationActivationListEnabled) { | 567 SpecialCaseNavigationActivationListEnabled) { |
569 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 568 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
570 ActivationDecision::ACTIVATED); | 569 ActivationDecision::ACTIVATED); |
571 } | 570 } |
572 | 571 |
573 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 572 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
574 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { | 573 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { |
575 Configuration config(ActivationLevel::ENABLED, | 574 Configuration config(ActivationLevel::ENABLED, |
576 ActivationScope::ACTIVATION_LIST, | 575 ActivationScope::ACTIVATION_LIST, |
577 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 576 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
578 config.performance_measurement_rate = 1.0; | 577 config.activation_options.performance_measurement_rate = 1.0; |
579 ResetConfiguration(std::move(config)); | 578 ResetConfiguration(std::move(config)); |
580 | 579 |
581 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 580 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
582 ActivationDecision::ACTIVATED); | 581 ActivationDecision::ACTIVATED); |
583 } | 582 } |
584 | 583 |
585 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { | 584 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { |
586 const GURL url(kExampleUrl); | 585 const GURL url(kExampleUrl); |
587 ResetConfigurationToEnableFilteringOnAllSites(); | 586 ResetConfigurationToEnableFilteringOnAllSites(); |
588 NavigateAndExpectActivation({false}, {url}, EMPTY, | 587 NavigateAndExpectActivation({false}, {url}, EMPTY, |
589 ActivationDecision::ACTIVATED); | 588 ActivationDecision::ACTIVATED); |
590 EmulateFailedNavigationAndExpectNoActivation(url); | 589 EmulateFailedNavigationAndExpectNoActivation(url); |
591 } | 590 } |
592 | 591 |
593 // TODO(melandory): refactor the test so it no longer require the current | 592 // TODO(melandory): refactor the test so it no longer require the current |
594 // activation list to be matching. | 593 // activation list to be matching. |
595 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { | 594 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { |
596 struct RedirectRedirectChainMatchPatternTestData { | 595 struct RedirectRedirectChainMatchPatternTestData { |
597 std::vector<bool> blacklisted_urls; | 596 std::vector<bool> blacklisted_urls; |
598 std::vector<GURL> navigation_chain; | 597 std::vector<GURL> navigation_chain; |
599 RedirectChainMatchPattern hit_expected_pattern; | 598 RedirectChainMatchPattern hit_expected_pattern; |
600 ActivationDecision expected_activation_decision; | 599 ActivationDecision expected_activation_decision; |
601 } kRedirectRedirectChainMatchPatternTestData[] = { | 600 } kRedirectRedirectChainMatchPatternTestData[] = { |
602 {{false}, | 601 {{false}, |
603 {GURL(kUrlA)}, | 602 {GURL(kUrlA)}, |
604 EMPTY, | 603 EMPTY, |
605 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 604 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
606 {{true}, {GURL(kUrlA)}, NO_REDIRECTS_HIT, ActivationDecision::ACTIVATED}, | 605 {{true}, {GURL(kUrlA)}, NO_REDIRECTS_HIT, ActivationDecision::ACTIVATED}, |
607 {{false, false}, | 606 {{false, false}, |
608 {GURL(kUrlA), GURL(kUrlB)}, | 607 {GURL(kUrlA), GURL(kUrlB)}, |
609 EMPTY, | 608 EMPTY, |
610 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 609 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
611 {{false, true}, | 610 {{false, true}, |
612 {GURL(kUrlA), GURL(kUrlB)}, | 611 {GURL(kUrlA), GURL(kUrlB)}, |
613 F0M0L1, | 612 F0M0L1, |
614 ActivationDecision::ACTIVATED}, | 613 ActivationDecision::ACTIVATED}, |
615 {{true, false}, | 614 {{true, false}, |
616 {GURL(kUrlA), GURL(kUrlB)}, | 615 {GURL(kUrlA), GURL(kUrlB)}, |
617 F1M0L0, | 616 F1M0L0, |
618 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 617 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
619 {{true, true}, | 618 {{true, true}, |
620 {GURL(kUrlA), GURL(kUrlB)}, | 619 {GURL(kUrlA), GURL(kUrlB)}, |
621 F1M0L1, | 620 F1M0L1, |
622 ActivationDecision::ACTIVATED}, | 621 ActivationDecision::ACTIVATED}, |
623 {{false, false, false}, | 622 {{false, false, false}, |
624 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 623 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
625 EMPTY, | 624 EMPTY, |
626 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 625 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
627 {{false, false, true}, | 626 {{false, false, true}, |
628 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 627 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
629 F0M0L1, | 628 F0M0L1, |
630 ActivationDecision::ACTIVATED}, | 629 ActivationDecision::ACTIVATED}, |
631 {{false, true, false}, | 630 {{false, true, false}, |
632 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 631 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
633 F0M1L0, | 632 F0M1L0, |
634 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 633 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
635 {{false, true, true}, | 634 {{false, true, true}, |
636 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 635 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
637 F0M1L1, | 636 F0M1L1, |
638 ActivationDecision::ACTIVATED}, | 637 ActivationDecision::ACTIVATED}, |
639 {{true, false, false}, | 638 {{true, false, false}, |
640 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 639 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
641 F1M0L0, | 640 F1M0L0, |
642 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 641 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
643 {{true, false, true}, | 642 {{true, false, true}, |
644 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 643 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
645 F1M0L1, | 644 F1M0L1, |
646 ActivationDecision::ACTIVATED}, | 645 ActivationDecision::ACTIVATED}, |
647 {{true, true, false}, | 646 {{true, true, false}, |
648 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 647 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
649 F1M1L0, | 648 F1M1L0, |
650 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 649 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
651 {{true, true, true}, | 650 {{true, true, true}, |
652 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 651 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
653 F1M1L1, | 652 F1M1L1, |
654 ActivationDecision::ACTIVATED}, | 653 ActivationDecision::ACTIVATED}, |
655 {{false, true, false, false}, | 654 {{false, true, false, false}, |
656 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)}, | 655 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)}, |
657 F0M1L0, | 656 F0M1L0, |
658 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 657 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
659 }; | 658 }; |
660 | 659 |
661 for (size_t i = 0U; i < arraysize(kRedirectRedirectChainMatchPatternTestData); | 660 for (size_t i = 0U; i < arraysize(kRedirectRedirectChainMatchPatternTestData); |
662 ++i) { | 661 ++i) { |
663 auto test_data = kRedirectRedirectChainMatchPatternTestData[i]; | 662 auto test_data = kRedirectRedirectChainMatchPatternTestData[i]; |
664 NavigateAndExpectActivation( | 663 NavigateAndExpectActivation( |
665 test_data.blacklisted_urls, test_data.navigation_chain, | 664 test_data.blacklisted_urls, test_data.navigation_chain, |
666 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 665 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
667 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 666 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
668 content::Referrer(), ui::PAGE_TRANSITION_LINK, | 667 content::Referrer(), ui::PAGE_TRANSITION_LINK, |
669 test_data.hit_expected_pattern, test_data.expected_activation_decision); | 668 test_data.hit_expected_pattern, test_data.expected_activation_decision); |
670 NavigateAndExpectActivation( | 669 NavigateAndExpectActivation( |
671 {false}, {GURL("https://dummy.com")}, EMPTY, | 670 {false}, {GURL("https://dummy.com")}, EMPTY, |
672 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 671 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
673 #if defined(GOOGLE_CHROME_BUILD) | 672 #if defined(GOOGLE_CHROME_BUILD) |
674 NavigateAndExpectActivation( | 673 NavigateAndExpectActivation( |
675 test_data.blacklisted_urls, test_data.navigation_chain, | 674 test_data.blacklisted_urls, test_data.navigation_chain, |
676 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, | 675 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
677 safe_browsing::ThreatPatternType::NONE, content::Referrer(), | 676 safe_browsing::ThreatPatternType::NONE, content::Referrer(), |
678 ui::PAGE_TRANSITION_LINK, test_data.hit_expected_pattern, | 677 ui::PAGE_TRANSITION_LINK, test_data.hit_expected_pattern, |
679 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 678 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
680 #endif | 679 #endif |
681 } | 680 } |
682 } | 681 } |
683 | 682 |
684 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { | 683 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { |
685 ResetConfigurationToEnableFilteringOnAllSites(); | 684 ResetConfigurationToEnableFilteringOnAllSites(); |
686 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 685 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
687 ActivationDecision::ACTIVATED); | 686 ActivationDecision::ACTIVATED); |
688 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); | 687 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); |
689 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 688 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
690 true /* expect_cancelled */); | 689 true /* expect_cancelled */); |
691 } | 690 } |
692 | 691 |
693 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 692 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
694 SuppressNotificationVisibility) { | 693 SuppressNotificationVisibility) { |
695 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | 694 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
696 config.should_suppress_notifications = true; | 695 config.activation_options.should_suppress_notifications = true; |
697 ResetConfiguration(std::move(config)); | 696 ResetConfiguration(std::move(config)); |
698 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 697 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
699 ActivationDecision::ACTIVATED); | 698 ActivationDecision::ACTIVATED); |
700 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); | 699 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
701 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 700 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
702 true /* expect_cancelled */); | 701 true /* expect_cancelled */); |
703 } | 702 } |
704 | 703 |
705 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 704 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
706 InactiveMainFrame_SubframeNotFiltered) { | 705 InactiveMainFrame_SubframeNotFiltered) { |
(...skipping 13 matching lines...) Expand all Loading... |
720 } kTestCases[] = { | 719 } kTestCases[] = { |
721 {content::Referrer(), ui::PAGE_TRANSITION_LINK, | 720 {content::Referrer(), ui::PAGE_TRANSITION_LINK, |
722 ActivationDecision::ACTIVATED}, | 721 ActivationDecision::ACTIVATED}, |
723 {content::Referrer(GURL(kUrlA), blink::kWebReferrerPolicyDefault), | 722 {content::Referrer(GURL(kUrlA), blink::kWebReferrerPolicyDefault), |
724 ui::PAGE_TRANSITION_LINK, ActivationDecision::ACTIVATED}, | 723 ui::PAGE_TRANSITION_LINK, ActivationDecision::ACTIVATED}, |
725 {content::Referrer(GURL(kExampleUrl), blink::kWebReferrerPolicyDefault), | 724 {content::Referrer(GURL(kExampleUrl), blink::kWebReferrerPolicyDefault), |
726 ui::PAGE_TRANSITION_LINK, ActivationDecision::URL_WHITELISTED}, | 725 ui::PAGE_TRANSITION_LINK, ActivationDecision::URL_WHITELISTED}, |
727 {content::Referrer(), ui::PAGE_TRANSITION_RELOAD, | 726 {content::Referrer(), ui::PAGE_TRANSITION_RELOAD, |
728 ActivationDecision::URL_WHITELISTED}}; | 727 ActivationDecision::URL_WHITELISTED}}; |
729 | 728 |
| 729 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 730 config.activation_options.should_whitelist_site_on_reload = true; |
| 731 ResetConfiguration(std::move(config)); |
| 732 |
730 for (const auto& test_case : kTestCases) { | 733 for (const auto& test_case : kTestCases) { |
731 SCOPED_TRACE(::testing::Message("referrer = \"") | 734 SCOPED_TRACE(::testing::Message("referrer = \"") |
732 << test_case.referrer.url << "\"" | 735 << test_case.referrer.url << "\"" |
733 << " transition = \"" << test_case.transition << "\""); | 736 << " transition = \"" << test_case.transition << "\""); |
734 | 737 |
735 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | |
736 config.should_whitelist_site_on_reload = true; | |
737 ResetConfiguration(std::move(config)); | |
738 | |
739 NavigateAndExpectActivation( | 738 NavigateAndExpectActivation( |
740 {false}, {GURL(kExampleUrl)}, | 739 {false}, {GURL(kExampleUrl)}, |
741 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 740 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
742 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 741 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
743 test_case.referrer, test_case.transition, EMPTY, | 742 test_case.referrer, test_case.transition, EMPTY, |
744 test_case.expected_activation_decision); | 743 test_case.expected_activation_decision); |
745 // Verify that if the first URL failed to activate, subsequent same-origin | 744 // Verify that if the first URL failed to activate, subsequent same-origin |
746 // navigations also fail to activate. | 745 // navigations also fail to activate. |
747 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, | 746 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, |
748 test_case.expected_activation_decision); | 747 test_case.expected_activation_decision); |
749 } | 748 } |
750 } | 749 } |
751 | 750 |
| 751 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoConfigs) { |
| 752 ResetConfiguration(std::vector<Configuration>()); |
| 753 NavigateAndExpectActivation( |
| 754 {true}, {GURL(kExampleUrl)}, NO_REDIRECTS_HIT, |
| 755 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 756 } |
| 757 |
| 758 TEST_F(ContentSubresourceFilterDriverFactoryTest, MultipleSimultaneousConfigs) { |
| 759 Configuration config1(ActivationLevel::DRYRUN, ActivationScope::NO_SITES); |
| 760 config1.activation_conditions.priority = 2; |
| 761 |
| 762 Configuration config2(ActivationLevel::DISABLED, |
| 763 ActivationScope::ACTIVATION_LIST, |
| 764 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 765 config2.activation_conditions.priority = 1; |
| 766 |
| 767 Configuration config3(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 768 config3.activation_options.should_whitelist_site_on_reload = true; |
| 769 config3.activation_conditions.priority = 0; |
| 770 |
| 771 ResetConfiguration({config1, config2, config3}); |
| 772 |
| 773 // Should match |config2| and |config3|, the former with the higher priority. |
| 774 NavigateAndExpectActivation({true}, {GURL(kExampleUrl)}, NO_REDIRECTS_HIT, |
| 775 ActivationDecision::ACTIVATION_DISABLED); |
| 776 |
| 777 // Should match |config3|. |
| 778 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 779 ActivationDecision::ACTIVATED); |
| 780 |
| 781 // Should match |config3|, but a reload, so this should get whitelisted. |
| 782 NavigateAndExpectActivation( |
| 783 {false}, {GURL(kExampleUrl)}, safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 784 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 785 content::Referrer(), ui::PAGE_TRANSITION_RELOAD, EMPTY, |
| 786 ActivationDecision::URL_WHITELISTED); |
| 787 } |
| 788 |
752 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, | 789 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, |
753 ActivateForFrameState) { | 790 ActivateForFrameState) { |
754 const ActivationLevelTestData& test_data = GetParam(); | 791 const ActivationLevelTestData& test_data = GetParam(); |
755 ResetConfiguration(Configuration( | 792 ResetConfiguration(Configuration( |
756 test_data.activation_level, ActivationScope::ACTIVATION_LIST, | 793 test_data.activation_level, ActivationScope::ACTIVATION_LIST, |
757 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 794 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
758 | 795 |
759 const GURL url(kExampleUrlWithParams); | 796 const GURL url(kExampleUrlWithParams); |
760 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 797 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
761 test_data.expected_activation_decision); | 798 test_data.expected_activation_decision); |
762 factory()->client()->WhitelistInCurrentWebContents(url); | 799 factory()->client()->WhitelistInCurrentWebContents(url); |
763 NavigateAndExpectActivation( | 800 NavigateAndExpectActivation({true}, {GURL(kExampleUrlWithParams)}, |
764 {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, | 801 NO_REDIRECTS_HIT, |
765 GetActiveConfigurations()->the_one_and_only().activation_level == | 802 ActivationDecision::URL_WHITELISTED); |
766 ActivationLevel::DISABLED | |
767 ? ActivationDecision::ACTIVATION_DISABLED | |
768 : ActivationDecision::URL_WHITELISTED); | |
769 } | 803 } |
770 | 804 |
771 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, | 805 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, |
772 ActivateForTheListType) { | 806 ActivateForTheListType) { |
773 // Sets up the experiment in a way that the activation decision depends on the | 807 // Sets up the experiment in a way that the activation decision depends on the |
774 // list for which the Safe Browsing hit has happened. | 808 // list for which the Safe Browsing hit has happened. |
775 const ActivationListTestData& test_data = GetParam(); | 809 const ActivationListTestData& test_data = GetParam(); |
776 ResetConfiguration(Configuration(ActivationLevel::ENABLED, | 810 ResetConfiguration(Configuration(ActivationLevel::ENABLED, |
777 ActivationScope::ACTIVATION_LIST, | 811 ActivationScope::ACTIVATION_LIST, |
778 test_data.activation_list)); | 812 test_data.activation_list)); |
(...skipping 21 matching lines...) Expand all Loading... |
800 | 834 |
801 const GURL test_url(kExampleUrlWithParams); | 835 const GURL test_url(kExampleUrlWithParams); |
802 | 836 |
803 RedirectChainMatchPattern expected_pattern = | 837 RedirectChainMatchPattern expected_pattern = |
804 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 838 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
805 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 839 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
806 {test_url}, expected_pattern, | 840 {test_url}, expected_pattern, |
807 test_data.expected_activation_decision); | 841 test_data.expected_activation_decision); |
808 if (test_data.url_matches_activation_list) { | 842 if (test_data.url_matches_activation_list) { |
809 factory()->client()->WhitelistInCurrentWebContents(test_url); | 843 factory()->client()->WhitelistInCurrentWebContents(test_url); |
810 NavigateAndExpectActivation( | 844 ActivationDecision expected_decision = |
811 {test_data.url_matches_activation_list}, {GURL(kExampleUrlWithParams)}, | 845 test_data.expected_activation_decision; |
812 expected_pattern, | 846 if (expected_decision == ActivationDecision::ACTIVATED) |
813 GetActiveConfigurations()->the_one_and_only().activation_scope == | 847 expected_decision = ActivationDecision::URL_WHITELISTED; |
814 ActivationScope::NO_SITES | 848 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
815 ? ActivationDecision::ACTIVATION_DISABLED | 849 {GURL(kExampleUrlWithParams)}, expected_pattern, |
816 : ActivationDecision::URL_WHITELISTED); | 850 expected_decision); |
817 } | 851 } |
818 }; | 852 }; |
819 | 853 |
820 // Only main frames with http/https schemes should activate, unless the | 854 // Only main frames with http/https schemes should activate. |
821 // activation scope is for all sites. | |
822 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 855 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
823 ActivateForSupportedUrlScheme) { | 856 ActivateForSupportedUrlScheme) { |
824 const ActivationScopeTestData& test_data = GetParam(); | 857 const ActivationScopeTestData& test_data = GetParam(); |
825 ResetConfiguration( | 858 ResetConfiguration( |
826 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, | 859 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, |
827 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 860 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
828 | 861 |
829 // data URLs are also not supported, but not listed here, as it's not possible | 862 // data URLs are also not supported, but not listed here, as it's not possible |
830 // for a page to redirect to them after https://crbug.com/594215 is fixed. | 863 // for a page to redirect to them after https://crbug.com/594215 is fixed. |
831 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", | 864 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", |
832 "chrome-extension://some-extension", | 865 "chrome-extension://some-extension", |
833 "file:///var/www/index.html"}; | 866 "file:///var/www/index.html"}; |
834 const char* supported_urls[] = {"http://example.test", | 867 const char* supported_urls[] = {"http://example.test", |
835 "https://example.test"}; | 868 "https://example.test"}; |
836 for (auto* url : unsupported_urls) { | 869 for (auto* url : unsupported_urls) { |
837 SCOPED_TRACE(url); | 870 SCOPED_TRACE(url); |
838 RedirectChainMatchPattern expected_pattern = EMPTY; | 871 RedirectChainMatchPattern expected_pattern = EMPTY; |
839 NavigateAndExpectActivation( | 872 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
840 {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, | 873 {GURL(url)}, expected_pattern, |
841 GetActiveConfigurations()->the_one_and_only().activation_scope == | 874 ActivationDecision::UNSUPPORTED_SCHEME); |
842 ActivationScope::NO_SITES | |
843 ? ActivationDecision::ACTIVATION_DISABLED | |
844 : ActivationDecision::UNSUPPORTED_SCHEME); | |
845 } | 875 } |
846 for (auto* url : supported_urls) { | 876 for (auto* url : supported_urls) { |
847 SCOPED_TRACE(url); | 877 SCOPED_TRACE(url); |
848 RedirectChainMatchPattern expected_pattern = | 878 RedirectChainMatchPattern expected_pattern = |
849 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 879 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
850 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 880 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
851 {GURL(url)}, expected_pattern, | 881 {GURL(url)}, expected_pattern, |
852 test_data.expected_activation_decision); | 882 test_data.expected_activation_decision); |
853 } | 883 } |
854 }; | 884 }; |
855 | 885 |
856 INSTANTIATE_TEST_CASE_P(NoSocEngHit, | 886 INSTANTIATE_TEST_CASE_P(NoSocEngHit, |
857 ContentSubresourceFilterDriverFactoryThreatTypeTest, | 887 ContentSubresourceFilterDriverFactoryThreatTypeTest, |
858 ::testing::ValuesIn(kActivationListTestData)); | 888 ::testing::ValuesIn(kActivationListTestData)); |
859 | 889 |
860 INSTANTIATE_TEST_CASE_P( | 890 INSTANTIATE_TEST_CASE_P( |
861 ActivationScopeTest, | 891 ActivationScopeTest, |
862 ContentSubresourceFilterDriverFactoryActivationScopeTest, | 892 ContentSubresourceFilterDriverFactoryActivationScopeTest, |
863 ::testing::ValuesIn(kActivationScopeTestData)); | 893 ::testing::ValuesIn(kActivationScopeTestData)); |
864 | 894 |
865 INSTANTIATE_TEST_CASE_P( | 895 INSTANTIATE_TEST_CASE_P( |
866 ActivationLevelTest, | 896 ActivationLevelTest, |
867 ContentSubresourceFilterDriverFactoryActivationLevelTest, | 897 ContentSubresourceFilterDriverFactoryActivationLevelTest, |
868 ::testing::ValuesIn(kActivationLevelTestData)); | 898 ::testing::ValuesIn(kActivationLevelTestData)); |
869 | 899 |
870 } // namespace subresource_filter | 900 } // namespace subresource_filter |
OLD | NEW |