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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 net::X509Certificate::CreateCertificateListFromBytes( 239 net::X509Certificate::CreateCertificateListFromBytes(
240 cert_data.data(), 240 cert_data.data(),
241 cert_data.size(), 241 cert_data.size(),
242 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 242 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
243 return certs.empty() ? NULL : certs[0]; 243 return certs.empty() ? NULL : certs[0];
244 } 244 }
245 245
246 private: 246 private:
247 // Helper functions for FlushThreadMessageLoops. 247 // Helper functions for FlushThreadMessageLoops.
248 void RunAllPendingAndQuitUI() { 248 void RunAllPendingAndQuitUI() {
249 MessageLoop::current()->RunUntilIdle(); 249 base::MessageLoop::current()->RunUntilIdle();
250 BrowserThread::PostTask( 250 BrowserThread::PostTask(
251 BrowserThread::UI, 251 BrowserThread::UI,
252 FROM_HERE, 252 FROM_HERE,
253 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop, 253 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop,
254 base::Unretained(this))); 254 base::Unretained(this)));
255 } 255 }
256 256
257 void QuitMessageLoop() { 257 void QuitMessageLoop() {
258 MessageLoop::current()->Quit(); 258 base::MessageLoop::current()->Quit();
259 } 259 }
260 260
261 void PostRunMessageLoopTask(BrowserThread::ID thread) { 261 void PostRunMessageLoopTask(BrowserThread::ID thread) {
262 BrowserThread::PostTask( 262 BrowserThread::PostTask(
263 thread, 263 thread,
264 FROM_HERE, 264 FROM_HERE,
265 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI, 265 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI,
266 base::Unretained(this))); 266 base::Unretained(this)));
267 } 267 }
268 268
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 return result_ == expected ? 301 return result_ == expected ?
302 testing::AssertionSuccess() : 302 testing::AssertionSuccess() :
303 testing::AssertionFailure() << "Expected " << expected << 303 testing::AssertionFailure() << "Expected " << expected <<
304 ", got " << result_; 304 ", got " << result_;
305 } 305 }
306 306
307 protected: 307 protected:
308 scoped_refptr<FakeSafeBrowsingService> sb_service_; 308 scoped_refptr<FakeSafeBrowsingService> sb_service_;
309 scoped_refptr<MockSignatureUtil> signature_util_; 309 scoped_refptr<MockSignatureUtil> signature_util_;
310 DownloadProtectionService* download_service_; 310 DownloadProtectionService* download_service_;
311 MessageLoop msg_loop_; 311 base::MessageLoop msg_loop_;
312 DownloadProtectionService::DownloadCheckResult result_; 312 DownloadProtectionService::DownloadCheckResult result_;
313 bool has_result_; 313 bool has_result_;
314 scoped_ptr<content::TestBrowserThread> io_thread_; 314 scoped_ptr<content::TestBrowserThread> io_thread_;
315 scoped_ptr<content::TestBrowserThread> ui_thread_; 315 scoped_ptr<content::TestBrowserThread> ui_thread_;
316 base::FilePath testdata_path_; 316 base::FilePath testdata_path_;
317 }; 317 };
318 318
319 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { 319 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) {
320 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); 320 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
321 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); 321 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 "http://www.google.com/bla.exe", 820 "http://www.google.com/bla.exe",
821 referrer.spec())); 821 referrer.spec()));
822 EXPECT_TRUE(request.has_signature()); 822 EXPECT_TRUE(request.has_signature());
823 ASSERT_EQ(1, request.signature().certificate_chain_size()); 823 ASSERT_EQ(1, request.signature().certificate_chain_size());
824 const ClientDownloadRequest_CertificateChain& chain = 824 const ClientDownloadRequest_CertificateChain& chain =
825 request.signature().certificate_chain(0); 825 request.signature().certificate_chain(0);
826 ASSERT_EQ(1, chain.element_size()); 826 ASSERT_EQ(1, chain.element_size());
827 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); 827 EXPECT_EQ("dummy cert data", chain.element(0).certificate());
828 828
829 // Simulate the request finishing. 829 // Simulate the request finishing.
830 MessageLoop::current()->PostTask( 830 base::MessageLoop::current()->PostTask(
831 FROM_HERE, 831 FROM_HERE,
832 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 832 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
833 base::Unretained(this), fetcher)); 833 base::Unretained(this), fetcher));
834 msg_loop_.Run(); 834 msg_loop_.Run();
835 #endif 835 #endif
836 } 836 }
837 837
838 // Similar to above, but with an unsigned binary. 838 // Similar to above, but with an unsigned binary.
839 TEST_F(DownloadProtectionServiceTest, 839 TEST_F(DownloadProtectionServiceTest,
840 CheckClientDownloadValidateRequestNoSignature) { 840 CheckClientDownloadValidateRequestNoSignature) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 ClientDownloadRequest::DOWNLOAD_REDIRECT, 891 ClientDownloadRequest::DOWNLOAD_REDIRECT,
892 "http://www.google.com/", "")); 892 "http://www.google.com/", ""));
893 EXPECT_TRUE(RequestContainsResource(request, 893 EXPECT_TRUE(RequestContainsResource(request,
894 ClientDownloadRequest::DOWNLOAD_URL, 894 ClientDownloadRequest::DOWNLOAD_URL,
895 "ftp://www.google.com/bla.exe", 895 "ftp://www.google.com/bla.exe",
896 referrer.spec())); 896 referrer.spec()));
897 EXPECT_TRUE(request.has_signature()); 897 EXPECT_TRUE(request.has_signature());
898 EXPECT_EQ(0, request.signature().certificate_chain_size()); 898 EXPECT_EQ(0, request.signature().certificate_chain_size());
899 899
900 // Simulate the request finishing. 900 // Simulate the request finishing.
901 MessageLoop::current()->PostTask( 901 base::MessageLoop::current()->PostTask(
902 FROM_HERE, 902 FROM_HERE,
903 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 903 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
904 base::Unretained(this), fetcher)); 904 base::Unretained(this), fetcher));
905 msg_loop_.Run(); 905 msg_loop_.Run();
906 #endif 906 #endif
907 } 907 }
908 908
909 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { 909 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
910 std::vector<GURL> url_chain; 910 std::vector<GURL> url_chain;
911 url_chain.push_back(GURL("http://www.google.com/")); 911 url_chain.push_back(GURL("http://www.google.com/"));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1122 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
1123 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1123 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1124 1124
1125 cert = ReadTestCertificate("test_c.pem"); 1125 cert = ReadTestCertificate("test_c.pem");
1126 ASSERT_TRUE(cert.get()); 1126 ASSERT_TRUE(cert.get());
1127 whitelist_strings.clear(); 1127 whitelist_strings.clear();
1128 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1128 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
1129 EXPECT_THAT(whitelist_strings, ElementsAre()); 1129 EXPECT_THAT(whitelist_strings, ElementsAre());
1130 } 1130 }
1131 } // namespace safe_browsing 1131 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/database_manager.cc ('k') | chrome/browser/safe_browsing/malware_details_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698