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

Side by Side Diff: chrome/browser/password_manager/simple_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/simple_password_store_mac.h" 5 #include "chrome/browser/password_manager/simple_password_store_mac.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/os_crypt/os_crypt.h" 10 #include "components/os_crypt/os_crypt_mocker.h"
11 #include "components/password_manager/core/browser/login_database.h" 11 #include "components/password_manager/core/browser/login_database.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 using password_manager::PasswordStoreChange; 19 using password_manager::PasswordStoreChange;
20 using testing::ElementsAreArray; 20 using testing::ElementsAreArray;
(...skipping 10 matching lines...) Expand all
31 class SimplePasswordStoreMacTest : public testing::Test { 31 class SimplePasswordStoreMacTest : public testing::Test {
32 public: 32 public:
33 SimplePasswordStoreMacTest() 33 SimplePasswordStoreMacTest()
34 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD) {} 34 : thread_bundle_(content::TestBrowserThreadBundle::REAL_FILE_THREAD) {}
35 35
36 void SetUp() override { 36 void SetUp() override {
37 ASSERT_TRUE(db_dir_.CreateUniqueTempDir()); 37 ASSERT_TRUE(db_dir_.CreateUniqueTempDir());
38 38
39 // Ensure that LoginDatabase will use the mock keychain if it needs to 39 // Ensure that LoginDatabase will use the mock keychain if it needs to
40 // encrypt/decrypt a password. 40 // encrypt/decrypt a password.
41 OSCrypt::UseMockKeychain(true); 41 OSCryptMocker::SetUpWithSingleton();
42 42
43 // Setup LoginDatabase. 43 // Setup LoginDatabase.
44 std::unique_ptr<password_manager::LoginDatabase> login_db( 44 std::unique_ptr<password_manager::LoginDatabase> login_db(
45 new password_manager::LoginDatabase(test_login_db_file_path())); 45 new password_manager::LoginDatabase(test_login_db_file_path()));
46 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = 46 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
47 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 47 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
48 ASSERT_TRUE(file_task_runner); 48 ASSERT_TRUE(file_task_runner);
49 file_task_runner->PostTask( 49 file_task_runner->PostTask(
50 FROM_HERE, 50 FROM_HERE,
51 base::Bind(&InitOnBackgroundThread, base::Unretained(login_db.get()))); 51 base::Bind(&InitOnBackgroundThread, base::Unretained(login_db.get())));
52 store_ = new SimplePasswordStoreMac( 52 store_ = new SimplePasswordStoreMac(
53 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), nullptr, 53 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), nullptr,
54 std::unique_ptr<password_manager::LoginDatabase>()); 54 std::unique_ptr<password_manager::LoginDatabase>());
55 file_task_runner->PostTask( 55 file_task_runner->PostTask(
56 FROM_HERE, 56 FROM_HERE,
57 base::Bind(&SimplePasswordStoreMac::InitWithTaskRunner, store_, 57 base::Bind(&SimplePasswordStoreMac::InitWithTaskRunner, store_,
58 file_task_runner, base::Passed(&login_db))); 58 file_task_runner, base::Passed(&login_db)));
59 // Make sure deferred initialization is finished. 59 // Make sure deferred initialization is finished.
60 FinishAsyncProcessing(); 60 FinishAsyncProcessing();
61 } 61 }
62 62
63 void TearDown() override { 63 void TearDown() override {
64 store_->ShutdownOnUIThread(); 64 store_->ShutdownOnUIThread();
65 EXPECT_TRUE(store_->GetBackgroundTaskRunner()); 65 EXPECT_TRUE(store_->GetBackgroundTaskRunner());
66 store_ = nullptr; 66 store_ = nullptr;
67 OSCryptMocker::TearDown();
67 } 68 }
68 69
69 base::FilePath test_login_db_file_path() const { 70 base::FilePath test_login_db_file_path() const {
70 return db_dir_.path().Append(FILE_PATH_LITERAL("login.db")); 71 return db_dir_.path().Append(FILE_PATH_LITERAL("login.db"));
71 } 72 }
72 73
73 scoped_refptr<SimplePasswordStoreMac> store() { return store_; } 74 scoped_refptr<SimplePasswordStoreMac> store() { return store_; }
74 75
75 void FinishAsyncProcessing() { 76 void FinishAsyncProcessing() {
76 scoped_refptr<content::MessageLoopRunner> runner( 77 scoped_refptr<content::MessageLoopRunner> runner(
(...skipping 30 matching lines...) Expand all
107 PasswordStoreChange(PasswordStoreChange::ADD, form), 108 PasswordStoreChange(PasswordStoreChange::ADD, form),
108 }; 109 };
109 EXPECT_CALL(observer, 110 EXPECT_CALL(observer,
110 OnLoginsChanged(ElementsAreArray(expected_add_changes))); 111 OnLoginsChanged(ElementsAreArray(expected_add_changes)));
111 // Adding a login should trigger a notification. 112 // Adding a login should trigger a notification.
112 store()->AddLogin(form); 113 store()->AddLogin(form);
113 FinishAsyncProcessing(); 114 FinishAsyncProcessing();
114 } 115 }
115 116
116 } // namespace 117 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_proxy_mac_unittest.cc ('k') | chrome/browser/signin/local_auth_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698