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

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

Issue 2669833004: Refactor subresource filter activation to support PlzNavigate cleanly. (Closed)
Patch Set: Rebase. Created 3 years, 10 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 class MockSubresourceFilterDriver 106 class MockSubresourceFilterDriver
107 : public subresource_filter::ContentSubresourceFilterDriver { 107 : public subresource_filter::ContentSubresourceFilterDriver {
108 public: 108 public:
109 explicit MockSubresourceFilterDriver( 109 explicit MockSubresourceFilterDriver(
110 content::RenderFrameHost* render_frame_host) 110 content::RenderFrameHost* render_frame_host)
111 : subresource_filter::ContentSubresourceFilterDriver(render_frame_host) {} 111 : subresource_filter::ContentSubresourceFilterDriver(render_frame_host) {}
112 112
113 ~MockSubresourceFilterDriver() override = default; 113 ~MockSubresourceFilterDriver() override = default;
114 114
115 MOCK_METHOD3(ActivateForProvisionalLoad, 115 MOCK_METHOD2(ActivateForNextCommittedLoad,
116 void(subresource_filter::ActivationLevel, const GURL&, bool)); 116 void(subresource_filter::ActivationLevel, bool));
117 117
118 private: 118 private:
119 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterDriver); 119 DISALLOW_COPY_AND_ASSIGN(MockSubresourceFilterDriver);
120 }; 120 };
121 121
122 class NeverCompletingHttpResponse : public net::test_server::HttpResponse { 122 class NeverCompletingHttpResponse : public net::test_server::HttpResponse {
123 public: 123 public:
124 ~NeverCompletingHttpResponse() override {} 124 ~NeverCompletingHttpResponse() override {}
125 125
126 void SendResponse( 126 void SendResponse(
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage); 947 GURL bad_url = embedded_test_server()->GetURL(kMalwarePage);
948 948
949 SBFullHashResult malware_full_hash; 949 SBFullHashResult malware_full_hash;
950 GenUrlFullHashResultWithMetadata(bad_url, 950 GenUrlFullHashResultWithMetadata(bad_url,
951 PHISH, 951 PHISH,
952 ThreatPatternType::SOCIAL_ENGINEERING_ADS, 952 ThreatPatternType::SOCIAL_ENGINEERING_ADS,
953 &malware_full_hash); 953 &malware_full_hash);
954 SetupResponseForUrl(bad_url, malware_full_hash); 954 SetupResponseForUrl(bad_url, malware_full_hash);
955 955
956 WebContents* main_contents = 956 WebContents* main_contents =
957 browser()->tab_strip_model()->GetActiveWebContents(); 957 browser()->tab_strip_model()->GetActiveWebContents();
958 958
959 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) 959 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url)))
960 .Times(1); 960 .Times(1);
961 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_, ::testing::_, 961 EXPECT_CALL(*driver(),
962 ::testing::_)) 962 ActivateForNextCommittedLoad(::testing::_, ::testing::_))
963 .Times(0); 963 .Times(0);
964 ui_test_utils::NavigateToURL(browser(), bad_url); 964 ui_test_utils::NavigateToURL(browser(), bad_url);
965 Mock::VerifyAndClearExpectations(&observer_); 965 Mock::VerifyAndClearExpectations(&observer_);
966 ASSERT_TRUE(got_hit_report()); 966 ASSERT_TRUE(got_hit_report());
967 967
968 content::WaitForInterstitialAttach(main_contents); 968 content::WaitForInterstitialAttach(main_contents);
969 EXPECT_TRUE(ShowingInterstitialPage()); 969 EXPECT_TRUE(ShowingInterstitialPage());
970 testing::Mock::VerifyAndClearExpectations(driver()); 970 testing::Mock::VerifyAndClearExpectations(driver());
971 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_, ::testing::_, 971 EXPECT_CALL(*driver(),
972 ::testing::_)) 972 ActivateForNextCommittedLoad(::testing::_, ::testing::_))
973 .Times(1); 973 .Times(1);
974 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); 974 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage();
975 ASSERT_TRUE(interstitial_page); 975 ASSERT_TRUE(interstitial_page);
976 interstitial_page->Proceed(); 976 interstitial_page->Proceed();
977 content::WaitForInterstitialDetach(main_contents); 977 content::WaitForInterstitialDetach(main_contents);
978 EXPECT_FALSE(ShowingInterstitialPage()); 978 EXPECT_FALSE(ShowingInterstitialPage());
979 testing::Mock::VerifyAndClearExpectations(driver()); 979 testing::Mock::VerifyAndClearExpectations(driver());
980 } 980 }
981 981
982 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, SocEngReportingBlacklistEmpty) { 982 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, SocEngReportingBlacklistEmpty) {
983 // Tests that URLS which doesn't belong to the SOCIAL_ENGINEERING_ADS threat 983 // Tests that URLS which doesn't belong to the SOCIAL_ENGINEERING_ADS threat
984 // type aren't seen by the Subresource Filter. 984 // type aren't seen by the Subresource Filter.
985 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle 985 subresource_filter::testing::ScopedSubresourceFilterFeatureToggle
986 scoped_feature_toggle( 986 scoped_feature_toggle(
987 base::FeatureList::OVERRIDE_ENABLE_FEATURE, 987 base::FeatureList::OVERRIDE_ENABLE_FEATURE,
988 subresource_filter::kActivationLevelEnabled, 988 subresource_filter::kActivationLevelEnabled,
989 subresource_filter::kActivationScopeNoSites, 989 subresource_filter::kActivationScopeNoSites,
990 subresource_filter::kActivationListSocialEngineeringAdsInterstitial); 990 subresource_filter::kActivationListSocialEngineeringAdsInterstitial);
991 991
992 GURL bad_url = embedded_test_server()->base_url().Resolve(kMalwarePage); 992 GURL bad_url = embedded_test_server()->base_url().Resolve(kMalwarePage);
993 993
994 SBFullHashResult malware_full_hash; 994 SBFullHashResult malware_full_hash;
995 GenUrlFullHashResult(bad_url, MALWARE, &malware_full_hash); 995 GenUrlFullHashResult(bad_url, MALWARE, &malware_full_hash);
996 SetupResponseForUrl(bad_url, malware_full_hash); 996 SetupResponseForUrl(bad_url, malware_full_hash);
997 997
998 WebContents* main_contents = 998 WebContents* main_contents =
999 browser()->tab_strip_model()->GetActiveWebContents(); 999 browser()->tab_strip_model()->GetActiveWebContents();
1000 1000
1001 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url))) 1001 EXPECT_CALL(observer_, OnSafeBrowsingHit(IsUnsafeResourceFor(bad_url)))
1002 .Times(1); 1002 .Times(1);
1003 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_, ::testing::_, 1003 EXPECT_CALL(*driver(),
1004 ::testing::_)) 1004 ActivateForNextCommittedLoad(::testing::_, ::testing::_))
1005 .Times(0); 1005 .Times(0);
1006 ui_test_utils::NavigateToURL(browser(), bad_url); 1006 ui_test_utils::NavigateToURL(browser(), bad_url);
1007 testing::Mock::VerifyAndClearExpectations(driver()); 1007 testing::Mock::VerifyAndClearExpectations(driver());
1008 ASSERT_TRUE(got_hit_report()); 1008 ASSERT_TRUE(got_hit_report());
1009 1009
1010 content::WaitForInterstitialAttach(main_contents); 1010 content::WaitForInterstitialAttach(main_contents);
1011 EXPECT_TRUE(ShowingInterstitialPage()); 1011 EXPECT_TRUE(ShowingInterstitialPage());
1012 testing::Mock::VerifyAndClearExpectations(driver()); 1012 testing::Mock::VerifyAndClearExpectations(driver());
1013 EXPECT_CALL(*driver(), ActivateForProvisionalLoad(::testing::_, ::testing::_, 1013 EXPECT_CALL(*driver(),
1014 ::testing::_)) 1014 ActivateForNextCommittedLoad(::testing::_, ::testing::_))
1015 .Times(0); 1015 .Times(0);
1016 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage(); 1016 InterstitialPage* interstitial_page = main_contents->GetInterstitialPage();
1017 ASSERT_TRUE(interstitial_page); 1017 ASSERT_TRUE(interstitial_page);
1018 interstitial_page->Proceed(); 1018 interstitial_page->Proceed();
1019 content::WaitForInterstitialDetach(main_contents); 1019 content::WaitForInterstitialDetach(main_contents);
1020 EXPECT_FALSE(ShowingInterstitialPage()); 1020 EXPECT_FALSE(ShowingInterstitialPage());
1021 testing::Mock::VerifyAndClearExpectations(driver()); 1021 testing::Mock::VerifyAndClearExpectations(driver());
1022 } 1022 }
1023 1023
1024 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, 1024 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest,
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 content::Source<SafeBrowsingDatabaseManager>( 1828 content::Source<SafeBrowsingDatabaseManager>(
1829 sb_factory_->test_safe_browsing_service()->database_manager().get())); 1829 sb_factory_->test_safe_browsing_service()->database_manager().get()));
1830 BrowserThread::PostTask( 1830 BrowserThread::PostTask(
1831 BrowserThread::IO, FROM_HERE, 1831 BrowserThread::IO, FROM_HERE,
1832 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, 1832 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate,
1833 base::Unretained(this))); 1833 base::Unretained(this)));
1834 observer.Wait(); 1834 observer.Wait();
1835 } 1835 }
1836 1836
1837 } // namespace safe_browsing 1837 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698