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

Side by Side Diff: net/cert/nss_cert_database_unittest.cc

Issue 2722733002: Revert of Use TaskScheduler instead of WorkerPool in nss_cert_database.cc. (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « net/cert/nss_cert_database_chromeos_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/cert/nss_cert_database.h" 5 #include "net/cert/nss_cert_database.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <certdb.h> 8 #include <certdb.h>
9 #include <pk11pub.h> 9 #include <pk11pub.h>
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/message_loop/message_loop.h"
19 #include "base/run_loop.h" 18 #include "base/run_loop.h"
20 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
21 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
23 #include "base/test/scoped_task_scheduler.h"
24 #include "base/threading/thread_task_runner_handle.h" 22 #include "base/threading/thread_task_runner_handle.h"
25 #include "crypto/scoped_nss_types.h" 23 #include "crypto/scoped_nss_types.h"
26 #include "crypto/scoped_test_nss_db.h" 24 #include "crypto/scoped_test_nss_db.h"
27 #include "net/base/crypto_module.h" 25 #include "net/base/crypto_module.h"
28 #include "net/base/hash_value.h" 26 #include "net/base/hash_value.h"
29 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
30 #include "net/cert/cert_status_flags.h" 28 #include "net/cert/cert_status_flags.h"
31 #include "net/cert/cert_verify_proc_nss.h" 29 #include "net/cert/cert_verify_proc_nss.h"
32 #include "net/cert/cert_verify_result.h" 30 #include "net/cert/cert_verify_result.h"
33 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
(...skipping 22 matching lines...) Expand all
56 void SwapCertList(CertificateList* destination, 54 void SwapCertList(CertificateList* destination,
57 std::unique_ptr<CertificateList> source) { 55 std::unique_ptr<CertificateList> source) {
58 ASSERT_TRUE(destination); 56 ASSERT_TRUE(destination);
59 destination->swap(*source); 57 destination->swap(*source);
60 } 58 }
61 59
62 } // namespace 60 } // namespace
63 61
64 class CertDatabaseNSSTest : public testing::Test { 62 class CertDatabaseNSSTest : public testing::Test {
65 public: 63 public:
66 CertDatabaseNSSTest()
67 : scoped_task_scheduler_(base::MessageLoop::current()) {}
68
69 void SetUp() override { 64 void SetUp() override {
70 ASSERT_TRUE(test_nssdb_.is_open()); 65 ASSERT_TRUE(test_nssdb_.is_open());
71 cert_db_.reset(new NSSCertDatabase( 66 cert_db_.reset(new NSSCertDatabase(
72 crypto::ScopedPK11Slot( 67 crypto::ScopedPK11Slot(
73 PK11_ReferenceSlot(test_nssdb_.slot())) /* public slot */, 68 PK11_ReferenceSlot(test_nssdb_.slot())) /* public slot */,
74 crypto::ScopedPK11Slot( 69 crypto::ScopedPK11Slot(
75 PK11_ReferenceSlot(test_nssdb_.slot())) /* private slot */)); 70 PK11_ReferenceSlot(test_nssdb_.slot())) /* private slot */));
76 public_slot_ = cert_db_->GetPublicSlot(); 71 public_slot_ = cert_db_->GetPublicSlot();
77 72
78 // Test db should be empty at start of test. 73 // Test db should be empty at start of test.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 result.begin(), result.end(), 118 result.begin(), result.end(),
124 [](const scoped_refptr<X509Certificate>& lhs, 119 [](const scoped_refptr<X509Certificate>& lhs,
125 const scoped_refptr<X509Certificate>& rhs) { 120 const scoped_refptr<X509Certificate>& rhs) {
126 return SHA256HashValueLessThan()( 121 return SHA256HashValueLessThan()(
127 X509Certificate::CalculateFingerprint256(lhs->os_cert_handle()), 122 X509Certificate::CalculateFingerprint256(lhs->os_cert_handle()),
128 X509Certificate::CalculateFingerprint256(rhs->os_cert_handle())); 123 X509Certificate::CalculateFingerprint256(rhs->os_cert_handle()));
129 }); 124 });
130 return result; 125 return result;
131 } 126 }
132 127
133 base::test::ScopedTaskScheduler scoped_task_scheduler_;
134 std::unique_ptr<NSSCertDatabase> cert_db_; 128 std::unique_ptr<NSSCertDatabase> cert_db_;
135 const CertificateList empty_cert_list_; 129 const CertificateList empty_cert_list_;
136 crypto::ScopedTestNSSDB test_nssdb_; 130 crypto::ScopedTestNSSDB test_nssdb_;
137 crypto::ScopedPK11Slot public_slot_; 131 crypto::ScopedPK11Slot public_slot_;
138 }; 132 };
139 133
140 TEST_F(CertDatabaseNSSTest, ListCertsSync) { 134 TEST_F(CertDatabaseNSSTest, ListCertsSync) {
141 // This test isn't terribly useful, though it will at least let valgrind test 135 // This test isn't terribly useful, though it will at least let valgrind test
142 // for leaks. 136 // for leaks.
143 CertificateList certs; 137 CertificateList certs;
144 cert_db_->ListCertsSync(&certs); 138 cert_db_->ListCertsSync(&certs);
145 // The test DB is empty, but let's assume there will always be something in 139 // The test DB is empty, but let's assume there will always be something in
146 // the other slots. 140 // the other slots.
147 EXPECT_LT(0U, certs.size()); 141 EXPECT_LT(0U, certs.size());
148 } 142 }
149 143
150 TEST_F(CertDatabaseNSSTest, ListCerts) { 144 TEST_F(CertDatabaseNSSTest, ListCerts) {
151 // This test isn't terribly useful, though it will at least let valgrind test 145 // This test isn't terribly useful, though it will at least let valgrind test
152 // for leaks. 146 // for leaks.
153 CertificateList certs; 147 CertificateList certs;
148 cert_db_->SetSlowTaskRunnerForTest(base::ThreadTaskRunnerHandle::Get());
154 cert_db_->ListCerts(base::Bind(&SwapCertList, base::Unretained(&certs))); 149 cert_db_->ListCerts(base::Bind(&SwapCertList, base::Unretained(&certs)));
155 EXPECT_EQ(0U, certs.size()); 150 EXPECT_EQ(0U, certs.size());
156 151
157 base::RunLoop().RunUntilIdle(); 152 base::RunLoop().RunUntilIdle();
158 153
159 // The test DB is empty, but let's assume there will always be something in 154 // The test DB is empty, but let's assume there will always be something in
160 // the other slots. 155 // the other slots.
161 EXPECT_LT(0U, certs.size()); 156 EXPECT_LT(0U, certs.size());
162 } 157 }
163 158
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT, 1014 EXPECT_EQ(NSSCertDatabase::TRUST_DEFAULT,
1020 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT)); 1015 cert_db_->GetCertTrust(certs2[0].get(), SERVER_CERT));
1021 1016
1022 new_certs = ListCerts(); 1017 new_certs = ListCerts();
1023 ASSERT_EQ(2U, new_certs.size()); 1018 ASSERT_EQ(2U, new_certs.size());
1024 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname, 1019 EXPECT_STRNE(new_certs[0]->os_cert_handle()->nickname,
1025 new_certs[1]->os_cert_handle()->nickname); 1020 new_certs[1]->os_cert_handle()->nickname);
1026 } 1021 }
1027 1022
1028 } // namespace net 1023 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/nss_cert_database_chromeos_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698