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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "base/strings/string_util.h" | |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/test/histogram_tester.h" | 19 #include "base/test/histogram_tester.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/metrics/subprocess_metrics_provider.h" | 21 #include "chrome/browser/metrics/subprocess_metrics_provider.h" |
21 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" | 22 #include "chrome/browser/page_load_metrics/observers/subresource_filter_metrics_ observer.h" |
22 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" | 23 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
24 #include "chrome/browser/safe_browsing/v4_test_utils.h" | |
23 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" | 25 #include "chrome/browser/subresource_filter/test_ruleset_publisher.h" |
24 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_commands.h" | 27 #include "chrome/browser/ui/browser_commands.h" |
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
27 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
28 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
29 #include "chrome/test/base/in_process_browser_test.h" | 31 #include "chrome/test/base/in_process_browser_test.h" |
30 #include "chrome/test/base/ui_test_utils.h" | 32 #include "chrome/test/base/ui_test_utils.h" |
31 #include "components/safe_browsing_db/test_database_manager.h" | 33 #include "components/safe_browsing_db/test_database_manager.h" |
32 #include "components/safe_browsing_db/util.h" | 34 #include "components/safe_browsing_db/util.h" |
35 #include "components/safe_browsing_db/v4_database.h" | |
33 #include "components/security_interstitials/content/unsafe_resource.h" | 36 #include "components/security_interstitials/content/unsafe_resource.h" |
34 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" | 37 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h" |
35 #include "components/subresource_filter/core/browser/subresource_filter_features .h" | 38 #include "components/subresource_filter/core/browser/subresource_filter_features .h" |
36 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" | 39 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" |
37 #include "components/subresource_filter/core/common/activation_level.h" | 40 #include "components/subresource_filter/core/common/activation_level.h" |
38 #include "components/subresource_filter/core/common/scoped_timers.h" | 41 #include "components/subresource_filter/core/common/scoped_timers.h" |
39 #include "components/subresource_filter/core/common/test_ruleset_utils.h" | 42 #include "components/subresource_filter/core/common/test_ruleset_utils.h" |
40 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
41 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
42 #include "content/public/browser/notification_types.h" | 45 #include "content/public/browser/notification_types.h" |
43 #include "content/public/browser/render_frame_host.h" | 46 #include "content/public/browser/render_frame_host.h" |
44 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
45 #include "content/public/common/content_switches.h" | 48 #include "content/public/common/content_switches.h" |
46 #include "content/public/test/browser_test_utils.h" | 49 #include "content/public/test/browser_test_utils.h" |
47 #include "content/public/test/test_navigation_observer.h" | 50 #include "content/public/test/test_navigation_observer.h" |
48 #include "content/public/test/test_utils.h" | 51 #include "content/public/test/test_utils.h" |
49 #include "net/dns/mock_host_resolver.h" | 52 #include "net/dns/mock_host_resolver.h" |
50 #include "net/test/embedded_test_server/embedded_test_server.h" | 53 #include "net/test/embedded_test_server/embedded_test_server.h" |
51 #include "net/test/spawned_test_server/spawned_test_server.h" | 54 #include "net/test/spawned_test_server/spawned_test_server.h" |
52 #include "net/test/test_data_directory.h" | 55 #include "net/test/test_data_directory.h" |
53 #include "testing/gmock/include/gmock/gmock.h" | 56 #include "testing/gmock/include/gmock/gmock.h" |
54 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
55 | 58 |
56 namespace { | 59 namespace { |
57 | 60 |
58 // The path to a multi-frame document used for tests. | 61 // The path to a multi-frame document used for tests. |
59 static constexpr const char kTestFrameSetPath[] = | 62 static constexpr const char kTestFrameSetPath[] = |
60 "subresource_filter/frame_set.html"; | 63 "/subresource_filter/frame_set.html"; |
61 | 64 |
62 // Names of DocumentLoad histograms. | 65 // Names of DocumentLoad histograms. |
63 constexpr const char kDocumentLoadActivationLevel[] = | 66 constexpr const char kDocumentLoadActivationLevel[] = |
64 "SubresourceFilter.DocumentLoad.ActivationState"; | 67 "SubresourceFilter.DocumentLoad.ActivationState"; |
65 constexpr const char kSubresourceLoadsTotal[] = | 68 constexpr const char kSubresourceLoadsTotal[] = |
66 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Total"; | 69 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Total"; |
67 constexpr const char kSubresourceLoadsEvaluated[] = | 70 constexpr const char kSubresourceLoadsEvaluated[] = |
68 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Evaluated"; | 71 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.Evaluated"; |
69 constexpr const char kSubresourceLoadsMatchedRules[] = | 72 constexpr const char kSubresourceLoadsMatchedRules[] = |
70 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.MatchedRules"; | 73 "SubresourceFilter.DocumentLoad.NumSubresourceLoads.MatchedRules"; |
(...skipping 20 matching lines...) Expand all Loading... | |
91 "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration"; | 94 "SubresourceFilter.PageLoad.SubresourceEvaluation.TotalCPUDuration"; |
92 constexpr const char kEvaluationTotalWallDurationForDocument[] = | 95 constexpr const char kEvaluationTotalWallDurationForDocument[] = |
93 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; | 96 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalWallDuration"; |
94 constexpr const char kEvaluationTotalCPUDurationForDocument[] = | 97 constexpr const char kEvaluationTotalCPUDurationForDocument[] = |
95 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; | 98 "SubresourceFilter.DocumentLoad.SubresourceEvaluation.TotalCPUDuration"; |
96 constexpr const char kEvaluationWallDuration[] = | 99 constexpr const char kEvaluationWallDuration[] = |
97 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; | 100 "SubresourceFilter.SubresourceLoad.Evaluation.WallDuration"; |
98 constexpr const char kEvaluationCPUDuration[] = | 101 constexpr const char kEvaluationCPUDuration[] = |
99 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; | 102 "SubresourceFilter.SubresourceLoad.Evaluation.CPUDuration"; |
100 | 103 |
104 #if defined(GOOGLE_CHROME_BUILD) | |
105 // Names of navigation chain patterns histogram. | |
106 const char kMatchesPatternHistogramName[] = | |
107 "SubresourceFilter.PageLoad.RedirectChainMatchPattern"; | |
108 const char kNavigationChainSize[] = | |
109 "SubresourceFilter.PageLoad.RedirectChainLength"; | |
110 const char kSubresourceFilterOnlySuffix[] = ".SubresourceFilterOnly"; | |
111 #endif | |
112 | |
101 // Other histograms. | 113 // Other histograms. |
102 const char kSubresourceFilterPromptHistogram[] = | 114 const char kSubresourceFilterPromptHistogram[] = |
103 "SubresourceFilter.Prompt.NumVisibility"; | 115 "SubresourceFilter.Prompt.NumVisibility"; |
104 | 116 |
105 // Database manager that allows any URL to be configured as blacklisted for | 117 // Human readable representation of expected redirect chain match patterns. |
106 // testing. | 118 // The explanations for the buckets given for the following redirect chain: |
107 class FakeSafeBrowsingDatabaseManager | 119 // A->B->C->D, where A is initial URL and D is a final URL. |
108 : public safe_browsing::TestSafeBrowsingDatabaseManager { | 120 enum RedirectChainMatchPattern { |
109 public: | 121 EMPTY, // No histograms were recorded. |
110 FakeSafeBrowsingDatabaseManager() {} | 122 F0M0L1, // D is a Safe Browsing match. |
111 | 123 F0M1L0, // B or C, or both are Safe Browsing matches. |
112 void AddBlacklistedURL(const GURL& url, | 124 F0M1L1, // B or C, or both and D are Safe Browsing matches. |
113 safe_browsing::SBThreatType threat_type) { | 125 F1M0L0, // A is Safe Browsing match |
114 url_to_threat_type_[url] = threat_type; | 126 F1M0L1, // A and D are Safe Browsing matches. |
115 } | 127 F1M1L0, // B and/or C and A are Safe Browsing matches. |
116 | 128 F1M1L1, // B and/or C and A and D are Safe Browsing matches. |
117 protected: | 129 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects |
118 ~FakeSafeBrowsingDatabaseManager() override {} | 130 // has happened, and this URL was a Safe Browsing hit. |
119 | 131 NUM_HIT_PATTERNS, |
120 bool CheckBrowseUrl(const GURL& url, Client* client) override { | |
121 if (!url_to_threat_type_.count(url)) | |
122 return true; | |
123 | |
124 content::BrowserThread::PostTask( | |
125 content::BrowserThread::IO, FROM_HERE, | |
126 base::Bind(&Client::OnCheckBrowseUrlResult, base::Unretained(client), | |
127 url, url_to_threat_type_[url], | |
128 safe_browsing::ThreatMetadata())); | |
129 return false; | |
130 } | |
131 | |
132 bool CheckResourceUrl(const GURL& url, Client* client) override { | |
133 return true; | |
134 } | |
135 | |
136 bool IsSupported() const override { return true; } | |
137 bool ChecksAreAlwaysAsync() const override { return false; } | |
138 bool CanCheckResourceType( | |
139 content::ResourceType /* resource_type */) const override { | |
140 return true; | |
141 } | |
142 | |
143 safe_browsing::ThreatSource GetThreatSource() const override { | |
144 return safe_browsing::ThreatSource::LOCAL_PVER4; | |
145 } | |
146 | |
147 bool CheckExtensionIDs(const std::set<std::string>& extension_ids, | |
148 Client* client) override { | |
149 return true; | |
150 } | |
151 | |
152 private: | |
153 std::map<GURL, safe_browsing::SBThreatType> url_to_threat_type_; | |
154 | |
155 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingDatabaseManager); | |
156 }; | 132 }; |
157 | 133 |
158 // UI manager that never actually shows any interstitials, but emulates as if | 134 // UI manager that never actually shows any interstitials, but emulates as if |
159 // the user chose to proceed through them. | 135 // the user chose to proceed through them. |
160 class FakeSafeBrowsingUIManager | 136 class FakeSafeBrowsingUIManager |
161 : public safe_browsing::TestSafeBrowsingUIManager { | 137 : public safe_browsing::TestSafeBrowsingUIManager { |
162 public: | 138 public: |
163 FakeSafeBrowsingUIManager() {} | 139 FakeSafeBrowsingUIManager() {} |
164 | 140 |
165 protected: | 141 protected: |
166 ~FakeSafeBrowsingUIManager() override {} | 142 ~FakeSafeBrowsingUIManager() override {} |
167 | 143 |
168 void DisplayBlockingPage(const UnsafeResource& resource) override { | 144 void DisplayBlockingPage(const UnsafeResource& resource) override { |
169 resource.callback_thread->PostTask( | 145 resource.callback_thread->PostTask( |
170 FROM_HERE, base::Bind(resource.callback, true /* proceed */)); | 146 FROM_HERE, base::Bind(resource.callback, true /* proceed */)); |
171 } | 147 } |
172 | 148 |
173 private: | 149 private: |
174 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingUIManager); | 150 DISALLOW_COPY_AND_ASSIGN(FakeSafeBrowsingUIManager); |
175 }; | 151 }; |
176 | 152 |
177 GURL GetURLWithFragment(const GURL& url, base::StringPiece fragment) { | 153 GURL GetURLWithFragment(const GURL& url, base::StringPiece fragment) { |
178 GURL::Replacements replacements; | 154 GURL::Replacements replacements; |
179 replacements.SetRefStr(fragment); | 155 replacements.SetRefStr(fragment); |
180 return url.ReplaceComponents(replacements); | 156 return url.ReplaceComponents(replacements); |
181 } | 157 } |
182 | 158 |
183 GURL GetURLWithQuery(const GURL& url, base::StringPiece query) { | |
184 GURL::Replacements replacements; | |
185 replacements.SetQueryStr(query); | |
186 return url.ReplaceComponents(replacements); | |
187 } | |
188 | |
189 } // namespace | 159 } // namespace |
190 | 160 |
191 namespace subresource_filter { | 161 namespace subresource_filter { |
192 | 162 |
193 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; | 163 using subresource_filter::testing::ScopedSubresourceFilterFeatureToggle; |
194 using subresource_filter::testing::TestRulesetPublisher; | 164 using subresource_filter::testing::TestRulesetPublisher; |
195 using subresource_filter::testing::TestRulesetCreator; | 165 using subresource_filter::testing::TestRulesetCreator; |
196 using subresource_filter::testing::TestRulesetPair; | 166 using subresource_filter::testing::TestRulesetPair; |
197 using ActivationDecision = | 167 using ActivationDecision = |
198 ContentSubresourceFilterDriverFactory::ActivationDecision; | 168 ContentSubresourceFilterDriverFactory::ActivationDecision; |
(...skipping 23 matching lines...) Expand all Loading... | |
222 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates | 192 // called after ChromeBrowserMainParts::PreBrowserStart(), which instantiates |
223 // the RulesetService. | 193 // the RulesetService. |
224 // | 194 // |
225 // On the other hand, setting up field trials in this method would be too | 195 // On the other hand, setting up field trials in this method would be too |
226 // early, as it is called before BrowserMain, which expects no FieldTrialList | 196 // early, as it is called before BrowserMain, which expects no FieldTrialList |
227 // singleton to exist. There are no other hooks we could use either. | 197 // singleton to exist. There are no other hooks we could use either. |
228 // | 198 // |
229 // As a workaround, enable the feature here, then enable the feature once | 199 // As a workaround, enable the feature here, then enable the feature once |
230 // again + set up the field trials later. | 200 // again + set up the field trials later. |
231 void SetUpCommandLine(base::CommandLine* command_line) override { | 201 void SetUpCommandLine(base::CommandLine* command_line) override { |
232 command_line->AppendSwitchASCII(switches::kEnableFeatures, | 202 command_line->AppendSwitchASCII( |
233 kSafeBrowsingSubresourceFilter.name); | 203 switches::kEnableFeatures, |
204 base::JoinString({std::string(kSafeBrowsingSubresourceFilter.name), | |
engedy
2017/03/21 13:44:16
nit: I think you can drop std::string, should work
melandory
2017/03/24 15:49:27
Done.
| |
205 "SafeBrowsingV4OnlyEnabled"}, | |
206 ",")); | |
234 } | 207 } |
235 | 208 |
236 void SetUpInProcessBrowserTestFixture() override { | 209 void SetUp() override { |
237 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); | 210 sb_factory_ = |
238 test_safe_browsing_factory_.SetTestDatabaseManager( | 211 base::MakeUnique<safe_browsing::TestSafeBrowsingServiceFactory>( |
239 fake_safe_browsing_database_.get()); | 212 safe_browsing::V4FeatureList::V4UsageStatus::V4_ONLY); |
240 test_safe_browsing_factory_.SetTestUIManager(new FakeSafeBrowsingUIManager); | 213 sb_factory_->SetTestUIManager(new FakeSafeBrowsingUIManager()); |
241 safe_browsing::SafeBrowsingService::RegisterFactory( | 214 safe_browsing::SafeBrowsingService::RegisterFactory(sb_factory_.get()); |
242 &test_safe_browsing_factory_); | 215 |
216 safe_browsing::V4Database::RegisterStoreFactoryForTest( | |
217 base::WrapUnique(new safe_browsing::TestV4StoreFactory())); | |
218 | |
219 v4_db_factory_ = new safe_browsing::TestV4DatabaseFactory(); | |
220 safe_browsing::V4Database::RegisterDatabaseFactoryForTest( | |
221 base::WrapUnique(v4_db_factory_)); | |
222 | |
223 v4_get_hash_factory_ = | |
224 new safe_browsing::TestV4GetHashProtocolManagerFactory(); | |
225 safe_browsing::V4GetHashProtocolManager::RegisterFactory( | |
226 base::WrapUnique(v4_get_hash_factory_)); | |
227 InProcessBrowserTest::SetUp(); | |
228 } | |
229 | |
230 void TearDown() override { | |
231 InProcessBrowserTest::TearDown(); | |
232 // Unregister test factories after InProcessBrowserTest::TearDown | |
233 // (which destructs SafeBrowsingService). | |
234 safe_browsing::V4GetHashProtocolManager::RegisterFactory(nullptr); | |
235 safe_browsing::V4Database::RegisterDatabaseFactoryForTest(nullptr); | |
236 safe_browsing::V4Database::RegisterStoreFactoryForTest(nullptr); | |
237 safe_browsing::SafeBrowsingService::RegisterFactory(nullptr); | |
243 } | 238 } |
244 | 239 |
245 void SetUpOnMainThread() override { | 240 void SetUpOnMainThread() override { |
246 scoped_feature_toggle_.reset(new ScopedSubresourceFilterFeatureToggle( | 241 scoped_feature_toggle_.reset(new ScopedSubresourceFilterFeatureToggle( |
247 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, | 242 base::FeatureList::OVERRIDE_ENABLE_FEATURE, kActivationLevelEnabled, |
248 kActivationScopeActivationList, kActivationListPhishingInterstitial, | 243 kActivationScopeActivationList, kActivationListPhishingInterstitial, |
249 measure_performance_ ? "1" : "0", "" /* suppress_notifications */, | 244 measure_performance_ ? "1" : "0", "" /* suppress_notifications */, |
250 whitelist_site_on_reload_ ? "true" : "false")); | 245 whitelist_site_on_reload_ ? "true" : "false")); |
251 | 246 |
252 base::FilePath test_data_dir; | 247 base::FilePath test_data_dir; |
253 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 248 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
254 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 249 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
255 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); | 250 host_resolver()->AddSimulatedFailure("host-with-dns-lookup-failure"); |
256 host_resolver()->AddRule("*", "127.0.0.1"); | 251 host_resolver()->AddRule("*", "127.0.0.1"); |
257 content::SetupCrossSiteRedirector(embedded_test_server()); | 252 content::SetupCrossSiteRedirector(embedded_test_server()); |
258 ASSERT_TRUE(embedded_test_server()->Start()); | 253 ASSERT_TRUE(embedded_test_server()->Start()); |
259 } | 254 } |
260 | 255 |
261 GURL GetTestUrl(const std::string& relative_url) { | 256 GURL GetTestUrl(const std::string& relative_url) { |
262 return embedded_test_server()->base_url().Resolve(relative_url); | 257 return embedded_test_server()->base_url().Resolve(relative_url); |
263 } | 258 } |
264 | 259 |
260 void MarkUrlAsMatchingListWithId( | |
261 const GURL& bad_url, | |
262 const safe_browsing::ListIdentifier& list_id, | |
263 safe_browsing::ThreatPatternType threat_pattern_type) { | |
264 safe_browsing::FullHashInfo full_hash_info = | |
265 GetFullHashInfoWithMetadata(bad_url, list_id, threat_pattern_type); | |
266 v4_db_factory_->MarkPrefixAsBad(list_id, full_hash_info.full_hash); | |
267 v4_get_hash_factory_->AddToFullHashCache(full_hash_info); | |
268 } | |
269 | |
265 void ConfigureAsPhishingURL(const GURL& url) { | 270 void ConfigureAsPhishingURL(const GURL& url) { |
266 fake_safe_browsing_database_->AddBlacklistedURL( | 271 MarkUrlAsMatchingListWithId(url, safe_browsing::GetUrlSocEngId(), |
267 url, safe_browsing::SB_THREAT_TYPE_URL_PHISHING); | 272 safe_browsing::ThreatPatternType::NONE); |
273 } | |
274 | |
275 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { | |
276 MarkUrlAsMatchingListWithId(url, safe_browsing::GetUrlSubresourceFilterId(), | |
277 safe_browsing::ThreatPatternType::NONE); | |
268 } | 278 } |
269 | 279 |
270 content::WebContents* web_contents() { | 280 content::WebContents* web_contents() { |
271 return browser()->tab_strip_model()->GetActiveWebContents(); | 281 return browser()->tab_strip_model()->GetActiveWebContents(); |
272 } | 282 } |
273 | 283 |
274 content::RenderFrameHost* FindFrameByName(const std::string& name) { | 284 content::RenderFrameHost* FindFrameByName(const std::string& name) { |
275 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { | 285 for (content::RenderFrameHost* frame : web_contents()->GetAllFrames()) { |
276 if (frame->GetFrameName() == name) | 286 if (frame->GetFrameName() == name) |
277 return frame; | 287 return frame; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 | 343 |
334 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { | 344 void SetRulesetWithRules(const std::vector<proto::UrlRule>& rules) { |
335 TestRulesetPair test_ruleset_pair; | 345 TestRulesetPair test_ruleset_pair; |
336 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); | 346 ruleset_creator_.CreateRulesetWithRules(rules, &test_ruleset_pair); |
337 ASSERT_NO_FATAL_FAILURE( | 347 ASSERT_NO_FATAL_FAILURE( |
338 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); | 348 test_ruleset_publisher_.SetRuleset(test_ruleset_pair.unindexed)); |
339 } | 349 } |
340 | 350 |
341 private: | 351 private: |
342 TestRulesetCreator ruleset_creator_; | 352 TestRulesetCreator ruleset_creator_; |
343 safe_browsing::TestSafeBrowsingServiceFactory test_safe_browsing_factory_; | |
344 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; | |
345 | 353 |
346 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_; | 354 std::unique_ptr<ScopedSubresourceFilterFeatureToggle> scoped_feature_toggle_; |
347 TestRulesetPublisher test_ruleset_publisher_; | 355 TestRulesetPublisher test_ruleset_publisher_; |
348 const bool measure_performance_; | 356 const bool measure_performance_; |
349 const bool whitelist_site_on_reload_; | 357 const bool whitelist_site_on_reload_; |
350 | 358 |
359 std::unique_ptr<safe_browsing::TestSafeBrowsingServiceFactory> sb_factory_; | |
360 // Owned by the V4Database. | |
361 safe_browsing::TestV4DatabaseFactory* v4_db_factory_; | |
362 // Owned by the V4GetHashProtocolManager. | |
363 safe_browsing::TestV4GetHashProtocolManagerFactory* v4_get_hash_factory_; | |
364 | |
351 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTestImpl); | 365 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterBrowserTestImpl); |
352 }; | 366 }; |
353 | 367 |
354 class SubresourceFilterBrowserTest : public SubresourceFilterBrowserTestImpl { | 368 class SubresourceFilterBrowserTest : public SubresourceFilterBrowserTestImpl { |
355 public: | 369 public: |
356 SubresourceFilterBrowserTest() | 370 SubresourceFilterBrowserTest() |
357 : SubresourceFilterBrowserTestImpl(false, false) {} | 371 : SubresourceFilterBrowserTestImpl(false, false) {} |
358 }; | 372 }; |
359 | 373 |
360 // TODO(pkalinnikov): It should be possible to have only one fixture, i.e., | 374 // TODO(pkalinnikov): It should be possible to have only one fixture, i.e., |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; | 486 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; |
473 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false}; | 487 const std::vector<bool> kExpectScriptInFrameToLoad{false, true, false}; |
474 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames( | 488 ASSERT_NO_FATAL_FAILURE(ExpectParsedScriptElementLoadedStatusInFrames( |
475 kSubframeNames, kExpectScriptInFrameToLoad)); | 489 kSubframeNames, kExpectScriptInFrameToLoad)); |
476 | 490 |
477 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); | 491 tester.ExpectBucketCount(kSubresourceFilterPromptHistogram, true, 1); |
478 } | 492 } |
479 | 493 |
480 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, | 494 IN_PROC_BROWSER_TEST_F(SubresourceFilterBrowserTest, |
481 HistoryNavigationActivation) { | 495 HistoryNavigationActivation) { |
482 GURL url_without_activation(GetTestUrl(kTestFrameSetPath)); | 496 GURL url_with_activation(GetTestUrl(kTestFrameSetPath)); |
483 GURL url_with_activation( | 497 GURL url_without_activation( |
484 GetURLWithQuery(url_without_activation, "activation")); | 498 embedded_test_server()->GetURL("a.com", kTestFrameSetPath)); |
485 ConfigureAsPhishingURL(url_with_activation); | 499 ConfigureAsPhishingURL(url_with_activation); |
486 ASSERT_NO_FATAL_FAILURE( | 500 ASSERT_NO_FATAL_FAILURE( |
487 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | 501 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); |
488 | 502 |
489 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; | 503 const std::vector<const char*> kSubframeNames{"one", "two", "three"}; |
490 const std::vector<bool> kExpectScriptInFrameToLoadWithoutActivation{ | 504 const std::vector<bool> kExpectScriptInFrameToLoadWithoutActivation{ |
491 true, true, true}; | 505 true, true, true}; |
492 const std::vector<bool> kExpectScriptInFrameToLoadWithActivation{false, true, | 506 const std::vector<bool> kExpectScriptInFrameToLoadWithActivation{false, true, |
493 false}; | 507 false}; |
494 | 508 |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 internal::kHistogramSubresourceFilterActivationDecision, | 1014 internal::kHistogramSubresourceFilterActivationDecision, |
1001 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); | 1015 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); |
1002 | 1016 |
1003 tester.ExpectTotalCount( | 1017 tester.ExpectTotalCount( |
1004 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); | 1018 internal::kHistogramSubresourceFilterActivationDecisionReload, 1); |
1005 tester.ExpectBucketCount( | 1019 tester.ExpectBucketCount( |
1006 internal::kHistogramSubresourceFilterActivationDecisionReload, | 1020 internal::kHistogramSubresourceFilterActivationDecisionReload, |
1007 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); | 1021 static_cast<int>(ActivationDecision::URL_WHITELISTED), 1); |
1008 } | 1022 } |
1009 | 1023 |
1024 #if defined(GOOGLE_CHROME_BUILD) | |
1025 // This test is only enabled when GOOGLE_CHROME_BUILD is true because the store | |
1026 // that this test uses is only populated on GOOGLE_CHROME_BUILD builds. | |
1027 IN_PROC_BROWSER_TEST_F( | |
1028 SubresourceFilterBrowserTest, | |
1029 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyMatch) { | |
1030 ASSERT_NO_FATAL_FAILURE(SetRulesetToDisallowURLsWithPathSuffix( | |
1031 "suffix-that-does-not-match-anything")); | |
1032 | |
1033 GURL url(GetTestUrl("subresource_filter/frame_with_included_script.html")); | |
1034 ConfigureAsSubresourceFilterOnlyURL(url); | |
1035 | |
1036 base::HistogramTester tester; | |
1037 ui_test_utils::NavigateToURL(browser(), url); | |
1038 | |
1039 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
1040 std::string(kSubresourceFilterOnlySuffix)), | |
1041 ::testing::ElementsAre(base::Bucket(NO_REDIRECTS_HIT, 1))); | |
1042 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
1043 std::string(kSubresourceFilterOnlySuffix)), | |
1044 ::testing::ElementsAre(base::Bucket(1, 1))); | |
1045 } | |
1046 | |
1047 IN_PROC_BROWSER_TEST_F( | |
1048 SubresourceFilterBrowserTest, | |
1049 ExpectRedirectPatternHistogramsAreRecordedForSubresourceFilterOnlyRedirectMa tch) { | |
1050 ASSERT_NO_FATAL_FAILURE( | |
1051 SetRulesetToDisallowURLsWithPathSuffix("included_script.js")); | |
1052 const std::string initial_host("a.com"); | |
1053 const std::string redirected_host("b.com"); | |
1054 | |
1055 GURL redirect_url(embedded_test_server()->GetURL( | |
1056 redirected_host, "/subresource_filter/frame_with_included_script.html")); | |
1057 GURL url(embedded_test_server()->GetURL( | |
1058 initial_host, "/server-redirect?" + redirect_url.spec())); | |
1059 | |
1060 ConfigureAsSubresourceFilterOnlyURL(url.GetOrigin()); | |
1061 base::HistogramTester tester; | |
1062 ui_test_utils::NavigateToURL(browser(), url); | |
1063 EXPECT_THAT(tester.GetAllSamples(std::string(kMatchesPatternHistogramName) + | |
engedy
2017/03/21 13:44:16
nit: Could you please add a comment to explain tha
melandory
2017/03/24 15:49:27
You mean that the real list is empty?
| |
1064 std::string(kSubresourceFilterOnlySuffix)), | |
1065 ::testing::IsEmpty()); | |
1066 | |
1067 EXPECT_THAT(tester.GetAllSamples(std::string(kNavigationChainSize) + | |
1068 std::string(kSubresourceFilterOnlySuffix)), | |
1069 ::testing::IsEmpty()); | |
1070 } | |
1071 #endif | |
1072 | |
1010 } // namespace subresource_filter | 1073 } // namespace subresource_filter |
engedy
2017/03/21 13:44:16
We should have at least one test that verifies end
melandory
2017/03/24 15:49:27
Done.
| |
OLD | NEW |