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

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

Issue 12211076: Refactored FakeURLFetcher to make it more flexible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 #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"
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 info.referrer_url = GURL("http://www.google.com/a.exe"); 356 info.referrer_url = GURL("http://www.google.com/a.exe");
357 download_service_->CheckClientDownload( 357 download_service_->CheckClientDownload(
358 info, 358 info,
359 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 359 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
360 base::Unretained(this))); 360 base::Unretained(this)));
361 msg_loop_.Run(); 361 msg_loop_.Run();
362 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 362 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
363 } 363 }
364 364
365 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { 365 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) {
366 net::FakeURLFetcherFactory factory; 366 net::FakeURLFetcherFactory factory(NULL);
367 // HTTP request will fail. 367 // HTTP request will fail.
368 factory.SetFakeResponse( 368 factory.SetFakeResponse(
369 DownloadProtectionService::GetDownloadRequestUrl(), "", false); 369 DownloadProtectionService::GetDownloadRequestUrl(), "", false);
370 370
371 DownloadProtectionService::DownloadInfo info; 371 DownloadProtectionService::DownloadInfo info;
372 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp")); 372 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
373 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe")); 373 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
374 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 374 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
375 info.referrer_url = GURL("http://www.google.com/"); 375 info.referrer_url = GURL("http://www.google.com/");
376 376
377 EXPECT_CALL(*sb_service_->mock_database_manager(), 377 EXPECT_CALL(*sb_service_->mock_database_manager(),
378 MatchDownloadWhitelistUrl(_)) 378 MatchDownloadWhitelistUrl(_))
379 .WillRepeatedly(Return(false)); 379 .WillRepeatedly(Return(false));
380 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); 380 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
381 381
382 download_service_->CheckClientDownload( 382 download_service_->CheckClientDownload(
383 info, 383 info,
384 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 384 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
385 base::Unretained(this))); 385 base::Unretained(this)));
386 msg_loop_.Run(); 386 msg_loop_.Run();
387 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 387 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
388 } 388 }
389 389
390 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { 390 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
391 ClientDownloadResponse response; 391 ClientDownloadResponse response;
392 response.set_verdict(ClientDownloadResponse::SAFE); 392 response.set_verdict(ClientDownloadResponse::SAFE);
393 net::FakeURLFetcherFactory factory; 393 net::FakeURLFetcherFactory factory(NULL);
394 // Empty response means SAFE. 394 // Empty response means SAFE.
395 factory.SetFakeResponse( 395 factory.SetFakeResponse(
396 DownloadProtectionService::GetDownloadRequestUrl(), 396 DownloadProtectionService::GetDownloadRequestUrl(),
397 response.SerializeAsString(), 397 response.SerializeAsString(),
398 true); 398 true);
399 399
400 DownloadProtectionService::DownloadInfo info; 400 DownloadProtectionService::DownloadInfo info;
401 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp")); 401 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
402 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe")); 402 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
403 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 403 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 #if defined(OS_WIN) 481 #if defined(OS_WIN)
482 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); 482 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST));
483 #else 483 #else
484 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 484 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
485 #endif 485 #endif
486 } 486 }
487 487
488 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { 488 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) {
489 ClientDownloadResponse response; 489 ClientDownloadResponse response;
490 response.set_verdict(ClientDownloadResponse::DANGEROUS); 490 response.set_verdict(ClientDownloadResponse::DANGEROUS);
491 net::FakeURLFetcherFactory factory; 491 net::FakeURLFetcherFactory factory(NULL);
492 factory.SetFakeResponse( 492 factory.SetFakeResponse(
493 DownloadProtectionService::GetDownloadRequestUrl(), 493 DownloadProtectionService::GetDownloadRequestUrl(),
494 response.SerializeAsString(), 494 response.SerializeAsString(),
495 true); 495 true);
496 496
497 DownloadProtectionService::DownloadInfo info; 497 DownloadProtectionService::DownloadInfo info;
498 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp")); 498 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
499 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe")); 499 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
500 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe")); 500 info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe"));
501 info.referrer_url = GURL("http://www.google.com/"); 501 info.referrer_url = GURL("http://www.google.com/");
(...skipping 11 matching lines...) Expand all
513 #if defined(OS_WIN) 513 #if defined(OS_WIN)
514 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 514 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
515 #else 515 #else
516 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 516 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
517 #endif 517 #endif
518 } 518 }
519 519
520 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { 520 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
521 ClientDownloadResponse response; 521 ClientDownloadResponse response;
522 response.set_verdict(ClientDownloadResponse::SAFE); 522 response.set_verdict(ClientDownloadResponse::SAFE);
523 net::FakeURLFetcherFactory factory; 523 net::FakeURLFetcherFactory factory(NULL);
524 // Empty response means SAFE. 524 // Empty response means SAFE.
525 factory.SetFakeResponse( 525 factory.SetFakeResponse(
526 DownloadProtectionService::GetDownloadRequestUrl(), 526 DownloadProtectionService::GetDownloadRequestUrl(),
527 response.SerializeAsString(), 527 response.SerializeAsString(),
528 true); 528 true);
529 529
530 base::ScopedTempDir download_dir; 530 base::ScopedTempDir download_dir;
531 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); 531 ASSERT_TRUE(download_dir.CreateUniqueTempDir());
532 532
533 DownloadProtectionService::DownloadInfo info; 533 DownloadProtectionService::DownloadInfo info;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 Mock::VerifyAndClearExpectations(sb_service_); 618 Mock::VerifyAndClearExpectations(sb_service_);
619 Mock::VerifyAndClearExpectations(signature_util_); 619 Mock::VerifyAndClearExpectations(signature_util_);
620 } 620 }
621 621
622 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { 622 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) {
623 ClientDownloadResponse response; 623 ClientDownloadResponse response;
624 // Even if the server verdict is dangerous we should return SAFE because 624 // Even if the server verdict is dangerous we should return SAFE because
625 // DownloadProtectionService::IsSupportedDownload() will return false 625 // DownloadProtectionService::IsSupportedDownload() will return false
626 // for crx downloads. 626 // for crx downloads.
627 response.set_verdict(ClientDownloadResponse::DANGEROUS); 627 response.set_verdict(ClientDownloadResponse::DANGEROUS);
628 net::FakeURLFetcherFactory factory; 628 net::FakeURLFetcherFactory factory(NULL);
629 // Empty response means SAFE. 629 // Empty response means SAFE.
630 factory.SetFakeResponse( 630 factory.SetFakeResponse(
631 DownloadProtectionService::GetDownloadRequestUrl(), 631 DownloadProtectionService::GetDownloadRequestUrl(),
632 response.SerializeAsString(), 632 response.SerializeAsString(),
633 true); 633 true);
634 634
635 DownloadProtectionService::DownloadInfo info; 635 DownloadProtectionService::DownloadInfo info;
636 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp")); 636 info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
637 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.crx")); 637 info.target_file = base::FilePath(FILE_PATH_LITERAL("a.crx"));
638 info.download_url_chain.push_back(GURL("http://www.evil.com/a.crx")); 638 info.download_url_chain.push_back(GURL("http://www.evil.com/a.crx"));
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 936 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
937 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 937 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
938 938
939 cert = ReadTestCertificate("test_c.pem"); 939 cert = ReadTestCertificate("test_c.pem");
940 ASSERT_TRUE(cert.get()); 940 ASSERT_TRUE(cert.get());
941 whitelist_strings.clear(); 941 whitelist_strings.clear();
942 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 942 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
943 EXPECT_THAT(whitelist_strings, ElementsAre()); 943 EXPECT_THAT(whitelist_strings, ElementsAre());
944 } 944 }
945 } // namespace safe_browsing 945 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/client_side_detection_service_unittest.cc ('k') | net/url_request/test_url_fetcher_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698