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

Unified Diff: components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc

Issue 2814733002: Add the SocEng as a type for checking in CheckUrlForSubresourceFilter. (Closed)
Patch Set: remove tests which are not neede anymore 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 side-by-side diff with in-line comments
Download patch
Index: components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc
diff --git a/components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc
index 0a49f61053ca70ba71e791330bd52b2510f6674c..6183aa6b0de818b89053a9bba58809e0f9971145 100644
--- a/components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc
+++ b/components/subresource_filter/content/browser/subresource_filter_safe_browsing_activation_throttle_unittest.cc
@@ -31,28 +31,9 @@ char kURL[] = "http://example.test/";
char kRedirectURL[] = "http://foo.test/";
// Names of navigation chain patterns histogram.
-const char kMatchesPatternHistogramNameSubresourceFilterSuffix[] =
- "SubresourceFilter.PageLoad.RedirectChainMatchPattern."
- "SubresourceFilterOnly";
-const char kNavigationChainSizeSubresourceFilterSuffix[] =
- "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly";
-
-// 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,
-};
+const char kMatchesPatternHistogramName[] = "SubresourceFilter.PageLoad.Match.";
+const char kNavigationChainSize[] =
+ "SubresourceFilter.PageLoad.RedirectChainLength.";
// Database manager that allows any URL to be configured as blacklisted for
// testing.
@@ -62,8 +43,9 @@ class FakeSafeBrowsingDatabaseManager
FakeSafeBrowsingDatabaseManager() : simulate_timeout_(false) {}
void AddBlacklistedUrl(const GURL& url,
- safe_browsing::SBThreatType threat_type) {
- url_to_threat_type_[url] = threat_type;
+ safe_browsing::SBThreatType threat_type,
+ safe_browsing::ThreatPatternType pattern_type) {
+ url_to_threat_type_[url] = std::make_pair(threat_type, pattern_type);
}
void SimulateTimeout() { simulate_timeout_ = true; }
@@ -77,11 +59,12 @@ class FakeSafeBrowsingDatabaseManager
if (!url_to_threat_type_.count(url))
return true;
+ safe_browsing::ThreatMetadata metadata;
+ metadata.threat_pattern_type = url_to_threat_type_[url].second;
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client),
- url, url_to_threat_type_[url],
- safe_browsing::ThreatMetadata()));
+ url, url_to_threat_type_[url].first, metadata));
return false;
}
@@ -106,7 +89,10 @@ class FakeSafeBrowsingDatabaseManager
}
private:
- std::map<GURL, safe_browsing::SBThreatType> url_to_threat_type_;
+ std::map<
+ GURL,
+ std::pair<safe_browsing::SBThreatType, safe_browsing::ThreatPatternType>>
+ url_to_threat_type_;
bool simulate_timeout_;
DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager);
@@ -150,11 +136,48 @@ class TestForwardingNavigationThrottle : public content::NavigationThrottle {
DISALLOW_COPY_AND_ASSIGN(TestForwardingNavigationThrottle);
};
+std::string GetSuffixForList(const ActivationList& type) {
+ switch (type) {
+ case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL:
+ return "SocialEngineeringAdsInterstitial";
+ case ActivationList::PHISHING_INTERSTITIAL:
+ return "PhishingInterstital";
+ case ActivationList::SUBRESOURCE_FILTER:
+ return "SubresourceFilterOnly";
+ case ActivationList::NONE:
+ return std::string();
+ }
+ return std::string();
+}
+
+struct ActivationListTestData {
+ const char* const activation_list;
+ ActivationList activation_list_type;
+ safe_browsing::SBThreatType threat_type;
+ safe_browsing::ThreatPatternType threat_type_metadata;
+};
+
+const ActivationListTestData kActivationListTestData[] = {
+ {subresource_filter::kActivationListSocialEngineeringAdsInterstitial,
+ ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL,
+ safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
+ safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS},
+ {subresource_filter::kActivationListPhishingInterstitial,
+ ActivationList::PHISHING_INTERSTITIAL,
+ safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
+ safe_browsing::ThreatPatternType::NONE},
+ {subresource_filter::kActivationListSubresourceFilter,
+ ActivationList::SUBRESOURCE_FILTER,
+ safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER,
+ safe_browsing::ThreatPatternType::NONE},
+};
+
} // namespace
class SubresourceFilterSafeBrowsingActivationThrottleTest
: public content::RenderViewHostTestHarness,
- public content::WebContentsObserver {
+ public content::WebContentsObserver,
+ public ::testing::WithParamInterface<ActivationListTestData> {
public:
SubresourceFilterSafeBrowsingActivationThrottleTest()
: field_trial_list_(nullptr) {}
@@ -162,10 +185,11 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
void SetUp() override {
content::RenderViewHostTestHarness::SetUp();
+ const ActivationListTestData& test_data = GetParam();
scoped_feature_toggle_.reset(
new testing::ScopedSubresourceFilterFeatureToggle(
base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
- kActivationScopeActivationList, kActivationListSubresourceFilter));
+ kActivationScopeActivationList, test_data.activation_list));
auto client = base::MakeUnique<MockSubresourceFilterClient>();
ContentSubresourceFilterDriverFactory::CreateForWebContents(
RenderViewHostTestHarness::web_contents(), std::move(client));
@@ -215,9 +239,10 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
main_rfh());
}
- void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) {
+ void ConfigureForMatch(const GURL& url) {
+ const ActivationListTestData& test_data = GetParam();
fake_safe_browsing_database_->AddBlacklistedUrl(
- url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER);
+ url, test_data.threat_type, test_data.threat_type_metadata);
}
void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); }
@@ -236,39 +261,42 @@ class SubresourceFilterSafeBrowsingActivationThrottleTest
DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest);
};
-TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
+TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTest,
ListNotMatched_NoActivation) {
+ const ActivationListTestData& test_data = GetParam();
const GURL url(kURL);
+ const std::string suffix(GetSuffixForList(test_data.activation_list_type));
CreateTestNavigationForMainFrame(url);
SimulateStartAndExpectProceed();
SimulateCommitAndExpectProceed();
EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision::
ACTIVATION_LIST_NOT_MATCHED,
factory()->GetActivationDecisionForLastCommittedPageLoad());
- tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix,
- 0);
- tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
+ tester().ExpectTotalCount(kMatchesPatternHistogramName + suffix, 0);
+ tester().ExpectTotalCount(kNavigationChainSize + suffix, 0);
}
-TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
+TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTest,
ListMatched_Activation) {
+ const ActivationListTestData& test_data = GetParam();
const GURL url(kURL);
- ConfigureAsSubresourceFilterOnlyURL(url);
+ const std::string suffix(GetSuffixForList(test_data.activation_list_type));
+ ConfigureForMatch(url);
CreateTestNavigationForMainFrame(url);
SimulateStartAndExpectProceed();
SimulateCommitAndExpectProceed();
EXPECT_EQ(
ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED,
factory()->GetActivationDecisionForLastCommittedPageLoad());
- tester().ExpectUniqueSample(
- kMatchesPatternHistogramNameSubresourceFilterSuffix, NO_REDIRECTS_HIT, 1);
- tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 1,
- 1);
+ tester().ExpectTotalCount(kMatchesPatternHistogramName + suffix, 1);
+ tester().ExpectUniqueSample(kNavigationChainSize + suffix, 1, 1);
}
-TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
+TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTest,
ListNotMatchedAfterRedirect_NoActivation) {
+ const ActivationListTestData& test_data = GetParam();
const GURL url(kURL);
+ const std::string suffix(GetSuffixForList(test_data.activation_list_type));
CreateTestNavigationForMainFrame(url);
SimulateStartAndExpectProceed();
SimulateRedirectAndExpectProceed(GURL(kRedirectURL));
@@ -276,15 +304,16 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision::
ACTIVATION_LIST_NOT_MATCHED,
factory()->GetActivationDecisionForLastCommittedPageLoad());
- tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix,
- 0);
- tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
+ tester().ExpectTotalCount(kMatchesPatternHistogramName + suffix, 0);
+ tester().ExpectTotalCount(kNavigationChainSize + suffix, 0);
}
-TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
+TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTest,
ListMatchedAfterRedirect_Activation) {
+ const ActivationListTestData& test_data = GetParam();
const GURL url(kURL);
- ConfigureAsSubresourceFilterOnlyURL(GURL(kRedirectURL));
+ const std::string suffix(GetSuffixForList(test_data.activation_list_type));
+ ConfigureForMatch(GURL(kRedirectURL));
CreateTestNavigationForMainFrame(url);
SimulateStartAndExpectProceed();
SimulateRedirectAndExpectProceed(GURL(kRedirectURL));
@@ -292,15 +321,15 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
EXPECT_EQ(
ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED,
factory()->GetActivationDecisionForLastCommittedPageLoad());
- tester().ExpectUniqueSample(
- kMatchesPatternHistogramNameSubresourceFilterSuffix, F0M0L1, 1);
- tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2,
- 1);
+ tester().ExpectTotalCount(kMatchesPatternHistogramName + suffix, 1);
+ tester().ExpectUniqueSample(kNavigationChainSize + suffix, 2, 1);
}
-TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
+TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTest,
ListNotMatchedAndTimeout_NoActivation) {
+ const ActivationListTestData& test_data = GetParam();
const GURL url(kURL);
+ const std::string suffix(GetSuffixForList(test_data.activation_list_type));
SimulateTimeout();
CreateTestNavigationForMainFrame(url);
SimulateStartAndExpectProceed();
@@ -308,9 +337,8 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision::
ACTIVATION_LIST_NOT_MATCHED,
factory()->GetActivationDecisionForLastCommittedPageLoad());
- tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix,
- 0);
- tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0);
+ tester().ExpectTotalCount(kMatchesPatternHistogramName + suffix, 0);
+ tester().ExpectTotalCount(kNavigationChainSize + suffix, 0);
}
// TODO(melandory): Once non-defering check in WillStart is implemented add one
@@ -318,4 +346,8 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest,
// while the SB check is pending? (To be run by ASAN bots to ensure
// no use-after-free.)
+INSTANTIATE_TEST_CASE_P(ActivationLevelTest,
+ SubresourceFilterSafeBrowsingActivationThrottleTest,
+ ::testing::ValuesIn(kActivationListTestData));
+
} // namespace subresource_filter

Powered by Google App Engine
This is Rietveld 408576698