blob: 630b1eb98fb7d6f9d9e47bf2d907bc20b79ed21b [file] [log] [blame]
[email protected]027dd442011-02-15 23:17:341// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]2609bc12010-01-24 08:32:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]42fe7bf22010-12-17 21:44:475#include <string>
6
[email protected]2609bc12010-01-24 08:32:557#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:158#include "base/memory/scoped_ptr.h"
[email protected]2609bc12010-01-24 08:32:559#include "base/message_loop.h"
[email protected]be1ce6a72010-08-03 14:35:2210#include "base/utf_string_conversions.h"
[email protected]468327f2010-10-04 20:02:2911#include "chrome/browser/autofill/autofill_common_test.h"
[email protected]2609bc12010-01-24 08:32:5512#include "chrome/browser/autofill/autofill_profile.h"
[email protected]ce78c1f92010-04-09 02:23:2613#include "chrome/browser/autofill/form_structure.h"
[email protected]2609bc12010-01-24 08:32:5514#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a7e585a2011-08-08 20:32:5415#include "chrome/browser/autofill/personal_data_manager_observer.h"
[email protected]ecbf2892010-07-16 01:51:4516#include "chrome/browser/password_manager/encryptor.h"
[email protected]3eb0d8f72010-12-15 23:38:2517#include "chrome/common/guid.h"
[email protected]bf9257742011-08-11 21:01:1518#include "chrome/test/base/testing_browser_process.h"
[email protected]a4ff9eae2011-08-01 19:58:1619#include "chrome/test/base/testing_profile.h"
[email protected]6c2381d2011-10-19 02:52:5320#include "content/public/browser/notification_details.h"
21#include "content/public/browser/notification_registrar.h"
22#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:1623#include "content/public/browser/notification_types.h"
[email protected]6c2381d2011-10-19 02:52:5324#include "content/test/notification_observer_mock.h"
[email protected]c38831a12011-10-28 12:44:4925#include "content/test/test_browser_thread.h"
[email protected]2609bc12010-01-24 08:32:5526#include "testing/gmock/include/gmock/gmock.h"
27#include "testing/gtest/include/gtest/gtest.h"
[email protected]7b37fbb2011-03-07 16:16:0328#include "webkit/glue/form_data.h"
[email protected]2609bc12010-01-24 08:32:5529
[email protected]631bb742011-11-02 11:29:3930using content::BrowserThread;
[email protected]cea1d112010-07-01 00:57:3331using webkit_glue::FormData;
32
[email protected]2609bc12010-01-24 08:32:5533ACTION(QuitUIMessageLoop) {
[email protected]faec6312010-10-05 03:35:3434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2609bc12010-01-24 08:32:5535 MessageLoop::current()->Quit();
36}
37
[email protected]a7e585a2011-08-08 20:32:5438class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver {
[email protected]2609bc12010-01-24 08:32:5539 public:
40 PersonalDataLoadedObserverMock() {}
41 virtual ~PersonalDataLoadedObserverMock() {}
42
[email protected]3813dec2011-05-11 20:56:3643 MOCK_METHOD0(OnPersonalDataChanged, void());
[email protected]2609bc12010-01-24 08:32:5544};
45
46class PersonalDataManagerTest : public testing::Test {
47 protected:
48 PersonalDataManagerTest()
[email protected]faec6312010-10-05 03:35:3449 : ui_thread_(BrowserThread::UI, &message_loop_),
50 db_thread_(BrowserThread::DB) {
[email protected]2609bc12010-01-24 08:32:5551 }
52
53 virtual void SetUp() {
54 db_thread_.Start();
55
56 profile_.reset(new TestingProfile);
57 profile_->CreateWebDataService(false);
58
[email protected]468327f2010-10-04 20:02:2959 autofill_test::DisableSystemServices(profile_.get());
[email protected]2609bc12010-01-24 08:32:5560 ResetPersonalDataManager();
61 }
62
63 virtual void TearDown() {
[email protected]ea9edcb02011-09-23 22:05:0464 // Destruction order is imposed explicitly here.
65 personal_data_.reset(NULL);
66 profile_.reset(NULL);
[email protected]2609bc12010-01-24 08:32:5567
68 db_thread_.Stop();
[email protected]a778709f2011-12-10 00:28:1769 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
[email protected]2609bc12010-01-24 08:32:5570 MessageLoop::current()->Run();
71 }
72
73 void ResetPersonalDataManager() {
[email protected]ea9edcb02011-09-23 22:05:0474 personal_data_.reset(new PersonalDataManager);
[email protected]e0976a72010-04-02 01:25:2475 personal_data_->Init(profile_.get());
[email protected]2609bc12010-01-24 08:32:5576 personal_data_->SetObserver(&personal_data_observer_);
[email protected]3813dec2011-05-11 20:56:3677
78 // Verify that the web database has been updated and the notification sent.
79 EXPECT_CALL(personal_data_observer_,
80 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
81 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:5582 }
83
[email protected]2609bc12010-01-24 08:32:5584 MessageLoopForUI message_loop_;
[email protected]c38831a12011-10-28 12:44:4985 content::TestBrowserThread ui_thread_;
86 content::TestBrowserThread db_thread_;
[email protected]2609bc12010-01-24 08:32:5587 scoped_ptr<TestingProfile> profile_;
[email protected]ea9edcb02011-09-23 22:05:0488 scoped_ptr<PersonalDataManager> personal_data_;
[email protected]6c2381d2011-10-19 02:52:5389 content::NotificationRegistrar registrar_;
90 content::NotificationObserverMock observer_;
[email protected]2609bc12010-01-24 08:32:5591 PersonalDataLoadedObserverMock personal_data_observer_;
92};
93
[email protected]0ed984b2011-04-28 01:22:0294TEST_F(PersonalDataManagerTest, AddProfile) {
[email protected]0ed984b2011-04-28 01:22:0295 AutofillProfile profile0;
96 autofill_test::SetProfileInfo(&profile0,
97 "John", "Mitchell", "Smith",
98 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
[email protected]4ef55f8c12011-09-17 00:06:5499 "94102", "USA", "4158889999");
[email protected]0ed984b2011-04-28 01:22:02100
101 // Add profile0 to the database.
102 personal_data_->AddProfile(profile0);
103
104 // Reload the database.
105 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02106
107 // Verify the addition.
108 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
109 ASSERT_EQ(1U, results1.size());
[email protected]3813dec2011-05-11 20:56:36110 EXPECT_EQ(0, profile0.CompareMulti(*results1[0]));
[email protected]0ed984b2011-04-28 01:22:02111
112 // Add profile with identical values. Duplicates should not get saved.
113 AutofillProfile profile0a = profile0;
114 profile0a.set_guid(guid::GenerateGUID());
115 personal_data_->AddProfile(profile0a);
116
117 // Reload the database.
118 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02119
120 // Verify the non-addition.
121 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
122 ASSERT_EQ(1U, results2.size());
[email protected]3813dec2011-05-11 20:56:36123 EXPECT_EQ(0, profile0.CompareMulti(*results2[0]));
[email protected]0ed984b2011-04-28 01:22:02124
125 // New profile with different email.
126 AutofillProfile profile1 = profile0;
127 profile1.set_guid(guid::GenerateGUID());
128 profile1.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("[email protected]"));
129
130 // Add the different profile. This should save as a separate profile.
131 // Note that if this same profile was "merged" it would collapse to one
132 // profile with a multi-valued entry for email.
133 personal_data_->AddProfile(profile1);
134
135 // Reload the database.
136 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02137
138 // Verify the addition.
139 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
140 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36141 EXPECT_EQ(0, profile0.CompareMulti(*results3[0]));
142 EXPECT_EQ(0, profile1.CompareMulti(*results3[1]));
[email protected]0ed984b2011-04-28 01:22:02143}
144
[email protected]3813dec2011-05-11 20:56:36145TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) {
[email protected]e90c2252011-03-10 12:29:21146 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29147 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34148 "Marion", "Mitchell", "Morrison",
[email protected]2609bc12010-01-24 08:32:55149 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54150 "91601", "US", "12345678910");
[email protected]2609bc12010-01-24 08:32:55151
[email protected]e90c2252011-03-10 12:29:21152 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29153 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34154 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55155 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54156 "US", "19482937549");
[email protected]2609bc12010-01-24 08:32:55157
[email protected]e90c2252011-03-10 12:29:21158 AutofillProfile profile2;
[email protected]468327f2010-10-04 20:02:29159 autofill_test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34160 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55161 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:54162 "32801", "US", "19482937549");
[email protected]2609bc12010-01-24 08:32:55163
[email protected]542e1992010-07-14 18:25:52164 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36165 personal_data_->AddProfile(profile0);
166 personal_data_->AddProfile(profile1);
167
168 // Verify that the web database has been updated and the notification sent.
169 EXPECT_CALL(personal_data_observer_,
170 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
171 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55172
[email protected]e90c2252011-03-10 12:29:21173 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]2609bc12010-01-24 08:32:55174 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36175 EXPECT_EQ(0, profile0.Compare(*results1[0]));
176 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]2609bc12010-01-24 08:32:55177
[email protected]3813dec2011-05-11 20:56:36178 // Update, remove, and add.
[email protected]1ffe8e992011-03-17 06:26:29179 profile0.SetInfo(NAME_FIRST, ASCIIToUTF16("John"));
[email protected]3813dec2011-05-11 20:56:36180 personal_data_->UpdateProfile(profile0);
181 personal_data_->RemoveProfile(profile1.guid());
182 personal_data_->AddProfile(profile2);
183
184 // Verify that the web database has been updated and the notification sent.
185 EXPECT_CALL(personal_data_observer_,
186 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
187 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55188
[email protected]e90c2252011-03-10 12:29:21189 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]2609bc12010-01-24 08:32:55190 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36191 EXPECT_EQ(0, profile0.Compare(*results2[0]));
192 EXPECT_EQ(0, profile2.Compare(*results2[1]));
[email protected]2609bc12010-01-24 08:32:55193
194 // Reset the PersonalDataManager. This tests that the personal data was saved
195 // to the web database, and that we can load the profiles from the web
196 // database.
197 ResetPersonalDataManager();
198
[email protected]2609bc12010-01-24 08:32:55199 // Verify that we've loaded the profiles from the web database.
[email protected]e90c2252011-03-10 12:29:21200 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
[email protected]2609bc12010-01-24 08:32:55201 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36202 EXPECT_EQ(0, profile0.Compare(*results3[0]));
203 EXPECT_EQ(0, profile2.Compare(*results3[1]));
[email protected]2609bc12010-01-24 08:32:55204}
[email protected]f11f6212010-01-25 20:47:20205
[email protected]3813dec2011-05-11 20:56:36206TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) {
207 CreditCard credit_card0;
208 autofill_test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54209 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]f11f6212010-01-25 20:47:20210
[email protected]3813dec2011-05-11 20:56:36211 CreditCard credit_card1;
212 autofill_test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54213 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]f11f6212010-01-25 20:47:20214
[email protected]3813dec2011-05-11 20:56:36215 CreditCard credit_card2;
216 autofill_test::SetCreditCardInfo(&credit_card2,
[email protected]2a13edd2010-10-26 22:52:54217 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
[email protected]f11f6212010-01-25 20:47:20218
[email protected]542e1992010-07-14 18:25:52219 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36220 personal_data_->AddCreditCard(credit_card0);
221 personal_data_->AddCreditCard(credit_card1);
222
223 // Verify that the web database has been updated and the notification sent.
224 EXPECT_CALL(personal_data_observer_,
225 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
226 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20227
[email protected]f11f6212010-01-25 20:47:20228 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
229 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36230 EXPECT_EQ(0, credit_card0.Compare(*results1[0]));
231 EXPECT_EQ(0, credit_card1.Compare(*results1[1]));
[email protected]f11f6212010-01-25 20:47:20232
[email protected]3813dec2011-05-11 20:56:36233 // Update, remove, and add.
234 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe"));
235 personal_data_->UpdateCreditCard(credit_card0);
236 personal_data_->RemoveCreditCard(credit_card1.guid());
237 personal_data_->AddCreditCard(credit_card2);
238
239 // Verify that the web database has been updated and the notification sent.
240 EXPECT_CALL(personal_data_observer_,
241 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
242 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20243
[email protected]f11f6212010-01-25 20:47:20244 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
245 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36246 EXPECT_EQ(credit_card0, *results2[0]);
247 EXPECT_EQ(credit_card2, *results2[1]);
[email protected]f11f6212010-01-25 20:47:20248
249 // Reset the PersonalDataManager. This tests that the personal data was saved
250 // to the web database, and that we can load the credit cards from the web
251 // database.
252 ResetPersonalDataManager();
253
[email protected]f11f6212010-01-25 20:47:20254 // Verify that we've loaded the credit cards from the web database.
255 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
256 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36257 EXPECT_EQ(credit_card0, *results3[0]);
258 EXPECT_EQ(credit_card2, *results3[1]);
[email protected]f11f6212010-01-25 20:47:20259}
[email protected]e0976a72010-04-02 01:25:24260
[email protected]3813dec2011-05-11 20:56:36261TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) {
[email protected]e90c2252011-03-10 12:29:21262 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29263 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34264 "Marion", "Mitchell", "Morrison",
[email protected]542e1992010-07-14 18:25:52265 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54266 "91601", "US", "12345678910");
[email protected]542e1992010-07-14 18:25:52267
[email protected]e90c2252011-03-10 12:29:21268 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29269 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34270 "Josephine", "Alicia", "Saenz",
[email protected]542e1992010-07-14 18:25:52271 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54272 "US", "19482937549");
[email protected]542e1992010-07-14 18:25:52273
[email protected]3813dec2011-05-11 20:56:36274 CreditCard credit_card0;
275 autofill_test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54276 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]542e1992010-07-14 18:25:52277
[email protected]3813dec2011-05-11 20:56:36278 CreditCard credit_card1;
279 autofill_test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54280 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]542e1992010-07-14 18:25:52281
[email protected]542e1992010-07-14 18:25:52282 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36283 personal_data_->AddProfile(profile0);
284 personal_data_->AddProfile(profile1);
285
286 // Verify that the web database has been updated and the notification sent.
287 EXPECT_CALL(personal_data_observer_,
288 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
289 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52290
[email protected]e90c2252011-03-10 12:29:21291 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]542e1992010-07-14 18:25:52292 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36293 EXPECT_EQ(0, profile0.Compare(*results1[0]));
294 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]414c35482011-02-09 01:26:13295
[email protected]542e1992010-07-14 18:25:52296 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36297 personal_data_->AddCreditCard(credit_card0);
298 personal_data_->AddCreditCard(credit_card1);
[email protected]542e1992010-07-14 18:25:52299
[email protected]3813dec2011-05-11 20:56:36300 // Verify that the web database has been updated and the notification sent.
301 EXPECT_CALL(personal_data_observer_,
302 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
303 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52304
305 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
306 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36307 EXPECT_EQ(credit_card0, *results2[0]);
308 EXPECT_EQ(credit_card1, *results2[1]);
[email protected]542e1992010-07-14 18:25:52309
[email protected]e43783402010-11-04 19:45:04310 // Determine uniqueness by inserting all of the GUIDs into a set and verifying
311 // the size of the set matches the number of GUIDs.
312 std::set<std::string> guids;
313 guids.insert(profile0.guid());
314 guids.insert(profile1.guid());
[email protected]3813dec2011-05-11 20:56:36315 guids.insert(credit_card0.guid());
316 guids.insert(credit_card1.guid());
[email protected]e43783402010-11-04 19:45:04317 EXPECT_EQ(4U, guids.size());
[email protected]542e1992010-07-14 18:25:52318}
319
[email protected]3813dec2011-05-11 20:56:36320// Test for http://crbug.com/50047. Makes sure that guids are populated
321// correctly on load.
[email protected]7c543fd2010-07-24 02:44:59322TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) {
[email protected]e90c2252011-03-10 12:29:21323 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29324 autofill_test::SetProfileInfo(&profile0,
[email protected]4ef55f8c12011-09-17 00:06:54325 "y", "", "", "", "", "", "", "", "", "", "", "");
[email protected]7c543fd2010-07-24 02:44:59326
[email protected]7c543fd2010-07-24 02:44:59327 // Add the profile0 to the db.
[email protected]3813dec2011-05-11 20:56:36328 personal_data_->AddProfile(profile0);
[email protected]7c543fd2010-07-24 02:44:59329
[email protected]3813dec2011-05-11 20:56:36330 // Verify that the web database has been updated and the notification sent.
331 EXPECT_CALL(personal_data_observer_,
332 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]7c543fd2010-07-24 02:44:59333 MessageLoop::current()->Run();
334
335 // Verify that we've loaded the profiles from the web database.
[email protected]e90c2252011-03-10 12:29:21336 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]7c543fd2010-07-24 02:44:59337 ASSERT_EQ(1U, results2.size());
[email protected]3813dec2011-05-11 20:56:36338 EXPECT_EQ(0, profile0.Compare(*results2[0]));
[email protected]7c543fd2010-07-24 02:44:59339
340 // Add a new profile.
[email protected]e90c2252011-03-10 12:29:21341 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29342 autofill_test::SetProfileInfo(&profile1,
[email protected]4ef55f8c12011-09-17 00:06:54343 "z", "", "", "", "", "", "", "", "", "", "", "");
[email protected]3813dec2011-05-11 20:56:36344 personal_data_->AddProfile(profile1);
[email protected]7c543fd2010-07-24 02:44:59345
[email protected]3813dec2011-05-11 20:56:36346 // Verify that the web database has been updated and the notification sent.
347 EXPECT_CALL(personal_data_observer_,
348 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
349 MessageLoop::current()->Run();
350
351 // Make sure the two profiles have different GUIDs, both valid.
[email protected]e90c2252011-03-10 12:29:21352 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
[email protected]7c543fd2010-07-24 02:44:59353 ASSERT_EQ(2U, results3.size());
[email protected]e43783402010-11-04 19:45:04354 EXPECT_NE(results3[0]->guid(), results3[1]->guid());
355 EXPECT_TRUE(guid::IsValidGUID(results3[0]->guid()));
356 EXPECT_TRUE(guid::IsValidGUID(results3[1]->guid()));
[email protected]7c543fd2010-07-24 02:44:59357}
358
[email protected]98a94ee2010-07-12 16:03:22359TEST_F(PersonalDataManagerTest, SetEmptyProfile) {
[email protected]e90c2252011-03-10 12:29:21360 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29361 autofill_test::SetProfileInfo(&profile0,
[email protected]4ef55f8c12011-09-17 00:06:54362 "", "", "", "", "", "", "", "", "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22363
[email protected]98a94ee2010-07-12 16:03:22364 // Add the empty profile to the database.
[email protected]3813dec2011-05-11 20:56:36365 personal_data_->AddProfile(profile0);
[email protected]98a94ee2010-07-12 16:03:22366
[email protected]3813dec2011-05-11 20:56:36367 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22368
369 // Reset the PersonalDataManager. This tests that the personal data was saved
370 // to the web database, and that we can load the profiles from the web
371 // database.
372 ResetPersonalDataManager();
373
[email protected]98a94ee2010-07-12 16:03:22374 // Verify that we've loaded the profiles from the web database.
[email protected]e90c2252011-03-10 12:29:21375 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]98a94ee2010-07-12 16:03:22376 ASSERT_EQ(0U, results2.size());
377}
378
379TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) {
[email protected]3813dec2011-05-11 20:56:36380 CreditCard credit_card0;
381 autofill_test::SetCreditCardInfo(&credit_card0, "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22382
383 // Add the empty credit card to the database.
[email protected]3813dec2011-05-11 20:56:36384 personal_data_->AddCreditCard(credit_card0);
[email protected]98a94ee2010-07-12 16:03:22385
[email protected]3813dec2011-05-11 20:56:36386 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22387
388 // Reset the PersonalDataManager. This tests that the personal data was saved
389 // to the web database, and that we can load the credit cards from the web
390 // database.
391 ResetPersonalDataManager();
392
[email protected]98a94ee2010-07-12 16:03:22393 // Verify that we've loaded the credit cards from the web database.
394 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
395 ASSERT_EQ(0U, results2.size());
396}
397
[email protected]e0976a72010-04-02 01:25:24398TEST_F(PersonalDataManagerTest, Refresh) {
[email protected]e90c2252011-03-10 12:29:21399 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29400 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34401 "Marion", "Mitchell", "Morrison",
[email protected]e0976a72010-04-02 01:25:24402 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54403 "91601", "US", "12345678910");
[email protected]e0976a72010-04-02 01:25:24404
[email protected]e90c2252011-03-10 12:29:21405 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29406 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34407 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24408 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54409 "US", "19482937549");
[email protected]e0976a72010-04-02 01:25:24410
[email protected]e0976a72010-04-02 01:25:24411 // Add the test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36412 personal_data_->AddProfile(profile0);
413 personal_data_->AddProfile(profile1);
[email protected]e0976a72010-04-02 01:25:24414
[email protected]e43783402010-11-04 19:45:04415 // Labels depend on other profiles in the list - update labels manually.
[email protected]e90c2252011-03-10 12:29:21416 std::vector<AutofillProfile *> profile_pointers;
[email protected]9f321442010-10-25 23:53:53417 profile_pointers.push_back(&profile0);
418 profile_pointers.push_back(&profile1);
[email protected]e90c2252011-03-10 12:29:21419 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]e0976a72010-04-02 01:25:24420
[email protected]3813dec2011-05-11 20:56:36421 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24422 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36423 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24424 MessageLoop::current()->Run();
425
[email protected]e90c2252011-03-10 12:29:21426 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]e0976a72010-04-02 01:25:24427 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36428 EXPECT_EQ(profile0, *results1[0]);
429 EXPECT_EQ(profile1, *results1[1]);
[email protected]e0976a72010-04-02 01:25:24430
[email protected]e90c2252011-03-10 12:29:21431 AutofillProfile profile2;
[email protected]61f25cd0e2010-11-07 05:23:50432 autofill_test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34433 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24434 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:54435 "32801", "US", "19482937549");
[email protected]e0976a72010-04-02 01:25:24436
[email protected]9f321442010-10-25 23:53:53437 // Adjust all labels.
[email protected]61f25cd0e2010-11-07 05:23:50438 profile_pointers.push_back(&profile2);
[email protected]e90c2252011-03-10 12:29:21439 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]9f321442010-10-25 23:53:53440
[email protected]e0976a72010-04-02 01:25:24441 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
442 ASSERT_TRUE(wds);
[email protected]e90c2252011-03-10 12:29:21443 wds->AddAutofillProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24444
445 personal_data_->Refresh();
446
[email protected]3813dec2011-05-11 20:56:36447 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24448 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36449 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24450 MessageLoop::current()->Run();
451
[email protected]e90c2252011-03-10 12:29:21452 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]e0976a72010-04-02 01:25:24453 ASSERT_EQ(3U, results2.size());
[email protected]3813dec2011-05-11 20:56:36454 EXPECT_EQ(profile0, *results2[0]);
455 EXPECT_EQ(profile1, *results2[1]);
456 EXPECT_EQ(profile2, *results2[2]);
[email protected]e0976a72010-04-02 01:25:24457
[email protected]e90c2252011-03-10 12:29:21458 wds->RemoveAutofillProfile(profile1.guid());
459 wds->RemoveAutofillProfile(profile2.guid());
[email protected]e0976a72010-04-02 01:25:24460
461 // Before telling the PDM to refresh, simulate an edit to one of the profiles
[email protected]663bd9e2011-03-21 01:07:01462 // via a SetProfile update (this would happen if the Autofill window was
[email protected]e0976a72010-04-02 01:25:24463 // open with a previous snapshot of the profiles, and something [e.g. sync]
464 // removed a profile from the browser. In this edge case, we will end up
465 // in a consistent state by dropping the write).
[email protected]1ffe8e992011-03-17 06:26:29466 profile2.SetInfo(NAME_FIRST, ASCIIToUTF16("Jo"));
[email protected]3813dec2011-05-11 20:56:36467 personal_data_->UpdateProfile(profile0);
468 personal_data_->AddProfile(profile1);
469 personal_data_->AddProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24470
[email protected]3813dec2011-05-11 20:56:36471 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24472 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36473 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24474 MessageLoop::current()->Run();
475
[email protected]e90c2252011-03-10 12:29:21476 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
[email protected]e0976a72010-04-02 01:25:24477 ASSERT_EQ(1U, results3.size());
[email protected]3813dec2011-05-11 20:56:36478 EXPECT_EQ(profile0, *results2[0]);
[email protected]e0976a72010-04-02 01:25:24479}
[email protected]83723f02010-04-07 17:33:10480
[email protected]ce78c1f92010-04-09 02:23:26481TEST_F(PersonalDataManagerTest, ImportFormData) {
[email protected]cea1d112010-07-01 00:57:33482 FormData form;
483 webkit_glue::FormField field;
[email protected]468327f2010-10-04 20:02:29484 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33485 "First name:", "first_name", "George", "text", &field);
486 form.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29487 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33488 "Last name:", "last_name", "Washington", "text", &field);
489 form.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29490 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33491 "Email:", "email", "[email protected]", "text", &field);
492 form.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52493 autofill_test::CreateTestFormField(
494 "Address:", "address1", "21 Laussat St", "text", &field);
495 form.fields.push_back(field);
496 autofill_test::CreateTestFormField(
497 "City:", "city", "San Francisco", "text", &field);
498 form.fields.push_back(field);
499 autofill_test::CreateTestFormField(
500 "State:", "state", "California", "text", &field);
501 form.fields.push_back(field);
502 autofill_test::CreateTestFormField(
503 "Zip:", "zip", "94102", "text", &field);
504 form.fields.push_back(field);
[email protected]ce78c1f92010-04-09 02:23:26505 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55506 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24507 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21508 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
509 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24510 ASSERT_FALSE(imported_credit_card);
[email protected]ce78c1f92010-04-09 02:23:26511
[email protected]3813dec2011-05-11 20:56:36512 // Verify that the web database has been updated and the notification sent.
[email protected]ce78c1f92010-04-09 02:23:26513 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36514 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]ce78c1f92010-04-09 02:23:26515 MessageLoop::current()->Run();
516
[email protected]e90c2252011-03-10 12:29:21517 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34518 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52519 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54520 "San Francisco", "California", "94102", NULL, NULL);
[email protected]e90c2252011-03-10 12:29:21521 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
[email protected]ce78c1f92010-04-09 02:23:26522 ASSERT_EQ(1U, results.size());
[email protected]e43783402010-11-04 19:45:04523 EXPECT_EQ(0, expected.Compare(*results[0]));
[email protected]ce78c1f92010-04-09 02:23:26524}
525
[email protected]a2a1baf2011-02-03 20:22:00526TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) {
527 FormData form;
528 webkit_glue::FormField field;
529 autofill_test::CreateTestFormField(
530 "First name:", "first_name", "George", "text", &field);
531 form.fields.push_back(field);
532 autofill_test::CreateTestFormField(
533 "Last name:", "last_name", "Washington", "text", &field);
534 form.fields.push_back(field);
535 autofill_test::CreateTestFormField(
536 "Email:", "email", "bogus", "text", &field);
537 form.fields.push_back(field);
538 autofill_test::CreateTestFormField(
539 "Address:", "address1", "21 Laussat St", "text", &field);
540 form.fields.push_back(field);
541 autofill_test::CreateTestFormField(
542 "City:", "city", "San Francisco", "text", &field);
543 form.fields.push_back(field);
544 autofill_test::CreateTestFormField(
545 "State:", "state", "California", "text", &field);
546 form.fields.push_back(field);
547 autofill_test::CreateTestFormField(
548 "Zip:", "zip", "94102", "text", &field);
549 form.fields.push_back(field);
550 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55551 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24552 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21553 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
554 &imported_credit_card));
[email protected]ca9bdeb2011-03-17 20:01:41555 ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card);
[email protected]a2a1baf2011-02-03 20:22:00556
[email protected]e90c2252011-03-10 12:29:21557 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
[email protected]ca9bdeb2011-03-17 20:01:41558 ASSERT_EQ(0U, results.size());
[email protected]a2a1baf2011-02-03 20:22:00559}
560
[email protected]204777552011-01-26 19:46:28561TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) {
[email protected]4fb058092010-11-24 23:52:25562 FormData form;
563 webkit_glue::FormField field;
564 autofill_test::CreateTestFormField(
565 "First name:", "first_name", "George", "text", &field);
566 form.fields.push_back(field);
567 autofill_test::CreateTestFormField(
568 "Last name:", "last_name", "Washington", "text", &field);
569 form.fields.push_back(field);
570 autofill_test::CreateTestFormField(
571 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field);
572 form.fields.push_back(field);
573 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55574 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24575 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21576 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
577 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24578 ASSERT_FALSE(imported_credit_card);
[email protected]4fb058092010-11-24 23:52:25579
[email protected]e90c2252011-03-10 12:29:21580 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles();
[email protected]4fb058092010-11-24 23:52:25581 ASSERT_EQ(0U, profiles.size());
582 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
583 ASSERT_EQ(0U, credit_cards.size());
584}
585
[email protected]3aa8bec22010-11-23 07:51:28586TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) {
587 FormData form;
588 webkit_glue::FormField field;
589 autofill_test::CreateTestFormField(
590 "First name:", "first_name", "George", "text", &field);
591 form.fields.push_back(field);
592 autofill_test::CreateTestFormField(
593 "Last name:", "last_name", "Washington", "text", &field);
594 form.fields.push_back(field);
595 autofill_test::CreateTestFormField(
596 "Phone #:", "home_phone_area_code", "650", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04597 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28598 form.fields.push_back(field);
599 autofill_test::CreateTestFormField(
600 "Phone #:", "home_phone_prefix", "555", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04601 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28602 form.fields.push_back(field);
603 autofill_test::CreateTestFormField(
604 "Phone #:", "home_phone_suffix", "0000", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04605 field.max_length = 4;
[email protected]3aa8bec22010-11-23 07:51:28606 form.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52607 autofill_test::CreateTestFormField(
608 "Address:", "address1", "21 Laussat St", "text", &field);
609 form.fields.push_back(field);
610 autofill_test::CreateTestFormField(
611 "City:", "city", "San Francisco", "text", &field);
612 form.fields.push_back(field);
613 autofill_test::CreateTestFormField(
614 "State:", "state", "California", "text", &field);
615 form.fields.push_back(field);
616 autofill_test::CreateTestFormField(
617 "Zip:", "zip", "94102", "text", &field);
618 form.fields.push_back(field);
[email protected]3aa8bec22010-11-23 07:51:28619 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55620 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24621 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21622 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
623 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24624 ASSERT_FALSE(imported_credit_card);
[email protected]3aa8bec22010-11-23 07:51:28625
[email protected]3813dec2011-05-11 20:56:36626 // Verify that the web database has been updated and the notification sent.
[email protected]3aa8bec22010-11-23 07:51:28627 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36628 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]3aa8bec22010-11-23 07:51:28629 MessageLoop::current()->Run();
630
[email protected]e90c2252011-03-10 12:29:21631 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34632 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52633 "Washington", NULL, NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54634 "San Francisco", "California", "94102", NULL, "6505550000");
[email protected]e90c2252011-03-10 12:29:21635 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
[email protected]3aa8bec22010-11-23 07:51:28636 ASSERT_EQ(1U, results.size());
637 EXPECT_EQ(0, expected.Compare(*results[0]));
638}
639
[email protected]47e119f02010-04-15 00:46:55640TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
[email protected]e43783402010-11-04 19:45:04641 CreditCard credit_card0;
[email protected]1ffe8e992011-03-17 06:26:29642 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John"));
[email protected]e43783402010-11-04 19:45:04643 CreditCard credit_card1;
[email protected]1ffe8e992011-03-17 06:26:29644 credit_card1.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul"));
[email protected]e43783402010-11-04 19:45:04645 CreditCard credit_card2;
[email protected]1ffe8e992011-03-17 06:26:29646 credit_card2.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo"));
[email protected]e43783402010-11-04 19:45:04647 CreditCard credit_card3;
[email protected]1ffe8e992011-03-17 06:26:29648 credit_card3.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other"));
[email protected]e43783402010-11-04 19:45:04649 CreditCard credit_card4;
[email protected]1ffe8e992011-03-17 06:26:29650 credit_card4.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy"));
[email protected]e43783402010-11-04 19:45:04651 CreditCard credit_card5;
[email protected]1ffe8e992011-03-17 06:26:29652 credit_card5.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio"));
[email protected]47e119f02010-04-15 00:46:55653
[email protected]98a94ee2010-07-12 16:03:22654 // Add the test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36655 personal_data_->AddCreditCard(credit_card0);
656 personal_data_->AddCreditCard(credit_card1);
657 personal_data_->AddCreditCard(credit_card2);
658 personal_data_->AddCreditCard(credit_card3);
659 personal_data_->AddCreditCard(credit_card4);
660 personal_data_->AddCreditCard(credit_card5);
[email protected]47e119f02010-04-15 00:46:55661
[email protected]18f92d4f2010-10-19 00:14:58662 // Reset the PersonalDataManager. This tests that the personal data was saved
663 // to the web database, and that we can load the credit cards from the web
664 // database.
665 ResetPersonalDataManager();
666
[email protected]47e119f02010-04-15 00:46:55667 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
668 ASSERT_EQ(6U, results.size());
[email protected]027dd442011-02-15 23:17:34669 EXPECT_EQ(credit_card0.guid(), results[0]->guid());
670 EXPECT_EQ(credit_card1.guid(), results[1]->guid());
671 EXPECT_EQ(credit_card2.guid(), results[2]->guid());
672 EXPECT_EQ(credit_card3.guid(), results[3]->guid());
673 EXPECT_EQ(credit_card4.guid(), results[4]->guid());
674 EXPECT_EQ(credit_card5.guid(), results[5]->guid());
[email protected]47e119f02010-04-15 00:46:55675}
[email protected]cea1d112010-07-01 00:57:33676
[email protected]f1ed7272010-11-11 21:57:07677TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) {
678 FormData form1;
[email protected]cea1d112010-07-01 00:57:33679 webkit_glue::FormField field;
[email protected]468327f2010-10-04 20:02:29680 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33681 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07682 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29683 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33684 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07685 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29686 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33687 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07688 form1.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52689 autofill_test::CreateTestFormField(
690 "Address:", "address1", "21 Laussat St", "text", &field);
691 form1.fields.push_back(field);
692 autofill_test::CreateTestFormField(
693 "City:", "city", "San Francisco", "text", &field);
694 form1.fields.push_back(field);
695 autofill_test::CreateTestFormField(
696 "State:", "state", "California", "text", &field);
697 form1.fields.push_back(field);
698 autofill_test::CreateTestFormField(
699 "Zip:", "zip", "94102", "text", &field);
700 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33701
[email protected]f1ed7272010-11-11 21:57:07702 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:55703 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24704 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21705 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
706 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24707 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33708
[email protected]3813dec2011-05-11 20:56:36709 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33710 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36711 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33712 MessageLoop::current()->Run();
713
[email protected]e90c2252011-03-10 12:29:21714 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34715 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52716 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54717 "San Francisco", "California", "94102", NULL, NULL);
[email protected]e90c2252011-03-10 12:29:21718 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:07719 ASSERT_EQ(1U, results1.size());
720 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:33721
722 // Now create a completely different profile.
[email protected]f1ed7272010-11-11 21:57:07723 FormData form2;
[email protected]468327f2010-10-04 20:02:29724 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33725 "First name:", "first_name", "John", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07726 form2.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29727 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33728 "Last name:", "last_name", "Adams", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07729 form2.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29730 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33731 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07732 form2.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52733 autofill_test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24734 "Address:", "address1", "22 Laussat St", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52735 form2.fields.push_back(field);
736 autofill_test::CreateTestFormField(
737 "City:", "city", "San Francisco", "text", &field);
738 form2.fields.push_back(field);
739 autofill_test::CreateTestFormField(
740 "State:", "state", "California", "text", &field);
741 form2.fields.push_back(field);
742 autofill_test::CreateTestFormField(
743 "Zip:", "zip", "94102", "text", &field);
744 form2.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33745
[email protected]f1ed7272010-11-11 21:57:07746 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:55747 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:21748 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
749 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24750 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33751
[email protected]3813dec2011-05-11 20:56:36752 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33753 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36754 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33755 MessageLoop::current()->Run();
756
[email protected]e90c2252011-03-10 12:29:21757 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]cea1d112010-07-01 00:57:33758
[email protected]e90c2252011-03-10 12:29:21759 AutofillProfile expected2;
[email protected]027dd442011-02-15 23:17:34760 autofill_test::SetProfileInfo(&expected2, "John", NULL,
[email protected]023e1822011-04-13 15:52:24761 "Adams", "[email protected]", NULL, "22 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54762 "San Francisco", "California", "94102", NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:07763 ASSERT_EQ(2U, results2.size());
764 EXPECT_EQ(0, expected.Compare(*results2[0]));
765 EXPECT_EQ(0, expected2.Compare(*results2[1]));
766}
[email protected]cea1d112010-07-01 00:57:33767
[email protected]023e1822011-04-13 15:52:24768TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) {
769 FormData form1;
770 webkit_glue::FormField field;
771 autofill_test::CreateTestFormField(
772 "First name:", "first_name", "George", "text", &field);
773 form1.fields.push_back(field);
774 autofill_test::CreateTestFormField(
775 "Last name:", "last_name", "Washington", "text", &field);
776 form1.fields.push_back(field);
777 autofill_test::CreateTestFormField(
778 "Email:", "email", "[email protected]", "text", &field);
779 form1.fields.push_back(field);
780 autofill_test::CreateTestFormField(
781 "Address:", "address1", "21 Laussat St", "text", &field);
782 form1.fields.push_back(field);
783 autofill_test::CreateTestFormField(
784 "City:", "city", "San Francisco", "text", &field);
785 form1.fields.push_back(field);
786 autofill_test::CreateTestFormField(
787 "State:", "state", "California", "text", &field);
788 form1.fields.push_back(field);
789 autofill_test::CreateTestFormField(
790 "Zip:", "zip", "94102", "text", &field);
791 form1.fields.push_back(field);
792
793 FormStructure form_structure1(form1);
794 form_structure1.DetermineHeuristicTypes();
[email protected]023e1822011-04-13 15:52:24795 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21796 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
797 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24798 ASSERT_FALSE(imported_credit_card);
799
[email protected]3813dec2011-05-11 20:56:36800 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24801 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36802 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24803 MessageLoop::current()->Run();
804
805 AutofillProfile expected;
806 autofill_test::SetProfileInfo(&expected, "George", NULL,
807 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54808 "San Francisco", "California", "94102", NULL, NULL);
[email protected]023e1822011-04-13 15:52:24809 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
810 ASSERT_EQ(1U, results1.size());
811 EXPECT_EQ(0, expected.Compare(*results1[0]));
812
813 // Now create a completely different profile.
814 FormData form2;
815 autofill_test::CreateTestFormField(
816 "First name:", "first_name", "John", "text", &field);
817 form2.fields.push_back(field);
818 autofill_test::CreateTestFormField(
819 "Last name:", "last_name", "Adams", "text", &field);
820 form2.fields.push_back(field);
821 autofill_test::CreateTestFormField(
822 "Email:", "email", "[email protected]", "text", &field);
823 form2.fields.push_back(field);
824 autofill_test::CreateTestFormField(
825 "Address:", "address1", "21 Laussat St", "text", &field);
826 form2.fields.push_back(field);
827 autofill_test::CreateTestFormField(
828 "City:", "city", "San Francisco", "text", &field);
829 form2.fields.push_back(field);
830 autofill_test::CreateTestFormField(
831 "State:", "state", "California", "text", &field);
832 form2.fields.push_back(field);
833 autofill_test::CreateTestFormField(
834 "Zip:", "zip", "94102", "text", &field);
835 form2.fields.push_back(field);
836
837 FormStructure form_structure2(form2);
838 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:21839 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
840 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24841 ASSERT_FALSE(imported_credit_card);
842
[email protected]3813dec2011-05-11 20:56:36843 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24844 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36845 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24846 MessageLoop::current()->Run();
847
848 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
849
850 // Modify expected to include multi-valued fields.
851 std::vector<string16> values;
852 expected.GetMultiInfo(NAME_FULL, &values);
853 values.push_back(ASCIIToUTF16("John Adams"));
854 expected.SetMultiInfo(NAME_FULL, values);
855 expected.GetMultiInfo(EMAIL_ADDRESS, &values);
856 values.push_back(ASCIIToUTF16("[email protected]"));
857 expected.SetMultiInfo(EMAIL_ADDRESS, values);
858
859 ASSERT_EQ(1U, results2.size());
860 EXPECT_EQ(0, expected.CompareMulti(*results2[0]));
861}
862
[email protected]f1ed7272010-11-11 21:57:07863TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) {
864 FormData form1;
865 webkit_glue::FormField field;
[email protected]468327f2010-10-04 20:02:29866 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33867 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07868 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29869 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33870 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07871 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29872 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:07873 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
874 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29875 autofill_test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:34876 "Address Line 2:", "address2", "Suite A", "text", &field);
877 form1.fields.push_back(field);
878 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52879 "City:", "city", "San Francisco", "text", &field);
880 form1.fields.push_back(field);
881 autofill_test::CreateTestFormField(
882 "State:", "state", "California", "text", &field);
883 form1.fields.push_back(field);
884 autofill_test::CreateTestFormField(
885 "Zip:", "zip", "94102", "text", &field);
886 form1.fields.push_back(field);
887 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:07888 "Email:", "email", "[email protected]", "text", &field);
889 form1.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:34890 // Phone gets updated.
891 autofill_test::CreateTestFormField(
[email protected]11c2bdd12011-05-23 18:24:32892 "Phone:", "phone", "6505556666", "text", &field);
[email protected]465d07f2010-11-30 04:52:34893 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33894
[email protected]f1ed7272010-11-11 21:57:07895 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:55896 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24897 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21898 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
899 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24900 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33901
[email protected]3813dec2011-05-11 20:56:36902 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33903 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36904 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33905 MessageLoop::current()->Run();
906
[email protected]e90c2252011-03-10 12:29:21907 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34908 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]465d07f2010-11-30 04:52:34909 "Washington", "[email protected]", NULL, "1600 Pennsylvania Avenue",
[email protected]4ef55f8c12011-09-17 00:06:54910 "Suite A", "San Francisco", "California", "94102", NULL, "4085556666");
[email protected]e90c2252011-03-10 12:29:21911 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:07912 ASSERT_EQ(1U, results1.size());
913 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:33914
[email protected]f1ed7272010-11-11 21:57:07915 // Now create an updated profile.
916 FormData form2;
917 autofill_test::CreateTestFormField(
918 "First name:", "first_name", "George", "text", &field);
919 form2.fields.push_back(field);
920 autofill_test::CreateTestFormField(
921 "Last name:", "last_name", "Washington", "text", &field);
922 form2.fields.push_back(field);
923 autofill_test::CreateTestFormField(
924 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
925 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:34926 autofill_test::CreateTestFormField(
927 "Address Line 2:", "address2", "Suite A", "text", &field);
928 form2.fields.push_back(field);
929 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52930 "City:", "city", "San Francisco", "text", &field);
931 form2.fields.push_back(field);
932 autofill_test::CreateTestFormField(
933 "State:", "state", "California", "text", &field);
934 form2.fields.push_back(field);
935 autofill_test::CreateTestFormField(
936 "Zip:", "zip", "94102", "text", &field);
937 form2.fields.push_back(field);
938 autofill_test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:34939 "Email:", "email", "[email protected]", "text", &field);
940 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:07941 // Country gets added.
942 autofill_test::CreateTestFormField(
943 "Country:", "country", "USA", "text", &field);
944 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:34945 // Phone gets updated.
[email protected]f1ed7272010-11-11 21:57:07946 autofill_test::CreateTestFormField(
[email protected]11c2bdd12011-05-23 18:24:32947 "Phone:", "phone", "6502231234", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07948 form2.fields.push_back(field);
949
950 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:55951 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:21952 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
953 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24954 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:07955
[email protected]3813dec2011-05-11 20:56:36956 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:07957 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36958 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:07959 MessageLoop::current()->Run();
960
[email protected]e90c2252011-03-10 12:29:21961 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:07962
[email protected]023e1822011-04-13 15:52:24963 // Add multi-valued phone number to expectation. Also, country gets added.
964 std::vector<string16> values;
965 expected.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
[email protected]11c2bdd12011-05-23 18:24:32966 values.push_back(ASCIIToUTF16("6502231234"));
[email protected]023e1822011-04-13 15:52:24967 expected.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
968 expected.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"));
[email protected]f1ed7272010-11-11 21:57:07969 ASSERT_EQ(1U, results2.size());
[email protected]023e1822011-04-13 15:52:24970 EXPECT_EQ(0, expected.CompareMulti(*results2[0]));
[email protected]f1ed7272010-11-11 21:57:07971}
972
973TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) {
974 FormData form1;
975 webkit_glue::FormField field;
976 autofill_test::CreateTestFormField(
977 "First name:", "first_name", "George", "text", &field);
978 form1.fields.push_back(field);
979 autofill_test::CreateTestFormField(
980 "Last name:", "last_name", "Washington", "text", &field);
981 form1.fields.push_back(field);
982 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52983 "Address Line 1:", "address", "190 High Street", "text", &field);
984 form1.fields.push_back(field);
985 autofill_test::CreateTestFormField(
986 "City:", "city", "Philadelphia", "text", &field);
987 form1.fields.push_back(field);
988 autofill_test::CreateTestFormField(
989 "State:", "state", "Pennsylvania", "text", &field);
990 form1.fields.push_back(field);
991 autofill_test::CreateTestFormField(
992 "Zip:", "zipcode", "19106", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07993 form1.fields.push_back(field);
994
995 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:55996 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24997 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21998 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
999 &imported_credit_card));
[email protected]a73830e2011-10-05 01:12:581000 EXPECT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071001
[email protected]3813dec2011-05-11 20:56:361002 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071003 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361004 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071005 MessageLoop::current()->Run();
1006
[email protected]e90c2252011-03-10 12:29:211007 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:341008 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521009 "Washington", NULL, NULL, "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541010 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]e90c2252011-03-10 12:29:211011 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071012 ASSERT_EQ(1U, results1.size());
1013 EXPECT_EQ(0, expected.Compare(*results1[0]));
1014
1015 // Submit a form with new data for the first profile.
1016 FormData form2;
1017 autofill_test::CreateTestFormField(
1018 "First name:", "first_name", "George", "text", &field);
1019 form2.fields.push_back(field);
1020 autofill_test::CreateTestFormField(
1021 "Last name:", "last_name", "Washington", "text", &field);
1022 form2.fields.push_back(field);
1023 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521024 "Email:", "email", "[email protected]", "text", &field);
1025 form2.fields.push_back(field);
1026 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071027 "Address Line 1:", "address", "190 High Street", "text", &field);
1028 form2.fields.push_back(field);
1029 autofill_test::CreateTestFormField(
1030 "City:", "city", "Philadelphia", "text", &field);
1031 form2.fields.push_back(field);
1032 autofill_test::CreateTestFormField(
1033 "State:", "state", "Pennsylvania", "text", &field);
1034 form2.fields.push_back(field);
1035 autofill_test::CreateTestFormField(
1036 "Zip:", "zipcode", "19106", "text", &field);
1037 form2.fields.push_back(field);
1038
1039 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551040 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211041 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1042 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241043 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071044
[email protected]3813dec2011-05-11 20:56:361045 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071046 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361047 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071048 MessageLoop::current()->Run();
1049
[email protected]e90c2252011-03-10 12:29:211050 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071051
[email protected]e90c2252011-03-10 12:29:211052 AutofillProfile expected2;
[email protected]027dd442011-02-15 23:17:341053 autofill_test::SetProfileInfo(&expected2, "George", NULL,
[email protected]cea1d112010-07-01 00:57:331054 "Washington", "[email protected]", NULL, "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541055 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:071056 ASSERT_EQ(1U, results2.size());
1057 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1058}
[email protected]cea1d112010-07-01 00:57:331059
[email protected]f1ed7272010-11-11 21:57:071060TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) {
1061 FormData form1;
1062 webkit_glue::FormField field;
1063 autofill_test::CreateTestFormField(
1064 "First name:", "first_name", "George", "text", &field);
1065 form1.fields.push_back(field);
1066 autofill_test::CreateTestFormField(
1067 "Last name:", "last_name", "Washington", "text", &field);
1068 form1.fields.push_back(field);
1069 autofill_test::CreateTestFormField(
1070 "Company:", "company", "Government", "text", &field);
1071 form1.fields.push_back(field);
1072 autofill_test::CreateTestFormField(
1073 "Email:", "email", "[email protected]", "text", &field);
1074 form1.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:521075 autofill_test::CreateTestFormField(
1076 "Address Line 1:", "address", "190 High Street", "text", &field);
1077 form1.fields.push_back(field);
1078 autofill_test::CreateTestFormField(
1079 "City:", "city", "Philadelphia", "text", &field);
1080 form1.fields.push_back(field);
1081 autofill_test::CreateTestFormField(
1082 "State:", "state", "Pennsylvania", "text", &field);
1083 form1.fields.push_back(field);
1084 autofill_test::CreateTestFormField(
1085 "Zip:", "zipcode", "19106", "text", &field);
1086 form1.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071087
1088 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551089 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241090 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211091 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1092 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241093 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071094
[email protected]3813dec2011-05-11 20:56:361095 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071096 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361097 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071098 MessageLoop::current()->Run();
1099
[email protected]e90c2252011-03-10 12:29:211100 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:341101 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521102 "Washington", "[email protected]", "Government", "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541103 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]e90c2252011-03-10 12:29:211104 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071105 ASSERT_EQ(1U, results1.size());
1106 EXPECT_EQ(0, expected.Compare(*results1[0]));
1107
1108 // Submit a form with new data for the first profile.
1109 FormData form2;
1110 autofill_test::CreateTestFormField(
1111 "First name:", "first_name", "George", "text", &field);
1112 form2.fields.push_back(field);
1113 autofill_test::CreateTestFormField(
1114 "Last name:", "last_name", "Washington", "text", &field);
1115 form2.fields.push_back(field);
1116 // Note missing Company field.
1117 autofill_test::CreateTestFormField(
1118 "Email:", "email", "[email protected]", "text", &field);
1119 form2.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:521120 autofill_test::CreateTestFormField(
1121 "Address Line 1:", "address", "190 High Street", "text", &field);
1122 form2.fields.push_back(field);
1123 autofill_test::CreateTestFormField(
1124 "City:", "city", "Philadelphia", "text", &field);
1125 form2.fields.push_back(field);
1126 autofill_test::CreateTestFormField(
1127 "State:", "state", "Pennsylvania", "text", &field);
1128 form2.fields.push_back(field);
1129 autofill_test::CreateTestFormField(
1130 "Zip:", "zipcode", "19106", "text", &field);
1131 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071132
1133 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551134 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211135 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1136 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241137 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071138
[email protected]3813dec2011-05-11 20:56:361139 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071140 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361141 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071142 MessageLoop::current()->Run();
1143
[email protected]e90c2252011-03-10 12:29:211144 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071145
1146 // Expect no change.
1147 ASSERT_EQ(1U, results2.size());
1148 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]cea1d112010-07-01 00:57:331149}
[email protected]d7da65d2010-11-11 19:26:051150
[email protected]37ff612e2011-02-03 15:54:521151TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) {
1152 FormData form1;
1153 webkit_glue::FormField field;
1154 autofill_test::CreateTestFormField(
1155 "First name:", "first_name", "George", "text", &field);
1156 form1.fields.push_back(field);
1157 autofill_test::CreateTestFormField(
1158 "Last name:", "last_name", "Washington", "text", &field);
1159 form1.fields.push_back(field);
1160 autofill_test::CreateTestFormField(
1161 "Company:", "company", "Government", "text", &field);
1162 form1.fields.push_back(field);
1163 autofill_test::CreateTestFormField(
1164 "Email:", "email", "[email protected]", "text", &field);
1165 form1.fields.push_back(field);
1166 autofill_test::CreateTestFormField(
1167 "Address Line 1:", "address", "190 High Street", "text", &field);
1168 form1.fields.push_back(field);
1169 autofill_test::CreateTestFormField(
1170 "City:", "city", "Philadelphia", "text", &field);
1171 form1.fields.push_back(field);
1172
1173 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551174 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241175 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211176 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1,
1177 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241178 ASSERT_FALSE(imported_credit_card);
[email protected]414c35482011-02-09 01:26:131179
[email protected]3813dec2011-05-11 20:56:361180 // Note: no refresh here.
[email protected]414c35482011-02-09 01:26:131181
[email protected]e90c2252011-03-10 12:29:211182 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles();
[email protected]414c35482011-02-09 01:26:131183 ASSERT_EQ(0U, profiles.size());
1184 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
1185 ASSERT_EQ(0U, credit_cards.size());
[email protected]37ff612e2011-02-03 15:54:521186}
1187
[email protected]0b5847612011-10-05 03:52:181188TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) {
1189 // Simulate having access to an auxiliary profile.
1190 // |auxiliary_profile| will be owned by |personal_data_|.
1191 AutofillProfile* auxiliary_profile = new AutofillProfile;
1192 autofill_test::SetProfileInfo(auxiliary_profile,
1193 "Tester", "Frederick", "McAddressBookTesterson",
1194 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco",
1195 "CA", "94102", "USA", "1.415.888.9999");
1196 ScopedVector<AutofillProfile>& auxiliary_profiles =
1197 personal_data_->auxiliary_profiles_;
1198 auxiliary_profiles.push_back(auxiliary_profile);
1199
1200 // Simulate a form submission with a subset of the info.
1201 // Note that the phone number format is different from the saved format.
1202 FormData form;
1203 webkit_glue::FormField field;
1204 autofill_test::CreateTestFormField(
1205 "First name:", "first_name", "Tester", "text", &field);
1206 form.fields.push_back(field);
1207 autofill_test::CreateTestFormField(
1208 "Last name:", "last_name", "McAddressBookTesterson", "text", &field);
1209 form.fields.push_back(field);
1210 autofill_test::CreateTestFormField(
1211 "Email:", "email", "[email protected]", "text", &field);
1212 form.fields.push_back(field);
1213 autofill_test::CreateTestFormField(
1214 "Address:", "address1", "1 Main", "text", &field);
1215 form.fields.push_back(field);
1216 autofill_test::CreateTestFormField(
1217 "City:", "city", "San Francisco", "text", &field);
1218 form.fields.push_back(field);
1219 autofill_test::CreateTestFormField(
1220 "State:", "state", "CA", "text", &field);
1221 form.fields.push_back(field);
1222 autofill_test::CreateTestFormField(
1223 "Zip:", "zip", "94102", "text", &field);
1224 form.fields.push_back(field);
1225 autofill_test::CreateTestFormField(
1226 "Phone:", "phone", "4158889999", "text", &field);
1227 form.fields.push_back(field);
1228
1229 FormStructure form_structure(form);
1230 form_structure.DetermineHeuristicTypes();
1231 const CreditCard* imported_credit_card;
1232 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
1233 &imported_credit_card));
1234 EXPECT_FALSE(imported_credit_card);
1235
1236 // Note: No refresh.
1237
1238 // Expect no change.
1239 const std::vector<AutofillProfile*>& web_profiles =
1240 personal_data_->web_profiles();
1241 EXPECT_EQ(0U, web_profiles.size());
1242 ASSERT_EQ(1U, auxiliary_profiles.size());
1243 EXPECT_EQ(0, auxiliary_profile->Compare(*auxiliary_profiles[0]));
1244}
1245
[email protected]d7da65d2010-11-11 19:26:051246TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) {
1247 FormData form1;
1248
1249 // Start with a single valid credit card form.
1250 webkit_glue::FormField field;
1251 autofill_test::CreateTestFormField(
1252 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1253 form1.fields.push_back(field);
1254 autofill_test::CreateTestFormField(
1255 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1256 form1.fields.push_back(field);
1257 autofill_test::CreateTestFormField(
1258 "Exp Month:", "exp_month", "01", "text", &field);
1259 form1.fields.push_back(field);
1260 autofill_test::CreateTestFormField(
1261 "Exp Year:", "exp_year", "2011", "text", &field);
1262 form1.fields.push_back(field);
1263
1264 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551265 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241266 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211267 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1268 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241269 ASSERT_TRUE(imported_credit_card);
1270 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1271 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051272
[email protected]3813dec2011-05-11 20:56:361273 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051274 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361275 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051276 MessageLoop::current()->Run();
1277
1278 CreditCard expected;
1279 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341280 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051281 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1282 ASSERT_EQ(1U, results.size());
1283 EXPECT_EQ(0, expected.Compare(*results[0]));
1284
1285 // Add a second different valid credit card.
1286 FormData form2;
1287 autofill_test::CreateTestFormField(
[email protected]490a6a502011-09-27 17:30:111288 "Name on card:", "name_on_card", "", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051289 form2.fields.push_back(field);
1290 autofill_test::CreateTestFormField(
1291 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field);
1292 form2.fields.push_back(field);
1293 autofill_test::CreateTestFormField(
1294 "Exp Month:", "exp_month", "02", "text", &field);
1295 form2.fields.push_back(field);
1296 autofill_test::CreateTestFormField(
1297 "Exp Year:", "exp_year", "2012", "text", &field);
1298 form2.fields.push_back(field);
1299
1300 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551301 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211302 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1303 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241304 ASSERT_TRUE(imported_credit_card);
1305 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1306 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051307
[email protected]3813dec2011-05-11 20:56:361308 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051309 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361310 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051311 MessageLoop::current()->Run();
1312
1313 CreditCard expected2;
1314 autofill_test::SetCreditCardInfo(&expected2,
[email protected]490a6a502011-09-27 17:30:111315 "", "5500000000000004", "02", "2012");
[email protected]d7da65d2010-11-11 19:26:051316 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1317 ASSERT_EQ(2U, results2.size());
1318 EXPECT_EQ(0, expected.Compare(*results2[0]));
1319 EXPECT_EQ(0, expected2.Compare(*results2[1]));
1320}
1321
1322TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) {
1323 FormData form1;
1324
1325 // Start with a single valid credit card form.
1326 webkit_glue::FormField field;
1327 autofill_test::CreateTestFormField(
1328 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1329 form1.fields.push_back(field);
1330 autofill_test::CreateTestFormField(
1331 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1332 form1.fields.push_back(field);
1333 autofill_test::CreateTestFormField(
1334 "Exp Month:", "exp_month", "01", "text", &field);
1335 form1.fields.push_back(field);
1336 autofill_test::CreateTestFormField(
1337 "Exp Year:", "exp_year", "2011", "text", &field);
1338 form1.fields.push_back(field);
1339
1340 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551341 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241342 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211343 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1344 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241345 ASSERT_TRUE(imported_credit_card);
1346 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1347 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051348
[email protected]3813dec2011-05-11 20:56:361349 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051350 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361351 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051352 MessageLoop::current()->Run();
1353
1354 CreditCard expected;
1355 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341356 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051357 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1358 ASSERT_EQ(1U, results.size());
1359 EXPECT_EQ(0, expected.Compare(*results[0]));
1360
1361 // Add a second different invalid credit card.
1362 FormData form2;
1363 autofill_test::CreateTestFormField(
1364 "Name on card:", "name_on_card", "Jim Johansen", "text", &field);
1365 form2.fields.push_back(field);
1366 autofill_test::CreateTestFormField(
1367 "Card Number:", "card_number", "1000000000000000", "text", &field);
1368 form2.fields.push_back(field);
1369 autofill_test::CreateTestFormField(
1370 "Exp Month:", "exp_month", "02", "text", &field);
1371 form2.fields.push_back(field);
1372 autofill_test::CreateTestFormField(
1373 "Exp Year:", "exp_year", "2012", "text", &field);
1374 form2.fields.push_back(field);
1375
1376 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551377 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211378 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1379 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241380 ASSERT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051381
1382 // Note: no refresh here.
1383
1384 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1385 ASSERT_EQ(1U, results2.size());
1386 EXPECT_EQ(0, expected.Compare(*results2[0]));
1387}
1388
1389TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) {
1390 FormData form1;
1391
1392 // Start with a single valid credit card form.
1393 webkit_glue::FormField field;
1394 autofill_test::CreateTestFormField(
1395 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1396 form1.fields.push_back(field);
1397 autofill_test::CreateTestFormField(
1398 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1399 form1.fields.push_back(field);
1400 autofill_test::CreateTestFormField(
1401 "Exp Month:", "exp_month", "01", "text", &field);
1402 form1.fields.push_back(field);
1403 autofill_test::CreateTestFormField(
1404 "Exp Year:", "exp_year", "2011", "text", &field);
1405 form1.fields.push_back(field);
1406
1407 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551408 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241409 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211410 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1411 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241412 ASSERT_TRUE(imported_credit_card);
1413 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1414 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051415
[email protected]3813dec2011-05-11 20:56:361416 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051417 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361418 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051419 MessageLoop::current()->Run();
1420
1421 CreditCard expected;
1422 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341423 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051424 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1425 ASSERT_EQ(1U, results.size());
1426 EXPECT_EQ(0, expected.Compare(*results[0]));
1427
1428 // Add a second different valid credit card where the year is different but
1429 // the credit card number matches.
1430 FormData form2;
1431 autofill_test::CreateTestFormField(
1432 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1433 form2.fields.push_back(field);
1434 autofill_test::CreateTestFormField(
1435 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field);
1436 form2.fields.push_back(field);
1437 autofill_test::CreateTestFormField(
1438 "Exp Month:", "exp_month", "01", "text", &field);
1439 form2.fields.push_back(field);
1440 autofill_test::CreateTestFormField(
1441 "Exp Year:", "exp_year", "2012", "text", &field);
1442 form2.fields.push_back(field);
1443
1444 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551445 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211446 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1447 &imported_credit_card));
[email protected]e5f5cf72011-10-04 22:18:061448 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051449
[email protected]3813dec2011-05-11 20:56:361450 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051451 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361452 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051453 MessageLoop::current()->Run();
1454
1455 // Expect that the newer information is saved. In this case the year is
1456 // updated to "2012".
1457 CreditCard expected2;
1458 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341459 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051460 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1461 ASSERT_EQ(1U, results2.size());
1462 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1463}
1464
1465TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) {
1466 FormData form1;
1467
1468 // Start with a single valid credit card form.
1469 webkit_glue::FormField field;
1470 autofill_test::CreateTestFormField(
1471 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1472 form1.fields.push_back(field);
1473 autofill_test::CreateTestFormField(
1474 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1475 form1.fields.push_back(field);
1476 autofill_test::CreateTestFormField(
1477 "Exp Month:", "exp_month", "01", "text", &field);
1478 form1.fields.push_back(field);
1479 autofill_test::CreateTestFormField(
1480 "Exp Year:", "exp_year", "2011", "text", &field);
1481 form1.fields.push_back(field);
1482
1483 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551484 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241485 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211486 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1487 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241488 ASSERT_TRUE(imported_credit_card);
1489 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1490 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051491
[email protected]3813dec2011-05-11 20:56:361492 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051493 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361494 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051495 MessageLoop::current()->Run();
1496
1497 CreditCard expected;
1498 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341499 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051500 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1501 ASSERT_EQ(1U, results.size());
1502 EXPECT_EQ(0, expected.Compare(*results[0]));
1503
1504 // Add a second credit card with no number.
1505 FormData form2;
1506 autofill_test::CreateTestFormField(
1507 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1508 form2.fields.push_back(field);
1509 autofill_test::CreateTestFormField(
1510 "Exp Month:", "exp_month", "01", "text", &field);
1511 form2.fields.push_back(field);
1512 autofill_test::CreateTestFormField(
1513 "Exp Year:", "exp_year", "2012", "text", &field);
1514 form2.fields.push_back(field);
1515
1516 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551517 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211518 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1519 &imported_credit_card));
[email protected]3e6e82da2011-04-06 05:41:341520 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051521
1522 // Note: no refresh here.
1523
1524 // No change is expected.
1525 CreditCard expected2;
1526 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341527 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051528 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1529 ASSERT_EQ(1U, results2.size());
1530 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1531}
1532
1533TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) {
1534 FormData form1;
1535
1536 // Start with a single valid credit card form.
1537 webkit_glue::FormField field;
1538 autofill_test::CreateTestFormField(
1539 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1540 form1.fields.push_back(field);
1541 autofill_test::CreateTestFormField(
1542 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1543 form1.fields.push_back(field);
1544 autofill_test::CreateTestFormField(
1545 "Exp Month:", "exp_month", "01", "text", &field);
1546 form1.fields.push_back(field);
1547 autofill_test::CreateTestFormField(
1548 "Exp Year:", "exp_year", "2011", "text", &field);
1549 form1.fields.push_back(field);
1550
1551 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551552 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241553 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211554 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1555 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241556 ASSERT_TRUE(imported_credit_card);
1557 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1558 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051559
[email protected]3813dec2011-05-11 20:56:361560 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051561 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361562 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051563 MessageLoop::current()->Run();
1564
1565 CreditCard expected;
1566 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341567 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051568 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1569 ASSERT_EQ(1U, results.size());
1570 EXPECT_EQ(0, expected.Compare(*results[0]));
1571
1572 // Add a second different valid credit card where the name is missing but
1573 // the credit card number matches.
1574 FormData form2;
1575 // Note missing name.
1576 autofill_test::CreateTestFormField(
1577 "Card Number:", "card_number", "4111111111111111", "text", &field);
1578 form2.fields.push_back(field);
1579 autofill_test::CreateTestFormField(
1580 "Exp Month:", "exp_month", "01", "text", &field);
1581 form2.fields.push_back(field);
1582 autofill_test::CreateTestFormField(
1583 "Exp Year:", "exp_year", "2011", "text", &field);
1584 form2.fields.push_back(field);
1585
1586 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551587 form_structure2.DetermineHeuristicTypes();
[email protected]e5f5cf72011-10-04 22:18:061588 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1589 &imported_credit_card));
1590 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051591
[email protected]e5f5cf72011-10-04 22:18:061592 // Wait for the refresh, which in this case is a no-op.
1593 EXPECT_CALL(personal_data_observer_,
1594 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1595 MessageLoop::current()->Run();
[email protected]d7da65d2010-11-11 19:26:051596
1597 // No change is expected.
1598 CreditCard expected2;
1599 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341600 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051601 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1602 ASSERT_EQ(1U, results2.size());
1603 EXPECT_EQ(0, expected2.Compare(*results2[0]));
[email protected]cdd0d4482011-07-22 04:24:221604
1605 // Add a third credit card where the expiration date is missing.
1606 FormData form3;
1607 autofill_test::CreateTestFormField(
1608 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field);
1609 form3.fields.push_back(field);
1610 autofill_test::CreateTestFormField(
1611 "Card Number:", "card_number", "5555555555554444", "text", &field);
1612 form3.fields.push_back(field);
1613 // Note missing expiration month and year..
1614
1615 FormStructure form_structure3(form3);
1616 form_structure3.DetermineHeuristicTypes();
1617 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3,
1618 &imported_credit_card));
1619 ASSERT_FALSE(imported_credit_card);
1620
1621 // Note: no refresh here.
1622
1623 // No change is expected.
1624 CreditCard expected3;
1625 autofill_test::SetCreditCardInfo(&expected3,
1626 "Biggie Smalls", "4111111111111111", "01", "2011");
1627 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
1628 ASSERT_EQ(1U, results3.size());
1629 EXPECT_EQ(0, expected3.Compare(*results2[0]));
[email protected]d7da65d2010-11-11 19:26:051630}
1631
1632TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) {
[email protected]cdd0d4482011-07-22 04:24:221633 // Start with a single valid credit card stored via the preferences.
1634 // Note the empty name.
1635 CreditCard saved_credit_card;
1636 autofill_test::SetCreditCardInfo(&saved_credit_card,
1637 "", "4111111111111111" /* Visa */, "01", "2011");
1638 personal_data_->AddCreditCard(saved_credit_card);
[email protected]d7da65d2010-11-11 19:26:051639
[email protected]3813dec2011-05-11 20:56:361640 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051641 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361642 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051643 MessageLoop::current()->Run();
1644
[email protected]cdd0d4482011-07-22 04:24:221645 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1646 ASSERT_EQ(1U, results1.size());
1647 EXPECT_EQ(saved_credit_card, *results1[0]);
1648
[email protected]d7da65d2010-11-11 19:26:051649
1650 // Add a second different valid credit card where the year is different but
1651 // the credit card number matches.
[email protected]cdd0d4482011-07-22 04:24:221652 FormData form;
1653 webkit_glue::FormField field;
[email protected]d7da65d2010-11-11 19:26:051654 autofill_test::CreateTestFormField(
1655 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221656 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051657 autofill_test::CreateTestFormField(
1658 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221659 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051660 autofill_test::CreateTestFormField(
1661 "Exp Month:", "exp_month", "01", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221662 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051663 autofill_test::CreateTestFormField(
[email protected]cdd0d4482011-07-22 04:24:221664 "Exp Year:", "exp_year", "2012", "text", &field);
1665 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051666
[email protected]cdd0d4482011-07-22 04:24:221667 FormStructure form_structure(form);
1668 form_structure.DetermineHeuristicTypes();
1669 const CreditCard* imported_credit_card;
1670 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
[email protected]2a958552011-05-05 04:01:211671 &imported_credit_card));
[email protected]e5f5cf72011-10-04 22:18:061672 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051673
[email protected]3813dec2011-05-11 20:56:361674 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051675 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361676 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051677 MessageLoop::current()->Run();
1678
1679 // Expect that the newer information is saved. In this case the year is
1680 // added to the existing credit card.
1681 CreditCard expected2;
1682 autofill_test::SetCreditCardInfo(&expected2,
[email protected]cdd0d4482011-07-22 04:24:221683 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051684 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1685 ASSERT_EQ(1U, results2.size());
1686 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1687}
[email protected]ca64d232011-05-06 05:46:001688
[email protected]e5f5cf72011-10-04 22:18:061689// We allow the user to store a credit card number with separators via the UI.
1690// We should not try to re-aggregate the same card with the separators stripped.
1691TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) {
1692 // Start with a single valid credit card stored via the preferences.
1693 // Note the separators in the credit card number.
1694 CreditCard saved_credit_card;
1695 autofill_test::SetCreditCardInfo(&saved_credit_card,
1696 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011");
1697 personal_data_->AddCreditCard(saved_credit_card);
1698
1699 // Verify that the web database has been updated and the notification sent.
1700 EXPECT_CALL(personal_data_observer_,
1701 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1702 MessageLoop::current()->Run();
1703
1704 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1705 ASSERT_EQ(1U, results1.size());
1706 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0]));
1707
1708 // Import the same card info, but with different separators in the number.
1709 FormData form;
1710 webkit_glue::FormField field;
1711 autofill_test::CreateTestFormField(
1712 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1713 form.fields.push_back(field);
1714 autofill_test::CreateTestFormField(
1715 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1716 form.fields.push_back(field);
1717 autofill_test::CreateTestFormField(
1718 "Exp Month:", "exp_month", "01", "text", &field);
1719 form.fields.push_back(field);
1720 autofill_test::CreateTestFormField(
1721 "Exp Year:", "exp_year", "2011", "text", &field);
1722 form.fields.push_back(field);
1723
1724 FormStructure form_structure(form);
1725 form_structure.DetermineHeuristicTypes();
1726 const CreditCard* imported_credit_card;
1727 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
1728 &imported_credit_card));
1729 EXPECT_FALSE(imported_credit_card);
1730
1731 // Wait for the refresh, which in this case is a no-op.
1732 EXPECT_CALL(personal_data_observer_,
1733 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1734 MessageLoop::current()->Run();
1735
1736 // Expect that no new card is saved.
1737 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1738 ASSERT_EQ(1U, results2.size());
1739 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0]));
1740}
1741
[email protected]1308c2832011-05-09 18:30:231742TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
[email protected]ca64d232011-05-06 05:46:001743 // Check that there are no available types with no profiles stored.
[email protected]1308c2832011-05-09 18:30:231744 FieldTypeSet non_empty_types;
1745 personal_data_->GetNonEmptyTypes(&non_empty_types);
1746 EXPECT_EQ(0U, non_empty_types.size());
[email protected]ca64d232011-05-06 05:46:001747
1748 // Test with one profile stored.
1749 AutofillProfile profile0;
1750 autofill_test::SetProfileInfo(&profile0,
1751 "Marion", NULL, "Morrison",
1752 "[email protected]", NULL, "123 Zoo St.", NULL, "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:541753 "91601", "US", "14155678910");
[email protected]ca64d232011-05-06 05:46:001754
[email protected]3813dec2011-05-11 20:56:361755 personal_data_->AddProfile(profile0);
1756
1757 // Verify that the web database has been updated and the notification sent.
1758 EXPECT_CALL(personal_data_observer_,
1759 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1760 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001761
[email protected]1308c2832011-05-09 18:30:231762 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]11c2bdd12011-05-23 18:24:321763 EXPECT_EQ(14U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231764 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1765 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1766 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1767 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1768 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1769 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1770 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1771 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1772 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1773 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
[email protected]11c2bdd12011-05-23 18:24:321774 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
[email protected]1308c2832011-05-09 18:30:231775 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1776 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1777 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001778
1779 // Test with multiple profiles stored.
1780 AutofillProfile profile1;
1781 autofill_test::SetProfileInfo(&profile1,
1782 "Josephine", "Alicia", "Saenz",
1783 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:541784 "US", "16502937549");
[email protected]ca64d232011-05-06 05:46:001785
1786 AutofillProfile profile2;
1787 autofill_test::SetProfileInfo(&profile2,
1788 "Josephine", "Alicia", "Saenz",
1789 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:541790 "32801", "US", "16502937549");
[email protected]ca64d232011-05-06 05:46:001791
[email protected]3813dec2011-05-11 20:56:361792 personal_data_->AddProfile(profile1);
1793 personal_data_->AddProfile(profile2);
1794
1795 // Verify that the web database has been updated and the notification sent.
1796 EXPECT_CALL(personal_data_observer_,
1797 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1798 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001799
[email protected]1308c2832011-05-09 18:30:231800 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]4ef55f8c12011-09-17 00:06:541801 EXPECT_EQ(18U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231802 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1803 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1804 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1805 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1806 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1807 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1808 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1809 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1810 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1811 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1812 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1813 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1814 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1815 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1816 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1817 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1818 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1819 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001820
1821 // Test with credit card information also stored.
1822 CreditCard credit_card;
1823 autofill_test::SetCreditCardInfo(&credit_card,
1824 "John Dillinger", "423456789012" /* Visa */,
1825 "01", "2010");
[email protected]3813dec2011-05-11 20:56:361826 personal_data_->AddCreditCard(credit_card);
[email protected]ca64d232011-05-06 05:46:001827
[email protected]3813dec2011-05-11 20:56:361828 // Verify that the web database has been updated and the notification sent.
1829 EXPECT_CALL(personal_data_observer_,
1830 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1831 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001832
[email protected]1308c2832011-05-09 18:30:231833 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]4ef55f8c12011-09-17 00:06:541834 EXPECT_EQ(25U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231835 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1836 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1837 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1838 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1839 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1840 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1841 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1842 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1843 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1844 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1845 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1846 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1847 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1848 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1849 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1850 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1851 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1852 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]1308c2832011-05-09 18:30:231853 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NAME));
1854 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NUMBER));
1855 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_MONTH));
1856 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_2_DIGIT_YEAR));
1857 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1858 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR));
1859 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR));
[email protected]ca64d232011-05-06 05:46:001860}
[email protected]343b4fd2011-08-15 19:32:391861
1862TEST_F(PersonalDataManagerTest, CaseInsensitiveMultiValueAggregation) {
1863 FormData form1;
1864 webkit_glue::FormField field;
1865 autofill_test::CreateTestFormField(
1866 "First name:", "first_name", "George", "text", &field);
1867 form1.fields.push_back(field);
1868 autofill_test::CreateTestFormField(
1869 "Last name:", "last_name", "Washington", "text", &field);
1870 form1.fields.push_back(field);
1871 autofill_test::CreateTestFormField(
1872 "Email:", "email", "[email protected]", "text", &field);
1873 form1.fields.push_back(field);
1874 autofill_test::CreateTestFormField(
1875 "Address:", "address1", "21 Laussat St", "text", &field);
1876 form1.fields.push_back(field);
1877 autofill_test::CreateTestFormField(
1878 "City:", "city", "San Francisco", "text", &field);
1879 form1.fields.push_back(field);
1880 autofill_test::CreateTestFormField(
1881 "State:", "state", "California", "text", &field);
1882 form1.fields.push_back(field);
1883 autofill_test::CreateTestFormField(
1884 "Zip:", "zip", "94102", "text", &field);
1885 form1.fields.push_back(field);
1886 autofill_test::CreateTestFormField(
1887 "Phone number:", "phone_number", "817-555-6789", "text", &field);
1888 form1.fields.push_back(field);
1889
1890 FormStructure form_structure1(form1);
1891 form_structure1.DetermineHeuristicTypes();
1892 const CreditCard* imported_credit_card;
1893 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1894 &imported_credit_card));
1895 ASSERT_FALSE(imported_credit_card);
1896
1897 // Verify that the web database has been updated and the notification sent.
1898 EXPECT_CALL(personal_data_observer_,
1899 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1900 MessageLoop::current()->Run();
1901
1902 AutofillProfile expected;
1903 autofill_test::SetProfileInfo(&expected, "George", NULL,
1904 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541905 "San Francisco", "California", "94102", NULL, "817-555-6789");
[email protected]343b4fd2011-08-15 19:32:391906 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
1907 ASSERT_EQ(1U, results1.size());
1908 EXPECT_EQ(0, expected.Compare(*results1[0]));
1909
1910 // Upper-case the first name and change the phone number.
1911 FormData form2;
1912 autofill_test::CreateTestFormField(
1913 "First name:", "first_name", "GEORGE", "text", &field);
1914 form2.fields.push_back(field);
1915 autofill_test::CreateTestFormField(
1916 "Last name:", "last_name", "Washington", "text", &field);
1917 form2.fields.push_back(field);
1918 autofill_test::CreateTestFormField(
1919 "Email:", "email", "[email protected]", "text", &field);
1920 form2.fields.push_back(field);
1921 autofill_test::CreateTestFormField(
1922 "Address:", "address1", "21 Laussat St", "text", &field);
1923 form2.fields.push_back(field);
1924 autofill_test::CreateTestFormField(
1925 "City:", "city", "San Francisco", "text", &field);
1926 form2.fields.push_back(field);
1927 autofill_test::CreateTestFormField(
1928 "State:", "state", "California", "text", &field);
1929 form2.fields.push_back(field);
1930 autofill_test::CreateTestFormField(
1931 "Zip:", "zip", "94102", "text", &field);
1932 form2.fields.push_back(field);
1933 autofill_test::CreateTestFormField(
1934 "Phone number:", "phone_number", "214-555-1234", "text", &field);
1935 form2.fields.push_back(field);
1936
1937 FormStructure form_structure2(form2);
1938 form_structure2.DetermineHeuristicTypes();
1939 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1940 &imported_credit_card));
1941 ASSERT_FALSE(imported_credit_card);
1942
1943 // Verify that the web database has been updated and the notification sent.
1944 EXPECT_CALL(personal_data_observer_,
1945 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1946 MessageLoop::current()->Run();
1947
1948 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
1949
1950 // Modify expected to include multi-valued fields.
1951 std::vector<string16> values;
1952 expected.GetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, &values);
1953 values.push_back(ASCIIToUTF16("214-555-1234"));
1954 expected.SetMultiInfo(PHONE_HOME_CITY_AND_NUMBER, values);
1955
1956 ASSERT_EQ(1U, results2.size());
1957 EXPECT_EQ(0, expected.CompareMulti(*results2[0]));
1958}