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

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

Issue 2566873002: Remove ScopedVector from PasswordStoreMac (Closed)
Patch Set: back_inserter Created 4 years 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // Macro to simplify calling CheckFormsAgainstExpectations with a useful label. 110 // Macro to simplify calling CheckFormsAgainstExpectations with a useful label.
111 #define CHECK_FORMS(forms, expectations, i) \ 111 #define CHECK_FORMS(forms, expectations, i) \
112 CheckFormsAgainstExpectations(forms, expectations, #forms, i) 112 CheckFormsAgainstExpectations(forms, expectations, #forms, i)
113 113
114 // Ensures that the data in |forms| match |expectations|, causing test failures 114 // Ensures that the data in |forms| match |expectations|, causing test failures
115 // for any discrepencies. 115 // for any discrepencies.
116 // TODO(stuartmorgan): This is current order-dependent; ideally it shouldn't 116 // TODO(stuartmorgan): This is current order-dependent; ideally it shouldn't
117 // matter if |forms| and |expectations| are scrambled. 117 // matter if |forms| and |expectations| are scrambled.
118 void CheckFormsAgainstExpectations( 118 void CheckFormsAgainstExpectations(
119 const std::vector<PasswordForm*>& forms, 119 const std::vector<std::unique_ptr<PasswordForm>>& forms,
120 const std::vector<PasswordFormData*>& expectations, 120 const std::vector<PasswordFormData*>& expectations,
121 121
122 const char* forms_label, 122 const char* forms_label,
123 unsigned int test_number) { 123 unsigned int test_number) {
124 EXPECT_EQ(expectations.size(), forms.size()) << forms_label << " in test " 124 EXPECT_EQ(expectations.size(), forms.size()) << forms_label << " in test "
125 << test_number; 125 << test_number;
126 if (expectations.size() != forms.size()) 126 if (expectations.size() != forms.size())
127 return; 127 return;
128 128
129 for (unsigned int i = 0; i < expectations.size(); ++i) { 129 for (unsigned int i = 0; i < expectations.size(); ++i) {
130 SCOPED_TRACE(testing::Message() << forms_label << " in test " << test_number 130 SCOPED_TRACE(testing::Message() << forms_label << " in test " << test_number
131 << ", item " << i); 131 << ", item " << i);
132 PasswordForm* form = forms[i]; 132 PasswordForm* form = forms[i].get();
133 PasswordFormData* expectation = expectations[i]; 133 PasswordFormData* expectation = expectations[i];
134 EXPECT_EQ(expectation->scheme, form->scheme); 134 EXPECT_EQ(expectation->scheme, form->scheme);
135 EXPECT_EQ(std::string(expectation->signon_realm), form->signon_realm); 135 EXPECT_EQ(std::string(expectation->signon_realm), form->signon_realm);
136 EXPECT_EQ(GURL(expectation->origin), form->origin); 136 EXPECT_EQ(GURL(expectation->origin), form->origin);
137 EXPECT_EQ(GURL(expectation->action), form->action); 137 EXPECT_EQ(GURL(expectation->action), form->action);
138 EXPECT_EQ(WideToUTF16(expectation->submit_element), form->submit_element); 138 EXPECT_EQ(WideToUTF16(expectation->submit_element), form->submit_element);
139 EXPECT_EQ(WideToUTF16(expectation->username_element), 139 EXPECT_EQ(WideToUTF16(expectation->username_element),
140 form->username_element); 140 form->username_element);
141 EXPECT_EQ(WideToUTF16(expectation->password_element), 141 EXPECT_EQ(WideToUTF16(expectation->password_element),
142 form->password_element); 142 form->password_element);
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 }; 490 };
491 491
492 MacKeychainPasswordFormAdapter keychain_adapter(keychain_); 492 MacKeychainPasswordFormAdapter keychain_adapter(keychain_);
493 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_); 493 MacKeychainPasswordFormAdapter owned_keychain_adapter(keychain_);
494 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); 494 owned_keychain_adapter.SetFindsOnlyOwnedItems(true);
495 for (unsigned int i = 0; i < arraysize(test_data); ++i) { 495 for (unsigned int i = 0; i < arraysize(test_data); ++i) {
496 std::unique_ptr<PasswordForm> query_form = 496 std::unique_ptr<PasswordForm> query_form =
497 CreatePasswordFormFromDataForTesting(test_data[i].data); 497 CreatePasswordFormFromDataForTesting(test_data[i].data);
498 498
499 // Check matches treating the form as a fill target. 499 // Check matches treating the form as a fill target.
500 ScopedVector<autofill::PasswordForm> matching_items = 500 std::vector<std::unique_ptr<PasswordForm>> matching_items =
501 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, 501 keychain_adapter.PasswordsFillingForm(query_form->signon_realm,
502 query_form->scheme); 502 query_form->scheme);
503 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size()); 503 EXPECT_EQ(test_data[i].expected_fill_matches, matching_items.size());
504 504
505 // Check matches treating the form as a merging target. 505 // Check matches treating the form as a merging target.
506 EXPECT_EQ(test_data[i].expected_merge_matches > 0, 506 EXPECT_EQ(test_data[i].expected_merge_matches > 0,
507 keychain_adapter.HasPasswordsMergeableWithForm(*query_form)); 507 keychain_adapter.HasPasswordsMergeableWithForm(*query_form));
508 std::vector<SecKeychainItemRef> keychain_items; 508 std::vector<SecKeychainItemRef> keychain_items;
509 std::vector<internal_keychain_helpers::ItemFormPair> item_form_pairs = 509 std::vector<internal_keychain_helpers::ItemFormPair> item_form_pairs =
510 internal_keychain_helpers:: 510 internal_keychain_helpers::
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) { 571 for (unsigned int i = 0; i < arraysize(base_form_data); ++i) {
572 // Create a base form and make sure we find a match. 572 // Create a base form and make sure we find a match.
573 std::unique_ptr<PasswordForm> base_form = 573 std::unique_ptr<PasswordForm> base_form =
574 CreatePasswordFormFromDataForTesting(base_form_data[i]); 574 CreatePasswordFormFromDataForTesting(base_form_data[i]);
575 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form)); 575 EXPECT_TRUE(keychain_adapter.HasPasswordsMergeableWithForm(*base_form));
576 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form)); 576 EXPECT_TRUE(keychain_adapter.HasPasswordExactlyMatchingForm(*base_form));
577 577
578 // Make sure that the matching isn't looser than it should be by checking 578 // Make sure that the matching isn't looser than it should be by checking
579 // that slightly altered forms don't match. 579 // that slightly altered forms don't match.
580 ScopedVector<autofill::PasswordForm> modified_forms; 580 std::vector<std::unique_ptr<PasswordForm>> modified_forms;
581 581
582 modified_forms.push_back(new PasswordForm(*base_form)); 582 modified_forms.push_back(base::MakeUnique<PasswordForm>(*base_form));
583 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); 583 modified_forms.back()->username_value = ASCIIToUTF16("wrong_user");
584 584
585 modified_forms.push_back(new PasswordForm(*base_form)); 585 modified_forms.push_back(base::MakeUnique<PasswordForm>(*base_form));
586 SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); 586 SetPasswordFormPath(modified_forms.back().get(), "elsewhere.html");
587 587
588 modified_forms.push_back(new PasswordForm(*base_form)); 588 modified_forms.push_back(base::MakeUnique<PasswordForm>(*base_form));
589 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER; 589 modified_forms.back()->scheme = PasswordForm::SCHEME_OTHER;
590 590
591 modified_forms.push_back(new PasswordForm(*base_form)); 591 modified_forms.push_back(base::MakeUnique<PasswordForm>(*base_form));
592 SetPasswordFormPort(modified_forms.back(), "1234"); 592 SetPasswordFormPort(modified_forms.back().get(), "1234");
593 593
594 modified_forms.push_back(new PasswordForm(*base_form)); 594 modified_forms.push_back(base::MakeUnique<PasswordForm>(*base_form));
595 modified_forms.back()->blacklisted_by_user = true; 595 modified_forms.back()->blacklisted_by_user = true;
596 596
597 if (base_form->scheme == PasswordForm::SCHEME_BASIC || 597 if (base_form->scheme == PasswordForm::SCHEME_BASIC ||
598 base_form->scheme == PasswordForm::SCHEME_DIGEST) { 598 base_form->scheme == PasswordForm::SCHEME_DIGEST) {
599 modified_forms.push_back(new PasswordForm(*base_form)); 599 modified_forms.push_back(base::MakeUnique<PasswordForm>(*base_form));
600 SetPasswordFormRealm(modified_forms.back(), "incorrect"); 600 SetPasswordFormRealm(modified_forms.back().get(), "incorrect");
601 } 601 }
602 602
603 for (unsigned int j = 0; j < modified_forms.size(); ++j) { 603 for (unsigned int j = 0; j < modified_forms.size(); ++j) {
604 bool match = 604 bool match =
605 keychain_adapter.HasPasswordExactlyMatchingForm(*modified_forms[j]); 605 keychain_adapter.HasPasswordExactlyMatchingForm(*modified_forms[j]);
606 EXPECT_FALSE(match) << "In modified version " << j << " of base form " 606 EXPECT_FALSE(match) << "In modified version " << j << " of base form "
607 << i; 607 << i;
608 } 608 }
609 } 609 }
610 } 610 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 // credentials are not tried to be matched with a Keychain item. 1063 // credentials are not tried to be matched with a Keychain item.
1064 ++current_test; 1064 ++current_test;
1065 CHECK(current_test < kTestCount); 1065 CHECK(current_test < kTestCount);
1066 test_data[KEYCHAIN_INPUT][current_test].push_back(&keychain_android); 1066 test_data[KEYCHAIN_INPUT][current_test].push_back(&keychain_android);
1067 test_data[DATABASE_INPUT][current_test].push_back(&db_federated); 1067 test_data[DATABASE_INPUT][current_test].push_back(&db_federated);
1068 test_data[DATABASE_INPUT][current_test].push_back(&db_android); 1068 test_data[DATABASE_INPUT][current_test].push_back(&db_android);
1069 test_data[MERGE_OUTPUT][current_test].push_back(&db_federated); 1069 test_data[MERGE_OUTPUT][current_test].push_back(&db_federated);
1070 test_data[MERGE_OUTPUT][current_test].push_back(&merged_android); 1070 test_data[MERGE_OUTPUT][current_test].push_back(&merged_android);
1071 1071
1072 for (unsigned int test_case = 0; test_case <= current_test; ++test_case) { 1072 for (unsigned int test_case = 0; test_case <= current_test; ++test_case) {
1073 ScopedVector<autofill::PasswordForm> keychain_forms; 1073 std::vector<std::unique_ptr<PasswordForm>> keychain_forms;
1074 for (std::vector<PasswordFormData*>::iterator i = 1074 for (std::vector<PasswordFormData*>::iterator i =
1075 test_data[KEYCHAIN_INPUT][test_case].begin(); 1075 test_data[KEYCHAIN_INPUT][test_case].begin();
1076 i != test_data[KEYCHAIN_INPUT][test_case].end(); ++i) { 1076 i != test_data[KEYCHAIN_INPUT][test_case].end(); ++i) {
1077 keychain_forms.push_back( 1077 keychain_forms.push_back(CreatePasswordFormFromDataForTesting(*(*i)));
1078 CreatePasswordFormFromDataForTesting(*(*i)).release());
1079 } 1078 }
1080 ScopedVector<autofill::PasswordForm> database_forms; 1079 std::vector<std::unique_ptr<PasswordForm>> database_forms;
1081 for (std::vector<PasswordFormData*>::iterator i = 1080 for (std::vector<PasswordFormData*>::iterator i =
1082 test_data[DATABASE_INPUT][test_case].begin(); 1081 test_data[DATABASE_INPUT][test_case].begin();
1083 i != test_data[DATABASE_INPUT][test_case].end(); ++i) { 1082 i != test_data[DATABASE_INPUT][test_case].end(); ++i) {
1084 database_forms.push_back( 1083 database_forms.push_back(CreatePasswordFormFromDataForTesting(*(*i)));
1085 CreatePasswordFormFromDataForTesting(*(*i)).release());
1086 } 1084 }
1087 1085
1088 ScopedVector<autofill::PasswordForm> merged_forms; 1086 std::vector<std::unique_ptr<PasswordForm>> merged_forms;
1089 internal_keychain_helpers::MergePasswordForms( 1087 internal_keychain_helpers::MergePasswordForms(
1090 &keychain_forms, &database_forms, &merged_forms); 1088 &keychain_forms, &database_forms, &merged_forms);
1091 1089
1092 CHECK_FORMS(keychain_forms.get(), test_data[KEYCHAIN_OUTPUT][test_case], 1090 CHECK_FORMS(keychain_forms, test_data[KEYCHAIN_OUTPUT][test_case],
1093 test_case); 1091 test_case);
1094 CHECK_FORMS(database_forms.get(), test_data[DATABASE_OUTPUT][test_case], 1092 CHECK_FORMS(database_forms, test_data[DATABASE_OUTPUT][test_case],
1095 test_case); 1093 test_case);
1096 CHECK_FORMS(merged_forms.get(), test_data[MERGE_OUTPUT][test_case], 1094 CHECK_FORMS(merged_forms, test_data[MERGE_OUTPUT][test_case], test_case);
1097 test_case);
1098 } 1095 }
1099 } 1096 }
1100 1097
1101 TEST_F(PasswordStoreMacInternalsTest, TestPasswordBulkLookup) { 1098 TEST_F(PasswordStoreMacInternalsTest, TestPasswordBulkLookup) {
1102 PasswordFormData db_data[] = { 1099 PasswordFormData db_data[] = {
1103 {PasswordForm::SCHEME_HTML, "http://some.domain.com/", 1100 {PasswordForm::SCHEME_HTML, "http://some.domain.com/",
1104 "http://some.domain.com/", "http://some.domain.com/action.cgi", 1101 "http://some.domain.com/", "http://some.domain.com/action.cgi",
1105 L"submit", L"username", L"password", L"joe_user", L"", true, 1212121212}, 1102 L"submit", L"username", L"password", L"joe_user", L"", true, 1212121212},
1106 {PasswordForm::SCHEME_HTML, "http://some.domain.com/", 1103 {PasswordForm::SCHEME_HTML, "http://some.domain.com/",
1107 "http://some.domain.com/page.html", 1104 "http://some.domain.com/page.html",
1108 "http://some.domain.com/handlepage.cgi", L"submit", L"username", 1105 "http://some.domain.com/handlepage.cgi", L"submit", L"username",
1109 L"password", L"joe_user", L"", true, 1234567890}, 1106 L"password", L"joe_user", L"", true, 1234567890},
1110 {PasswordForm::SCHEME_HTML, "http://some.domain.com/", 1107 {PasswordForm::SCHEME_HTML, "http://some.domain.com/",
1111 "http://some.domain.com/page.html", 1108 "http://some.domain.com/page.html",
1112 "http://some.domain.com/handlepage.cgi", L"submit", L"username", 1109 "http://some.domain.com/handlepage.cgi", L"submit", L"username",
1113 L"password", L"second-account", L"", true, 1240000000}, 1110 L"password", L"second-account", L"", true, 1240000000},
1114 {PasswordForm::SCHEME_HTML, "http://dont.remember.com/", 1111 {PasswordForm::SCHEME_HTML, "http://dont.remember.com/",
1115 "http://dont.remember.com/", "http://dont.remember.com/handlepage.cgi", 1112 "http://dont.remember.com/", "http://dont.remember.com/handlepage.cgi",
1116 L"submit", L"username", L"password", L"joe_user", L"", true, 1240000000}, 1113 L"submit", L"username", L"password", L"joe_user", L"", true, 1240000000},
1117 {PasswordForm::SCHEME_HTML, "http://some.domain.com/", 1114 {PasswordForm::SCHEME_HTML, "http://some.domain.com/",
1118 "http://some.domain.com/path.html", "http://some.domain.com/action.cgi", 1115 "http://some.domain.com/path.html", "http://some.domain.com/action.cgi",
1119 L"submit", L"username", L"password", NULL, NULL, true, 1212121212}, 1116 L"submit", L"username", L"password", NULL, NULL, true, 1212121212},
1120 }; 1117 };
1121 ScopedVector<autofill::PasswordForm> database_forms; 1118 std::vector<std::unique_ptr<PasswordForm>> database_forms;
1122 for (unsigned int i = 0; i < arraysize(db_data); ++i) { 1119 for (const PasswordFormData& form_data : db_data) {
1123 database_forms.push_back( 1120 database_forms.push_back(CreatePasswordFormFromDataForTesting(form_data));
1124 CreatePasswordFormFromDataForTesting(db_data[i]).release());
1125 } 1121 }
1126 ScopedVector<autofill::PasswordForm> merged_forms; 1122 std::vector<std::unique_ptr<PasswordForm>> merged_forms;
1127 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, 1123 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms,
1128 &merged_forms); 1124 &merged_forms);
1129 EXPECT_EQ(2U, database_forms.size()); 1125 EXPECT_EQ(2U, database_forms.size());
1130 ASSERT_EQ(3U, merged_forms.size()); 1126 ASSERT_EQ(3U, merged_forms.size());
1131 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value); 1127 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value);
1132 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value); 1128 EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value);
1133 EXPECT_TRUE(merged_forms[2]->blacklisted_by_user); 1129 EXPECT_TRUE(merged_forms[2]->blacklisted_by_user);
1134 } 1130 }
1135 1131
1136 TEST_F(PasswordStoreMacInternalsTest, TestBlacklistedFiltering) { 1132 TEST_F(PasswordStoreMacInternalsTest, TestBlacklistedFiltering) {
1137 PasswordFormData db_data[] = { 1133 PasswordFormData db_data[] = {
1138 {PasswordForm::SCHEME_HTML, "http://dont.remember.com/", 1134 {PasswordForm::SCHEME_HTML, "http://dont.remember.com/",
1139 "http://dont.remember.com/", "http://dont.remember.com/handlepage.cgi", 1135 "http://dont.remember.com/", "http://dont.remember.com/handlepage.cgi",
1140 L"submit", L"username", L"password", L"joe_user", L"non_empty_password", 1136 L"submit", L"username", L"password", L"joe_user", L"non_empty_password",
1141 true, 1240000000}, 1137 true, 1240000000},
1142 {PasswordForm::SCHEME_HTML, "https://dont.remember.com/", 1138 {PasswordForm::SCHEME_HTML, "https://dont.remember.com/",
1143 "https://dont.remember.com/", 1139 "https://dont.remember.com/",
1144 "https://dont.remember.com/handlepage_secure.cgi", L"submit", 1140 "https://dont.remember.com/handlepage_secure.cgi", L"submit",
1145 L"username", L"password", L"joe_user", L"non_empty_password", true, 1141 L"username", L"password", L"joe_user", L"non_empty_password", true,
1146 1240000000}, 1142 1240000000},
1147 }; 1143 };
1148 ScopedVector<autofill::PasswordForm> database_forms; 1144 std::vector<std::unique_ptr<PasswordForm>> database_forms;
1149 for (unsigned int i = 0; i < arraysize(db_data); ++i) { 1145 for (const PasswordFormData& form_data : db_data) {
1150 database_forms.push_back( 1146 database_forms.push_back(CreatePasswordFormFromDataForTesting(form_data));
1151 CreatePasswordFormFromDataForTesting(db_data[i]).release());
1152 } 1147 }
1153 ScopedVector<autofill::PasswordForm> merged_forms; 1148 std::vector<std::unique_ptr<PasswordForm>> merged_forms;
1154 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, 1149 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms,
1155 &merged_forms); 1150 &merged_forms);
1156 EXPECT_EQ(2U, database_forms.size()); 1151 EXPECT_EQ(2U, database_forms.size());
1157 ASSERT_EQ(0U, merged_forms.size()); 1152 ASSERT_EQ(0U, merged_forms.size());
1158 } 1153 }
1159 1154
1160 TEST_F(PasswordStoreMacInternalsTest, TestFillPasswordFormFromKeychainItem) { 1155 TEST_F(PasswordStoreMacInternalsTest, TestFillPasswordFormFromKeychainItem) {
1161 // When |extract_password_data| is false, the password field must be empty, 1156 // When |extract_password_data| is false, the password field must be empty,
1162 // and |blacklisted_by_user| must be false. 1157 // and |blacklisted_by_user| must be false.
1163 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(1); 1158 SecKeychainItemRef keychain_item = reinterpret_cast<SecKeychainItemRef>(1);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 {PasswordForm::SCHEME_DIGEST, "https://digest.site.com/differentrealm", 1231 {PasswordForm::SCHEME_DIGEST, "https://digest.site.com/differentrealm",
1237 "https://digest.site.com/secure.html", NULL, NULL, NULL, NULL, 1232 "https://digest.site.com/secure.html", NULL, NULL, NULL, NULL,
1238 L"testname", L"testpass", false, 0}, 1233 L"testname", L"testpass", false, 0},
1239 }; 1234 };
1240 for (unsigned int i = 0; i < arraysize(owned_password_data); ++i) { 1235 for (unsigned int i = 0; i < arraysize(owned_password_data); ++i) {
1241 std::unique_ptr<PasswordForm> form = 1236 std::unique_ptr<PasswordForm> form =
1242 CreatePasswordFormFromDataForTesting(owned_password_data[i]); 1237 CreatePasswordFormFromDataForTesting(owned_password_data[i]);
1243 owned_keychain_adapter.AddPassword(*form); 1238 owned_keychain_adapter.AddPassword(*form);
1244 } 1239 }
1245 1240
1246 ScopedVector<autofill::PasswordForm> all_passwords = 1241 std::vector<std::unique_ptr<PasswordForm>> all_passwords =
1247 keychain_adapter.GetAllPasswordFormPasswords(); 1242 keychain_adapter.GetAllPasswordFormPasswords();
1248 EXPECT_EQ(9 + arraysize(owned_password_data), all_passwords.size()); 1243 EXPECT_EQ(9 + arraysize(owned_password_data), all_passwords.size());
1249 1244
1250 ScopedVector<autofill::PasswordForm> owned_passwords = 1245 std::vector<std::unique_ptr<PasswordForm>> owned_passwords =
1251 owned_keychain_adapter.GetAllPasswordFormPasswords(); 1246 owned_keychain_adapter.GetAllPasswordFormPasswords();
1252 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size()); 1247 EXPECT_EQ(arraysize(owned_password_data), owned_passwords.size());
1253 } 1248 }
1254 1249
1255 #pragma mark - 1250 #pragma mark -
1256 1251
1257 class PasswordStoreMacTest : public testing::Test { 1252 class PasswordStoreMacTest : public testing::Test {
1258 public: 1253 public:
1259 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} 1254 PasswordStoreMacTest() : ui_thread_(BrowserThread::UI, &message_loop_) {}
1260 1255
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 } 1479 }
1485 1480
1486 FinishAsyncProcessing(); 1481 FinishAsyncProcessing();
1487 1482
1488 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); 1483 MacKeychainPasswordFormAdapter keychain_adapter(keychain());
1489 for (unsigned int i = 0; i < arraysize(updates); ++i) { 1484 for (unsigned int i = 0; i < arraysize(updates); ++i) {
1490 SCOPED_TRACE(testing::Message("iteration ") << i); 1485 SCOPED_TRACE(testing::Message("iteration ") << i);
1491 std::unique_ptr<PasswordForm> query_form = 1486 std::unique_ptr<PasswordForm> query_form =
1492 CreatePasswordFormFromDataForTesting(updates[i].form_data); 1487 CreatePasswordFormFromDataForTesting(updates[i].form_data);
1493 1488
1494 ScopedVector<autofill::PasswordForm> matching_items = 1489 std::vector<std::unique_ptr<PasswordForm>> matching_items =
1495 keychain_adapter.PasswordsFillingForm(query_form->signon_realm, 1490 keychain_adapter.PasswordsFillingForm(query_form->signon_realm,
1496 query_form->scheme); 1491 query_form->scheme);
1497 if (updates[i].password) { 1492 if (updates[i].password) {
1498 EXPECT_GT(matching_items.size(), 0U); 1493 EXPECT_GT(matching_items.size(), 0U);
1499 if (matching_items.size() >= 1) 1494 if (matching_items.size() >= 1)
1500 EXPECT_EQ(ASCIIToUTF16(updates[i].password), 1495 EXPECT_EQ(ASCIIToUTF16(updates[i].password),
1501 matching_items[0]->password_value); 1496 matching_items[0]->password_value);
1502 } else { 1497 } else {
1503 EXPECT_EQ(0U, matching_items.size()); 1498 EXPECT_EQ(0U, matching_items.size());
1504 } 1499 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 EXPECT_EQ(AddChangeForForm(returned_form), 1559 EXPECT_EQ(AddChangeForForm(returned_form),
1565 login_db()->AddLogin(returned_form)); 1560 login_db()->AddLogin(returned_form));
1566 owned_keychain_adapter.AddPassword(m_form); 1561 owned_keychain_adapter.AddPassword(m_form);
1567 1562
1568 // 4. Remove both passwords. 1563 // 4. Remove both passwords.
1569 store_->RemoveLogin(*www_form); 1564 store_->RemoveLogin(*www_form);
1570 store_->RemoveLogin(m_form); 1565 store_->RemoveLogin(m_form);
1571 FinishAsyncProcessing(); 1566 FinishAsyncProcessing();
1572 1567
1573 // No trace of www.facebook.com. 1568 // No trace of www.facebook.com.
1574 ScopedVector<autofill::PasswordForm> matching_items = 1569 std::vector<std::unique_ptr<PasswordForm>> matching_items =
1575 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm, 1570 owned_keychain_adapter.PasswordsFillingForm(www_form->signon_realm,
1576 www_form->scheme); 1571 www_form->scheme);
1577 EXPECT_EQ(0u, matching_items.size()); 1572 EXPECT_EQ(0u, matching_items.size());
1578 1573
1579 std::vector<std::unique_ptr<PasswordForm>> matching_db_items; 1574 std::vector<std::unique_ptr<PasswordForm>> matching_db_items;
1580 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form), 1575 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form),
1581 &matching_db_items)); 1576 &matching_db_items));
1582 EXPECT_EQ(0u, matching_db_items.size()); 1577 EXPECT_EQ(0u, matching_db_items.size());
1583 1578
1584 // No trace of m.facebook.com. 1579 // No trace of m.facebook.com.
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 test->store()->AddLogin(*form_facebook); 1678 test->store()->AddLogin(*form_facebook);
1684 test->store()->AddLogin(*form_other); 1679 test->store()->AddLogin(*form_other);
1685 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook_old))); 1680 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook_old)));
1686 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook))); 1681 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook)));
1687 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_other))); 1682 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_other)));
1688 observer.WaitAndVerify(test); 1683 observer.WaitAndVerify(test);
1689 1684
1690 // Check the keychain content. 1685 // Check the keychain content.
1691 MacKeychainPasswordFormAdapter owned_keychain_adapter(test->keychain()); 1686 MacKeychainPasswordFormAdapter owned_keychain_adapter(test->keychain());
1692 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); 1687 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1693 ScopedVector<PasswordForm> matching_items( 1688 std::vector<std::unique_ptr<PasswordForm>> matching_items(
1694 owned_keychain_adapter.PasswordsFillingForm(form_facebook->signon_realm, 1689 owned_keychain_adapter.PasswordsFillingForm(form_facebook->signon_realm,
1695 form_facebook->scheme)); 1690 form_facebook->scheme));
1696 EXPECT_EQ(1u, matching_items.size()); 1691 EXPECT_EQ(1u, matching_items.size());
1697 matching_items = owned_keychain_adapter.PasswordsFillingForm( 1692 matching_items = owned_keychain_adapter.PasswordsFillingForm(
1698 form_other->signon_realm, form_other->scheme); 1693 form_other->signon_realm, form_other->scheme);
1699 EXPECT_EQ(1u, matching_items.size()); 1694 EXPECT_EQ(1u, matching_items.size());
1700 1695
1701 // Remove facebook. 1696 // Remove facebook.
1702 if (check_created) { 1697 if (check_created) {
1703 test->store()->RemoveLoginsCreatedBetween(base::Time(), next_day, 1698 test->store()->RemoveLoginsCreatedBetween(base::Time(), next_day,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 form_google->skip_zero_click = false; 1779 form_google->skip_zero_click = false;
1785 1780
1786 // Add the zero-clickable forms to the database. 1781 // Add the zero-clickable forms to the database.
1787 PasswordsChangeObserver observer(store()); 1782 PasswordsChangeObserver observer(store());
1788 store()->AddLogin(*form_facebook); 1783 store()->AddLogin(*form_facebook);
1789 store()->AddLogin(*form_google); 1784 store()->AddLogin(*form_google);
1790 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook))); 1785 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_facebook)));
1791 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_google))); 1786 EXPECT_CALL(observer, OnLoginsChanged(GetAddChangeList(*form_google)));
1792 observer.WaitAndVerify(this); 1787 observer.WaitAndVerify(this);
1793 1788
1794 ScopedVector<autofill::PasswordForm> forms; 1789 std::vector<std::unique_ptr<PasswordForm>> forms;
1795 EXPECT_TRUE(login_db()->GetAutoSignInLogins(&forms)); 1790 EXPECT_TRUE(login_db()->GetAutoSignInLogins(&forms));
1796 EXPECT_EQ(2u, forms.size()); 1791 EXPECT_EQ(2u, forms.size());
1797 EXPECT_FALSE(forms[0]->skip_zero_click); 1792 EXPECT_FALSE(forms[0]->skip_zero_click);
1798 EXPECT_FALSE(forms[1]->skip_zero_click); 1793 EXPECT_FALSE(forms[1]->skip_zero_click);
1799 1794
1800 store()->DisableAutoSignInForOrigins( 1795 store()->DisableAutoSignInForOrigins(
1801 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==), 1796 base::Bind(static_cast<bool (*)(const GURL&, const GURL&)>(operator==),
1802 form_google->origin), 1797 form_google->origin),
1803 base::Closure()); 1798 base::Closure());
1804 FinishAsyncProcessing(); 1799 FinishAsyncProcessing();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time(), 1864 store_->RemoveLoginsCreatedBetween(base::Time(), base::Time(),
1870 base::Closure()); 1865 base::Closure());
1871 FinishAsyncProcessing(); 1866 FinishAsyncProcessing();
1872 1867
1873 // Check the second facebook form is gone. 1868 // Check the second facebook form is gone.
1874 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form), 1869 EXPECT_TRUE(login_db()->GetLogins(PasswordStore::FormDigest(*www_form),
1875 &matching_items)); 1870 &matching_items));
1876 EXPECT_EQ(0u, matching_items.size()); 1871 EXPECT_EQ(0u, matching_items.size());
1877 1872
1878 // Check the first facebook form is still there. 1873 // Check the first facebook form is still there.
1879 ScopedVector<PasswordForm> matching_keychain_items; 1874 std::vector<std::unique_ptr<PasswordForm>> matching_keychain_items;
1880 matching_keychain_items = owned_keychain_adapter.PasswordsFillingForm( 1875 matching_keychain_items = owned_keychain_adapter.PasswordsFillingForm(
1881 www_form->signon_realm, www_form->scheme); 1876 www_form->signon_realm, www_form->scheme);
1882 ASSERT_EQ(1u, matching_keychain_items.size()); 1877 ASSERT_EQ(1u, matching_keychain_items.size());
1883 EXPECT_EQ(ASCIIToUTF16("joe_user"), 1878 EXPECT_EQ(ASCIIToUTF16("joe_user"),
1884 matching_keychain_items[0]->username_value); 1879 matching_keychain_items[0]->username_value);
1885 1880
1886 // Check the third-party password is still there. 1881 // Check the third-party password is still there.
1887 owned_keychain_adapter.SetFindsOnlyOwnedItems(false); 1882 owned_keychain_adapter.SetFindsOnlyOwnedItems(false);
1888 matching_keychain_items = owned_keychain_adapter.PasswordsFillingForm( 1883 matching_keychain_items = owned_keychain_adapter.PasswordsFillingForm(
1889 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML); 1884 "http://some.domain.com/insecure.html", PasswordForm::SCHEME_HTML);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 MockAppleKeychain::KeychainTestData data1 = { kSecAuthenticationTypeHTMLForm, 2092 MockAppleKeychain::KeychainTestData data1 = { kSecAuthenticationTypeHTMLForm,
2098 "some.domain.com", kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z", 2093 "some.domain.com", kSecProtocolTypeHTTP, NULL, 0, NULL, "20020601171500Z",
2099 "joe_user", "sekrit", false}; 2094 "joe_user", "sekrit", false};
2100 keychain()->AddTestItem(data1); 2095 keychain()->AddTestItem(data1);
2101 2096
2102 MacKeychainPasswordFormAdapter keychain_adapter(keychain()); 2097 MacKeychainPasswordFormAdapter keychain_adapter(keychain());
2103 PasswordFormData data2 = { PasswordForm::SCHEME_HTML, "http://web.site.com/", 2098 PasswordFormData data2 = { PasswordForm::SCHEME_HTML, "http://web.site.com/",
2104 "http://web.site.com/path/to/page.html", NULL, NULL, NULL, NULL, 2099 "http://web.site.com/path/to/page.html", NULL, NULL, NULL, NULL,
2105 L"anonymous", L"knock-knock", false, 0 }; 2100 L"anonymous", L"knock-knock", false, 0 };
2106 keychain_adapter.AddPassword(*CreatePasswordFormFromDataForTesting(data2)); 2101 keychain_adapter.AddPassword(*CreatePasswordFormFromDataForTesting(data2));
2107 std::vector<std::unique_ptr<autofill::PasswordForm>> passwords = 2102 std::vector<std::unique_ptr<PasswordForm>> passwords =
2108 password_manager_util::ConvertScopedVector( 2103 keychain_adapter.GetAllPasswordFormPasswords();
2109 keychain_adapter.GetAllPasswordFormPasswords());
2110 EXPECT_EQ(2u, passwords.size()); 2104 EXPECT_EQ(2u, passwords.size());
2111 2105
2112 // Delete everyhting but only the Chrome-owned item should be affected. 2106 // Delete everyhting but only the Chrome-owned item should be affected.
2113 PasswordStoreMac::CleanUpKeychain(keychain(), passwords); 2107 PasswordStoreMac::CleanUpKeychain(keychain(), passwords);
2114 passwords = password_manager_util::ConvertScopedVector( 2108 passwords = keychain_adapter.GetAllPasswordFormPasswords();
2115 keychain_adapter.GetAllPasswordFormPasswords());
2116 ASSERT_EQ(1u, passwords.size()); 2109 ASSERT_EQ(1u, passwords.size());
2117 EXPECT_EQ("http://some.domain.com/", passwords[0]->signon_realm); 2110 EXPECT_EQ("http://some.domain.com/", passwords[0]->signon_realm);
2118 EXPECT_EQ(ASCIIToUTF16("sekrit"), passwords[0]->password_value); 2111 EXPECT_EQ(ASCIIToUTF16("sekrit"), passwords[0]->password_value);
2119 } 2112 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698