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

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

Issue 2691683003: Remove OnCertDBChanged |cert| parameter. (Closed)
Patch Set: comment wording Created 3 years, 10 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.cc ('k') | net/quic/chromium/quic_stream_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_chromeos.h" 5 #include "net/cert/nss_cert_database_chromeos.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 class NSSCertDatabaseChromeOSTest : public testing::Test, 49 class NSSCertDatabaseChromeOSTest : public testing::Test,
50 public CertDatabase::Observer { 50 public CertDatabase::Observer {
51 public: 51 public:
52 NSSCertDatabaseChromeOSTest() 52 NSSCertDatabaseChromeOSTest()
53 : scoped_task_scheduler_(base::MessageLoop::current()), 53 : scoped_task_scheduler_(base::MessageLoop::current()),
54 observer_added_(false), 54 observer_added_(false),
55 db_changed_count_(0),
55 user_1_("user1"), 56 user_1_("user1"),
56 user_2_("user2") {} 57 user_2_("user2") {}
57 58
58 void SetUp() override { 59 void SetUp() override {
59 // Initialize nss_util slots. 60 // Initialize nss_util slots.
60 ASSERT_TRUE(user_1_.constructed_successfully()); 61 ASSERT_TRUE(user_1_.constructed_successfully());
61 ASSERT_TRUE(user_2_.constructed_successfully()); 62 ASSERT_TRUE(user_2_.constructed_successfully());
62 user_1_.FinishInit(); 63 user_1_.FinishInit();
63 user_2_.FinishInit(); 64 user_2_.FinishInit();
64 65
(...skipping 16 matching lines...) Expand all
81 CertDatabase::GetInstance()->AddObserver(this); 82 CertDatabase::GetInstance()->AddObserver(this);
82 observer_added_ = true; 83 observer_added_ = true;
83 } 84 }
84 85
85 void TearDown() override { 86 void TearDown() override {
86 if (observer_added_) 87 if (observer_added_)
87 CertDatabase::GetInstance()->RemoveObserver(this); 88 CertDatabase::GetInstance()->RemoveObserver(this);
88 } 89 }
89 90
90 // CertDatabase::Observer: 91 // CertDatabase::Observer:
91 void OnCertDBChanged(const X509Certificate* cert) override { 92 void OnCertDBChanged() override { db_changed_count_++; }
92 added_ca_.push_back(cert ? cert->os_cert_handle() : NULL);
93 }
94 93
95 protected: 94 protected:
96 base::test::ScopedTaskScheduler scoped_task_scheduler_; 95 base::test::ScopedTaskScheduler scoped_task_scheduler_;
97 96
98 bool observer_added_; 97 bool observer_added_;
99 // Certificates that were passed to the CertDatabase observers. 98 int db_changed_count_;
100 std::vector<CERTCertificate*> added_ca_;
101 99
102 crypto::ScopedTestNSSChromeOSUser user_1_; 100 crypto::ScopedTestNSSChromeOSUser user_1_;
103 crypto::ScopedTestNSSChromeOSUser user_2_; 101 crypto::ScopedTestNSSChromeOSUser user_2_;
104 crypto::ScopedTestNSSDB system_db_; 102 crypto::ScopedTestNSSDB system_db_;
105 std::unique_ptr<NSSCertDatabaseChromeOS> db_1_; 103 std::unique_ptr<NSSCertDatabaseChromeOS> db_1_;
106 std::unique_ptr<NSSCertDatabaseChromeOS> db_2_; 104 std::unique_ptr<NSSCertDatabaseChromeOS> db_2_;
107 }; 105 };
108 106
109 // Test that ListModules() on each user includes that user's NSS software slot, 107 // Test that ListModules() on each user includes that user's NSS software slot,
110 // and does not include the software slot of the other user. (Does not check the 108 // and does not include the software slot of the other user. (Does not check the
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // imported them. 170 // imported them.
173 EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist)); 171 EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist));
174 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist)); 172 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist));
175 173
176 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist)); 174 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist));
177 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist)); 175 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist));
178 176
179 // Run the message loop so the observer notifications get processed. 177 // Run the message loop so the observer notifications get processed.
180 base::RunLoop().RunUntilIdle(); 178 base::RunLoop().RunUntilIdle();
181 // Should have gotten two OnCertDBChanged notifications. 179 // Should have gotten two OnCertDBChanged notifications.
182 ASSERT_EQ(2U, added_ca_.size()); 180 ASSERT_EQ(2, db_changed_count_);
183 // TODO(mattm): make NSSCertDatabase actually pass the cert to the callback,
184 // and enable these checks:
185 // EXPECT_EQ(certs_1[0]->os_cert_handle(), added_ca_[0]);
186 // EXPECT_EQ(certs_2[0]->os_cert_handle(), added_ca_[1]);
187 181
188 // Tests that the new certs are loaded by async ListCerts method. 182 // Tests that the new certs are loaded by async ListCerts method.
189 CertificateList user_1_certlist_async; 183 CertificateList user_1_certlist_async;
190 CertificateList user_2_certlist_async; 184 CertificateList user_2_certlist_async;
191 db_1_->ListCerts( 185 db_1_->ListCerts(
192 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async))); 186 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async)));
193 db_2_->ListCerts( 187 db_2_->ListCerts(
194 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async))); 188 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async)));
195 189
196 base::RunLoop().RunUntilIdle(); 190 base::RunLoop().RunUntilIdle();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist)); 234 EXPECT_TRUE(IsCertInCertificateList(certs_1[0].get(), user_1_certlist));
241 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist)); 235 EXPECT_FALSE(IsCertInCertificateList(certs_1[0].get(), user_2_certlist));
242 236
243 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist)); 237 EXPECT_TRUE(IsCertInCertificateList(certs_2[0].get(), user_2_certlist));
244 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist)); 238 EXPECT_FALSE(IsCertInCertificateList(certs_2[0].get(), user_1_certlist));
245 239
246 // Run the message loop so the observer notifications get processed. 240 // Run the message loop so the observer notifications get processed.
247 base::RunLoop().RunUntilIdle(); 241 base::RunLoop().RunUntilIdle();
248 // TODO(mattm): ImportServerCert doesn't actually cause any observers to 242 // TODO(mattm): ImportServerCert doesn't actually cause any observers to
249 // fire. Is that correct? 243 // fire. Is that correct?
250 EXPECT_EQ(0U, added_ca_.size()); 244 EXPECT_EQ(0, db_changed_count_);
251 245
252 // Tests that the new certs are loaded by async ListCerts method. 246 // Tests that the new certs are loaded by async ListCerts method.
253 CertificateList user_1_certlist_async; 247 CertificateList user_1_certlist_async;
254 CertificateList user_2_certlist_async; 248 CertificateList user_2_certlist_async;
255 db_1_->ListCerts( 249 db_1_->ListCerts(
256 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async))); 250 base::Bind(&SwapCertLists, base::Unretained(&user_1_certlist_async)));
257 db_2_->ListCerts( 251 db_2_->ListCerts(
258 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async))); 252 base::Bind(&SwapCertLists, base::Unretained(&user_2_certlist_async)));
259 253
260 base::RunLoop().RunUntilIdle(); 254 base::RunLoop().RunUntilIdle();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 "client_2.pem", 306 "client_2.pem",
313 "client_2.pk8", 307 "client_2.pk8",
314 system_db_.slot())); 308 system_db_.slot()));
315 CertificateList certs; 309 CertificateList certs;
316 db_2_->ListCertsSync(&certs); 310 db_2_->ListCertsSync(&certs);
317 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs)); 311 EXPECT_TRUE(IsCertInCertificateList(cert_1.get(), certs));
318 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs)); 312 EXPECT_FALSE(IsCertInCertificateList(cert_2.get(), certs));
319 } 313 }
320 314
321 } // namespace net 315 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/nss_cert_database.cc ('k') | net/quic/chromium/quic_stream_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698