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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 503 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
504 #endif | 504 #endif |
505 | 505 |
506 // Only if the final url is whitelisted should it be SAFE. | 506 // Only if the final url is whitelisted should it be SAFE. |
507 url_chain.push_back(GURL("http://www.google.com/a.exe")); | 507 url_chain.push_back(GURL("http://www.google.com/a.exe")); |
508 download_service_->CheckClientDownload( | 508 download_service_->CheckClientDownload( |
509 &item, | 509 &item, |
510 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 510 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
511 base::Unretained(this))); | 511 base::Unretained(this))); |
512 MessageLoop::current()->Run(); | 512 MessageLoop::current()->Run(); |
| 513 #if defined(OS_MACOSX) |
| 514 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 515 #else |
513 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 516 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 517 #endif |
514 } | 518 } |
515 | 519 |
516 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 520 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
517 net::FakeURLFetcherFactory factory(NULL); | 521 net::FakeURLFetcherFactory factory(NULL); |
518 // HTTP request will fail. | 522 // HTTP request will fail. |
519 factory.SetFakeResponse( | 523 factory.SetFakeResponse( |
520 DownloadProtectionService::GetDownloadRequestUrl(), std::string(), | 524 DownloadProtectionService::GetDownloadRequestUrl(), std::string(), |
521 net::HTTP_INTERNAL_SERVER_ERROR, net::URLRequestStatus::FAILED); | 525 net::HTTP_INTERNAL_SERVER_ERROR, net::URLRequestStatus::FAILED); |
522 | 526 |
523 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 527 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)) | 978 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)) |
975 .WillOnce(SetCertificateContents("dummy cert data")); | 979 .WillOnce(SetCertificateContents("dummy cert data")); |
976 EXPECT_CALL(*binary_feature_extractor_.get(), | 980 EXPECT_CALL(*binary_feature_extractor_.get(), |
977 ExtractImageHeaders(tmp_path, _)) | 981 ExtractImageHeaders(tmp_path, _)) |
978 .WillOnce(SetDosHeaderContents("dummy dos header")); | 982 .WillOnce(SetDosHeaderContents("dummy dos header")); |
979 download_service_->CheckClientDownload( | 983 download_service_->CheckClientDownload( |
980 &item, | 984 &item, |
981 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 985 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
982 base::Unretained(this))); | 986 base::Unretained(this))); |
983 | 987 |
984 #if !defined(OS_WIN) | 988 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
985 // SendRequest is not called. Wait for FinishRequest to call our callback. | 989 // SendRequest is not called. Wait for FinishRequest to call our callback. |
986 MessageLoop::current()->Run(); | 990 MessageLoop::current()->Run(); |
987 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 991 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
988 EXPECT_EQ(NULL, fetcher); | 992 EXPECT_EQ(NULL, fetcher); |
989 #else | 993 #else |
990 // Run the message loop(s) until SendRequest is called. | 994 // Run the message loop(s) until SendRequest is called. |
991 FlushThreadMessageLoops(); | 995 FlushThreadMessageLoops(); |
992 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 996 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
993 ASSERT_TRUE(fetcher); | 997 ASSERT_TRUE(fetcher); |
994 ClientDownloadRequest request; | 998 ClientDownloadRequest request; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 MatchDownloadWhitelistUrl(_)) | 1063 MatchDownloadWhitelistUrl(_)) |
1060 .WillRepeatedly(Return(false)); | 1064 .WillRepeatedly(Return(false)); |
1061 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)); | 1065 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)); |
1062 EXPECT_CALL(*binary_feature_extractor_.get(), | 1066 EXPECT_CALL(*binary_feature_extractor_.get(), |
1063 ExtractImageHeaders(tmp_path, _)); | 1067 ExtractImageHeaders(tmp_path, _)); |
1064 download_service_->CheckClientDownload( | 1068 download_service_->CheckClientDownload( |
1065 &item, | 1069 &item, |
1066 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1070 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1067 base::Unretained(this))); | 1071 base::Unretained(this))); |
1068 | 1072 |
1069 #if !defined(OS_WIN) | 1073 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
1070 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1074 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1071 MessageLoop::current()->Run(); | 1075 MessageLoop::current()->Run(); |
1072 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1076 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1073 EXPECT_EQ(NULL, fetcher); | 1077 EXPECT_EQ(NULL, fetcher); |
1074 #else | 1078 #else |
1075 // Run the message loop(s) until SendRequest is called. | 1079 // Run the message loop(s) until SendRequest is called. |
1076 FlushThreadMessageLoops(); | 1080 FlushThreadMessageLoops(); |
1077 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1081 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1078 ASSERT_TRUE(fetcher); | 1082 ASSERT_TRUE(fetcher); |
1079 ClientDownloadRequest request; | 1083 ClientDownloadRequest request; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 .WillRepeatedly(SetDosHeaderContents("dummy dos header")); | 1151 .WillRepeatedly(SetDosHeaderContents("dummy dos header")); |
1148 | 1152 |
1149 // First test with no history match for the tab URL. | 1153 // First test with no history match for the tab URL. |
1150 { | 1154 { |
1151 TestURLFetcherWatcher fetcher_watcher(&factory); | 1155 TestURLFetcherWatcher fetcher_watcher(&factory); |
1152 download_service_->CheckClientDownload( | 1156 download_service_->CheckClientDownload( |
1153 &item, | 1157 &item, |
1154 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1158 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1155 base::Unretained(this))); | 1159 base::Unretained(this))); |
1156 | 1160 |
1157 #if !defined(OS_WIN) | 1161 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
1158 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1162 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1159 MessageLoop::current()->Run(); | 1163 MessageLoop::current()->Run(); |
1160 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1164 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1161 EXPECT_EQ(NULL, fetcher); | 1165 EXPECT_EQ(NULL, fetcher); |
1162 #else | 1166 #else |
1163 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); | 1167 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); |
1164 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1168 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1165 ASSERT_TRUE(fetcher); | 1169 ASSERT_TRUE(fetcher); |
1166 ClientDownloadRequest request; | 1170 ClientDownloadRequest request; |
1167 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1171 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 redirects, | 1226 redirects, |
1223 content::PAGE_TRANSITION_TYPED, | 1227 content::PAGE_TRANSITION_TYPED, |
1224 history::SOURCE_BROWSED, | 1228 history::SOURCE_BROWSED, |
1225 false); | 1229 false); |
1226 | 1230 |
1227 TestURLFetcherWatcher fetcher_watcher(&factory); | 1231 TestURLFetcherWatcher fetcher_watcher(&factory); |
1228 download_service_->CheckClientDownload( | 1232 download_service_->CheckClientDownload( |
1229 &item, | 1233 &item, |
1230 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1234 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1231 base::Unretained(this))); | 1235 base::Unretained(this))); |
1232 #if !defined(OS_WIN) | 1236 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
1233 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1237 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1234 MessageLoop::current()->Run(); | 1238 MessageLoop::current()->Run(); |
1235 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1239 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1236 EXPECT_EQ(NULL, fetcher); | 1240 EXPECT_EQ(NULL, fetcher); |
1237 #else | 1241 #else |
1238 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); | 1242 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); |
1239 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1243 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1240 ASSERT_TRUE(fetcher); | 1244 ASSERT_TRUE(fetcher); |
1241 ClientDownloadRequest request; | 1245 ClientDownloadRequest request; |
1242 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1246 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 1518 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
1515 | 1519 |
1516 cert = ReadTestCertificate("test_c.pem"); | 1520 cert = ReadTestCertificate("test_c.pem"); |
1517 ASSERT_TRUE(cert.get()); | 1521 ASSERT_TRUE(cert.get()); |
1518 whitelist_strings.clear(); | 1522 whitelist_strings.clear(); |
1519 GetCertificateWhitelistStrings( | 1523 GetCertificateWhitelistStrings( |
1520 *cert.get(), *issuer_cert.get(), &whitelist_strings); | 1524 *cert.get(), *issuer_cert.get(), &whitelist_strings); |
1521 EXPECT_THAT(whitelist_strings, ElementsAre()); | 1525 EXPECT_THAT(whitelist_strings, ElementsAre()); |
1522 } | 1526 } |
1523 } // namespace safe_browsing | 1527 } // namespace safe_browsing |
OLD | NEW |