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

Side by Side Diff: chrome/browser/chromeos/cros/network_library_unittest.cc

Issue 11174006: Implement ScopedTestNSSDB instead of OpenTestNSSDB() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another test Created 8 years, 2 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 <cert.h> 5 #include <cert.h>
6 #include <pk11pub.h> 6 #include <pk11pub.h>
7 7
8 #include <vector> 8 #include <vector>
9 #include <string> 9 #include <string>
10 10
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // NetworkLibraryStubImpl. 131 // NetworkLibraryStubImpl.
132 // NOTE: It would be of little value to test stub functions that simply return 132 // NOTE: It would be of little value to test stub functions that simply return
133 // predefined values, e.g. ethernet_available(). However, many other functions 133 // predefined values, e.g. ethernet_available(). However, many other functions
134 // such as connected_network() return values which are set indirectly and thus 134 // such as connected_network() return values which are set indirectly and thus
135 // we can test the logic of those setters. 135 // we can test the logic of those setters.
136 136
137 class NetworkLibraryStubTest : public testing::Test { 137 class NetworkLibraryStubTest : public testing::Test {
138 public: 138 public:
139 NetworkLibraryStubTest() : cros_(NULL) {} 139 NetworkLibraryStubTest() : cros_(NULL) {}
140 140
141 static void SetUpTestCase() {
142 // Ideally, we'd open a test DB for each test case, and close it
143 // again, removing the temp dir, but unfortunately, there's a
144 // bug in NSS that prevents this from working, so we just open
145 // it once, and empty it for each test case. Here's the bug:
146 // https://bugzilla.mozilla.org/show_bug.cgi?id=588269
147 ASSERT_TRUE(crypto::OpenTestNSSDB());
148 // There is no matching TearDownTestCase call to close the test NSS DB
149 // because that would leave NSS in a potentially broken state for further
150 // tests, due to https://bugzilla.mozilla.org/show_bug.cgi?id=588269
151 }
152
153 protected: 141 protected:
154 virtual void SetUp() { 142 virtual void SetUp() {
143 test_nssdb_.reset(new crypto::ScopedTestNSSDB());
144 ASSERT_TRUE(test_nssdb_->is_open());
145
155 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule(); 146 slot_ = net::NSSCertDatabase::GetInstance()->GetPublicModule();
156 cros_ = CrosLibrary::Get()->GetNetworkLibrary(); 147 cros_ = CrosLibrary::Get()->GetNetworkLibrary();
157 ASSERT_TRUE(cros_) << "GetNetworkLibrary() Failed!"; 148 ASSERT_TRUE(cros_) << "GetNetworkLibrary() Failed!";
158 149
159 // Test db should be empty at start of test. 150 // Test db should be empty at start of test.
160 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); 151 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size());
161 } 152 }
162 virtual void TearDown() { 153 virtual void TearDown() {
163 cros_ = NULL; 154 cros_ = NULL;
164 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle())); 155 EXPECT_TRUE(CleanupSlotContents(slot_->os_module_handle()));
165 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size()); 156 EXPECT_EQ(0U, ListCertsInSlot(slot_->os_module_handle()).size());
157 test_nssdb_.reset();
166 } 158 }
167 159
168 virtual void GetTestData(const std::string& filename, std::string* contents) { 160 virtual void GetTestData(const std::string& filename, std::string* contents) {
169 FilePath path; 161 FilePath path;
170 std::string error; 162 std::string error;
171 PathService::Get(chrome::DIR_TEST_DATA, &path); 163 PathService::Get(chrome::DIR_TEST_DATA, &path);
172 path = path.AppendASCII("chromeos").AppendASCII("cros").Append(filename); 164 path = path.AppendASCII("chromeos").AppendASCII("cros").Append(filename);
173 ASSERT_TRUE(contents != NULL); 165 ASSERT_TRUE(contents != NULL);
174 ASSERT_TRUE(file_util::PathExists(path)) 166 ASSERT_TRUE(file_util::PathExists(path))
175 << "Couldn't find test data file " << path.value(); 167 << "Couldn't find test data file " << path.value();
(...skipping 24 matching lines...) Expand all
200 bool ok = true; 192 bool ok = true;
201 net::CertificateList certs = ListCertsInSlot(slot); 193 net::CertificateList certs = ListCertsInSlot(slot);
202 for (size_t i = 0; i < certs.size(); ++i) { 194 for (size_t i = 0; i < certs.size(); ++i) {
203 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i])) 195 if (!net::NSSCertDatabase::GetInstance()->DeleteCertAndKey(certs[i]))
204 ok = false; 196 ok = false;
205 } 197 }
206 return ok; 198 return ok;
207 } 199 }
208 200
209 scoped_refptr<net::CryptoModule> slot_; 201 scoped_refptr<net::CryptoModule> slot_;
202 scoped_ptr<crypto::ScopedTestNSSDB> test_nssdb_;
Takashi Toyoshima 2012/10/17 04:58:53 I think I should not use scoped_ptr here too.
210 }; 203 };
211 204
212 // Default stub state: 205 // Default stub state:
213 // vpn1: disconnected, L2TP/IPsec + PSK 206 // vpn1: disconnected, L2TP/IPsec + PSK
214 // vpn2: disconnected, L2TP/IPsec + user cert 207 // vpn2: disconnected, L2TP/IPsec + user cert
215 // vpn3: disconnected, OpenVpn 208 // vpn3: disconnected, OpenVpn
216 // eth1: connected (active network) 209 // eth1: connected (active network)
217 // wifi1: connected 210 // wifi1: connected
218 // wifi2: disconnected 211 // wifi2: disconnected
219 // wifi3: disconnected, WEP 212 // wifi3: disconnected, WEP
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 363
371 // TODO(stevenjb): Test network profiles. 364 // TODO(stevenjb): Test network profiles.
372 365
373 // TODO(stevenjb): Test network devices. 366 // TODO(stevenjb): Test network devices.
374 367
375 // TODO(stevenjb): Test data plans. 368 // TODO(stevenjb): Test data plans.
376 369
377 // TODO(stevenjb): Test monitor network / device. 370 // TODO(stevenjb): Test monitor network / device.
378 371
379 } // namespace chromeos 372 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698