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

Side by Side Diff: chrome/browser/autofill/personal_data_manager_unittest.cc

Issue 11360055: [Autofill] Rename GetInfo and SetInfo to GetRawInfo and SetRawInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 8 years, 1 month 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 ResetPersonalDataManager(); 133 ResetPersonalDataManager();
134 134
135 // Verify the non-addition. 135 // Verify the non-addition.
136 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); 136 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
137 ASSERT_EQ(1U, results2.size()); 137 ASSERT_EQ(1U, results2.size());
138 EXPECT_EQ(0, profile0.Compare(*results2[0])); 138 EXPECT_EQ(0, profile0.Compare(*results2[0]));
139 139
140 // New profile with different email. 140 // New profile with different email.
141 AutofillProfile profile1 = profile0; 141 AutofillProfile profile1 = profile0;
142 profile1.set_guid(base::GenerateGUID()); 142 profile1.set_guid(base::GenerateGUID());
143 profile1.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com")); 143 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("john@smith.com"));
144 144
145 // Add the different profile. This should save as a separate profile. 145 // Add the different profile. This should save as a separate profile.
146 // Note that if this same profile was "merged" it would collapse to one 146 // Note that if this same profile was "merged" it would collapse to one
147 // profile with a multi-valued entry for email. 147 // profile with a multi-valued entry for email.
148 personal_data_->AddProfile(profile1); 148 personal_data_->AddProfile(profile1);
149 149
150 // Reload the database. 150 // Reload the database.
151 ResetPersonalDataManager(); 151 ResetPersonalDataManager();
152 152
153 // Verify the addition. 153 // Verify the addition.
(...skipping 30 matching lines...) Expand all
184 EXPECT_CALL(personal_data_observer_, 184 EXPECT_CALL(personal_data_observer_,
185 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 185 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
186 MessageLoop::current()->Run(); 186 MessageLoop::current()->Run();
187 187
188 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); 188 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
189 ASSERT_EQ(2U, results1.size()); 189 ASSERT_EQ(2U, results1.size());
190 EXPECT_EQ(0, profile0.Compare(*results1[0])); 190 EXPECT_EQ(0, profile0.Compare(*results1[0]));
191 EXPECT_EQ(0, profile1.Compare(*results1[1])); 191 EXPECT_EQ(0, profile1.Compare(*results1[1]));
192 192
193 // Update, remove, and add. 193 // Update, remove, and add.
194 profile0.SetInfo(NAME_FIRST, ASCIIToUTF16("John")); 194 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
195 personal_data_->UpdateProfile(profile0); 195 personal_data_->UpdateProfile(profile0);
196 personal_data_->RemoveProfile(profile1.guid()); 196 personal_data_->RemoveProfile(profile1.guid());
197 personal_data_->AddProfile(profile2); 197 personal_data_->AddProfile(profile2);
198 198
199 // Verify that the web database has been updated and the notification sent. 199 // Verify that the web database has been updated and the notification sent.
200 EXPECT_CALL(personal_data_observer_, 200 EXPECT_CALL(personal_data_observer_,
201 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 201 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
202 MessageLoop::current()->Run(); 202 MessageLoop::current()->Run();
203 203
204 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); 204 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 EXPECT_CALL(personal_data_observer_, 239 EXPECT_CALL(personal_data_observer_,
240 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 240 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
241 MessageLoop::current()->Run(); 241 MessageLoop::current()->Run();
242 242
243 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); 243 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
244 ASSERT_EQ(2U, results1.size()); 244 ASSERT_EQ(2U, results1.size());
245 EXPECT_EQ(0, credit_card0.Compare(*results1[0])); 245 EXPECT_EQ(0, credit_card0.Compare(*results1[0]));
246 EXPECT_EQ(0, credit_card1.Compare(*results1[1])); 246 EXPECT_EQ(0, credit_card1.Compare(*results1[1]));
247 247
248 // Update, remove, and add. 248 // Update, remove, and add.
249 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); 249 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe"));
250 personal_data_->UpdateCreditCard(credit_card0); 250 personal_data_->UpdateCreditCard(credit_card0);
251 personal_data_->RemoveCreditCard(credit_card1.guid()); 251 personal_data_->RemoveCreditCard(credit_card1.guid());
252 personal_data_->AddCreditCard(credit_card2); 252 personal_data_->AddCreditCard(credit_card2);
253 253
254 // Verify that the web database has been updated and the notification sent. 254 // Verify that the web database has been updated and the notification sent.
255 EXPECT_CALL(personal_data_observer_, 255 EXPECT_CALL(personal_data_observer_,
256 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 256 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
257 MessageLoop::current()->Run(); 257 MessageLoop::current()->Run();
258 258
259 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); 259 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 EXPECT_EQ(profile2, *results2[2]); 472 EXPECT_EQ(profile2, *results2[2]);
473 473
474 wds->RemoveAutofillProfile(profile1.guid()); 474 wds->RemoveAutofillProfile(profile1.guid());
475 wds->RemoveAutofillProfile(profile2.guid()); 475 wds->RemoveAutofillProfile(profile2.guid());
476 476
477 // Before telling the PDM to refresh, simulate an edit to one of the profiles 477 // Before telling the PDM to refresh, simulate an edit to one of the profiles
478 // via a SetProfile update (this would happen if the Autofill window was 478 // via a SetProfile update (this would happen if the Autofill window was
479 // open with a previous snapshot of the profiles, and something [e.g. sync] 479 // open with a previous snapshot of the profiles, and something [e.g. sync]
480 // removed a profile from the browser. In this edge case, we will end up 480 // removed a profile from the browser. In this edge case, we will end up
481 // in a consistent state by dropping the write). 481 // in a consistent state by dropping the write).
482 profile2.SetInfo(NAME_FIRST, ASCIIToUTF16("Jo")); 482 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo"));
483 personal_data_->UpdateProfile(profile0); 483 personal_data_->UpdateProfile(profile0);
484 personal_data_->AddProfile(profile1); 484 personal_data_->AddProfile(profile1);
485 personal_data_->AddProfile(profile2); 485 personal_data_->AddProfile(profile2);
486 486
487 // Verify that the web database has been updated and the notification sent. 487 // Verify that the web database has been updated and the notification sent.
488 EXPECT_CALL(personal_data_observer_, 488 EXPECT_CALL(personal_data_observer_,
489 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 489 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
490 MessageLoop::current()->Run(); 490 MessageLoop::current()->Run();
491 491
492 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles(); 492 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 autofill_test::SetProfileInfo(&expected, "George", NULL, 648 autofill_test::SetProfileInfo(&expected, "George", NULL,
649 "Washington", NULL, NULL, "21 Laussat St", NULL, 649 "Washington", NULL, NULL, "21 Laussat St", NULL,
650 "San Francisco", "California", "94102", NULL, "6505550000"); 650 "San Francisco", "California", "94102", NULL, "6505550000");
651 const std::vector<AutofillProfile*>& results = personal_data_->profiles(); 651 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
652 ASSERT_EQ(1U, results.size()); 652 ASSERT_EQ(1U, results.size());
653 EXPECT_EQ(0, expected.Compare(*results[0])); 653 EXPECT_EQ(0, expected.Compare(*results[0]));
654 } 654 }
655 655
656 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { 656 TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
657 CreditCard credit_card0; 657 CreditCard credit_card0;
658 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John")); 658 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John"));
659 CreditCard credit_card1; 659 CreditCard credit_card1;
660 credit_card1.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul")); 660 credit_card1.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul"));
661 CreditCard credit_card2; 661 CreditCard credit_card2;
662 credit_card2.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo")); 662 credit_card2.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo"));
663 CreditCard credit_card3; 663 CreditCard credit_card3;
664 credit_card3.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other")); 664 credit_card3.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other"));
665 CreditCard credit_card4; 665 CreditCard credit_card4;
666 credit_card4.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy")); 666 credit_card4.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy"));
667 CreditCard credit_card5; 667 CreditCard credit_card5;
668 credit_card5.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio")); 668 credit_card5.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio"));
669 669
670 // Add the test credit cards to the database. 670 // Add the test credit cards to the database.
671 personal_data_->AddCreditCard(credit_card0); 671 personal_data_->AddCreditCard(credit_card0);
672 personal_data_->AddCreditCard(credit_card1); 672 personal_data_->AddCreditCard(credit_card1);
673 personal_data_->AddCreditCard(credit_card2); 673 personal_data_->AddCreditCard(credit_card2);
674 personal_data_->AddCreditCard(credit_card3); 674 personal_data_->AddCreditCard(credit_card3);
675 personal_data_->AddCreditCard(credit_card4); 675 personal_data_->AddCreditCard(credit_card4);
676 personal_data_->AddCreditCard(credit_card5); 676 personal_data_->AddCreditCard(credit_card5);
677 677
678 // Reset the PersonalDataManager. This tests that the personal data was saved 678 // Reset the PersonalDataManager. This tests that the personal data was saved
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); 974 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
975 MessageLoop::current()->Run(); 975 MessageLoop::current()->Run();
976 976
977 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); 977 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
978 978
979 // Add multi-valued phone number to expectation. Also, country gets added. 979 // Add multi-valued phone number to expectation. Also, country gets added.
980 std::vector<string16> values; 980 std::vector<string16> values;
981 expected.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 981 expected.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
982 values.push_back(ASCIIToUTF16("6502231234")); 982 values.push_back(ASCIIToUTF16("6502231234"));
983 expected.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); 983 expected.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
984 expected.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States")); 984 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"));
985 ASSERT_EQ(1U, results2.size()); 985 ASSERT_EQ(1U, results2.size());
986 EXPECT_EQ(0, expected.Compare(*results2[0])); 986 EXPECT_EQ(0, expected.Compare(*results2[0]));
987 } 987 }
988 988
989 TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) { 989 TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) {
990 FormData form1; 990 FormData form1;
991 FormFieldData field; 991 FormFieldData field;
992 autofill_test::CreateTestFormField( 992 autofill_test::CreateTestFormField(
993 "First name:", "first_name", "George", "text", &field); 993 "First name:", "first_name", "George", "text", &field);
994 form1.fields.push_back(field); 994 form1.fields.push_back(field);
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 1965
1966 // Modify expected to include multi-valued fields. 1966 // Modify expected to include multi-valued fields.
1967 std::vector<string16> values; 1967 std::vector<string16> values;
1968 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values); 1968 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values);
1969 values.push_back(ASCIIToUTF16("214-555-1234")); 1969 values.push_back(ASCIIToUTF16("214-555-1234"));
1970 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values); 1970 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values);
1971 1971
1972 ASSERT_EQ(1U, results2.size()); 1972 ASSERT_EQ(1U, results2.size());
1973 EXPECT_EQ(0, expected.Compare(*results2[0])); 1973 EXPECT_EQ(0, expected.Compare(*results2[0]));
1974 } 1974 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/personal_data_manager_mac.mm ('k') | chrome/browser/autofill/phone_number.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698