| Index: components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| diff --git a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| index 91991880da0f002a19a383ba984cca3503cc7710..0465ae486f4db75450efb53decf71f7339b7b896 100644
|
| --- a/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| +++ b/components/subresource_filter/content/browser/content_subresource_filter_driver_factory_unittest.cc
|
| @@ -5,6 +5,7 @@
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/metrics/field_trial.h"
|
| +#include "base/test/histogram_tester.h"
|
| #include "components/safe_browsing_db/util.h"
|
| #include "components/subresource_filter/content/browser/content_subresource_filter_driver.h"
|
| #include "components/subresource_filter/content/browser/content_subresource_filter_driver_factory.h"
|
| @@ -12,21 +13,48 @@
|
| #include "components/subresource_filter/core/browser/subresource_filter_features.h"
|
| #include "components/subresource_filter/core/browser/subresource_filter_features_test_support.h"
|
| #include "content/public/browser/web_contents.h"
|
| +#include "content/public/common/browser_side_navigation_policy.h"
|
| #include "content/public/test/test_renderer_host.h"
|
| #include "content/public/test/web_contents_tester.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "url/gurl.h"
|
|
|
| +namespace subresource_filter {
|
| +
|
| namespace {
|
|
|
| const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc";
|
| -const char kTestUrl[] = "https://test.com";
|
| const char kExampleUrl[] = "https://example.com";
|
| const char kExampleLoginUrl[] = "https://example.com/login";
|
| +const char kMatchesPatternHistogramName[] =
|
| + "SubresourceFilter.PageLoad.RedirectChainMatchPattern";
|
| +const char kNavigationChainSize[] =
|
| + "SubresourceFilter.PageLoad.RedirectChainLength";
|
| +const char kUrlA[] = "https://example_a.com";
|
| +const char kUrlB[] = "https://example_b.com";
|
| +const char kUrlC[] = "https://example_c.com";
|
| +const char kUrlD[] = "https://example_d.com";
|
| +
|
| +// Human readable representation of expected redirect chain match patterns.
|
| +// The explanations for the buckets given for the following redirect chain:
|
| +// A->B->C->D, where A is initial URL and D is a final URL.
|
| +enum RedirectChainMatchPattern {
|
| + EMPTY, // No histograms were recorded.
|
| + F0M0L1, // D is a Safe Browsing match.
|
| + F0M1L0, // B or C, or both are Safe Browsing matches.
|
| + F0M1L1, // B or C, or both and D are Safe Browsing matches.
|
| + F1M0L0, // A is Safe Browsing match
|
| + F1M0L1, // A and D are Safe Browsing matches.
|
| + F1M1L0, // B and/or C and A are Safe Browsing matches.
|
| + F1M1L1, // B and/or C and A and D are Safe Browsing matches.
|
| + NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects
|
| + // has happened, and this URL was a Safe Browsing hit.
|
| + NUM_HIT_PATTERNS,
|
| +};
|
|
|
| struct ActivationListTestData {
|
| - bool should_add;
|
| + bool expected_activation;
|
| const char* const activation_list;
|
| safe_browsing::SBThreatType threat_type;
|
| safe_browsing::ThreatPatternType threat_type_metadata;
|
| @@ -44,9 +72,6 @@ const ActivationListTestData kActivationListTestData[] = {
|
| {false, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
|
| safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
|
| safe_browsing::ThreatPatternType::MALWARE_DISTRIBUTION},
|
| - {true, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
|
| - safe_browsing::SB_THREAT_TYPE_URL_MALWARE,
|
| - safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
|
| {false, subresource_filter::kActivationListPhishingInterstitial,
|
| safe_browsing::SB_THREAT_TYPE_API_ABUSE,
|
| safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
|
| @@ -74,11 +99,40 @@ const ActivationListTestData kActivationListTestData[] = {
|
| {true, subresource_filter::kActivationListPhishingInterstitial,
|
| safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
|
| safe_browsing::ThreatPatternType::NONE},
|
| + {true, subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
|
| + safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
|
| + safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
|
| };
|
|
|
| -} // namespace
|
| +struct ActivationScopeTestData {
|
| + bool expected_activation;
|
| + bool url_matches_activation_list;
|
| + const char* const activation_scope;
|
| +};
|
|
|
| -namespace subresource_filter {
|
| +const ActivationScopeTestData kActivationScopeTestData[] = {
|
| + {true /* expected_activation */, false /* url_matches_activation_list */,
|
| + kActivationScopeAllSites},
|
| + {true /* expected_activation */, true /* url_matches_activation_list */,
|
| + kActivationScopeAllSites},
|
| + {false /* expected_activation */, true /* url_matches_activation_list */,
|
| + kActivationScopeNoSites},
|
| + {true /* expected_activation */, true /* url_matches_activation_list */,
|
| + kActivationScopeActivationList},
|
| + {false /* expected_activation */, false /* url_matches_activation_list */,
|
| + kActivationScopeActivationList},
|
| +};
|
| +
|
| +struct ActivationStateTestData {
|
| + bool expected_activation;
|
| + const char* const activation_state;
|
| +};
|
| +
|
| +const ActivationStateTestData kActivationStateTestData[] = {
|
| + {true /* expected_activation */, kActivationStateDryRun},
|
| + {true /* expected_activation */, kActivationStateEnabled},
|
| + {false /* expected_activation */, kActivationStateDisabled},
|
| +};
|
|
|
| class MockSubresourceFilterDriver : public ContentSubresourceFilterDriver {
|
| public:
|
| @@ -106,6 +160,8 @@ class MockSubresourceFilterClient : public SubresourceFilterClient {
|
| DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient);
|
| };
|
|
|
| +} // namespace
|
| +
|
| class ContentSubresourceFilterDriverFactoryTest
|
| : public content::RenderViewHostTestHarness {
|
| public:
|
| @@ -149,37 +205,63 @@ class ContentSubresourceFilterDriverFactoryTest
|
| content::RenderFrameHost* subframe_rfh() { return subframe_rfh_; }
|
|
|
| void BlacklistURLWithRedirectsNavigateAndCommit(
|
| - const GURL& bad_url,
|
| - const std::vector<GURL>& redirects,
|
| - const GURL& url,
|
| - bool should_activate) {
|
| + const std::vector<bool>& blacklisted_urls,
|
| + const std::vector<GURL>& navigation_chain,
|
| + safe_browsing::SBThreatType threat_type,
|
| + safe_browsing::ThreatPatternType threat_type_metadata,
|
| + RedirectChainMatchPattern extected_pattern,
|
| + bool expected_activation) {
|
| + base::HistogramTester tester;
|
| EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1);
|
| - content::WebContentsTester::For(web_contents())->StartNavigation(url);
|
| + content::RenderFrameHostTester* rfh_tester =
|
| + content::RenderFrameHostTester::For(main_rfh());
|
| +
|
| + rfh_tester->SimulateNavigationStart(navigation_chain.front());
|
| + if (blacklisted_urls.front()) {
|
| + factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
|
| + navigation_chain.front(), navigation_chain, threat_type,
|
| + threat_type_metadata);
|
| + }
|
| ::testing::Mock::VerifyAndClearExpectations(client());
|
| - factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
|
| - bad_url, redirects, safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
|
| - safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS);
|
|
|
| - ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), url,
|
| - should_activate);
|
| - content::RenderFrameHostTester::For(main_rfh())
|
| - ->SimulateNavigationCommit(url);
|
| - }
|
| + for (size_t i = 1; i < navigation_chain.size(); ++i) {
|
| + const GURL url = navigation_chain[i];
|
| + if (i < blacklisted_urls.size() && blacklisted_urls[i]) {
|
| + factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
|
| + url, navigation_chain, threat_type, threat_type_metadata);
|
| + }
|
| + rfh_tester->SimulateRedirect(url);
|
| + }
|
| + EXPECT_CALL(*driver(),
|
| + ActivateForProvisionalLoad(::testing::_, ::testing::_))
|
| + .Times(expected_activation);
|
| + if (!content::IsBrowserSideNavigationEnabled()) {
|
| + factory()->ReadyToCommitNavigationInternal(main_rfh(),
|
| + navigation_chain.back());
|
| + }
|
|
|
| - void ActivateAndExpectForFrameHostForUrl(MockSubresourceFilterDriver* driver,
|
| - content::RenderFrameHost* rfh,
|
| - const GURL& url,
|
| - bool should_activate) {
|
| - EXPECT_CALL(*driver, ActivateForProvisionalLoad(::testing::_, ::testing::_))
|
| - .Times(should_activate);
|
| - factory()->ReadyToCommitNavigationInternal(rfh, url);
|
| - ::testing::Mock::VerifyAndClearExpectations(driver);
|
| + rfh_tester->SimulateNavigationCommit(navigation_chain.back());
|
| + ::testing::Mock::VerifyAndClearExpectations(driver());
|
| +
|
| + if (extected_pattern != EMPTY) {
|
| + EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName),
|
| + ::testing::ElementsAre(base::Bucket(extected_pattern, 1)));
|
| + EXPECT_THAT(
|
| + tester.GetAllSamples(kNavigationChainSize),
|
| + ::testing::ElementsAre(base::Bucket(navigation_chain.size(), 1)));
|
| +
|
| + } else {
|
| + EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName),
|
| + ::testing::IsEmpty());
|
| + EXPECT_THAT(tester.GetAllSamples(kNavigationChainSize),
|
| + ::testing::IsEmpty());
|
| + }
|
| }
|
|
|
| - void NavigateAndCommitSubframe(const GURL& url, bool should_activate) {
|
| + void NavigateAndCommitSubframe(const GURL& url, bool expected_activation) {
|
| EXPECT_CALL(*subframe_driver(),
|
| ActivateForProvisionalLoad(::testing::_, ::testing::_))
|
| - .Times(should_activate);
|
| + .Times(expected_activation);
|
| EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0);
|
|
|
| factory()->ReadyToCommitNavigationInternal(subframe_rfh(), url);
|
| @@ -187,30 +269,44 @@ class ContentSubresourceFilterDriverFactoryTest
|
| ::testing::Mock::VerifyAndClearExpectations(client());
|
| }
|
|
|
| - void BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - const GURL& bad_url,
|
| - const std::vector<GURL>& redirects,
|
| - const GURL& url,
|
| - bool should_activate) {
|
| - BlacklistURLWithRedirectsNavigateAndCommit(bad_url, redirects, url,
|
| - should_activate);
|
| + void NavigateAndExpectActivation(
|
| + const std::vector<bool>& blacklisted_urls,
|
| + const std::vector<GURL>& navigation_chain,
|
| + safe_browsing::SBThreatType threat_type,
|
| + safe_browsing::ThreatPatternType threat_type_metadata,
|
| + RedirectChainMatchPattern extected_pattern,
|
| + bool expected_activation) {
|
| + BlacklistURLWithRedirectsNavigateAndCommit(
|
| + blacklisted_urls, navigation_chain, threat_type, threat_type_metadata,
|
| + extected_pattern, expected_activation);
|
| +
|
| + NavigateAndCommitSubframe(GURL(kExampleLoginUrl), expected_activation);
|
| + }
|
|
|
| - NavigateAndCommitSubframe(GURL(kExampleLoginUrl), should_activate);
|
| + void NavigateAndExpectActivation(const std::vector<bool>& blacklisted_urls,
|
| + const std::vector<GURL>& navigation_chain,
|
| + RedirectChainMatchPattern extected_pattern,
|
| + bool expected_activation) {
|
| + NavigateAndExpectActivation(
|
| + blacklisted_urls, navigation_chain,
|
| + safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
|
| + safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS,
|
| + extected_pattern, expected_activation);
|
| }
|
|
|
| - void SpecialCaseNavSeq(const GURL& bad_url,
|
| - const std::vector<GURL>& redirects,
|
| - bool should_activate) {
|
| + void EmulateInPageNavigation(const std::vector<bool>& blacklisted_urls,
|
| + RedirectChainMatchPattern extected_pattern,
|
| + bool expected_activation) {
|
| // This test-case examinse the nevigation woth following sequence of event:
|
| // DidStartProvisional(main, "example.com")
|
| - // ReadyToCommitMainFrameNavigation(“example.com”)
|
| + // ReadyToCommitNavigation(“example.com”)
|
| // DidCommitProvisional(main, "example.com")
|
| // DidStartProvisional(sub, "example.com/login")
|
| // DidCommitProvisional(sub, "example.com/login")
|
| // DidCommitProvisional(main, "example.com#ref")
|
|
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - bad_url, redirects, GURL(kExampleUrl), should_activate);
|
| + NavigateAndExpectActivation(blacklisted_urls, {GURL(kExampleUrl)},
|
| + extected_pattern, expected_activation);
|
| EXPECT_CALL(*driver(),
|
| ActivateForProvisionalLoad(::testing::_, ::testing::_))
|
| .Times(0);
|
| @@ -243,197 +339,224 @@ class ContentSubresourceFilterDriverFactoryThreatTypeTest
|
| DISALLOW_COPY_AND_ASSIGN(ContentSubresourceFilterDriverFactoryThreatTypeTest);
|
| };
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - ActivateForFrameHostNotNeeded) {
|
| - base::FieldTrialList field_trial_list(nullptr);
|
| - testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_DISABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
|
| - ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), GURL(kTestUrl),
|
| - false /* should_activate */);
|
| - const GURL url(kExampleUrlWithParams);
|
| - BlacklistURLWithRedirectsNavigateAndCommit(url, std::vector<GURL>(), url,
|
| - false /* should_activate */);
|
| - BlacklistURLWithRedirectsNavigateAndCommit(url, std::vector<GURL>(),
|
| - GURL("https://not-example.com"),
|
| - false /* should_activate */);
|
| -}
|
| -
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest, ActivateForFrameHostNeeded) {
|
| - base::FieldTrialList field_trial_list(nullptr);
|
| - testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeActivationList,
|
| - kActivationListSocialEngineeringAdsInterstitial);
|
| -
|
| - const GURL url(kExampleUrlWithParams);
|
| - BlacklistURLWithRedirectsNavigateAndCommit(url, std::vector<GURL>(), url,
|
| - true /* should_activate */);
|
| - BlacklistURLWithRedirectsNavigateAndCommit(
|
| - url, std::vector<GURL>(), GURL(kExampleUrl), false /* should_activate */);
|
| -}
|
| -
|
| -TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, NonSocEngHit) {
|
| - const ActivationListTestData& test_data = GetParam();
|
| - base::FieldTrialList field_trial_list(nullptr);
|
| - testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeNoSites, test_data.activation_list);
|
| +class ContentSubresourceFilterDriverFactoryActivationScopeTest
|
| + : public ContentSubresourceFilterDriverFactoryTest,
|
| + public ::testing::WithParamInterface<ActivationScopeTestData> {
|
| + public:
|
| + ContentSubresourceFilterDriverFactoryActivationScopeTest() {}
|
| + ~ContentSubresourceFilterDriverFactoryActivationScopeTest() override {}
|
|
|
| - std::vector<GURL> redirects;
|
| - redirects.push_back(GURL("https://example1.com"));
|
| - redirects.push_back(GURL("https://example2.com"));
|
| - redirects.push_back(GURL("https://example3.com"));
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(
|
| + ContentSubresourceFilterDriverFactoryActivationScopeTest);
|
| +};
|
|
|
| - const GURL test_url("https://example.com/nonsoceng?q=engsocnon");
|
| +class ContentSubresourceFilterDriverFactoryActivationStateTest
|
| + : public ContentSubresourceFilterDriverFactoryTest,
|
| + public ::testing::WithParamInterface<ActivationStateTestData> {
|
| + public:
|
| + ContentSubresourceFilterDriverFactoryActivationStateTest() {}
|
| + ~ContentSubresourceFilterDriverFactoryActivationStateTest() override {}
|
|
|
| - BlacklistURLWithRedirectsNavigateAndCommit(GURL::EmptyGURL(),
|
| - std::vector<GURL>(), test_url,
|
| - false /* should_activate */);
|
| - EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1);
|
| - content::WebContentsTester::For(web_contents())->StartNavigation(test_url);
|
| - ::testing::Mock::VerifyAndClearExpectations(client());
|
| - factory()->OnMainResourceMatchedSafeBrowsingBlacklist(
|
| - test_url, redirects, test_data.threat_type,
|
| - test_data.threat_type_metadata);
|
| - ActivateAndExpectForFrameHostForUrl(driver(), main_rfh(), test_url, false);
|
| - content::RenderFrameHostTester::For(main_rfh())
|
| - ->SimulateNavigationCommit(test_url);
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(
|
| + ContentSubresourceFilterDriverFactoryActivationStateTest);
|
| };
|
|
|
| TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - ActivationPromptNotShownForNonMainFrames) {
|
| + ActivateForFrameHostDisabledFeature) {
|
| + // Activation scope is set to NONE => no activation should happen even if URL
|
| + // which is visited was a SB hit.
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeActivationList,
|
| - kActivationListSocialEngineeringAdsInterstitial);
|
| - BlacklistURLWithRedirectsNavigateAndCommit(
|
| - GURL::EmptyGURL(), std::vector<GURL>(), GURL(kExampleUrl),
|
| - false /* should_prompt */);
|
| -}
|
| -
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - DidStartProvisionalLoadScopeAllSitesStateDryRun) {
|
| - base::FieldTrialList field_trial_list(nullptr);
|
| - testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun,
|
| + base::FeatureList::OVERRIDE_DISABLE_FEATURE, kActivationStateEnabled,
|
| kActivationScopeAllSites,
|
| kActivationListSocialEngineeringAdsInterstitial);
|
| const GURL url(kExampleUrlWithParams);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), url, true /* should_activate */);
|
| + NavigateAndExpectActivation({true}, {url}, EMPTY,
|
| + false /* expected_activation */);
|
| factory()->AddHostOfURLToWhitelistSet(url);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), GURL(kExampleUrlWithParams),
|
| - false /* should_activate */);
|
| + NavigateAndExpectActivation({true}, {url}, EMPTY,
|
| + false /* expected_activation */);
|
| }
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - DidStartProvisionalLoadScopeAllSitesStateEnabled) {
|
| +TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) {
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeAllSites,
|
| + kActivationScopeActivationList,
|
| kActivationListSocialEngineeringAdsInterstitial);
|
| - const GURL url(kExampleUrlWithParams);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), url, true /* should_activate */);
|
| - factory()->AddHostOfURLToWhitelistSet(url);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), GURL(kExampleUrlWithParams),
|
| - false /* should_activate */);
|
| + NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY,
|
| + false /* should_prompt */);
|
| }
|
|
|
| TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - DidStartProvisionalLoadScopeActivationListSitesStateEnabled) {
|
| + SpecialCaseNavigationAllSitesEnabled) {
|
| + // Check that when the experiment is enabled for all site, the activation
|
| + // signal is always sent.
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeActivationList,
|
| - kActivationListSocialEngineeringAdsInterstitial);
|
| - const GURL url(kExampleUrlWithParams);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), url, true /* should_activate */);
|
| - factory()->AddHostOfURLToWhitelistSet(url);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), GURL(kExampleUrlWithParams),
|
| - false /* should_activate */);
|
| + kActivationScopeAllSites);
|
| + EmulateInPageNavigation({false}, EMPTY, true /* expected_activation */);
|
| }
|
|
|
| TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - DidStartProvisionalLoadScopeActivationListSitesStateDryRun) {
|
| + SpecialCaseNavigationActivationListEnabled) {
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun,
|
| + base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| kActivationScopeActivationList,
|
| kActivationListSocialEngineeringAdsInterstitial);
|
| - const GURL url(kExampleUrlWithParams);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), url, true /* should_activate */);
|
| - factory()->AddHostOfURLToWhitelistSet(url);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - url, std::vector<GURL>(), url, false /* should_activate */);
|
| + EmulateInPageNavigation({true}, NO_REDIRECTS_HIT,
|
| + true /* expected_activation */);
|
| }
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - DidStartProvisionalLoadScopeNoSites) {
|
| +TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) {
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun,
|
| - kActivationScopeNoSites, kActivationListSocialEngineeringAdsInterstitial);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - GURL::EmptyGURL(), std::vector<GURL>(), GURL(kExampleUrlWithParams),
|
| - false /* should_activate */);
|
| + base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| + kActivationScopeActivationList,
|
| + kActivationListSocialEngineeringAdsInterstitial);
|
| + struct RedirectRedirectChainMatchPatternTestData {
|
| + std::vector<bool> blacklisted_urls;
|
| + std::vector<GURL> navigation_chain;
|
| + RedirectChainMatchPattern hit_extected_pattern;
|
| + bool expected_activation;
|
| + } kRedirectRedirectChainMatchPatternTestData[] = {
|
| + {{false}, {GURL(kUrlA)}, EMPTY, false},
|
| + {{true}, {GURL(kUrlA)}, NO_REDIRECTS_HIT, true},
|
| + {{false, false}, {GURL(kUrlA), GURL(kUrlB)}, EMPTY, false},
|
| + {{false, true}, {GURL(kUrlA), GURL(kUrlB)}, F0M0L1, true},
|
| + {{true, false}, {GURL(kUrlA), GURL(kUrlB)}, F1M0L0, false},
|
| + {{true, true}, {GURL(kUrlA), GURL(kUrlB)}, F1M0L1, true},
|
| +
|
| + {{false, false, false},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + EMPTY,
|
| + false},
|
| + {{false, false, true},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F0M0L1,
|
| + true},
|
| + {{false, true, false},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F0M1L0,
|
| + false},
|
| + {{false, true, true},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F0M1L1,
|
| + true},
|
| + {{true, false, false},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F1M0L0,
|
| + false},
|
| + {{true, false, true},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F1M0L1,
|
| + true},
|
| + {{true, true, false},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F1M1L0,
|
| + false},
|
| + {{true, true, true},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
|
| + F1M1L1,
|
| + true},
|
| + {{false, true, false, false},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)},
|
| + F0M1L0,
|
| + false},
|
| + };
|
| +
|
| + for (size_t i = 0U; i < arraysize(kRedirectRedirectChainMatchPatternTestData);
|
| + ++i) {
|
| + auto test_data = kRedirectRedirectChainMatchPatternTestData[i];
|
| + NavigateAndExpectActivation(
|
| + test_data.blacklisted_urls, test_data.navigation_chain,
|
| + safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
|
| + safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS,
|
| + test_data.hit_extected_pattern, test_data.expected_activation);
|
| + NavigateAndExpectActivation({false}, {GURL("https://dummy.com")}, EMPTY,
|
| + false);
|
| + }
|
| }
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - DidStartProvisionalLoadScopeActivationList) {
|
| +TEST_P(ContentSubresourceFilterDriverFactoryActivationStateTest,
|
| + ActivateForFrameState) {
|
| + const ActivationStateTestData& test_data = GetParam();
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDisabled,
|
| + base::FeatureList::OVERRIDE_ENABLE_FEATURE, test_data.activation_state,
|
| kActivationScopeActivationList,
|
| kActivationListSocialEngineeringAdsInterstitial);
|
| - BlacklistURLWithRedirectsNavigateMainFrameAndSubrame(
|
| - GURL::EmptyGURL(), std::vector<GURL>(), GURL(kExampleUrlWithParams),
|
| - false /* should_activate */);
|
| -}
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - SpecialCaseNavigationAllSitesDryRun) {
|
| - base::FieldTrialList field_trial_list(nullptr);
|
| - testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| - base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateDryRun,
|
| - kActivationScopeAllSites);
|
| - SpecialCaseNavSeq(GURL::EmptyGURL(), std::vector<GURL>(),
|
| - true /* should_activate */);
|
| + const GURL url(kExampleUrlWithParams);
|
| + NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT,
|
| + test_data.expected_activation);
|
| + factory()->AddHostOfURLToWhitelistSet(url);
|
| + NavigateAndExpectActivation({true}, {GURL(kExampleUrlWithParams)},
|
| + NO_REDIRECTS_HIT,
|
| + false /* expected_activation */);
|
| }
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - SpecialCaseNavigationAllSitesEnabled) {
|
| - // Check that when the experiment is enabled for all site, the activation
|
| - // signal is always sent.
|
| +TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest,
|
| + ActivateForTheListType) {
|
| + // Sets up the experiment in a way that the activation decision depends on the
|
| + // list for which the Safe Browsing hit has happened.
|
| + const ActivationListTestData& test_data = GetParam();
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeAllSites);
|
| - SpecialCaseNavSeq(GURL::EmptyGURL(), std::vector<GURL>(),
|
| - true /* should_activate */);
|
| -}
|
| + kActivationScopeActivationList, test_data.activation_list);
|
|
|
| -TEST_F(ContentSubresourceFilterDriverFactoryTest,
|
| - SpecialCaseNavigationActivationListEnabled) {
|
| + const GURL test_url("https://example.com/nonsoceng?q=engsocnon");
|
| + std::vector<GURL> navigation_chain;
|
| +
|
| + NavigateAndExpectActivation({false, false, false, true},
|
| + {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), test_url},
|
| + test_data.threat_type,
|
| + test_data.threat_type_metadata,
|
| + test_data.expected_activation ? F0M0L1 : EMPTY,
|
| + test_data.expected_activation);
|
| +};
|
| +
|
| +TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest,
|
| + ActivateForScopeType) {
|
| + const ActivationScopeTestData& test_data = GetParam();
|
| base::FieldTrialList field_trial_list(nullptr);
|
| testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
|
| base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationStateEnabled,
|
| - kActivationScopeActivationList,
|
| + test_data.activation_scope,
|
| kActivationListSocialEngineeringAdsInterstitial);
|
| - SpecialCaseNavSeq(GURL(kExampleUrl), std::vector<GURL>(),
|
| - true /* should_activate */);
|
| -}
|
|
|
| -INSTANTIATE_TEST_CASE_P(NoSonEngHit,
|
| + const GURL test_url(kExampleUrlWithParams);
|
| +
|
| + RedirectChainMatchPattern extected_pattern =
|
| + test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY;
|
| + NavigateAndExpectActivation({test_data.url_matches_activation_list},
|
| + {test_url}, extected_pattern,
|
| + test_data.expected_activation);
|
| + if (test_data.url_matches_activation_list) {
|
| + factory()->AddHostOfURLToWhitelistSet(test_url);
|
| + NavigateAndExpectActivation({test_data.url_matches_activation_list},
|
| + {GURL(kExampleUrlWithParams)}, extected_pattern,
|
| + false /* expected_activation */);
|
| + }
|
| +};
|
| +
|
| +INSTANTIATE_TEST_CASE_P(NoSocEngHit,
|
| ContentSubresourceFilterDriverFactoryThreatTypeTest,
|
| ::testing::ValuesIn(kActivationListTestData));
|
|
|
| +INSTANTIATE_TEST_CASE_P(
|
| + ActivationScopeTest,
|
| + ContentSubresourceFilterDriverFactoryActivationScopeTest,
|
| + ::testing::ValuesIn(kActivationScopeTestData));
|
| +
|
| +INSTANTIATE_TEST_CASE_P(
|
| + ActivationStateTest,
|
| + ContentSubresourceFilterDriverFactoryActivationStateTest,
|
| + ::testing::ValuesIn(kActivationStateTestData));
|
| +
|
| } // namespace subresource_filter
|
|
|