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

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

Issue 2821193005: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/safe_browsing (Closed)
Patch Set: 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 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // database and safebrowsing service issues a get hash request to backends. 398 // database and safebrowsing service issues a get hash request to backends.
399 // We return a result from the prefilled full_hashes_ hash_map to simulate 399 // We return a result from the prefilled full_hashes_ hash_map to simulate
400 // server's response. At the same time, latency is added to simulate real 400 // server's response. At the same time, latency is added to simulate real
401 // life network issues. 401 // life network issues.
402 void GetFullHash(const std::vector<SBPrefix>& prefixes, 402 void GetFullHash(const std::vector<SBPrefix>& prefixes,
403 SafeBrowsingProtocolManager::FullHashCallback callback, 403 SafeBrowsingProtocolManager::FullHashCallback callback,
404 bool is_download, 404 bool is_download,
405 ExtendedReportingLevel reporting_level) override { 405 ExtendedReportingLevel reporting_level) override {
406 BrowserThread::PostDelayedTask( 406 BrowserThread::PostDelayedTask(
407 BrowserThread::IO, FROM_HERE, 407 BrowserThread::IO, FROM_HERE,
408 base::Bind(InvokeFullHashCallback, callback, full_hashes_), delay_); 408 base::BindOnce(InvokeFullHashCallback, callback, full_hashes_), delay_);
409 } 409 }
410 410
411 // Prepare the GetFullHash results for the next request. 411 // Prepare the GetFullHash results for the next request.
412 void AddGetFullHashResponse(const SBFullHashResult& full_hash_result) { 412 void AddGetFullHashResponse(const SBFullHashResult& full_hash_result) {
413 full_hashes_.push_back(full_hash_result); 413 full_hashes_.push_back(full_hash_result);
414 } 414 }
415 415
416 void IntroduceDelay(const base::TimeDelta& delay) { delay_ = delay; } 416 void IntroduceDelay(const base::TimeDelta& delay) { delay_ = delay; }
417 417
418 static int create_count() { return create_count_; } 418 static int create_count() { return create_count_; }
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 : threat_type_(SB_THREAT_TYPE_SAFE), 1186 : threat_type_(SB_THREAT_TYPE_SAFE),
1187 safe_browsing_service_(g_browser_process->safe_browsing_service()) {} 1187 safe_browsing_service_(g_browser_process->safe_browsing_service()) {}
1188 1188
1189 SBThreatType GetThreatType() const { return threat_type_; } 1189 SBThreatType GetThreatType() const { return threat_type_; }
1190 1190
1191 std::string GetThreatHash() const { return threat_hash_; } 1191 std::string GetThreatHash() const { return threat_hash_; }
1192 1192
1193 void CheckDownloadUrl(const std::vector<GURL>& url_chain) { 1193 void CheckDownloadUrl(const std::vector<GURL>& url_chain) {
1194 BrowserThread::PostTask( 1194 BrowserThread::PostTask(
1195 BrowserThread::IO, FROM_HERE, 1195 BrowserThread::IO, FROM_HERE,
1196 base::Bind(&TestSBClient::CheckDownloadUrlOnIOThread, this, url_chain)); 1196 base::BindOnce(&TestSBClient::CheckDownloadUrlOnIOThread, this,
1197 url_chain));
1197 content::RunMessageLoop(); // Will stop in OnCheckDownloadUrlResult. 1198 content::RunMessageLoop(); // Will stop in OnCheckDownloadUrlResult.
1198 } 1199 }
1199 1200
1200 void CheckBrowseUrl(const GURL& url) { 1201 void CheckBrowseUrl(const GURL& url) {
1201 BrowserThread::PostTask( 1202 BrowserThread::PostTask(
1202 BrowserThread::IO, FROM_HERE, 1203 BrowserThread::IO, FROM_HERE,
1203 base::Bind(&TestSBClient::CheckBrowseUrlOnIOThread, this, url)); 1204 base::BindOnce(&TestSBClient::CheckBrowseUrlOnIOThread, this, url));
1204 content::RunMessageLoop(); // Will stop in OnCheckBrowseUrlResult. 1205 content::RunMessageLoop(); // Will stop in OnCheckBrowseUrlResult.
1205 } 1206 }
1206 1207
1207 void CheckResourceUrl(const GURL& url) { 1208 void CheckResourceUrl(const GURL& url) {
1208 BrowserThread::PostTask( 1209 BrowserThread::PostTask(
1209 BrowserThread::IO, FROM_HERE, 1210 BrowserThread::IO, FROM_HERE,
1210 base::Bind(&TestSBClient::CheckResourceUrlOnIOThread, this, url)); 1211 base::BindOnce(&TestSBClient::CheckResourceUrlOnIOThread, this, url));
1211 content::RunMessageLoop(); // Will stop in OnCheckResourceUrlResult. 1212 content::RunMessageLoop(); // Will stop in OnCheckResourceUrlResult.
1212 } 1213 }
1213 1214
1214 private: 1215 private:
1215 friend class base::RefCountedThreadSafe<TestSBClient>; 1216 friend class base::RefCountedThreadSafe<TestSBClient>;
1216 ~TestSBClient() override {} 1217 ~TestSBClient() override {}
1217 1218
1218 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain) { 1219 void CheckDownloadUrlOnIOThread(const std::vector<GURL>& url_chain) {
1219 bool synchronous_safe_signal = 1220 bool synchronous_safe_signal =
1220 safe_browsing_service_->database_manager()->CheckDownloadUrl(url_chain, 1221 safe_browsing_service_->database_manager()->CheckDownloadUrl(url_chain,
1221 this); 1222 this);
1222 if (synchronous_safe_signal) { 1223 if (synchronous_safe_signal) {
1223 threat_type_ = SB_THREAT_TYPE_SAFE; 1224 threat_type_ = SB_THREAT_TYPE_SAFE;
1224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1225 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1225 base::Bind(&TestSBClient::CheckDone, this)); 1226 base::BindOnce(&TestSBClient::CheckDone, this));
1226 } 1227 }
1227 } 1228 }
1228 1229
1229 void CheckBrowseUrlOnIOThread(const GURL& url) { 1230 void CheckBrowseUrlOnIOThread(const GURL& url) {
1230 // The async CheckDone() hook will not be called when we have a synchronous 1231 // The async CheckDone() hook will not be called when we have a synchronous
1231 // safe signal, handle it right away. 1232 // safe signal, handle it right away.
1232 bool synchronous_safe_signal = 1233 bool synchronous_safe_signal =
1233 safe_browsing_service_->database_manager()->CheckBrowseUrl(url, this); 1234 safe_browsing_service_->database_manager()->CheckBrowseUrl(url, this);
1234 if (synchronous_safe_signal) { 1235 if (synchronous_safe_signal) {
1235 threat_type_ = SB_THREAT_TYPE_SAFE; 1236 threat_type_ = SB_THREAT_TYPE_SAFE;
1236 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1237 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1237 base::Bind(&TestSBClient::CheckDone, this)); 1238 base::BindOnce(&TestSBClient::CheckDone, this));
1238 } 1239 }
1239 } 1240 }
1240 1241
1241 void CheckResourceUrlOnIOThread(const GURL& url) { 1242 void CheckResourceUrlOnIOThread(const GURL& url) {
1242 bool synchronous_safe_signal = 1243 bool synchronous_safe_signal =
1243 safe_browsing_service_->database_manager()->CheckResourceUrl(url, this); 1244 safe_browsing_service_->database_manager()->CheckResourceUrl(url, this);
1244 if (synchronous_safe_signal) { 1245 if (synchronous_safe_signal) {
1245 threat_type_ = SB_THREAT_TYPE_SAFE; 1246 threat_type_ = SB_THREAT_TYPE_SAFE;
1246 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1247 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1247 base::Bind(&TestSBClient::CheckDone, this)); 1248 base::BindOnce(&TestSBClient::CheckDone, this));
1248 } 1249 }
1249 } 1250 }
1250 1251
1251 // Called when the result of checking a download URL is known. 1252 // Called when the result of checking a download URL is known.
1252 void OnCheckDownloadUrlResult(const std::vector<GURL>& /* url_chain */, 1253 void OnCheckDownloadUrlResult(const std::vector<GURL>& /* url_chain */,
1253 SBThreatType threat_type) override { 1254 SBThreatType threat_type) override {
1254 threat_type_ = threat_type; 1255 threat_type_ = threat_type;
1255 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1256 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1256 base::Bind(&TestSBClient::CheckDone, this)); 1257 base::BindOnce(&TestSBClient::CheckDone, this));
1257 } 1258 }
1258 1259
1259 // Called when the result of checking a browse URL is known. 1260 // Called when the result of checking a browse URL is known.
1260 void OnCheckBrowseUrlResult(const GURL& /* url */, 1261 void OnCheckBrowseUrlResult(const GURL& /* url */,
1261 SBThreatType threat_type, 1262 SBThreatType threat_type,
1262 const ThreatMetadata& /* metadata */) override { 1263 const ThreatMetadata& /* metadata */) override {
1263 threat_type_ = threat_type; 1264 threat_type_ = threat_type;
1264 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1265 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1265 base::Bind(&TestSBClient::CheckDone, this)); 1266 base::BindOnce(&TestSBClient::CheckDone, this));
1266 } 1267 }
1267 1268
1268 // Called when the result of checking a resource URL is known. 1269 // Called when the result of checking a resource URL is known.
1269 void OnCheckResourceUrlResult(const GURL& /* url */, 1270 void OnCheckResourceUrlResult(const GURL& /* url */,
1270 SBThreatType threat_type, 1271 SBThreatType threat_type,
1271 const std::string& threat_hash) override { 1272 const std::string& threat_hash) override {
1272 threat_type_ = threat_type; 1273 threat_type_ = threat_type;
1273 threat_hash_ = threat_hash; 1274 threat_hash_ = threat_hash;
1274 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 1275 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1275 base::Bind(&TestSBClient::CheckDone, this)); 1276 base::BindOnce(&TestSBClient::CheckDone, this));
1276 } 1277 }
1277 1278
1278 void CheckDone() { base::MessageLoopForUI::current()->QuitWhenIdle(); } 1279 void CheckDone() { base::MessageLoopForUI::current()->QuitWhenIdle(); }
1279 1280
1280 SBThreatType threat_type_; 1281 SBThreatType threat_type_;
1281 std::string threat_hash_; 1282 std::string threat_hash_;
1282 SafeBrowsingService* safe_browsing_service_; 1283 SafeBrowsingService* safe_browsing_service_;
1283 1284
1284 DISALLOW_COPY_AND_ASSIGN(TestSBClient); 1285 DISALLOW_COPY_AND_ASSIGN(TestSBClient);
1285 }; 1286 };
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
1773 // Test that a Local Safe Browsing database update request both sends cookies 1774 // Test that a Local Safe Browsing database update request both sends cookies
1774 // and can save cookies. 1775 // and can save cookies.
1775 IN_PROC_BROWSER_TEST_F(SafeBrowsingDatabaseManagerCookieTest, 1776 IN_PROC_BROWSER_TEST_F(SafeBrowsingDatabaseManagerCookieTest,
1776 TestSBUpdateCookies) { 1777 TestSBUpdateCookies) {
1777 content::WindowedNotificationObserver observer( 1778 content::WindowedNotificationObserver observer(
1778 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE, 1779 chrome::NOTIFICATION_SAFE_BROWSING_UPDATE_COMPLETE,
1779 content::Source<SafeBrowsingDatabaseManager>( 1780 content::Source<SafeBrowsingDatabaseManager>(
1780 sb_factory_->test_safe_browsing_service()->database_manager().get())); 1781 sb_factory_->test_safe_browsing_service()->database_manager().get()));
1781 BrowserThread::PostTask( 1782 BrowserThread::PostTask(
1782 BrowserThread::IO, FROM_HERE, 1783 BrowserThread::IO, FROM_HERE,
1783 base::Bind(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate, 1784 base::BindOnce(&SafeBrowsingDatabaseManagerCookieTest::ForceUpdate,
1784 base::Unretained(this))); 1785 base::Unretained(this)));
1785 observer.Wait(); 1786 observer.Wait();
1786 } 1787 }
1787 1788
1788 // Tests the safe browsing blocking page in a browser. 1789 // Tests the safe browsing blocking page in a browser.
1789 class V4SafeBrowsingServiceTest : public SafeBrowsingServiceTest { 1790 class V4SafeBrowsingServiceTest : public SafeBrowsingServiceTest {
1790 public: 1791 public:
1791 V4SafeBrowsingServiceTest() : SafeBrowsingServiceTest() {} 1792 V4SafeBrowsingServiceTest() : SafeBrowsingServiceTest() {}
1792 1793
1793 void SetUp() override { 1794 void SetUp() override {
1794 sb_factory_ = base::MakeUnique<TestSafeBrowsingServiceFactory>( 1795 sb_factory_ = base::MakeUnique<TestSafeBrowsingServiceFactory>(
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
2497 } 2498 }
2498 2499
2499 INSTANTIATE_TEST_CASE_P( 2500 INSTANTIATE_TEST_CASE_P(
2500 MaybeSetMetadata, 2501 MaybeSetMetadata,
2501 V4SafeBrowsingServiceMetadataTest, 2502 V4SafeBrowsingServiceMetadataTest,
2502 testing::Values(ThreatPatternType::NONE, 2503 testing::Values(ThreatPatternType::NONE,
2503 ThreatPatternType::MALWARE_LANDING, 2504 ThreatPatternType::MALWARE_LANDING,
2504 ThreatPatternType::MALWARE_DISTRIBUTION)); 2505 ThreatPatternType::MALWARE_DISTRIBUTION));
2505 2506
2506 } // namespace safe_browsing 2507 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_service.cc ('k') | chrome/browser/safe_browsing/sandboxed_zip_analyzer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698