OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/subresource_filter_safe_
browsing_activation_throttle.h" | 5 #include "components/subresource_filter/content/browser/subresource_filter_safe_
browsing_activation_throttle.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." | 46 "SubresourceFilter.PageLoad.RedirectChainMatchPattern." |
47 "SubresourceFilterOnly"; | 47 "SubresourceFilterOnly"; |
48 const char kNavigationChainSizeSubresourceFilterSuffix[] = | 48 const char kNavigationChainSizeSubresourceFilterSuffix[] = |
49 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly"; | 49 "SubresourceFilter.PageLoad.RedirectChainLength.SubresourceFilterOnly"; |
50 const char kSafeBrowsingNavigationDelay[] = | 50 const char kSafeBrowsingNavigationDelay[] = |
51 "SubresourceFilter.PageLoad.SafeBrowsingDelay"; | 51 "SubresourceFilter.PageLoad.SafeBrowsingDelay"; |
52 const char kSafeBrowsingNavigationDelayNoSpeculation[] = | 52 const char kSafeBrowsingNavigationDelayNoSpeculation[] = |
53 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation"; | 53 "SubresourceFilter.PageLoad.SafeBrowsingDelay.NoRedirectSpeculation"; |
54 const char kSafeBrowsingCheckTime[] = | 54 const char kSafeBrowsingCheckTime[] = |
55 "SubresourceFilter.SafeBrowsing.CheckTime"; | 55 "SubresourceFilter.SafeBrowsing.CheckTime"; |
56 | 56 const char kMatchesPatternHistogramName[] = |
57 // Human readable representation of expected redirect chain match patterns. | 57 "SubresourceFilter.PageLoad.FinalURLMatch."; |
58 // The explanations for the buckets given for the following redirect chain: | 58 const char kNavigationChainSize[] = |
59 // A->B->C->D, where A is initial URL and D is a final URL. | 59 "SubresourceFilter.PageLoad.RedirectChainLength."; |
60 enum RedirectChainMatchPattern { | |
61 EMPTY, // No histograms were recorded. | |
62 F0M0L1, // D is a Safe Browsing match. | |
63 F0M1L0, // B or C, or both are Safe Browsing matches. | |
64 F0M1L1, // B or C, or both and D are Safe Browsing matches. | |
65 F1M0L0, // A is Safe Browsing match | |
66 F1M0L1, // A and D are Safe Browsing matches. | |
67 F1M1L0, // B and/or C and A are Safe Browsing matches. | |
68 F1M1L1, // B and/or C and A and D are Safe Browsing matches. | |
69 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects | |
70 // has happened, and this URL was a Safe Browsing hit. | |
71 NUM_HIT_PATTERNS, | |
72 }; | |
73 | 60 |
74 class MockSubresourceFilterClient | 61 class MockSubresourceFilterClient |
75 : public subresource_filter::SubresourceFilterClient { | 62 : public subresource_filter::SubresourceFilterClient { |
76 public: | 63 public: |
77 MockSubresourceFilterClient() {} | 64 MockSubresourceFilterClient() {} |
78 | 65 |
79 ~MockSubresourceFilterClient() override = default; | 66 ~MockSubresourceFilterClient() override = default; |
80 | 67 |
81 MOCK_METHOD1(ToggleNotificationVisibility, void(bool)); | 68 MOCK_METHOD1(ToggleNotificationVisibility, void(bool)); |
82 MOCK_METHOD2(OnPageActivationComputed, | 69 MOCK_METHOD2(OnPageActivationComputed, |
(...skipping 24 matching lines...) Expand all Loading... |
107 return content::NavigationThrottle::PROCEED; | 94 return content::NavigationThrottle::PROCEED; |
108 } | 95 } |
109 const char* GetNameForLogging() override { | 96 const char* GetNameForLogging() override { |
110 return "TestForwardingNavigationThrottle"; | 97 return "TestForwardingNavigationThrottle"; |
111 } | 98 } |
112 | 99 |
113 private: | 100 private: |
114 DISALLOW_COPY_AND_ASSIGN(TestForwardingNavigationThrottle); | 101 DISALLOW_COPY_AND_ASSIGN(TestForwardingNavigationThrottle); |
115 }; | 102 }; |
116 | 103 |
| 104 std::string GetSuffixForList(const ActivationList& type) { |
| 105 switch (type) { |
| 106 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: |
| 107 return "SocialEngineeringAdsInterstitial"; |
| 108 case ActivationList::PHISHING_INTERSTITIAL: |
| 109 return "PhishingInterstital"; |
| 110 case ActivationList::SUBRESOURCE_FILTER: |
| 111 return "SubresourceFilterOnly"; |
| 112 case ActivationList::NONE: |
| 113 return std::string(); |
| 114 } |
| 115 return std::string(); |
| 116 } |
| 117 |
| 118 struct ActivationListTestData { |
| 119 const char* const activation_list; |
| 120 ActivationList activation_list_type; |
| 121 safe_browsing::SBThreatType threat_type; |
| 122 safe_browsing::ThreatPatternType threat_type_metadata; |
| 123 }; |
| 124 |
| 125 const ActivationListTestData kActivationListTestData[] = { |
| 126 {subresource_filter::kActivationListSocialEngineeringAdsInterstitial, |
| 127 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, |
| 128 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 129 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
| 130 {subresource_filter::kActivationListPhishingInterstitial, |
| 131 ActivationList::PHISHING_INTERSTITIAL, |
| 132 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
| 133 safe_browsing::ThreatPatternType::NONE}, |
| 134 {subresource_filter::kActivationListSubresourceFilter, |
| 135 ActivationList::SUBRESOURCE_FILTER, |
| 136 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
| 137 safe_browsing::ThreatPatternType::NONE}, |
| 138 }; |
| 139 |
| 140 void ExpectSampleForSuffix(const std::string& suffix, |
| 141 const std::string& match_suffix, |
| 142 const base::HistogramTester& tester) { |
| 143 tester.ExpectUniqueSample(kMatchesPatternHistogramName + suffix, |
| 144 (suffix == match_suffix), 1); |
| 145 } |
| 146 |
117 } // namespace | 147 } // namespace |
118 | 148 |
119 class SubresourceFilterSafeBrowsingActivationThrottleTest | 149 class SubresourceFilterSafeBrowsingActivationThrottleTest |
120 : public content::RenderViewHostTestHarness, | 150 : public content::RenderViewHostTestHarness, |
121 public content::WebContentsObserver { | 151 public content::WebContentsObserver { |
122 public: | 152 public: |
123 SubresourceFilterSafeBrowsingActivationThrottleTest() | 153 SubresourceFilterSafeBrowsingActivationThrottleTest() |
124 : field_trial_list_(nullptr) {} | 154 : field_trial_list_(nullptr) {} |
125 ~SubresourceFilterSafeBrowsingActivationThrottleTest() override {} | 155 ~SubresourceFilterSafeBrowsingActivationThrottleTest() override {} |
126 | 156 |
127 void SetUp() override { | 157 void SetUp() override { |
128 content::RenderViewHostTestHarness::SetUp(); | 158 content::RenderViewHostTestHarness::SetUp(); |
129 scoped_configuration_.ResetConfiguration(Configuration( | 159 Configure(); |
130 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, | |
131 ActivationList::SUBRESOURCE_FILTER)); | |
132 test_io_task_runner_ = new base::TestMockTimeTaskRunner(); | 160 test_io_task_runner_ = new base::TestMockTimeTaskRunner(); |
133 // Note: Using NiceMock to allow uninteresting calls and suppress warnings. | 161 // Note: Using NiceMock to allow uninteresting calls and suppress warnings. |
134 client_ = | 162 client_ = |
135 base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>(); | 163 base::MakeUnique<::testing::NiceMock<MockSubresourceFilterClient>>(); |
136 ContentSubresourceFilterDriverFactory::CreateForWebContents( | 164 ContentSubresourceFilterDriverFactory::CreateForWebContents( |
137 RenderViewHostTestHarness::web_contents(), client_.get()); | 165 RenderViewHostTestHarness::web_contents(), client_.get()); |
138 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); | 166 fake_safe_browsing_database_ = new FakeSafeBrowsingDatabaseManager(); |
139 NavigateAndCommit(GURL("https://test.com")); | 167 NavigateAndCommit(GURL("https://test.com")); |
140 Observe(RenderViewHostTestHarness::web_contents()); | 168 Observe(RenderViewHostTestHarness::web_contents()); |
141 } | 169 } |
142 | 170 |
| 171 virtual void Configure() { |
| 172 scoped_configuration_.ResetConfiguration(Configuration( |
| 173 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, |
| 174 ActivationList::SUBRESOURCE_FILTER)); |
| 175 } |
| 176 |
143 void TearDown() override { | 177 void TearDown() override { |
144 RunUntilIdle(); | 178 RunUntilIdle(); |
145 content::RenderViewHostTestHarness::TearDown(); | 179 content::RenderViewHostTestHarness::TearDown(); |
146 } | 180 } |
147 | 181 |
148 ContentSubresourceFilterDriverFactory* factory() { | 182 ContentSubresourceFilterDriverFactory* factory() { |
149 return ContentSubresourceFilterDriverFactory::FromWebContents( | 183 return ContentSubresourceFilterDriverFactory::FromWebContents( |
150 RenderViewHostTestHarness::web_contents()); | 184 RenderViewHostTestHarness::web_contents()); |
151 } | 185 } |
152 | 186 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void SimulateCommitAndExpectProceed() { | 240 void SimulateCommitAndExpectProceed() { |
207 EXPECT_EQ(content::NavigationThrottle::PROCEED, SimulateCommit()); | 241 EXPECT_EQ(content::NavigationThrottle::PROCEED, SimulateCommit()); |
208 } | 242 } |
209 | 243 |
210 void CreateTestNavigationForMainFrame(const GURL& first_url) { | 244 void CreateTestNavigationForMainFrame(const GURL& first_url) { |
211 navigation_simulator_ = | 245 navigation_simulator_ = |
212 content::NavigationSimulator::CreateRendererInitiated(first_url, | 246 content::NavigationSimulator::CreateRendererInitiated(first_url, |
213 main_rfh()); | 247 main_rfh()); |
214 } | 248 } |
215 | 249 |
216 void ConfigureAsSubresourceFilterOnlyURL(const GURL& url) { | 250 void ConfigureForMatch(const GURL& url, |
217 fake_safe_browsing_database_->AddBlacklistedUrl( | 251 safe_browsing::SBThreatType pattern_type = |
218 url, safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER); | 252 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
| 253 safe_browsing::ThreatPatternType metadata = |
| 254 safe_browsing::ThreatPatternType::NONE) { |
| 255 fake_safe_browsing_database_->AddBlacklistedUrl(url, pattern_type, |
| 256 metadata); |
219 } | 257 } |
220 | 258 |
221 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); } | 259 void SimulateTimeout() { fake_safe_browsing_database_->SimulateTimeout(); } |
222 | 260 |
223 void RunUntilIdle() { | 261 void RunUntilIdle() { |
224 test_io_task_runner_->RunUntilIdle(); | 262 test_io_task_runner_->RunUntilIdle(); |
225 base::RunLoop().RunUntilIdle(); | 263 base::RunLoop().RunUntilIdle(); |
226 } | 264 } |
227 | 265 |
228 const base::HistogramTester& tester() const { return tester_; } | 266 const base::HistogramTester& tester() const { return tester_; } |
229 | 267 |
230 base::TestMockTimeTaskRunner* test_io_task_runner() const { | 268 base::TestMockTimeTaskRunner* test_io_task_runner() const { |
231 return test_io_task_runner_.get(); | 269 return test_io_task_runner_.get(); |
232 } | 270 } |
233 | 271 |
| 272 testing::ScopedSubresourceFilterConfigurator* scoped_configuration() { |
| 273 return &scoped_configuration_; |
| 274 } |
| 275 |
234 private: | 276 private: |
235 base::FieldTrialList field_trial_list_; | 277 base::FieldTrialList field_trial_list_; |
236 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; | 278 testing::ScopedSubresourceFilterConfigurator scoped_configuration_; |
237 scoped_refptr<base::TestMockTimeTaskRunner> test_io_task_runner_; | 279 scoped_refptr<base::TestMockTimeTaskRunner> test_io_task_runner_; |
238 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; | 280 std::unique_ptr<content::NavigationSimulator> navigation_simulator_; |
239 std::unique_ptr<SubresourceFilterClient> client_; | 281 std::unique_ptr<SubresourceFilterClient> client_; |
240 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; | 282 scoped_refptr<FakeSafeBrowsingDatabaseManager> fake_safe_browsing_database_; |
241 base::HistogramTester tester_; | 283 base::HistogramTester tester_; |
242 | 284 |
243 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest); | 285 DISALLOW_COPY_AND_ASSIGN(SubresourceFilterSafeBrowsingActivationThrottleTest); |
244 }; | 286 }; |
245 | 287 |
| 288 class SubresourceFilterSafeBrowsingActivationThrottleParamTest |
| 289 : public SubresourceFilterSafeBrowsingActivationThrottleTest, |
| 290 public ::testing::WithParamInterface<ActivationListTestData> { |
| 291 public: |
| 292 SubresourceFilterSafeBrowsingActivationThrottleParamTest() {} |
| 293 ~SubresourceFilterSafeBrowsingActivationThrottleParamTest() override {} |
| 294 |
| 295 void Configure() override { |
| 296 const ActivationListTestData& test_data = GetParam(); |
| 297 scoped_configuration()->ResetConfiguration(Configuration( |
| 298 ActivationLevel::ENABLED, ActivationScope::ACTIVATION_LIST, |
| 299 test_data.activation_list_type)); |
| 300 } |
| 301 |
| 302 void ConfigureForMatchParam(const GURL& url) { |
| 303 const ActivationListTestData& test_data = GetParam(); |
| 304 ConfigureForMatch(url, test_data.threat_type, |
| 305 test_data.threat_type_metadata); |
| 306 } |
| 307 |
| 308 private: |
| 309 DISALLOW_COPY_AND_ASSIGN( |
| 310 SubresourceFilterSafeBrowsingActivationThrottleParamTest); |
| 311 }; |
| 312 |
246 class SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling | 313 class SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling |
247 : public SubresourceFilterSafeBrowsingActivationThrottleTest, | 314 : public SubresourceFilterSafeBrowsingActivationThrottleTest, |
248 public ::testing::WithParamInterface< | 315 public ::testing::WithParamInterface< |
249 std::tuple<content::CancellingNavigationThrottle::CancelTime, | 316 std::tuple<content::CancellingNavigationThrottle::CancelTime, |
250 content::CancellingNavigationThrottle::ResultSynchrony>> { | 317 content::CancellingNavigationThrottle::ResultSynchrony>> { |
251 public: | 318 public: |
252 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling() { | 319 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling() { |
253 std::tie(cancel_time_, result_sync_) = GetParam(); | 320 std::tie(cancel_time_, result_sync_) = GetParam(); |
254 } | 321 } |
255 ~SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling() | 322 ~SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling() |
(...skipping 16 matching lines...) Expand all Loading... |
272 } | 339 } |
273 | 340 |
274 private: | 341 private: |
275 content::CancellingNavigationThrottle::CancelTime cancel_time_; | 342 content::CancellingNavigationThrottle::CancelTime cancel_time_; |
276 content::CancellingNavigationThrottle::ResultSynchrony result_sync_; | 343 content::CancellingNavigationThrottle::ResultSynchrony result_sync_; |
277 | 344 |
278 DISALLOW_COPY_AND_ASSIGN( | 345 DISALLOW_COPY_AND_ASSIGN( |
279 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling); | 346 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling); |
280 }; | 347 }; |
281 | 348 |
282 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 349 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
283 ListNotMatched_NoActivation) { | 350 ListNotMatched_NoActivation) { |
| 351 const ActivationListTestData& test_data = GetParam(); |
284 const GURL url(kURL); | 352 const GURL url(kURL); |
| 353 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
285 CreateTestNavigationForMainFrame(url); | 354 CreateTestNavigationForMainFrame(url); |
286 SimulateStartAndExpectProceed(); | 355 SimulateStartAndExpectProceed(); |
287 SimulateCommitAndExpectProceed(); | 356 SimulateCommitAndExpectProceed(); |
288 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: | 357 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: |
289 ACTIVATION_CONDITIONS_NOT_MET, | 358 ACTIVATION_CONDITIONS_NOT_MET, |
290 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 359 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
291 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, | 360 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", std::string(), |
292 0); | 361 tester()); |
293 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); | 362 ExpectSampleForSuffix("PhishingInterstital", std::string(), tester()); |
| 363 ExpectSampleForSuffix("SubresourceFilterOnly", std::string(), tester()); |
| 364 |
294 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 1); | 365 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 1); |
295 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); | 366 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); |
296 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 1); | 367 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 1); |
| 368 tester().ExpectTotalCount(kNavigationChainSize + suffix, 0); |
297 } | 369 } |
298 | 370 |
299 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 371 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
300 ListMatched_Activation) { | 372 ListMatched_Activation) { |
| 373 const ActivationListTestData& test_data = GetParam(); |
301 const GURL url(kURL); | 374 const GURL url(kURL); |
302 ConfigureAsSubresourceFilterOnlyURL(url); | 375 ConfigureForMatchParam(url); |
303 CreateTestNavigationForMainFrame(url); | 376 CreateTestNavigationForMainFrame(url); |
304 SimulateStartAndExpectProceed(); | 377 SimulateStartAndExpectProceed(); |
305 SimulateCommitAndExpectProceed(); | 378 SimulateCommitAndExpectProceed(); |
306 EXPECT_EQ( | 379 EXPECT_EQ( |
307 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, | 380 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, |
308 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 381 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
309 tester().ExpectUniqueSample( | 382 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
310 kMatchesPatternHistogramNameSubresourceFilterSuffix, NO_REDIRECTS_HIT, 1); | 383 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester()); |
311 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 1, | 384 ExpectSampleForSuffix("PhishingInterstital", suffix, tester()); |
312 1); | 385 ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester()); |
| 386 tester().ExpectUniqueSample(kNavigationChainSize + suffix, 1, 1); |
313 } | 387 } |
314 | 388 |
315 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 389 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
316 ListNotMatchedAfterRedirect_NoActivation) { | 390 ListNotMatchedAfterRedirect_NoActivation) { |
| 391 const ActivationListTestData& test_data = GetParam(); |
317 const GURL url(kURL); | 392 const GURL url(kURL); |
| 393 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
318 CreateTestNavigationForMainFrame(url); | 394 CreateTestNavigationForMainFrame(url); |
319 SimulateStartAndExpectProceed(); | 395 SimulateStartAndExpectProceed(); |
320 SimulateRedirectAndExpectProceed(GURL(kRedirectURL)); | 396 SimulateRedirectAndExpectProceed(GURL(kRedirectURL)); |
321 SimulateCommitAndExpectProceed(); | 397 SimulateCommitAndExpectProceed(); |
322 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: | 398 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: |
323 ACTIVATION_CONDITIONS_NOT_MET, | 399 ACTIVATION_CONDITIONS_NOT_MET, |
324 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 400 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
325 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, | 401 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", std::string(), |
326 0); | 402 tester()); |
327 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); | 403 ExpectSampleForSuffix("PhishingInterstital", std::string(), tester()); |
| 404 ExpectSampleForSuffix("SubresourceFilterOnly", std::string(), tester()); |
| 405 tester().ExpectTotalCount(kNavigationChainSize + suffix, 0); |
328 } | 406 } |
329 | 407 |
330 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 408 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
331 ListMatchedAfterRedirect_Activation) { | 409 ListMatchedAfterRedirect_Activation) { |
| 410 const ActivationListTestData& test_data = GetParam(); |
332 const GURL url(kURL); | 411 const GURL url(kURL); |
333 ConfigureAsSubresourceFilterOnlyURL(GURL(kRedirectURL)); | 412 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
| 413 ConfigureForMatchParam(GURL(kRedirectURL)); |
334 CreateTestNavigationForMainFrame(url); | 414 CreateTestNavigationForMainFrame(url); |
335 SimulateStartAndExpectProceed(); | 415 SimulateStartAndExpectProceed(); |
336 SimulateRedirectAndExpectProceed(GURL(kRedirectURL)); | 416 SimulateRedirectAndExpectProceed(GURL(kRedirectURL)); |
337 SimulateCommitAndExpectProceed(); | 417 SimulateCommitAndExpectProceed(); |
338 EXPECT_EQ( | 418 EXPECT_EQ( |
339 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, | 419 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, |
340 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 420 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
341 tester().ExpectUniqueSample( | 421 tester().ExpectUniqueSample(kNavigationChainSize + suffix, 2, 1); |
342 kMatchesPatternHistogramNameSubresourceFilterSuffix, F0M0L1, 1); | 422 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester()); |
343 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2, | 423 ExpectSampleForSuffix("PhishingInterstital", suffix, tester()); |
344 1); | 424 ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester()); |
345 } | 425 } |
346 | 426 |
347 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 427 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
348 ListNotMatchedAndTimeout_NoActivation) { | 428 ListNotMatchedAndTimeout_NoActivation) { |
| 429 const ActivationListTestData& test_data = GetParam(); |
349 const GURL url(kURL); | 430 const GURL url(kURL); |
| 431 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
350 SimulateTimeout(); | 432 SimulateTimeout(); |
351 CreateTestNavigationForMainFrame(url); | 433 CreateTestNavigationForMainFrame(url); |
352 SimulateStartAndExpectProceed(); | 434 SimulateStartAndExpectProceed(); |
353 | 435 |
354 // Flush the pending tasks on the IO thread, so the delayed task surely gets | 436 // Flush the pending tasks on the IO thread, so the delayed task surely gets |
355 // posted. | 437 // posted. |
356 test_io_task_runner()->RunUntilIdle(); | 438 test_io_task_runner()->RunUntilIdle(); |
357 | 439 |
358 // Expect one delayed task, and fast forward time. | 440 // Expect one delayed task, and fast forward time. |
359 base::TimeDelta expected_delay = | 441 base::TimeDelta expected_delay = |
360 SubresourceFilterSafeBrowsingClientRequest::kCheckURLTimeout; | 442 SubresourceFilterSafeBrowsingClientRequest::kCheckURLTimeout; |
361 EXPECT_EQ(expected_delay, test_io_task_runner()->NextPendingTaskDelay()); | 443 EXPECT_EQ(expected_delay, test_io_task_runner()->NextPendingTaskDelay()); |
362 test_io_task_runner()->FastForwardBy(expected_delay); | 444 test_io_task_runner()->FastForwardBy(expected_delay); |
363 SimulateCommitAndExpectProceed(); | 445 SimulateCommitAndExpectProceed(); |
364 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: | 446 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: |
365 ACTIVATION_CONDITIONS_NOT_MET, | 447 ACTIVATION_CONDITIONS_NOT_MET, |
366 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 448 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
367 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, | 449 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, |
368 0); | 450 0); |
369 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); | 451 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); |
370 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 1); | 452 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 1); |
371 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); | 453 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); |
372 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 1); | 454 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 1); |
373 } | 455 } |
374 | 456 |
375 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 457 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
376 ListMatchedOnStart_NoDelay) { | 458 ListMatchedOnStart_NoDelay) { |
| 459 const ActivationListTestData& test_data = GetParam(); |
377 const GURL url(kURL); | 460 const GURL url(kURL); |
378 ConfigureAsSubresourceFilterOnlyURL(url); | 461 ConfigureForMatchParam(url); |
379 CreateTestNavigationForMainFrame(url); | 462 CreateTestNavigationForMainFrame(url); |
380 SimulateStartAndExpectProceed(); | 463 SimulateStartAndExpectProceed(); |
381 | 464 |
382 // Get the database result back before commit. | 465 // Get the database result back before commit. |
383 RunUntilIdle(); | 466 RunUntilIdle(); |
384 | 467 |
385 SimulateCommitAndExpectProceed(); | 468 SimulateCommitAndExpectProceed(); |
386 EXPECT_EQ( | 469 EXPECT_EQ( |
387 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, | 470 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, |
388 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 471 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
389 tester().ExpectUniqueSample( | 472 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
390 kMatchesPatternHistogramNameSubresourceFilterSuffix, NO_REDIRECTS_HIT, 1); | 473 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester()); |
391 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 1, | 474 ExpectSampleForSuffix("PhishingInterstital", suffix, tester()); |
392 1); | 475 ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester()); |
| 476 tester().ExpectUniqueSample(kNavigationChainSize + suffix, 1, 1); |
| 477 |
393 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay, | 478 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay, |
394 base::TimeDelta::FromMilliseconds(0), 1); | 479 base::TimeDelta::FromMilliseconds(0), 1); |
395 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); | 480 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); |
396 } | 481 } |
397 | 482 |
398 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 483 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
399 ListMatchedOnRedirect_NoDelay) { | 484 ListMatchedOnRedirect_NoDelay) { |
| 485 const ActivationListTestData& test_data = GetParam(); |
400 const GURL url(kURL); | 486 const GURL url(kURL); |
401 const GURL redirect_url(kRedirectURL); | 487 const GURL redirect_url(kRedirectURL); |
402 ConfigureAsSubresourceFilterOnlyURL(redirect_url); | 488 ConfigureForMatchParam(redirect_url); |
403 CreateTestNavigationForMainFrame(url); | 489 CreateTestNavigationForMainFrame(url); |
404 | 490 |
405 SimulateStartAndExpectProceed(); | 491 SimulateStartAndExpectProceed(); |
406 SimulateRedirectAndExpectProceed(redirect_url); | 492 SimulateRedirectAndExpectProceed(redirect_url); |
407 | 493 |
408 // Get the database result back before commit. | 494 // Get the database result back before commit. |
409 RunUntilIdle(); | 495 RunUntilIdle(); |
410 | 496 |
411 SimulateCommitAndExpectProceed(); | 497 SimulateCommitAndExpectProceed(); |
412 EXPECT_EQ( | 498 EXPECT_EQ( |
413 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, | 499 ContentSubresourceFilterDriverFactory::ActivationDecision::ACTIVATED, |
414 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 500 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
415 tester().ExpectUniqueSample( | 501 const std::string suffix(GetSuffixForList(test_data.activation_list_type)); |
416 kMatchesPatternHistogramNameSubresourceFilterSuffix, F0M0L1, 1); | 502 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester()); |
417 tester().ExpectUniqueSample(kNavigationChainSizeSubresourceFilterSuffix, 2, | 503 ExpectSampleForSuffix("PhishingInterstital", suffix, tester()); |
418 1); | 504 ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester()); |
| 505 tester().ExpectUniqueSample(kNavigationChainSize + suffix, 2, 1); |
| 506 |
419 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay, | 507 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay, |
420 base::TimeDelta::FromMilliseconds(0), 1); | 508 base::TimeDelta::FromMilliseconds(0), 1); |
421 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); | 509 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); |
422 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 2); | 510 tester().ExpectTotalCount(kSafeBrowsingCheckTime, 2); |
423 } | 511 } |
424 | 512 |
425 TEST_F(SubresourceFilterSafeBrowsingActivationThrottleTest, | 513 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
426 ListMatchedOnStartWithRedirect_NoActivation) { | 514 ListMatchedOnStartWithRedirect_NoActivation) { |
427 const GURL url(kURL); | 515 const GURL url(kURL); |
428 const GURL redirect_url(kRedirectURL); | 516 const GURL redirect_url(kRedirectURL); |
429 ConfigureAsSubresourceFilterOnlyURL(url); | 517 ConfigureForMatchParam(url); |
430 CreateTestNavigationForMainFrame(url); | 518 CreateTestNavigationForMainFrame(url); |
431 | 519 |
432 // These two lines also test how the database client reacts to two requests | 520 // These two lines also test how the database client reacts to two requests |
433 // happening one after another. | 521 // happening one after another. |
434 SimulateStartAndExpectProceed(); | 522 SimulateStartAndExpectProceed(); |
435 SimulateRedirectAndExpectProceed(redirect_url); | 523 SimulateRedirectAndExpectProceed(redirect_url); |
436 | 524 |
437 // Get the database result back before commit. | 525 // Get the database result back before commit. |
438 RunUntilIdle(); | 526 RunUntilIdle(); |
439 | 527 |
440 SimulateCommitAndExpectProceed(); | 528 SimulateCommitAndExpectProceed(); |
441 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: | 529 EXPECT_EQ(ContentSubresourceFilterDriverFactory::ActivationDecision:: |
442 ACTIVATION_CONDITIONS_NOT_MET, | 530 ACTIVATION_CONDITIONS_NOT_MET, |
443 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 531 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
444 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, | 532 tester().ExpectTotalCount(kMatchesPatternHistogramNameSubresourceFilterSuffix, |
445 0); | 533 0); |
446 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); | 534 tester().ExpectTotalCount(kNavigationChainSizeSubresourceFilterSuffix, 0); |
447 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay, | 535 tester().ExpectTimeBucketCount(kSafeBrowsingNavigationDelay, |
448 base::TimeDelta::FromMilliseconds(0), 1); | 536 base::TimeDelta::FromMilliseconds(0), 1); |
449 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); | 537 tester().ExpectTotalCount(kSafeBrowsingNavigationDelayNoSpeculation, 1); |
450 } | 538 } |
451 | 539 |
452 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling, | 540 TEST_P(SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling, |
453 Cancel) { | 541 Cancel) { |
454 const GURL url(kURL); | 542 const GURL url(kURL); |
455 SCOPED_TRACE(::testing::Message() << "CancelTime: " << cancel_time() | 543 SCOPED_TRACE(::testing::Message() << "CancelTime: " << cancel_time() |
456 << " ResultSynchrony: " << result_sync()); | 544 << " ResultSynchrony: " << result_sync()); |
457 ConfigureAsSubresourceFilterOnlyURL(url); | 545 ConfigureForMatch(url); |
458 CreateTestNavigationForMainFrame(url); | 546 CreateTestNavigationForMainFrame(url); |
459 | 547 |
460 content::NavigationThrottle::ThrottleCheckResult result = SimulateStart(); | 548 content::NavigationThrottle::ThrottleCheckResult result = SimulateStart(); |
461 if (cancel_time() == | 549 if (cancel_time() == |
462 content::CancellingNavigationThrottle::WILL_START_REQUEST) { | 550 content::CancellingNavigationThrottle::WILL_START_REQUEST) { |
463 EXPECT_EQ(content::NavigationThrottle::CANCEL, result); | 551 EXPECT_EQ(content::NavigationThrottle::CANCEL, result); |
464 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0); | 552 tester().ExpectTotalCount(kSafeBrowsingNavigationDelay, 0); |
465 return; | 553 return; |
466 } | 554 } |
467 EXPECT_EQ(content::NavigationThrottle::PROCEED, result); | 555 EXPECT_EQ(content::NavigationThrottle::PROCEED, result); |
(...skipping 19 matching lines...) Expand all Loading... |
487 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling, | 575 SubresourceFilterSafeBrowsingActivationThrottleTestWithCancelling, |
488 ::testing::Combine( | 576 ::testing::Combine( |
489 ::testing::Values( | 577 ::testing::Values( |
490 content::CancellingNavigationThrottle::WILL_START_REQUEST, | 578 content::CancellingNavigationThrottle::WILL_START_REQUEST, |
491 content::CancellingNavigationThrottle::WILL_REDIRECT_REQUEST, | 579 content::CancellingNavigationThrottle::WILL_REDIRECT_REQUEST, |
492 content::CancellingNavigationThrottle::WILL_PROCESS_RESPONSE), | 580 content::CancellingNavigationThrottle::WILL_PROCESS_RESPONSE), |
493 ::testing::Values( | 581 ::testing::Values( |
494 content::CancellingNavigationThrottle::SYNCHRONOUS, | 582 content::CancellingNavigationThrottle::SYNCHRONOUS, |
495 content::CancellingNavigationThrottle::ASYNCHRONOUS))); | 583 content::CancellingNavigationThrottle::ASYNCHRONOUS))); |
496 | 584 |
| 585 INSTANTIATE_TEST_CASE_P( |
| 586 ActivationLevelTest, |
| 587 SubresourceFilterSafeBrowsingActivationThrottleParamTest, |
| 588 ::testing::ValuesIn(kActivationListTestData)); |
| 589 |
497 } // namespace subresource_filter | 590 } // namespace subresource_filter |
OLD | NEW |