| OLD | NEW |
| 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 |
| (...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 // The query operations will also do some housekeeping: they will remove | 1344 // The query operations will also do some housekeeping: they will remove |
| 1345 // dangling credentials in the LoginDatabase without a matching Keychain | 1345 // dangling credentials in the LoginDatabase without a matching Keychain |
| 1346 // item when one is expected. If the logic that stores the Keychain item | 1346 // item when one is expected. If the logic that stores the Keychain item |
| 1347 // is incorrect, this will wipe the newly added form before the second | 1347 // is incorrect, this will wipe the newly added form before the second |
| 1348 // query. | 1348 // query. |
| 1349 store()->GetAutofillableLogins(&mock_consumer); | 1349 store()->GetAutofillableLogins(&mock_consumer); |
| 1350 base::RunLoop().Run(); | 1350 base::RunLoop().Run(); |
| 1351 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); | 1351 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
| 1352 EXPECT_EQ(form, returned_form); | 1352 EXPECT_EQ(form, returned_form); |
| 1353 | 1353 |
| 1354 PasswordForm query_form = form; | 1354 PasswordStore::FormDigest query_form(form); |
| 1355 query_form.password_value.clear(); | |
| 1356 query_form.username_value.clear(); | |
| 1357 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) | 1355 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) |
| 1358 .WillOnce( | 1356 .WillOnce( |
| 1359 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); | 1357 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); |
| 1360 store()->GetLogins(query_form, &mock_consumer); | 1358 store()->GetLogins(query_form, &mock_consumer); |
| 1361 base::RunLoop().Run(); | 1359 base::RunLoop().Run(); |
| 1362 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); | 1360 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); |
| 1363 EXPECT_EQ(form, returned_form); | 1361 EXPECT_EQ(form, returned_form); |
| 1364 | 1362 |
| 1365 store()->RemoveLogin(form); | 1363 store()->RemoveLogin(form); |
| 1366 } | 1364 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 if (updates[i].password) { | 1496 if (updates[i].password) { |
| 1499 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; | 1497 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; |
| 1500 if (matching_items.size() >= 1) | 1498 if (matching_items.size() >= 1) |
| 1501 EXPECT_EQ(ASCIIToUTF16(updates[i].password), | 1499 EXPECT_EQ(ASCIIToUTF16(updates[i].password), |
| 1502 matching_items[0]->password_value) | 1500 matching_items[0]->password_value) |
| 1503 << "iteration " << i; | 1501 << "iteration " << i; |
| 1504 } else { | 1502 } else { |
| 1505 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; | 1503 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; |
| 1506 } | 1504 } |
| 1507 | 1505 |
| 1508 EXPECT_TRUE(login_db()->GetLogins(*query_form, &matching_items)); | 1506 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*query_form), |
| 1507 &matching_items)); |
| 1509 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) | 1508 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) |
| 1510 << "iteration " << i; | 1509 << "iteration " << i; |
| 1511 } | 1510 } |
| 1512 } | 1511 } |
| 1513 | 1512 |
| 1514 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { | 1513 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { |
| 1515 // Tests that association between the keychain and login database parts of a | 1514 // Tests that association between the keychain and login database parts of a |
| 1516 // password added by fuzzy (PSL) matching works. | 1515 // password added by fuzzy (PSL) matching works. |
| 1517 // 1. Add a password for www.facebook.com | 1516 // 1. Add a password for www.facebook.com |
| 1518 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the | 1517 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1545 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); | 1544 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain()); |
| 1546 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | 1545 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| 1547 owned_keychain_adapter.AddPassword(*www_form); | 1546 owned_keychain_adapter.AddPassword(*www_form); |
| 1548 | 1547 |
| 1549 // 2. Get a password for m.facebook.com. | 1548 // 2. Get a password for m.facebook.com. |
| 1550 PasswordForm m_form(*www_form); | 1549 PasswordForm m_form(*www_form); |
| 1551 m_form.signon_realm = "http://m.facebook.com"; | 1550 m_form.signon_realm = "http://m.facebook.com"; |
| 1552 m_form.origin = GURL("http://m.facebook.com/index.html"); | 1551 m_form.origin = GURL("http://m.facebook.com/index.html"); |
| 1553 | 1552 |
| 1554 MockPasswordStoreConsumer consumer; | 1553 MockPasswordStoreConsumer consumer; |
| 1555 store_->GetLogins(m_form, &consumer); | 1554 store_->GetLogins(PasswordStore::FormDigest(m_form), &consumer); |
| 1556 PasswordForm returned_form; | 1555 PasswordForm returned_form; |
| 1557 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) | 1556 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) |
| 1558 .WillOnce( | 1557 .WillOnce( |
| 1559 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); | 1558 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); |
| 1560 base::RunLoop().Run(); | 1559 base::RunLoop().Run(); |
| 1561 | 1560 |
| 1562 // 3. Add the returned password for m.facebook.com. | 1561 // 3. Add the returned password for m.facebook.com. |
| 1563 returned_form.signon_realm = "http://m.facebook.com"; | 1562 returned_form.signon_realm = "http://m.facebook.com"; |
| 1564 returned_form.origin = GURL("http://m.facebook.com/index.html"); | 1563 returned_form.origin = GURL("http://m.facebook.com/index.html"); |
| 1565 EXPECT_EQ(AddChangeForForm(returned_form), | 1564 EXPECT_EQ(AddChangeForForm(returned_form), |
| 1566 login_db()->AddLogin(returned_form)); | 1565 login_db()->AddLogin(returned_form)); |
| 1567 owned_keychain_adapter.AddPassword(m_form); | 1566 owned_keychain_adapter.AddPassword(m_form); |
| 1568 | 1567 |
| 1569 // 4. Remove both passwords. | 1568 // 4. Remove both passwords. |
| 1570 store_->RemoveLogin(*www_form); | 1569 store_->RemoveLogin(*www_form); |
| 1571 store_->RemoveLogin(m_form); | 1570 store_->RemoveLogin(m_form); |
| 1572 FinishAsyncProcessing(); | 1571 FinishAsyncProcessing(); |
| 1573 | 1572 |
| 1574 // No trace of www.facebook.com. | 1573 // No trace of www.facebook.com. |
| 1575 ScopedVector<autofill::PasswordForm> matching_items = | 1574 ScopedVector<autofill::PasswordForm> matching_items = |
| 1576 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, | 1575 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, |
| 1577 www_form->scheme); | 1576 www_form->scheme); |
| 1578 EXPECT_EQ(0u, matching_items.size()); | 1577 EXPECT_EQ(0u, matching_items.size()); |
| 1579 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items)); | 1578 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form), |
| 1579 &matching_items)); |
| 1580 EXPECT_EQ(0u, matching_items.size()); | 1580 EXPECT_EQ(0u, matching_items.size()); |
| 1581 // No trace of m.facebook.com. | 1581 // No trace of m.facebook.com. |
| 1582 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1582 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1583 m_form.signon_realm, m_form.scheme); | 1583 m_form.signon_realm, m_form.scheme); |
| 1584 EXPECT_EQ(0u, matching_items.size()); | 1584 EXPECT_EQ(0u, matching_items.size()); |
| 1585 EXPECT_TRUE(login_db()->GetLogins(m_form, &matching_items)); | 1585 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(m_form), |
| 1586 &matching_items)); |
| 1586 EXPECT_EQ(0u, matching_items.size()); | 1587 EXPECT_EQ(0u, matching_items.size()); |
| 1587 } | 1588 } |
| 1588 | 1589 |
| 1589 namespace { | 1590 namespace { |
| 1590 | 1591 |
| 1591 class PasswordsChangeObserver | 1592 class PasswordsChangeObserver |
| 1592 : public password_manager::PasswordStore::Observer { | 1593 : public password_manager::PasswordStore::Observer { |
| 1593 public: | 1594 public: |
| 1594 explicit PasswordsChangeObserver(PasswordStoreMac* store) : observer_(this) { | 1595 explicit PasswordsChangeObserver(PasswordStoreMac* store) : observer_(this) { |
| 1595 observer_.Add(store); | 1596 observer_.Add(store); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 L"submit", | 1850 L"submit", |
| 1850 L"not_joe_user", | 1851 L"not_joe_user", |
| 1851 L"12345", | 1852 L"12345", |
| 1852 true, | 1853 true, |
| 1853 1}; | 1854 1}; |
| 1854 www_form = CreatePasswordFormFromDataForTesting(www_form_data2); | 1855 www_form = CreatePasswordFormFromDataForTesting(www_form_data2); |
| 1855 store_->AddLogin(*www_form); | 1856 store_->AddLogin(*www_form); |
| 1856 FinishAsyncProcessing(); | 1857 FinishAsyncProcessing(); |
| 1857 | 1858 |
| 1858 ScopedVector<PasswordForm> matching_items; | 1859 ScopedVector<PasswordForm> matching_items; |
| 1859 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items)); | 1860 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form), |
| 1861 &matching_items)); |
| 1860 EXPECT_EQ(1u, matching_items.size()); | 1862 EXPECT_EQ(1u, matching_items.size()); |
| 1861 | 1863 |
| 1862 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time(), | 1864 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time(), |
| 1863 base::Closure()); | 1865 base::Closure()); |
| 1864 FinishAsyncProcessing(); | 1866 FinishAsyncProcessing(); |
| 1865 | 1867 |
| 1866 // Check the second facebook form is gone. | 1868 // Check the second facebook form is gone. |
| 1867 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items)); | 1869 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form), |
| 1870 &matching_items)); |
| 1868 EXPECT_EQ(0u, matching_items.size()); | 1871 EXPECT_EQ(0u, matching_items.size()); |
| 1869 | 1872 |
| 1870 // Check the first facebook form is still there. | 1873 // Check the first facebook form is still there. |
| 1871 matching_items = owned_keychain_adapter.PasswordsFillingForm( | 1874 matching_items = owned_keychain_adapter.PasswordsFillingForm( |
| 1872 www_form->signon_realm, www_form->scheme); | 1875 www_form->signon_realm, www_form->scheme); |
| 1873 ASSERT_EQ(1u, matching_items.size()); | 1876 ASSERT_EQ(1u, matching_items.size()); |
| 1874 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | 1877 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
| 1875 | 1878 |
| 1876 // Check the third-party password is still there. | 1879 // Check the third-party password is still there. |
| 1877 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | 1880 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 m_form.signon_realm = "http://m.facebook.com"; | 1913 m_form.signon_realm = "http://m.facebook.com"; |
| 1911 m_form.origin = GURL("http://m.facebook.com/index.html"); | 1914 m_form.origin = GURL("http://m.facebook.com/index.html"); |
| 1912 | 1915 |
| 1913 MockPasswordStoreConsumer consumer; | 1916 MockPasswordStoreConsumer consumer; |
| 1914 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) | 1917 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
| 1915 .WillByDefault(QuitUIMessageLoop()); | 1918 .WillByDefault(QuitUIMessageLoop()); |
| 1916 EXPECT_CALL(mock_observer, OnLoginsChanged(_)).Times(0); | 1919 EXPECT_CALL(mock_observer, OnLoginsChanged(_)).Times(0); |
| 1917 // The PSL-matched form isn't returned because there is no actual password in | 1920 // The PSL-matched form isn't returned because there is no actual password in |
| 1918 // the keychain. | 1921 // the keychain. |
| 1919 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 1922 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
| 1920 store_->GetLogins(m_form, &consumer); | 1923 store_->GetLogins(PasswordStore::FormDigest(m_form), &consumer); |
| 1921 base::RunLoop().Run(); | 1924 base::RunLoop().Run(); |
| 1922 ScopedVector<autofill::PasswordForm> all_forms; | 1925 ScopedVector<autofill::PasswordForm> all_forms; |
| 1923 EXPECT_TRUE(login_db()->GetAutofillableLogins(&all_forms)); | 1926 EXPECT_TRUE(login_db()->GetAutofillableLogins(&all_forms)); |
| 1924 EXPECT_EQ(1u, all_forms.size()); | 1927 EXPECT_EQ(1u, all_forms.size()); |
| 1925 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | 1928 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); |
| 1926 | 1929 |
| 1927 // 3. Get a password for www.facebook.com. The form is implicitly removed and | 1930 // 3. Get a password for www.facebook.com. The form is implicitly removed and |
| 1928 // the observer is notified. | 1931 // the observer is notified. |
| 1929 password_manager::PasswordStoreChangeList list; | 1932 password_manager::PasswordStoreChangeList list; |
| 1930 list.push_back(password_manager::PasswordStoreChange( | 1933 list.push_back(password_manager::PasswordStoreChange( |
| 1931 password_manager::PasswordStoreChange::REMOVE, *www_form)); | 1934 password_manager::PasswordStoreChange::REMOVE, *www_form)); |
| 1932 EXPECT_CALL(mock_observer, OnLoginsChanged(list)); | 1935 EXPECT_CALL(mock_observer, OnLoginsChanged(list)); |
| 1933 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); | 1936 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
| 1934 store_->GetLogins(*www_form, &consumer); | 1937 store_->GetLogins(PasswordStore::FormDigest(*www_form), &consumer); |
| 1935 base::RunLoop().Run(); | 1938 base::RunLoop().Run(); |
| 1936 EXPECT_TRUE(login_db()->GetAutofillableLogins(&all_forms)); | 1939 EXPECT_TRUE(login_db()->GetAutofillableLogins(&all_forms)); |
| 1937 EXPECT_EQ(0u, all_forms.size()); | 1940 EXPECT_EQ(0u, all_forms.size()); |
| 1938 } | 1941 } |
| 1939 | 1942 |
| 1940 // Verify that Android app passwords can be stored, retrieved, and deleted. | 1943 // Verify that Android app passwords can be stored, retrieved, and deleted. |
| 1941 // Regression test for http://crbug.com/455551 | 1944 // Regression test for http://crbug.com/455551 |
| 1942 TEST_F(PasswordStoreMacTest, StoringAndRetrievingAndroidCredentials) { | 1945 TEST_F(PasswordStoreMacTest, StoringAndRetrievingAndroidCredentials) { |
| 1943 PasswordForm form; | 1946 PasswordForm form; |
| 1944 form.signon_realm = "android://7x7IDboo8u9YKraUsbmVkuf1@net.rateflix.app/"; | 1947 form.signon_realm = "android://7x7IDboo8u9YKraUsbmVkuf1@net.rateflix.app/"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1991 FinishAsyncProcessing(); | 1994 FinishAsyncProcessing(); |
| 1992 | 1995 |
| 1993 ASSERT_TRUE(base::PostTaskAndReplyWithResult( | 1996 ASSERT_TRUE(base::PostTaskAndReplyWithResult( |
| 1994 thread_->task_runner().get(), FROM_HERE, | 1997 thread_->task_runner().get(), FROM_HERE, |
| 1995 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), | 1998 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), |
| 1996 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); | 1999 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); |
| 1997 FinishAsyncProcessing(); | 2000 FinishAsyncProcessing(); |
| 1998 | 2001 |
| 1999 // The password should be stored in the database by now. | 2002 // The password should be stored in the database by now. |
| 2000 ScopedVector<PasswordForm> matching_items; | 2003 ScopedVector<PasswordForm> matching_items; |
| 2001 EXPECT_TRUE(login_db()->GetLogins(form1, &matching_items)); | 2004 EXPECT_TRUE( |
| 2005 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items)); |
| 2002 ASSERT_EQ(1u, matching_items.size()); | 2006 ASSERT_EQ(1u, matching_items.size()); |
| 2003 EXPECT_EQ(form1, *matching_items[0]); | 2007 EXPECT_EQ(form1, *matching_items[0]); |
| 2004 | 2008 |
| 2005 EXPECT_TRUE(login_db()->GetLogins(form2, &matching_items)); | 2009 EXPECT_TRUE( |
| 2010 login_db()->GetLogins(PasswordStore::FormDigest(form2), &matching_items)); |
| 2006 ASSERT_EQ(1u, matching_items.size()); | 2011 ASSERT_EQ(1u, matching_items.size()); |
| 2007 EXPECT_EQ(form2, *matching_items[0]); | 2012 EXPECT_EQ(form2, *matching_items[0]); |
| 2008 | 2013 |
| 2009 EXPECT_TRUE(login_db()->GetLogins(blacklisted_form, &matching_items)); | 2014 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(blacklisted_form), |
| 2015 &matching_items)); |
| 2010 ASSERT_EQ(1u, matching_items.size()); | 2016 ASSERT_EQ(1u, matching_items.size()); |
| 2011 EXPECT_EQ(blacklisted_form, *matching_items[0]); | 2017 EXPECT_EQ(blacklisted_form, *matching_items[0]); |
| 2012 | 2018 |
| 2013 // The passwords are encrypted using a key from the Keychain. | 2019 // The passwords are encrypted using a key from the Keychain. |
| 2014 EXPECT_TRUE( | 2020 EXPECT_TRUE( |
| 2015 histogram_tester_->GetHistogramSamplesSinceCreation("OSX.Keychain.Access") | 2021 histogram_tester_->GetHistogramSamplesSinceCreation("OSX.Keychain.Access") |
| 2016 ->TotalCount()); | 2022 ->TotalCount()); |
| 2017 histogram_tester_.reset(); | 2023 histogram_tester_.reset(); |
| 2018 } | 2024 } |
| 2019 | 2025 |
| 2020 // Import a federated credential while the Keychain is locked. | 2026 // Import a federated credential while the Keychain is locked. |
| 2021 TEST_F(PasswordStoreMacTest, ImportFederatedFromLockedKeychain) { | 2027 TEST_F(PasswordStoreMacTest, ImportFederatedFromLockedKeychain) { |
| 2022 keychain()->set_locked(true); | 2028 keychain()->set_locked(true); |
| 2023 PasswordForm form1; | 2029 PasswordForm form1; |
| 2024 form1.origin = GURL("http://example.com/Login"); | 2030 form1.origin = GURL("http://example.com/Login"); |
| 2025 form1.signon_realm = "http://example.com/"; | 2031 form1.signon_realm = "http://example.com/"; |
| 2026 form1.username_value = ASCIIToUTF16("my_username"); | 2032 form1.username_value = ASCIIToUTF16("my_username"); |
| 2027 form1.federation_origin = url::Origin(GURL("https://accounts.google.com/")); | 2033 form1.federation_origin = url::Origin(GURL("https://accounts.google.com/")); |
| 2028 | 2034 |
| 2029 store()->AddLogin(form1); | 2035 store()->AddLogin(form1); |
| 2030 FinishAsyncProcessing(); | 2036 FinishAsyncProcessing(); |
| 2031 ASSERT_TRUE(base::PostTaskAndReplyWithResult( | 2037 ASSERT_TRUE(base::PostTaskAndReplyWithResult( |
| 2032 thread_->task_runner().get(), FROM_HERE, | 2038 thread_->task_runner().get(), FROM_HERE, |
| 2033 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), | 2039 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), |
| 2034 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); | 2040 base::Bind(&CheckMigrationResult, PasswordStoreMac::MIGRATION_OK))); |
| 2035 FinishAsyncProcessing(); | 2041 FinishAsyncProcessing(); |
| 2036 | 2042 |
| 2037 ScopedVector<PasswordForm> matching_items; | 2043 ScopedVector<PasswordForm> matching_items; |
| 2038 EXPECT_TRUE(login_db()->GetLogins(form1, &matching_items)); | 2044 EXPECT_TRUE( |
| 2045 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items)); |
| 2039 ASSERT_EQ(1u, matching_items.size()); | 2046 ASSERT_EQ(1u, matching_items.size()); |
| 2040 EXPECT_EQ(form1, *matching_items[0]); | 2047 EXPECT_EQ(form1, *matching_items[0]); |
| 2041 } | 2048 } |
| 2042 | 2049 |
| 2043 // Try to import while the Keychain is locked but the encryption key had been | 2050 // Try to import while the Keychain is locked but the encryption key had been |
| 2044 // read earlier. | 2051 // read earlier. |
| 2045 TEST_F(PasswordStoreMacTest, ImportFromLockedKeychainError) { | 2052 TEST_F(PasswordStoreMacTest, ImportFromLockedKeychainError) { |
| 2046 PasswordForm form1; | 2053 PasswordForm form1; |
| 2047 form1.origin = GURL("http://accounts.google.com/LoginAuth"); | 2054 form1.origin = GURL("http://accounts.google.com/LoginAuth"); |
| 2048 form1.signon_realm = "http://accounts.google.com/"; | 2055 form1.signon_realm = "http://accounts.google.com/"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2059 EXPECT_TRUE(adapter.AddPassword(form2)); | 2066 EXPECT_TRUE(adapter.AddPassword(form2)); |
| 2060 | 2067 |
| 2061 keychain()->set_locked(true); | 2068 keychain()->set_locked(true); |
| 2062 ASSERT_TRUE(base::PostTaskAndReplyWithResult( | 2069 ASSERT_TRUE(base::PostTaskAndReplyWithResult( |
| 2063 thread_->task_runner().get(), FROM_HERE, | 2070 thread_->task_runner().get(), FROM_HERE, |
| 2064 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), | 2071 base::Bind(&PasswordStoreMac::ImportFromKeychain, store()), |
| 2065 base::Bind(&CheckMigrationResult, PasswordStoreMac::KEYCHAIN_BLOCKED))); | 2072 base::Bind(&CheckMigrationResult, PasswordStoreMac::KEYCHAIN_BLOCKED))); |
| 2066 FinishAsyncProcessing(); | 2073 FinishAsyncProcessing(); |
| 2067 | 2074 |
| 2068 ScopedVector<PasswordForm> matching_items; | 2075 ScopedVector<PasswordForm> matching_items; |
| 2069 EXPECT_TRUE(login_db()->GetLogins(form1, &matching_items)); | 2076 EXPECT_TRUE( |
| 2077 login_db()->GetLogins(PasswordStore::FormDigest(form1), &matching_items)); |
| 2070 ASSERT_EQ(1u, matching_items.size()); | 2078 ASSERT_EQ(1u, matching_items.size()); |
| 2071 EXPECT_EQ(base::string16(), matching_items[0]->password_value); | 2079 EXPECT_EQ(base::string16(), matching_items[0]->password_value); |
| 2072 | 2080 |
| 2073 histogram_tester_->ExpectUniqueSample( | 2081 histogram_tester_->ExpectUniqueSample( |
| 2074 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1); | 2082 "PasswordManager.KeychainMigration.NumPasswordsOnFailure", 1, 1); |
| 2075 histogram_tester_->ExpectUniqueSample( | 2083 histogram_tester_->ExpectUniqueSample( |
| 2076 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1); | 2084 "PasswordManager.KeychainMigration.NumFailedPasswords", 1, 1); |
| 2077 histogram_tester_->ExpectUniqueSample( | 2085 histogram_tester_->ExpectUniqueSample( |
| 2078 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords", | 2086 "PasswordManager.KeychainMigration.NumChromeOwnedInaccessiblePasswords", |
| 2079 2, 1); | 2087 2, 1); |
| 2080 // Don't test the encryption key access. | 2088 // Don't test the encryption key access. |
| 2081 histogram_tester_.reset(); | 2089 histogram_tester_.reset(); |
| 2082 } | 2090 } |
| OLD | NEW |