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

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

Issue 10581012: Move test_url_fetcher_factory.* from content/ to net/url_request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove export annotations Created 8 years, 6 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 | Annotate | Revision Log
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 <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/scoped_temp_dir.h" 19 #include "base/scoped_temp_dir.h"
20 #include "base/string_number_conversions.h" 20 #include "base/string_number_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h" 21 #include "base/threading/sequenced_worker_pool.h"
22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
23 #include "chrome/browser/safe_browsing/signature_util.h" 23 #include "chrome/browser/safe_browsing/signature_util.h"
24 #include "chrome/common/safe_browsing/csd.pb.h" 24 #include "chrome/common/safe_browsing/csd.pb.h"
25 #include "chrome/common/zip.h" 25 #include "chrome/common/zip.h"
26 #include "content/public/browser/download_item.h" 26 #include "content/public/browser/download_item.h"
27 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
28 #include "content/public/test/test_url_fetcher_factory.h"
29 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
30 #include "net/base/x509_certificate.h" 29 #include "net/base/x509_certificate.h"
30 #include "net/url_request/test_url_fetcher_factory.h"
31 #include "net/url_request/url_fetcher_delegate.h" 31 #include "net/url_request/url_fetcher_delegate.h"
32 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 34
35 using ::testing::ContainerEq; 35 using ::testing::ContainerEq;
36 using ::testing::DoAll; 36 using ::testing::DoAll;
37 using ::testing::ElementsAre; 37 using ::testing::ElementsAre;
38 using ::testing::Mock; 38 using ::testing::Mock;
39 using ::testing::NotNull; 39 using ::testing::NotNull;
40 using ::testing::Return; 40 using ::testing::Return;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 msg_loop_.Run(); 243 msg_loop_.Run();
244 } 244 }
245 245
246 public: 246 public:
247 void CheckDoneCallback( 247 void CheckDoneCallback(
248 DownloadProtectionService::DownloadCheckResult result) { 248 DownloadProtectionService::DownloadCheckResult result) {
249 result_.reset(new DownloadProtectionService::DownloadCheckResult(result)); 249 result_.reset(new DownloadProtectionService::DownloadCheckResult(result));
250 msg_loop_.Quit(); 250 msg_loop_.Quit();
251 } 251 }
252 252
253 void SendURLFetchComplete(TestURLFetcher* fetcher) { 253 void SendURLFetchComplete(net::TestURLFetcher* fetcher) {
254 fetcher->delegate()->OnURLFetchComplete(fetcher); 254 fetcher->delegate()->OnURLFetchComplete(fetcher);
255 } 255 }
256 256
257 void ExpectResult(DownloadProtectionService::DownloadCheckResult expected) { 257 void ExpectResult(DownloadProtectionService::DownloadCheckResult expected) {
258 ASSERT_TRUE(result_.get()); 258 ASSERT_TRUE(result_.get());
259 EXPECT_EQ(expected, *result_); 259 EXPECT_EQ(expected, *result_);
260 } 260 }
261 261
262 protected: 262 protected:
263 scoped_refptr<MockSafeBrowsingService> sb_service_; 263 scoped_refptr<MockSafeBrowsingService> sb_service_;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 info.referrer_url = GURL("http://www.google.com/a.exe"); 317 info.referrer_url = GURL("http://www.google.com/a.exe");
318 download_service_->CheckClientDownload( 318 download_service_->CheckClientDownload(
319 info, 319 info,
320 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 320 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
321 base::Unretained(this))); 321 base::Unretained(this)));
322 msg_loop_.Run(); 322 msg_loop_.Run();
323 ExpectResult(DownloadProtectionService::SAFE); 323 ExpectResult(DownloadProtectionService::SAFE);
324 } 324 }
325 325
326 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { 326 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) {
327 FakeURLFetcherFactory factory; 327 net::FakeURLFetcherFactory factory;
328 // HTTP request will fail. 328 // HTTP request will fail.
329 factory.SetFakeResponse( 329 factory.SetFakeResponse(
330 DownloadProtectionService::kDownloadRequestUrl, "", false); 330 DownloadProtectionService::kDownloadRequestUrl, "", false);
331 331
332 DownloadProtectionService::DownloadInfo info; 332 DownloadProtectionService::DownloadInfo info;
333 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); 333 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp"));
334 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); 334 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe"));
335 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 335 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
336 info.referrer_url = GURL("http://www.google.com/"); 336 info.referrer_url = GURL("http://www.google.com/");
337 337
338 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 338 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
339 .WillRepeatedly(Return(false)); 339 .WillRepeatedly(Return(false));
340 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); 340 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
341 341
342 download_service_->CheckClientDownload( 342 download_service_->CheckClientDownload(
343 info, 343 info,
344 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 344 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
345 base::Unretained(this))); 345 base::Unretained(this)));
346 msg_loop_.Run(); 346 msg_loop_.Run();
347 ExpectResult(DownloadProtectionService::SAFE); 347 ExpectResult(DownloadProtectionService::SAFE);
348 } 348 }
349 349
350 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { 350 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
351 ClientDownloadResponse response; 351 ClientDownloadResponse response;
352 response.set_verdict(ClientDownloadResponse::SAFE); 352 response.set_verdict(ClientDownloadResponse::SAFE);
353 FakeURLFetcherFactory factory; 353 net::FakeURLFetcherFactory factory;
354 // Empty response means SAFE. 354 // Empty response means SAFE.
355 factory.SetFakeResponse( 355 factory.SetFakeResponse(
356 DownloadProtectionService::kDownloadRequestUrl, 356 DownloadProtectionService::kDownloadRequestUrl,
357 response.SerializeAsString(), 357 response.SerializeAsString(),
358 true); 358 true);
359 359
360 DownloadProtectionService::DownloadInfo info; 360 DownloadProtectionService::DownloadInfo info;
361 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); 361 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp"));
362 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); 362 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe"));
363 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 363 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 #if defined(OS_WIN) 421 #if defined(OS_WIN)
422 ExpectResult(DownloadProtectionService::UNCOMMON); 422 ExpectResult(DownloadProtectionService::UNCOMMON);
423 #else 423 #else
424 ExpectResult(DownloadProtectionService::SAFE); 424 ExpectResult(DownloadProtectionService::SAFE);
425 #endif 425 #endif
426 } 426 }
427 427
428 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { 428 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) {
429 ClientDownloadResponse response; 429 ClientDownloadResponse response;
430 response.set_verdict(ClientDownloadResponse::DANGEROUS); 430 response.set_verdict(ClientDownloadResponse::DANGEROUS);
431 FakeURLFetcherFactory factory; 431 net::FakeURLFetcherFactory factory;
432 factory.SetFakeResponse( 432 factory.SetFakeResponse(
433 DownloadProtectionService::kDownloadRequestUrl, 433 DownloadProtectionService::kDownloadRequestUrl,
434 response.SerializeAsString(), 434 response.SerializeAsString(),
435 true); 435 true);
436 436
437 DownloadProtectionService::DownloadInfo info; 437 DownloadProtectionService::DownloadInfo info;
438 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); 438 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp"));
439 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); 439 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe"));
440 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe")); 440 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe"));
441 info.referrer_url = GURL("http://www.google.com/"); 441 info.referrer_url = GURL("http://www.google.com/");
(...skipping 10 matching lines...) Expand all
452 #if defined(OS_WIN) 452 #if defined(OS_WIN)
453 ExpectResult(DownloadProtectionService::DANGEROUS); 453 ExpectResult(DownloadProtectionService::DANGEROUS);
454 #else 454 #else
455 ExpectResult(DownloadProtectionService::SAFE); 455 ExpectResult(DownloadProtectionService::SAFE);
456 #endif 456 #endif
457 } 457 }
458 458
459 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { 459 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
460 ClientDownloadResponse response; 460 ClientDownloadResponse response;
461 response.set_verdict(ClientDownloadResponse::SAFE); 461 response.set_verdict(ClientDownloadResponse::SAFE);
462 FakeURLFetcherFactory factory; 462 net::FakeURLFetcherFactory factory;
463 // Empty response means SAFE. 463 // Empty response means SAFE.
464 factory.SetFakeResponse( 464 factory.SetFakeResponse(
465 DownloadProtectionService::kDownloadRequestUrl, 465 DownloadProtectionService::kDownloadRequestUrl,
466 response.SerializeAsString(), 466 response.SerializeAsString(),
467 true); 467 true);
468 468
469 ScopedTempDir download_dir; 469 ScopedTempDir download_dir;
470 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); 470 ASSERT_TRUE(download_dir.CreateUniqueTempDir());
471 471
472 DownloadProtectionService::DownloadInfo info; 472 DownloadProtectionService::DownloadInfo info;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 Mock::VerifyAndClearExpectations(sb_service_); 556 Mock::VerifyAndClearExpectations(sb_service_);
557 Mock::VerifyAndClearExpectations(signature_util_); 557 Mock::VerifyAndClearExpectations(signature_util_);
558 } 558 }
559 559
560 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { 560 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) {
561 ClientDownloadResponse response; 561 ClientDownloadResponse response;
562 // Even if the server verdict is dangerous we should return SAFE because 562 // Even if the server verdict is dangerous we should return SAFE because
563 // DownloadProtectionService::IsSupportedDownload() will return false 563 // DownloadProtectionService::IsSupportedDownload() will return false
564 // for crx downloads. 564 // for crx downloads.
565 response.set_verdict(ClientDownloadResponse::DANGEROUS); 565 response.set_verdict(ClientDownloadResponse::DANGEROUS);
566 FakeURLFetcherFactory factory; 566 net::FakeURLFetcherFactory factory;
567 // Empty response means SAFE. 567 // Empty response means SAFE.
568 factory.SetFakeResponse( 568 factory.SetFakeResponse(
569 DownloadProtectionService::kDownloadRequestUrl, 569 DownloadProtectionService::kDownloadRequestUrl,
570 response.SerializeAsString(), 570 response.SerializeAsString(),
571 true); 571 true);
572 572
573 DownloadProtectionService::DownloadInfo info; 573 DownloadProtectionService::DownloadInfo info;
574 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); 574 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp"));
575 info.target_file = FilePath(FILE_PATH_LITERAL("a.crx")); 575 info.target_file = FilePath(FILE_PATH_LITERAL("a.crx"));
576 info.download_url_chain.push_back(GURL("http://www.evil.com/a.crx")); 576 info.download_url_chain.push_back(GURL("http://www.evil.com/a.crx"));
577 info.referrer_url = GURL("http://www.google.com/"); 577 info.referrer_url = GURL("http://www.google.com/");
578 578
579 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 579 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
580 .WillRepeatedly(Return(false)); 580 .WillRepeatedly(Return(false));
581 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1); 581 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1);
582 582
583 EXPECT_FALSE(download_service_->IsSupportedDownload(info)); 583 EXPECT_FALSE(download_service_->IsSupportedDownload(info));
584 download_service_->CheckClientDownload( 584 download_service_->CheckClientDownload(
585 info, 585 info,
586 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 586 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
587 base::Unretained(this))); 587 base::Unretained(this)));
588 msg_loop_.Run(); 588 msg_loop_.Run();
589 ExpectResult(DownloadProtectionService::SAFE); 589 ExpectResult(DownloadProtectionService::SAFE);
590 } 590 }
591 591
592 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { 592 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
593 TestURLFetcherFactory factory; 593 net::TestURLFetcherFactory factory;
594 594
595 DownloadProtectionService::DownloadInfo info; 595 DownloadProtectionService::DownloadInfo info;
596 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); 596 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp"));
597 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); 597 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe"));
598 info.download_url_chain.push_back(GURL("http://www.google.com/")); 598 info.download_url_chain.push_back(GURL("http://www.google.com/"));
599 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); 599 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
600 info.referrer_url = GURL("http://www.google.com/"); 600 info.referrer_url = GURL("http://www.google.com/");
601 info.sha256_hash = "hash"; 601 info.sha256_hash = "hash";
602 info.total_bytes = 100; 602 info.total_bytes = 100;
603 info.user_initiated = true; 603 info.user_initiated = true;
604 info.remote_address = "10.11.12.13"; 604 info.remote_address = "10.11.12.13";
605 605
606 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 606 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
607 .WillRepeatedly(Return(false)); 607 .WillRepeatedly(Return(false));
608 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)) 608 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _))
609 .WillOnce(SetCertificateContents("dummy cert data")); 609 .WillOnce(SetCertificateContents("dummy cert data"));
610 download_service_->CheckClientDownload( 610 download_service_->CheckClientDownload(
611 info, 611 info,
612 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 612 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
613 base::Unretained(this))); 613 base::Unretained(this)));
614 614
615 #if !defined(OS_WIN) 615 #if !defined(OS_WIN)
616 // SendRequest is not called. Wait for FinishRequest to call our callback. 616 // SendRequest is not called. Wait for FinishRequest to call our callback.
617 msg_loop_.Run(); 617 msg_loop_.Run();
618 TestURLFetcher* fetcher = factory.GetFetcherByID(0); 618 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
619 EXPECT_EQ(NULL, fetcher); 619 EXPECT_EQ(NULL, fetcher);
620 #else 620 #else
621 // Run the message loop(s) until SendRequest is called. 621 // Run the message loop(s) until SendRequest is called.
622 FlushThreadMessageLoops(); 622 FlushThreadMessageLoops();
623 TestURLFetcher* fetcher = factory.GetFetcherByID(0); 623 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
624 ASSERT_TRUE(fetcher); 624 ASSERT_TRUE(fetcher);
625 ClientDownloadRequest request; 625 ClientDownloadRequest request;
626 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); 626 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data()));
627 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); 627 EXPECT_EQ("http://www.google.com/bla.exe", request.url());
628 EXPECT_EQ(info.sha256_hash, request.digests().sha256()); 628 EXPECT_EQ(info.sha256_hash, request.digests().sha256());
629 EXPECT_EQ(info.total_bytes, request.length()); 629 EXPECT_EQ(info.total_bytes, request.length());
630 EXPECT_EQ(info.user_initiated, request.user_initiated()); 630 EXPECT_EQ(info.user_initiated, request.user_initiated());
631 EXPECT_TRUE(RequestContainsServerIp(request, info.remote_address)); 631 EXPECT_TRUE(RequestContainsServerIp(request, info.remote_address));
632 EXPECT_EQ(2, request.resources_size()); 632 EXPECT_EQ(2, request.resources_size());
633 EXPECT_TRUE(RequestContainsResource(request, 633 EXPECT_TRUE(RequestContainsResource(request,
(...skipping 15 matching lines...) Expand all
649 FROM_HERE, 649 FROM_HERE,
650 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 650 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
651 base::Unretained(this), fetcher)); 651 base::Unretained(this), fetcher));
652 msg_loop_.Run(); 652 msg_loop_.Run();
653 #endif 653 #endif
654 } 654 }
655 655
656 // Similar to above, but with an unsigned binary. 656 // Similar to above, but with an unsigned binary.
657 TEST_F(DownloadProtectionServiceTest, 657 TEST_F(DownloadProtectionServiceTest,
658 CheckClientDownloadValidateRequestNoSignature) { 658 CheckClientDownloadValidateRequestNoSignature) {
659 TestURLFetcherFactory factory; 659 net::TestURLFetcherFactory factory;
660 660
661 DownloadProtectionService::DownloadInfo info; 661 DownloadProtectionService::DownloadInfo info;
662 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); 662 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp"));
663 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); 663 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe"));
664 info.download_url_chain.push_back(GURL("http://www.google.com/")); 664 info.download_url_chain.push_back(GURL("http://www.google.com/"));
665 info.download_url_chain.push_back(GURL("ftp://www.google.com/bla.exe")); 665 info.download_url_chain.push_back(GURL("ftp://www.google.com/bla.exe"));
666 info.referrer_url = GURL("http://www.google.com/"); 666 info.referrer_url = GURL("http://www.google.com/");
667 info.sha256_hash = "hash"; 667 info.sha256_hash = "hash";
668 info.total_bytes = 100; 668 info.total_bytes = 100;
669 info.user_initiated = false; 669 info.user_initiated = false;
670 670
671 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 671 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
672 .WillRepeatedly(Return(false)); 672 .WillRepeatedly(Return(false));
673 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); 673 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
674 download_service_->CheckClientDownload( 674 download_service_->CheckClientDownload(
675 info, 675 info,
676 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 676 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
677 base::Unretained(this))); 677 base::Unretained(this)));
678 678
679 #if !defined(OS_WIN) 679 #if !defined(OS_WIN)
680 // SendRequest is not called. Wait for FinishRequest to call our callback. 680 // SendRequest is not called. Wait for FinishRequest to call our callback.
681 msg_loop_.Run(); 681 msg_loop_.Run();
682 TestURLFetcher* fetcher = factory.GetFetcherByID(0); 682 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
683 EXPECT_EQ(NULL, fetcher); 683 EXPECT_EQ(NULL, fetcher);
684 #else 684 #else
685 // Run the message loop(s) until SendRequest is called. 685 // Run the message loop(s) until SendRequest is called.
686 FlushThreadMessageLoops(); 686 FlushThreadMessageLoops();
687 TestURLFetcher* fetcher = factory.GetFetcherByID(0); 687 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
688 ASSERT_TRUE(fetcher); 688 ASSERT_TRUE(fetcher);
689 ClientDownloadRequest request; 689 ClientDownloadRequest request;
690 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); 690 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data()));
691 EXPECT_EQ("ftp://www.google.com/bla.exe", request.url()); 691 EXPECT_EQ("ftp://www.google.com/bla.exe", request.url());
692 EXPECT_EQ(info.sha256_hash, request.digests().sha256()); 692 EXPECT_EQ(info.sha256_hash, request.digests().sha256());
693 EXPECT_EQ(info.total_bytes, request.length()); 693 EXPECT_EQ(info.total_bytes, request.length());
694 EXPECT_EQ(info.user_initiated, request.user_initiated()); 694 EXPECT_EQ(info.user_initiated, request.user_initiated());
695 EXPECT_EQ(2, request.resources_size()); 695 EXPECT_EQ(2, request.resources_size());
696 EXPECT_TRUE(RequestContainsResource(request, 696 EXPECT_TRUE(RequestContainsResource(request,
697 ClientDownloadRequest::DOWNLOAD_REDIRECT, 697 ClientDownloadRequest::DOWNLOAD_REDIRECT,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 Return(false))); 768 Return(false)));
769 download_service_->CheckDownloadUrl( 769 download_service_->CheckDownloadUrl(
770 info, 770 info,
771 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 771 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
772 base::Unretained(this))); 772 base::Unretained(this)));
773 msg_loop_.Run(); 773 msg_loop_.Run();
774 ExpectResult(DownloadProtectionService::DANGEROUS); 774 ExpectResult(DownloadProtectionService::DANGEROUS);
775 } 775 }
776 776
777 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { 777 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) {
778 TestURLFetcherFactory factory; 778 net::TestURLFetcherFactory factory;
779 779
780 DownloadProtectionService::DownloadInfo info; 780 DownloadProtectionService::DownloadInfo info;
781 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); 781 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe"));
782 info.referrer_url = GURL("http://www.google.com/"); 782 info.referrer_url = GURL("http://www.google.com/");
783 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); 783 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp"));
784 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); 784 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe"));
785 785
786 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 786 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
787 .WillRepeatedly(Return(false)); 787 .WillRepeatedly(Return(false));
788 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); 788 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 870 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
871 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 871 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
872 872
873 cert = ReadTestCertificate("test_c.pem"); 873 cert = ReadTestCertificate("test_c.pem");
874 ASSERT_TRUE(cert.get()); 874 ASSERT_TRUE(cert.get());
875 whitelist_strings.clear(); 875 whitelist_strings.clear();
876 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 876 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
877 EXPECT_THAT(whitelist_strings, ElementsAre()); 877 EXPECT_THAT(whitelist_strings, ElementsAre());
878 } 878 }
879 } // namespace safe_browsing 879 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698