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

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

Issue 906973007: PasswordStore: Clean up expectations about rewriting vectors of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed, except for dropping clear() (yet) Created 5 years, 9 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"
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 if (updates[i].password) { 1242 if (updates[i].password) {
1243 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i; 1243 EXPECT_GT(matching_items.size(), 0U) << "iteration " << i;
1244 if (matching_items.size() >= 1) 1244 if (matching_items.size() >= 1)
1245 EXPECT_EQ(ASCIIToUTF16(updates[i].password), 1245 EXPECT_EQ(ASCIIToUTF16(updates[i].password),
1246 matching_items[0]->password_value) << "iteration " << i; 1246 matching_items[0]->password_value) << "iteration " << i;
1247 } else { 1247 } else {
1248 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i; 1248 EXPECT_EQ(0U, matching_items.size()) << "iteration " << i;
1249 } 1249 }
1250 matching_items.clear(); 1250 matching_items.clear();
1251 1251
1252 login_db()->GetLogins(*query_form, &matching_items); 1252 EXPECT_TRUE(login_db()->GetLogins(*query_form, &matching_items));
1253 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size()) 1253 EXPECT_EQ(updates[i].password ? 1U : 0U, matching_items.size())
1254 << "iteration " << i; 1254 << "iteration " << i;
1255 } 1255 }
1256 } 1256 }
1257 1257
1258 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) { 1258 TEST_F(PasswordStoreMacTest, TestDBKeychainAssociation) {
1259 // Tests that association between the keychain and login database parts of a 1259 // Tests that association between the keychain and login database parts of a
1260 // password added by fuzzy (PSL) matching works. 1260 // password added by fuzzy (PSL) matching works.
1261 // 1. Add a password for www.facebook.com 1261 // 1. Add a password for www.facebook.com
1262 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the 1262 // 2. Get a password for m.facebook.com. This fuzzy matches and returns the
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 // 4. Remove both passwords. 1305 // 4. Remove both passwords.
1306 store_->RemoveLogin(*www_form); 1306 store_->RemoveLogin(*www_form);
1307 store_->RemoveLogin(m_form); 1307 store_->RemoveLogin(m_form);
1308 FinishAsyncProcessing(); 1308 FinishAsyncProcessing();
1309 1309
1310 // No trace of www.facebook.com. 1310 // No trace of www.facebook.com.
1311 ScopedVector<autofill::PasswordForm> matching_items = 1311 ScopedVector<autofill::PasswordForm> matching_items =
1312 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, 1312 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm,
1313 www_form->scheme); 1313 www_form->scheme);
1314 EXPECT_EQ(0u, matching_items.size()); 1314 EXPECT_EQ(0u, matching_items.size());
1315 login_db()->GetLogins(*www_form, &matching_items); 1315 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items));
1316 EXPECT_EQ(0u, matching_items.size()); 1316 EXPECT_EQ(0u, matching_items.size());
1317 // No trace of m.facebook.com. 1317 // No trace of m.facebook.com.
1318 matching_items = owned_keychain_adapter.PasswordsFillingForm( 1318 matching_items = owned_keychain_adapter.PasswordsFillingForm(
1319 m_form.signon_realm, m_form.scheme); 1319 m_form.signon_realm, m_form.scheme);
1320 EXPECT_EQ(0u, matching_items.size()); 1320 EXPECT_EQ(0u, matching_items.size());
1321 login_db()->GetLogins(m_form, &matching_items); 1321 EXPECT_TRUE(login_db()->GetLogins(m_form, &matching_items));
1322 EXPECT_EQ(0u, matching_items.size()); 1322 EXPECT_EQ(0u, matching_items.size());
1323 } 1323 }
1324 1324
1325 namespace { 1325 namespace {
1326 1326
1327 class PasswordsChangeObserver : 1327 class PasswordsChangeObserver :
1328 public password_manager::PasswordStore::Observer { 1328 public password_manager::PasswordStore::Observer {
1329 public: 1329 public:
1330 PasswordsChangeObserver(TestPasswordStoreMac* store) : observer_(this) { 1330 PasswordsChangeObserver(TestPasswordStoreMac* store) : observer_(this) {
1331 observer_.Add(store); 1331 observer_.Add(store);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 // Add a password from the current profile. 1479 // Add a password from the current profile.
1480 PasswordFormData www_form_data2 = { 1480 PasswordFormData www_form_data2 = {
1481 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", 1481 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1482 "http://www.facebook.com/index.html", "login", L"username", L"password", 1482 "http://www.facebook.com/index.html", "login", L"username", L"password",
1483 L"submit", L"not_joe_user", L"12345", true, false, 1 }; 1483 L"submit", L"not_joe_user", L"12345", true, false, 1 };
1484 www_form = CreatePasswordFormFromDataForTesting(www_form_data2); 1484 www_form = CreatePasswordFormFromDataForTesting(www_form_data2);
1485 store_->AddLogin(*www_form); 1485 store_->AddLogin(*www_form);
1486 FinishAsyncProcessing(); 1486 FinishAsyncProcessing();
1487 1487
1488 ScopedVector<PasswordForm> matching_items; 1488 ScopedVector<PasswordForm> matching_items;
1489 login_db()->GetLogins(*www_form, &matching_items); 1489 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items));
1490 EXPECT_EQ(1u, matching_items.size()); 1490 EXPECT_EQ(1u, matching_items.size());
1491 matching_items.clear(); 1491 matching_items.clear();
1492 1492
1493 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); 1493 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time());
1494 FinishAsyncProcessing(); 1494 FinishAsyncProcessing();
1495 1495
1496 // Check the second facebook form is gone. 1496 // Check the second facebook form is gone.
1497 login_db()->GetLogins(*www_form, &matching_items); 1497 EXPECT_TRUE(login_db()->GetLogins(*www_form, &matching_items));
1498 EXPECT_EQ(0u, matching_items.size()); 1498 EXPECT_EQ(0u, matching_items.size());
1499 1499
1500 // Check the first facebook form is still there. 1500 // Check the first facebook form is still there.
1501 matching_items = owned_keychain_adapter.PasswordsFillingForm( 1501 matching_items = owned_keychain_adapter.PasswordsFillingForm(
1502 www_form->signon_realm, www_form->scheme); 1502 www_form->signon_realm, www_form->scheme);
1503 ASSERT_EQ(1u, matching_items.size()); 1503 ASSERT_EQ(1u, matching_items.size());
1504 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); 1504 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value);
1505 matching_items.clear(); 1505 matching_items.clear();
1506 1506
1507 // Check the third-party password is still there. 1507 // Check the third-party password is still there.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 query_form.password_value.clear(); 1682 query_form.password_value.clear();
1683 query_form.username_value.clear(); 1683 query_form.username_value.clear();
1684 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u))) 1684 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResultsConstRef(SizeIs(1u)))
1685 .WillOnce( 1685 .WillOnce(
1686 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop())); 1686 DoAll(SaveACopyOfFirstForm(&returned_form), QuitUIMessageLoop()));
1687 store()->GetLogins(query_form, PasswordStore::ALLOW_PROMPT, &mock_consumer); 1687 store()->GetLogins(query_form, PasswordStore::ALLOW_PROMPT, &mock_consumer);
1688 base::MessageLoop::current()->Run(); 1688 base::MessageLoop::current()->Run();
1689 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer); 1689 ::testing::Mock::VerifyAndClearExpectations(&mock_consumer);
1690 EXPECT_EQ(form, returned_form); 1690 EXPECT_EQ(form, returned_form);
1691 } 1691 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698