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 "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 Loading... | |
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 Loading... | |
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 | |
1293 // Remove form_facebook. | |
1294 void (PasswordStore::*method)(base::Time, base::Time) = | |
1295 check_created ? &PasswordStore::RemoveLoginsCreatedBetween | |
1296 : &PasswordStore::RemoveLoginsSyncedBetween; | |
1297 (test->store()->*method)(base::Time(), next_day); | |
1298 test->WaitForStoreUpdate(); | |
1299 | |
1300 MacKeychainPasswordFormAdapter owned_keychain_adapter(test->keychain()); | |
1301 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | |
1302 ScopedVector<PasswordForm> matching_items; | |
1303 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | |
vabr (Chromium)
2014/07/02 13:15:55
optional nit: Consider doing these 2 checks (or at
vasilii
2014/07/02 14:02:58
Done.
| |
1304 form_facebook->signon_realm, form_facebook->scheme); | |
1305 EXPECT_EQ(0u, matching_items.size()); | |
1306 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | |
1307 form_other->signon_realm, form_other->scheme); | |
1308 EXPECT_EQ(1u, matching_items.size()); | |
1309 matching_items.clear(); | |
1310 | |
1311 // Remove form_facebook. | |
1312 (test->store()->*method)(next_day, base::Time()); | |
1313 test->WaitForStoreUpdate(); | |
1314 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | |
1315 form_other->signon_realm, form_other->scheme); | |
1316 EXPECT_EQ(0u, matching_items.size()); | |
1317 } | |
1318 | |
1319 } // namespace | |
1320 | |
1321 TEST_F(PasswordStoreMacTest, TestRemoveLoginsCreatedBetween) { | |
1322 CheckRemoveLoginsBetween(this, true); | |
1323 } | |
1324 | |
1325 TEST_F(PasswordStoreMacTest, TestRemoveLoginsSyncedBetween) { | |
1326 CheckRemoveLoginsBetween(this, false); | |
1327 } | |
1328 | |
1329 TEST_F(PasswordStoreMacTest, TestRemoveLoginsMultiProfile) { | |
1330 // Make sure that RemoveLoginsCreatedBetween does affect only the correct | |
1331 // profile. | |
1332 | |
1333 // Add a third-party password. | |
1334 MockAppleKeychain::KeychainTestData keychain_data = { | |
1335 kSecAuthenticationTypeHTMLForm, "some.domain.com", | |
1336 kSecProtocolTypeHTTP, "/insecure.html", 0, NULL, "20020601171500Z", | |
1337 "joe_user", "sekrit", false }; | |
1338 keychain_->AddTestItem(keychain_data); | |
1339 | |
1340 // Add a password from another profile. | |
vabr (Chromium)
2014/07/02 13:15:55
optional nit: Indicate that "from another profile"
vasilii
2014/07/02 14:02:58
Done.
| |
1341 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); | |
1342 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); | |
1343 PasswordFormData www_form_data1 = { | |
1344 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | |
1345 "http://www.facebook.com/index.html", "login", L"username", L"password", | |
1346 L"submit", L"joe_user", L"sekrit", true, false, 1 }; | |
1347 scoped_ptr<PasswordForm> www_form(CreatePasswordFormFromData(www_form_data1)); | |
1348 EXPECT_TRUE(owned_keychain_adapter.AddPassword(*www_form)); | |
1349 | |
1350 // Add a password from the current profile. | |
1351 PasswordFormData www_form_data2 = { | |
1352 PasswordForm::SCHEME_HTML, "http://www.facebook.com/", | |
1353 "http://www.facebook.com/index.html", "login", L"username", L"password", | |
1354 L"submit", L"not_joe_user", L"12345", true, false, 1 }; | |
1355 www_form.reset(CreatePasswordFormFromData(www_form_data2)); | |
1356 store_->AddLogin(*www_form); | |
1357 WaitForStoreUpdate(); | |
1358 | |
1359 ScopedVector<PasswordForm> matching_items; | |
1360 login_db_->GetLogins(*www_form, &matching_items.get()); | |
1361 EXPECT_EQ(1u, matching_items.size()); | |
1362 matching_items.clear(); | |
1363 | |
1364 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time()); | |
1365 WaitForStoreUpdate(); | |
1366 | |
1367 // Check the second facebook form is gone. | |
1368 login_db_->GetLogins(*www_form, &matching_items.get()); | |
1369 EXPECT_EQ(0u, matching_items.size()); | |
1370 | |
1371 // Check the first facebook form is still there. | |
1372 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | |
1373 www_form->signon_realm, www_form->scheme); | |
1374 ASSERT_EQ(1u, matching_items.size()); | |
1375 EXPECT_EQ(ASCIIToUTF16("joe_user"), matching_items[0]->username_value); | |
1376 matching_items.clear(); | |
1377 | |
1378 // Check the third-party password is still there. | |
1379 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); | |
1380 matching_items.get() = owned_keychain_adapter.PasswordsFillingForm( | |
1381 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); | |
1382 ASSERT_EQ(1u, matching_items.size()); | |
1383 } | |
OLD | NEW |