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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service_unittest.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 #include "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 226
227 ACTION_P(CheckDownloadUrlDone, threat_type) { 227 ACTION_P(CheckDownloadUrlDone, threat_type) {
228 // TODO(nparker): Remove use of SafeBrowsingCheck and instead call 228 // TODO(nparker): Remove use of SafeBrowsingCheck and instead call
229 // client->OnCheckDownloadUrlResult(..) directly. 229 // client->OnCheckDownloadUrlResult(..) directly.
230 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck* check = 230 LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck* check =
231 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck( 231 new LocalSafeBrowsingDatabaseManager::SafeBrowsingCheck(
232 arg0, std::vector<SBFullHash>(), arg1, BINURL, 232 arg0, std::vector<SBFullHash>(), arg1, BINURL,
233 std::vector<SBThreatType>(1, SB_THREAT_TYPE_BINARY_MALWARE_URL)); 233 std::vector<SBThreatType>(1, SB_THREAT_TYPE_BINARY_MALWARE_URL));
234 for (size_t i = 0; i < check->url_results.size(); ++i) 234 for (size_t i = 0; i < check->url_results.size(); ++i)
235 check->url_results[i] = threat_type; 235 check->url_results[i] = threat_type;
236 BrowserThread::PostTask(BrowserThread::IO, 236 BrowserThread::PostTask(
237 FROM_HERE, 237 BrowserThread::IO, FROM_HERE,
238 base::Bind(&OnSafeBrowsingResult, 238 base::BindOnce(&OnSafeBrowsingResult, base::Owned(check)));
239 base::Owned(check)));
240 } 239 }
241 240
242 class DownloadProtectionServiceTest : public testing::Test { 241 class DownloadProtectionServiceTest : public testing::Test {
243 protected: 242 protected:
244 DownloadProtectionServiceTest() 243 DownloadProtectionServiceTest()
245 : test_browser_thread_bundle_( 244 : test_browser_thread_bundle_(
246 content::TestBrowserThreadBundle::IO_MAINLOOP) { 245 content::TestBrowserThreadBundle::IO_MAINLOOP) {
247 } 246 }
248 void SetUp() override { 247 void SetUp() override {
249 // Start real threads for the IO and File threads so that the DCHECKs 248 // Start real threads for the IO and File threads so that the DCHECKs
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // Helper functions for FlushThreadMessageLoops. 457 // Helper functions for FlushThreadMessageLoops.
459 void RunAllPendingAndQuitUI(const base::Closure& quit_closure) { 458 void RunAllPendingAndQuitUI(const base::Closure& quit_closure) {
460 RunLoop().RunUntilIdle(); 459 RunLoop().RunUntilIdle();
461 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_closure); 460 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, quit_closure);
462 } 461 }
463 462
464 void PostRunMessageLoopTask(BrowserThread::ID thread, 463 void PostRunMessageLoopTask(BrowserThread::ID thread,
465 const base::Closure& quit_closure) { 464 const base::Closure& quit_closure) {
466 BrowserThread::PostTask( 465 BrowserThread::PostTask(
467 thread, FROM_HERE, 466 thread, FROM_HERE,
468 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI, 467 base::BindOnce(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI,
469 base::Unretained(this), quit_closure)); 468 base::Unretained(this), quit_closure));
470 } 469 }
471 470
472 void FlushMessageLoop(BrowserThread::ID thread) { 471 void FlushMessageLoop(BrowserThread::ID thread) {
473 RunLoop run_loop; 472 RunLoop run_loop;
474 BrowserThread::PostTask( 473 BrowserThread::PostTask(
475 BrowserThread::UI, FROM_HERE, 474 BrowserThread::UI, FROM_HERE,
476 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, 475 base::BindOnce(&DownloadProtectionServiceTest::PostRunMessageLoopTask,
477 base::Unretained(this), thread, run_loop.QuitClosure())); 476 base::Unretained(this), thread, run_loop.QuitClosure()));
478 run_loop.Run(); 477 run_loop.Run();
479 } 478 }
480 479
481 void OnClientDownloadRequest(content::DownloadItem* download, 480 void OnClientDownloadRequest(content::DownloadItem* download,
482 const ClientDownloadRequest* request) { 481 const ClientDownloadRequest* request) {
483 if (request) 482 if (request)
484 last_client_download_request_.reset(new ClientDownloadRequest(*request)); 483 last_client_download_request_.reset(new ClientDownloadRequest(*request));
485 else 484 else
486 last_client_download_request_.reset(); 485 last_client_download_request_.reset();
487 } 486 }
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 EXPECT_TRUE(request.has_image_headers()); 1504 EXPECT_TRUE(request.has_image_headers());
1506 const ClientDownloadRequest_ImageHeaders& headers = 1505 const ClientDownloadRequest_ImageHeaders& headers =
1507 request.image_headers(); 1506 request.image_headers();
1508 EXPECT_TRUE(headers.has_pe_headers()); 1507 EXPECT_TRUE(headers.has_pe_headers());
1509 EXPECT_TRUE(headers.pe_headers().has_dos_header()); 1508 EXPECT_TRUE(headers.pe_headers().has_dos_header());
1510 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); 1509 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header());
1511 1510
1512 // Simulate the request finishing. 1511 // Simulate the request finishing.
1513 base::ThreadTaskRunnerHandle::Get()->PostTask( 1512 base::ThreadTaskRunnerHandle::Get()->PostTask(
1514 FROM_HERE, 1513 FROM_HERE,
1515 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 1514 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete,
1516 base::Unretained(this), fetcher)); 1515 base::Unretained(this), fetcher));
1517 run_loop.Run(); 1516 run_loop.Run();
1518 } 1517 }
1519 1518
1520 // Similar to above, but with an unsigned binary. 1519 // Similar to above, but with an unsigned binary.
1521 TEST_F(DownloadProtectionServiceTest, 1520 TEST_F(DownloadProtectionServiceTest,
1522 CheckClientDownloadValidateRequestNoSignature) { 1521 CheckClientDownloadValidateRequestNoSignature) {
1523 net::TestURLFetcherFactory factory; 1522 net::TestURLFetcherFactory factory;
1524 1523
1525 content::MockDownloadItem item; 1524 content::MockDownloadItem item;
1526 PrepareBasicDownloadItem( 1525 PrepareBasicDownloadItem(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 EXPECT_TRUE(RequestContainsResource(request, 1564 EXPECT_TRUE(RequestContainsResource(request,
1566 ClientDownloadRequest::DOWNLOAD_URL, 1565 ClientDownloadRequest::DOWNLOAD_URL,
1567 "ftp://www.google.com/bla.exe", 1566 "ftp://www.google.com/bla.exe",
1568 referrer_.spec())); 1567 referrer_.spec()));
1569 EXPECT_TRUE(request.has_signature()); 1568 EXPECT_TRUE(request.has_signature());
1570 EXPECT_EQ(0, request.signature().certificate_chain_size()); 1569 EXPECT_EQ(0, request.signature().certificate_chain_size());
1571 1570
1572 // Simulate the request finishing. 1571 // Simulate the request finishing.
1573 base::ThreadTaskRunnerHandle::Get()->PostTask( 1572 base::ThreadTaskRunnerHandle::Get()->PostTask(
1574 FROM_HERE, 1573 FROM_HERE,
1575 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 1574 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete,
1576 base::Unretained(this), fetcher)); 1575 base::Unretained(this), fetcher));
1577 run_loop.Run(); 1576 run_loop.Run();
1578 } 1577 }
1579 1578
1580 // Similar to above, but with tab history. 1579 // Similar to above, but with tab history.
1581 TEST_F(DownloadProtectionServiceTest, 1580 TEST_F(DownloadProtectionServiceTest,
1582 CheckClientDownloadValidateRequestTabHistory) { 1581 CheckClientDownloadValidateRequestTabHistory) {
1583 net::TestURLFetcherFactory factory; 1582 net::TestURLFetcherFactory factory;
1584 1583
1585 content::MockDownloadItem item; 1584 content::MockDownloadItem item;
1586 PrepareBasicDownloadItem( 1585 PrepareBasicDownloadItem(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 EXPECT_TRUE(request.has_image_headers()); 1652 EXPECT_TRUE(request.has_image_headers());
1654 const ClientDownloadRequest_ImageHeaders& headers = 1653 const ClientDownloadRequest_ImageHeaders& headers =
1655 request.image_headers(); 1654 request.image_headers();
1656 EXPECT_TRUE(headers.has_pe_headers()); 1655 EXPECT_TRUE(headers.has_pe_headers());
1657 EXPECT_TRUE(headers.pe_headers().has_dos_header()); 1656 EXPECT_TRUE(headers.pe_headers().has_dos_header());
1658 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); 1657 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header());
1659 1658
1660 // Simulate the request finishing. 1659 // Simulate the request finishing.
1661 base::ThreadTaskRunnerHandle::Get()->PostTask( 1660 base::ThreadTaskRunnerHandle::Get()->PostTask(
1662 FROM_HERE, 1661 FROM_HERE,
1663 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 1662 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete,
1664 base::Unretained(this), fetcher)); 1663 base::Unretained(this), fetcher));
1665 run_loop.Run(); 1664 run_loop.Run();
1666 } 1665 }
1667 1666
1668 // Now try with a history match. 1667 // Now try with a history match.
1669 { 1668 {
1670 history::RedirectList redirects; 1669 history::RedirectList redirects;
1671 redirects.push_back(GURL("http://tab.com/ref1")); 1670 redirects.push_back(GURL("http://tab.com/ref1"));
1672 redirects.push_back(GURL("http://tab.com/ref2")); 1671 redirects.push_back(GURL("http://tab.com/ref2"));
1673 redirects.push_back(tab_url); 1672 redirects.push_back(tab_url);
1674 HistoryServiceFactory::GetForProfile(profile_.get(), 1673 HistoryServiceFactory::GetForProfile(profile_.get(),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 EXPECT_TRUE(request.has_signature()); 1724 EXPECT_TRUE(request.has_signature());
1726 ASSERT_EQ(1, request.signature().certificate_chain_size()); 1725 ASSERT_EQ(1, request.signature().certificate_chain_size());
1727 const ClientDownloadRequest_CertificateChain& chain = 1726 const ClientDownloadRequest_CertificateChain& chain =
1728 request.signature().certificate_chain(0); 1727 request.signature().certificate_chain(0);
1729 ASSERT_EQ(1, chain.element_size()); 1728 ASSERT_EQ(1, chain.element_size());
1730 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); 1729 EXPECT_EQ("dummy cert data", chain.element(0).certificate());
1731 1730
1732 // Simulate the request finishing. 1731 // Simulate the request finishing.
1733 base::ThreadTaskRunnerHandle::Get()->PostTask( 1732 base::ThreadTaskRunnerHandle::Get()->PostTask(
1734 FROM_HERE, 1733 FROM_HERE,
1735 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 1734 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete,
1736 base::Unretained(this), fetcher)); 1735 base::Unretained(this), fetcher));
1737 run_loop.Run(); 1736 run_loop.Run();
1738 } 1737 }
1739 } 1738 }
1740 1739
1741 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { 1740 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
1742 net::TestURLFetcherFactory factory; 1741 net::TestURLFetcherFactory factory;
1743 1742
1744 std::vector<GURL> url_chain; 1743 std::vector<GURL> url_chain;
1745 url_chain.push_back(GURL("http://www.google.com/")); 1744 url_chain.push_back(GURL("http://www.google.com/"));
1746 url_chain.push_back(GURL("http://www.google.com/bla.exe")); 1745 url_chain.push_back(GURL("http://www.google.com/bla.exe"));
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2346 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 2345 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
2347 base::Unretained(this), run_loop.QuitClosure())); 2346 base::Unretained(this), run_loop.QuitClosure()));
2348 run_loop.Run(); 2347 run_loop.Run();
2349 2348
2350 EXPECT_FALSE(HasClientDownloadRequest()); 2349 EXPECT_FALSE(HasClientDownloadRequest());
2351 // Overriden by flag: 2350 // Overriden by flag:
2352 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
2353 } 2352 }
2354 2353
2355 } // namespace safe_browsing 2354 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698