| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 462 |
| 463 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; | 463 std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
| 464 factory()->throttle_manager()->MaybeAppendNavigationThrottles( | 464 factory()->throttle_manager()->MaybeAppendNavigationThrottles( |
| 465 navigation_handle, &throttles); | 465 navigation_handle, &throttles); |
| 466 for (auto& it : throttles) | 466 for (auto& it : throttles) |
| 467 navigation_handle->RegisterThrottleForTesting(std::move(it)); | 467 navigation_handle->RegisterThrottleForTesting(std::move(it)); |
| 468 } | 468 } |
| 469 | 469 |
| 470 private: | 470 private: |
| 471 static bool expected_measure_performance() { | 471 static bool expected_measure_performance() { |
| 472 const double rate = GetActiveConfiguration().performance_measurement_rate; | 472 const double rate = GetActiveConfigurations() |
| 473 ->the_one_and_only() |
| 474 .performance_measurement_rate; |
| 473 // Note: The case when 0 < rate < 1 is not deterministic, don't test it. | 475 // Note: The case when 0 < rate < 1 is not deterministic, don't test it. |
| 474 EXPECT_TRUE(rate == 0 || rate == 1); | 476 EXPECT_TRUE(rate == 0 || rate == 1); |
| 475 return rate == 1; | 477 return rate == 1; |
| 476 } | 478 } |
| 477 | 479 |
| 478 testing::TestRulesetCreator test_ruleset_creator_; | 480 testing::TestRulesetCreator test_ruleset_creator_; |
| 479 testing::TestRulesetPair test_ruleset_pair_; | 481 testing::TestRulesetPair test_ruleset_pair_; |
| 480 | 482 |
| 481 // Owned by the factory. | 483 // Owned by the factory. |
| 482 MockSubresourceFilterClient* client_; | 484 MockSubresourceFilterClient* client_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 | 525 |
| 524 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 526 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 525 ActivateForFrameHostDisabledFeature) { | 527 ActivateForFrameHostDisabledFeature) { |
| 526 // Activation scope is set to NONE => no activation should happen even if URL | 528 // Activation scope is set to NONE => no activation should happen even if URL |
| 527 // which is visited was a SB hit. | 529 // which is visited was a SB hit. |
| 528 base::FieldTrialList field_trial_list(nullptr); | 530 base::FieldTrialList field_trial_list(nullptr); |
| 529 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 531 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 530 base::FeatureList::OVERRIDE_DISABLE_FEATURE, kActivationLevelEnabled, | 532 base::FeatureList::OVERRIDE_DISABLE_FEATURE, kActivationLevelEnabled, |
| 531 kActivationScopeAllSites, | 533 kActivationScopeAllSites, |
| 532 kActivationListSocialEngineeringAdsInterstitial); | 534 kActivationListSocialEngineeringAdsInterstitial); |
| 533 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 534 const GURL url(kExampleUrlWithParams); | 535 const GURL url(kExampleUrlWithParams); |
| 535 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 536 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 536 ActivationDecision::ACTIVATION_DISABLED); | 537 ActivationDecision::ACTIVATION_DISABLED); |
| 537 factory()->client()->WhitelistInCurrentWebContents(url); | 538 factory()->client()->WhitelistInCurrentWebContents(url); |
| 538 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 539 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 539 ActivationDecision::ACTIVATION_DISABLED); | 540 ActivationDecision::ACTIVATION_DISABLED); |
| 540 } | 541 } |
| 541 | 542 |
| 542 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { | 543 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { |
| 543 base::FieldTrialList field_trial_list(nullptr); | 544 base::FieldTrialList field_trial_list(nullptr); |
| 544 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 545 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 545 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 546 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 546 kActivationScopeActivationList, | 547 kActivationScopeActivationList, |
| 547 kActivationListSocialEngineeringAdsInterstitial); | 548 kActivationListSocialEngineeringAdsInterstitial); |
| 548 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 549 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 549 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 550 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 550 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); |
| 551 } | 551 } |
| 552 | 552 |
| 553 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 553 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 554 SpecialCaseNavigationAllSitesEnabled) { | 554 SpecialCaseNavigationAllSitesEnabled) { |
| 555 // Check that when the experiment is enabled for all site, the activation | 555 // Check that when the experiment is enabled for all site, the activation |
| 556 // signal is always sent. | 556 // signal is always sent. |
| 557 base::FieldTrialList field_trial_list(nullptr); | 557 base::FieldTrialList field_trial_list(nullptr); |
| 558 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 558 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 559 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 559 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 560 kActivationScopeAllSites); | 560 kActivationScopeAllSites); |
| 561 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 562 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); | 561 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); |
| 563 } | 562 } |
| 564 | 563 |
| 565 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 564 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 566 SpecialCaseNavigationActivationListEnabled) { | 565 SpecialCaseNavigationActivationListEnabled) { |
| 567 base::FieldTrialList field_trial_list(nullptr); | 566 base::FieldTrialList field_trial_list(nullptr); |
| 568 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 567 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 569 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 568 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 570 kActivationScopeActivationList, | 569 kActivationScopeActivationList, |
| 571 kActivationListSocialEngineeringAdsInterstitial); | 570 kActivationListSocialEngineeringAdsInterstitial); |
| 572 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 573 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 571 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| 574 ActivationDecision::ACTIVATED); | 572 ActivationDecision::ACTIVATED); |
| 575 } | 573 } |
| 576 | 574 |
| 577 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 575 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 578 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { | 576 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { |
| 579 base::FieldTrialList field_trial_list(nullptr); | 577 base::FieldTrialList field_trial_list(nullptr); |
| 580 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 578 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 581 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 579 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 582 kActivationScopeActivationList, | 580 kActivationScopeActivationList, |
| 583 kActivationListSocialEngineeringAdsInterstitial, | 581 kActivationListSocialEngineeringAdsInterstitial, |
| 584 "1" /* performance_measurement_rate */); | 582 "1" /* performance_measurement_rate */); |
| 585 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 586 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 583 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, |
| 587 ActivationDecision::ACTIVATED); | 584 ActivationDecision::ACTIVATED); |
| 588 } | 585 } |
| 589 | 586 |
| 590 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { | 587 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { |
| 591 base::FieldTrialList field_trial_list(nullptr); | 588 base::FieldTrialList field_trial_list(nullptr); |
| 592 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 589 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 593 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 590 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 594 kActivationScopeAllSites); | 591 kActivationScopeAllSites); |
| 595 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 596 const GURL url(kExampleUrl); | 592 const GURL url(kExampleUrl); |
| 597 NavigateAndExpectActivation({false}, {url}, EMPTY, | 593 NavigateAndExpectActivation({false}, {url}, EMPTY, |
| 598 ActivationDecision::ACTIVATED); | 594 ActivationDecision::ACTIVATED); |
| 599 EmulateFailedNavigationAndExpectNoActivation(url); | 595 EmulateFailedNavigationAndExpectNoActivation(url); |
| 600 } | 596 } |
| 601 | 597 |
| 602 // 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 |
| 603 // activation list to be matching. | 599 // activation list to be matching. |
| 604 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { | 600 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { |
| 605 base::FieldTrialList field_trial_list(nullptr); | 601 base::FieldTrialList field_trial_list(nullptr); |
| 606 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 602 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 607 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 603 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 608 kActivationScopeActivationList, | 604 kActivationScopeActivationList, |
| 609 kActivationListSocialEngineeringAdsInterstitial); | 605 kActivationListSocialEngineeringAdsInterstitial); |
| 610 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 611 struct RedirectRedirectChainMatchPatternTestData { | 606 struct RedirectRedirectChainMatchPatternTestData { |
| 612 std::vector<bool> blacklisted_urls; | 607 std::vector<bool> blacklisted_urls; |
| 613 std::vector<GURL> navigation_chain; | 608 std::vector<GURL> navigation_chain; |
| 614 RedirectChainMatchPattern hit_expected_pattern; | 609 RedirectChainMatchPattern hit_expected_pattern; |
| 615 ActivationDecision expected_activation_decision; | 610 ActivationDecision expected_activation_decision; |
| 616 } kRedirectRedirectChainMatchPatternTestData[] = { | 611 } kRedirectRedirectChainMatchPatternTestData[] = { |
| 617 {{false}, | 612 {{false}, |
| 618 {GURL(kUrlA)}, | 613 {GURL(kUrlA)}, |
| 619 EMPTY, | 614 EMPTY, |
| 620 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, | 615 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); | 689 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); |
| 695 #endif | 690 #endif |
| 696 } | 691 } |
| 697 } | 692 } |
| 698 | 693 |
| 699 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { | 694 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { |
| 700 base::FieldTrialList field_trial_list(nullptr); | 695 base::FieldTrialList field_trial_list(nullptr); |
| 701 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 696 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 702 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 697 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 703 kActivationScopeAllSites); | 698 kActivationScopeAllSites); |
| 704 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 705 | |
| 706 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 699 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 707 ActivationDecision::ACTIVATED); | 700 ActivationDecision::ACTIVATED); |
| 708 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); | 701 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); |
| 709 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 702 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
| 710 true /* expect_cancelled */); | 703 true /* expect_cancelled */); |
| 711 } | 704 } |
| 712 | 705 |
| 713 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 706 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 714 SuppressNotificationVisibility) { | 707 SuppressNotificationVisibility) { |
| 715 base::FieldTrialList field_trial_list(nullptr); | 708 base::FieldTrialList field_trial_list(nullptr); |
| 716 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 709 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 717 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 710 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 718 kActivationScopeAllSites, "" /* activation_lists */, | 711 kActivationScopeAllSites, "" /* activation_lists */, |
| 719 "" /* performance_measurement_rate */, | 712 "" /* performance_measurement_rate */, |
| 720 "true" /* suppress_notifications */); | 713 "true" /* suppress_notifications */); |
| 721 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 722 | |
| 723 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 714 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, |
| 724 ActivationDecision::ACTIVATED); | 715 ActivationDecision::ACTIVATED); |
| 725 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); | 716 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
| 726 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 717 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
| 727 true /* expect_cancelled */); | 718 true /* expect_cancelled */); |
| 728 } | 719 } |
| 729 | 720 |
| 730 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 721 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
| 731 InactiveMainFrame_SubframeNotFiltered) { | 722 InactiveMainFrame_SubframeNotFiltered) { |
| 732 GURL url(kExampleUrl); | 723 GURL url(kExampleUrl); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 754 SCOPED_TRACE(::testing::Message("referrer = \"") | 745 SCOPED_TRACE(::testing::Message("referrer = \"") |
| 755 << test_case.referrer.url << "\"" | 746 << test_case.referrer.url << "\"" |
| 756 << " transition = \"" << test_case.transition << "\""); | 747 << " transition = \"" << test_case.transition << "\""); |
| 757 | 748 |
| 758 base::FieldTrialList field_trial_list(nullptr); | 749 base::FieldTrialList field_trial_list(nullptr); |
| 759 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 750 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 760 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 751 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 761 kActivationScopeAllSites, "" /* activation_lists */, | 752 kActivationScopeAllSites, "" /* activation_lists */, |
| 762 "" /* performance_measurement_rate */, "" /* suppress_notifications */, | 753 "" /* performance_measurement_rate */, "" /* suppress_notifications */, |
| 763 "true" /* whitelist_site_on_reload */); | 754 "true" /* whitelist_site_on_reload */); |
| 764 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 765 | 755 |
| 766 NavigateAndExpectActivation( | 756 NavigateAndExpectActivation( |
| 767 {false}, {GURL(kExampleUrl)}, | 757 {false}, {GURL(kExampleUrl)}, |
| 768 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 758 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 769 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 759 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
| 770 test_case.referrer, test_case.transition, EMPTY, | 760 test_case.referrer, test_case.transition, EMPTY, |
| 771 test_case.expected_activation_decision); | 761 test_case.expected_activation_decision); |
| 772 // Verify that if the first URL failed to activate, subsequent same-origin | 762 // Verify that if the first URL failed to activate, subsequent same-origin |
| 773 // navigations also fail to activate. | 763 // navigations also fail to activate. |
| 774 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, | 764 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, |
| 775 test_case.expected_activation_decision); | 765 test_case.expected_activation_decision); |
| 776 } | 766 } |
| 777 } | 767 } |
| 778 | 768 |
| 779 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, | 769 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| 780 ActivateForFrameState) { | 770 ActivateForFrameState) { |
| 781 const ActivationLevelTestData& test_data = GetParam(); | 771 const ActivationLevelTestData& test_data = GetParam(); |
| 782 base::FieldTrialList field_trial_list(nullptr); | 772 base::FieldTrialList field_trial_list(nullptr); |
| 783 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 773 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 784 base::FeatureList::OVERRIDE_ENABLE_FEATURE, test_data.activation_level, | 774 base::FeatureList::OVERRIDE_ENABLE_FEATURE, test_data.activation_level, |
| 785 kActivationScopeActivationList, | 775 kActivationScopeActivationList, |
| 786 kActivationListSocialEngineeringAdsInterstitial); | 776 kActivationListSocialEngineeringAdsInterstitial); |
| 787 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 788 | 777 |
| 789 const GURL url(kExampleUrlWithParams); | 778 const GURL url(kExampleUrlWithParams); |
| 790 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 779 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, |
| 791 test_data.expected_activation_decision); | 780 test_data.expected_activation_decision); |
| 792 factory()->client()->WhitelistInCurrentWebContents(url); | 781 factory()->client()->WhitelistInCurrentWebContents(url); |
| 793 NavigateAndExpectActivation( | 782 NavigateAndExpectActivation( |
| 794 {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, | 783 {true}, {GURL(kExampleUrlWithParams)}, NO_REDIRECTS_HIT, |
| 795 GetActiveConfiguration().activation_level == ActivationLevel::DISABLED | 784 GetActiveConfigurations()->the_one_and_only().activation_level == |
| 785 ActivationLevel::DISABLED |
| 796 ? ActivationDecision::ACTIVATION_DISABLED | 786 ? ActivationDecision::ACTIVATION_DISABLED |
| 797 : ActivationDecision::URL_WHITELISTED); | 787 : ActivationDecision::URL_WHITELISTED); |
| 798 } | 788 } |
| 799 | 789 |
| 800 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, | 790 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| 801 ActivateForTheListType) { | 791 ActivateForTheListType) { |
| 802 // Sets up the experiment in a way that the activation decision depends on the | 792 // Sets up the experiment in a way that the activation decision depends on the |
| 803 // list for which the Safe Browsing hit has happened. | 793 // list for which the Safe Browsing hit has happened. |
| 804 const ActivationListTestData& test_data = GetParam(); | 794 const ActivationListTestData& test_data = GetParam(); |
| 805 base::FieldTrialList field_trial_list(nullptr); | 795 base::FieldTrialList field_trial_list(nullptr); |
| 806 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 796 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 807 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 797 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 808 kActivationScopeActivationList, test_data.activation_list); | 798 kActivationScopeActivationList, test_data.activation_list); |
| 809 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 810 | 799 |
| 811 const GURL test_url("https://example.com/nonsoceng?q=engsocnon"); | 800 const GURL test_url("https://example.com/nonsoceng?q=engsocnon"); |
| 812 std::vector<GURL> navigation_chain; | 801 std::vector<GURL> navigation_chain; |
| 813 | 802 |
| 814 ActivationList effective_list = GetListForThreatTypeAndMetadata( | 803 ActivationList effective_list = GetListForThreatTypeAndMetadata( |
| 815 test_data.threat_type, test_data.threat_type_metadata); | 804 test_data.threat_type, test_data.threat_type_metadata); |
| 816 NavigateAndExpectActivation( | 805 NavigateAndExpectActivation( |
| 817 {false, false, false, true}, | 806 {false, false, false, true}, |
| 818 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), test_url}, test_data.threat_type, | 807 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), test_url}, test_data.threat_type, |
| 819 test_data.threat_type_metadata, content::Referrer(), | 808 test_data.threat_type_metadata, content::Referrer(), |
| 820 ui::PAGE_TRANSITION_LINK, | 809 ui::PAGE_TRANSITION_LINK, |
| 821 effective_list != ActivationList::NONE ? F0M0L1 : EMPTY, | 810 effective_list != ActivationList::NONE ? F0M0L1 : EMPTY, |
| 822 test_data.expected_activation_decision); | 811 test_data.expected_activation_decision); |
| 823 }; | 812 }; |
| 824 | 813 |
| 825 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 814 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 826 ActivateForScopeType) { | 815 ActivateForScopeType) { |
| 827 const ActivationScopeTestData& test_data = GetParam(); | 816 const ActivationScopeTestData& test_data = GetParam(); |
| 828 base::FieldTrialList field_trial_list(nullptr); | 817 base::FieldTrialList field_trial_list(nullptr); |
| 829 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 818 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 830 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 819 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 831 test_data.activation_scope, | 820 test_data.activation_scope, |
| 832 kActivationListSocialEngineeringAdsInterstitial); | 821 kActivationListSocialEngineeringAdsInterstitial); |
| 833 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 834 | 822 |
| 835 const GURL test_url(kExampleUrlWithParams); | 823 const GURL test_url(kExampleUrlWithParams); |
| 836 | 824 |
| 837 RedirectChainMatchPattern expected_pattern = | 825 RedirectChainMatchPattern expected_pattern = |
| 838 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 826 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
| 839 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 827 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 840 {test_url}, expected_pattern, | 828 {test_url}, expected_pattern, |
| 841 test_data.expected_activation_decision); | 829 test_data.expected_activation_decision); |
| 842 if (test_data.url_matches_activation_list) { | 830 if (test_data.url_matches_activation_list) { |
| 843 factory()->client()->WhitelistInCurrentWebContents(test_url); | 831 factory()->client()->WhitelistInCurrentWebContents(test_url); |
| 844 NavigateAndExpectActivation( | 832 NavigateAndExpectActivation( |
| 845 {test_data.url_matches_activation_list}, {GURL(kExampleUrlWithParams)}, | 833 {test_data.url_matches_activation_list}, {GURL(kExampleUrlWithParams)}, |
| 846 expected_pattern, | 834 expected_pattern, |
| 847 GetActiveConfiguration().activation_scope == ActivationScope::NO_SITES | 835 GetActiveConfigurations()->the_one_and_only().activation_scope == |
| 836 ActivationScope::NO_SITES |
| 848 ? ActivationDecision::ACTIVATION_DISABLED | 837 ? ActivationDecision::ACTIVATION_DISABLED |
| 849 : ActivationDecision::URL_WHITELISTED); | 838 : ActivationDecision::URL_WHITELISTED); |
| 850 } | 839 } |
| 851 }; | 840 }; |
| 852 | 841 |
| 853 // Only main frames with http/https schemes should activate, unless the | 842 // Only main frames with http/https schemes should activate, unless the |
| 854 // activation scope is for all sites. | 843 // activation scope is for all sites. |
| 855 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 844 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 856 ActivateForSupportedUrlScheme) { | 845 ActivateForSupportedUrlScheme) { |
| 857 const ActivationScopeTestData& test_data = GetParam(); | 846 const ActivationScopeTestData& test_data = GetParam(); |
| 858 base::FieldTrialList field_trial_list(nullptr); | 847 base::FieldTrialList field_trial_list(nullptr); |
| 859 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( | 848 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( |
| 860 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 849 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
| 861 test_data.activation_scope, | 850 test_data.activation_scope, |
| 862 kActivationListSocialEngineeringAdsInterstitial); | 851 kActivationListSocialEngineeringAdsInterstitial); |
| 863 factory()->set_configuration_for_testing(GetActiveConfiguration()); | |
| 864 | 852 |
| 865 // data URLs are also not supported, but not listed here, as it's not possible | 853 // data URLs are also not supported, but not listed here, as it's not possible |
| 866 // for a page to redirect to them after https://crbug.com/594215 is fixed. | 854 // for a page to redirect to them after https://crbug.com/594215 is fixed. |
| 867 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", | 855 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", |
| 868 "chrome-extension://some-extension", | 856 "chrome-extension://some-extension", |
| 869 "file:///var/www/index.html"}; | 857 "file:///var/www/index.html"}; |
| 870 const char* supported_urls[] = {"http://example.test", | 858 const char* supported_urls[] = {"http://example.test", |
| 871 "https://example.test"}; | 859 "https://example.test"}; |
| 872 for (auto* url : unsupported_urls) { | 860 for (auto* url : unsupported_urls) { |
| 873 SCOPED_TRACE(url); | 861 SCOPED_TRACE(url); |
| 874 RedirectChainMatchPattern expected_pattern = EMPTY; | 862 RedirectChainMatchPattern expected_pattern = EMPTY; |
| 875 NavigateAndExpectActivation( | 863 NavigateAndExpectActivation( |
| 876 {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, | 864 {test_data.url_matches_activation_list}, {GURL(url)}, expected_pattern, |
| 877 GetActiveConfiguration().activation_scope == ActivationScope::NO_SITES | 865 GetActiveConfigurations()->the_one_and_only().activation_scope == |
| 866 ActivationScope::NO_SITES |
| 878 ? ActivationDecision::ACTIVATION_DISABLED | 867 ? ActivationDecision::ACTIVATION_DISABLED |
| 879 : ActivationDecision::UNSUPPORTED_SCHEME); | 868 : ActivationDecision::UNSUPPORTED_SCHEME); |
| 880 } | 869 } |
| 881 for (auto* url : supported_urls) { | 870 for (auto* url : supported_urls) { |
| 882 SCOPED_TRACE(url); | 871 SCOPED_TRACE(url); |
| 883 RedirectChainMatchPattern expected_pattern = | 872 RedirectChainMatchPattern expected_pattern = |
| 884 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 873 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; |
| 885 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 874 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
| 886 {GURL(url)}, expected_pattern, | 875 {GURL(url)}, expected_pattern, |
| 887 test_data.expected_activation_decision); | 876 test_data.expected_activation_decision); |
| 888 } | 877 } |
| 889 }; | 878 }; |
| 890 | 879 |
| 891 INSTANTIATE_TEST_CASE_P(NoSocEngHit, | 880 INSTANTIATE_TEST_CASE_P(NoSocEngHit, |
| 892 ContentSubresourceFilterDriverFactoryThreatTypeTest, | 881 ContentSubresourceFilterDriverFactoryThreatTypeTest, |
| 893 ::testing::ValuesIn(kActivationListTestData)); | 882 ::testing::ValuesIn(kActivationListTestData)); |
| 894 | 883 |
| 895 INSTANTIATE_TEST_CASE_P( | 884 INSTANTIATE_TEST_CASE_P( |
| 896 ActivationScopeTest, | 885 ActivationScopeTest, |
| 897 ContentSubresourceFilterDriverFactoryActivationScopeTest, | 886 ContentSubresourceFilterDriverFactoryActivationScopeTest, |
| 898 ::testing::ValuesIn(kActivationScopeTestData)); | 887 ::testing::ValuesIn(kActivationScopeTestData)); |
| 899 | 888 |
| 900 INSTANTIATE_TEST_CASE_P( | 889 INSTANTIATE_TEST_CASE_P( |
| 901 ActivationLevelTest, | 890 ActivationLevelTest, |
| 902 ContentSubresourceFilterDriverFactoryActivationLevelTest, | 891 ContentSubresourceFilterDriverFactoryActivationLevelTest, |
| 903 ::testing::ValuesIn(kActivationLevelTestData)); | 892 ::testing::ValuesIn(kActivationLevelTestData)); |
| 904 | 893 |
| 905 } // namespace subresource_filter | 894 } // namespace subresource_filter |
| OLD | NEW |