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

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

Issue 2645283007: Add the client for accessing Subresource Filter only list. (Closed)
Patch Set: feature 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/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 18 matching lines...) Expand all
29 namespace subresource_filter { 29 namespace subresource_filter {
30 30
31 using ActivationDecision = 31 using ActivationDecision =
32 ContentSubresourceFilterDriverFactory::ActivationDecision; 32 ContentSubresourceFilterDriverFactory::ActivationDecision;
33 33
34 namespace { 34 namespace {
35 35
36 const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc"; 36 const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc";
37 const char kExampleUrl[] = "https://example.com"; 37 const char kExampleUrl[] = "https://example.com";
38 const char kExampleLoginUrl[] = "https://example.com/login"; 38 const char kExampleLoginUrl[] = "https://example.com/login";
39 const char kMatchesPatternHistogramName[] =
40 "SubresourceFilter.PageLoad.RedirectChainMatchPattern";
41 const char kNavigationChainSize[] =
42 "SubresourceFilter.PageLoad.RedirectChainLength";
43 const char kUrlA[] = "https://example_a.com"; 39 const char kUrlA[] = "https://example_a.com";
44 const char kUrlB[] = "https://example_b.com"; 40 const char kUrlB[] = "https://example_b.com";
45 const char kUrlC[] = "https://example_c.com"; 41 const char kUrlC[] = "https://example_c.com";
46 const char kUrlD[] = "https://example_d.com"; 42 const char kUrlD[] = "https://example_d.com";
47 const char kSubframeName[] = "Child"; 43 const char kSubframeName[] = "Child";
48 44
45 const char kMatchesPatternHistogramName[] =
46 "SubresourceFilter.PageLoad.RedirectChainMatchPattern.";
47 const char kNavigationChainSize[] =
48 "SubresourceFilter.PageLoad.RedirectChainLength.";
49
49 // Human readable representation of expected redirect chain match patterns. 50 // Human readable representation of expected redirect chain match patterns.
50 // The explanations for the buckets given for the following redirect chain: 51 // The explanations for the buckets given for the following redirect chain:
51 // A->B->C->D, where A is initial URL and D is a final URL. 52 // A->B->C->D, where A is initial URL and D is a final URL.
52 enum RedirectChainMatchPattern { 53 enum RedirectChainMatchPattern {
53 EMPTY, // No histograms were recorded. 54 EMPTY, // No histograms were recorded.
54 F0M0L1, // D is a Safe Browsing match. 55 F0M0L1, // D is a Safe Browsing match.
55 F0M1L0, // B or C, or both are Safe Browsing matches. 56 F0M1L0, // B or C, or both are Safe Browsing matches.
56 F0M1L1, // B or C, or both and D are Safe Browsing matches. 57 F0M1L1, // B or C, or both and D are Safe Browsing matches.
57 F1M0L0, // A is Safe Browsing match 58 F1M0L0, // A is Safe Browsing match
58 F1M0L1, // A and D are Safe Browsing matches. 59 F1M0L1, // A and D are Safe Browsing matches.
59 F1M1L0, // B and/or C and A are Safe Browsing matches. 60 F1M1L0, // B and/or C and A are Safe Browsing matches.
60 F1M1L1, // B and/or C and A and D are Safe Browsing matches. 61 F1M1L1, // B and/or C and A and D are Safe Browsing matches.
61 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects 62 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects
62 // has happened, and this URL was a Safe Browsing hit. 63 // has happened, and this URL was a Safe Browsing hit.
63 NUM_HIT_PATTERNS, 64 NUM_HIT_PATTERNS,
64 }; 65 };
65 66
66 std::string GetSuffixForList(const ActivationList& type) { 67 std::string GetSuffixForList(const ActivationList& type) {
67 switch (type) { 68 switch (type) {
68 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: 69 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL:
69 return ".SocialEngineeringAdsInterstitial"; 70 return "SocialEngineeringAdsInterstitial";
70 case ActivationList::PHISHING_INTERSTITIAL: 71 case ActivationList::PHISHING_INTERSTITIAL:
71 return ".PhishingInterstital"; 72 return "PhishingInterstital";
73 case ActivationList::SUBRESOURCE_FILTER:
74 return "SubresourceFilterOnly";
72 case ActivationList::NONE: 75 case ActivationList::NONE:
73 return std::string(); 76 return std::string();
74 } 77 }
75 return std::string(); 78 return std::string();
76 } 79 }
77 80
78 struct ActivationListTestData { 81 struct ActivationListTestData {
79 ActivationDecision expected_activation_decision; 82 ActivationDecision expected_activation_decision;
80 const char* const activation_list; 83 const char* const activation_list;
81 safe_browsing::SBThreatType threat_type; 84 safe_browsing::SBThreatType threat_type;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 factory()->GetActivationDecisionForLastCommittedPageLoad()); 290 factory()->GetActivationDecisionForLastCommittedPageLoad());
288 291
289 // Re-create a subframe now that the frame has navigated. 292 // Re-create a subframe now that the frame has navigated.
290 content::RenderFrameHostTester* rfh_tester = 293 content::RenderFrameHostTester* rfh_tester =
291 content::RenderFrameHostTester::For(main_rfh()); 294 content::RenderFrameHostTester::For(main_rfh());
292 rfh_tester->AppendChild(kSubframeName); 295 rfh_tester->AppendChild(kSubframeName);
293 ActivationList activation_list = 296 ActivationList activation_list =
294 GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata); 297 GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata);
295 298
296 const std::string suffix(GetSuffixForList(activation_list)); 299 const std::string suffix(GetSuffixForList(activation_list));
300 size_t all_pattern =
301 tester.GetTotalCountsForPrefix(kMatchesPatternHistogramName).size();
302 size_t all_chain_size =
303 tester.GetTotalCountsForPrefix(kNavigationChainSize).size();
297 if (expected_pattern != EMPTY) { 304 if (expected_pattern != EMPTY) {
298 EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName + suffix), 305 EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName + suffix),
299 ::testing::ElementsAre(base::Bucket(expected_pattern, 1))); 306 ::testing::ElementsAre(base::Bucket(expected_pattern, 1)));
300 EXPECT_THAT( 307 EXPECT_THAT(
301 tester.GetAllSamples(kNavigationChainSize + suffix), 308 tester.GetAllSamples(kNavigationChainSize + suffix),
302 ::testing::ElementsAre(base::Bucket(navigation_chain.size(), 1))); 309 ::testing::ElementsAre(base::Bucket(navigation_chain.size(), 1)));
310 // Check that we recorded only what is needed.
311 EXPECT_EQ(1u, all_pattern);
312 EXPECT_EQ(1u, all_chain_size);
303 } else { 313 } else {
304 EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName + suffix), 314 EXPECT_EQ(0u, all_pattern);
305 ::testing::IsEmpty()); 315 EXPECT_EQ(0u, all_chain_size);
306 EXPECT_THAT(tester.GetAllSamples(kNavigationChainSize + suffix),
307 ::testing::IsEmpty());
308 } 316 }
309 } 317 }
310 318
311 void NavigateAndCommitSubframe(const GURL& url, bool expected_activation) { 319 void NavigateAndCommitSubframe(const GURL& url, bool expected_activation) {
312 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); 320 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0);
313 321
314 content::NavigationSimulator::NavigateAndCommitFromDocument( 322 content::NavigationSimulator::NavigateAndCommitFromDocument(
315 url, GetSubframeRFH()); 323 url, GetSubframeRFH());
316 ExpectActivationSignalForFrame(GetSubframeRFH(), expected_activation); 324 ExpectActivationSignalForFrame(GetSubframeRFH(), expected_activation);
317 ::testing::Mock::VerifyAndClearExpectations(client()); 325 ::testing::Mock::VerifyAndClearExpectations(client());
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 F0M0L1, 548 F0M0L1,
541 ActivationDecision::ACTIVATED}, 549 ActivationDecision::ACTIVATED},
542 {{true, false}, 550 {{true, false},
543 {GURL(kUrlA), GURL(kUrlB)}, 551 {GURL(kUrlA), GURL(kUrlB)},
544 F1M0L0, 552 F1M0L0,
545 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, 553 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED},
546 {{true, true}, 554 {{true, true},
547 {GURL(kUrlA), GURL(kUrlB)}, 555 {GURL(kUrlA), GURL(kUrlB)},
548 F1M0L1, 556 F1M0L1,
549 ActivationDecision::ACTIVATED}, 557 ActivationDecision::ACTIVATED},
550
551 {{false, false, false}, 558 {{false, false, false},
552 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, 559 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
553 EMPTY, 560 EMPTY,
554 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED}, 561 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED},
555 {{false, false, true}, 562 {{false, false, true},
556 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, 563 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
557 F0M0L1, 564 F0M0L1,
558 ActivationDecision::ACTIVATED}, 565 ActivationDecision::ACTIVATED},
559 {{false, true, false}, 566 {{false, true, false},
560 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, 567 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)},
(...skipping 30 matching lines...) Expand all
591 auto test_data = kRedirectRedirectChainMatchPatternTestData[i]; 598 auto test_data = kRedirectRedirectChainMatchPatternTestData[i];
592 NavigateAndExpectActivation( 599 NavigateAndExpectActivation(
593 test_data.blacklisted_urls, test_data.navigation_chain, 600 test_data.blacklisted_urls, test_data.navigation_chain,
594 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, 601 safe_browsing::SB_THREAT_TYPE_URL_PHISHING,
595 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, 602 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS,
596 content::Referrer(), ui::PAGE_TRANSITION_LINK, 603 content::Referrer(), ui::PAGE_TRANSITION_LINK,
597 test_data.hit_expected_pattern, test_data.expected_activation_decision); 604 test_data.hit_expected_pattern, test_data.expected_activation_decision);
598 NavigateAndExpectActivation( 605 NavigateAndExpectActivation(
599 {false}, {GURL("https://dummy.com")}, EMPTY, 606 {false}, {GURL("https://dummy.com")}, EMPTY,
600 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED); 607 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED);
608 #if defined(GOOGLE_CHROME_BUILD)
609 NavigateAndExpectActivation(
610 test_data.blacklisted_urls, test_data.navigation_chain,
611 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER,
612 safe_browsing::ThreatPatternType::NONE, content::Referrer(),
613 ui::PAGE_TRANSITION_LINK, EMPTY, test_data.hit_expected_pattern,
614 ActivationDecision::ACTIVATION_LIST_NOT_MATCHED);
615 #endif
601 } 616 }
602 } 617 }
603 618
604 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { 619 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) {
605 base::FieldTrialList field_trial_list(nullptr); 620 base::FieldTrialList field_trial_list(nullptr);
606 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle( 621 testing::ScopedSubresourceFilterFeatureToggle scoped_feature_toggle(
607 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, 622 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled,
608 kActivationScopeAllSites); 623 kActivationScopeAllSites);
609 624
610 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, 625 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 ActivationScopeTest, 797 ActivationScopeTest,
783 ContentSubresourceFilterDriverFactoryActivationScopeTest, 798 ContentSubresourceFilterDriverFactoryActivationScopeTest,
784 ::testing::ValuesIn(kActivationScopeTestData)); 799 ::testing::ValuesIn(kActivationScopeTestData));
785 800
786 INSTANTIATE_TEST_CASE_P( 801 INSTANTIATE_TEST_CASE_P(
787 ActivationLevelTest, 802 ActivationLevelTest,
788 ContentSubresourceFilterDriverFactoryActivationLevelTest, 803 ContentSubresourceFilterDriverFactoryActivationLevelTest,
789 ::testing::ValuesIn(kActivationLevelTestData)); 804 ::testing::ValuesIn(kActivationLevelTestData));
790 805
791 } // namespace subresource_filter 806 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698