Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(987)

Side by Side Diff: components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698