Chromium Code Reviews| Index: chrome/browser/password_manager/password_store_mac_unittest.cc |
| diff --git a/chrome/browser/password_manager/password_store_mac_unittest.cc b/chrome/browser/password_manager/password_store_mac_unittest.cc |
| index 5625b9ed610b996937b5573413123a3234a6625f..329d6975579a10faa1ce48c6b82a6e0342f7def6 100644 |
| --- a/chrome/browser/password_manager/password_store_mac_unittest.cc |
| +++ b/chrome/browser/password_manager/password_store_mac_unittest.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/basictypes.h" |
| #include "base/files/scoped_temp_dir.h" |
| +#include "base/memory/scoped_vector.h" |
| #include "base/path_service.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string_util.h" |
| @@ -1079,15 +1080,19 @@ class PasswordStoreMacTest : public testing::Test { |
| EXPECT_FALSE(store_->GetBackgroundTaskRunner()); |
| } |
| - void WaitForStoreUpdate() { |
| + void WaitForStoreUpdate(scoped_refptr<TestPasswordStoreMac> store) { |
|
vabr (Chromium)
2014/07/02 07:41:49
It looks like you always call this with |store_|,
vasilii
2014/07/02 12:34:03
Done.
|
| // Do a store-level query to wait for all the operations above to be done. |
| MockPasswordStoreConsumer consumer; |
| EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) |
| .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); |
| - store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); |
| + store->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); |
| base::MessageLoop::current()->Run(); |
| } |
| + void WaitForStoreUpdate() { |
| + return WaitForStoreUpdate(store_); |
| + } |
| + |
| protected: |
| base::MessageLoopForUI message_loop_; |
| content::TestBrowserThread ui_thread_; |
| @@ -1254,3 +1259,59 @@ TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { |
| login_db_->GetLogins(m_form, &matching_items); |
| EXPECT_EQ(0u, matching_items.size()); |
| } |
| + |
| +TEST_F(PasswordStoreMacTest, TestRemoveLoginsCreatedBetween) { |
| + // Make sure that RemoveLoginsCreatedBetween does affect only the correct |
| + // profile. |
| + |
| + // Add a third-party password. |
| + MockAppleKeychain::KeychainTestData joint_keychain_data = { |
| + kSecAuthenticationTypeHTMLForm, "some.domain.com", |
| + kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", |
| + "joe_user", "sekrit", false }; |
| + keychain_->AddTestItem(joint_keychain_data); |
| + |
| + // Add a password from another profile. |
| + MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); |
| + owned_keychain_adapter.SetFindsOnlyOwnedItems(true); |
| + PasswordFormData www_form_data1 = { |
| + PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| + "http://www.facebook.com/index.html", "login", L"username", L"password", |
| + L"submit", L"joe_user", L"sekrit", true, false, 1 }; |
| + scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data1)); |
| + EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form)); |
| + |
| + // Add a password from the current profile. |
| + PasswordFormData www_form_data2 = { |
| + PasswordForm::SCHEME_HTML, "http://www.facebook.com/", |
| + "http://www.facebook.com/index.html", "login", L"username", L"password", |
| + L"submit", L"not_joe_user", L"12345", true, false, 1 }; |
| + www_form.reset(CreatePasswordFormFromData(www_form_data2)); |
| + store_->AddLogin(*www_form); |
| + WaitForStoreUpdate(); |
| + |
| + ScopedVector<PasswordForm> matching_items; |
| + login_db_->GetLogins(*www_form, &matching_items.get()); |
| + EXPECT_EQ(1u, matching_items.size()); |
| + matching_items.clear(); |
| + |
| + store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); |
| + WaitForStoreUpdate(); |
| + |
| + // Check the second facebook form is gone. |
| + login_db_->GetLogins(*www_form, &matching_items.get()); |
| + EXPECT_EQ(0u, matching_items.size()); |
| + |
| + // Check the first facebook form is still there. |
| + matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( |
| + www_form->signon_realm, www_form->scheme); |
| + ASSERT_EQ(1u, matching_items.size()); |
| + EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); |
| + matching_items.clear(); |
| + |
| + // Check the third-party password is still there. |
| + owned_keychain_adapter.SetFindsOnlyOwnedItems(false); |
| + matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( |
| + "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); |
| + ASSERT_EQ(1u, matching_items.size()); |
| +} |