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

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: Created 7 years, 7 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 net::X509Certificate::CreateCertificateListFromBytes( 238 net::X509Certificate::CreateCertificateListFromBytes(
239 cert_data.data(), 239 cert_data.data(),
240 cert_data.size(), 240 cert_data.size(),
241 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); 241 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE);
242 return certs.empty() ? NULL : certs[0]; 242 return certs.empty() ? NULL : certs[0];
243 } 243 }
244 244
245 private: 245 private:
246 // Helper functions for FlushThreadMessageLoops. 246 // Helper functions for FlushThreadMessageLoops.
247 void RunAllPendingAndQuitUI() { 247 void RunAllPendingAndQuitUI() {
248 MessageLoop::current()->RunUntilIdle(); 248 base::MessageLoop::current()->RunUntilIdle();
249 BrowserThread::PostTask( 249 BrowserThread::PostTask(
250 BrowserThread::UI, 250 BrowserThread::UI,
251 FROM_HERE, 251 FROM_HERE,
252 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop, 252 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop,
253 base::Unretained(this))); 253 base::Unretained(this)));
254 } 254 }
255 255
256 void QuitMessageLoop() { 256 void QuitMessageLoop() {
257 MessageLoop::current()->Quit(); 257 base::MessageLoop::current()->Quit();
258 } 258 }
259 259
260 void PostRunMessageLoopTask(BrowserThread::ID thread) { 260 void PostRunMessageLoopTask(BrowserThread::ID thread) {
261 BrowserThread::PostTask( 261 BrowserThread::PostTask(
262 thread, 262 thread,
263 FROM_HERE, 263 FROM_HERE,
264 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI, 264 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI,
265 base::Unretained(this))); 265 base::Unretained(this)));
266 } 266 }
267 267
(...skipping 26 matching lines...) Expand all
294 return result_ == expected ? 294 return result_ == expected ?
295 testing::AssertionSuccess() : 295 testing::AssertionSuccess() :
296 testing::AssertionFailure() << "Expected " << expected << 296 testing::AssertionFailure() << "Expected " << expected <<
297 ", got " << result_; 297 ", got " << result_;
298 } 298 }
299 299
300 protected: 300 protected:
301 scoped_refptr<FakeSafeBrowsingService> sb_service_; 301 scoped_refptr<FakeSafeBrowsingService> sb_service_;
302 scoped_refptr<MockSignatureUtil> signature_util_; 302 scoped_refptr<MockSignatureUtil> signature_util_;
303 DownloadProtectionService* download_service_; 303 DownloadProtectionService* download_service_;
304 MessageLoop msg_loop_; 304 base::MessageLoop msg_loop_;
305 DownloadProtectionService::DownloadCheckResult result_; 305 DownloadProtectionService::DownloadCheckResult result_;
306 bool has_result_; 306 bool has_result_;
307 scoped_ptr<content::TestBrowserThread> io_thread_; 307 scoped_ptr<content::TestBrowserThread> io_thread_;
308 scoped_ptr<content::TestBrowserThread> ui_thread_; 308 scoped_ptr<content::TestBrowserThread> ui_thread_;
309 base::FilePath testdata_path_; 309 base::FilePath testdata_path_;
310 }; 310 };
311 311
312 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { 312 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) {
313 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); 313 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
314 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); 314 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 "http://www.google.com/bla.exe", 813 "http://www.google.com/bla.exe",
814 referrer.spec())); 814 referrer.spec()));
815 EXPECT_TRUE(request.has_signature()); 815 EXPECT_TRUE(request.has_signature());
816 ASSERT_EQ(1, request.signature().certificate_chain_size()); 816 ASSERT_EQ(1, request.signature().certificate_chain_size());
817 const ClientDownloadRequest_CertificateChain& chain = 817 const ClientDownloadRequest_CertificateChain& chain =
818 request.signature().certificate_chain(0); 818 request.signature().certificate_chain(0);
819 ASSERT_EQ(1, chain.element_size()); 819 ASSERT_EQ(1, chain.element_size());
820 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); 820 EXPECT_EQ("dummy cert data", chain.element(0).certificate());
821 821
822 // Simulate the request finishing. 822 // Simulate the request finishing.
823 MessageLoop::current()->PostTask( 823 base::MessageLoop::current()->PostTask(
824 FROM_HERE, 824 FROM_HERE,
825 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 825 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
826 base::Unretained(this), fetcher)); 826 base::Unretained(this),
827 fetcher));
827 msg_loop_.Run(); 828 msg_loop_.Run();
828 #endif 829 #endif
829 } 830 }
830 831
831 // Similar to above, but with an unsigned binary. 832 // Similar to above, but with an unsigned binary.
832 TEST_F(DownloadProtectionServiceTest, 833 TEST_F(DownloadProtectionServiceTest,
833 CheckClientDownloadValidateRequestNoSignature) { 834 CheckClientDownloadValidateRequestNoSignature) {
834 net::TestURLFetcherFactory factory; 835 net::TestURLFetcherFactory factory;
835 836
836 base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp")); 837 base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp"));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 ClientDownloadRequest::DOWNLOAD_REDIRECT, 885 ClientDownloadRequest::DOWNLOAD_REDIRECT,
885 "http://www.google.com/", "")); 886 "http://www.google.com/", ""));
886 EXPECT_TRUE(RequestContainsResource(request, 887 EXPECT_TRUE(RequestContainsResource(request,
887 ClientDownloadRequest::DOWNLOAD_URL, 888 ClientDownloadRequest::DOWNLOAD_URL,
888 "ftp://www.google.com/bla.exe", 889 "ftp://www.google.com/bla.exe",
889 referrer.spec())); 890 referrer.spec()));
890 EXPECT_TRUE(request.has_signature()); 891 EXPECT_TRUE(request.has_signature());
891 EXPECT_EQ(0, request.signature().certificate_chain_size()); 892 EXPECT_EQ(0, request.signature().certificate_chain_size());
892 893
893 // Simulate the request finishing. 894 // Simulate the request finishing.
894 MessageLoop::current()->PostTask( 895 base::MessageLoop::current()->PostTask(
895 FROM_HERE, 896 FROM_HERE,
896 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 897 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
897 base::Unretained(this), fetcher)); 898 base::Unretained(this),
899 fetcher));
898 msg_loop_.Run(); 900 msg_loop_.Run();
899 #endif 901 #endif
900 } 902 }
901 903
902 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { 904 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
903 std::vector<GURL> url_chain; 905 std::vector<GURL> url_chain;
904 url_chain.push_back(GURL("http://www.google.com/")); 906 url_chain.push_back(GURL("http://www.google.com/"));
905 url_chain.push_back(GURL("http://www.google.com/bla.exe")); 907 url_chain.push_back(GURL("http://www.google.com/bla.exe"));
906 GURL referrer("http://www.google.com/"); 908 GURL referrer("http://www.google.com/");
907 std::string hash = "hash"; 909 std::string hash = "hash";
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1076 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
1075 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1077 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1076 1078
1077 cert = ReadTestCertificate("test_c.pem"); 1079 cert = ReadTestCertificate("test_c.pem");
1078 ASSERT_TRUE(cert.get()); 1080 ASSERT_TRUE(cert.get());
1079 whitelist_strings.clear(); 1081 whitelist_strings.clear();
1080 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1082 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings);
1081 EXPECT_THAT(whitelist_strings, ElementsAre()); 1083 EXPECT_THAT(whitelist_strings, ElementsAre());
1082 } 1084 }
1083 } // namespace safe_browsing 1085 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698