| 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <stddef.h> | 6 #include <stddef.h> |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 base::Unretained(&backend), | 534 base::Unretained(&backend), |
| 535 credentials)); | 535 credentials)); |
| 536 | 536 |
| 537 PasswordStore::FormDigest target_form = {scheme, url.spec(), url}; | 537 PasswordStore::FormDigest target_form = {scheme, url.spec(), url}; |
| 538 if (scheme != PasswordForm::SCHEME_HTML) { | 538 if (scheme != PasswordForm::SCHEME_HTML) { |
| 539 // For non-HTML forms, the realm used for authentication | 539 // For non-HTML forms, the realm used for authentication |
| 540 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the | 540 // (http://tools.ietf.org/html/rfc1945#section-10.2) is appended to the |
| 541 // signon_realm. Just use a default value for now. | 541 // signon_realm. Just use a default value for now. |
| 542 target_form.signon_realm.append("Realm"); | 542 target_form.signon_realm.append("Realm"); |
| 543 } | 543 } |
| 544 ScopedVector<autofill::PasswordForm> form_list; | 544 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 545 BrowserThread::PostTaskAndReplyWithResult( | 545 BrowserThread::PostTaskAndReplyWithResult( |
| 546 BrowserThread::DB, | 546 BrowserThread::DB, |
| 547 FROM_HERE, | 547 FROM_HERE, |
| 548 base::Bind(&NativeBackendGnome::GetLogins, | 548 base::Bind(&NativeBackendGnome::GetLogins, |
| 549 base::Unretained(&backend), | 549 base::Unretained(&backend), |
| 550 target_form, | 550 target_form, |
| 551 &form_list), | 551 &form_list), |
| 552 base::Bind(&CheckTrue)); | 552 base::Bind(&CheckTrue)); |
| 553 | 553 |
| 554 RunBothThreads(); | 554 RunBothThreads(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 583 base::Unretained(&backend), | 583 base::Unretained(&backend), |
| 584 form_facebook_), | 584 form_facebook_), |
| 585 base::Bind(&CheckPasswordChanges, | 585 base::Bind(&CheckPasswordChanges, |
| 586 PasswordStoreChangeList(1, PasswordStoreChange( | 586 PasswordStoreChangeList(1, PasswordStoreChange( |
| 587 PasswordStoreChange::ADD, form_facebook_)))); | 587 PasswordStoreChange::ADD, form_facebook_)))); |
| 588 | 588 |
| 589 // Get the PSL-matched copy of the saved login for m.facebook. | 589 // Get the PSL-matched copy of the saved login for m.facebook. |
| 590 const GURL kMobileURL("http://m.facebook.com/"); | 590 const GURL kMobileURL("http://m.facebook.com/"); |
| 591 PasswordStore::FormDigest m_facebook_lookup = { | 591 PasswordStore::FormDigest m_facebook_lookup = { |
| 592 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL}; | 592 PasswordForm::SCHEME_HTML, kMobileURL.spec(), kMobileURL}; |
| 593 ScopedVector<autofill::PasswordForm> form_list; | 593 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 594 BrowserThread::PostTaskAndReplyWithResult( | 594 BrowserThread::PostTaskAndReplyWithResult( |
| 595 BrowserThread::DB, | 595 BrowserThread::DB, |
| 596 FROM_HERE, | 596 FROM_HERE, |
| 597 base::Bind(&NativeBackendGnome::GetLogins, | 597 base::Bind(&NativeBackendGnome::GetLogins, |
| 598 base::Unretained(&backend), | 598 base::Unretained(&backend), |
| 599 m_facebook_lookup, | 599 m_facebook_lookup, |
| 600 &form_list), | 600 &form_list), |
| 601 base::Bind(&CheckTrue)); | 601 base::Bind(&CheckTrue)); |
| 602 RunBothThreads(); | 602 RunBothThreads(); |
| 603 EXPECT_EQ(1u, mock_keyring_items.size()); | 603 EXPECT_EQ(1u, mock_keyring_items.size()); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 | 820 |
| 821 TEST_F(NativeBackendGnomeTest, BasicListLogins) { | 821 TEST_F(NativeBackendGnomeTest, BasicListLogins) { |
| 822 NativeBackendGnome backend(42); | 822 NativeBackendGnome backend(42); |
| 823 backend.Init(); | 823 backend.Init(); |
| 824 | 824 |
| 825 BrowserThread::PostTask( | 825 BrowserThread::PostTask( |
| 826 BrowserThread::DB, FROM_HERE, | 826 BrowserThread::DB, FROM_HERE, |
| 827 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 827 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 828 base::Unretained(&backend), form_google_)); | 828 base::Unretained(&backend), form_google_)); |
| 829 | 829 |
| 830 ScopedVector<autofill::PasswordForm> form_list; | 830 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 831 BrowserThread::PostTaskAndReplyWithResult( | 831 BrowserThread::PostTaskAndReplyWithResult( |
| 832 BrowserThread::DB, FROM_HERE, | 832 BrowserThread::DB, FROM_HERE, |
| 833 base::Bind(&NativeBackendGnome::GetAutofillableLogins, | 833 base::Bind(&NativeBackendGnome::GetAutofillableLogins, |
| 834 base::Unretained(&backend), &form_list), | 834 base::Unretained(&backend), &form_list), |
| 835 base::Bind(&CheckTrue)); | 835 base::Bind(&CheckTrue)); |
| 836 | 836 |
| 837 RunBothThreads(); | 837 RunBothThreads(); |
| 838 | 838 |
| 839 // Quick check that we got something back. | 839 // Quick check that we got something back. |
| 840 EXPECT_EQ(1u, form_list.size()); | 840 EXPECT_EQ(1u, form_list.size()); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1013 // Attempt to remove a login that doesn't exist. | 1013 // Attempt to remove a login that doesn't exist. |
| 1014 PasswordStoreChangeList changes; | 1014 PasswordStoreChangeList changes; |
| 1015 BrowserThread::PostTaskAndReplyWithResult( | 1015 BrowserThread::PostTaskAndReplyWithResult( |
| 1016 BrowserThread::DB, FROM_HERE, | 1016 BrowserThread::DB, FROM_HERE, |
| 1017 base::Bind(&NativeBackendGnome::RemoveLogin, | 1017 base::Bind(&NativeBackendGnome::RemoveLogin, |
| 1018 base::Unretained(&backend), form_isc_, &changes), | 1018 base::Unretained(&backend), form_isc_, &changes), |
| 1019 base::Bind(&CheckPasswordChangesWithResult, | 1019 base::Bind(&CheckPasswordChangesWithResult, |
| 1020 base::Owned(new PasswordStoreChangeList), &changes)); | 1020 base::Owned(new PasswordStoreChangeList), &changes)); |
| 1021 | 1021 |
| 1022 // Make sure we can still get the first form back. | 1022 // Make sure we can still get the first form back. |
| 1023 ScopedVector<autofill::PasswordForm> form_list; | 1023 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 1024 BrowserThread::PostTaskAndReplyWithResult( | 1024 BrowserThread::PostTaskAndReplyWithResult( |
| 1025 BrowserThread::DB, FROM_HERE, | 1025 BrowserThread::DB, FROM_HERE, |
| 1026 base::Bind(&NativeBackendGnome::GetAutofillableLogins, | 1026 base::Bind(&NativeBackendGnome::GetAutofillableLogins, |
| 1027 base::Unretained(&backend), &form_list), | 1027 base::Unretained(&backend), &form_list), |
| 1028 base::Bind(&CheckTrue)); | 1028 base::Bind(&CheckTrue)); |
| 1029 | 1029 |
| 1030 RunBothThreads(); | 1030 RunBothThreads(); |
| 1031 | 1031 |
| 1032 // Quick check that we got something back. | 1032 // Quick check that we got something back. |
| 1033 EXPECT_EQ(1u, form_list.size()); | 1033 EXPECT_EQ(1u, form_list.size()); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1150 | 1150 |
| 1151 PasswordStore::FormDigest observed_android_form(saved_android_form); | 1151 PasswordStore::FormDigest observed_android_form(saved_android_form); |
| 1152 BrowserThread::PostTaskAndReplyWithResult( | 1152 BrowserThread::PostTaskAndReplyWithResult( |
| 1153 BrowserThread::DB, FROM_HERE, | 1153 BrowserThread::DB, FROM_HERE, |
| 1154 base::Bind(&NativeBackendGnome::AddLogin, | 1154 base::Bind(&NativeBackendGnome::AddLogin, |
| 1155 base::Unretained(&backend), saved_android_form), | 1155 base::Unretained(&backend), saved_android_form), |
| 1156 base::Bind(&CheckPasswordChanges, | 1156 base::Bind(&CheckPasswordChanges, |
| 1157 PasswordStoreChangeList(1, PasswordStoreChange( | 1157 PasswordStoreChangeList(1, PasswordStoreChange( |
| 1158 PasswordStoreChange::ADD, saved_android_form)))); | 1158 PasswordStoreChange::ADD, saved_android_form)))); |
| 1159 | 1159 |
| 1160 ScopedVector<autofill::PasswordForm> form_list; | 1160 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 1161 BrowserThread::PostTaskAndReplyWithResult( | 1161 BrowserThread::PostTaskAndReplyWithResult( |
| 1162 BrowserThread::DB, FROM_HERE, | 1162 BrowserThread::DB, FROM_HERE, |
| 1163 base::Bind(&NativeBackendGnome::GetLogins, | 1163 base::Bind(&NativeBackendGnome::GetLogins, |
| 1164 base::Unretained(&backend), observed_android_form, | 1164 base::Unretained(&backend), observed_android_form, |
| 1165 &form_list), | 1165 &form_list), |
| 1166 base::Bind(&CheckTrue)); | 1166 base::Bind(&CheckTrue)); |
| 1167 | 1167 |
| 1168 RunBothThreads(); | 1168 RunBothThreads(); |
| 1169 | 1169 |
| 1170 EXPECT_EQ(1u, form_list.size()); | 1170 EXPECT_EQ(1u, form_list.size()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 MockKeyringItem::attribute_map::iterator it = | 1256 MockKeyringItem::attribute_map::iterator it = |
| 1257 mock_keyring_items[0].attributes.find("origin_url"); | 1257 mock_keyring_items[0].attributes.find("origin_url"); |
| 1258 ASSERT_NE(mock_keyring_items[0].attributes.end(), it); | 1258 ASSERT_NE(mock_keyring_items[0].attributes.end(), it); |
| 1259 size_t position = it->second.value_string.find(unique_string); | 1259 size_t position = it->second.value_string.find(unique_string); |
| 1260 ASSERT_NE(std::string::npos, position) << it->second.value_string; | 1260 ASSERT_NE(std::string::npos, position) << it->second.value_string; |
| 1261 it->second.value_string.replace( | 1261 it->second.value_string.replace( |
| 1262 position, std::string(unique_string_replacement).length(), | 1262 position, std::string(unique_string_replacement).length(), |
| 1263 unique_string_replacement); | 1263 unique_string_replacement); |
| 1264 | 1264 |
| 1265 // Now test that GetAutofillableLogins returns only one form. | 1265 // Now test that GetAutofillableLogins returns only one form. |
| 1266 ScopedVector<autofill::PasswordForm> form_list; | 1266 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 1267 BrowserThread::PostTaskAndReplyWithResult( | 1267 BrowserThread::PostTaskAndReplyWithResult( |
| 1268 BrowserThread::DB, FROM_HERE, | 1268 BrowserThread::DB, FROM_HERE, |
| 1269 base::Bind(&NativeBackendGnome::GetAutofillableLogins, | 1269 base::Bind(&NativeBackendGnome::GetAutofillableLogins, |
| 1270 base::Unretained(&backend), &form_list), | 1270 base::Unretained(&backend), &form_list), |
| 1271 base::Bind(&CheckTrue)); | 1271 base::Bind(&CheckTrue)); |
| 1272 RunBothThreads(); | 1272 RunBothThreads(); |
| 1273 | 1273 |
| 1274 EXPECT_EQ(1u, form_list.size()); | 1274 EXPECT_EQ(1u, form_list.size()); |
| 1275 EXPECT_EQ(form_google_, *form_list[0]); | 1275 EXPECT_EQ(form_google_, *form_list[0]); |
| 1276 | 1276 |
| 1277 EXPECT_EQ(1u, mock_keyring_items.size()); | 1277 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 1278 if (mock_keyring_items.size() > 0) | 1278 if (mock_keyring_items.size() > 0) |
| 1279 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 1279 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 1280 } | 1280 } |
| 1281 | 1281 |
| 1282 TEST_F(NativeBackendGnomeTest, GetAllLogins) { | 1282 TEST_F(NativeBackendGnomeTest, GetAllLogins) { |
| 1283 NativeBackendGnome backend(42); | 1283 NativeBackendGnome backend(42); |
| 1284 backend.Init(); | 1284 backend.Init(); |
| 1285 | 1285 |
| 1286 BrowserThread::PostTask( | 1286 BrowserThread::PostTask( |
| 1287 BrowserThread::DB, FROM_HERE, | 1287 BrowserThread::DB, FROM_HERE, |
| 1288 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 1288 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 1289 base::Unretained(&backend), form_google_)); | 1289 base::Unretained(&backend), form_google_)); |
| 1290 | 1290 |
| 1291 BrowserThread::PostTask( | 1291 BrowserThread::PostTask( |
| 1292 BrowserThread::DB, FROM_HERE, | 1292 BrowserThread::DB, FROM_HERE, |
| 1293 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 1293 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 1294 base::Unretained(&backend), form_facebook_)); | 1294 base::Unretained(&backend), form_facebook_)); |
| 1295 | 1295 |
| 1296 ScopedVector<autofill::PasswordForm> form_list; | 1296 std::vector<std::unique_ptr<PasswordForm>> form_list; |
| 1297 BrowserThread::PostTaskAndReplyWithResult( | 1297 BrowserThread::PostTaskAndReplyWithResult( |
| 1298 BrowserThread::DB, FROM_HERE, | 1298 BrowserThread::DB, FROM_HERE, |
| 1299 base::Bind(&NativeBackendGnome::GetAllLogins, base::Unretained(&backend), | 1299 base::Bind(&NativeBackendGnome::GetAllLogins, base::Unretained(&backend), |
| 1300 &form_list), | 1300 &form_list), |
| 1301 base::Bind(&CheckTrue)); | 1301 base::Bind(&CheckTrue)); |
| 1302 | 1302 |
| 1303 RunBothThreads(); | 1303 RunBothThreads(); |
| 1304 | 1304 |
| 1305 EXPECT_EQ(2u, form_list.size()); | 1305 EXPECT_EQ(2u, form_list.size()); |
| 1306 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), | 1306 EXPECT_THAT(form_list, UnorderedElementsAre(Pointee(form_google_), |
| 1307 Pointee(form_facebook_))); | 1307 Pointee(form_facebook_))); |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 // TODO(mdm): add more basic tests here at some point. | 1310 // TODO(mdm): add more basic tests here at some point. |
| OLD | NEW |