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 "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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc"; | 45 const char kExampleUrlWithParams[] = "https://example.com/soceng?q=engsoc"; |
46 const char kExampleUrl[] = "https://example.com"; | 46 const char kExampleUrl[] = "https://example.com"; |
47 const char kExampleLoginUrl[] = "https://example.com/login"; | 47 const char kExampleLoginUrl[] = "https://example.com/login"; |
48 const char kUrlA[] = "https://example_a.com"; | 48 const char kUrlA[] = "https://example_a.com"; |
49 const char kUrlB[] = "https://example_b.com"; | 49 const char kUrlB[] = "https://example_b.com"; |
50 const char kUrlC[] = "https://example_c.com"; | 50 const char kUrlC[] = "https://example_c.com"; |
51 const char kUrlD[] = "https://example_d.com"; | 51 const char kUrlD[] = "https://example_d.com"; |
52 const char kSubframeName[] = "Child"; | 52 const char kSubframeName[] = "Child"; |
53 const char kDisallowedUrl[] = "https://example.com/disallowed.html"; | 53 const char kDisallowedUrl[] = "https://example.com/disallowed.html"; |
54 | 54 |
55 const char kMatchesPatternHistogramName[] = | 55 const char kMatchesHistogramName[] = |
56 "SubresourceFilter.PageLoad.RedirectChainMatchPattern."; | 56 "SubresourceFilter.PageLoad.FinalURLMatch."; |
57 const char kNavigationChainSize[] = | 57 const char kNavigationChainSize[] = |
58 "SubresourceFilter.PageLoad.RedirectChainLength."; | 58 "SubresourceFilter.PageLoad.RedirectChainLength."; |
59 | 59 |
60 // Human readable representation of expected redirect chain match patterns. | 60 // Enum helps to setup test cases. In future, when checking first URL in the |
61 // The explanations for the buckets given for the following redirect chain: | 61 // redirect chain is implemented, the enum will be expanded. |
62 // A->B->C->D, where A is initial URL and D is a final URL. | 62 enum RecordedHistograms { |
63 enum RedirectChainMatchPattern { | 63 NO_HISTOGRAMS, |
64 EMPTY, // No histograms were recorded. | 64 FINAL_URL_MATCHES, |
65 F0M0L1, // D is a Safe Browsing match. | 65 REDIRECT_CHAIN_LENGTH, |
66 F0M1L0, // B or C, or both are Safe Browsing matches. | |
67 F0M1L1, // B or C, or both and D are Safe Browsing matches. | |
68 F1M0L0, // A is Safe Browsing match | |
69 F1M0L1, // A and D are Safe Browsing matches. | |
70 F1M1L0, // B and/or C and A are Safe Browsing matches. | |
71 F1M1L1, // B and/or C and A and D are Safe Browsing matches. | |
72 NO_REDIRECTS_HIT, // Redirect chain consists of single URL, aka no redirects | |
73 // has happened, and this URL was a Safe Browsing hit. | |
74 NUM_HIT_PATTERNS, | |
75 }; | 66 }; |
76 | 67 |
77 std::string GetSuffixForList(const ActivationList& type) { | 68 std::string GetSuffixForList(const ActivationList& type) { |
78 switch (type) { | 69 switch (type) { |
79 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: | 70 case ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL: |
80 return "SocialEngineeringAdsInterstitial"; | 71 return "SocialEngineeringAdsInterstitial"; |
81 case ActivationList::PHISHING_INTERSTITIAL: | 72 case ActivationList::PHISHING_INTERSTITIAL: |
82 return "PhishingInterstital"; | 73 return "PhishingInterstital"; |
83 case ActivationList::SUBRESOURCE_FILTER: | 74 case ActivationList::SUBRESOURCE_FILTER: |
84 return "SubresourceFilterOnly"; | 75 return "SubresourceFilterOnly"; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 135 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
145 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, | 136 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, |
146 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 137 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
147 safe_browsing::ThreatPatternType::NONE}, | 138 safe_browsing::ThreatPatternType::NONE}, |
148 {ActivationDecision::ACTIVATED, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, | 139 {ActivationDecision::ACTIVATED, ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL, |
149 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 140 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
150 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 141 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
151 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, | 142 {ActivationDecision::ACTIVATED, ActivationList::PHISHING_INTERSTITIAL, |
152 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 143 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
153 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, | 144 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS}, |
| 145 {ActivationDecision::ACTIVATED, ActivationList::SUBRESOURCE_FILTER, |
| 146 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
| 147 safe_browsing::ThreatPatternType::NONE}, |
| 148 {ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET, |
| 149 ActivationList::PHISHING_INTERSTITIAL, |
| 150 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
| 151 safe_browsing::ThreatPatternType::NONE}, |
154 }; | 152 }; |
155 | 153 |
156 struct ActivationScopeTestData { | 154 struct ActivationScopeTestData { |
157 ActivationDecision expected_activation_decision; | 155 ActivationDecision expected_activation_decision; |
158 bool url_matches_activation_list; | 156 bool url_matches_activation_list; |
159 ActivationScope activation_scope; | 157 ActivationScope activation_scope; |
160 }; | 158 }; |
161 | 159 |
162 const ActivationScopeTestData kActivationScopeTestData[] = { | 160 const ActivationScopeTestData kActivationScopeTestData[] = { |
163 {ActivationDecision::ACTIVATED, false /* url_matches_activation_list */, | 161 {ActivationDecision::ACTIVATED, false /* url_matches_activation_list */, |
(...skipping 27 matching lines...) Expand all Loading... |
191 ~MockSubresourceFilterClient() override = default; | 189 ~MockSubresourceFilterClient() override = default; |
192 | 190 |
193 bool OnPageActivationComputed(content::NavigationHandle* handle, | 191 bool OnPageActivationComputed(content::NavigationHandle* handle, |
194 bool activated) override { | 192 bool activated) override { |
195 DCHECK(handle->IsInMainFrame()); | 193 DCHECK(handle->IsInMainFrame()); |
196 return whitelisted_hosts_.count(handle->GetURL().host()); | 194 return whitelisted_hosts_.count(handle->GetURL().host()); |
197 } | 195 } |
198 | 196 |
199 void WhitelistByContentSettings(const GURL& url) override {} | 197 void WhitelistByContentSettings(const GURL& url) override {} |
200 void WhitelistInCurrentWebContents(const GURL& url) override { | 198 void WhitelistInCurrentWebContents(const GURL& url) override { |
201 if (url.SchemeIsHTTPOrHTTPS()) | 199 ASSERT_TRUE(url.SchemeIsHTTPOrHTTPS()); |
202 whitelisted_hosts_.insert(url.host()); | 200 whitelisted_hosts_.insert(url.host()); |
203 } | 201 } |
204 | 202 |
205 VerifiedRulesetDealer::Handle* GetRulesetDealer() override { | 203 VerifiedRulesetDealer::Handle* GetRulesetDealer() override { |
206 return ruleset_dealer_; | 204 return ruleset_dealer_; |
207 } | 205 } |
208 | 206 |
209 MOCK_METHOD1(ToggleNotificationVisibility, void(bool)); | 207 MOCK_METHOD1(ToggleNotificationVisibility, void(bool)); |
210 | 208 |
211 private: | 209 private: |
212 std::set<std::string> whitelisted_hosts_; | 210 std::set<std::string> whitelisted_hosts_; |
| 211 |
213 // Owned by the test harness. | 212 // Owned by the test harness. |
214 VerifiedRulesetDealer::Handle* ruleset_dealer_; | 213 VerifiedRulesetDealer::Handle* ruleset_dealer_; |
215 | 214 |
216 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient); | 215 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterClient); |
217 }; | 216 }; |
218 | 217 |
| 218 void ExpectSampleForSuffix(const std::string& suffix_to_check, |
| 219 const std::string& suffix, |
| 220 const base::HistogramTester& tester) { |
| 221 tester.ExpectUniqueSample(kMatchesHistogramName + suffix_to_check, |
| 222 (suffix_to_check == suffix), 1); |
| 223 } |
| 224 |
219 } // namespace | 225 } // namespace |
220 | 226 |
221 class ContentSubresourceFilterDriverFactoryTest | 227 class ContentSubresourceFilterDriverFactoryTest |
222 : public content::RenderViewHostTestHarness, | 228 : public content::RenderViewHostTestHarness, |
223 public content::WebContentsObserver { | 229 public content::WebContentsObserver { |
224 public: | 230 public: |
225 ContentSubresourceFilterDriverFactoryTest() {} | 231 ContentSubresourceFilterDriverFactoryTest() {} |
226 ~ContentSubresourceFilterDriverFactoryTest() override {} | 232 ~ContentSubresourceFilterDriverFactoryTest() override {} |
227 | 233 |
228 // content::RenderViewHostImplTestHarness: | 234 // content::RenderViewHostImplTestHarness: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 render_process_host->sink().ClearMessages(); | 314 render_process_host->sink().ClearMessages(); |
309 } | 315 } |
310 | 316 |
311 void BlacklistURLWithRedirectsNavigateAndCommit( | 317 void BlacklistURLWithRedirectsNavigateAndCommit( |
312 const std::vector<bool>& blacklisted_urls, | 318 const std::vector<bool>& blacklisted_urls, |
313 const std::vector<GURL>& navigation_chain, | 319 const std::vector<GURL>& navigation_chain, |
314 safe_browsing::SBThreatType threat_type, | 320 safe_browsing::SBThreatType threat_type, |
315 safe_browsing::ThreatPatternType threat_type_metadata, | 321 safe_browsing::ThreatPatternType threat_type_metadata, |
316 const content::Referrer& referrer, | 322 const content::Referrer& referrer, |
317 ui::PageTransition transition, | 323 ui::PageTransition transition, |
318 RedirectChainMatchPattern expected_pattern, | 324 RecordedHistograms expected_histograms, |
319 ActivationDecision expected_activation_decision) { | 325 ActivationDecision expected_activation_decision) { |
320 const bool expected_activation = | 326 const bool expected_activation = |
321 expected_activation_decision == ActivationDecision::ACTIVATED; | 327 expected_activation_decision == ActivationDecision::ACTIVATED; |
322 base::HistogramTester tester; | 328 base::HistogramTester tester; |
323 EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); | 329 EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); |
324 | 330 |
325 std::unique_ptr<content::NavigationSimulator> navigation_simulator = | 331 std::unique_ptr<content::NavigationSimulator> navigation_simulator = |
326 content::NavigationSimulator::CreateRendererInitiated( | 332 content::NavigationSimulator::CreateRendererInitiated( |
327 navigation_chain.front(), main_rfh()); | 333 navigation_chain.front(), main_rfh()); |
328 navigation_simulator->SetReferrer(referrer); | 334 navigation_simulator->SetReferrer(referrer); |
329 navigation_simulator->SetTransition(transition); | 335 navigation_simulator->SetTransition(transition); |
330 navigation_simulator->Start(); | 336 navigation_simulator->Start(); |
331 | 337 |
332 if (blacklisted_urls.front()) { | 338 if (blacklisted_urls.front()) { |
333 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 339 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
334 navigation_chain.front(), navigation_chain, threat_type, | 340 navigation_chain.front(), navigation_chain, threat_type, |
335 threat_type_metadata); | 341 threat_type_metadata); |
336 } | 342 } |
337 ::testing::Mock::VerifyAndClearExpectations(client()); | 343 ::testing::Mock::VerifyAndClearExpectations(client()); |
338 | 344 |
339 for (size_t i = 1; i < navigation_chain.size(); ++i) { | 345 for (size_t i = 1; i < navigation_chain.size(); ++i) { |
340 const GURL url = navigation_chain[i]; | 346 const GURL url = navigation_chain[i]; |
341 if (i < blacklisted_urls.size() && blacklisted_urls[i]) { | 347 if (i < blacklisted_urls.size() && blacklisted_urls[i]) { |
342 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( | 348 factory()->OnMainResourceMatchedSafeBrowsingBlacklist( |
343 url, navigation_chain, threat_type, threat_type_metadata); | 349 url, navigation_chain, threat_type, threat_type_metadata); |
344 } | 350 } |
345 navigation_simulator->Redirect(url); | 351 navigation_simulator->Redirect(url); |
346 } | 352 } |
| 353 std::string suffix; |
| 354 ActivationList activation_list = |
| 355 GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata); |
| 356 suffix = blacklisted_urls.back() ? GetSuffixForList(activation_list) |
| 357 : std::string(); |
347 | 358 |
348 navigation_simulator->Commit(); | 359 navigation_simulator->Commit(); |
349 ExpectActivationSignalForFrame(main_rfh(), expected_activation); | 360 ExpectActivationSignalForFrame(main_rfh(), expected_activation); |
350 EXPECT_EQ(expected_activation_decision, | 361 EXPECT_EQ(expected_activation_decision, |
351 factory()->GetActivationDecisionForLastCommittedPageLoad()); | 362 factory()->GetActivationDecisionForLastCommittedPageLoad()); |
352 | 363 |
353 // Re-create a subframe now that the frame has navigated. | 364 // Re-create a subframe now that the frame has navigated. |
354 content::RenderFrameHostTester* rfh_tester = | 365 content::RenderFrameHostTester* rfh_tester = |
355 content::RenderFrameHostTester::For(main_rfh()); | 366 content::RenderFrameHostTester::For(main_rfh()); |
356 rfh_tester->AppendChild(kSubframeName); | 367 rfh_tester->AppendChild(kSubframeName); |
357 ActivationList activation_list = | 368 size_t all_matches = |
358 GetListForThreatTypeAndMetadata(threat_type, threat_type_metadata); | 369 tester.GetTotalCountsForPrefix(kMatchesHistogramName).size(); |
359 | |
360 const std::string suffix(GetSuffixForList(activation_list)); | |
361 size_t all_pattern = | |
362 tester.GetTotalCountsForPrefix(kMatchesPatternHistogramName).size(); | |
363 size_t all_chain_size = | 370 size_t all_chain_size = |
364 tester.GetTotalCountsForPrefix(kNavigationChainSize).size(); | 371 tester.GetTotalCountsForPrefix(kNavigationChainSize).size(); |
365 if (expected_pattern != EMPTY) { | 372 // Check that we recorded only what is needed. |
366 EXPECT_THAT(tester.GetAllSamples(kMatchesPatternHistogramName + suffix), | 373 if (expected_histograms == NO_HISTOGRAMS) { |
367 ::testing::ElementsAre(base::Bucket(expected_pattern, 1))); | 374 EXPECT_EQ(0u, all_matches); |
368 EXPECT_THAT( | 375 EXPECT_EQ(0U, all_chain_size); |
369 tester.GetAllSamples(kNavigationChainSize + suffix), | 376 } else { |
370 ::testing::ElementsAre(base::Bucket(navigation_chain.size(), 1))); | 377 EXPECT_EQ(3u, all_matches); |
371 // Check that we recorded only what is needed. | 378 ExpectSampleForSuffix("SocialEngineeringAdsInterstitial", suffix, tester); |
372 EXPECT_EQ(1u, all_pattern); | 379 ExpectSampleForSuffix("PhishingInterstital", suffix, tester); |
| 380 ExpectSampleForSuffix("SubresourceFilterOnly", suffix, tester); |
| 381 } |
| 382 |
| 383 if (expected_histograms == REDIRECT_CHAIN_LENGTH) { |
| 384 tester.ExpectUniqueSample(kNavigationChainSize + suffix, |
| 385 navigation_chain.size(), 1); |
373 EXPECT_EQ(1u, all_chain_size); | 386 EXPECT_EQ(1u, all_chain_size); |
374 } else { | 387 } else { |
375 EXPECT_EQ(0u, all_pattern); | 388 EXPECT_EQ(0U, all_chain_size); |
376 EXPECT_EQ(0u, all_chain_size); | |
377 } | 389 } |
378 } | 390 } |
379 | 391 |
380 void NavigateSubframeAndExpectCheckResult(const GURL& url, | 392 void NavigateSubframeAndExpectCheckResult(const GURL& url, |
381 bool expect_cancelled) { | 393 bool expect_cancelled) { |
382 std::unique_ptr<content::NavigationSimulator> simulator = | 394 std::unique_ptr<content::NavigationSimulator> simulator = |
383 content::NavigationSimulator::CreateRendererInitiated(url, | 395 content::NavigationSimulator::CreateRendererInitiated(url, |
384 GetSubframeRFH()); | 396 GetSubframeRFH()); |
385 simulator->Start(); | 397 simulator->Start(); |
386 content::NavigationThrottle::ThrottleCheckResult result = | 398 content::NavigationThrottle::ThrottleCheckResult result = |
(...skipping 15 matching lines...) Expand all Loading... |
402 ::testing::Mock::VerifyAndClearExpectations(client()); | 414 ::testing::Mock::VerifyAndClearExpectations(client()); |
403 } | 415 } |
404 | 416 |
405 void NavigateAndExpectActivation( | 417 void NavigateAndExpectActivation( |
406 const std::vector<bool>& blacklisted_urls, | 418 const std::vector<bool>& blacklisted_urls, |
407 const std::vector<GURL>& navigation_chain, | 419 const std::vector<GURL>& navigation_chain, |
408 safe_browsing::SBThreatType threat_type, | 420 safe_browsing::SBThreatType threat_type, |
409 safe_browsing::ThreatPatternType threat_type_metadata, | 421 safe_browsing::ThreatPatternType threat_type_metadata, |
410 const content::Referrer& referrer, | 422 const content::Referrer& referrer, |
411 ui::PageTransition transition, | 423 ui::PageTransition transition, |
412 RedirectChainMatchPattern expected_pattern, | 424 RecordedHistograms expected_histograms, |
413 ActivationDecision expected_activation_decision) { | 425 ActivationDecision expected_activation_decision) { |
414 const bool expected_activation = | 426 const bool expected_activation = |
415 expected_activation_decision == ActivationDecision::ACTIVATED; | 427 expected_activation_decision == ActivationDecision::ACTIVATED; |
416 BlacklistURLWithRedirectsNavigateAndCommit( | 428 BlacklistURLWithRedirectsNavigateAndCommit( |
417 blacklisted_urls, navigation_chain, threat_type, threat_type_metadata, | 429 blacklisted_urls, navigation_chain, threat_type, threat_type_metadata, |
418 referrer, transition, expected_pattern, expected_activation_decision); | 430 referrer, transition, expected_histograms, |
| 431 expected_activation_decision); |
419 | 432 |
420 NavigateAndCommitSubframe(GURL(kExampleLoginUrl), expected_activation); | 433 NavigateAndCommitSubframe(GURL(kExampleLoginUrl), expected_activation); |
421 } | 434 } |
422 | 435 |
423 void NavigateAndExpectActivation( | 436 void NavigateAndExpectActivation( |
424 const std::vector<bool>& blacklisted_urls, | 437 const std::vector<bool>& blacklisted_urls, |
425 const std::vector<GURL>& navigation_chain, | 438 const std::vector<GURL>& navigation_chain, |
426 RedirectChainMatchPattern expected_pattern, | 439 RecordedHistograms expected_histograms, |
427 ActivationDecision expected_activation_decision) { | 440 ActivationDecision expected_activation_decision) { |
428 NavigateAndExpectActivation( | 441 NavigateAndExpectActivation( |
429 blacklisted_urls, navigation_chain, | 442 blacklisted_urls, navigation_chain, |
430 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 443 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
431 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 444 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
432 content::Referrer(), ui::PAGE_TRANSITION_LINK, expected_pattern, | 445 content::Referrer(), ui::PAGE_TRANSITION_LINK, expected_histograms, |
433 expected_activation_decision); | 446 expected_activation_decision); |
434 } | 447 } |
435 | 448 |
436 void EmulateFailedNavigationAndExpectNoActivation(const GURL& url) { | 449 void EmulateFailedNavigationAndExpectNoActivation(const GURL& url) { |
437 EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); | 450 EXPECT_CALL(*client(), ToggleNotificationVisibility(false)).Times(1); |
438 | 451 |
439 // With browser-side navigation enabled, ReadyToCommitNavigation is invoked | 452 // With browser-side navigation enabled, ReadyToCommitNavigation is invoked |
440 // even for failed navigations. This is correctly simulated by | 453 // even for failed navigations. This is correctly simulated by |
441 // NavigationSimulator. Make sure no activation message is sent in this | 454 // NavigationSimulator. Make sure no activation message is sent in this |
442 // case. | 455 // case. |
443 content::NavigationSimulator::NavigateAndFailFromDocument( | 456 content::NavigationSimulator::NavigateAndFailFromDocument( |
444 url, net::ERR_TIMED_OUT, main_rfh()); | 457 url, net::ERR_TIMED_OUT, main_rfh()); |
445 ExpectActivationSignalForFrame(main_rfh(), false); | 458 ExpectActivationSignalForFrame(main_rfh(), false); |
446 ::testing::Mock::VerifyAndClearExpectations(client()); | 459 ::testing::Mock::VerifyAndClearExpectations(client()); |
447 } | 460 } |
448 | 461 |
449 void EmulateInPageNavigation( | 462 void EmulateInPageNavigation( |
450 const std::vector<bool>& blacklisted_urls, | 463 const std::vector<bool>& blacklisted_urls, |
451 RedirectChainMatchPattern expected_pattern, | 464 RecordedHistograms expected_histograms, |
452 ActivationDecision expected_activation_decision) { | 465 ActivationDecision expected_activation_decision) { |
453 // This test examines the navigation with the following sequence of events: | 466 // This test examines the navigation with the following sequence of events: |
454 // DidStartProvisional(main, "example.com") | 467 // DidStartProvisional(main, "example.com") |
455 // ReadyToCommitNavigation(“example.com”) | 468 // ReadyToCommitNavigation(“example.com”) |
456 // DidCommitProvisional(main, "example.com") | 469 // DidCommitProvisional(main, "example.com") |
457 // DidStartProvisional(sub, "example.com/login") | 470 // DidStartProvisional(sub, "example.com/login") |
458 // DidCommitProvisional(sub, "example.com/login") | 471 // DidCommitProvisional(sub, "example.com/login") |
459 // DidCommitProvisional(main, "example.com#ref") | 472 // DidCommitProvisional(main, "example.com#ref") |
460 | 473 |
461 NavigateAndExpectActivation(blacklisted_urls, {GURL(kExampleUrl)}, | 474 NavigateAndExpectActivation(blacklisted_urls, {GURL(kExampleUrl)}, |
462 expected_pattern, expected_activation_decision); | 475 expected_histograms, |
| 476 expected_activation_decision); |
463 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); | 477 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
464 std::unique_ptr<content::NavigationSimulator> navigation_simulator = | 478 std::unique_ptr<content::NavigationSimulator> navigation_simulator = |
465 content::NavigationSimulator::CreateRendererInitiated(GURL(kExampleUrl), | 479 content::NavigationSimulator::CreateRendererInitiated(GURL(kExampleUrl), |
466 main_rfh()); | 480 main_rfh()); |
467 navigation_simulator->CommitSameDocument(); | 481 navigation_simulator->CommitSameDocument(); |
468 ExpectActivationSignalForFrame(main_rfh(), false); | 482 ExpectActivationSignalForFrame(main_rfh(), false); |
469 ::testing::Mock::VerifyAndClearExpectations(client()); | 483 ::testing::Mock::VerifyAndClearExpectations(client()); |
470 } | 484 } |
471 | 485 |
472 protected: | 486 protected: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 545 |
532 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 546 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
533 NoActivationWhenActivationLevelIsDisabled) { | 547 NoActivationWhenActivationLevelIsDisabled) { |
534 Configuration config(ActivationLevel::DISABLED, | 548 Configuration config(ActivationLevel::DISABLED, |
535 ActivationScope::ACTIVATION_LIST, | 549 ActivationScope::ACTIVATION_LIST, |
536 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 550 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
537 config.activation_options.activation_level = ActivationLevel::DISABLED; | 551 config.activation_options.activation_level = ActivationLevel::DISABLED; |
538 ResetConfiguration(std::move(config)); | 552 ResetConfiguration(std::move(config)); |
539 | 553 |
540 NavigateAndExpectActivation( | 554 NavigateAndExpectActivation( |
541 {false}, {GURL(kExampleLoginUrl)}, EMPTY, | 555 {false}, {GURL(kExampleLoginUrl)}, FINAL_URL_MATCHES, |
542 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); | 556 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
543 | 557 |
544 const GURL url(kExampleUrlWithParams); | 558 const GURL url(kExampleUrlWithParams); |
545 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 559 NavigateAndExpectActivation({true}, {url}, REDIRECT_CHAIN_LENGTH, |
546 ActivationDecision::ACTIVATION_DISABLED); | 560 ActivationDecision::ACTIVATION_DISABLED); |
547 | 561 |
548 // Whitelisting occurs last, so the decision should still be DISABLED. | 562 // Whitelisting occurs last, so the decision should still be DISABLED. |
549 factory()->client()->WhitelistInCurrentWebContents(url); | 563 factory()->client()->WhitelistInCurrentWebContents(url); |
550 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 564 NavigateAndExpectActivation({true}, {url}, REDIRECT_CHAIN_LENGTH, |
551 ActivationDecision::ACTIVATION_DISABLED); | 565 ActivationDecision::ACTIVATION_DISABLED); |
552 } | 566 } |
553 | 567 |
554 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { | 568 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoActivationWhenNoMatch) { |
555 NavigateAndExpectActivation( | 569 NavigateAndExpectActivation( |
556 {false}, {GURL(kExampleUrl)}, EMPTY, | 570 {false}, {GURL(kExampleUrl)}, FINAL_URL_MATCHES, |
557 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); | 571 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
558 } | 572 } |
559 | 573 |
560 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 574 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
561 SpecialCaseNavigationAllSitesEnabled) { | 575 SpecialCaseNavigationAllSitesEnabled) { |
562 // Check that when the experiment is enabled for all site, the activation | 576 // Check that when the experiment is enabled for all site, the activation |
563 // signal is always sent. | 577 // signal is always sent. |
564 ResetConfigurationToEnableFilteringOnAllSites(); | 578 ResetConfigurationToEnableFilteringOnAllSites(); |
565 EmulateInPageNavigation({false}, EMPTY, ActivationDecision::ACTIVATED); | 579 EmulateInPageNavigation({false}, FINAL_URL_MATCHES, |
| 580 ActivationDecision::ACTIVATED); |
566 } | 581 } |
567 | 582 |
568 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 583 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
569 SpecialCaseNavigationActivationListEnabled) { | 584 SpecialCaseNavigationActivationListEnabled) { |
570 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 585 EmulateInPageNavigation({true}, REDIRECT_CHAIN_LENGTH, |
571 ActivationDecision::ACTIVATED); | 586 ActivationDecision::ACTIVATED); |
572 } | 587 } |
573 | 588 |
574 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 589 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
575 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { | 590 SpecialCaseNavigationActivationListEnabledWithPerformanceMeasurement) { |
576 Configuration config(ActivationLevel::ENABLED, | 591 Configuration config(ActivationLevel::ENABLED, |
577 ActivationScope::ACTIVATION_LIST, | 592 ActivationScope::ACTIVATION_LIST, |
578 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 593 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
579 config.activation_options.performance_measurement_rate = 1.0; | 594 config.activation_options.performance_measurement_rate = 1.0; |
580 ResetConfiguration(std::move(config)); | 595 ResetConfiguration(std::move(config)); |
581 | 596 |
582 EmulateInPageNavigation({true}, NO_REDIRECTS_HIT, | 597 EmulateInPageNavigation({true}, REDIRECT_CHAIN_LENGTH, |
583 ActivationDecision::ACTIVATED); | 598 ActivationDecision::ACTIVATED); |
584 } | 599 } |
585 | 600 |
586 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { | 601 TEST_F(ContentSubresourceFilterDriverFactoryTest, FailedNavigation) { |
587 const GURL url(kExampleUrl); | 602 const GURL url(kExampleUrl); |
588 ResetConfigurationToEnableFilteringOnAllSites(); | 603 ResetConfigurationToEnableFilteringOnAllSites(); |
589 NavigateAndExpectActivation({false}, {url}, EMPTY, | 604 NavigateAndExpectActivation({false}, {url}, FINAL_URL_MATCHES, |
590 ActivationDecision::ACTIVATED); | 605 ActivationDecision::ACTIVATED); |
591 EmulateFailedNavigationAndExpectNoActivation(url); | 606 EmulateFailedNavigationAndExpectNoActivation(url); |
592 } | 607 } |
593 | 608 |
594 // TODO(melandory): refactor the test so it no longer require the current | 609 // TODO(melandory): refactor the test so it no longer require the current |
595 // activation list to be matching. | 610 // activation list to be matching. |
596 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { | 611 TEST_F(ContentSubresourceFilterDriverFactoryTest, RedirectPatternTest) { |
597 struct RedirectRedirectChainMatchPatternTestData { | 612 struct RedirectRedirectChainMatchPatternTestData { |
598 std::vector<bool> blacklisted_urls; | 613 std::vector<bool> blacklisted_urls; |
599 std::vector<GURL> navigation_chain; | 614 std::vector<GURL> navigation_chain; |
600 RedirectChainMatchPattern hit_expected_pattern; | 615 RecordedHistograms hit_expected_histograms; |
601 ActivationDecision expected_activation_decision; | 616 ActivationDecision expected_activation_decision; |
602 } kRedirectRedirectChainMatchPatternTestData[] = { | 617 } kRedirectRecordedHistogramsTestData[] = { |
603 {{false}, | 618 {{false}, |
604 {GURL(kUrlA)}, | 619 {GURL(kUrlA)}, |
605 EMPTY, | 620 FINAL_URL_MATCHES, |
606 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 621 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
607 {{true}, {GURL(kUrlA)}, NO_REDIRECTS_HIT, ActivationDecision::ACTIVATED}, | 622 {{true}, |
| 623 {GURL(kUrlA)}, |
| 624 REDIRECT_CHAIN_LENGTH, |
| 625 ActivationDecision::ACTIVATED}, |
608 {{false, false}, | 626 {{false, false}, |
609 {GURL(kUrlA), GURL(kUrlB)}, | 627 {GURL(kUrlA), GURL(kUrlB)}, |
610 EMPTY, | 628 FINAL_URL_MATCHES, |
611 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 629 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
612 {{false, true}, | 630 {{false, true}, |
613 {GURL(kUrlA), GURL(kUrlB)}, | 631 {GURL(kUrlA), GURL(kUrlB)}, |
614 F0M0L1, | 632 REDIRECT_CHAIN_LENGTH, |
615 ActivationDecision::ACTIVATED}, | 633 ActivationDecision::ACTIVATED}, |
616 {{true, false}, | 634 {{true, false}, |
617 {GURL(kUrlA), GURL(kUrlB)}, | 635 {GURL(kUrlA), GURL(kUrlB)}, |
618 F1M0L0, | 636 FINAL_URL_MATCHES, |
619 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 637 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
620 {{true, true}, | 638 {{true, true}, |
621 {GURL(kUrlA), GURL(kUrlB)}, | 639 {GURL(kUrlA), GURL(kUrlB)}, |
622 F1M0L1, | 640 REDIRECT_CHAIN_LENGTH, |
623 ActivationDecision::ACTIVATED}, | 641 ActivationDecision::ACTIVATED}, |
624 {{false, false, false}, | 642 {{false, false, false}, |
625 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 643 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
626 EMPTY, | 644 FINAL_URL_MATCHES, |
627 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 645 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
628 {{false, false, true}, | 646 {{false, false, true}, |
629 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 647 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
630 F0M0L1, | 648 REDIRECT_CHAIN_LENGTH, |
631 ActivationDecision::ACTIVATED}, | 649 ActivationDecision::ACTIVATED}, |
632 {{false, true, false}, | 650 {{false, true, false}, |
633 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 651 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
634 F0M1L0, | 652 FINAL_URL_MATCHES, |
635 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 653 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
636 {{false, true, true}, | 654 {{false, true, true}, |
637 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 655 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
638 F0M1L1, | 656 REDIRECT_CHAIN_LENGTH, |
639 ActivationDecision::ACTIVATED}, | 657 ActivationDecision::ACTIVATED}, |
640 {{true, false, false}, | 658 {{true, false, false}, |
641 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 659 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
642 F1M0L0, | 660 FINAL_URL_MATCHES, |
643 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 661 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
644 {{true, false, true}, | 662 {{true, false, true}, |
645 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 663 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
646 F1M0L1, | 664 REDIRECT_CHAIN_LENGTH, |
647 ActivationDecision::ACTIVATED}, | 665 ActivationDecision::ACTIVATED}, |
648 {{true, true, false}, | 666 {{true, true, false}, |
649 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 667 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
650 F1M1L0, | 668 FINAL_URL_MATCHES, |
651 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 669 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
652 {{true, true, true}, | 670 {{true, true, true}, |
653 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, | 671 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC)}, |
654 F1M1L1, | 672 REDIRECT_CHAIN_LENGTH, |
655 ActivationDecision::ACTIVATED}, | 673 ActivationDecision::ACTIVATED}, |
656 {{false, true, false, false}, | 674 {{false, true, false, false}, |
657 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)}, | 675 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), GURL(kUrlD)}, |
658 F0M1L0, | 676 FINAL_URL_MATCHES, |
659 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, | 677 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET}, |
660 }; | 678 }; |
661 | 679 |
662 for (size_t i = 0U; i < arraysize(kRedirectRedirectChainMatchPatternTestData); | 680 for (const auto& test_data : kRedirectRecordedHistogramsTestData) { |
663 ++i) { | |
664 auto test_data = kRedirectRedirectChainMatchPatternTestData[i]; | |
665 NavigateAndExpectActivation( | 681 NavigateAndExpectActivation( |
666 test_data.blacklisted_urls, test_data.navigation_chain, | 682 test_data.blacklisted_urls, test_data.navigation_chain, |
667 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 683 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
668 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 684 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
669 content::Referrer(), ui::PAGE_TRANSITION_LINK, | 685 content::Referrer(), ui::PAGE_TRANSITION_LINK, |
670 test_data.hit_expected_pattern, test_data.expected_activation_decision); | 686 test_data.hit_expected_histograms, |
| 687 test_data.expected_activation_decision); |
671 NavigateAndExpectActivation( | 688 NavigateAndExpectActivation( |
672 {false}, {GURL("https://dummy.com")}, EMPTY, | 689 {false}, {GURL("https://dummy.com")}, FINAL_URL_MATCHES, |
673 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); | 690 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
674 #if defined(GOOGLE_CHROME_BUILD) | 691 #if defined(GOOGLE_CHROME_BUILD) |
675 NavigateAndExpectActivation( | 692 NavigateAndExpectActivation( |
676 test_data.blacklisted_urls, test_data.navigation_chain, | 693 test_data.blacklisted_urls, test_data.navigation_chain, |
677 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, | 694 safe_browsing::SB_THREAT_TYPE_SUBRESOURCE_FILTER, |
678 safe_browsing::ThreatPatternType::NONE, content::Referrer(), | 695 safe_browsing::ThreatPatternType::NONE, content::Referrer(), |
679 ui::PAGE_TRANSITION_LINK, test_data.hit_expected_pattern, | 696 ui::PAGE_TRANSITION_LINK, test_data.hit_expected_histograms, |
680 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); | 697 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
681 #endif | 698 #endif |
682 } | 699 } |
683 } | 700 } |
684 | 701 |
685 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { | 702 TEST_F(ContentSubresourceFilterDriverFactoryTest, NotificationVisibility) { |
686 ResetConfigurationToEnableFilteringOnAllSites(); | 703 ResetConfigurationToEnableFilteringOnAllSites(); |
687 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 704 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, FINAL_URL_MATCHES, |
688 ActivationDecision::ACTIVATED); | 705 ActivationDecision::ACTIVATED); |
689 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); | 706 EXPECT_CALL(*client(), ToggleNotificationVisibility(true)).Times(1); |
690 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 707 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
691 true /* expect_cancelled */); | 708 true /* expect_cancelled */); |
692 } | 709 } |
693 | 710 |
694 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 711 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
695 SuppressNotificationVisibility) { | 712 SuppressNotificationVisibility) { |
696 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | 713 Configuration config(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
697 config.activation_options.should_suppress_notifications = true; | 714 config.activation_options.should_suppress_notifications = true; |
698 ResetConfiguration(std::move(config)); | 715 ResetConfiguration(std::move(config)); |
699 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 716 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, FINAL_URL_MATCHES, |
700 ActivationDecision::ACTIVATED); | 717 ActivationDecision::ACTIVATED); |
701 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); | 718 EXPECT_CALL(*client(), ToggleNotificationVisibility(::testing::_)).Times(0); |
702 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), | 719 NavigateSubframeAndExpectCheckResult(GURL(kDisallowedUrl), |
703 true /* expect_cancelled */); | 720 true /* expect_cancelled */); |
704 } | 721 } |
705 | 722 |
706 TEST_F(ContentSubresourceFilterDriverFactoryTest, | 723 TEST_F(ContentSubresourceFilterDriverFactoryTest, |
707 InactiveMainFrame_SubframeNotFiltered) { | 724 InactiveMainFrame_SubframeNotFiltered) { |
708 GURL url(kExampleUrl); | 725 GURL url(kExampleUrl); |
709 Configuration config(ActivationLevel::DISABLED, ActivationScope::ALL_SITES); | 726 Configuration config(ActivationLevel::DISABLED, ActivationScope::ALL_SITES); |
710 ResetConfiguration(std::move(config)); | 727 ResetConfiguration(std::move(config)); |
711 NavigateAndExpectActivation({false}, {url}, EMPTY, | 728 NavigateAndExpectActivation({false}, {url}, FINAL_URL_MATCHES, |
712 ActivationDecision::ACTIVATION_DISABLED); | 729 ActivationDecision::ACTIVATION_DISABLED); |
713 NavigateSubframeAndExpectCheckResult(url, false /* expect_cancelled */); | 730 NavigateSubframeAndExpectCheckResult(url, false /* expect_cancelled */); |
714 } | 731 } |
715 | 732 |
716 TEST_F(ContentSubresourceFilterDriverFactoryTest, WhitelistSiteOnReload) { | 733 TEST_F(ContentSubresourceFilterDriverFactoryTest, WhitelistSiteOnReload) { |
717 const struct { | 734 const struct { |
718 content::Referrer referrer; | 735 content::Referrer referrer; |
719 ui::PageTransition transition; | 736 ui::PageTransition transition; |
720 ActivationDecision expected_activation_decision; | 737 ActivationDecision expected_activation_decision; |
721 } kTestCases[] = { | 738 } kTestCases[] = { |
(...skipping 12 matching lines...) Expand all Loading... |
734 | 751 |
735 for (const auto& test_case : kTestCases) { | 752 for (const auto& test_case : kTestCases) { |
736 SCOPED_TRACE(::testing::Message("referrer = \"") | 753 SCOPED_TRACE(::testing::Message("referrer = \"") |
737 << test_case.referrer.url << "\"" | 754 << test_case.referrer.url << "\"" |
738 << " transition = \"" << test_case.transition << "\""); | 755 << " transition = \"" << test_case.transition << "\""); |
739 | 756 |
740 NavigateAndExpectActivation( | 757 NavigateAndExpectActivation( |
741 {false}, {GURL(kExampleUrl)}, | 758 {false}, {GURL(kExampleUrl)}, |
742 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 759 safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
743 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 760 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
744 test_case.referrer, test_case.transition, EMPTY, | 761 test_case.referrer, test_case.transition, FINAL_URL_MATCHES, |
745 test_case.expected_activation_decision); | 762 test_case.expected_activation_decision); |
746 // Verify that if the first URL failed to activate, subsequent same-origin | 763 // Verify that if the first URL failed to activate, subsequent same-origin |
747 // navigations also fail to activate. | 764 // navigations also fail to activate. |
748 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, EMPTY, | 765 NavigateAndExpectActivation({false}, {GURL(kExampleUrlWithParams)}, |
| 766 FINAL_URL_MATCHES, |
749 test_case.expected_activation_decision); | 767 test_case.expected_activation_decision); |
750 } | 768 } |
751 } | 769 } |
752 | 770 |
753 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoConfigs) { | 771 TEST_F(ContentSubresourceFilterDriverFactoryTest, NoConfigs) { |
754 ResetConfiguration(std::vector<Configuration>()); | 772 ResetConfiguration(std::vector<Configuration>()); |
755 NavigateAndExpectActivation( | 773 NavigateAndExpectActivation( |
756 {true}, {GURL(kExampleUrl)}, NO_REDIRECTS_HIT, | 774 {true}, {GURL(kExampleUrl)}, REDIRECT_CHAIN_LENGTH, |
757 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); | 775 ActivationDecision::ACTIVATION_CONDITIONS_NOT_MET); |
758 } | 776 } |
759 | 777 |
760 TEST_F(ContentSubresourceFilterDriverFactoryTest, MultipleSimultaneousConfigs) { | 778 TEST_F(ContentSubresourceFilterDriverFactoryTest, MultipleSimultaneousConfigs) { |
761 Configuration config1(ActivationLevel::DRYRUN, ActivationScope::NO_SITES); | 779 Configuration config1(ActivationLevel::DRYRUN, ActivationScope::NO_SITES); |
762 config1.activation_conditions.priority = 2; | 780 config1.activation_conditions.priority = 2; |
763 | 781 |
764 Configuration config2(ActivationLevel::DISABLED, | 782 Configuration config2(ActivationLevel::DISABLED, |
765 ActivationScope::ACTIVATION_LIST, | 783 ActivationScope::ACTIVATION_LIST, |
766 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); | 784 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL); |
767 config2.activation_conditions.priority = 1; | 785 config2.activation_conditions.priority = 1; |
768 | 786 |
769 Configuration config3(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); | 787 Configuration config3(ActivationLevel::ENABLED, ActivationScope::ALL_SITES); |
770 config3.activation_options.should_whitelist_site_on_reload = true; | 788 config3.activation_options.should_whitelist_site_on_reload = true; |
771 config3.activation_conditions.priority = 0; | 789 config3.activation_conditions.priority = 0; |
772 | 790 |
773 ResetConfiguration({config1, config2, config3}); | 791 ResetConfiguration({config1, config2, config3}); |
774 | 792 |
775 // Should match |config2| and |config3|, the former with the higher priority. | 793 // Should match |config2| and |config3|, the former with the higher priority. |
776 NavigateAndExpectActivation({true}, {GURL(kExampleUrl)}, NO_REDIRECTS_HIT, | 794 NavigateAndExpectActivation({true}, {GURL(kExampleUrl)}, |
| 795 REDIRECT_CHAIN_LENGTH, |
777 ActivationDecision::ACTIVATION_DISABLED); | 796 ActivationDecision::ACTIVATION_DISABLED); |
778 | 797 |
779 // Should match |config3|. | 798 // Should match |config3|. |
780 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, EMPTY, | 799 NavigateAndExpectActivation({false}, {GURL(kExampleUrl)}, FINAL_URL_MATCHES, |
781 ActivationDecision::ACTIVATED); | 800 ActivationDecision::ACTIVATED); |
782 | 801 |
783 // Should match |config3|, but a reload, so this should get whitelisted. | 802 // Should match |config3|, but a reload, so this should get whitelisted. |
784 NavigateAndExpectActivation( | 803 NavigateAndExpectActivation( |
785 {false}, {GURL(kExampleUrl)}, safe_browsing::SB_THREAT_TYPE_URL_PHISHING, | 804 {false}, {GURL(kExampleUrl)}, safe_browsing::SB_THREAT_TYPE_URL_PHISHING, |
786 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, | 805 safe_browsing::ThreatPatternType::SOCIAL_ENGINEERING_ADS, |
787 content::Referrer(), ui::PAGE_TRANSITION_RELOAD, EMPTY, | 806 content::Referrer(), ui::PAGE_TRANSITION_RELOAD, FINAL_URL_MATCHES, |
788 ActivationDecision::URL_WHITELISTED); | 807 ActivationDecision::URL_WHITELISTED); |
789 } | 808 } |
790 | 809 |
791 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, | 810 TEST_P(ContentSubresourceFilterDriverFactoryActivationLevelTest, |
792 ActivateForFrameState) { | 811 ActivateForFrameState) { |
793 const ActivationLevelTestData& test_data = GetParam(); | 812 const ActivationLevelTestData& test_data = GetParam(); |
794 ResetConfiguration(Configuration( | 813 ResetConfiguration(Configuration( |
795 test_data.activation_level, ActivationScope::ACTIVATION_LIST, | 814 test_data.activation_level, ActivationScope::ACTIVATION_LIST, |
796 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 815 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
797 | 816 |
798 const GURL url(kExampleUrlWithParams); | 817 const GURL url(kExampleUrlWithParams); |
799 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, | 818 NavigateAndExpectActivation({true}, {url}, REDIRECT_CHAIN_LENGTH, |
800 test_data.expected_activation_decision); | 819 test_data.expected_activation_decision); |
801 factory()->client()->WhitelistInCurrentWebContents(url); | 820 factory()->client()->WhitelistInCurrentWebContents(url); |
802 | 821 |
803 // Whitelisting is only applied when the page will otherwise activate. | 822 // Whitelisting is only applied when the page will otherwise activate. |
804 ActivationDecision decision = | 823 ActivationDecision decision = |
805 test_data.activation_level == ActivationLevel::DISABLED | 824 test_data.activation_level == ActivationLevel::DISABLED |
806 ? test_data.expected_activation_decision | 825 ? test_data.expected_activation_decision |
807 : ActivationDecision::URL_WHITELISTED; | 826 : ActivationDecision::URL_WHITELISTED; |
808 NavigateAndExpectActivation({true}, {url}, NO_REDIRECTS_HIT, decision); | 827 NavigateAndExpectActivation({true}, {url}, REDIRECT_CHAIN_LENGTH, decision); |
809 } | 828 } |
810 | 829 |
811 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, | 830 TEST_P(ContentSubresourceFilterDriverFactoryThreatTypeTest, |
812 ActivateForTheListType) { | 831 ActivateForTheListType) { |
813 // Sets up the experiment in a way that the activation decision depends on the | 832 // Sets up the experiment in a way that the activation decision depends on the |
814 // list for which the Safe Browsing hit has happened. | 833 // list for which the Safe Browsing hit has happened. |
815 const ActivationListTestData& test_data = GetParam(); | 834 const ActivationListTestData& test_data = GetParam(); |
816 ResetConfiguration(Configuration(ActivationLevel::ENABLED, | 835 ResetConfiguration(Configuration(ActivationLevel::ENABLED, |
817 ActivationScope::ACTIVATION_LIST, | 836 ActivationScope::ACTIVATION_LIST, |
818 test_data.activation_list)); | 837 test_data.activation_list)); |
819 | 838 |
820 const GURL test_url("https://example.com/nonsoceng?q=engsocnon"); | 839 const GURL test_url("https://example.com/nonsoceng?q=engsocnon"); |
821 std::vector<GURL> navigation_chain; | 840 std::vector<GURL> navigation_chain; |
822 | 841 |
823 ActivationList effective_list = GetListForThreatTypeAndMetadata( | 842 ActivationList effective_list = GetListForThreatTypeAndMetadata( |
824 test_data.threat_type, test_data.threat_type_metadata); | 843 test_data.threat_type, test_data.threat_type_metadata); |
825 NavigateAndExpectActivation( | 844 NavigateAndExpectActivation( |
826 {false, false, false, true}, | 845 {false, false, false, true}, |
827 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), test_url}, test_data.threat_type, | 846 {GURL(kUrlA), GURL(kUrlB), GURL(kUrlC), test_url}, test_data.threat_type, |
828 test_data.threat_type_metadata, content::Referrer(), | 847 test_data.threat_type_metadata, content::Referrer(), |
829 ui::PAGE_TRANSITION_LINK, | 848 ui::PAGE_TRANSITION_LINK, |
830 effective_list != ActivationList::NONE ? F0M0L1 : EMPTY, | 849 effective_list != ActivationList::NONE ? REDIRECT_CHAIN_LENGTH |
| 850 : FINAL_URL_MATCHES, |
831 test_data.expected_activation_decision); | 851 test_data.expected_activation_decision); |
832 }; | 852 }; |
833 | 853 |
834 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 854 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
835 ActivateForScopeType) { | 855 ActivateForScopeType) { |
836 const ActivationScopeTestData& test_data = GetParam(); | 856 const ActivationScopeTestData& test_data = GetParam(); |
837 ResetConfiguration( | 857 ResetConfiguration( |
838 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, | 858 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, |
839 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 859 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
840 | 860 |
841 const GURL test_url(kExampleUrlWithParams); | 861 const GURL test_url(kExampleUrlWithParams); |
842 | 862 |
843 RedirectChainMatchPattern expected_pattern = | 863 RecordedHistograms expected_histograms = test_data.url_matches_activation_list |
844 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 864 ? REDIRECT_CHAIN_LENGTH |
| 865 : FINAL_URL_MATCHES; |
845 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 866 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
846 {test_url}, expected_pattern, | 867 {test_url}, expected_histograms, |
847 test_data.expected_activation_decision); | 868 test_data.expected_activation_decision); |
848 if (test_data.url_matches_activation_list) { | 869 if (test_data.url_matches_activation_list) { |
849 factory()->client()->WhitelistInCurrentWebContents(test_url); | 870 factory()->client()->WhitelistInCurrentWebContents(test_url); |
850 ActivationDecision expected_decision = | 871 ActivationDecision expected_decision = |
851 test_data.expected_activation_decision; | 872 test_data.expected_activation_decision; |
852 if (expected_decision == ActivationDecision::ACTIVATED) | 873 if (expected_decision == ActivationDecision::ACTIVATED) |
853 expected_decision = ActivationDecision::URL_WHITELISTED; | 874 expected_decision = ActivationDecision::URL_WHITELISTED; |
854 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 875 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
855 {GURL(kExampleUrlWithParams)}, expected_pattern, | 876 {GURL(kExampleUrlWithParams)}, |
856 expected_decision); | 877 expected_histograms, expected_decision); |
857 } | 878 } |
858 }; | 879 }; |
859 | 880 |
860 // Only main frames with http/https schemes should activate. | 881 // Only main frames with http/https schemes should activate. |
861 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, | 882 TEST_P(ContentSubresourceFilterDriverFactoryActivationScopeTest, |
862 ActivateForSupportedUrlScheme) { | 883 ActivateForSupportedUrlScheme) { |
863 const ActivationScopeTestData& test_data = GetParam(); | 884 const ActivationScopeTestData& test_data = GetParam(); |
864 ResetConfiguration( | 885 ResetConfiguration( |
865 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, | 886 Configuration(ActivationLevel::ENABLED, test_data.activation_scope, |
866 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); | 887 ActivationList::SOCIAL_ENG_ADS_INTERSTITIAL)); |
867 | 888 |
868 // data URLs are also not supported, but not listed here, as it's not possible | 889 // data URLs are also not supported, but not listed here, as it's not possible |
869 // for a page to redirect to them after https://crbug.com/594215 is fixed. | 890 // for a page to redirect to them after https://crbug.com/594215 is fixed. |
870 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", | 891 const char* unsupported_urls[] = {"ftp://example.com/", "chrome://settings", |
871 "chrome-extension://some-extension", | 892 "chrome-extension://some-extension", |
872 "file:///var/www/index.html"}; | 893 "file:///var/www/index.html"}; |
873 const char* supported_urls[] = {"http://example.test", | 894 const char* supported_urls[] = {"http://example.test", |
874 "https://example.test"}; | 895 "https://example.test"}; |
875 for (auto* url : unsupported_urls) { | 896 for (auto* url : unsupported_urls) { |
876 SCOPED_TRACE(url); | 897 SCOPED_TRACE(url); |
877 RedirectChainMatchPattern expected_pattern = EMPTY; | |
878 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 898 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
879 {GURL(url)}, expected_pattern, | 899 {GURL(url)}, NO_HISTOGRAMS, |
880 ActivationDecision::UNSUPPORTED_SCHEME); | 900 ActivationDecision::UNSUPPORTED_SCHEME); |
881 } | 901 } |
882 for (auto* url : supported_urls) { | 902 for (auto* url : supported_urls) { |
883 SCOPED_TRACE(url); | 903 SCOPED_TRACE(url); |
884 RedirectChainMatchPattern expected_pattern = | 904 RecordedHistograms expected_histograms = |
885 test_data.url_matches_activation_list ? NO_REDIRECTS_HIT : EMPTY; | 905 test_data.url_matches_activation_list ? REDIRECT_CHAIN_LENGTH |
| 906 : FINAL_URL_MATCHES; |
886 NavigateAndExpectActivation({test_data.url_matches_activation_list}, | 907 NavigateAndExpectActivation({test_data.url_matches_activation_list}, |
887 {GURL(url)}, expected_pattern, | 908 {GURL(url)}, expected_histograms, |
888 test_data.expected_activation_decision); | 909 test_data.expected_activation_decision); |
889 } | 910 } |
890 }; | 911 }; |
891 | 912 |
892 INSTANTIATE_TEST_CASE_P(NoSocEngHit, | 913 INSTANTIATE_TEST_CASE_P(NoSocEngHit, |
893 ContentSubresourceFilterDriverFactoryThreatTypeTest, | 914 ContentSubresourceFilterDriverFactoryThreatTypeTest, |
894 ::testing::ValuesIn(kActivationListTestData)); | 915 ::testing::ValuesIn(kActivationListTestData)); |
895 | 916 |
896 INSTANTIATE_TEST_CASE_P( | 917 INSTANTIATE_TEST_CASE_P( |
897 ActivationScopeTest, | 918 ActivationScopeTest, |
898 ContentSubresourceFilterDriverFactoryActivationScopeTest, | 919 ContentSubresourceFilterDriverFactoryActivationScopeTest, |
899 ::testing::ValuesIn(kActivationScopeTestData)); | 920 ::testing::ValuesIn(kActivationScopeTestData)); |
900 | 921 |
901 INSTANTIATE_TEST_CASE_P( | 922 INSTANTIATE_TEST_CASE_P( |
902 ActivationLevelTest, | 923 ActivationLevelTest, |
903 ContentSubresourceFilterDriverFactoryActivationLevelTest, | 924 ContentSubresourceFilterDriverFactoryActivationLevelTest, |
904 ::testing::ValuesIn(kActivationLevelTestData)); | 925 ::testing::ValuesIn(kActivationLevelTestData)); |
905 | 926 |
906 } // namespace subresource_filter | 927 } // namespace subresource_filter |
OLD | NEW |