Chromium Code Reviews| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 rules.push_back(testing::CreateSuffixRule("disallowed.html")); | 232 rules.push_back(testing::CreateSuffixRule("disallowed.html")); |
| 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_ = new MockSubresourceFilterClient(ruleset_dealer_.get()); | 239 client_ = new MockSubresourceFilterClient(ruleset_dealer_.get()); |
| 240 ContentSubresourceFilterDriverFactory::CreateForWebContents( | 240 ContentSubresourceFilterDriverFactory::CreateForWebContents( |
| 241 RenderViewHostTestHarness::web_contents(), base::WrapUnique(client())); | 241 RenderViewHostTestHarness::web_contents(), base::WrapUnique(client())); |
| 242 ResetConfigurationToEnableFilteringOnSocialEngineeringSites(); | 242 ResetConfigurationToEnableFilteringOnPhishingSites(); |
| 243 | 243 |
| 244 // Add a subframe. | 244 // Add a subframe. |
| 245 content::RenderFrameHostTester* rfh_tester = | 245 content::RenderFrameHostTester* rfh_tester = |
| 246 content::RenderFrameHostTester::For(main_rfh()); | 246 content::RenderFrameHostTester::For(main_rfh()); |
| 247 rfh_tester->InitializeRenderFrameIfNeeded(); | 247 rfh_tester->InitializeRenderFrameIfNeeded(); |
| 248 rfh_tester->AppendChild(kSubframeName); | 248 rfh_tester->AppendChild(kSubframeName); |
| 249 | 249 |
| 250 Observe(content::RenderViewHostTestHarness::web_contents()); | 250 Observe(content::RenderViewHostTestHarness::web_contents()); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void TearDown() override { | 253 void TearDown() override { |
| 254 ruleset_dealer_.reset(); | 254 ruleset_dealer_.reset(); |
| 255 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
| 256 RenderViewHostTestHarness::TearDown(); | 256 RenderViewHostTestHarness::TearDown(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ResetConfiguration(Configuration config) { | 259 void ResetConfiguration(Configuration config) { |
| 260 scoped_configuration_.ResetConfiguration(std::move(config)); | 260 scoped_configuration_.ResetConfiguration(std::move(config)); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void ResetConfigurationToEnableFilteringOnAllSites() { | 263 void ResetConfigurationToEnableFilteringOnAllSites() { |
| 264 ResetConfiguration( | 264 ResetConfiguration( |
| 265 Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES)); | 265 Configuration(ActivationLevel::ENABLED, ActivationScope::ALL_SITES)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void ResetConfigurationToEnableFilteringOnSocialEngineeringSites() { | 268 void ResetConfigurationToEnableFilteringOnPhishingSites() { |
| 269 ResetConfiguration(Configuration( | 269 ResetConfiguration(Configuration::MakePresetForLiveRunOnPhishingSites()); |
| 270 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, | 270 } |
| 271 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 271 |
| 272 Configuration GetExactlyOneEnabledConfig() { | |
| 273 const auto config_list = GetEnabledConfigurations(); | |
| 274 EXPECT_EQ(1u, config_list->configs_by_decreasing_priority().size()); | |
| 275 if (config_list->configs_by_decreasing_priority().empty()) | |
|
pkalinnikov
2017/05/04 12:04:22
Given that ParseEnabledConfigurations always pushe
engedy
2017/05/05 12:25:42
Yes, I made this cleaner.
pkalinnikov
2017/05/05 13:29:58
Yup, looks better.
| |
| 276 return Configuration(); | |
| 277 return (config_list->configs_by_decreasing_priority().front()); | |
| 272 } | 278 } |
| 273 | 279 |
| 274 ContentSubresourceFilterDriverFactory* factory() { | 280 ContentSubresourceFilterDriverFactory* factory() { |
| 275 return ContentSubresourceFilterDriverFactory::FromWebContents( | 281 return ContentSubresourceFilterDriverFactory::FromWebContents( |
| 276 RenderViewHostTestHarness::web_contents()); | 282 RenderViewHostTestHarness::web_contents()); |
| 277 } | 283 } |
| 278 | 284 |
| 279 MockSubresourceFilterClient* client() { return client_; } | 285 MockSubresourceFilterClient* client() { return client_; } |
| 280 | 286 |
| 281 content::RenderFrameHost* GetSubframeRFH() { | 287 content::RenderFrameHost* GetSubframeRFH() { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 return; | 479 return; |
| 474 | 480 |
| 475 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; | 481 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
| 476 factory()->throttle_manager()->MaybeAppendNavigationThrottles( | 482 factory()->throttle_manager()->MaybeAppendNavigationThrottles( |
| 477 navigation_handle, &throttles); | 483 navigation_handle, &throttles); |
| 478 for (auto& it : throttles) | 484 for (auto& it : throttles) |
| 479 navigation_handle->RegisterThrottleForTesting(std::move(it)); | 485 navigation_handle->RegisterThrottleForTesting(std::move(it)); |
| 480 } | 486 } |
| 481 | 487 |
| 482 private: | 488 private: |
| 483 static bool expected_measure_performance() { | |
| 484 const double rate = GetActiveConfigurations() | |
| 485 ->the_one_and_only() | |
| 486 .performance_measurement_rate; | |
| 487 // Note: The case when 0 < rate < 1 is not deterministic, don't test it. | |
| 488 EXPECT_TRUE(rate == 0 || rate == 1); | |
| 489 return rate == 1; | |
| 490 } | |
| 491 | |
| 492 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; | 489 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; |
| 493 testing::TestRulesetCreator test_ruleset_creator_; | 490 testing::TestRulesetCreator test_ruleset_creator_; |
| 494 testing::TestRulesetPair test_ruleset_pair_; | 491 testing::TestRulesetPair test_ruleset_pair_; |
| 495 | 492 |
| 496 // Owned by the factory. | 493 // Owned by the factory. |
| 497 MockSubresourceFilterClient* client_; | 494 MockSubresourceFilterClient* client_; |
| 498 | 495 |
| 499 std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_; | 496 std::unique_ptr<VerifiedRulesetDealer::Handle> ruleset_dealer_; |
| 500 | 497 |
| 501 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); | 498 DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryTest); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 private: | 531 private: |
| 535 DISALLOW_COPY_AND_ASSIGN( | 532 DISALLOW_COPY_AND_ASSIGN( |
| 536 ContentSubresourceFilterDriverFactoryActivationLevelTest); | 533 ContentSubresourceFilterDriverFactoryActivationLevelTest); |
| 537 }; | 534 }; |
| 538 | 535 |
| 539 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 536 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 540 NoActivationWhenActivationLevelIsDisabled) { | 537 NoActivationWhenActivationLevelIsDisabled) { |
| 541 Configuration config(ActivationLevel::DISABLED, | 538 Configuration config(ActivationLevel::DISABLED, |
| 542 ActivationScope::ACTIVATION_LIST, | 539 ActivationScope::ACTIVATION_LIST, |
| 543 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 540 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 544 config.activation_level = ActivationLevel::DISABLED; | 541 config.activation_options.activation_level = ActivationLevel::DISABLED; |
| 545 ResetConfiguration(std::move(config)); | 542 ResetConfiguration(std::move(config)); |
| 546 | 543 |
| 547 const GURL url(kExampleUrlWithParams); | 544 const GURL url(kExampleUrlWithParams); |
| 548 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 545 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 549 ActivationDecision::ACTIVATION_DISABLED); | 546 ActivationDecision::ACTIVATION_DISABLED); |
| 550 factory()->client()->WhitelistInCurrentWebContents(url); | 547 factory()->client()->WhitelistInCurrentWebContents(url); |
| 551 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 548 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 552 ActivationDecision::ACTIVATION_DISABLED); | 549 ActivationDecision::ACTIVATION_DISABLED); |
| 553 } | 550 } |
| 554 | 551 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 569 SpecialCaseNavigationActivationListEnabled) { | 566 SpecialCaseNavigationActivationListEnabled) { |
| 570 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 567 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| 571 ActivationDecision::ACTIVATED); | 568 ActivationDecision::ACTIVATED); |
| 572 } | 569 } |
| 573 | 570 |
| 574 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 571 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 575 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { | 572 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { |
| 576 Configuration config(ActivationLevel::ENABLED, | 573 Configuration config(ActivationLevel::ENABLED, |
| 577 ActivationScope::ACTIVATION_LIST, | 574 ActivationScope::ACTIVATION_LIST, |
| 578 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 575 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
| 579 config.performance_measurement_rate = 1.0; | 576 config.activation_options.performance_measurement_rate = 1.0; |
| 580 ResetConfiguration(std::move(config)); | 577 ResetConfiguration(std::move(config)); |
| 581 | 578 |
| 582 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 579 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| 583 ActivationDecision::ACTIVATED); | 580 ActivationDecision::ACTIVATED); |
| 584 } | 581 } |
| 585 | 582 |
| 586 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { | 583 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { |
| 587 const GURL url(kExampleUrl); | 584 const GURL url(kExampleUrl); |
| 588 ResetConfigurationToEnableFilteringOnAllSites(); | 585 ResetConfigurationToEnableFilteringOnAllSites(); |
| 589 NavigateAndExpectActivation({false}, {url}, EMPTY, | 586 NavigateAndExpectActivation({false}, {url}, EMPTY, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 684 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 688 ActivationDecision::ACTIVATED); | 685 ActivationDecision::ACTIVATED); |
| 689 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); | 686 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); |
| 690 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 687 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
| 691 true /* expect_cancelled */); | 688 true /* expect_cancelled */); |
| 692 } | 689 } |
| 693 | 690 |
| 694 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 691 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 695 SuppressNotificationVisibility) { | 692 SuppressNotificationVisibility) { |
| 696 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | 693 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 697 config.should_suppress_notifications = true; | 694 config.activation_options.should_suppress_notifications = true; |
| 698 ResetConfiguration(std::move(config)); | 695 ResetConfiguration(std::move(config)); |
| 699 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 696 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 700 ActivationDecision::ACTIVATED); | 697 ActivationDecision::ACTIVATED); |
| 701 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); | 698 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
| 702 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 699 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
| 703 true /* expect_cancelled */); | 700 true /* expect_cancelled */); |
| 704 } | 701 } |
| 705 | 702 |
| 706 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 703 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 707 InactiveMainFrame_SubframeNotFiltered) { | 704 InactiveMainFrame_SubframeNotFiltered) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 727 ui::PAGE_TRANSITION_LINK, ActivationDecision::URL_WHITELISTED}, | 724 ui::PAGE_TRANSITION_LINK, ActivationDecision::URL_WHITELISTED}, |
| 728 {content::Referrer(), ui::PAGE_TRANSITION_RELOAD, | 725 {content::Referrer(), ui::PAGE_TRANSITION_RELOAD, |
| 729 ActivationDecision::URL_WHITELISTED}}; | 726 ActivationDecision::URL_WHITELISTED}}; |
| 730 | 727 |
| 731 for (const auto& test_case : kTestCases) { | 728 for (const auto& test_case : kTestCases) { |
| 732 SCOPED_TRACE(::testing::Message("referrer = \"") | 729 SCOPED_TRACE(::testing::Message("referrer = \"") |
| 733 << test_case.referrer.url << "\"" | 730 << test_case.referrer.url << "\"" |
| 734 << " transition = \"" << test_case.transition << "\""); | 731 << " transition = \"" << test_case.transition << "\""); |
| 735 | 732 |
| 736 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | 733 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
| 737 config.should_whitelist_site_on_reload = true; | 734 config.activation_options.should_whitelist_site_on_reload = true; |
| 738 ResetConfiguration(std::move(config)); | 735 ResetConfiguration(std::move(config)); |
| 739 | 736 |
| 740 NavigateAndExpectActivation( | 737 NavigateAndExpectActivation( |
| 741 {false}, {GURL(kExampleUrl)}, | 738 {false}, {GURL(kExampleUrl)}, |
| 742 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 739 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 743 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 740 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 744 test_case.referrer, test_case.transition, EMPTY, | 741 test_case.referrer, test_case.transition, EMPTY, |
| 745 test_case.expected_activation_decision); | 742 test_case.expected_activation_decision); |
| 746 // Verify that if the first URL failed to activate, subsequent same-origin | 743 // Verify that if the first URL failed to activate, subsequent same-origin |
| 747 // navigations also fail to activate. | 744 // navigations also fail to activate. |
| 748 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, | 745 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, |
| 749 test_case.expected_activation_decision); | 746 test_case.expected_activation_decision); |
| 750 } | 747 } |
| 751 } | 748 } |
| 752 | 749 |
| 753 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, | 750 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| 754 ActivateForFrameState) { | 751 ActivateForFrameState) { |
| 755 const ActivationLevelTestData& test_data = GetParam(); | 752 const ActivationLevelTestData& test_data = GetParam(); |
| 756 ResetConfiguration(Configuration( | 753 ResetConfiguration(Configuration( |
| 757 test_data.activation_level, ActivationScope::ACTIVATION_LIST, | 754 test_data.activation_level, ActivationScope::ACTIVATION_LIST, |
| 758 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 755 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
| 759 | 756 |
| 760 const GURL url(kExampleUrlWithParams); | 757 const GURL url(kExampleUrlWithParams); |
| 761 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 758 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 762 test_data.expected_activation_decision); | 759 test_data.expected_activation_decision); |
| 763 factory()->client()->WhitelistInCurrentWebContents(url); | 760 factory()->client()->WhitelistInCurrentWebContents(url); |
| 761 bool expect_activation_is_disabled = | |
| 762 GetExactlyOneEnabledConfig().activation_options.activation_level == | |
| 763 ActivationLevel::DISABLED; | |
| 764 NavigateAndExpectActivation( | 764 NavigateAndExpectActivation( |
| 765 {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, | 765 {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, |
| 766 GetActiveConfigurations()->the_one_and_only().activation_level == | 766 expect_activation_is_disabled ? ActivationDecision::ACTIVATION_DISABLED |
| 767 ActivationLevel::DISABLED | 767 : ActivationDecision::URL_WHITELISTED); |
| 768 ? ActivationDecision::ACTIVATION_DISABLED | |
| 769 : ActivationDecision::URL_WHITELISTED); | |
| 770 } | 768 } |
| 771 | 769 |
| 772 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, | 770 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| 773 ActivateForTheListType) { | 771 ActivateForTheListType) { |
| 774 // Sets up the experiment in a way that the activation decision depends on the | 772 // Sets up the experiment in a way that the activation decision depends on the |
| 775 // list for which the Safe Browsing hit has happened. | 773 // list for which the Safe Browsing hit has happened. |
| 776 const ActivationListTestData& test_data = GetParam(); | 774 const ActivationListTestData& test_data = GetParam(); |
| 777 ResetConfiguration(Configuration(ActivationLevel::ENABLED, | 775 ResetConfiguration(Configuration(ActivationLevel::ENABLED, |
| 778 ActivationScope::ACTIVATION_LIST, | 776 ActivationScope::ACTIVATION_LIST, |
| 779 test_data.activation_list)); | 777 test_data.activation_list)); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 801 | 799 |
| 802 const GURL test_url(kExampleUrlWithParams); | 800 const GURL test_url(kExampleUrlWithParams); |
| 803 | 801 |
| 804 RedirectChainMatchPattern expected_pattern = | 802 RedirectChainMatchPattern expected_pattern = |
| 805 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 803 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
| 806 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 804 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 807 {test_url}, expected_pattern, | 805 {test_url}, expected_pattern, |
| 808 test_data.expected_activation_decision); | 806 test_data.expected_activation_decision); |
| 809 if (test_data.url_matches_activation_list) { | 807 if (test_data.url_matches_activation_list) { |
| 810 factory()->client()->WhitelistInCurrentWebContents(test_url); | 808 factory()->client()->WhitelistInCurrentWebContents(test_url); |
| 811 NavigateAndExpectActivation( | 809 bool expect_activation_is_disabled = |
| 812 {test_data.url_matches_activation_list}, {GURL(kExampleUrlWithParams)}, | 810 GetExactlyOneEnabledConfig().activation_conditions.activation_scope == |
| 813 expected_pattern, | 811 ActivationScope::NO_SITES; |
| 814 GetActiveConfigurations()->the_one_and_only().activation_scope == | 812 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 815 ActivationScope::NO_SITES | 813 {GURL(kExampleUrlWithParams)}, expected_pattern, |
| 816 ? ActivationDecision::ACTIVATION_DISABLED | 814 expect_activation_is_disabled |
| 817 : ActivationDecision::URL_WHITELISTED); | 815 ? ActivationDecision::ACTIVATION_DISABLED |
| 816 : ActivationDecision::URL_WHITELISTED); | |
| 818 } | 817 } |
| 819 }; | 818 }; |
| 820 | 819 |
| 821 // Only main frames with http/https schemes should activate, unless the | 820 // Only main frames with http/https schemes should activate, unless the |
| 822 // activation scope is for all sites. | 821 // activation scope is for all sites. |
| 823 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 822 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 824 ActivateForSupportedUrlScheme) { | 823 ActivateForSupportedUrlScheme) { |
| 825 const ActivationScopeTestData& test_data = GetParam(); | 824 const ActivationScopeTestData& test_data = GetParam(); |
| 826 ResetConfiguration( | 825 ResetConfiguration( |
| 827 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, | 826 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, |
| 828 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 827 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
| 829 | 828 |
| 830 // data URLs are also not supported, but not listed here, as it's not possible | 829 // data URLs are also not supported, but not listed here, as it's not possible |
| 831 // for a page to redirect to them after https://crbug.com/594215 is fixed. | 830 // for a page to redirect to them after https://crbug.com/594215 is fixed. |
| 832 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", | 831 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", |
| 833 "chrome-extension://some-extension", | 832 "chrome-extension://some-extension", |
| 834 "file:///var/www/index.html"}; | 833 "file:///var/www/index.html"}; |
| 835 const char* supported_urls[] = {"http://example.test", | 834 const char* supported_urls[] = {"http://example.test", |
| 836 "https://example.test"}; | 835 "https://example.test"}; |
| 837 for (auto* url : unsupported_urls) { | 836 for (auto* url : unsupported_urls) { |
| 838 SCOPED_TRACE(url); | 837 SCOPED_TRACE(url); |
| 838 bool expect_activation_is_disabled = | |
| 839 GetExactlyOneEnabledConfig().activation_conditions.activation_scope == | |
| 840 ActivationScope::NO_SITES; | |
| 839 RedirectChainMatchPattern expected_pattern = EMPTY; | 841 RedirectChainMatchPattern expected_pattern = EMPTY; |
| 840 NavigateAndExpectActivation( | 842 NavigateAndExpectActivation( |
| 841 {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, | 843 {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, |
| 842 GetActiveConfigurations()->the_one_and_only().activation_scope == | 844 expect_activation_is_disabled ? ActivationDecision::ACTIVATION_DISABLED |
| 843 ActivationScope::NO_SITES | 845 : ActivationDecision::UNSUPPORTED_SCHEME); |
| 844 ? ActivationDecision::ACTIVATION_DISABLED | |
| 845 : ActivationDecision::UNSUPPORTED_SCHEME); | |
| 846 } | 846 } |
| 847 for (auto* url : supported_urls) { | 847 for (auto* url : supported_urls) { |
| 848 SCOPED_TRACE(url); | 848 SCOPED_TRACE(url); |
| 849 RedirectChainMatchPattern expected_pattern = | 849 RedirectChainMatchPattern expected_pattern = |
| 850 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 850 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
| 851 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 851 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 852 {GURL(url)}, expected_pattern, | 852 {GURL(url)}, expected_pattern, |
| 853 test_data.expected_activation_decision); | 853 test_data.expected_activation_decision); |
| 854 } | 854 } |
| 855 }; | 855 }; |
| 856 | 856 |
| 857 INSTANTIATE_TEST_CASE_P(NoSocEngHit, | 857 INSTANTIATE_TEST_CASE_P(NoSocEngHit, |
| 858 ContentSubresourceFilterDriverFactoryThreatTypeTest, | 858 ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| 859 ::testing::ValuesIn(kActivationListTestData)); | 859 ::testing::ValuesIn(kActivationListTestData)); |
| 860 | 860 |
| 861 INSTANTIATE_TEST_CASE_P( | 861 INSTANTIATE_TEST_CASE_P( |
| 862 ActivationScopeTest, | 862 ActivationScopeTest, |
| 863 ContentSubresourceFilterDriverFactoryActivationScopeTest, | 863 ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 864 ::testing::ValuesIn(kActivationScopeTestData)); | 864 ::testing::ValuesIn(kActivationScopeTestData)); |
| 865 | 865 |
| 866 INSTANTIATE_TEST_CASE_P( | 866 INSTANTIATE_TEST_CASE_P( |
| 867 ActivationLevelTest, | 867 ActivationLevelTest, |
| 868 ContentSubresourceFilterDriverFactoryActivationLevelTest, | 868 ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| 869 ::testing::ValuesIn(kActivationLevelTestData)); | 869 ::testing::ValuesIn(kActivationLevelTestData)); |
| 870 | 870 |
| 871 } // namespace subresource_filter | 871 } // namespace subresource_filter |
| OLD | NEW |