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

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

Issue 1211253015: Revert "Start the migration of passwords from the Keychain." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/scoped_observer.h" 9 #include "base/scoped_observer.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "chrome/browser/password_manager/password_store_mac_internal.h" 16 #include "chrome/browser/password_manager/password_store_mac_internal.h"
17 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
18 #include "components/os_crypt/os_crypt.h" 18 #include "components/os_crypt/os_crypt.h"
19 #include "components/password_manager/core/browser/login_database.h" 19 #include "components/password_manager/core/browser/login_database.h"
20 #include "components/password_manager/core/browser/password_manager_test_utils.h " 20 #include "components/password_manager/core/browser/password_manager_test_utils.h "
21 #include "components/password_manager/core/browser/password_store_consumer.h" 21 #include "components/password_manager/core/browser/password_store_consumer.h"
22 #include "content/public/test/test_browser_thread.h" 22 #include "content/public/test/test_browser_thread.h"
23 #include "content/public/test/test_utils.h"
24 #include "crypto/mock_apple_keychain.h" 23 #include "crypto/mock_apple_keychain.h"
25 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 26
28 using autofill::PasswordForm; 27 using autofill::PasswordForm;
29 using base::ASCIIToUTF16; 28 using base::ASCIIToUTF16;
30 using base::WideToUTF16; 29 using base::WideToUTF16;
31 using content::BrowserThread; 30 using content::BrowserThread;
32 using crypto::MockAppleKeychain; 31 using crypto::MockAppleKeychain;
33 using internal_keychain_helpers::FormsMatchForMerge; 32 using internal_keychain_helpers::FormsMatchForMerge;
(...skipping 19 matching lines...) Expand all
53 base::MessageLoop::current()->Quit(); 52 base::MessageLoop::current()->Quit();
54 } 53 }
55 54
56 // From the mock's argument #0 of type const std::vector<PasswordForm*>& takes 55 // From the mock's argument #0 of type const std::vector<PasswordForm*>& takes
57 // the first form and copies it to the form pointed to by |target_form_ptr|. 56 // the first form and copies it to the form pointed to by |target_form_ptr|.
58 ACTION_P(SaveACopyOfFirstForm, target_form_ptr) { 57 ACTION_P(SaveACopyOfFirstForm, target_form_ptr) {
59 ASSERT_FALSE(arg0.empty()); 58 ASSERT_FALSE(arg0.empty());
60 *target_form_ptr = *arg0[0]; 59 *target_form_ptr = *arg0[0];
61 } 60 }
62 61
63 void Noop() {
64 }
65
66 class MockPasswordStoreConsumer : public PasswordStoreConsumer { 62 class MockPasswordStoreConsumer : public PasswordStoreConsumer {
67 public: 63 public:
68 MOCK_METHOD1(OnGetPasswordStoreResultsConstRef, 64 MOCK_METHOD1(OnGetPasswordStoreResultsConstRef,
69 void(const std::vector<PasswordForm*>&)); 65 void(const std::vector<PasswordForm*>&));
70 66
71 // GMock cannot mock methods with move-only args. 67 // GMock cannot mock methods with move-only args.
72 void OnGetPasswordStoreResults(ScopedVector<PasswordForm> results) override { 68 void OnGetPasswordStoreResults(ScopedVector<PasswordForm> results) override {
73 OnGetPasswordStoreResultsConstRef(results.get()); 69 OnGetPasswordStoreResultsConstRef(results.get());
74 } 70 }
75 }; 71 };
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 } 1208 }
1213 1209
1214 static void InitLoginDatabase(password_manager::LoginDatabase* login_db) { 1210 static void InitLoginDatabase(password_manager::LoginDatabase* login_db) {
1215 ASSERT_TRUE(login_db->Init()); 1211 ASSERT_TRUE(login_db->Init());
1216 } 1212 }
1217 1213
1218 void CreateAndInitPasswordStore(password_manager::LoginDatabase* login_db) { 1214 void CreateAndInitPasswordStore(password_manager::LoginDatabase* login_db) {
1219 store_ = new PasswordStoreMac( 1215 store_ = new PasswordStoreMac(
1220 base::ThreadTaskRunnerHandle::Get(), nullptr, 1216 base::ThreadTaskRunnerHandle::Get(), nullptr,
1221 make_scoped_ptr<AppleKeychain>(new MockAppleKeychain)); 1217 make_scoped_ptr<AppleKeychain>(new MockAppleKeychain));
1222 ASSERT_TRUE(thread_->task_runner()->PostTask( 1218 store_->InitWithTaskRunner(thread_->task_runner());
1223 FROM_HERE, base::Bind(&PasswordStoreMac::InitWithTaskRunner, store_, 1219 ASSERT_TRUE(store_->ScheduleTask(
1224 thread_->task_runner()))); 1220 base::Bind(&PasswordStoreMac::set_login_metadata_db, store_,
1225 1221 base::Unretained(login_db))));
1226 ASSERT_TRUE(thread_->task_runner()->PostTask(
1227 FROM_HERE, base::Bind(&PasswordStoreMac::set_login_metadata_db, store_,
1228 base::Unretained(login_db))));
1229 } 1222 }
1230 1223
1231 void ClosePasswordStore() { 1224 void ClosePasswordStore() {
1232 if (!store_) 1225 if (!store_)
1233 return; 1226 return;
1234 1227
1235 store_->Shutdown(); 1228 store_->Shutdown();
1236 store_ = nullptr; 1229 store_ = nullptr;
1237 } 1230 }
1238 1231
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 1285
1293 password_manager::LoginDatabase* login_db() const { 1286 password_manager::LoginDatabase* login_db() const {
1294 return store_->login_metadata_db(); 1287 return store_->login_metadata_db();
1295 } 1288 }
1296 1289
1297 MockAppleKeychain* keychain() { 1290 MockAppleKeychain* keychain() {
1298 return static_cast<MockAppleKeychain*>(store_->keychain()); 1291 return static_cast<MockAppleKeychain*>(store_->keychain());
1299 } 1292 }
1300 1293
1301 void FinishAsyncProcessing() { 1294 void FinishAsyncProcessing() {
1302 scoped_refptr<content::MessageLoopRunner> runner = 1295 // Do a store-level query to wait for all the previously enqueued operations
1303 new content::MessageLoopRunner; 1296 // to finish.
1304 ASSERT_TRUE(thread_->task_runner()->PostTaskAndReply( 1297 MockPasswordStoreConsumer consumer;
1305 FROM_HERE, base::Bind(&Noop), runner->QuitClosure())); 1298 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer);
1306 runner->Run(); 1299 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(_))
1300 .WillOnce(QuitUIMessageLoop());
1301 base::MessageLoop::current()->Run();
1307 } 1302 }
1308 1303
1309 PasswordStoreMac* store() { return store_.get(); } 1304 PasswordStoreMac* store() { return store_.get(); }
1310 1305
1311 protected: 1306 protected:
1312 base::MessageLoopForUI message_loop_; 1307 base::MessageLoopForUI message_loop_;
1313 content::TestBrowserThread ui_thread_; 1308 content::TestBrowserThread ui_thread_;
1314 // Thread that the synchronous methods are run on. 1309 // Thread that the synchronous methods are run on.
1315 scoped_ptr<base::Thread> thread_; 1310 scoped_ptr<base::Thread> thread_;
1316 1311
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 ASSERT_EQ(1u, matching_items.size()); 1661 ASSERT_EQ(1u, matching_items.size());
1667 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); 1662 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value);
1668 1663
1669 // Check the third-party password is still there. 1664 // Check the third-party password is still there.
1670 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); 1665 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1671 matching_items = owned_keychain_adapter.PasswordsFillingForm( 1666 matching_items = owned_keychain_adapter.PasswordsFillingForm(
1672 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); 1667 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML);
1673 ASSERT_EQ(1u, matching_items.size()); 1668 ASSERT_EQ(1u, matching_items.size());
1674 } 1669 }
1675 1670
1671 // Open the store and immediately write to it and try to read it back, without
1672 // first waiting for the initialization to finish. If tasks are processed in
1673 // order, read/write operations will correctly be performed only after the
1674 // initialization has finished.
1675 TEST_F(PasswordStoreMacTest, StoreIsUsableImmediatelyAfterConstruction) {
1676 ClosePasswordStore();
1677
1678 base::WaitableEvent event(false, false);
1679 login_db_.reset(
1680 new SlowToInitLoginDatabase(test_login_db_file_path(), &event));
1681 ASSERT_TRUE(thread_->task_runner()->PostTask(
1682 FROM_HERE, base::Bind(&PasswordStoreMacTest::InitLoginDatabase,
1683 base::Unretained(login_db_.get()))));
1684 CreateAndInitPasswordStore(login_db_.get());
1685
1686 PasswordFormData www_form_data = {
1687 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1688 "http://www.facebook.com/index.html", "login", L"username", L"password",
1689 L"submit", L"not_joe_user", L"12345", true, false, 1};
1690 scoped_ptr<PasswordForm> form =
1691 CreatePasswordFormFromDataForTesting(www_form_data);
1692 store()->AddLogin(*form);
1693
1694 MockPasswordStoreConsumer mock_consumer;
1695 store()->GetLogins(*form, PasswordStore::ALLOW_PROMPT, &mock_consumer);
1696
1697 // Now the read/write tasks are scheduled, let the DB initialization proceed.
1698 event.Signal();
1699
1700 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u)))
1701 .WillOnce(QuitUIMessageLoop());
1702 base::MessageLoop::current()->Run();
1703 EXPECT_TRUE(login_db());
1704 }
1705
1676 // Add a facebook form to the store but not to the keychain. The form is to be 1706 // Add a facebook form to the store but not to the keychain. The form is to be
1677 // implicitly deleted. However, the observers shouldn't get notified about 1707 // implicitly deleted. However, the observers shouldn't get notified about
1678 // deletion of non-existent forms like m.facebook.com. 1708 // deletion of non-existent forms like m.facebook.com.
1679 TEST_F(PasswordStoreMacTest, SilentlyRemoveOrphanedForm) { 1709 TEST_F(PasswordStoreMacTest, SilentlyRemoveOrphanedForm) {
1680 testing::StrictMock<MockPasswordStoreObserver> mock_observer; 1710 testing::StrictMock<MockPasswordStoreObserver> mock_observer;
1681 store()->AddObserver(&mock_observer); 1711 store()->AddObserver(&mock_observer);
1682 1712
1683 // 1. Add a password for www.facebook.com to the LoginDatabase. 1713 // 1. Add a password for www.facebook.com to the LoginDatabase.
1684 PasswordFormData www_form_data = { 1714 PasswordFormData www_form_data = {
1685 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", 1715 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 histogram_tester_->ExpectUniqueSample( 1887 histogram_tester_->ExpectUniqueSample(
1858 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1); 1888 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1);
1859 histogram_tester_->ExpectUniqueSample( 1889 histogram_tester_->ExpectUniqueSample(
1860 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1); 1890 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1);
1861 histogram_tester_->ExpectUniqueSample( 1891 histogram_tester_->ExpectUniqueSample(
1862 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords", 1892 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords",
1863 2, 1); 1893 2, 1);
1864 // Don't test the encryption key access. 1894 // Don't test the encryption key access.
1865 histogram_tester_.reset(); 1895 histogram_tester_.reset();
1866 } 1896 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | chrome/browser/password_manager/password_store_proxy_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698