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

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

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