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