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 3479cee5c95e8e55be56e03388fc59b8d5513b37..fae0d8d42755f4d03a64650411a59164ea45fec3 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 |
@@ -32,28 +32,10 @@ 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[] = |
+ "SubresourecFilter.PageLoad.FinalURLMatch."; |
engedy
2017/04/26 13:47:10
Same typo here.
melandory
2017/04/26 15:02:21
Done.
|
+const char kNavigationChainSize[] = |
+ "SubresourceFilter.PageLoad.RedirectChainLength."; |
class MockSubresourceFilterClient |
: public subresource_filter::SubresourceFilterClient { |
@@ -97,11 +79,55 @@ 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}, |
+}; |
+ |
+void ExpectSampleForSuffix(const std::string& suffix, |
engedy
2017/04/26 13:47:10
nit: This method is a bit hard to understand. How
|
+ const std::string& match_suffix, |
+ const base::HistogramTester& tester) { |
+ tester.ExpectUniqueSample(kMatchesPatternHistogramName + suffix, |
+ (suffix == match_suffix), 1); |
+} |
+ |
} // namespace |
class SubresourceFilterSafeBrowsingActivationThrottleTest |
: public content::RenderViewHostTestHarness, |
- public content::WebContentsObserver { |
+ public content::WebContentsObserver, |
+ public ::testing::WithParamInterface<ActivationListTestData> { |
public: |
SubresourceFilterSafeBrowsingActivationThrottleTest() |
: field_trial_list_(nullptr) {} |
@@ -109,10 +135,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)); |
// Note: Using NiceMock to allow uninteresting calls and suppress warnings. |
auto client = |
base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>(); |
@@ -164,9 +191,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(); } |
@@ -185,39 +213,48 @@ 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); |
+ ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", std::string(), |
+ tester()); |
+ ExpectSampleForSuffix("PhishingInterstital", std::string(), tester()); |
+ ExpectSampleForSuffix("SubresourceFilterOnly", std::string(), tester()); |
+ |
+ 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); |
+ ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester()); |
+ ExpectSampleForSuffix("PhishingInterstital", suffix, tester()); |
+ ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester()); |
+ 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)); |
@@ -225,15 +262,19 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, |
EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: |
ACTIVATION_LIST_NOT_MATCHED, |
factory()->GetActivationDecisionForLastCommittedPageLoad()); |
- tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, |
- 0); |
- tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); |
+ ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", std::string(), |
+ tester()); |
+ ExpectSampleForSuffix("PhishingInterstital", std::string(), tester()); |
+ ExpectSampleForSuffix("SubresourceFilterOnly", std::string(), tester()); |
+ 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)); |
@@ -241,15 +282,17 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, |
EXPECT_EQ( |
ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, |
factory()->GetActivationDecisionForLastCommittedPageLoad()); |
- tester().ExpectUniqueSample( |
- kMatchesPatternHistogramNameSubresourceFilterSuffix, F0M0L1, 1); |
- tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2, |
- 1); |
+ tester().ExpectUniqueSample(kNavigationChainSize + suffix, 2, 1); |
+ ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester()); |
+ ExpectSampleForSuffix("PhishingInterstital", suffix, tester()); |
+ ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester()); |
} |
-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(); |
@@ -257,9 +300,11 @@ TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, |
EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: |
ACTIVATION_LIST_NOT_MATCHED, |
factory()->GetActivationDecisionForLastCommittedPageLoad()); |
- tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, |
- 0); |
- tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); |
+ ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", std::string(), |
+ tester()); |
+ ExpectSampleForSuffix("PhishingInterstital", std::string(), tester()); |
+ ExpectSampleForSuffix("SubresourceFilterOnly", std::string(), tester()); |
+ tester().ExpectTotalCount(kNavigationChainSize + suffix, 0); |
} |
// TODO(melandory): Once non-defering check in WillStart is implemented add one |
@@ -267,4 +312,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 |