| 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> config) { |
| 265 scoped_configuration_.ResetConfiguration(std::move(config)); |
| 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, | 275 } |
| 272 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 276 |
| 277 void GetExactlyOneEnabledConfig(Configuration* config) { |
| 278 const auto config_list = GetEnabledConfigurations(); |
| 279 ASSERT_EQ(1u, config_list->configs_by_decreasing_priority().size()); |
| 280 *config = config_list->configs_by_decreasing_priority().front(); |
| 273 } | 281 } |
| 274 | 282 |
| 275 ContentSubresourceFilterDriverFactory* factory() { | 283 ContentSubresourceFilterDriverFactory* factory() { |
| 276 return ContentSubresourceFilterDriverFactory::FromWebContents( | 284 return ContentSubresourceFilterDriverFactory::FromWebContents( |
| 277 RenderViewHostTestHarness::web_contents()); | 285 RenderViewHostTestHarness::web_contents()); |
| 278 } | 286 } |
| 279 | 287 |
| 280 MockSubresourceFilterClient* client() { return client_.get(); } | 288 MockSubresourceFilterClient* client() { return client_.get(); } |
| 281 | 289 |
| 282 content::RenderFrameHost* GetSubframeRFH() { | 290 content::RenderFrameHost* GetSubframeRFH() { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 return; | 482 return; |
| 475 | 483 |
| 476 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; | 484 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
| 477 factory()->throttle_manager()->MaybeAppendNavigationThrottles( | 485 factory()->throttle_manager()->MaybeAppendNavigationThrottles( |
| 478 navigation_handle, &throttles); | 486 navigation_handle, &throttles); |
| 479 for (auto& it : throttles) | 487 for (auto& it : throttles) |
| 480 navigation_handle->RegisterThrottleForTesting(std::move(it)); | 488 navigation_handle->RegisterThrottleForTesting(std::move(it)); |
| 481 } | 489 } |
| 482 | 490 |
| 483 private: | 491 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_; | 492 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; |
| 494 testing::TestRulesetCreator test_ruleset_creator_; | 493 testing::TestRulesetCreator test_ruleset_creator_; |
| 495 testing::TestRulesetPair test_ruleset_pair_; | 494 testing::TestRulesetPair test_ruleset_pair_; |
| 496 | 495 |
| 497 std::unique_ptr<MockSubresourceFilterClient> client_; | 496 std::unique_ptr<MockSubresourceFilterClient> client_; |
| 498 std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_; | 497 std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_; |
| 499 | 498 |
| 500 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); | 499 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); |
| 501 }; | 500 }; |
| 502 | 501 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 533 private: | 532 private: |
| 534 DISALLOW_COPY_AND_ASSIGN( | 533 DISALLOW_COPY_AND_ASSIGN( |
| 535 ContentSubresourceFilterDriverFactoryActivationLevelTest); | 534 ContentSubresourceFilterDriverFactoryActivationLevelTest); |
| 536 }; | 535 }; |
| 537 | 536 |
| 538 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 537 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 539 NoActivationWhenActivationLevelIsDisabled) { | 538 NoActivationWhenActivationLevelIsDisabled) { |
| 540 Configuration config(ActivationLevel::DISABLED, | 539 Configuration config(ActivationLevel::DISABLED, |
| 541 ActivationScope::ACTIVATION_LIST, | 540 ActivationScope::ACTIVATION_LIST, |
| 542 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 541 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 543 config.activation_level = ActivationLevel::DISABLED; | 542 config.activation_options.activation_level = ActivationLevel::DISABLED; |
| 544 ResetConfiguration(std::move(config)); | 543 ResetConfiguration(std::move(config)); |
| 545 | 544 |
| 545 NavigateAndExpectActivation( |
| 546 {false}, {GURL(kExampleLoginUrl)}, EMPTY, |
| 547 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 548 |
| 546 const GURL url(kExampleUrlWithParams); | 549 const GURL url(kExampleUrlWithParams); |
| 547 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 550 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 548 ActivationDecision::ACTIVATION_DISABLED); | 551 ActivationDecision::ACTIVATION_DISABLED); |
| 552 |
| 549 factory()->client()->WhitelistInCurrentWebContents(url); | 553 factory()->client()->WhitelistInCurrentWebContents(url); |
| 550 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 554 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 551 ActivationDecision::ACTIVATION_DISABLED); | 555 ActivationDecision::URL_WHITELISTED); |
| 552 } | 556 } |
| 553 | 557 |
| 554 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { | 558 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { |
| 555 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 559 NavigateAndExpectActivation( |
| 556 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 560 {false}, {GURL(kExampleUrl)}, EMPTY, |
| 561 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 557 } | 562 } |
| 558 | 563 |
| 559 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 564 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 560 SpecialCaseNavigationAllSitesEnabled) { | 565 SpecialCaseNavigationAllSitesEnabled) { |
| 561 // Check that when the experiment is enabled for all site, the activation | 566 // Check that when the experiment is enabled for all site, the activation |
| 562 // signal is always sent. | 567 // signal is always sent. |
| 563 ResetConfigurationToEnableFilteringOnAllSites(); | 568 ResetConfigurationToEnableFilteringOnAllSites(); |
| 564 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); | 569 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); |
| 565 } | 570 } |
| 566 | 571 |
| 567 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 572 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 568 SpecialCaseNavigationActivationListEnabled) { | 573 SpecialCaseNavigationActivationListEnabled) { |
| 569 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 574 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| 570 ActivationDecision::ACTIVATED); | 575 ActivationDecision::ACTIVATED); |
| 571 } | 576 } |
| 572 | 577 |
| 573 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 578 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 574 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { | 579 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { |
| 575 Configuration config(ActivationLevel::ENABLED, | 580 Configuration config(ActivationLevel::ENABLED, |
| 576 ActivationScope::ACTIVATION_LIST, | 581 ActivationScope::ACTIVATION_LIST, |
| 577 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 582 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 578 config.performance_measurement_rate = 1.0; | 583 config.activation_options.performance_measurement_rate = 1.0; |
| 579 ResetConfiguration(std::move(config)); | 584 ResetConfiguration(std::move(config)); |
| 580 | 585 |
| 581 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 586 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| 582 ActivationDecision::ACTIVATED); | 587 ActivationDecision::ACTIVATED); |
| 583 } | 588 } |
| 584 | 589 |
| 585 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { | 590 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { |
| 586 const GURL url(kExampleUrl); | 591 const GURL url(kExampleUrl); |
| 587 ResetConfigurationToEnableFilteringOnAllSites(); | 592 ResetConfigurationToEnableFilteringOnAllSites(); |
| 588 NavigateAndExpectActivation({false}, {url}, EMPTY, | 593 NavigateAndExpectActivation({false}, {url}, EMPTY, |
| 589 ActivationDecision::ACTIVATED); | 594 ActivationDecision::ACTIVATED); |
| 590 EmulateFailedNavigationAndExpectNoActivation(url); | 595 EmulateFailedNavigationAndExpectNoActivation(url); |
| 591 } | 596 } |
| 592 | 597 |
| 593 // TODO(melandory): refactor the test so it no longer require the current | 598 // TODO(melandory): refactor the test so it no longer require the current |
| 594 // activation list to be matching. | 599 // activation list to be matching. |
| 595 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { | 600 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { |
| 596 struct RedirectRedirectChainMatchPatternTestData { | 601 struct RedirectRedirectChainMatchPatternTestData { |
| 597 std::vector<bool> blacklisted_urls; | 602 std::vector<bool> blacklisted_urls; |
| 598 std::vector<GURL> navigation_chain; | 603 std::vector<GURL> navigation_chain; |
| 599 RedirectChainMatchPattern hit_expected_pattern; | 604 RedirectChainMatchPattern hit_expected_pattern; |
| 600 ActivationDecision expected_activation_decision; | 605 ActivationDecision expected_activation_decision; |
| 601 } kRedirectRedirectChainMatchPatternTestData[] = { | 606 } kRedirectRedirectChainMatchPatternTestData[] = { |
| 602 {{false}, | 607 {{false}, |
| 603 {GURL(kUrlA)}, | 608 {GURL(kUrlA)}, |
| 604 EMPTY, | 609 EMPTY, |
| 605 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 610 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 606 {{true}, {GURL(kUrlA)}, NO_REDIRECTS_HIT, ActivationDecision::ACTIVATED}, | 611 {{true}, {GURL(kUrlA)}, NO_REDIRECTS_HIT, ActivationDecision::ACTIVATED}, |
| 607 {{false, false}, | 612 {{false, false}, |
| 608 {GURL(kUrlA), GURL(kUrlB)}, | 613 {GURL(kUrlA), GURL(kUrlB)}, |
| 609 EMPTY, | 614 EMPTY, |
| 610 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 615 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 611 {{false, true}, | 616 {{false, true}, |
| 612 {GURL(kUrlA), GURL(kUrlB)}, | 617 {GURL(kUrlA), GURL(kUrlB)}, |
| 613 F0M0L1, | 618 F0M0L1, |
| 614 ActivationDecision::ACTIVATED}, | 619 ActivationDecision::ACTIVATED}, |
| 615 {{true, false}, | 620 {{true, false}, |
| 616 {GURL(kUrlA), GURL(kUrlB)}, | 621 {GURL(kUrlA), GURL(kUrlB)}, |
| 617 F1M0L0, | 622 F1M0L0, |
| 618 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 623 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 619 {{true, true}, | 624 {{true, true}, |
| 620 {GURL(kUrlA), GURL(kUrlB)}, | 625 {GURL(kUrlA), GURL(kUrlB)}, |
| 621 F1M0L1, | 626 F1M0L1, |
| 622 ActivationDecision::ACTIVATED}, | 627 ActivationDecision::ACTIVATED}, |
| 623 {{false, false, false}, | 628 {{false, false, false}, |
| 624 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 629 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 625 EMPTY, | 630 EMPTY, |
| 626 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 631 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 627 {{false, false, true}, | 632 {{false, false, true}, |
| 628 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 633 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 629 F0M0L1, | 634 F0M0L1, |
| 630 ActivationDecision::ACTIVATED}, | 635 ActivationDecision::ACTIVATED}, |
| 631 {{false, true, false}, | 636 {{false, true, false}, |
| 632 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 637 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 633 F0M1L0, | 638 F0M1L0, |
| 634 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 639 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 635 {{false, true, true}, | 640 {{false, true, true}, |
| 636 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 641 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 637 F0M1L1, | 642 F0M1L1, |
| 638 ActivationDecision::ACTIVATED}, | 643 ActivationDecision::ACTIVATED}, |
| 639 {{true, false, false}, | 644 {{true, false, false}, |
| 640 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 645 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 641 F1M0L0, | 646 F1M0L0, |
| 642 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 647 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 643 {{true, false, true}, | 648 {{true, false, true}, |
| 644 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 649 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 645 F1M0L1, | 650 F1M0L1, |
| 646 ActivationDecision::ACTIVATED}, | 651 ActivationDecision::ACTIVATED}, |
| 647 {{true, true, false}, | 652 {{true, true, false}, |
| 648 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 653 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 649 F1M1L0, | 654 F1M1L0, |
| 650 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 655 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 651 {{true, true, true}, | 656 {{true, true, true}, |
| 652 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 657 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
| 653 F1M1L1, | 658 F1M1L1, |
| 654 ActivationDecision::ACTIVATED}, | 659 ActivationDecision::ACTIVATED}, |
| 655 {{false, true, false, false}, | 660 {{false, true, false, false}, |
| 656 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)}, | 661 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)}, |
| 657 F0M1L0, | 662 F0M1L0, |
| 658 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 663 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
| 659 }; | 664 }; |
| 660 | 665 |
| 661 for (size_t i = 0U; i < arraysize(kRedirectRedirectChainMatchPatternTestData); | 666 for (size_t i = 0U; i < arraysize(kRedirectRedirectChainMatchPatternTestData); |
| 662 ++i) { | 667 ++i) { |
| 663 auto test_data = kRedirectRedirectChainMatchPatternTestData[i]; | 668 auto test_data = kRedirectRedirectChainMatchPatternTestData[i]; |
| 664 NavigateAndExpectActivation( | 669 NavigateAndExpectActivation( |
| 665 test_data.blacklisted_urls, test_data.navigation_chain, | 670 test_data.blacklisted_urls, test_data.navigation_chain, |
| 666 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 671 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 667 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 672 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 668 content::Referrer(), ui::PAGE_TRANSITION_LINK, | 673 content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 669 test_data.hit_expected_pattern, test_data.expected_activation_decision); | 674 test_data.hit_expected_pattern, test_data.expected_activation_decision); |
| 670 NavigateAndExpectActivation( | 675 NavigateAndExpectActivation( |
| 671 {false}, {GURL("https://dummy.com")}, EMPTY, | 676 {false}, {GURL("https://dummy.com")}, EMPTY, |
| 672 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 677 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 673 #if defined(GOOGLE_CHROME_BUILD) | 678 #if defined(GOOGLE_CHROME_BUILD) |
| 674 NavigateAndExpectActivation( | 679 NavigateAndExpectActivation( |
| 675 test_data.blacklisted_urls, test_data.navigation_chain, | 680 test_data.blacklisted_urls, test_data.navigation_chain, |
| 676 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, | 681 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
| 677 safe_browsing::ThreatPatternType::NONE, content::Referrer(), | 682 safe_browsing::ThreatPatternType::NONE, content::Referrer(), |
| 678 ui::PAGE_TRANSITION_LINK, test_data.hit_expected_pattern, | 683 ui::PAGE_TRANSITION_LINK, test_data.hit_expected_pattern, |
| 679 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 684 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 680 #endif | 685 #endif |
| 681 } | 686 } |
| 682 } | 687 } |
| 683 | 688 |
| 684 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { | 689 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { |
| 685 ResetConfigurationToEnableFilteringOnAllSites(); | 690 ResetConfigurationToEnableFilteringOnAllSites(); |
| 686 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 691 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 687 ActivationDecision::ACTIVATED); | 692 ActivationDecision::ACTIVATED); |
| 688 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); | 693 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); |
| 689 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 694 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
| 690 true /* expect_cancelled */); | 695 true /* expect_cancelled */); |
| 691 } | 696 } |
| 692 | 697 |
| 693 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 698 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 694 SuppressNotificationVisibility) { | 699 SuppressNotificationVisibility) { |
| 695 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | 700 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 696 config.should_suppress_notifications = true; | 701 config.activation_options.should_suppress_notifications = true; |
| 697 ResetConfiguration(std::move(config)); | 702 ResetConfiguration(std::move(config)); |
| 698 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 703 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 699 ActivationDecision::ACTIVATED); | 704 ActivationDecision::ACTIVATED); |
| 700 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); | 705 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
| 701 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 706 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
| 702 true /* expect_cancelled */); | 707 true /* expect_cancelled */); |
| 703 } | 708 } |
| 704 | 709 |
| 705 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 710 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 706 InactiveMainFrame_SubframeNotFiltered) { | 711 InactiveMainFrame_SubframeNotFiltered) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 720 } kTestCases[] = { | 725 } kTestCases[] = { |
| 721 {content::Referrer(), ui::PAGE_TRANSITION_LINK, | 726 {content::Referrer(), ui::PAGE_TRANSITION_LINK, |
| 722 ActivationDecision::ACTIVATED}, | 727 ActivationDecision::ACTIVATED}, |
| 723 {content::Referrer(GURL(kUrlA), blink::kWebReferrerPolicyDefault), | 728 {content::Referrer(GURL(kUrlA), blink::kWebReferrerPolicyDefault), |
| 724 ui::PAGE_TRANSITION_LINK, ActivationDecision::ACTIVATED}, | 729 ui::PAGE_TRANSITION_LINK, ActivationDecision::ACTIVATED}, |
| 725 {content::Referrer(GURL(kExampleUrl), blink::kWebReferrerPolicyDefault), | 730 {content::Referrer(GURL(kExampleUrl), blink::kWebReferrerPolicyDefault), |
| 726 ui::PAGE_TRANSITION_LINK, ActivationDecision::URL_WHITELISTED}, | 731 ui::PAGE_TRANSITION_LINK, ActivationDecision::URL_WHITELISTED}, |
| 727 {content::Referrer(), ui::PAGE_TRANSITION_RELOAD, | 732 {content::Referrer(), ui::PAGE_TRANSITION_RELOAD, |
| 728 ActivationDecision::URL_WHITELISTED}}; | 733 ActivationDecision::URL_WHITELISTED}}; |
| 729 | 734 |
| 735 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 736 config.activation_options.should_whitelist_site_on_reload = true; |
| 737 ResetConfiguration(std::move(config)); |
| 738 |
| 730 for (const auto& test_case : kTestCases) { | 739 for (const auto& test_case : kTestCases) { |
| 731 SCOPED_TRACE(::testing::Message("referrer = \"") | 740 SCOPED_TRACE(::testing::Message("referrer = \"") |
| 732 << test_case.referrer.url << "\"" | 741 << test_case.referrer.url << "\"" |
| 733 << " transition = \"" << test_case.transition << "\""); | 742 << " transition = \"" << test_case.transition << "\""); |
| 734 | 743 |
| 735 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | |
| 736 config.should_whitelist_site_on_reload = true; | |
| 737 ResetConfiguration(std::move(config)); | |
| 738 | |
| 739 NavigateAndExpectActivation( | 744 NavigateAndExpectActivation( |
| 740 {false}, {GURL(kExampleUrl)}, | 745 {false}, {GURL(kExampleUrl)}, |
| 741 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 746 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 742 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 747 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 743 test_case.referrer, test_case.transition, EMPTY, | 748 test_case.referrer, test_case.transition, EMPTY, |
| 744 test_case.expected_activation_decision); | 749 test_case.expected_activation_decision); |
| 745 // Verify that if the first URL failed to activate, subsequent same-origin | 750 // Verify that if the first URL failed to activate, subsequent same-origin |
| 746 // navigations also fail to activate. | 751 // navigations also fail to activate. |
| 747 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, | 752 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, |
| 748 test_case.expected_activation_decision); | 753 test_case.expected_activation_decision); |
| 749 } | 754 } |
| 750 } | 755 } |
| 751 | 756 |
| 757 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoConfigs) { |
| 758 ResetConfiguration(std::vector<Configuration>()); |
| 759 NavigateAndExpectActivation( |
| 760 {true}, {GURL(kExampleUrl)}, NO_REDIRECTS_HIT, |
| 761 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
| 762 } |
| 763 |
| 764 TEST_F(ContentSubresourceFilterDriverFactoryTest, MultipleSimultaneousConfigs) { |
| 765 Configuration config1(ActivationLevel::DRYRUN, ActivationScope::NO_SITES); |
| 766 config1.activation_conditions.priority = 2; |
| 767 |
| 768 Configuration config2(ActivationLevel::DISABLED, |
| 769 ActivationScope::ACTIVATION_LIST, |
| 770 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 771 config2.activation_conditions.priority = 1; |
| 772 |
| 773 Configuration config3(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 774 config3.activation_options.should_whitelist_site_on_reload = true; |
| 775 config3.activation_conditions.priority = 0; |
| 776 |
| 777 ResetConfiguration({config1, config2, config3}); |
| 778 |
| 779 // Should match |config2| and |config3|, the former with the higher priority. |
| 780 NavigateAndExpectActivation({true}, {GURL(kExampleUrl)}, NO_REDIRECTS_HIT, |
| 781 ActivationDecision::ACTIVATION_DISABLED); |
| 782 |
| 783 // Should match |config3|. |
| 784 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 785 ActivationDecision::ACTIVATED); |
| 786 |
| 787 // Should match |config3|, but a reload, so this should get whitelisted. |
| 788 NavigateAndExpectActivation( |
| 789 {false}, {GURL(kExampleUrl)}, safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 790 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 791 content::Referrer(), ui::PAGE_TRANSITION_RELOAD, EMPTY, |
| 792 ActivationDecision::URL_WHITELISTED); |
| 793 } |
| 794 |
| 752 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, | 795 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| 753 ActivateForFrameState) { | 796 ActivateForFrameState) { |
| 754 const ActivationLevelTestData& test_data = GetParam(); | 797 const ActivationLevelTestData& test_data = GetParam(); |
| 755 ResetConfiguration(Configuration( | 798 ResetConfiguration(Configuration( |
| 756 test_data.activation_level, ActivationScope::ACTIVATION_LIST, | 799 test_data.activation_level, ActivationScope::ACTIVATION_LIST, |
| 757 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 800 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
| 758 | 801 |
| 759 const GURL url(kExampleUrlWithParams); | 802 const GURL url(kExampleUrlWithParams); |
| 760 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 803 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 761 test_data.expected_activation_decision); | 804 test_data.expected_activation_decision); |
| 762 factory()->client()->WhitelistInCurrentWebContents(url); | 805 factory()->client()->WhitelistInCurrentWebContents(url); |
| 763 NavigateAndExpectActivation( | 806 NavigateAndExpectActivation({true}, {GURL(kExampleUrlWithParams)}, |
| 764 {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, | 807 NO_REDIRECTS_HIT, |
| 765 GetActiveConfigurations()->the_one_and_only().activation_level == | 808 ActivationDecision::URL_WHITELISTED); |
| 766 ActivationLevel::DISABLED | |
| 767 ? ActivationDecision::ACTIVATION_DISABLED | |
| 768 : ActivationDecision::URL_WHITELISTED); | |
| 769 } | 809 } |
| 770 | 810 |
| 771 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, | 811 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| 772 ActivateForTheListType) { | 812 ActivateForTheListType) { |
| 773 // Sets up the experiment in a way that the activation decision depends on the | 813 // Sets up the experiment in a way that the activation decision depends on the |
| 774 // list for which the Safe Browsing hit has happened. | 814 // list for which the Safe Browsing hit has happened. |
| 775 const ActivationListTestData& test_data = GetParam(); | 815 const ActivationListTestData& test_data = GetParam(); |
| 776 ResetConfiguration(Configuration(ActivationLevel::ENABLED, | 816 ResetConfiguration(Configuration(ActivationLevel::ENABLED, |
| 777 ActivationScope::ACTIVATION_LIST, | 817 ActivationScope::ACTIVATION_LIST, |
| 778 test_data.activation_list)); | 818 test_data.activation_list)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 800 | 840 |
| 801 const GURL test_url(kExampleUrlWithParams); | 841 const GURL test_url(kExampleUrlWithParams); |
| 802 | 842 |
| 803 RedirectChainMatchPattern expected_pattern = | 843 RedirectChainMatchPattern expected_pattern = |
| 804 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 844 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
| 805 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 845 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 806 {test_url}, expected_pattern, | 846 {test_url}, expected_pattern, |
| 807 test_data.expected_activation_decision); | 847 test_data.expected_activation_decision); |
| 808 if (test_data.url_matches_activation_list) { | 848 if (test_data.url_matches_activation_list) { |
| 809 factory()->client()->WhitelistInCurrentWebContents(test_url); | 849 factory()->client()->WhitelistInCurrentWebContents(test_url); |
| 810 NavigateAndExpectActivation( | 850 ActivationDecision expected_decision = |
| 811 {test_data.url_matches_activation_list}, {GURL(kExampleUrlWithParams)}, | 851 test_data.expected_activation_decision; |
| 812 expected_pattern, | 852 if (expected_decision == ActivationDecision::ACTIVATED) |
| 813 GetActiveConfigurations()->the_one_and_only().activation_scope == | 853 expected_decision = ActivationDecision::URL_WHITELISTED; |
| 814 ActivationScope::NO_SITES | 854 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 815 ? ActivationDecision::ACTIVATION_DISABLED | 855 {GURL(kExampleUrlWithParams)}, expected_pattern, |
| 816 : ActivationDecision::URL_WHITELISTED); | 856 expected_decision); |
| 817 } | 857 } |
| 818 }; | 858 }; |
| 819 | 859 |
| 820 // Only main frames with http/https schemes should activate, unless the | 860 // Only main frames with http/https schemes should activate. |
| 821 // activation scope is for all sites. | |
| 822 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 861 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 823 ActivateForSupportedUrlScheme) { | 862 ActivateForSupportedUrlScheme) { |
| 824 const ActivationScopeTestData& test_data = GetParam(); | 863 const ActivationScopeTestData& test_data = GetParam(); |
| 825 ResetConfiguration( | 864 ResetConfiguration( |
| 826 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, | 865 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, |
| 827 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 866 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
| 828 | 867 |
| 829 // data URLs are also not supported, but not listed here, as it's not possible | 868 // 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. | 869 // for a page to redirect to them after https://crbug.com/594215 is fixed. |
| 831 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", | 870 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", |
| 832 "chrome-extension://some-extension", | 871 "chrome-extension://some-extension", |
| 833 "file:///var/www/index.html"}; | 872 "file:///var/www/index.html"}; |
| 834 const char* supported_urls[] = {"http://example.test", | 873 const char* supported_urls[] = {"http://example.test", |
| 835 "https://example.test"}; | 874 "https://example.test"}; |
| 836 for (auto* url : unsupported_urls) { | 875 for (auto* url : unsupported_urls) { |
| 837 SCOPED_TRACE(url); | 876 SCOPED_TRACE(url); |
| 838 RedirectChainMatchPattern expected_pattern = EMPTY; | 877 RedirectChainMatchPattern expected_pattern = EMPTY; |
| 839 NavigateAndExpectActivation( | 878 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 840 {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, | 879 {GURL(url)}, expected_pattern, |
| 841 GetActiveConfigurations()->the_one_and_only().activation_scope == | 880 ActivationDecision::UNSUPPORTED_SCHEME); |
| 842 ActivationScope::NO_SITES | |
| 843 ? ActivationDecision::ACTIVATION_DISABLED | |
| 844 : ActivationDecision::UNSUPPORTED_SCHEME); | |
| 845 } | 881 } |
| 846 for (auto* url : supported_urls) { | 882 for (auto* url : supported_urls) { |
| 847 SCOPED_TRACE(url); | 883 SCOPED_TRACE(url); |
| 848 RedirectChainMatchPattern expected_pattern = | 884 RedirectChainMatchPattern expected_pattern = |
| 849 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 885 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
| 850 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 886 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 851 {GURL(url)}, expected_pattern, | 887 {GURL(url)}, expected_pattern, |
| 852 test_data.expected_activation_decision); | 888 test_data.expected_activation_decision); |
| 853 } | 889 } |
| 854 }; | 890 }; |
| 855 | 891 |
| 856 INSTANTIATE_TEST_CASE_P(NoSocEngHit, | 892 INSTANTIATE_TEST_CASE_P(NoSocEngHit, |
| 857 ContentSubresourceFilterDriverFactoryThreatTypeTest, | 893 ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| 858 ::testing::ValuesIn(kActivationListTestData)); | 894 ::testing::ValuesIn(kActivationListTestData)); |
| 859 | 895 |
| 860 INSTANTIATE_TEST_CASE_P( | 896 INSTANTIATE_TEST_CASE_P( |
| 861 ActivationScopeTest, | 897 ActivationScopeTest, |
| 862 ContentSubresourceFilterDriverFactoryActivationScopeTest, | 898 ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 863 ::testing::ValuesIn(kActivationScopeTestData)); | 899 ::testing::ValuesIn(kActivationScopeTestData)); |
| 864 | 900 |
| 865 INSTANTIATE_TEST_CASE_P( | 901 INSTANTIATE_TEST_CASE_P( |
| 866 ActivationLevelTest, | 902 ActivationLevelTest, |
| 867 ContentSubresourceFilterDriverFactoryActivationLevelTest, | 903 ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| 868 ::testing::ValuesIn(kActivationLevelTestData)); | 904 ::testing::ValuesIn(kActivationLevelTestData)); |
| 869 | 905 |
| 870 } // namespace subresource_filter | 906 } // namespace subresource_filter |
| OLD | NEW |