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

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

Issue 6903091: Autofill Multi-Value: Additional profiles with same name and address not added to DOM UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/ref_counted.h" 8 #include "base/memory/ref_counted.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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 MessageLoopForUI message_loop_; 80 MessageLoopForUI message_loop_;
81 BrowserThread ui_thread_; 81 BrowserThread ui_thread_;
82 BrowserThread db_thread_; 82 BrowserThread db_thread_;
83 scoped_ptr<TestingProfile> profile_; 83 scoped_ptr<TestingProfile> profile_;
84 scoped_refptr<PersonalDataManager> personal_data_; 84 scoped_refptr<PersonalDataManager> personal_data_;
85 NotificationRegistrar registrar_; 85 NotificationRegistrar registrar_;
86 NotificationObserverMock observer_; 86 NotificationObserverMock observer_;
87 PersonalDataLoadedObserverMock personal_data_observer_; 87 PersonalDataLoadedObserverMock personal_data_observer_;
88 }; 88 };
89 89
90 TEST_F(PersonalDataManagerTest, AddProfile) {
91 AutofillProfile profile0;
92 autofill_test::SetProfileInfo(&profile0,
93 "John", "Mitchell", "Smith",
94 "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
95 "94102", "USA", "4158889999", "4152223333");
96
97 // This will verify that the web database has been loaded and the notification
98 // sent out.
99 EXPECT_CALL(personal_data_observer_,
100 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
101
102 // The message loop will exit when the mock observer is notified.
103 MessageLoop::current()->Run();
Ilya Sherman 2011/04/27 23:32:43 nit: Please move lines 97-103 to the top of the fu
dhollowa 2011/04/28 00:08:46 Done.
104
105 // Add profile0 to the database.
106 personal_data_->AddProfile(profile0);
107
108 // Reload the database.
109 ResetPersonalDataManager();
110 EXPECT_CALL(personal_data_observer_,
111 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
112 MessageLoop::current()->Run();
113
114 // Verify the addition.
115 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
116 ASSERT_EQ(1U, results1.size());
117 EXPECT_EQ(0, profile0.CompareMulti(*results1.at(0)));
118
119 AutofillProfile profile0a;
120 autofill_test::SetProfileInfo(&profile0a,
121 "John", "Mitchell", "Smith",
122 "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
123 "94102", "USA", "4158889999", "4152223333");
124 // Add profile with identical values. Duplicates should not get saved.
125 personal_data_->AddProfile(profile0a);
Ilya Sherman 2011/04/27 23:32:43 nit: Why not just """personal_data_->AddProfile(pr
dhollowa 2011/04/28 00:08:46 To ensure that the same guid values don't cause re
126
127 // Reload the database.
128 ResetPersonalDataManager();
129 EXPECT_CALL(personal_data_observer_,
130 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
131 MessageLoop::current()->Run();
132
133 // Verify the non-addition.
134 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
135 ASSERT_EQ(1U, results2.size());
136 EXPECT_EQ(0, profile0.CompareMulti(*results2.at(0)));
137
138 // New profile with different email.
139 AutofillProfile profile1;
140 autofill_test::SetProfileInfo(&profile1,
141 "John", "Mitchell", "Smith",
142 "john@smith.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
143 "94102", "USA", "4158889999", "4152223333");
Ilya Sherman 2011/04/27 23:32:43 nit: This would be tidier if written as: Autofill
dhollowa 2011/04/28 00:08:46 Done. But the guid has to be accounted for.
144
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
147 // profile with a multi-valued entry for email.
148 personal_data_->AddProfile(profile1);
149
150 // Reload the database.
151 ResetPersonalDataManager();
152 EXPECT_CALL(personal_data_observer_,
153 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop());
154 MessageLoop::current()->Run();
155
156 // Verify the addition.
157 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
158 ASSERT_EQ(2U, results3.size());
159 EXPECT_EQ(0, profile0.CompareMulti(*results3.at(0)));
160 EXPECT_EQ(0, profile1.CompareMulti(*results3.at(1)));
161 }
162
90 // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. 163 // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile.
91 TEST_F(PersonalDataManagerTest, SetProfiles) { 164 TEST_F(PersonalDataManagerTest, SetProfiles) {
92 AutofillProfile profile0; 165 AutofillProfile profile0;
93 autofill_test::SetProfileInfo(&profile0, 166 autofill_test::SetProfileInfo(&profile0,
94 "Marion", "Mitchell", "Morrison", 167 "Marion", "Mitchell", "Morrison",
95 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", 168 "johnwayne@me.xyz", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
96 "91601", "US", "12345678910", "01987654321"); 169 "91601", "US", "12345678910", "01987654321");
97 170
98 AutofillProfile profile1; 171 AutofillProfile profile1;
99 autofill_test::SetProfileInfo(&profile1, 172 autofill_test::SetProfileInfo(&profile1,
(...skipping 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1735 1808
1736 // Expect that the newer information is saved. In this case the year is 1809 // Expect that the newer information is saved. In this case the year is
1737 // added to the existing credit card. 1810 // added to the existing credit card.
1738 CreditCard expected2; 1811 CreditCard expected2;
1739 autofill_test::SetCreditCardInfo(&expected2, 1812 autofill_test::SetCreditCardInfo(&expected2,
1740 "Biggie Smalls", "4111111111111111", "01", "2011"); 1813 "Biggie Smalls", "4111111111111111", "01", "2011");
1741 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); 1814 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1742 ASSERT_EQ(1U, results2.size()); 1815 ASSERT_EQ(1U, results2.size());
1743 EXPECT_EQ(0, expected2.Compare(*results2[0])); 1816 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1744 } 1817 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698