| OLD | NEW |
| 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 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 26 #include "chrome/browser/safe_browsing/signature_util.h" | 26 #include "chrome/browser/safe_browsing/signature_util.h" |
| 27 #include "chrome/common/safe_browsing/csd.pb.h" | 27 #include "chrome/common/safe_browsing/csd.pb.h" |
| 28 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/test/mock_download_item.h" | 29 #include "content/public/test/mock_download_item.h" |
| 30 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
| 31 #include "net/cert/x509_certificate.h" | 31 #include "net/cert/x509_certificate.h" |
| 32 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
| 33 #include "net/url_request/test_url_fetcher_factory.h" | 33 #include "net/url_request/test_url_fetcher_factory.h" |
| 34 #include "net/url_request/url_fetcher_delegate.h" | 34 #include "net/url_request/url_fetcher_delegate.h" |
| 35 #include "net/url_request/url_request_status.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "third_party/zlib/google/zip.h" | 38 #include "third_party/zlib/google/zip.h" |
| 38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 39 | 40 |
| 40 using ::testing::Assign; | 41 using ::testing::Assign; |
| 41 using ::testing::ContainerEq; | 42 using ::testing::ContainerEq; |
| 42 using ::testing::DoAll; | 43 using ::testing::DoAll; |
| 43 using ::testing::ElementsAre; | 44 using ::testing::ElementsAre; |
| 44 using ::testing::Mock; | 45 using ::testing::Mock; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 395 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 395 base::Unretained(this))); | 396 base::Unretained(this))); |
| 396 MessageLoop::current()->Run(); | 397 MessageLoop::current()->Run(); |
| 397 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 398 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 398 } | 399 } |
| 399 | 400 |
| 400 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 401 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
| 401 net::FakeURLFetcherFactory factory(NULL); | 402 net::FakeURLFetcherFactory factory(NULL); |
| 402 // HTTP request will fail. | 403 // HTTP request will fail. |
| 403 factory.SetFakeResponse( | 404 factory.SetFakeResponse( |
| 404 DownloadProtectionService::GetDownloadRequestUrl(), | 405 DownloadProtectionService::GetDownloadRequestUrl(), std::string(), |
| 405 std::string(), | 406 net::HTTP_INTERNAL_SERVER_ERROR, net::URLRequestStatus::FAILED); |
| 406 net::HTTP_INTERNAL_SERVER_ERROR); | |
| 407 | 407 |
| 408 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 408 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 409 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); | 409 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); |
| 410 std::vector<GURL> url_chain; | 410 std::vector<GURL> url_chain; |
| 411 url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 411 url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 412 GURL referrer("http://www.google.com/"); | 412 GURL referrer("http://www.google.com/"); |
| 413 std::string hash = "hash"; | 413 std::string hash = "hash"; |
| 414 | 414 |
| 415 content::MockDownloadItem item; | 415 content::MockDownloadItem item; |
| 416 EXPECT_CALL(item, AddObserver(_)); | 416 EXPECT_CALL(item, AddObserver(_)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 438 } | 438 } |
| 439 | 439 |
| 440 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { | 440 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { |
| 441 ClientDownloadResponse response; | 441 ClientDownloadResponse response; |
| 442 response.set_verdict(ClientDownloadResponse::SAFE); | 442 response.set_verdict(ClientDownloadResponse::SAFE); |
| 443 net::FakeURLFetcherFactory factory(NULL); | 443 net::FakeURLFetcherFactory factory(NULL); |
| 444 // Empty response means SAFE. | 444 // Empty response means SAFE. |
| 445 factory.SetFakeResponse( | 445 factory.SetFakeResponse( |
| 446 DownloadProtectionService::GetDownloadRequestUrl(), | 446 DownloadProtectionService::GetDownloadRequestUrl(), |
| 447 response.SerializeAsString(), | 447 response.SerializeAsString(), |
| 448 net::HTTP_OK); | 448 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 449 | 449 |
| 450 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 450 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 451 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); | 451 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); |
| 452 std::vector<GURL> url_chain; | 452 std::vector<GURL> url_chain; |
| 453 url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 453 url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 454 GURL referrer("http://www.google.com/"); | 454 GURL referrer("http://www.google.com/"); |
| 455 std::string hash = "hash"; | 455 std::string hash = "hash"; |
| 456 | 456 |
| 457 content::MockDownloadItem item; | 457 content::MockDownloadItem item; |
| 458 EXPECT_CALL(item, AddObserver(_)).Times(6); | 458 EXPECT_CALL(item, AddObserver(_)).Times(6); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 476 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 476 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 477 base::Unretained(this))); | 477 base::Unretained(this))); |
| 478 MessageLoop::current()->Run(); | 478 MessageLoop::current()->Run(); |
| 479 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 479 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 480 | 480 |
| 481 // Invalid response should be safe too. | 481 // Invalid response should be safe too. |
| 482 response.Clear(); | 482 response.Clear(); |
| 483 factory.SetFakeResponse( | 483 factory.SetFakeResponse( |
| 484 DownloadProtectionService::GetDownloadRequestUrl(), | 484 DownloadProtectionService::GetDownloadRequestUrl(), |
| 485 response.SerializePartialAsString(), | 485 response.SerializePartialAsString(), |
| 486 net::HTTP_OK); | 486 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 487 | 487 |
| 488 download_service_->CheckClientDownload( | 488 download_service_->CheckClientDownload( |
| 489 &item, | 489 &item, |
| 490 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 490 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 491 base::Unretained(this))); | 491 base::Unretained(this))); |
| 492 MessageLoop::current()->Run(); | 492 MessageLoop::current()->Run(); |
| 493 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 493 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 494 std::string feedback_ping; | 494 std::string feedback_ping; |
| 495 std::string feedback_response; | 495 std::string feedback_response; |
| 496 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 496 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 497 item, &feedback_ping, &feedback_response)); | 497 item, &feedback_ping, &feedback_response)); |
| 498 | 498 |
| 499 // If the response is dangerous the result should also be marked as dangerous. | 499 // If the response is dangerous the result should also be marked as dangerous. |
| 500 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 500 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 501 factory.SetFakeResponse( | 501 factory.SetFakeResponse( |
| 502 DownloadProtectionService::GetDownloadRequestUrl(), | 502 DownloadProtectionService::GetDownloadRequestUrl(), |
| 503 response.SerializeAsString(), | 503 response.SerializeAsString(), |
| 504 net::HTTP_OK); | 504 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 505 | 505 |
| 506 download_service_->CheckClientDownload( | 506 download_service_->CheckClientDownload( |
| 507 &item, | 507 &item, |
| 508 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 508 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 509 base::Unretained(this))); | 509 base::Unretained(this))); |
| 510 MessageLoop::current()->Run(); | 510 MessageLoop::current()->Run(); |
| 511 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 511 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 512 item, &feedback_ping, &feedback_response)); | 512 item, &feedback_ping, &feedback_response)); |
| 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 // If the response is uncommon the result should also be marked as uncommon. | 519 // If the response is uncommon the result should also be marked as uncommon. |
| 520 response.set_verdict(ClientDownloadResponse::UNCOMMON); | 520 response.set_verdict(ClientDownloadResponse::UNCOMMON); |
| 521 factory.SetFakeResponse( | 521 factory.SetFakeResponse( |
| 522 DownloadProtectionService::GetDownloadRequestUrl(), | 522 DownloadProtectionService::GetDownloadRequestUrl(), |
| 523 response.SerializeAsString(), | 523 response.SerializeAsString(), |
| 524 net::HTTP_OK); | 524 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 525 | 525 |
| 526 download_service_->CheckClientDownload( | 526 download_service_->CheckClientDownload( |
| 527 &item, | 527 &item, |
| 528 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 528 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 529 base::Unretained(this))); | 529 base::Unretained(this))); |
| 530 MessageLoop::current()->Run(); | 530 MessageLoop::current()->Run(); |
| 531 #if defined(OS_WIN) | 531 #if defined(OS_WIN) |
| 532 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); | 532 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); |
| 533 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 533 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 534 item, &feedback_ping, &feedback_response)); | 534 item, &feedback_ping, &feedback_response)); |
| 535 ClientDownloadRequest decoded_request; | 535 ClientDownloadRequest decoded_request; |
| 536 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); | 536 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); |
| 537 EXPECT_EQ(url_chain.back().spec(), decoded_request.url()); | 537 EXPECT_EQ(url_chain.back().spec(), decoded_request.url()); |
| 538 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 538 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
| 539 #else | 539 #else |
| 540 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 540 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 541 #endif | 541 #endif |
| 542 | 542 |
| 543 // If the response is dangerous_host the result should also be marked as | 543 // If the response is dangerous_host the result should also be marked as |
| 544 // dangerous_host. | 544 // dangerous_host. |
| 545 response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); | 545 response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
| 546 factory.SetFakeResponse( | 546 factory.SetFakeResponse( |
| 547 DownloadProtectionService::GetDownloadRequestUrl(), | 547 DownloadProtectionService::GetDownloadRequestUrl(), |
| 548 response.SerializeAsString(), | 548 response.SerializeAsString(), |
| 549 net::HTTP_OK); | 549 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 550 | 550 |
| 551 download_service_->CheckClientDownload( | 551 download_service_->CheckClientDownload( |
| 552 &item, | 552 &item, |
| 553 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 553 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 554 base::Unretained(this))); | 554 base::Unretained(this))); |
| 555 MessageLoop::current()->Run(); | 555 MessageLoop::current()->Run(); |
| 556 #if defined(OS_WIN) | 556 #if defined(OS_WIN) |
| 557 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); | 557 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); |
| 558 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 558 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 559 item, &feedback_ping, &feedback_response)); | 559 item, &feedback_ping, &feedback_response)); |
| 560 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 560 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
| 561 #else | 561 #else |
| 562 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 562 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 563 #endif | 563 #endif |
| 564 | 564 |
| 565 // If the response is POTENTIALLY_UNWANTED the result should also be marked as | 565 // If the response is POTENTIALLY_UNWANTED the result should also be marked as |
| 566 // POTENTIALLY_UNWANTED. | 566 // POTENTIALLY_UNWANTED. |
| 567 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); | 567 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
| 568 factory.SetFakeResponse( | 568 factory.SetFakeResponse( |
| 569 DownloadProtectionService::GetDownloadRequestUrl(), | 569 DownloadProtectionService::GetDownloadRequestUrl(), |
| 570 response.SerializeAsString(), | 570 response.SerializeAsString(), |
| 571 net::HTTP_OK); | 571 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 572 | 572 |
| 573 download_service_->CheckClientDownload( | 573 download_service_->CheckClientDownload( |
| 574 &item, | 574 &item, |
| 575 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 575 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 576 base::Unretained(this))); | 576 base::Unretained(this))); |
| 577 MessageLoop::current()->Run(); | 577 MessageLoop::current()->Run(); |
| 578 #if defined(OS_WIN) | 578 #if defined(OS_WIN) |
| 579 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); | 579 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); |
| 580 #else | 580 #else |
| 581 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 581 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 582 #endif | 582 #endif |
| 583 } | 583 } |
| 584 | 584 |
| 585 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 585 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
| 586 ClientDownloadResponse response; | 586 ClientDownloadResponse response; |
| 587 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 587 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 588 net::FakeURLFetcherFactory factory(NULL); | 588 net::FakeURLFetcherFactory factory(NULL); |
| 589 factory.SetFakeResponse( | 589 factory.SetFakeResponse( |
| 590 DownloadProtectionService::GetDownloadRequestUrl(), | 590 DownloadProtectionService::GetDownloadRequestUrl(), |
| 591 response.SerializeAsString(), | 591 response.SerializeAsString(), |
| 592 net::HTTP_OK); | 592 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 593 | 593 |
| 594 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 594 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 595 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); | 595 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); |
| 596 std::vector<GURL> url_chain; | 596 std::vector<GURL> url_chain; |
| 597 url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 597 url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 598 GURL referrer("http://www.google.com/"); | 598 GURL referrer("http://www.google.com/"); |
| 599 std::string hash = "hash"; | 599 std::string hash = "hash"; |
| 600 | 600 |
| 601 content::MockDownloadItem item; | 601 content::MockDownloadItem item; |
| 602 EXPECT_CALL(item, AddObserver(_)).Times(1); | 602 EXPECT_CALL(item, AddObserver(_)).Times(1); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 628 } | 628 } |
| 629 | 629 |
| 630 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { | 630 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { |
| 631 ClientDownloadResponse response; | 631 ClientDownloadResponse response; |
| 632 response.set_verdict(ClientDownloadResponse::SAFE); | 632 response.set_verdict(ClientDownloadResponse::SAFE); |
| 633 net::FakeURLFetcherFactory factory(NULL); | 633 net::FakeURLFetcherFactory factory(NULL); |
| 634 // Empty response means SAFE. | 634 // Empty response means SAFE. |
| 635 factory.SetFakeResponse( | 635 factory.SetFakeResponse( |
| 636 DownloadProtectionService::GetDownloadRequestUrl(), | 636 DownloadProtectionService::GetDownloadRequestUrl(), |
| 637 response.SerializeAsString(), | 637 response.SerializeAsString(), |
| 638 net::HTTP_OK); | 638 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 639 | 639 |
| 640 base::ScopedTempDir download_dir; | 640 base::ScopedTempDir download_dir; |
| 641 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 641 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
| 642 | 642 |
| 643 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); | 643 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); |
| 644 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); | 644 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); |
| 645 std::vector<GURL> url_chain; | 645 std::vector<GURL> url_chain; |
| 646 url_chain.push_back(GURL("http://www.evil.com/a.zip")); | 646 url_chain.push_back(GURL("http://www.evil.com/a.zip")); |
| 647 GURL referrer("http://www.google.com/"); | 647 GURL referrer("http://www.google.com/"); |
| 648 std::string hash = "hash"; | 648 std::string hash = "hash"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 MessageLoop::current()->Run(); | 695 MessageLoop::current()->Run(); |
| 696 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 696 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 697 Mock::VerifyAndClearExpectations(signature_util_.get()); | 697 Mock::VerifyAndClearExpectations(signature_util_.get()); |
| 698 | 698 |
| 699 // If the response is dangerous the result should also be marked as | 699 // If the response is dangerous the result should also be marked as |
| 700 // dangerous. | 700 // dangerous. |
| 701 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 701 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 702 factory.SetFakeResponse( | 702 factory.SetFakeResponse( |
| 703 DownloadProtectionService::GetDownloadRequestUrl(), | 703 DownloadProtectionService::GetDownloadRequestUrl(), |
| 704 response.SerializeAsString(), | 704 response.SerializeAsString(), |
| 705 net::HTTP_OK); | 705 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 706 | 706 |
| 707 download_service_->CheckClientDownload( | 707 download_service_->CheckClientDownload( |
| 708 &item, | 708 &item, |
| 709 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 709 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 710 base::Unretained(this))); | 710 base::Unretained(this))); |
| 711 MessageLoop::current()->Run(); | 711 MessageLoop::current()->Run(); |
| 712 #if defined(OS_WIN) | 712 #if defined(OS_WIN) |
| 713 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 713 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 714 #else | 714 #else |
| 715 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 715 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 ClientDownloadResponse response; | 758 ClientDownloadResponse response; |
| 759 // Even if the server verdict is dangerous we should return SAFE because | 759 // Even if the server verdict is dangerous we should return SAFE because |
| 760 // DownloadProtectionService::IsSupportedDownload() will return false | 760 // DownloadProtectionService::IsSupportedDownload() will return false |
| 761 // for crx downloads. | 761 // for crx downloads. |
| 762 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 762 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 763 net::FakeURLFetcherFactory factory(NULL); | 763 net::FakeURLFetcherFactory factory(NULL); |
| 764 // Empty response means SAFE. | 764 // Empty response means SAFE. |
| 765 factory.SetFakeResponse( | 765 factory.SetFakeResponse( |
| 766 DownloadProtectionService::GetDownloadRequestUrl(), | 766 DownloadProtectionService::GetDownloadRequestUrl(), |
| 767 response.SerializeAsString(), | 767 response.SerializeAsString(), |
| 768 net::HTTP_OK); | 768 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 769 | 769 |
| 770 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 770 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 771 base::FilePath a_crx(FILE_PATH_LITERAL("a.crx")); | 771 base::FilePath a_crx(FILE_PATH_LITERAL("a.crx")); |
| 772 std::vector<GURL> url_chain; | 772 std::vector<GURL> url_chain; |
| 773 url_chain.push_back(GURL("http://www.evil.com/a.crx")); | 773 url_chain.push_back(GURL("http://www.evil.com/a.crx")); |
| 774 GURL referrer("http://www.google.com/"); | 774 GURL referrer("http://www.google.com/"); |
| 775 std::string hash = "hash"; | 775 std::string hash = "hash"; |
| 776 | 776 |
| 777 content::MockDownloadItem item; | 777 content::MockDownloadItem item; |
| 778 EXPECT_CALL(item, AddObserver(_)).Times(1); | 778 EXPECT_CALL(item, AddObserver(_)).Times(1); |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 1170 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
| 1171 | 1171 |
| 1172 cert = ReadTestCertificate("test_c.pem"); | 1172 cert = ReadTestCertificate("test_c.pem"); |
| 1173 ASSERT_TRUE(cert.get()); | 1173 ASSERT_TRUE(cert.get()); |
| 1174 whitelist_strings.clear(); | 1174 whitelist_strings.clear(); |
| 1175 GetCertificateWhitelistStrings( | 1175 GetCertificateWhitelistStrings( |
| 1176 *cert.get(), *issuer_cert.get(), &whitelist_strings); | 1176 *cert.get(), *issuer_cert.get(), &whitelist_strings); |
| 1177 EXPECT_THAT(whitelist_strings, ElementsAre()); | 1177 EXPECT_THAT(whitelist_strings, ElementsAre()); |
| 1178 } | 1178 } |
| 1179 } // namespace safe_browsing | 1179 } // namespace safe_browsing |
| OLD | NEW |