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