Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_service_browsertest.cc

Issue 2831373002: Introduce subresource_filter::ConfigurationList and make querying it cheap. (Closed)
Patch Set: Rebase. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This test creates a safebrowsing service using test safebrowsing database 5 // This test creates a safebrowsing service using test safebrowsing database
6 // and a test protocol manager. It is used to test logics in safebrowsing 6 // and a test protocol manager. It is used to test logics in safebrowsing
7 // service. 7 // service.
8 8
9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "components/prefs/pref_service.h" 53 #include "components/prefs/pref_service.h"
54 #include "components/safe_browsing/common/safebrowsing_switches.h" 54 #include "components/safe_browsing/common/safebrowsing_switches.h"
55 #include "components/safe_browsing_db/database_manager.h" 55 #include "components/safe_browsing_db/database_manager.h"
56 #include "components/safe_browsing_db/metadata.pb.h" 56 #include "components/safe_browsing_db/metadata.pb.h"
57 #include "components/safe_browsing_db/test_database_manager.h" 57 #include "components/safe_browsing_db/test_database_manager.h"
58 #include "components/safe_browsing_db/util.h" 58 #include "components/safe_browsing_db/util.h"
59 #include "components/safe_browsing_db/v4_database.h" 59 #include "components/safe_browsing_db/v4_database.h"
60 #include "components/safe_browsing_db/v4_feature_list.h" 60 #include "components/safe_browsing_db/v4_feature_list.h"
61 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h" 61 #include "components/safe_browsing_db/v4_get_hash_protocol_manager.h"
62 #include "components/safe_browsing_db/v4_protocol_manager_util.h" 62 #include "components/safe_browsing_db/v4_protocol_manager_util.h"
63 #include "components/subresource_filter/content/browser/content_subresource_filt er_driver_factory.h"
64 #include "components/subresource_filter/core/browser/subresource_filter_features .h" 63 #include "components/subresource_filter/core/browser/subresource_filter_features .h"
65 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h" 64 #include "components/subresource_filter/core/browser/subresource_filter_features _test_support.h"
66 #include "components/subresource_filter/core/common/test_ruleset_creator.h" 65 #include "components/subresource_filter/core/common/test_ruleset_creator.h"
67 #include "content/public/browser/interstitial_page.h" 66 #include "content/public/browser/interstitial_page.h"
68 #include "content/public/browser/navigation_entry.h" 67 #include "content/public/browser/navigation_entry.h"
69 #include "content/public/browser/render_frame_host.h" 68 #include "content/public/browser/render_frame_host.h"
70 #include "content/public/browser/web_contents.h" 69 #include "content/public/browser/web_contents.h"
71 #include "content/public/common/content_switches.h" 70 #include "content/public/common/content_switches.h"
72 #include "content/public/test/browser_test_utils.h" 71 #include "content/public/test/browser_test_utils.h"
73 #include "crypto/sha2.h" 72 #include "crypto/sha2.h"
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 GURL phishing_url = embedded_test_server()->GetURL( 922 GURL phishing_url = embedded_test_server()->GetURL(
924 "/subresource_filter/frame_with_included_script.html"); 923 "/subresource_filter/frame_with_included_script.html");
925 SBFullHashResult malware_full_hash; 924 SBFullHashResult malware_full_hash;
926 GenUrlFullHashResultWithMetadata(phishing_url, PHISH, 925 GenUrlFullHashResultWithMetadata(phishing_url, PHISH,
927 ThreatPatternType::SOCIAL_ENGINEERING_ADS, 926 ThreatPatternType::SOCIAL_ENGINEERING_ADS,
928 &malware_full_hash); 927 &malware_full_hash);
929 SetupResponseForUrl(phishing_url, malware_full_hash); 928 SetupResponseForUrl(phishing_url, malware_full_hash);
930 929
931 WebContents* web_contents = 930 WebContents* web_contents =
932 browser()->tab_strip_model()->GetActiveWebContents(); 931 browser()->tab_strip_model()->GetActiveWebContents();
933 auto* driver_factory = subresource_filter::
934 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents);
935 driver_factory->set_configuration_for_testing(
936 subresource_filter::GetActiveConfiguration());
937 932
938 // Navigation to a phishing page should trigger an interstitial. If the user 933 // Navigation to a phishing page should trigger an interstitial. If the user
939 // clicks through it, the page load should proceed, but with subresource 934 // clicks through it, the page load should proceed, but with subresource
940 // filtering activated. This is verified by probing whether `included_script` 935 // filtering activated. This is verified by probing whether `included_script`
941 // that is disallowed above indeed fails to load. 936 // that is disallowed above indeed fails to load.
942 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url))); 937 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url)));
943 ui_test_utils::NavigateToURL(browser(), phishing_url); 938 ui_test_utils::NavigateToURL(browser(), phishing_url);
944 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_)); 939 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_));
945 ASSERT_TRUE(got_hit_report()); 940 ASSERT_TRUE(got_hit_report());
946 content::WaitForInterstitialAttach(web_contents); 941 content::WaitForInterstitialAttach(web_contents);
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
1997 ASSERT_NO_FATAL_FAILURE( 1992 ASSERT_NO_FATAL_FAILURE(
1998 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed)); 1993 test_ruleset_publisher.SetRuleset(test_ruleset_pair.unindexed));
1999 1994
2000 GURL phishing_url = embedded_test_server()->GetURL( 1995 GURL phishing_url = embedded_test_server()->GetURL(
2001 "/subresource_filter/frame_with_included_script.html"); 1996 "/subresource_filter/frame_with_included_script.html");
2002 MarkUrlForPhishingUnexpired(phishing_url, 1997 MarkUrlForPhishingUnexpired(phishing_url,
2003 ThreatPatternType::SOCIAL_ENGINEERING_ADS); 1998 ThreatPatternType::SOCIAL_ENGINEERING_ADS);
2004 1999
2005 WebContents* web_contents = 2000 WebContents* web_contents =
2006 browser()->tab_strip_model()->GetActiveWebContents(); 2001 browser()->tab_strip_model()->GetActiveWebContents();
2007 auto* driver_factory = subresource_filter::
2008 ContentSubresourceFilterDriverFactory::FromWebContents(web_contents);
2009 driver_factory->set_configuration_for_testing(
2010 subresource_filter::GetActiveConfiguration());
2011 2002
2012 // Navigation to a phishing page should trigger an interstitial. If the user 2003 // Navigation to a phishing page should trigger an interstitial. If the user
2013 // clicks through it, the page load should proceed, but with subresource 2004 // clicks through it, the page load should proceed, but with subresource
2014 // filtering activated. This is verified by probing whether `included_script` 2005 // filtering activated. This is verified by probing whether `included_script`
2015 // that is disallowed above indeed fails to load. 2006 // that is disallowed above indeed fails to load.
2016 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url))); 2007 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(phishing_url)));
2017 ui_test_utils::NavigateToURL(browser(), phishing_url); 2008 ui_test_utils::NavigateToURL(browser(), phishing_url);
2018 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_)); 2009 ASSERT_TRUE(Mock::VerifyAndClearExpectations(&observer_));
2019 ASSERT_TRUE(got_hit_report()); 2010 ASSERT_TRUE(got_hit_report());
2020 content::WaitForInterstitialAttach(web_contents); 2011 content::WaitForInterstitialAttach(web_contents);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2498 } 2489 }
2499 2490
2500 INSTANTIATE_TEST_CASE_P( 2491 INSTANTIATE_TEST_CASE_P(
2501 MaybeSetMetadata, 2492 MaybeSetMetadata,
2502 V4SafeBrowsingServiceMetadataTest, 2493 V4SafeBrowsingServiceMetadataTest,
2503 testing::Values(ThreatPatternType::NONE, 2494 testing::Values(ThreatPatternType::NONE,
2504 ThreatPatternType::MALWARE_LANDING, 2495 ThreatPatternType::MALWARE_LANDING,
2505 ThreatPatternType::MALWARE_DISTRIBUTION)); 2496 ThreatPatternType::MALWARE_DISTRIBUTION));
2506 2497
2507 } // namespace safe_browsing 2498 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698