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

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

Issue 360343002: PasswordStoreMac::RemoveLoginsCreatedBetween() shouldn't affect other profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove GetUnusedKeychainForms() + typos Created 6 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 | Annotate | Revision Log
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 "testing/gmock/include/gmock/gmock.h" 5 #include "testing/gmock/include/gmock/gmock.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_vector.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/password_manager/password_store_mac.h" 15 #include "chrome/browser/password_manager/password_store_mac.h"
15 #include "chrome/browser/password_manager/password_store_mac_internal.h" 16 #include "chrome/browser/password_manager/password_store_mac_internal.h"
16 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
17 #include "components/password_manager/core/browser/password_store_consumer.h" 18 #include "components/password_manager/core/browser/password_store_consumer.h"
18 #include "content/public/test/test_browser_thread.h" 19 #include "content/public/test/test_browser_thread.h"
19 #include "crypto/mock_apple_keychain.h" 20 #include "crypto/mock_apple_keychain.h"
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1082
1082 void WaitForStoreUpdate() { 1083 void WaitForStoreUpdate() {
1083 // Do a store-level query to wait for all the operations above to be done. 1084 // Do a store-level query to wait for all the operations above to be done.
1084 MockPasswordStoreConsumer consumer; 1085 MockPasswordStoreConsumer consumer;
1085 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_)) 1086 EXPECT_CALL(consumer, OnGetPasswordStoreResults(_))
1086 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); 1087 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop()));
1087 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer); 1088 store_->GetLogins(PasswordForm(), PasswordStore::ALLOW_PROMPT, &consumer);
1088 base::MessageLoop::current()->Run(); 1089 base::MessageLoop::current()->Run();
1089 } 1090 }
1090 1091
1092 scoped_refptr<TestPasswordStoreMac> store() { return store_; }
1093
1094 MockAppleKeychain* keychain() { return keychain_; }
1095
1091 protected: 1096 protected:
1092 base::MessageLoopForUI message_loop_; 1097 base::MessageLoopForUI message_loop_;
1093 content::TestBrowserThread ui_thread_; 1098 content::TestBrowserThread ui_thread_;
1094 1099
1095 MockAppleKeychain* keychain_; // Owned by store_. 1100 MockAppleKeychain* keychain_; // Owned by store_.
1096 LoginDatabase* login_db_; // Owned by store_. 1101 LoginDatabase* login_db_; // Owned by store_.
1097 scoped_refptr<TestPasswordStoreMac> store_; 1102 scoped_refptr<TestPasswordStoreMac> store_;
1098 base::ScopedTempDir db_dir_; 1103 base::ScopedTempDir db_dir_;
1099 }; 1104 };
1100 1105
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 EXPECT_EQ(0u, matching_items.size()); 1252 EXPECT_EQ(0u, matching_items.size());
1248 login_db_->GetLogins(*www_form, &matching_items); 1253 login_db_->GetLogins(*www_form, &matching_items);
1249 EXPECT_EQ(0u, matching_items.size()); 1254 EXPECT_EQ(0u, matching_items.size());
1250 // No trace of m.facebook.com. 1255 // No trace of m.facebook.com.
1251 matching_items = owned_keychain_adapter.PasswordsFillingForm( 1256 matching_items = owned_keychain_adapter.PasswordsFillingForm(
1252 m_form.signon_realm, m_form.scheme); 1257 m_form.signon_realm, m_form.scheme);
1253 EXPECT_EQ(0u, matching_items.size()); 1258 EXPECT_EQ(0u, matching_items.size());
1254 login_db_->GetLogins(m_form, &matching_items); 1259 login_db_->GetLogins(m_form, &matching_items);
1255 EXPECT_EQ(0u, matching_items.size()); 1260 EXPECT_EQ(0u, matching_items.size());
1256 } 1261 }
1262
1263 namespace {
1264
1265 // Tests RemoveLoginsCreatedBetween or RemoveLoginsSyncedBetween depending on
1266 // |check_created|.
1267 void CheckRemoveLoginsBetween(PasswordStoreMacTest* test, bool check_created) {
1268 PasswordFormData www_form_data1 = {
1269 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1270 "http://www.facebook.com/index.html", "login", L"username", L"password",
1271 L"submit", L"joe_user", L"sekrit", true, false, 0 };
1272 PasswordFormData www_form_data2 = {
1273 PasswordForm::SCHEME_HTML, "http://different.com/",
1274 "http://different.com/index.html", "login", L"username", L"password",
1275 L"submit", L"different_joe_user", L"sekrit", true, false, 0 };
1276 scoped_ptr<PasswordForm> form_facebook(
1277 CreatePasswordFormFromData(www_form_data1));
1278 scoped_ptr<PasswordForm> form_other(
1279 CreatePasswordFormFromData(www_form_data2));
1280 base::Time now = base::Time::Now();
1281 base::Time next_day = now + base::TimeDelta::FromDays(1);
1282 if (check_created) {
1283 form_facebook->date_created = now;
1284 form_other->date_created = next_day;
1285 } else {
1286 form_facebook->date_synced = now;
1287 form_other->date_synced = next_day;
1288 }
1289
1290 test->store()->AddLogin(*form_facebook);
1291 test->store()->AddLogin(*form_other);
1292 test->WaitForStoreUpdate();
1293
1294 MacKeychainPasswordFormAdapter owned_keychain_adapter(test->keychain());
1295 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1296 ScopedVector<PasswordForm> matching_items;
1297 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1298 form_facebook->signon_realm, form_facebook->scheme);
1299 EXPECT_EQ(1u, matching_items.size());
1300 matching_items.clear();
1301 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1302 form_other->signon_realm, form_other->scheme);
1303 EXPECT_EQ(1u, matching_items.size());
1304 matching_items.clear();
1305
1306 // Remove form_facebook.
1307 void (PasswordStore::*method)(base::Time, base::Time) =
1308 check_created ? &PasswordStore::RemoveLoginsCreatedBetween
1309 : &PasswordStore::RemoveLoginsSyncedBetween;
1310 (test->store()->*method)(base::Time(), next_day);
1311 test->WaitForStoreUpdate();
1312
1313 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1314 form_facebook->signon_realm, form_facebook->scheme);
1315 EXPECT_EQ(0u, matching_items.size());
1316 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1317 form_other->signon_realm, form_other->scheme);
1318 EXPECT_EQ(1u, matching_items.size());
1319 matching_items.clear();
1320
1321 // Remove form_facebook.
1322 (test->store()->*method)(next_day, base::Time());
1323 test->WaitForStoreUpdate();
1324 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1325 form_other->signon_realm, form_other->scheme);
1326 EXPECT_EQ(0u, matching_items.size());
1327 }
1328
1329 } // namespace
1330
1331 TEST_F(PasswordStoreMacTest, TestRemoveLoginsCreatedBetween) {
1332 CheckRemoveLoginsBetween(this, true);
1333 }
1334
1335 TEST_F(PasswordStoreMacTest, TestRemoveLoginsSyncedBetween) {
1336 CheckRemoveLoginsBetween(this, false);
1337 }
1338
1339 TEST_F(PasswordStoreMacTest, TestRemoveLoginsMultiProfile) {
1340 // Make sure that RemoveLoginsCreatedBetween does affect only the correct
1341 // profile.
1342
1343 // Add a third-party password.
1344 MockAppleKeychain::KeychainTestData keychain_data = {
1345 kSecAuthenticationTypeHTMLForm, "some.domain.com",
1346 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z",
1347 "joe_user", "sekrit", false };
1348 keychain_->AddTestItem(keychain_data);
1349
1350 // Add a password through the adapter. It has the "Chrome" creator tag.
1351 // However, it's not referenced by the password database.
1352 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_);
1353 owned_keychain_adapter.SetFindsOnlyOwnedItems(true);
1354 PasswordFormData www_form_data1 = {
1355 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1356 "http://www.facebook.com/index.html", "login", L"username", L"password",
1357 L"submit", L"joe_user", L"sekrit", true, false, 1 };
1358 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data1));
1359 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form));
1360
1361 // Add a password from the current profile.
1362 PasswordFormData www_form_data2 = {
1363 PasswordForm::SCHEME_HTML, "http://www.facebook.com/",
1364 "http://www.facebook.com/index.html", "login", L"username", L"password",
1365 L"submit", L"not_joe_user", L"12345", true, false, 1 };
1366 www_form.reset(CreatePasswordFormFromData(www_form_data2));
1367 store_->AddLogin(*www_form);
1368 WaitForStoreUpdate();
1369
1370 ScopedVector<PasswordForm> matching_items;
1371 login_db_->GetLogins(*www_form, &matching_items.get());
1372 EXPECT_EQ(1u, matching_items.size());
1373 matching_items.clear();
1374
1375 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time());
1376 WaitForStoreUpdate();
1377
1378 // Check the second facebook form is gone.
1379 login_db_->GetLogins(*www_form, &matching_items.get());
1380 EXPECT_EQ(0u, matching_items.size());
1381
1382 // Check the first facebook form is still there.
1383 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1384 www_form->signon_realm, www_form->scheme);
1385 ASSERT_EQ(1u, matching_items.size());
1386 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value);
1387 matching_items.clear();
1388
1389 // Check the third-party password is still there.
1390 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1391 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm(
1392 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML);
1393 ASSERT_EQ(1u, matching_items.size());
1394 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | components/password_manager/core/browser/login_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698