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

Side by Side Diff: chrome/browser/password_manager/password_store_mac_unittest.cc

Issue 2010463002: Mocker for OSCrypt (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated doc Created 4 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
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/password_manager/password_store_mac.h" 5 #include "chrome/browser/password_manager/password_store_mac.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/scoped_observer.h" 14 #include "base/scoped_observer.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/synchronization/waitable_event.h" 18 #include "base/synchronization/waitable_event.h"
19 #include "base/test/histogram_tester.h" 19 #include "base/test/histogram_tester.h"
20 #include "base/threading/thread_task_runner_handle.h" 20 #include "base/threading/thread_task_runner_handle.h"
21 #include "chrome/browser/password_manager/password_store_mac_internal.h" 21 #include "chrome/browser/password_manager/password_store_mac_internal.h"
22 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
23 #include "components/os_crypt/os_crypt.h" 23 #include "components/os_crypt/os_crypt_mocker.h"
24 #include "components/password_manager/core/browser/login_database.h" 24 #include "components/password_manager/core/browser/login_database.h"
25 #include "components/password_manager/core/browser/password_manager_test_utils.h " 25 #include "components/password_manager/core/browser/password_manager_test_utils.h "
26 #include "components/password_manager/core/browser/password_store_consumer.h" 26 #include "components/password_manager/core/browser/password_store_consumer.h"
27 #include "components/password_manager/core/browser/password_store_origin_unittes t.h" 27 #include "components/password_manager/core/browser/password_store_origin_unittes t.h"
28 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
29 #include "content/public/test/test_utils.h" 29 #include "content/public/test/test_utils.h"
30 #include "crypto/mock_apple_keychain.h" 30 #include "crypto/mock_apple_keychain.h"
31 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 #include "url/origin.h" 33 #include "url/origin.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 void PasswordStoreMacTestDelegate::FinishAsyncProcessing() { 209 void PasswordStoreMacTestDelegate::FinishAsyncProcessing() {
210 base::MessageLoop::current()->RunUntilIdle(); 210 base::MessageLoop::current()->RunUntilIdle();
211 } 211 }
212 212
213 void PasswordStoreMacTestDelegate::Initialize() { 213 void PasswordStoreMacTestDelegate::Initialize() {
214 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); 214 ASSERT_TRUE(db_dir_.CreateUniqueTempDir());
215 215
216 // Ensure that LoginDatabase will use the mock keychain if it needs to 216 // Ensure that LoginDatabase will use the mock keychain if it needs to
217 // encrypt/decrypt a password. 217 // encrypt/decrypt a password.
218 OSCrypt::UseMockKeychain(true); 218 OSCryptMocker::SetUpWithSingleton();
219 login_db_.reset(new LoginDatabase(test_login_db_file_path())); 219 login_db_.reset(new LoginDatabase(test_login_db_file_path()));
220 ASSERT_TRUE(login_db_->Init()); 220 ASSERT_TRUE(login_db_->Init());
221 221
222 // Create and initialize the password store. 222 // Create and initialize the password store.
223 store_ = new PasswordStoreMac(base::ThreadTaskRunnerHandle::Get(), 223 store_ = new PasswordStoreMac(base::ThreadTaskRunnerHandle::Get(),
224 base::ThreadTaskRunnerHandle::Get(), 224 base::ThreadTaskRunnerHandle::Get(),
225 base::WrapUnique(new MockAppleKeychain)); 225 base::WrapUnique(new MockAppleKeychain));
226 store_->set_login_metadata_db(login_db_.get()); 226 store_->set_login_metadata_db(login_db_.get());
227 store_->login_metadata_db()->set_clear_password_values(false); 227 store_->login_metadata_db()->set_clear_password_values(false);
228 } 228 }
229 229
230 void PasswordStoreMacTestDelegate::ClosePasswordStore() { 230 void PasswordStoreMacTestDelegate::ClosePasswordStore() {
231 store_->ShutdownOnUIThread(); 231 store_->ShutdownOnUIThread();
232 FinishAsyncProcessing(); 232 FinishAsyncProcessing();
233 OSCryptMocker::TearDown();
233 } 234 }
234 235
235 base::FilePath PasswordStoreMacTestDelegate::test_login_db_file_path() const { 236 base::FilePath PasswordStoreMacTestDelegate::test_login_db_file_path() const {
236 return db_dir_.path().Append(FILE_PATH_LITERAL("login.db")); 237 return db_dir_.path().Append(FILE_PATH_LITERAL("login.db"));
237 } 238 }
238 239
239 } // namespace 240 } // namespace
240 241
241 namespace password_manager { 242 namespace password_manager {
242 243
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 class PasswordStoreMacTest : public testing::Test { 1248 class PasswordStoreMacTest : public testing::Test {
1248 public: 1249 public:
1249 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} 1250 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {}
1250 1251
1251 void SetUp() override { 1252 void SetUp() override {
1252 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); 1253 ASSERT_TRUE(db_dir_.CreateUniqueTempDir());
1253 histogram_tester_.reset(new base::HistogramTester); 1254 histogram_tester_.reset(new base::HistogramTester);
1254 1255
1255 // Ensure that LoginDatabase will use the mock keychain if it needs to 1256 // Ensure that LoginDatabase will use the mock keychain if it needs to
1256 // encrypt/decrypt a password. 1257 // encrypt/decrypt a password.
1257 OSCrypt::UseMockKeychain(true); 1258 OSCryptMocker::SetUpWithSingleton();
1258 login_db_.reset( 1259 login_db_.reset(
1259 new password_manager::LoginDatabase(test_login_db_file_path())); 1260 new password_manager::LoginDatabase(test_login_db_file_path()));
1260 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread")); 1261 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread"));
1261 ASSERT_TRUE(thread_->Start()); 1262 ASSERT_TRUE(thread_->Start());
1262 ASSERT_TRUE(thread_->task_runner()->PostTask( 1263 ASSERT_TRUE(thread_->task_runner()->PostTask(
1263 FROM_HERE, base::Bind(&PasswordStoreMacTest::InitLoginDatabase, 1264 FROM_HERE, base::Bind(&PasswordStoreMacTest::InitLoginDatabase,
1264 base::Unretained(login_db_.get())))); 1265 base::Unretained(login_db_.get()))));
1265 CreateAndInitPasswordStore(login_db_.get()); 1266 CreateAndInitPasswordStore(login_db_.get());
1266 // Make sure deferred initialization is performed before some tests start 1267 // Make sure deferred initialization is performed before some tests start
1267 // accessing the |login_db| directly. 1268 // accessing the |login_db| directly.
1268 FinishAsyncProcessing(); 1269 FinishAsyncProcessing();
1269 } 1270 }
1270 1271
1271 void TearDown() override { 1272 void TearDown() override {
1272 ClosePasswordStore(); 1273 ClosePasswordStore();
1273 thread_.reset(); 1274 thread_.reset();
1274 login_db_.reset(); 1275 login_db_.reset();
1275 // Whatever a test did, PasswordStoreMac stores only empty password values 1276 // Whatever a test did, PasswordStoreMac stores only empty password values
1276 // in LoginDatabase. The empty valus do not require encryption and therefore 1277 // in LoginDatabase. The empty valus do not require encryption and therefore
1277 // OSCrypt shouldn't call the Keychain. The histogram doesn't cover the 1278 // OSCrypt shouldn't call the Keychain. The histogram doesn't cover the
1278 // internet passwords. 1279 // internet passwords.
1279 if (histogram_tester_) { 1280 if (histogram_tester_) {
1280 histogram_tester_->ExpectTotalCount("OSX.Keychain.Access", 0); 1281 histogram_tester_->ExpectTotalCount("OSX.Keychain.Access", 0);
1281 } 1282 }
1283 OSCryptMocker::TearDown();
1282 } 1284 }
1283 1285
1284 static void InitLoginDatabase(password_manager::LoginDatabase* login_db) { 1286 static void InitLoginDatabase(password_manager::LoginDatabase* login_db) {
1285 ASSERT_TRUE(login_db->Init()); 1287 ASSERT_TRUE(login_db->Init());
1286 } 1288 }
1287 1289
1288 void CreateAndInitPasswordStore(password_manager::LoginDatabase* login_db) { 1290 void CreateAndInitPasswordStore(password_manager::LoginDatabase* login_db) {
1289 store_ = new PasswordStoreMac( 1291 store_ = new PasswordStoreMac(
1290 base::ThreadTaskRunnerHandle::Get(), nullptr, 1292 base::ThreadTaskRunnerHandle::Get(), nullptr,
1291 base::WrapUnique<AppleKeychain>(new MockAppleKeychain)); 1293 base::WrapUnique<AppleKeychain>(new MockAppleKeychain));
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 histogram_tester_->ExpectUniqueSample( 1966 histogram_tester_->ExpectUniqueSample(
1965 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1); 1967 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1);
1966 histogram_tester_->ExpectUniqueSample( 1968 histogram_tester_->ExpectUniqueSample(
1967 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1); 1969 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1);
1968 histogram_tester_->ExpectUniqueSample( 1970 histogram_tester_->ExpectUniqueSample(
1969 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords", 1971 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords",
1970 2, 1); 1972 2, 1);
1971 // Don't test the encryption key access. 1973 // Don't test the encryption key access.
1972 histogram_tester_.reset(); 1974 histogram_tester_.reset();
1973 } 1975 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698