blob: 41d720b0a3d15700002aa4bd20c02da8c2d16283 [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/ref_counted.h"
9#include "base/memory/scoped_ptr.h"
[email protected]2609bc12010-01-24 08:32:5510#include "base/message_loop.h"
[email protected]be1ce6a72010-08-03 14:35:2211#include "base/utf_string_conversions.h"
[email protected]468327f2010-10-04 20:02:2912#include "chrome/browser/autofill/autofill_common_test.h"
[email protected]2609bc12010-01-24 08:32:5513#include "chrome/browser/autofill/autofill_profile.h"
[email protected]ce78c1f92010-04-09 02:23:2614#include "chrome/browser/autofill/form_structure.h"
[email protected]2609bc12010-01-24 08:32:5515#include "chrome/browser/autofill/personal_data_manager.h"
[email protected]a7e585a2011-08-08 20:32:5416#include "chrome/browser/autofill/personal_data_manager_observer.h"
[email protected]ecbf2892010-07-16 01:51:4517#include "chrome/browser/password_manager/encryptor.h"
[email protected]3eb0d8f72010-12-15 23:38:2518#include "chrome/common/guid.h"
[email protected]a4ff9eae2011-08-01 19:58:1619#include "chrome/test/base/testing_profile.h"
[email protected]79457792011-02-15 07:35:3720#include "chrome/test/testing_browser_process.h"
[email protected]1bda97552011-03-01 20:11:5221#include "content/browser/browser_thread.h"
[email protected]432115822011-07-10 15:52:2722#include "content/common/content_notification_types.h"
[email protected]652e16d2011-03-07 03:53:0023#include "content/common/notification_details.h"
24#include "content/common/notification_observer_mock.h"
25#include "content/common/notification_registrar.h"
26#include "content/common/notification_source.h"
[email protected]2609bc12010-01-24 08:32:5527#include "testing/gmock/include/gmock/gmock.h"
28#include "testing/gtest/include/gtest/gtest.h"
[email protected]7b37fbb2011-03-07 16:16:0329#include "webkit/glue/form_data.h"
[email protected]2609bc12010-01-24 08:32:5530
[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]414c35482011-02-09 01:26:1364 personal_data_ = NULL;
[email protected]2609bc12010-01-24 08:32:5565 if (profile_.get())
66 profile_.reset(NULL);
67
68 db_thread_.Stop();
69 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
70 MessageLoop::current()->Run();
71 }
72
73 void ResetPersonalDataManager() {
[email protected]36c1ff9fd2010-06-03 20:08:5974 personal_data_ = 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]79457792011-02-15 07:35:3784 ScopedTestingBrowserProcess browser_process_;
[email protected]2609bc12010-01-24 08:32:5585 MessageLoopForUI message_loop_;
[email protected]faec6312010-10-05 03:35:3486 BrowserThread ui_thread_;
87 BrowserThread db_thread_;
[email protected]2609bc12010-01-24 08:32:5588 scoped_ptr<TestingProfile> profile_;
[email protected]36c1ff9fd2010-06-03 20:08:5989 scoped_refptr<PersonalDataManager> personal_data_;
[email protected]2609bc12010-01-24 08:32:5590 NotificationRegistrar registrar_;
91 NotificationObserverMock observer_;
92 PersonalDataLoadedObserverMock personal_data_observer_;
93};
94
[email protected]0ed984b2011-04-28 01:22:0295TEST_F(PersonalDataManagerTest, AddProfile) {
[email protected]0ed984b2011-04-28 01:22:0296 AutofillProfile profile0;
97 autofill_test::SetProfileInfo(&profile0,
98 "John", "Mitchell", "Smith",
99 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
100 "94102", "USA", "4158889999", "4152223333");
101
102 // Add profile0 to the database.
103 personal_data_->AddProfile(profile0);
104
105 // Reload the database.
106 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02107
108 // Verify the addition.
109 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
110 ASSERT_EQ(1U, results1.size());
[email protected]3813dec2011-05-11 20:56:36111 EXPECT_EQ(0, profile0.CompareMulti(*results1[0]));
[email protected]0ed984b2011-04-28 01:22:02112
113 // Add profile with identical values. Duplicates should not get saved.
114 AutofillProfile profile0a = profile0;
115 profile0a.set_guid(guid::GenerateGUID());
116 personal_data_->AddProfile(profile0a);
117
118 // Reload the database.
119 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02120
121 // Verify the non-addition.
122 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
123 ASSERT_EQ(1U, results2.size());
[email protected]3813dec2011-05-11 20:56:36124 EXPECT_EQ(0, profile0.CompareMulti(*results2[0]));
[email protected]0ed984b2011-04-28 01:22:02125
126 // New profile with different email.
127 AutofillProfile profile1 = profile0;
128 profile1.set_guid(guid::GenerateGUID());
129 profile1.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("[email protected]"));
130
131 // Add the different profile. This should save as a separate profile.
132 // Note that if this same profile was "merged" it would collapse to one
133 // profile with a multi-valued entry for email.
134 personal_data_->AddProfile(profile1);
135
136 // Reload the database.
137 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02138
139 // Verify the addition.
140 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
141 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36142 EXPECT_EQ(0, profile0.CompareMulti(*results3[0]));
143 EXPECT_EQ(0, profile1.CompareMulti(*results3[1]));
[email protected]0ed984b2011-04-28 01:22:02144}
145
[email protected]3813dec2011-05-11 20:56:36146TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) {
[email protected]e90c2252011-03-10 12:29:21147 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29148 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34149 "Marion", "Mitchell", "Morrison",
[email protected]2609bc12010-01-24 08:32:55150 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
151 "91601", "US", "12345678910", "01987654321");
152
[email protected]e90c2252011-03-10 12:29:21153 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29154 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34155 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55156 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
157 "US", "19482937549", "13502849239");
158
[email protected]e90c2252011-03-10 12:29:21159 AutofillProfile profile2;
[email protected]468327f2010-10-04 20:02:29160 autofill_test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34161 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55162 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
163 "32801", "US", "19482937549", "13502849239");
164
[email protected]542e1992010-07-14 18:25:52165 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36166 personal_data_->AddProfile(profile0);
167 personal_data_->AddProfile(profile1);
168
169 // Verify that the web database has been updated and the notification sent.
170 EXPECT_CALL(personal_data_observer_,
171 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
172 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55173
[email protected]e90c2252011-03-10 12:29:21174 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]2609bc12010-01-24 08:32:55175 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36176 EXPECT_EQ(0, profile0.Compare(*results1[0]));
177 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]2609bc12010-01-24 08:32:55178
[email protected]3813dec2011-05-11 20:56:36179 // Update, remove, and add.
[email protected]1ffe8e992011-03-17 06:26:29180 profile0.SetInfo(NAME_FIRST, ASCIIToUTF16("John"));
[email protected]3813dec2011-05-11 20:56:36181 personal_data_->UpdateProfile(profile0);
182 personal_data_->RemoveProfile(profile1.guid());
183 personal_data_->AddProfile(profile2);
184
185 // Verify that the web database has been updated and the notification sent.
186 EXPECT_CALL(personal_data_observer_,
187 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
188 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55189
[email protected]e90c2252011-03-10 12:29:21190 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]2609bc12010-01-24 08:32:55191 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36192 EXPECT_EQ(0, profile0.Compare(*results2[0]));
193 EXPECT_EQ(0, profile2.Compare(*results2[1]));
[email protected]2609bc12010-01-24 08:32:55194
195 // Reset the PersonalDataManager. This tests that the personal data was saved
196 // to the web database, and that we can load the profiles from the web
197 // database.
198 ResetPersonalDataManager();
199
[email protected]2609bc12010-01-24 08:32:55200 // Verify that we've loaded the profiles from the web database.
[email protected]e90c2252011-03-10 12:29:21201 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
[email protected]2609bc12010-01-24 08:32:55202 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36203 EXPECT_EQ(0, profile0.Compare(*results3[0]));
204 EXPECT_EQ(0, profile2.Compare(*results3[1]));
[email protected]2609bc12010-01-24 08:32:55205}
[email protected]f11f6212010-01-25 20:47:20206
[email protected]3813dec2011-05-11 20:56:36207TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) {
208 CreditCard credit_card0;
209 autofill_test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54210 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]f11f6212010-01-25 20:47:20211
[email protected]3813dec2011-05-11 20:56:36212 CreditCard credit_card1;
213 autofill_test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54214 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]f11f6212010-01-25 20:47:20215
[email protected]3813dec2011-05-11 20:56:36216 CreditCard credit_card2;
217 autofill_test::SetCreditCardInfo(&credit_card2,
[email protected]2a13edd2010-10-26 22:52:54218 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
[email protected]f11f6212010-01-25 20:47:20219
[email protected]542e1992010-07-14 18:25:52220 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36221 personal_data_->AddCreditCard(credit_card0);
222 personal_data_->AddCreditCard(credit_card1);
223
224 // Verify that the web database has been updated and the notification sent.
225 EXPECT_CALL(personal_data_observer_,
226 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
227 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20228
[email protected]f11f6212010-01-25 20:47:20229 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
230 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36231 EXPECT_EQ(0, credit_card0.Compare(*results1[0]));
232 EXPECT_EQ(0, credit_card1.Compare(*results1[1]));
[email protected]f11f6212010-01-25 20:47:20233
[email protected]3813dec2011-05-11 20:56:36234 // Update, remove, and add.
235 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe"));
236 personal_data_->UpdateCreditCard(credit_card0);
237 personal_data_->RemoveCreditCard(credit_card1.guid());
238 personal_data_->AddCreditCard(credit_card2);
239
240 // Verify that the web database has been updated and the notification sent.
241 EXPECT_CALL(personal_data_observer_,
242 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
243 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20244
[email protected]f11f6212010-01-25 20:47:20245 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
246 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36247 EXPECT_EQ(credit_card0, *results2[0]);
248 EXPECT_EQ(credit_card2, *results2[1]);
[email protected]f11f6212010-01-25 20:47:20249
250 // Reset the PersonalDataManager. This tests that the personal data was saved
251 // to the web database, and that we can load the credit cards from the web
252 // database.
253 ResetPersonalDataManager();
254
[email protected]f11f6212010-01-25 20:47:20255 // Verify that we've loaded the credit cards from the web database.
256 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
257 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36258 EXPECT_EQ(credit_card0, *results3[0]);
259 EXPECT_EQ(credit_card2, *results3[1]);
[email protected]f11f6212010-01-25 20:47:20260}
[email protected]e0976a72010-04-02 01:25:24261
[email protected]3813dec2011-05-11 20:56:36262TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) {
[email protected]e90c2252011-03-10 12:29:21263 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29264 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34265 "Marion", "Mitchell", "Morrison",
[email protected]542e1992010-07-14 18:25:52266 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
267 "91601", "US", "12345678910", "01987654321");
268
[email protected]e90c2252011-03-10 12:29:21269 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29270 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34271 "Josephine", "Alicia", "Saenz",
[email protected]542e1992010-07-14 18:25:52272 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
273 "US", "19482937549", "13502849239");
274
[email protected]3813dec2011-05-11 20:56:36275 CreditCard credit_card0;
276 autofill_test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54277 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]542e1992010-07-14 18:25:52278
[email protected]3813dec2011-05-11 20:56:36279 CreditCard credit_card1;
280 autofill_test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54281 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]542e1992010-07-14 18:25:52282
[email protected]542e1992010-07-14 18:25:52283 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36284 personal_data_->AddProfile(profile0);
285 personal_data_->AddProfile(profile1);
286
287 // Verify that the web database has been updated and the notification sent.
288 EXPECT_CALL(personal_data_observer_,
289 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
290 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52291
[email protected]e90c2252011-03-10 12:29:21292 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]542e1992010-07-14 18:25:52293 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36294 EXPECT_EQ(0, profile0.Compare(*results1[0]));
295 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]414c35482011-02-09 01:26:13296
[email protected]542e1992010-07-14 18:25:52297 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36298 personal_data_->AddCreditCard(credit_card0);
299 personal_data_->AddCreditCard(credit_card1);
[email protected]542e1992010-07-14 18:25:52300
[email protected]3813dec2011-05-11 20:56:36301 // Verify that the web database has been updated and the notification sent.
302 EXPECT_CALL(personal_data_observer_,
303 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
304 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52305
306 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
307 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36308 EXPECT_EQ(credit_card0, *results2[0]);
309 EXPECT_EQ(credit_card1, *results2[1]);
[email protected]542e1992010-07-14 18:25:52310
[email protected]e43783402010-11-04 19:45:04311 // Determine uniqueness by inserting all of the GUIDs into a set and verifying
312 // the size of the set matches the number of GUIDs.
313 std::set<std::string> guids;
314 guids.insert(profile0.guid());
315 guids.insert(profile1.guid());
[email protected]3813dec2011-05-11 20:56:36316 guids.insert(credit_card0.guid());
317 guids.insert(credit_card1.guid());
[email protected]e43783402010-11-04 19:45:04318 EXPECT_EQ(4U, guids.size());
[email protected]542e1992010-07-14 18:25:52319}
320
[email protected]3813dec2011-05-11 20:56:36321// Test for http://crbug.com/50047. Makes sure that guids are populated
322// correctly on load.
[email protected]7c543fd2010-07-24 02:44:59323TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) {
[email protected]e90c2252011-03-10 12:29:21324 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29325 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34326 "y", "", "", "", "", "", "", "", "", "", "", "", "");
[email protected]7c543fd2010-07-24 02:44:59327
[email protected]7c543fd2010-07-24 02:44:59328 // Add the profile0 to the db.
[email protected]3813dec2011-05-11 20:56:36329 personal_data_->AddProfile(profile0);
[email protected]7c543fd2010-07-24 02:44:59330
[email protected]3813dec2011-05-11 20:56:36331 // Verify that the web database has been updated and the notification sent.
332 EXPECT_CALL(personal_data_observer_,
333 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]7c543fd2010-07-24 02:44:59334 MessageLoop::current()->Run();
335
336 // Verify that we've loaded the profiles from the web database.
[email protected]e90c2252011-03-10 12:29:21337 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]7c543fd2010-07-24 02:44:59338 ASSERT_EQ(1U, results2.size());
[email protected]3813dec2011-05-11 20:56:36339 EXPECT_EQ(0, profile0.Compare(*results2[0]));
[email protected]7c543fd2010-07-24 02:44:59340
341 // Add a new profile.
[email protected]e90c2252011-03-10 12:29:21342 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29343 autofill_test::SetProfileInfo(&profile1,
[email protected]3813dec2011-05-11 20:56:36344 "z", "", "", "", "", "", "", "", "", "", "", "", "");
345 personal_data_->AddProfile(profile1);
[email protected]7c543fd2010-07-24 02:44:59346
[email protected]3813dec2011-05-11 20:56:36347 // Verify that the web database has been updated and the notification sent.
348 EXPECT_CALL(personal_data_observer_,
349 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
350 MessageLoop::current()->Run();
351
352 // Make sure the two profiles have different GUIDs, both valid.
[email protected]e90c2252011-03-10 12:29:21353 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
[email protected]7c543fd2010-07-24 02:44:59354 ASSERT_EQ(2U, results3.size());
[email protected]e43783402010-11-04 19:45:04355 EXPECT_NE(results3[0]->guid(), results3[1]->guid());
356 EXPECT_TRUE(guid::IsValidGUID(results3[0]->guid()));
357 EXPECT_TRUE(guid::IsValidGUID(results3[1]->guid()));
[email protected]7c543fd2010-07-24 02:44:59358}
359
[email protected]98a94ee2010-07-12 16:03:22360TEST_F(PersonalDataManagerTest, SetEmptyProfile) {
[email protected]e90c2252011-03-10 12:29:21361 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29362 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34363 "", "", "", "", "", "", "", "", "", "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22364
[email protected]98a94ee2010-07-12 16:03:22365 // Add the empty profile to the database.
[email protected]3813dec2011-05-11 20:56:36366 personal_data_->AddProfile(profile0);
[email protected]98a94ee2010-07-12 16:03:22367
[email protected]3813dec2011-05-11 20:56:36368 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22369
370 // Reset the PersonalDataManager. This tests that the personal data was saved
371 // to the web database, and that we can load the profiles from the web
372 // database.
373 ResetPersonalDataManager();
374
[email protected]98a94ee2010-07-12 16:03:22375 // Verify that we've loaded the profiles from the web database.
[email protected]e90c2252011-03-10 12:29:21376 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]98a94ee2010-07-12 16:03:22377 ASSERT_EQ(0U, results2.size());
378}
379
380TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) {
[email protected]3813dec2011-05-11 20:56:36381 CreditCard credit_card0;
382 autofill_test::SetCreditCardInfo(&credit_card0, "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22383
384 // Add the empty credit card to the database.
[email protected]3813dec2011-05-11 20:56:36385 personal_data_->AddCreditCard(credit_card0);
[email protected]98a94ee2010-07-12 16:03:22386
[email protected]3813dec2011-05-11 20:56:36387 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22388
389 // Reset the PersonalDataManager. This tests that the personal data was saved
390 // to the web database, and that we can load the credit cards from the web
391 // database.
392 ResetPersonalDataManager();
393
[email protected]98a94ee2010-07-12 16:03:22394 // Verify that we've loaded the credit cards from the web database.
395 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
396 ASSERT_EQ(0U, results2.size());
397}
398
[email protected]e0976a72010-04-02 01:25:24399TEST_F(PersonalDataManagerTest, Refresh) {
[email protected]e90c2252011-03-10 12:29:21400 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29401 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34402 "Marion", "Mitchell", "Morrison",
[email protected]e0976a72010-04-02 01:25:24403 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
404 "91601", "US", "12345678910", "01987654321");
405
[email protected]e90c2252011-03-10 12:29:21406 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29407 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34408 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24409 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
410 "US", "19482937549", "13502849239");
411
[email protected]e0976a72010-04-02 01:25:24412 // Add the test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36413 personal_data_->AddProfile(profile0);
414 personal_data_->AddProfile(profile1);
[email protected]e0976a72010-04-02 01:25:24415
[email protected]e43783402010-11-04 19:45:04416 // Labels depend on other profiles in the list - update labels manually.
[email protected]e90c2252011-03-10 12:29:21417 std::vector<AutofillProfile *> profile_pointers;
[email protected]9f321442010-10-25 23:53:53418 profile_pointers.push_back(&profile0);
419 profile_pointers.push_back(&profile1);
[email protected]e90c2252011-03-10 12:29:21420 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]e0976a72010-04-02 01:25:24421
[email protected]3813dec2011-05-11 20:56:36422 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24423 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36424 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24425 MessageLoop::current()->Run();
426
[email protected]e90c2252011-03-10 12:29:21427 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]e0976a72010-04-02 01:25:24428 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36429 EXPECT_EQ(profile0, *results1[0]);
430 EXPECT_EQ(profile1, *results1[1]);
[email protected]e0976a72010-04-02 01:25:24431
[email protected]e90c2252011-03-10 12:29:21432 AutofillProfile profile2;
[email protected]61f25cd0e2010-11-07 05:23:50433 autofill_test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34434 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24435 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
436 "32801", "US", "19482937549", "13502849239");
437
[email protected]9f321442010-10-25 23:53:53438 // Adjust all labels.
[email protected]61f25cd0e2010-11-07 05:23:50439 profile_pointers.push_back(&profile2);
[email protected]e90c2252011-03-10 12:29:21440 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]9f321442010-10-25 23:53:53441
[email protected]e0976a72010-04-02 01:25:24442 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
443 ASSERT_TRUE(wds);
[email protected]e90c2252011-03-10 12:29:21444 wds->AddAutofillProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24445
446 personal_data_->Refresh();
447
[email protected]3813dec2011-05-11 20:56:36448 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24449 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36450 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24451 MessageLoop::current()->Run();
452
[email protected]e90c2252011-03-10 12:29:21453 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]e0976a72010-04-02 01:25:24454 ASSERT_EQ(3U, results2.size());
[email protected]3813dec2011-05-11 20:56:36455 EXPECT_EQ(profile0, *results2[0]);
456 EXPECT_EQ(profile1, *results2[1]);
457 EXPECT_EQ(profile2, *results2[2]);
[email protected]e0976a72010-04-02 01:25:24458
[email protected]e90c2252011-03-10 12:29:21459 wds->RemoveAutofillProfile(profile1.guid());
460 wds->RemoveAutofillProfile(profile2.guid());
[email protected]e0976a72010-04-02 01:25:24461
462 // Before telling the PDM to refresh, simulate an edit to one of the profiles
[email protected]663bd9e2011-03-21 01:07:01463 // via a SetProfile update (this would happen if the Autofill window was
[email protected]e0976a72010-04-02 01:25:24464 // open with a previous snapshot of the profiles, and something [e.g. sync]
465 // removed a profile from the browser. In this edge case, we will end up
466 // in a consistent state by dropping the write).
[email protected]1ffe8e992011-03-17 06:26:29467 profile2.SetInfo(NAME_FIRST, ASCIIToUTF16("Jo"));
[email protected]3813dec2011-05-11 20:56:36468 personal_data_->UpdateProfile(profile0);
469 personal_data_->AddProfile(profile1);
470 personal_data_->AddProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24471
[email protected]3813dec2011-05-11 20:56:36472 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24473 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36474 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24475 MessageLoop::current()->Run();
476
[email protected]e90c2252011-03-10 12:29:21477 const std::vector<AutofillProfile*>& results3 = personal_data_->profiles();
[email protected]e0976a72010-04-02 01:25:24478 ASSERT_EQ(1U, results3.size());
[email protected]3813dec2011-05-11 20:56:36479 EXPECT_EQ(profile0, *results2[0]);
[email protected]e0976a72010-04-02 01:25:24480}
[email protected]83723f02010-04-07 17:33:10481
[email protected]ce78c1f92010-04-09 02:23:26482TEST_F(PersonalDataManagerTest, ImportFormData) {
[email protected]cea1d112010-07-01 00:57:33483 FormData form;
484 webkit_glue::FormField field;
[email protected]468327f2010-10-04 20:02:29485 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33486 "First name:", "first_name", "George", "text", &field);
487 form.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29488 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33489 "Last name:", "last_name", "Washington", "text", &field);
490 form.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29491 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33492 "Email:", "email", "[email protected]", "text", &field);
493 form.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52494 autofill_test::CreateTestFormField(
495 "Address:", "address1", "21 Laussat St", "text", &field);
496 form.fields.push_back(field);
497 autofill_test::CreateTestFormField(
498 "City:", "city", "San Francisco", "text", &field);
499 form.fields.push_back(field);
500 autofill_test::CreateTestFormField(
501 "State:", "state", "California", "text", &field);
502 form.fields.push_back(field);
503 autofill_test::CreateTestFormField(
504 "Zip:", "zip", "94102", "text", &field);
505 form.fields.push_back(field);
[email protected]ce78c1f92010-04-09 02:23:26506 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55507 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24508 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21509 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
510 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24511 ASSERT_FALSE(imported_credit_card);
[email protected]ce78c1f92010-04-09 02:23:26512
[email protected]3813dec2011-05-11 20:56:36513 // Verify that the web database has been updated and the notification sent.
[email protected]ce78c1f92010-04-09 02:23:26514 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36515 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]ce78c1f92010-04-09 02:23:26516 MessageLoop::current()->Run();
517
[email protected]e90c2252011-03-10 12:29:21518 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34519 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52520 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
521 "San Francisco", "California", "94102", NULL, NULL, NULL);
[email protected]e90c2252011-03-10 12:29:21522 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
[email protected]ce78c1f92010-04-09 02:23:26523 ASSERT_EQ(1U, results.size());
[email protected]e43783402010-11-04 19:45:04524 EXPECT_EQ(0, expected.Compare(*results[0]));
[email protected]ce78c1f92010-04-09 02:23:26525}
526
[email protected]a2a1baf2011-02-03 20:22:00527TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) {
528 FormData form;
529 webkit_glue::FormField field;
530 autofill_test::CreateTestFormField(
531 "First name:", "first_name", "George", "text", &field);
532 form.fields.push_back(field);
533 autofill_test::CreateTestFormField(
534 "Last name:", "last_name", "Washington", "text", &field);
535 form.fields.push_back(field);
536 autofill_test::CreateTestFormField(
537 "Email:", "email", "bogus", "text", &field);
538 form.fields.push_back(field);
539 autofill_test::CreateTestFormField(
540 "Address:", "address1", "21 Laussat St", "text", &field);
541 form.fields.push_back(field);
542 autofill_test::CreateTestFormField(
543 "City:", "city", "San Francisco", "text", &field);
544 form.fields.push_back(field);
545 autofill_test::CreateTestFormField(
546 "State:", "state", "California", "text", &field);
547 form.fields.push_back(field);
548 autofill_test::CreateTestFormField(
549 "Zip:", "zip", "94102", "text", &field);
550 form.fields.push_back(field);
551 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55552 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24553 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21554 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
555 &imported_credit_card));
[email protected]ca9bdeb2011-03-17 20:01:41556 ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card);
[email protected]a2a1baf2011-02-03 20:22:00557
[email protected]e90c2252011-03-10 12:29:21558 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
[email protected]ca9bdeb2011-03-17 20:01:41559 ASSERT_EQ(0U, results.size());
[email protected]a2a1baf2011-02-03 20:22:00560}
561
[email protected]204777552011-01-26 19:46:28562TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) {
[email protected]4fb058092010-11-24 23:52:25563 FormData form;
564 webkit_glue::FormField field;
565 autofill_test::CreateTestFormField(
566 "First name:", "first_name", "George", "text", &field);
567 form.fields.push_back(field);
568 autofill_test::CreateTestFormField(
569 "Last name:", "last_name", "Washington", "text", &field);
570 form.fields.push_back(field);
571 autofill_test::CreateTestFormField(
572 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field);
573 form.fields.push_back(field);
574 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55575 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24576 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21577 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
578 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24579 ASSERT_FALSE(imported_credit_card);
[email protected]4fb058092010-11-24 23:52:25580
[email protected]e90c2252011-03-10 12:29:21581 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles();
[email protected]4fb058092010-11-24 23:52:25582 ASSERT_EQ(0U, profiles.size());
583 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
584 ASSERT_EQ(0U, credit_cards.size());
585}
586
[email protected]3aa8bec22010-11-23 07:51:28587TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) {
588 FormData form;
589 webkit_glue::FormField field;
590 autofill_test::CreateTestFormField(
591 "First name:", "first_name", "George", "text", &field);
592 form.fields.push_back(field);
593 autofill_test::CreateTestFormField(
594 "Last name:", "last_name", "Washington", "text", &field);
595 form.fields.push_back(field);
596 autofill_test::CreateTestFormField(
597 "Phone #:", "home_phone_area_code", "650", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04598 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28599 form.fields.push_back(field);
600 autofill_test::CreateTestFormField(
601 "Phone #:", "home_phone_prefix", "555", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04602 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28603 form.fields.push_back(field);
604 autofill_test::CreateTestFormField(
605 "Phone #:", "home_phone_suffix", "0000", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04606 field.max_length = 4;
[email protected]3aa8bec22010-11-23 07:51:28607 form.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52608 autofill_test::CreateTestFormField(
609 "Address:", "address1", "21 Laussat St", "text", &field);
610 form.fields.push_back(field);
611 autofill_test::CreateTestFormField(
612 "City:", "city", "San Francisco", "text", &field);
613 form.fields.push_back(field);
614 autofill_test::CreateTestFormField(
615 "State:", "state", "California", "text", &field);
616 form.fields.push_back(field);
617 autofill_test::CreateTestFormField(
618 "Zip:", "zip", "94102", "text", &field);
619 form.fields.push_back(field);
[email protected]3aa8bec22010-11-23 07:51:28620 FormStructure form_structure(form);
[email protected]68e91e92011-03-16 06:02:55621 form_structure.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24622 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21623 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
624 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24625 ASSERT_FALSE(imported_credit_card);
[email protected]3aa8bec22010-11-23 07:51:28626
[email protected]3813dec2011-05-11 20:56:36627 // Verify that the web database has been updated and the notification sent.
[email protected]3aa8bec22010-11-23 07:51:28628 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36629 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]3aa8bec22010-11-23 07:51:28630 MessageLoop::current()->Run();
631
[email protected]e90c2252011-03-10 12:29:21632 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34633 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52634 "Washington", NULL, NULL, "21 Laussat St", NULL,
635 "San Francisco", "California", "94102", NULL, "6505550000", NULL);
[email protected]e90c2252011-03-10 12:29:21636 const std::vector<AutofillProfile*>& results = personal_data_->profiles();
[email protected]3aa8bec22010-11-23 07:51:28637 ASSERT_EQ(1U, results.size());
638 EXPECT_EQ(0, expected.Compare(*results[0]));
639}
640
[email protected]47e119f02010-04-15 00:46:55641TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
[email protected]e43783402010-11-04 19:45:04642 CreditCard credit_card0;
[email protected]1ffe8e992011-03-17 06:26:29643 credit_card0.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John"));
[email protected]e43783402010-11-04 19:45:04644 CreditCard credit_card1;
[email protected]1ffe8e992011-03-17 06:26:29645 credit_card1.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul"));
[email protected]e43783402010-11-04 19:45:04646 CreditCard credit_card2;
[email protected]1ffe8e992011-03-17 06:26:29647 credit_card2.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo"));
[email protected]e43783402010-11-04 19:45:04648 CreditCard credit_card3;
[email protected]1ffe8e992011-03-17 06:26:29649 credit_card3.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other"));
[email protected]e43783402010-11-04 19:45:04650 CreditCard credit_card4;
[email protected]1ffe8e992011-03-17 06:26:29651 credit_card4.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy"));
[email protected]e43783402010-11-04 19:45:04652 CreditCard credit_card5;
[email protected]1ffe8e992011-03-17 06:26:29653 credit_card5.SetInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio"));
[email protected]47e119f02010-04-15 00:46:55654
[email protected]98a94ee2010-07-12 16:03:22655 // Add the test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36656 personal_data_->AddCreditCard(credit_card0);
657 personal_data_->AddCreditCard(credit_card1);
658 personal_data_->AddCreditCard(credit_card2);
659 personal_data_->AddCreditCard(credit_card3);
660 personal_data_->AddCreditCard(credit_card4);
661 personal_data_->AddCreditCard(credit_card5);
[email protected]47e119f02010-04-15 00:46:55662
[email protected]18f92d4f2010-10-19 00:14:58663 // Reset the PersonalDataManager. This tests that the personal data was saved
664 // to the web database, and that we can load the credit cards from the web
665 // database.
666 ResetPersonalDataManager();
667
[email protected]47e119f02010-04-15 00:46:55668 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
669 ASSERT_EQ(6U, results.size());
[email protected]027dd442011-02-15 23:17:34670 EXPECT_EQ(credit_card0.guid(), results[0]->guid());
671 EXPECT_EQ(credit_card1.guid(), results[1]->guid());
672 EXPECT_EQ(credit_card2.guid(), results[2]->guid());
673 EXPECT_EQ(credit_card3.guid(), results[3]->guid());
674 EXPECT_EQ(credit_card4.guid(), results[4]->guid());
675 EXPECT_EQ(credit_card5.guid(), results[5]->guid());
[email protected]47e119f02010-04-15 00:46:55676}
[email protected]cea1d112010-07-01 00:57:33677
[email protected]f1ed7272010-11-11 21:57:07678TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) {
679 FormData form1;
[email protected]cea1d112010-07-01 00:57:33680 webkit_glue::FormField field;
[email protected]468327f2010-10-04 20:02:29681 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33682 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07683 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29684 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33685 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07686 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29687 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33688 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07689 form1.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52690 autofill_test::CreateTestFormField(
691 "Address:", "address1", "21 Laussat St", "text", &field);
692 form1.fields.push_back(field);
693 autofill_test::CreateTestFormField(
694 "City:", "city", "San Francisco", "text", &field);
695 form1.fields.push_back(field);
696 autofill_test::CreateTestFormField(
697 "State:", "state", "California", "text", &field);
698 form1.fields.push_back(field);
699 autofill_test::CreateTestFormField(
700 "Zip:", "zip", "94102", "text", &field);
701 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33702
[email protected]f1ed7272010-11-11 21:57:07703 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:55704 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24705 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21706 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
707 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24708 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33709
[email protected]3813dec2011-05-11 20:56:36710 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33711 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36712 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33713 MessageLoop::current()->Run();
714
[email protected]e90c2252011-03-10 12:29:21715 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34716 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52717 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
718 "San Francisco", "California", "94102", NULL, NULL, NULL);
[email protected]e90c2252011-03-10 12:29:21719 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:07720 ASSERT_EQ(1U, results1.size());
721 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:33722
723 // Now create a completely different profile.
[email protected]f1ed7272010-11-11 21:57:07724 FormData form2;
[email protected]468327f2010-10-04 20:02:29725 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33726 "First name:", "first_name", "John", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07727 form2.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29728 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33729 "Last name:", "last_name", "Adams", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07730 form2.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29731 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33732 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07733 form2.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52734 autofill_test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24735 "Address:", "address1", "22 Laussat St", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52736 form2.fields.push_back(field);
737 autofill_test::CreateTestFormField(
738 "City:", "city", "San Francisco", "text", &field);
739 form2.fields.push_back(field);
740 autofill_test::CreateTestFormField(
741 "State:", "state", "California", "text", &field);
742 form2.fields.push_back(field);
743 autofill_test::CreateTestFormField(
744 "Zip:", "zip", "94102", "text", &field);
745 form2.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33746
[email protected]f1ed7272010-11-11 21:57:07747 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:55748 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:21749 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
750 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24751 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33752
[email protected]3813dec2011-05-11 20:56:36753 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33754 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36755 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33756 MessageLoop::current()->Run();
757
[email protected]e90c2252011-03-10 12:29:21758 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]cea1d112010-07-01 00:57:33759
[email protected]e90c2252011-03-10 12:29:21760 AutofillProfile expected2;
[email protected]027dd442011-02-15 23:17:34761 autofill_test::SetProfileInfo(&expected2, "John", NULL,
[email protected]023e1822011-04-13 15:52:24762 "Adams", "[email protected]", NULL, "22 Laussat St", NULL,
[email protected]37ff612e2011-02-03 15:54:52763 "San Francisco", "California", "94102", NULL, NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:07764 ASSERT_EQ(2U, results2.size());
765 EXPECT_EQ(0, expected.Compare(*results2[0]));
766 EXPECT_EQ(0, expected2.Compare(*results2[1]));
767}
[email protected]cea1d112010-07-01 00:57:33768
[email protected]023e1822011-04-13 15:52:24769TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) {
770 FormData form1;
771 webkit_glue::FormField field;
772 autofill_test::CreateTestFormField(
773 "First name:", "first_name", "George", "text", &field);
774 form1.fields.push_back(field);
775 autofill_test::CreateTestFormField(
776 "Last name:", "last_name", "Washington", "text", &field);
777 form1.fields.push_back(field);
778 autofill_test::CreateTestFormField(
779 "Email:", "email", "[email protected]", "text", &field);
780 form1.fields.push_back(field);
781 autofill_test::CreateTestFormField(
782 "Address:", "address1", "21 Laussat St", "text", &field);
783 form1.fields.push_back(field);
784 autofill_test::CreateTestFormField(
785 "City:", "city", "San Francisco", "text", &field);
786 form1.fields.push_back(field);
787 autofill_test::CreateTestFormField(
788 "State:", "state", "California", "text", &field);
789 form1.fields.push_back(field);
790 autofill_test::CreateTestFormField(
791 "Zip:", "zip", "94102", "text", &field);
792 form1.fields.push_back(field);
793
794 FormStructure form_structure1(form1);
795 form_structure1.DetermineHeuristicTypes();
[email protected]023e1822011-04-13 15:52:24796 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21797 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
798 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24799 ASSERT_FALSE(imported_credit_card);
800
[email protected]3813dec2011-05-11 20:56:36801 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24802 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36803 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24804 MessageLoop::current()->Run();
805
806 AutofillProfile expected;
807 autofill_test::SetProfileInfo(&expected, "George", NULL,
808 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
809 "San Francisco", "California", "94102", NULL, NULL, NULL);
810 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
811 ASSERT_EQ(1U, results1.size());
812 EXPECT_EQ(0, expected.Compare(*results1[0]));
813
814 // Now create a completely different profile.
815 FormData form2;
816 autofill_test::CreateTestFormField(
817 "First name:", "first_name", "John", "text", &field);
818 form2.fields.push_back(field);
819 autofill_test::CreateTestFormField(
820 "Last name:", "last_name", "Adams", "text", &field);
821 form2.fields.push_back(field);
822 autofill_test::CreateTestFormField(
823 "Email:", "email", "[email protected]", "text", &field);
824 form2.fields.push_back(field);
825 autofill_test::CreateTestFormField(
826 "Address:", "address1", "21 Laussat St", "text", &field);
827 form2.fields.push_back(field);
828 autofill_test::CreateTestFormField(
829 "City:", "city", "San Francisco", "text", &field);
830 form2.fields.push_back(field);
831 autofill_test::CreateTestFormField(
832 "State:", "state", "California", "text", &field);
833 form2.fields.push_back(field);
834 autofill_test::CreateTestFormField(
835 "Zip:", "zip", "94102", "text", &field);
836 form2.fields.push_back(field);
837
838 FormStructure form_structure2(form2);
839 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:21840 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
841 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24842 ASSERT_FALSE(imported_credit_card);
843
[email protected]3813dec2011-05-11 20:56:36844 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24845 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36846 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24847 MessageLoop::current()->Run();
848
849 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
850
851 // Modify expected to include multi-valued fields.
852 std::vector<string16> values;
853 expected.GetMultiInfo(NAME_FULL, &values);
854 values.push_back(ASCIIToUTF16("John Adams"));
855 expected.SetMultiInfo(NAME_FULL, values);
856 expected.GetMultiInfo(EMAIL_ADDRESS, &values);
857 values.push_back(ASCIIToUTF16("[email protected]"));
858 expected.SetMultiInfo(EMAIL_ADDRESS, values);
859
860 ASSERT_EQ(1U, results2.size());
861 EXPECT_EQ(0, expected.CompareMulti(*results2[0]));
862}
863
[email protected]f1ed7272010-11-11 21:57:07864TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) {
865 FormData form1;
866 webkit_glue::FormField field;
[email protected]468327f2010-10-04 20:02:29867 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33868 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07869 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29870 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33871 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07872 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29873 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:07874 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
875 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29876 autofill_test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:34877 "Address Line 2:", "address2", "Suite A", "text", &field);
878 form1.fields.push_back(field);
879 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52880 "City:", "city", "San Francisco", "text", &field);
881 form1.fields.push_back(field);
882 autofill_test::CreateTestFormField(
883 "State:", "state", "California", "text", &field);
884 form1.fields.push_back(field);
885 autofill_test::CreateTestFormField(
886 "Zip:", "zip", "94102", "text", &field);
887 form1.fields.push_back(field);
888 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:07889 "Email:", "email", "[email protected]", "text", &field);
890 form1.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:34891 // Phone gets updated.
892 autofill_test::CreateTestFormField(
[email protected]11c2bdd12011-05-23 18:24:32893 "Phone:", "phone", "6505556666", "text", &field);
[email protected]465d07f2010-11-30 04:52:34894 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33895
[email protected]f1ed7272010-11-11 21:57:07896 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:55897 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24898 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21899 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
900 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24901 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33902
[email protected]3813dec2011-05-11 20:56:36903 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33904 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36905 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33906 MessageLoop::current()->Run();
907
[email protected]e90c2252011-03-10 12:29:21908 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34909 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]465d07f2010-11-30 04:52:34910 "Washington", "[email protected]", NULL, "1600 Pennsylvania Avenue",
[email protected]11c2bdd12011-05-23 18:24:32911 "Suite A", "San Francisco", "California", "94102", NULL, "4085556666",
[email protected]37ff612e2011-02-03 15:54:52912 NULL);
[email protected]e90c2252011-03-10 12:29:21913 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:07914 ASSERT_EQ(1U, results1.size());
915 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:33916
[email protected]f1ed7272010-11-11 21:57:07917 // Now create an updated profile.
918 FormData form2;
919 autofill_test::CreateTestFormField(
920 "First name:", "first_name", "George", "text", &field);
921 form2.fields.push_back(field);
922 autofill_test::CreateTestFormField(
923 "Last name:", "last_name", "Washington", "text", &field);
924 form2.fields.push_back(field);
925 autofill_test::CreateTestFormField(
926 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
927 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:34928 autofill_test::CreateTestFormField(
929 "Address Line 2:", "address2", "Suite A", "text", &field);
930 form2.fields.push_back(field);
931 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52932 "City:", "city", "San Francisco", "text", &field);
933 form2.fields.push_back(field);
934 autofill_test::CreateTestFormField(
935 "State:", "state", "California", "text", &field);
936 form2.fields.push_back(field);
937 autofill_test::CreateTestFormField(
938 "Zip:", "zip", "94102", "text", &field);
939 form2.fields.push_back(field);
940 autofill_test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:34941 "Email:", "email", "[email protected]", "text", &field);
942 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:07943 // Country gets added.
944 autofill_test::CreateTestFormField(
945 "Country:", "country", "USA", "text", &field);
946 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:34947 // Phone gets updated.
[email protected]f1ed7272010-11-11 21:57:07948 autofill_test::CreateTestFormField(
[email protected]11c2bdd12011-05-23 18:24:32949 "Phone:", "phone", "6502231234", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07950 form2.fields.push_back(field);
951
952 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:55953 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:21954 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
955 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24956 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:07957
[email protected]3813dec2011-05-11 20:56:36958 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:07959 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36960 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:07961 MessageLoop::current()->Run();
962
[email protected]e90c2252011-03-10 12:29:21963 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:07964
[email protected]023e1822011-04-13 15:52:24965 // Add multi-valued phone number to expectation. Also, country gets added.
966 std::vector<string16> values;
967 expected.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
[email protected]11c2bdd12011-05-23 18:24:32968 values.push_back(ASCIIToUTF16("6502231234"));
[email protected]023e1822011-04-13 15:52:24969 expected.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
970 expected.SetInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("United States"));
[email protected]f1ed7272010-11-11 21:57:07971 ASSERT_EQ(1U, results2.size());
[email protected]023e1822011-04-13 15:52:24972 EXPECT_EQ(0, expected.CompareMulti(*results2[0]));
[email protected]f1ed7272010-11-11 21:57:07973}
974
975TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) {
976 FormData form1;
977 webkit_glue::FormField field;
978 autofill_test::CreateTestFormField(
979 "First name:", "first_name", "George", "text", &field);
980 form1.fields.push_back(field);
981 autofill_test::CreateTestFormField(
982 "Last name:", "last_name", "Washington", "text", &field);
983 form1.fields.push_back(field);
984 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52985 "Address Line 1:", "address", "190 High Street", "text", &field);
986 form1.fields.push_back(field);
987 autofill_test::CreateTestFormField(
988 "City:", "city", "Philadelphia", "text", &field);
989 form1.fields.push_back(field);
990 autofill_test::CreateTestFormField(
991 "State:", "state", "Pennsylvania", "text", &field);
992 form1.fields.push_back(field);
993 autofill_test::CreateTestFormField(
994 "Zip:", "zipcode", "19106", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07995 form1.fields.push_back(field);
996
997 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:55998 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:24999 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211000 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1001 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241002 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071003
[email protected]3813dec2011-05-11 20:56:361004 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071005 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361006 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071007 MessageLoop::current()->Run();
1008
[email protected]e90c2252011-03-10 12:29:211009 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:341010 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521011 "Washington", NULL, NULL, "190 High Street", NULL,
1012 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL);
[email protected]e90c2252011-03-10 12:29:211013 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071014 ASSERT_EQ(1U, results1.size());
1015 EXPECT_EQ(0, expected.Compare(*results1[0]));
1016
1017 // Submit a form with new data for the first profile.
1018 FormData form2;
1019 autofill_test::CreateTestFormField(
1020 "First name:", "first_name", "George", "text", &field);
1021 form2.fields.push_back(field);
1022 autofill_test::CreateTestFormField(
1023 "Last name:", "last_name", "Washington", "text", &field);
1024 form2.fields.push_back(field);
1025 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521026 "Email:", "email", "[email protected]", "text", &field);
1027 form2.fields.push_back(field);
1028 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071029 "Address Line 1:", "address", "190 High Street", "text", &field);
1030 form2.fields.push_back(field);
1031 autofill_test::CreateTestFormField(
1032 "City:", "city", "Philadelphia", "text", &field);
1033 form2.fields.push_back(field);
1034 autofill_test::CreateTestFormField(
1035 "State:", "state", "Pennsylvania", "text", &field);
1036 form2.fields.push_back(field);
1037 autofill_test::CreateTestFormField(
1038 "Zip:", "zipcode", "19106", "text", &field);
1039 form2.fields.push_back(field);
1040
1041 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551042 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211043 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1044 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241045 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071046
[email protected]3813dec2011-05-11 20:56:361047 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071048 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361049 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071050 MessageLoop::current()->Run();
1051
[email protected]e90c2252011-03-10 12:29:211052 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071053
[email protected]e90c2252011-03-10 12:29:211054 AutofillProfile expected2;
[email protected]027dd442011-02-15 23:17:341055 autofill_test::SetProfileInfo(&expected2, "George", NULL,
[email protected]cea1d112010-07-01 00:57:331056 "Washington", "[email protected]", NULL, "190 High Street", NULL,
1057 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:071058 ASSERT_EQ(1U, results2.size());
1059 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1060}
[email protected]cea1d112010-07-01 00:57:331061
[email protected]f1ed7272010-11-11 21:57:071062TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) {
1063 FormData form1;
1064 webkit_glue::FormField field;
1065 autofill_test::CreateTestFormField(
1066 "First name:", "first_name", "George", "text", &field);
1067 form1.fields.push_back(field);
1068 autofill_test::CreateTestFormField(
1069 "Last name:", "last_name", "Washington", "text", &field);
1070 form1.fields.push_back(field);
1071 autofill_test::CreateTestFormField(
1072 "Company:", "company", "Government", "text", &field);
1073 form1.fields.push_back(field);
1074 autofill_test::CreateTestFormField(
1075 "Email:", "email", "[email protected]", "text", &field);
1076 form1.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:521077 autofill_test::CreateTestFormField(
1078 "Address Line 1:", "address", "190 High Street", "text", &field);
1079 form1.fields.push_back(field);
1080 autofill_test::CreateTestFormField(
1081 "City:", "city", "Philadelphia", "text", &field);
1082 form1.fields.push_back(field);
1083 autofill_test::CreateTestFormField(
1084 "State:", "state", "Pennsylvania", "text", &field);
1085 form1.fields.push_back(field);
1086 autofill_test::CreateTestFormField(
1087 "Zip:", "zipcode", "19106", "text", &field);
1088 form1.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071089
1090 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551091 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241092 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211093 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1094 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241095 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071096
[email protected]3813dec2011-05-11 20:56:361097 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071098 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361099 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071100 MessageLoop::current()->Run();
1101
[email protected]e90c2252011-03-10 12:29:211102 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:341103 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521104 "Washington", "[email protected]", "Government", "190 High Street", NULL,
1105 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL);
[email protected]e90c2252011-03-10 12:29:211106 const std::vector<AutofillProfile*>& results1 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071107 ASSERT_EQ(1U, results1.size());
1108 EXPECT_EQ(0, expected.Compare(*results1[0]));
1109
1110 // Submit a form with new data for the first profile.
1111 FormData form2;
1112 autofill_test::CreateTestFormField(
1113 "First name:", "first_name", "George", "text", &field);
1114 form2.fields.push_back(field);
1115 autofill_test::CreateTestFormField(
1116 "Last name:", "last_name", "Washington", "text", &field);
1117 form2.fields.push_back(field);
1118 // Note missing Company field.
1119 autofill_test::CreateTestFormField(
1120 "Email:", "email", "[email protected]", "text", &field);
1121 form2.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:521122 autofill_test::CreateTestFormField(
1123 "Address Line 1:", "address", "190 High Street", "text", &field);
1124 form2.fields.push_back(field);
1125 autofill_test::CreateTestFormField(
1126 "City:", "city", "Philadelphia", "text", &field);
1127 form2.fields.push_back(field);
1128 autofill_test::CreateTestFormField(
1129 "State:", "state", "Pennsylvania", "text", &field);
1130 form2.fields.push_back(field);
1131 autofill_test::CreateTestFormField(
1132 "Zip:", "zipcode", "19106", "text", &field);
1133 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071134
1135 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551136 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211137 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1138 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241139 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071140
[email protected]3813dec2011-05-11 20:56:361141 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071142 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361143 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071144 MessageLoop::current()->Run();
1145
[email protected]e90c2252011-03-10 12:29:211146 const std::vector<AutofillProfile*>& results2 = personal_data_->profiles();
[email protected]f1ed7272010-11-11 21:57:071147
1148 // Expect no change.
1149 ASSERT_EQ(1U, results2.size());
1150 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]cea1d112010-07-01 00:57:331151}
[email protected]d7da65d2010-11-11 19:26:051152
[email protected]37ff612e2011-02-03 15:54:521153TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) {
1154 FormData form1;
1155 webkit_glue::FormField field;
1156 autofill_test::CreateTestFormField(
1157 "First name:", "first_name", "George", "text", &field);
1158 form1.fields.push_back(field);
1159 autofill_test::CreateTestFormField(
1160 "Last name:", "last_name", "Washington", "text", &field);
1161 form1.fields.push_back(field);
1162 autofill_test::CreateTestFormField(
1163 "Company:", "company", "Government", "text", &field);
1164 form1.fields.push_back(field);
1165 autofill_test::CreateTestFormField(
1166 "Email:", "email", "[email protected]", "text", &field);
1167 form1.fields.push_back(field);
1168 autofill_test::CreateTestFormField(
1169 "Address Line 1:", "address", "190 High Street", "text", &field);
1170 form1.fields.push_back(field);
1171 autofill_test::CreateTestFormField(
1172 "City:", "city", "Philadelphia", "text", &field);
1173 form1.fields.push_back(field);
1174
1175 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551176 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241177 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211178 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1,
1179 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241180 ASSERT_FALSE(imported_credit_card);
[email protected]414c35482011-02-09 01:26:131181
[email protected]3813dec2011-05-11 20:56:361182 // Note: no refresh here.
[email protected]414c35482011-02-09 01:26:131183
[email protected]e90c2252011-03-10 12:29:211184 const std::vector<AutofillProfile*>& profiles = personal_data_->profiles();
[email protected]414c35482011-02-09 01:26:131185 ASSERT_EQ(0U, profiles.size());
1186 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
1187 ASSERT_EQ(0U, credit_cards.size());
[email protected]37ff612e2011-02-03 15:54:521188}
1189
[email protected]d7da65d2010-11-11 19:26:051190TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) {
1191 FormData form1;
1192
1193 // Start with a single valid credit card form.
1194 webkit_glue::FormField field;
1195 autofill_test::CreateTestFormField(
1196 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1197 form1.fields.push_back(field);
1198 autofill_test::CreateTestFormField(
1199 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1200 form1.fields.push_back(field);
1201 autofill_test::CreateTestFormField(
1202 "Exp Month:", "exp_month", "01", "text", &field);
1203 form1.fields.push_back(field);
1204 autofill_test::CreateTestFormField(
1205 "Exp Year:", "exp_year", "2011", "text", &field);
1206 form1.fields.push_back(field);
1207
1208 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551209 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241210 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211211 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1212 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241213 ASSERT_TRUE(imported_credit_card);
1214 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1215 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051216
[email protected]3813dec2011-05-11 20:56:361217 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051218 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361219 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051220 MessageLoop::current()->Run();
1221
1222 CreditCard expected;
1223 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341224 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051225 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1226 ASSERT_EQ(1U, results.size());
1227 EXPECT_EQ(0, expected.Compare(*results[0]));
1228
1229 // Add a second different valid credit card.
1230 FormData form2;
1231 autofill_test::CreateTestFormField(
1232 "Name on card:", "name_on_card", "Jim Johansen", "text", &field);
1233 form2.fields.push_back(field);
1234 autofill_test::CreateTestFormField(
1235 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field);
1236 form2.fields.push_back(field);
1237 autofill_test::CreateTestFormField(
1238 "Exp Month:", "exp_month", "02", "text", &field);
1239 form2.fields.push_back(field);
1240 autofill_test::CreateTestFormField(
1241 "Exp Year:", "exp_year", "2012", "text", &field);
1242 form2.fields.push_back(field);
1243
1244 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551245 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211246 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1247 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241248 ASSERT_TRUE(imported_credit_card);
1249 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1250 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051251
[email protected]3813dec2011-05-11 20:56:361252 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051253 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361254 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051255 MessageLoop::current()->Run();
1256
1257 CreditCard expected2;
1258 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341259 "Jim Johansen", "5500000000000004", "02", "2012");
[email protected]d7da65d2010-11-11 19:26:051260 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1261 ASSERT_EQ(2U, results2.size());
1262 EXPECT_EQ(0, expected.Compare(*results2[0]));
1263 EXPECT_EQ(0, expected2.Compare(*results2[1]));
1264}
1265
1266TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) {
1267 FormData form1;
1268
1269 // Start with a single valid credit card form.
1270 webkit_glue::FormField field;
1271 autofill_test::CreateTestFormField(
1272 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1273 form1.fields.push_back(field);
1274 autofill_test::CreateTestFormField(
1275 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1276 form1.fields.push_back(field);
1277 autofill_test::CreateTestFormField(
1278 "Exp Month:", "exp_month", "01", "text", &field);
1279 form1.fields.push_back(field);
1280 autofill_test::CreateTestFormField(
1281 "Exp Year:", "exp_year", "2011", "text", &field);
1282 form1.fields.push_back(field);
1283
1284 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551285 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241286 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211287 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1288 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241289 ASSERT_TRUE(imported_credit_card);
1290 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1291 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051292
[email protected]3813dec2011-05-11 20:56:361293 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051294 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361295 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051296 MessageLoop::current()->Run();
1297
1298 CreditCard expected;
1299 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341300 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051301 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1302 ASSERT_EQ(1U, results.size());
1303 EXPECT_EQ(0, expected.Compare(*results[0]));
1304
1305 // Add a second different invalid credit card.
1306 FormData form2;
1307 autofill_test::CreateTestFormField(
1308 "Name on card:", "name_on_card", "Jim Johansen", "text", &field);
1309 form2.fields.push_back(field);
1310 autofill_test::CreateTestFormField(
1311 "Card Number:", "card_number", "1000000000000000", "text", &field);
1312 form2.fields.push_back(field);
1313 autofill_test::CreateTestFormField(
1314 "Exp Month:", "exp_month", "02", "text", &field);
1315 form2.fields.push_back(field);
1316 autofill_test::CreateTestFormField(
1317 "Exp Year:", "exp_year", "2012", "text", &field);
1318 form2.fields.push_back(field);
1319
1320 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551321 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211322 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1323 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241324 ASSERT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051325
1326 // Note: no refresh here.
1327
1328 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1329 ASSERT_EQ(1U, results2.size());
1330 EXPECT_EQ(0, expected.Compare(*results2[0]));
1331}
1332
1333TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) {
1334 FormData form1;
1335
1336 // Start with a single valid credit card form.
1337 webkit_glue::FormField field;
1338 autofill_test::CreateTestFormField(
1339 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1340 form1.fields.push_back(field);
1341 autofill_test::CreateTestFormField(
1342 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1343 form1.fields.push_back(field);
1344 autofill_test::CreateTestFormField(
1345 "Exp Month:", "exp_month", "01", "text", &field);
1346 form1.fields.push_back(field);
1347 autofill_test::CreateTestFormField(
1348 "Exp Year:", "exp_year", "2011", "text", &field);
1349 form1.fields.push_back(field);
1350
1351 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551352 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241353 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211354 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1355 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241356 ASSERT_TRUE(imported_credit_card);
1357 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1358 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051359
[email protected]3813dec2011-05-11 20:56:361360 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051361 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361362 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051363 MessageLoop::current()->Run();
1364
1365 CreditCard expected;
1366 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341367 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051368 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1369 ASSERT_EQ(1U, results.size());
1370 EXPECT_EQ(0, expected.Compare(*results[0]));
1371
1372 // Add a second different valid credit card where the year is different but
1373 // the credit card number matches.
1374 FormData form2;
1375 autofill_test::CreateTestFormField(
1376 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1377 form2.fields.push_back(field);
1378 autofill_test::CreateTestFormField(
1379 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field);
1380 form2.fields.push_back(field);
1381 autofill_test::CreateTestFormField(
1382 "Exp Month:", "exp_month", "01", "text", &field);
1383 form2.fields.push_back(field);
1384 autofill_test::CreateTestFormField(
1385 "Exp Year:", "exp_year", "2012", "text", &field);
1386 form2.fields.push_back(field);
1387
1388 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551389 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211390 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1391 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241392 ASSERT_TRUE(imported_credit_card);
1393 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1394 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051395
[email protected]3813dec2011-05-11 20:56:361396 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051397 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361398 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051399 MessageLoop::current()->Run();
1400
1401 // Expect that the newer information is saved. In this case the year is
1402 // updated to "2012".
1403 CreditCard expected2;
1404 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341405 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051406 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1407 ASSERT_EQ(1U, results2.size());
1408 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1409}
1410
1411TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) {
1412 FormData form1;
1413
1414 // Start with a single valid credit card form.
1415 webkit_glue::FormField field;
1416 autofill_test::CreateTestFormField(
1417 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1418 form1.fields.push_back(field);
1419 autofill_test::CreateTestFormField(
1420 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1421 form1.fields.push_back(field);
1422 autofill_test::CreateTestFormField(
1423 "Exp Month:", "exp_month", "01", "text", &field);
1424 form1.fields.push_back(field);
1425 autofill_test::CreateTestFormField(
1426 "Exp Year:", "exp_year", "2011", "text", &field);
1427 form1.fields.push_back(field);
1428
1429 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551430 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241431 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211432 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1433 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241434 ASSERT_TRUE(imported_credit_card);
1435 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1436 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051437
[email protected]3813dec2011-05-11 20:56:361438 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051439 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361440 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051441 MessageLoop::current()->Run();
1442
1443 CreditCard expected;
1444 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341445 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051446 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1447 ASSERT_EQ(1U, results.size());
1448 EXPECT_EQ(0, expected.Compare(*results[0]));
1449
1450 // Add a second credit card with no number.
1451 FormData form2;
1452 autofill_test::CreateTestFormField(
1453 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1454 form2.fields.push_back(field);
1455 autofill_test::CreateTestFormField(
1456 "Exp Month:", "exp_month", "01", "text", &field);
1457 form2.fields.push_back(field);
1458 autofill_test::CreateTestFormField(
1459 "Exp Year:", "exp_year", "2012", "text", &field);
1460 form2.fields.push_back(field);
1461
1462 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551463 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211464 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1465 &imported_credit_card));
[email protected]3e6e82da2011-04-06 05:41:341466 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051467
1468 // Note: no refresh here.
1469
1470 // No change is expected.
1471 CreditCard expected2;
1472 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341473 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051474 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1475 ASSERT_EQ(1U, results2.size());
1476 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1477}
1478
1479TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) {
1480 FormData form1;
1481
1482 // Start with a single valid credit card form.
1483 webkit_glue::FormField field;
1484 autofill_test::CreateTestFormField(
1485 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1486 form1.fields.push_back(field);
1487 autofill_test::CreateTestFormField(
1488 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1489 form1.fields.push_back(field);
1490 autofill_test::CreateTestFormField(
1491 "Exp Month:", "exp_month", "01", "text", &field);
1492 form1.fields.push_back(field);
1493 autofill_test::CreateTestFormField(
1494 "Exp Year:", "exp_year", "2011", "text", &field);
1495 form1.fields.push_back(field);
1496
1497 FormStructure form_structure1(form1);
[email protected]68e91e92011-03-16 06:02:551498 form_structure1.DetermineHeuristicTypes();
[email protected]abcdf1a2011-02-04 23:12:241499 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211500 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1501 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241502 ASSERT_TRUE(imported_credit_card);
1503 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1504 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051505
[email protected]3813dec2011-05-11 20:56:361506 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051507 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361508 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051509 MessageLoop::current()->Run();
1510
1511 CreditCard expected;
1512 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341513 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051514 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1515 ASSERT_EQ(1U, results.size());
1516 EXPECT_EQ(0, expected.Compare(*results[0]));
1517
1518 // Add a second different valid credit card where the name is missing but
1519 // the credit card number matches.
1520 FormData form2;
1521 // Note missing name.
1522 autofill_test::CreateTestFormField(
1523 "Card Number:", "card_number", "4111111111111111", "text", &field);
1524 form2.fields.push_back(field);
1525 autofill_test::CreateTestFormField(
1526 "Exp Month:", "exp_month", "01", "text", &field);
1527 form2.fields.push_back(field);
1528 autofill_test::CreateTestFormField(
1529 "Exp Year:", "exp_year", "2011", "text", &field);
1530 form2.fields.push_back(field);
1531
1532 FormStructure form_structure2(form2);
[email protected]68e91e92011-03-16 06:02:551533 form_structure2.DetermineHeuristicTypes();
[email protected]2a958552011-05-05 04:01:211534 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1535 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241536 ASSERT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051537
[email protected]7ed9caa2010-11-18 01:54:011538 // Note: no refresh here.
[email protected]d7da65d2010-11-11 19:26:051539
1540 // No change is expected.
1541 CreditCard expected2;
1542 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341543 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051544 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1545 ASSERT_EQ(1U, results2.size());
1546 EXPECT_EQ(0, expected2.Compare(*results2[0]));
[email protected]cdd0d4482011-07-22 04:24:221547
1548 // Add a third credit card where the expiration date is missing.
1549 FormData form3;
1550 autofill_test::CreateTestFormField(
1551 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field);
1552 form3.fields.push_back(field);
1553 autofill_test::CreateTestFormField(
1554 "Card Number:", "card_number", "5555555555554444", "text", &field);
1555 form3.fields.push_back(field);
1556 // Note missing expiration month and year..
1557
1558 FormStructure form_structure3(form3);
1559 form_structure3.DetermineHeuristicTypes();
1560 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3,
1561 &imported_credit_card));
1562 ASSERT_FALSE(imported_credit_card);
1563
1564 // Note: no refresh here.
1565
1566 // No change is expected.
1567 CreditCard expected3;
1568 autofill_test::SetCreditCardInfo(&expected3,
1569 "Biggie Smalls", "4111111111111111", "01", "2011");
1570 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
1571 ASSERT_EQ(1U, results3.size());
1572 EXPECT_EQ(0, expected3.Compare(*results2[0]));
[email protected]d7da65d2010-11-11 19:26:051573}
1574
1575TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) {
[email protected]cdd0d4482011-07-22 04:24:221576 // Start with a single valid credit card stored via the preferences.
1577 // Note the empty name.
1578 CreditCard saved_credit_card;
1579 autofill_test::SetCreditCardInfo(&saved_credit_card,
1580 "", "4111111111111111" /* Visa */, "01", "2011");
1581 personal_data_->AddCreditCard(saved_credit_card);
[email protected]d7da65d2010-11-11 19:26:051582
[email protected]3813dec2011-05-11 20:56:361583 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051584 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361585 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051586 MessageLoop::current()->Run();
1587
[email protected]cdd0d4482011-07-22 04:24:221588 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1589 ASSERT_EQ(1U, results1.size());
1590 EXPECT_EQ(saved_credit_card, *results1[0]);
1591
[email protected]d7da65d2010-11-11 19:26:051592
1593 // Add a second different valid credit card where the year is different but
1594 // the credit card number matches.
[email protected]cdd0d4482011-07-22 04:24:221595 FormData form;
1596 webkit_glue::FormField field;
[email protected]d7da65d2010-11-11 19:26:051597 autofill_test::CreateTestFormField(
1598 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221599 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051600 autofill_test::CreateTestFormField(
1601 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221602 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051603 autofill_test::CreateTestFormField(
1604 "Exp Month:", "exp_month", "01", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221605 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051606 autofill_test::CreateTestFormField(
[email protected]cdd0d4482011-07-22 04:24:221607 "Exp Year:", "exp_year", "2012", "text", &field);
1608 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051609
[email protected]cdd0d4482011-07-22 04:24:221610 FormStructure form_structure(form);
1611 form_structure.DetermineHeuristicTypes();
1612 const CreditCard* imported_credit_card;
1613 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
[email protected]2a958552011-05-05 04:01:211614 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241615 ASSERT_TRUE(imported_credit_card);
1616 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1617 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051618
[email protected]3813dec2011-05-11 20:56:361619 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051620 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361621 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051622 MessageLoop::current()->Run();
1623
1624 // Expect that the newer information is saved. In this case the year is
1625 // added to the existing credit card.
1626 CreditCard expected2;
1627 autofill_test::SetCreditCardInfo(&expected2,
[email protected]cdd0d4482011-07-22 04:24:221628 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051629 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1630 ASSERT_EQ(1U, results2.size());
1631 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1632}
[email protected]ca64d232011-05-06 05:46:001633
[email protected]1308c2832011-05-09 18:30:231634TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
[email protected]ca64d232011-05-06 05:46:001635 // Check that there are no available types with no profiles stored.
[email protected]1308c2832011-05-09 18:30:231636 FieldTypeSet non_empty_types;
1637 personal_data_->GetNonEmptyTypes(&non_empty_types);
1638 EXPECT_EQ(0U, non_empty_types.size());
[email protected]ca64d232011-05-06 05:46:001639
1640 // Test with one profile stored.
1641 AutofillProfile profile0;
1642 autofill_test::SetProfileInfo(&profile0,
1643 "Marion", NULL, "Morrison",
1644 "[email protected]", NULL, "123 Zoo St.", NULL, "Hollywood", "CA",
[email protected]11c2bdd12011-05-23 18:24:321645 "91601", "US", "14155678910", NULL);
[email protected]ca64d232011-05-06 05:46:001646
[email protected]3813dec2011-05-11 20:56:361647 personal_data_->AddProfile(profile0);
1648
1649 // Verify that the web database has been updated and the notification sent.
1650 EXPECT_CALL(personal_data_observer_,
1651 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1652 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001653
[email protected]1308c2832011-05-09 18:30:231654 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]11c2bdd12011-05-23 18:24:321655 EXPECT_EQ(14U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231656 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1657 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1658 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1659 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1660 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1661 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1662 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1663 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1664 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1665 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
[email protected]11c2bdd12011-05-23 18:24:321666 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
[email protected]1308c2832011-05-09 18:30:231667 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1668 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1669 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001670
1671 // Test with multiple profiles stored.
1672 AutofillProfile profile1;
1673 autofill_test::SetProfileInfo(&profile1,
1674 "Josephine", "Alicia", "Saenz",
1675 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]11c2bdd12011-05-23 18:24:321676 "US", "16502937549", "14082849239");
[email protected]ca64d232011-05-06 05:46:001677
1678 AutofillProfile profile2;
1679 autofill_test::SetProfileInfo(&profile2,
1680 "Josephine", "Alicia", "Saenz",
1681 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]11c2bdd12011-05-23 18:24:321682 "32801", "US", "16502937549", "14152849239");
[email protected]ca64d232011-05-06 05:46:001683
[email protected]3813dec2011-05-11 20:56:361684 personal_data_->AddProfile(profile1);
1685 personal_data_->AddProfile(profile2);
1686
1687 // Verify that the web database has been updated and the notification sent.
1688 EXPECT_CALL(personal_data_observer_,
1689 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1690 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001691
[email protected]1308c2832011-05-09 18:30:231692 personal_data_->GetNonEmptyTypes(&non_empty_types);
1693 EXPECT_EQ(23U, non_empty_types.size());
1694 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1695 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1696 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1697 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1698 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1699 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1700 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1701 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1702 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1703 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1704 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1705 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1706 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1707 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1708 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1709 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1710 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1711 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
1712 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_NUMBER));
1713 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_CITY_CODE));
1714 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_COUNTRY_CODE));
1715 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_CITY_AND_NUMBER));
1716 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001717
1718 // Test with credit card information also stored.
1719 CreditCard credit_card;
1720 autofill_test::SetCreditCardInfo(&credit_card,
1721 "John Dillinger", "423456789012" /* Visa */,
1722 "01", "2010");
[email protected]3813dec2011-05-11 20:56:361723 personal_data_->AddCreditCard(credit_card);
[email protected]ca64d232011-05-06 05:46:001724
[email protected]3813dec2011-05-11 20:56:361725 // Verify that the web database has been updated and the notification sent.
1726 EXPECT_CALL(personal_data_observer_,
1727 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1728 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001729
[email protected]1308c2832011-05-09 18:30:231730 personal_data_->GetNonEmptyTypes(&non_empty_types);
1731 EXPECT_EQ(30U, non_empty_types.size());
1732 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1733 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1734 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1735 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1736 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1737 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1738 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1739 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1740 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1741 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1742 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1743 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1744 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1745 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1746 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1747 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1748 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1749 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
1750 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_NUMBER));
1751 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_CITY_CODE));
1752 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_COUNTRY_CODE));
1753 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_CITY_AND_NUMBER));
1754 EXPECT_TRUE(non_empty_types.count(PHONE_FAX_WHOLE_NUMBER));
1755 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NAME));
1756 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NUMBER));
1757 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_MONTH));
1758 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_2_DIGIT_YEAR));
1759 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1760 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR));
1761 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR));
[email protected]ca64d232011-05-06 05:46:001762}