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

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

Issue 9639003: Handle uncommon download verdict for safebrowsing download protection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 9 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"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 true); 379 true);
380 380
381 DownloadProtectionService::DownloadInfo info; 381 DownloadProtectionService::DownloadInfo info;
382 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); 382 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp"));
383 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); 383 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe"));
384 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe")); 384 info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
385 info.referrer_url = GURL("http://www.google.com/"); 385 info.referrer_url = GURL("http://www.google.com/");
386 386
387 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) 387 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
388 .WillRepeatedly(Return(false)); 388 .WillRepeatedly(Return(false));
389 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(3); 389 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(4);
390 390
391 download_service_->CheckClientDownload( 391 download_service_->CheckClientDownload(
392 info, 392 info,
393 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 393 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
394 base::Unretained(this))); 394 base::Unretained(this)));
395 msg_loop_.Run(); 395 msg_loop_.Run();
396 ExpectResult(DownloadProtectionService::SAFE); 396 ExpectResult(DownloadProtectionService::SAFE);
397 397
398 // Invalid response should be safe too. 398 // Invalid response should be safe too.
399 response.Clear(); 399 response.Clear();
(...skipping 19 matching lines...) Expand all
419 download_service_->CheckClientDownload( 419 download_service_->CheckClientDownload(
420 info, 420 info,
421 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 421 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
422 base::Unretained(this))); 422 base::Unretained(this)));
423 msg_loop_.Run(); 423 msg_loop_.Run();
424 #if defined(OS_WIN) 424 #if defined(OS_WIN)
425 ExpectResult(DownloadProtectionService::DANGEROUS); 425 ExpectResult(DownloadProtectionService::DANGEROUS);
426 #else 426 #else
427 ExpectResult(DownloadProtectionService::SAFE); 427 ExpectResult(DownloadProtectionService::SAFE);
428 #endif 428 #endif
429
430 // If the response is uncommon the result should also be marked as uncommon.
431 response.set_verdict(ClientDownloadResponse::UNCOMMON);
432 factory.SetFakeResponse(
433 DownloadProtectionService::kDownloadRequestUrl,
434 response.SerializeAsString(),
435 true);
436
437 download_service_->CheckClientDownload(
438 info,
439 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
440 base::Unretained(this)));
441 msg_loop_.Run();
442 #if defined(OS_WIN)
443 ExpectResult(DownloadProtectionService::UNCOMMON);
444 #else
445 ExpectResult(DownloadProtectionService::SAFE);
446 #endif
429 } 447 }
430 448
431 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { 449 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
432 TestURLFetcherFactory factory; 450 TestURLFetcherFactory factory;
433 451
434 DownloadProtectionService::DownloadInfo info; 452 DownloadProtectionService::DownloadInfo info;
435 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); 453 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp"));
436 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); 454 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe"));
437 info.download_url_chain.push_back(GURL("http://www.google.com/")); 455 info.download_url_chain.push_back(GURL("http://www.google.com/"));
438 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); 456 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 873 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
856 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 874 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
857 875
858 cert = ReadTestCertificate("test_c.pem"); 876 cert = ReadTestCertificate("test_c.pem");
859 ASSERT_TRUE(cert.get()); 877 ASSERT_TRUE(cert.get());
860 whitelist_strings.clear(); 878 whitelist_strings.clear();
861 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 879 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
862 EXPECT_THAT(whitelist_strings, ElementsAre()); 880 EXPECT_THAT(whitelist_strings, ElementsAre());
863 } 881 }
864 } // namespace safe_browsing 882 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | chrome/common/safe_browsing/csd.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698