OLD | NEW |
---|---|
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 <map> | 5 #include <map> |
6 #include <memory> | 6 #include <memory> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration"; | 83 "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration"; |
84 constexpr const char kEvaluationTotalWallDurationForDocument[] = | 84 constexpr const char kEvaluationTotalWallDurationForDocument[] = |
85 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; | 85 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; |
86 constexpr const char kEvaluationTotalCPUDurationForDocument[] = | 86 constexpr const char kEvaluationTotalCPUDurationForDocument[] = |
87 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; | 87 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; |
88 constexpr const char kEvaluationWallDuration[] = | 88 constexpr const char kEvaluationWallDuration[] = |
89 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; | 89 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; |
90 constexpr const char kEvaluationCPUDuration[] = | 90 constexpr const char kEvaluationCPUDuration[] = |
91 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; | 91 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; |
92 | 92 |
93 // Names of navigation chain patterns diagram. | |
94 const char kMatchesPatternHistogramName[] = | |
vakh (use Gerrit instead)
2017/02/10 03:00:12
Didn't look closely at the changes in this file.
Y
| |
95 "SubresourceFilter.PageLoad.RedirectChainMatchPattern"; | |
96 const char kNavigationChainSize[] = | |
97 "SubresourceFilter.PageLoad.RedirectChainLength"; | |
98 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly"; | |
99 | |
93 // Other histograms. | 100 // Other histograms. |
94 const char kSubresourceFilterPromptHistogram[] = | 101 const char kSubresourceFilterPromptHistogram[] = |
95 "SubresourceFilter.Prompt.NumVisibility"; | 102 "SubresourceFilter.Prompt.NumVisibility"; |
96 | 103 |
104 // Human readable representation of expected redirect chain match patterns. | |
105 // The explanations for the buckets given for the following redirect chain: | |
106 // A->B->C->D, where A is initial URL and D is a final URL. | |
107 enum RedirectChainMatchPattern { | |
108 EMPTY, // No histograms were recorded. | |
109 F0M0L1, // D is a Safe Browsing match. | |
110 F0M1L0, // B or C, or both are Safe Browsing matches. | |
111 F0M1L1, // B or C, or both and D are Safe Browsing matches. | |
112 F1M0L0, // A is Safe Browsing match | |
113 F1M0L1, // A and D are Safe Browsing matches. | |
114 F1M1L0, // B and/or C and A are Safe Browsing matches. | |
115 F1M1L1, // B and/or C and A and D are Safe Browsing matches. | |
116 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects | |
117 // has happened, and this URL was a Safe Browsing hit. | |
118 NUM_HIT_PATTERNS, | |
119 }; | |
120 | |
97 // Database manager that allows any URL to be configured as blacklisted for | 121 // Database manager that allows any URL to be configured as blacklisted for |
98 // testing. | 122 // testing. |
99 class FakeSafeBrowsingDatabaseManager | 123 class FakeSafeBrowsingDatabaseManager |
100 : public safe_browsing::TestSafeBrowsingDatabaseManager { | 124 : public safe_browsing::TestSafeBrowsingDatabaseManager { |
101 public: | 125 public: |
102 FakeSafeBrowsingDatabaseManager() {} | 126 FakeSafeBrowsingDatabaseManager() {} |
103 | 127 |
104 void AddBlacklistedURL(const GURL& url, | 128 void AddBlacklistedURL(const GURL& url, |
105 safe_browsing::SBThreatType threat_type) { | 129 safe_browsing::SBThreatType threat_type) { |
106 url_to_threat_type_[url] = threat_type; | 130 url_to_threat_type_[url] = threat_type; |
(...skipping 11 matching lines...) Expand all Loading... | |
118 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), | 142 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), |
119 url, url_to_threat_type_[url], | 143 url, url_to_threat_type_[url], |
120 safe_browsing::ThreatMetadata())); | 144 safe_browsing::ThreatMetadata())); |
121 return false; | 145 return false; |
122 } | 146 } |
123 | 147 |
124 bool CheckResourceUrl(const GURL& url, Client* client) override { | 148 bool CheckResourceUrl(const GURL& url, Client* client) override { |
125 return true; | 149 return true; |
126 } | 150 } |
127 | 151 |
152 bool CheckUrlForSubresourceFilter(const GURL& url, Client* client) override { | |
153 if (!url_to_threat_type_.count(url)) | |
154 return true; | |
155 content::BrowserThread::PostTask( | |
156 content::BrowserThread::IO, FROM_HERE, | |
157 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), | |
158 url, url_to_threat_type_[url], | |
159 safe_browsing::ThreatMetadata())); | |
160 return false; | |
161 } | |
162 | |
128 bool IsSupported() const override { return true; } | 163 bool IsSupported() const override { return true; } |
129 bool ChecksAreAlwaysAsync() const override { return false; } | 164 bool ChecksAreAlwaysAsync() const override { return false; } |
130 bool CanCheckResourceType( | 165 bool CanCheckResourceType( |
131 content::ResourceType /* resource_type */) const override { | 166 content::ResourceType /* resource_type */) const override { |
132 return true; | 167 return true; |
133 } | 168 } |
134 | 169 |
135 safe_browsing::ThreatSource GetThreatSource() const override { | 170 safe_browsing::ThreatSource GetThreatSource() const override { |
136 return safe_browsing::ThreatSource::LOCAL_PVER4; | 171 return safe_browsing::ThreatSource::LOCAL_PVER4; |
137 } | 172 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates | 245 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates |
211 // the RulesetService. | 246 // the RulesetService. |
212 // | 247 // |
213 // On the other hand, setting up field trials in this method would be too | 248 // On the other hand, setting up field trials in this method would be too |
214 // early, as it is called before BrowserMain, which expects no FieldTrialList | 249 // early, as it is called before BrowserMain, which expects no FieldTrialList |
215 // singleton to exist. There are no other hooks we could use either. | 250 // singleton to exist. There are no other hooks we could use either. |
216 // | 251 // |
217 // As a workaround, enable the feature here, then enable the feature once | 252 // As a workaround, enable the feature here, then enable the feature once |
218 // again + set up the field trials later. | 253 // again + set up the field trials later. |
219 void SetUpCommandLine(base::CommandLine* command_line) override { | 254 void SetUpCommandLine(base::CommandLine* command_line) override { |
220 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 255 command_line->AppendSwitchASCII( |
221 kSafeBrowsingSubresourceFilter.name); | 256 switches::kEnableFeatures, |
257 std::string(kSafeBrowsingSubresourceFilter.name) + | |
258 ", SafeBrowsingV4OnlyEnabled"); | |
222 } | 259 } |
223 | 260 |
224 void SetUpInProcessBrowserTestFixture() override { | 261 void SetUpInProcessBrowserTestFixture() override { |
225 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); | 262 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); |
226 test_safe_browsing_factory_.SetTestDatabaseManager( | 263 test_safe_browsing_factory_.SetTestDatabaseManager( |
227 fake_safe_browsing_database_.get()); | 264 fake_safe_browsing_database_.get()); |
228 test_safe_browsing_factory_.SetTestUIManager(new FakeSafeBrowsingUIManager); | 265 test_safe_browsing_factory_.SetTestUIManager(new FakeSafeBrowsingUIManager); |
229 safe_browsing::SafeBrowsingService::RegisterFactory( | 266 safe_browsing::SafeBrowsingService::RegisterFactory( |
230 &test_safe_browsing_factory_); | 267 &test_safe_browsing_factory_); |
231 } | 268 } |
(...skipping 15 matching lines...) Expand all Loading... | |
247 | 284 |
248 GURL GetTestUrl(const std::string& path) { | 285 GURL GetTestUrl(const std::string& path) { |
249 return embedded_test_server()->base_url().Resolve(path); | 286 return embedded_test_server()->base_url().Resolve(path); |
250 } | 287 } |
251 | 288 |
252 void ConfigureAsPhishingURL(const GURL& url) { | 289 void ConfigureAsPhishingURL(const GURL& url) { |
253 fake_safe_browsing_database_->AddBlacklistedURL( | 290 fake_safe_browsing_database_->AddBlacklistedURL( |
254 url, safe_browsing::SB_THREAT_TYPE_URL_PHISHING); | 291 url, safe_browsing::SB_THREAT_TYPE_URL_PHISHING); |
255 } | 292 } |
256 | 293 |
294 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { | |
295 fake_safe_browsing_database_->AddBlacklistedURL( | |
296 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); | |
297 } | |
298 | |
257 content::WebContents* web_contents() { | 299 content::WebContents* web_contents() { |
258 return browser()->tab_strip_model()->GetActiveWebContents(); | 300 return browser()->tab_strip_model()->GetActiveWebContents(); |
259 } | 301 } |
260 | 302 |
261 content::RenderFrameHost* FindFrameByName(const std::string& name) { | 303 content::RenderFrameHost* FindFrameByName(const std::string& name) { |
262 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { | 304 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { |
263 if (frame->GetFrameName() == name) | 305 if (frame->GetFrameName() == name) |
264 return frame; | 306 return frame; |
265 } | 307 } |
266 return nullptr; | 308 return nullptr; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 tester.ExpectTotalCount(kSubresourceLoadsEvaluated, 0); | 761 tester.ExpectTotalCount(kSubresourceLoadsEvaluated, 0); |
720 tester.ExpectTotalCount(kSubresourceLoadsMatchedRules, 0); | 762 tester.ExpectTotalCount(kSubresourceLoadsMatchedRules, 0); |
721 tester.ExpectTotalCount(kSubresourceLoadsDisallowed, 0); | 763 tester.ExpectTotalCount(kSubresourceLoadsDisallowed, 0); |
722 | 764 |
723 // Although SubresourceFilterAgents still record the activation decision. | 765 // Although SubresourceFilterAgents still record the activation decision. |
724 tester.ExpectUniqueSample( | 766 tester.ExpectUniqueSample( |
725 kDocumentLoadActivationLevel, | 767 kDocumentLoadActivationLevel, |
726 static_cast<base::Histogram::Sample>(ActivationLevel::DISABLED), 6); | 768 static_cast<base::Histogram::Sample>(ActivationLevel::DISABLED), 6); |
727 } | 769 } |
728 | 770 |
771 IN_PROC_BROWSER_TEST_F( | |
772 SubresourceFilterBrowserTest, | |
773 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) { | |
774 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( | |
775 "suffix-that-does-not-match-anything")); | |
776 | |
777 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); | |
778 ConfigureAsSubresourceFilterOnlyURL(url); | |
779 | |
780 base::HistogramTester tester; | |
781 ui_test_utils::NavigateToURL(browser(), url); | |
782 | |
783 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
784 std::string(kSubresourceFilterOnlySuffix)), | |
785 ::testing::ElementsAre(base::Bucket(NO_REDIRECTS_HIT, 1))); | |
786 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
787 std::string(kSubresourceFilterOnlySuffix)), | |
788 ::testing::ElementsAre(base::Bucket(1, 1))); | |
789 } | |
790 | |
791 IN_PROC_BROWSER_TEST_F( | |
792 SubresourceFilterBrowserTest, | |
793 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyWithRedire cts) { | |
794 ASSERT_NO_FATAL_FAILURE( | |
795 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | |
796 std::string initial_host("a.com"); | |
797 std::string redirected_host("b.com"); | |
798 | |
799 GURL redirect_url(embedded_test_server()->GetURL(redirected_host, "/")); | |
800 GURL url(embedded_test_server()->GetURL( | |
801 initial_host, "/client-redirect?" + redirect_url.spec())); | |
802 | |
803 ConfigureAsSubresourceFilterOnlyURL(redirect_url); | |
804 base::HistogramTester tester; | |
805 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2); | |
806 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
807 std::string(kSubresourceFilterOnlySuffix)), | |
808 ::testing::ElementsAre(base::Bucket(NO_REDIRECTS_HIT, 1))); | |
809 | |
810 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
811 std::string(kSubresourceFilterOnlySuffix)), | |
812 ::testing::ElementsAre(base::Bucket(1, 1))); | |
813 } | |
814 | |
815 IN_PROC_BROWSER_TEST_F( | |
816 SubresourceFilterBrowserTest, | |
817 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyRedirectMa tch) { | |
818 ASSERT_NO_FATAL_FAILURE( | |
819 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | |
820 std::string initial_host("a.com"); | |
821 std::string redirected_host("b.com"); | |
822 | |
823 GURL redirect_url(embedded_test_server()->GetURL( | |
824 redirected_host, "/subresource_filter/frame_with_included_script.html")); | |
825 GURL url(embedded_test_server()->GetURL( | |
826 initial_host, "/client-redirect?" + redirect_url.spec())); | |
827 | |
828 ConfigureAsSubresourceFilterOnlyURL(GURL(url.host())); | |
829 base::HistogramTester tester; | |
830 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2); | |
831 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
832 std::string(kSubresourceFilterOnlySuffix)), | |
833 ::testing::IsEmpty()); | |
834 | |
835 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
836 std::string(kSubresourceFilterOnlySuffix)), | |
837 ::testing::IsEmpty()); | |
838 } | |
839 | |
729 } // namespace subresource_filter | 840 } // namespace subresource_filter |
OLD | NEW |