blob: 70c811194c0a0e638682d3387c8beb6efe073df0 [file] [log] [blame]
[email protected]f2cd8362012-01-23 22:34:001// Copyright (c) 2012 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]7e49ad32012-06-14 14:22:078#include "base/guid.h"
[email protected]3b63f8f42011-03-28 01:54:159#include "base/memory/scoped_ptr.h"
[email protected]2609bc12010-01-24 08:32:5510#include "base/message_loop.h"
[email protected]fabb4ba2013-03-20 20:32:0511#include "base/synchronization/waitable_event.h"
[email protected]be1ce6a72010-08-03 14:35:2212#include "base/utf_string_conversions.h"
[email protected]bf9257742011-08-11 21:01:1513#include "chrome/test/base/testing_browser_process.h"
[email protected]a4ff9eae2011-08-01 19:58:1614#include "chrome/test/base/testing_profile.h"
[email protected]e4b2fa32013-03-09 22:56:5615#include "components/autofill/browser/autofill_common_test.h"
16#include "components/autofill/browser/autofill_metrics.h"
17#include "components/autofill/browser/autofill_profile.h"
18#include "components/autofill/browser/form_structure.h"
19#include "components/autofill/browser/personal_data_manager.h"
20#include "components/autofill/browser/personal_data_manager_observer.h"
[email protected]ece282a2013-04-11 04:39:5721#include "components/autofill/browser/webdata/autofill_webdata_service.h"
[email protected]edf48d42013-03-07 05:44:4322#include "components/autofill/common/form_data.h"
[email protected]da84fa42013-03-24 20:57:3623#include "components/webdata/encryptor/encryptor.h"
[email protected]6c2381d2011-10-19 02:52:5324#include "content/public/browser/notification_details.h"
25#include "content/public/browser/notification_registrar.h"
26#include "content/public/browser/notification_source.h"
[email protected]0d6e9bd2011-10-18 04:29:1627#include "content/public/browser/notification_types.h"
[email protected]b8d48332012-06-03 21:59:5328#include "content/public/test/mock_notification_observer.h"
[email protected]e97882f2012-06-04 02:23:1729#include "content/public/test/test_browser_thread.h"
[email protected]2609bc12010-01-24 08:32:5530#include "testing/gmock/include/gmock/gmock.h"
31#include "testing/gtest/include/gtest/gtest.h"
32
[email protected]631bb742011-11-02 11:29:3933using content::BrowserThread;
[email protected]cea1d112010-07-01 00:57:3334
[email protected]dfd1818d2012-10-26 21:53:2935namespace {
36
[email protected]2609bc12010-01-24 08:32:5537ACTION(QuitUIMessageLoop) {
[email protected]faec6312010-10-05 03:35:3438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2609bc12010-01-24 08:32:5539 MessageLoop::current()->Quit();
40}
41
[email protected]a7e585a2011-08-08 20:32:5442class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver {
[email protected]2609bc12010-01-24 08:32:5543 public:
44 PersonalDataLoadedObserverMock() {}
45 virtual ~PersonalDataLoadedObserverMock() {}
46
[email protected]3813dec2011-05-11 20:56:3647 MOCK_METHOD0(OnPersonalDataChanged, void());
[email protected]2609bc12010-01-24 08:32:5548};
49
[email protected]dfd1818d2012-10-26 21:53:2950// Unlike the base AutofillMetrics, exposes copy and assignment constructors,
51// which are handy for briefer test code. The AutofillMetrics class is
52// stateless, so this is safe.
53class TestAutofillMetrics : public AutofillMetrics {
54 public:
55 TestAutofillMetrics() {}
56 virtual ~TestAutofillMetrics() {}
57};
58
59} // anonymous namespace
60
[email protected]2609bc12010-01-24 08:32:5561class PersonalDataManagerTest : public testing::Test {
62 protected:
63 PersonalDataManagerTest()
[email protected]faec6312010-10-05 03:35:3464 : ui_thread_(BrowserThread::UI, &message_loop_),
65 db_thread_(BrowserThread::DB) {
[email protected]2609bc12010-01-24 08:32:5566 }
67
68 virtual void SetUp() {
69 db_thread_.Start();
70
71 profile_.reset(new TestingProfile);
[email protected]d07edd42012-05-14 23:49:4672 profile_->CreateWebDataService();
[email protected]2609bc12010-01-24 08:32:5573
[email protected]468327f2010-10-04 20:02:2974 autofill_test::DisableSystemServices(profile_.get());
[email protected]2609bc12010-01-24 08:32:5575 ResetPersonalDataManager();
76 }
77
78 virtual void TearDown() {
[email protected]ea9edcb02011-09-23 22:05:0479 // Destruction order is imposed explicitly here.
80 personal_data_.reset(NULL);
81 profile_.reset(NULL);
[email protected]2609bc12010-01-24 08:32:5582
[email protected]fabb4ba2013-03-20 20:32:0583 // Schedule another task on the DB thread to notify us that it's safe to
84 // stop the thread.
85 base::WaitableEvent done(false, false);
86 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
87 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
88 done.Wait();
[email protected]a778709f2011-12-10 00:28:1789 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
[email protected]2609bc12010-01-24 08:32:5590 MessageLoop::current()->Run();
[email protected]fabb4ba2013-03-20 20:32:0591 db_thread_.Stop();
[email protected]2609bc12010-01-24 08:32:5592 }
93
94 void ResetPersonalDataManager() {
[email protected]0b2f513b2013-04-05 20:13:2395 personal_data_.reset(new PersonalDataManager("en-US"));
[email protected]e0976a72010-04-02 01:25:2496 personal_data_->Init(profile_.get());
[email protected]412bde72013-02-07 06:06:2497 personal_data_->AddObserver(&personal_data_observer_);
[email protected]3813dec2011-05-11 20:56:3698
99 // Verify that the web database has been updated and the notification sent.
100 EXPECT_CALL(personal_data_observer_,
101 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
102 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55103 }
104
[email protected]2609bc12010-01-24 08:32:55105 MessageLoopForUI message_loop_;
[email protected]c38831a12011-10-28 12:44:49106 content::TestBrowserThread ui_thread_;
107 content::TestBrowserThread db_thread_;
[email protected]2609bc12010-01-24 08:32:55108 scoped_ptr<TestingProfile> profile_;
[email protected]ea9edcb02011-09-23 22:05:04109 scoped_ptr<PersonalDataManager> personal_data_;
[email protected]6c2381d2011-10-19 02:52:53110 content::NotificationRegistrar registrar_;
[email protected]b8d48332012-06-03 21:59:53111 content::MockNotificationObserver observer_;
[email protected]2609bc12010-01-24 08:32:55112 PersonalDataLoadedObserverMock personal_data_observer_;
113};
114
[email protected]0ed984b2011-04-28 01:22:02115TEST_F(PersonalDataManagerTest, AddProfile) {
[email protected]0ed984b2011-04-28 01:22:02116 AutofillProfile profile0;
117 autofill_test::SetProfileInfo(&profile0,
118 "John", "Mitchell", "Smith",
119 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
[email protected]91b073d2013-01-05 01:30:28120 "94102", "US", "4158889999");
[email protected]0ed984b2011-04-28 01:22:02121
122 // Add profile0 to the database.
123 personal_data_->AddProfile(profile0);
124
125 // Reload the database.
126 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02127
128 // Verify the addition.
[email protected]771ad212012-11-29 18:58:33129 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]0ed984b2011-04-28 01:22:02130 ASSERT_EQ(1U, results1.size());
[email protected]f2cd8362012-01-23 22:34:00131 EXPECT_EQ(0, profile0.Compare(*results1[0]));
[email protected]0ed984b2011-04-28 01:22:02132
133 // Add profile with identical values. Duplicates should not get saved.
134 AutofillProfile profile0a = profile0;
[email protected]7e49ad32012-06-14 14:22:07135 profile0a.set_guid(base::GenerateGUID());
[email protected]0ed984b2011-04-28 01:22:02136 personal_data_->AddProfile(profile0a);
137
138 // Reload the database.
139 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02140
141 // Verify the non-addition.
[email protected]771ad212012-11-29 18:58:33142 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]0ed984b2011-04-28 01:22:02143 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:00144 EXPECT_EQ(0, profile0.Compare(*results2[0]));
[email protected]0ed984b2011-04-28 01:22:02145
146 // New profile with different email.
147 AutofillProfile profile1 = profile0;
[email protected]7e49ad32012-06-14 14:22:07148 profile1.set_guid(base::GenerateGUID());
[email protected]6b44b582012-11-10 06:31:18149 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("[email protected]"));
[email protected]0ed984b2011-04-28 01:22:02150
151 // Add the different profile. This should save as a separate profile.
152 // Note that if this same profile was "merged" it would collapse to one
153 // profile with a multi-valued entry for email.
154 personal_data_->AddProfile(profile1);
155
156 // Reload the database.
157 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02158
159 // Verify the addition.
[email protected]771ad212012-11-29 18:58:33160 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]0ed984b2011-04-28 01:22:02161 ASSERT_EQ(2U, results3.size());
[email protected]f2cd8362012-01-23 22:34:00162 EXPECT_EQ(0, profile0.Compare(*results3[0]));
163 EXPECT_EQ(0, profile1.Compare(*results3[1]));
[email protected]0ed984b2011-04-28 01:22:02164}
165
[email protected]3813dec2011-05-11 20:56:36166TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) {
[email protected]e90c2252011-03-10 12:29:21167 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29168 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34169 "Marion", "Mitchell", "Morrison",
[email protected]2609bc12010-01-24 08:32:55170 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54171 "91601", "US", "12345678910");
[email protected]2609bc12010-01-24 08:32:55172
[email protected]e90c2252011-03-10 12:29:21173 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29174 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34175 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55176 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54177 "US", "19482937549");
[email protected]2609bc12010-01-24 08:32:55178
[email protected]e90c2252011-03-10 12:29:21179 AutofillProfile profile2;
[email protected]468327f2010-10-04 20:02:29180 autofill_test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34181 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55182 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:54183 "32801", "US", "19482937549");
[email protected]2609bc12010-01-24 08:32:55184
[email protected]542e1992010-07-14 18:25:52185 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36186 personal_data_->AddProfile(profile0);
187 personal_data_->AddProfile(profile1);
188
189 // Verify that the web database has been updated and the notification sent.
190 EXPECT_CALL(personal_data_observer_,
191 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
192 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55193
[email protected]771ad212012-11-29 18:58:33194 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]2609bc12010-01-24 08:32:55195 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36196 EXPECT_EQ(0, profile0.Compare(*results1[0]));
197 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]2609bc12010-01-24 08:32:55198
[email protected]3813dec2011-05-11 20:56:36199 // Update, remove, and add.
[email protected]6b44b582012-11-10 06:31:18200 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
[email protected]3813dec2011-05-11 20:56:36201 personal_data_->UpdateProfile(profile0);
[email protected]8da04b852012-11-16 22:10:39202 personal_data_->RemoveByGUID(profile1.guid());
[email protected]3813dec2011-05-11 20:56:36203 personal_data_->AddProfile(profile2);
204
205 // Verify that the web database has been updated and the notification sent.
206 EXPECT_CALL(personal_data_observer_,
207 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
208 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55209
[email protected]771ad212012-11-29 18:58:33210 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]2609bc12010-01-24 08:32:55211 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36212 EXPECT_EQ(0, profile0.Compare(*results2[0]));
213 EXPECT_EQ(0, profile2.Compare(*results2[1]));
[email protected]2609bc12010-01-24 08:32:55214
215 // Reset the PersonalDataManager. This tests that the personal data was saved
216 // to the web database, and that we can load the profiles from the web
217 // database.
218 ResetPersonalDataManager();
219
[email protected]2609bc12010-01-24 08:32:55220 // Verify that we've loaded the profiles from the web database.
[email protected]771ad212012-11-29 18:58:33221 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]2609bc12010-01-24 08:32:55222 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36223 EXPECT_EQ(0, profile0.Compare(*results3[0]));
224 EXPECT_EQ(0, profile2.Compare(*results3[1]));
[email protected]2609bc12010-01-24 08:32:55225}
[email protected]f11f6212010-01-25 20:47:20226
[email protected]3813dec2011-05-11 20:56:36227TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) {
228 CreditCard credit_card0;
229 autofill_test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54230 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]f11f6212010-01-25 20:47:20231
[email protected]3813dec2011-05-11 20:56:36232 CreditCard credit_card1;
233 autofill_test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54234 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]f11f6212010-01-25 20:47:20235
[email protected]3813dec2011-05-11 20:56:36236 CreditCard credit_card2;
237 autofill_test::SetCreditCardInfo(&credit_card2,
[email protected]2a13edd2010-10-26 22:52:54238 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
[email protected]f11f6212010-01-25 20:47:20239
[email protected]542e1992010-07-14 18:25:52240 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36241 personal_data_->AddCreditCard(credit_card0);
242 personal_data_->AddCreditCard(credit_card1);
243
244 // Verify that the web database has been updated and the notification sent.
245 EXPECT_CALL(personal_data_observer_,
246 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
247 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20248
[email protected]f11f6212010-01-25 20:47:20249 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
250 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36251 EXPECT_EQ(0, credit_card0.Compare(*results1[0]));
252 EXPECT_EQ(0, credit_card1.Compare(*results1[1]));
[email protected]f11f6212010-01-25 20:47:20253
[email protected]3813dec2011-05-11 20:56:36254 // Update, remove, and add.
[email protected]6b44b582012-11-10 06:31:18255 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe"));
[email protected]3813dec2011-05-11 20:56:36256 personal_data_->UpdateCreditCard(credit_card0);
[email protected]8da04b852012-11-16 22:10:39257 personal_data_->RemoveByGUID(credit_card1.guid());
[email protected]3813dec2011-05-11 20:56:36258 personal_data_->AddCreditCard(credit_card2);
259
260 // Verify that the web database has been updated and the notification sent.
261 EXPECT_CALL(personal_data_observer_,
262 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
263 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20264
[email protected]f11f6212010-01-25 20:47:20265 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
266 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36267 EXPECT_EQ(credit_card0, *results2[0]);
268 EXPECT_EQ(credit_card2, *results2[1]);
[email protected]f11f6212010-01-25 20:47:20269
270 // Reset the PersonalDataManager. This tests that the personal data was saved
271 // to the web database, and that we can load the credit cards from the web
272 // database.
273 ResetPersonalDataManager();
274
[email protected]f11f6212010-01-25 20:47:20275 // Verify that we've loaded the credit cards from the web database.
276 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
277 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36278 EXPECT_EQ(credit_card0, *results3[0]);
279 EXPECT_EQ(credit_card2, *results3[1]);
[email protected]f11f6212010-01-25 20:47:20280}
[email protected]e0976a72010-04-02 01:25:24281
[email protected]3813dec2011-05-11 20:56:36282TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) {
[email protected]e90c2252011-03-10 12:29:21283 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29284 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34285 "Marion", "Mitchell", "Morrison",
[email protected]542e1992010-07-14 18:25:52286 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54287 "91601", "US", "12345678910");
[email protected]542e1992010-07-14 18:25:52288
[email protected]e90c2252011-03-10 12:29:21289 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29290 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34291 "Josephine", "Alicia", "Saenz",
[email protected]542e1992010-07-14 18:25:52292 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54293 "US", "19482937549");
[email protected]542e1992010-07-14 18:25:52294
[email protected]3813dec2011-05-11 20:56:36295 CreditCard credit_card0;
296 autofill_test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54297 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]542e1992010-07-14 18:25:52298
[email protected]3813dec2011-05-11 20:56:36299 CreditCard credit_card1;
300 autofill_test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54301 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]542e1992010-07-14 18:25:52302
[email protected]542e1992010-07-14 18:25:52303 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36304 personal_data_->AddProfile(profile0);
305 personal_data_->AddProfile(profile1);
306
307 // Verify that the web database has been updated and the notification sent.
308 EXPECT_CALL(personal_data_observer_,
309 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
310 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52311
[email protected]771ad212012-11-29 18:58:33312 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]542e1992010-07-14 18:25:52313 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36314 EXPECT_EQ(0, profile0.Compare(*results1[0]));
315 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]414c35482011-02-09 01:26:13316
[email protected]542e1992010-07-14 18:25:52317 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36318 personal_data_->AddCreditCard(credit_card0);
319 personal_data_->AddCreditCard(credit_card1);
[email protected]542e1992010-07-14 18:25:52320
[email protected]3813dec2011-05-11 20:56:36321 // Verify that the web database has been updated and the notification sent.
322 EXPECT_CALL(personal_data_observer_,
323 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
324 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52325
326 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
327 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36328 EXPECT_EQ(credit_card0, *results2[0]);
329 EXPECT_EQ(credit_card1, *results2[1]);
[email protected]542e1992010-07-14 18:25:52330
[email protected]e43783402010-11-04 19:45:04331 // Determine uniqueness by inserting all of the GUIDs into a set and verifying
332 // the size of the set matches the number of GUIDs.
333 std::set<std::string> guids;
334 guids.insert(profile0.guid());
335 guids.insert(profile1.guid());
[email protected]3813dec2011-05-11 20:56:36336 guids.insert(credit_card0.guid());
337 guids.insert(credit_card1.guid());
[email protected]e43783402010-11-04 19:45:04338 EXPECT_EQ(4U, guids.size());
[email protected]542e1992010-07-14 18:25:52339}
340
[email protected]3813dec2011-05-11 20:56:36341// Test for http://crbug.com/50047. Makes sure that guids are populated
342// correctly on load.
[email protected]7c543fd2010-07-24 02:44:59343TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) {
[email protected]e90c2252011-03-10 12:29:21344 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29345 autofill_test::SetProfileInfo(&profile0,
[email protected]4ef55f8c12011-09-17 00:06:54346 "y", "", "", "", "", "", "", "", "", "", "", "");
[email protected]7c543fd2010-07-24 02:44:59347
[email protected]7c543fd2010-07-24 02:44:59348 // Add the profile0 to the db.
[email protected]3813dec2011-05-11 20:56:36349 personal_data_->AddProfile(profile0);
[email protected]7c543fd2010-07-24 02:44:59350
[email protected]3813dec2011-05-11 20:56:36351 // Verify that the web database has been updated and the notification sent.
352 EXPECT_CALL(personal_data_observer_,
353 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]7c543fd2010-07-24 02:44:59354 MessageLoop::current()->Run();
355
356 // Verify that we've loaded the profiles from the web database.
[email protected]771ad212012-11-29 18:58:33357 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]7c543fd2010-07-24 02:44:59358 ASSERT_EQ(1U, results2.size());
[email protected]3813dec2011-05-11 20:56:36359 EXPECT_EQ(0, profile0.Compare(*results2[0]));
[email protected]7c543fd2010-07-24 02:44:59360
361 // Add a new profile.
[email protected]e90c2252011-03-10 12:29:21362 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29363 autofill_test::SetProfileInfo(&profile1,
[email protected]4ef55f8c12011-09-17 00:06:54364 "z", "", "", "", "", "", "", "", "", "", "", "");
[email protected]3813dec2011-05-11 20:56:36365 personal_data_->AddProfile(profile1);
[email protected]7c543fd2010-07-24 02:44:59366
[email protected]3813dec2011-05-11 20:56:36367 // Verify that the web database has been updated and the notification sent.
368 EXPECT_CALL(personal_data_observer_,
369 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
370 MessageLoop::current()->Run();
371
372 // Make sure the two profiles have different GUIDs, both valid.
[email protected]771ad212012-11-29 18:58:33373 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]7c543fd2010-07-24 02:44:59374 ASSERT_EQ(2U, results3.size());
[email protected]e43783402010-11-04 19:45:04375 EXPECT_NE(results3[0]->guid(), results3[1]->guid());
[email protected]7e49ad32012-06-14 14:22:07376 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid()));
377 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid()));
[email protected]7c543fd2010-07-24 02:44:59378}
379
[email protected]98a94ee2010-07-12 16:03:22380TEST_F(PersonalDataManagerTest, SetEmptyProfile) {
[email protected]e90c2252011-03-10 12:29:21381 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29382 autofill_test::SetProfileInfo(&profile0,
[email protected]4ef55f8c12011-09-17 00:06:54383 "", "", "", "", "", "", "", "", "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22384
[email protected]98a94ee2010-07-12 16:03:22385 // Add the empty profile to the database.
[email protected]3813dec2011-05-11 20:56:36386 personal_data_->AddProfile(profile0);
[email protected]98a94ee2010-07-12 16:03:22387
[email protected]3813dec2011-05-11 20:56:36388 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22389
390 // Reset the PersonalDataManager. This tests that the personal data was saved
391 // to the web database, and that we can load the profiles from the web
392 // database.
393 ResetPersonalDataManager();
394
[email protected]98a94ee2010-07-12 16:03:22395 // Verify that we've loaded the profiles from the web database.
[email protected]771ad212012-11-29 18:58:33396 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]98a94ee2010-07-12 16:03:22397 ASSERT_EQ(0U, results2.size());
398}
399
400TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) {
[email protected]3813dec2011-05-11 20:56:36401 CreditCard credit_card0;
402 autofill_test::SetCreditCardInfo(&credit_card0, "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22403
404 // Add the empty credit card to the database.
[email protected]3813dec2011-05-11 20:56:36405 personal_data_->AddCreditCard(credit_card0);
[email protected]98a94ee2010-07-12 16:03:22406
[email protected]3813dec2011-05-11 20:56:36407 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22408
409 // Reset the PersonalDataManager. This tests that the personal data was saved
410 // to the web database, and that we can load the credit cards from the web
411 // database.
412 ResetPersonalDataManager();
413
[email protected]98a94ee2010-07-12 16:03:22414 // Verify that we've loaded the credit cards from the web database.
415 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
416 ASSERT_EQ(0U, results2.size());
417}
418
[email protected]e0976a72010-04-02 01:25:24419TEST_F(PersonalDataManagerTest, Refresh) {
[email protected]e90c2252011-03-10 12:29:21420 AutofillProfile profile0;
[email protected]468327f2010-10-04 20:02:29421 autofill_test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34422 "Marion", "Mitchell", "Morrison",
[email protected]e0976a72010-04-02 01:25:24423 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54424 "91601", "US", "12345678910");
[email protected]e0976a72010-04-02 01:25:24425
[email protected]e90c2252011-03-10 12:29:21426 AutofillProfile profile1;
[email protected]468327f2010-10-04 20:02:29427 autofill_test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34428 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24429 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54430 "US", "19482937549");
[email protected]e0976a72010-04-02 01:25:24431
[email protected]e0976a72010-04-02 01:25:24432 // Add the test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36433 personal_data_->AddProfile(profile0);
434 personal_data_->AddProfile(profile1);
[email protected]e0976a72010-04-02 01:25:24435
[email protected]e43783402010-11-04 19:45:04436 // Labels depend on other profiles in the list - update labels manually.
[email protected]e90c2252011-03-10 12:29:21437 std::vector<AutofillProfile *> profile_pointers;
[email protected]9f321442010-10-25 23:53:53438 profile_pointers.push_back(&profile0);
439 profile_pointers.push_back(&profile1);
[email protected]e90c2252011-03-10 12:29:21440 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]e0976a72010-04-02 01:25:24441
[email protected]3813dec2011-05-11 20:56:36442 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24443 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36444 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24445 MessageLoop::current()->Run();
446
[email protected]771ad212012-11-29 18:58:33447 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]e0976a72010-04-02 01:25:24448 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36449 EXPECT_EQ(profile0, *results1[0]);
450 EXPECT_EQ(profile1, *results1[1]);
[email protected]e0976a72010-04-02 01:25:24451
[email protected]e90c2252011-03-10 12:29:21452 AutofillProfile profile2;
[email protected]61f25cd0e2010-11-07 05:23:50453 autofill_test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34454 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24455 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:54456 "32801", "US", "19482937549");
[email protected]e0976a72010-04-02 01:25:24457
[email protected]9f321442010-10-25 23:53:53458 // Adjust all labels.
[email protected]61f25cd0e2010-11-07 05:23:50459 profile_pointers.push_back(&profile2);
[email protected]e90c2252011-03-10 12:29:21460 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]9f321442010-10-25 23:53:53461
[email protected]e2b31052013-03-25 01:49:37462 scoped_refptr<AutofillWebDataService> wds =
463 AutofillWebDataService::FromBrowserContext(profile_.get());
[email protected]d07edd42012-05-14 23:49:46464 ASSERT_TRUE(wds.get());
[email protected]e90c2252011-03-10 12:29:21465 wds->AddAutofillProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24466
467 personal_data_->Refresh();
468
[email protected]3813dec2011-05-11 20:56:36469 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24470 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36471 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24472 MessageLoop::current()->Run();
473
[email protected]771ad212012-11-29 18:58:33474 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]e0976a72010-04-02 01:25:24475 ASSERT_EQ(3U, results2.size());
[email protected]3813dec2011-05-11 20:56:36476 EXPECT_EQ(profile0, *results2[0]);
477 EXPECT_EQ(profile1, *results2[1]);
478 EXPECT_EQ(profile2, *results2[2]);
[email protected]e0976a72010-04-02 01:25:24479
[email protected]e90c2252011-03-10 12:29:21480 wds->RemoveAutofillProfile(profile1.guid());
481 wds->RemoveAutofillProfile(profile2.guid());
[email protected]e0976a72010-04-02 01:25:24482
483 // Before telling the PDM to refresh, simulate an edit to one of the profiles
[email protected]663bd9e2011-03-21 01:07:01484 // via a SetProfile update (this would happen if the Autofill window was
[email protected]e0976a72010-04-02 01:25:24485 // open with a previous snapshot of the profiles, and something [e.g. sync]
486 // removed a profile from the browser. In this edge case, we will end up
487 // in a consistent state by dropping the write).
[email protected]6b44b582012-11-10 06:31:18488 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo"));
[email protected]3813dec2011-05-11 20:56:36489 personal_data_->UpdateProfile(profile0);
490 personal_data_->AddProfile(profile1);
491 personal_data_->AddProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24492
[email protected]3813dec2011-05-11 20:56:36493 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24494 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36495 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24496 MessageLoop::current()->Run();
497
[email protected]771ad212012-11-29 18:58:33498 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]e0976a72010-04-02 01:25:24499 ASSERT_EQ(1U, results3.size());
[email protected]3813dec2011-05-11 20:56:36500 EXPECT_EQ(profile0, *results2[0]);
[email protected]e0976a72010-04-02 01:25:24501}
[email protected]83723f02010-04-07 17:33:10502
[email protected]ce78c1f92010-04-09 02:23:26503TEST_F(PersonalDataManagerTest, ImportFormData) {
[email protected]cea1d112010-07-01 00:57:33504 FormData form;
[email protected]1ecbe862012-10-05 01:29:14505 FormFieldData field;
[email protected]468327f2010-10-04 20:02:29506 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33507 "First name:", "first_name", "George", "text", &field);
508 form.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29509 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33510 "Last name:", "last_name", "Washington", "text", &field);
511 form.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29512 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33513 "Email:", "email", "[email protected]", "text", &field);
514 form.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52515 autofill_test::CreateTestFormField(
516 "Address:", "address1", "21 Laussat St", "text", &field);
517 form.fields.push_back(field);
518 autofill_test::CreateTestFormField(
519 "City:", "city", "San Francisco", "text", &field);
520 form.fields.push_back(field);
521 autofill_test::CreateTestFormField(
522 "State:", "state", "California", "text", &field);
523 form.fields.push_back(field);
524 autofill_test::CreateTestFormField(
525 "Zip:", "zip", "94102", "text", &field);
526 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23527 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29528 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24529 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21530 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
531 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24532 ASSERT_FALSE(imported_credit_card);
[email protected]ce78c1f92010-04-09 02:23:26533
[email protected]3813dec2011-05-11 20:56:36534 // Verify that the web database has been updated and the notification sent.
[email protected]ce78c1f92010-04-09 02:23:26535 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36536 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]ce78c1f92010-04-09 02:23:26537 MessageLoop::current()->Run();
538
[email protected]e90c2252011-03-10 12:29:21539 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34540 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52541 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54542 "San Francisco", "California", "94102", NULL, NULL);
[email protected]771ad212012-11-29 18:58:33543 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
[email protected]ce78c1f92010-04-09 02:23:26544 ASSERT_EQ(1U, results.size());
[email protected]e43783402010-11-04 19:45:04545 EXPECT_EQ(0, expected.Compare(*results[0]));
[email protected]ce78c1f92010-04-09 02:23:26546}
547
[email protected]a2a1baf2011-02-03 20:22:00548TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) {
549 FormData form;
[email protected]1ecbe862012-10-05 01:29:14550 FormFieldData field;
[email protected]a2a1baf2011-02-03 20:22:00551 autofill_test::CreateTestFormField(
552 "First name:", "first_name", "George", "text", &field);
553 form.fields.push_back(field);
554 autofill_test::CreateTestFormField(
555 "Last name:", "last_name", "Washington", "text", &field);
556 form.fields.push_back(field);
557 autofill_test::CreateTestFormField(
558 "Email:", "email", "bogus", "text", &field);
559 form.fields.push_back(field);
560 autofill_test::CreateTestFormField(
561 "Address:", "address1", "21 Laussat St", "text", &field);
562 form.fields.push_back(field);
563 autofill_test::CreateTestFormField(
564 "City:", "city", "San Francisco", "text", &field);
565 form.fields.push_back(field);
566 autofill_test::CreateTestFormField(
567 "State:", "state", "California", "text", &field);
568 form.fields.push_back(field);
569 autofill_test::CreateTestFormField(
570 "Zip:", "zip", "94102", "text", &field);
571 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23572 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29573 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24574 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21575 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
576 &imported_credit_card));
[email protected]ca9bdeb2011-03-17 20:01:41577 ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card);
[email protected]a2a1baf2011-02-03 20:22:00578
[email protected]771ad212012-11-29 18:58:33579 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
[email protected]ca9bdeb2011-03-17 20:01:41580 ASSERT_EQ(0U, results.size());
[email protected]a2a1baf2011-02-03 20:22:00581}
582
[email protected]ad651d382013-04-10 06:31:22583// Tests that a 'confirm email' field does not block profile import.
584TEST_F(PersonalDataManagerTest, ImportFormDataTwoEmails) {
585 FormData form;
586 FormFieldData field;
587 autofill_test::CreateTestFormField(
588 "Name:", "name", "George Washington", "text", &field);
589 form.fields.push_back(field);
590 autofill_test::CreateTestFormField(
591 "Address:", "address1", "21 Laussat St", "text", &field);
592 form.fields.push_back(field);
593 autofill_test::CreateTestFormField(
594 "City:", "city", "San Francisco", "text", &field);
595 form.fields.push_back(field);
596 autofill_test::CreateTestFormField(
597 "State:", "state", "California", "text", &field);
598 form.fields.push_back(field);
599 autofill_test::CreateTestFormField(
600 "Zip:", "zip", "94102", "text", &field);
601 form.fields.push_back(field);
602 autofill_test::CreateTestFormField(
603 "Email:", "email", "[email protected]", "text", &field);
604 form.fields.push_back(field);
605 autofill_test::CreateTestFormField(
606 "Confirm email:", "confirm_email", "[email protected]", "text", &field);
607 form.fields.push_back(field);
608 FormStructure form_structure(form, std::string());
609 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
610 const CreditCard* imported_credit_card;
611 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
612 &imported_credit_card));
613 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
614 ASSERT_EQ(1U, results.size());
615}
616
617// Tests two email fields containing different values blocks provile import.
618TEST_F(PersonalDataManagerTest, ImportFormDataTwoDifferentEmails) {
619 FormData form;
620 FormFieldData field;
621 autofill_test::CreateTestFormField(
622 "Name:", "name", "George Washington", "text", &field);
623 form.fields.push_back(field);
624 autofill_test::CreateTestFormField(
625 "Address:", "address1", "21 Laussat St", "text", &field);
626 form.fields.push_back(field);
627 autofill_test::CreateTestFormField(
628 "City:", "city", "San Francisco", "text", &field);
629 form.fields.push_back(field);
630 autofill_test::CreateTestFormField(
631 "State:", "state", "California", "text", &field);
632 form.fields.push_back(field);
633 autofill_test::CreateTestFormField(
634 "Zip:", "zip", "94102", "text", &field);
635 form.fields.push_back(field);
636 autofill_test::CreateTestFormField(
637 "Email:", "email", "[email protected]", "text", &field);
638 form.fields.push_back(field);
639 autofill_test::CreateTestFormField(
640 "Email:", "email2", "[email protected]", "text", &field);
641 form.fields.push_back(field);
642 FormStructure form_structure(form, std::string());
643 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
644 const CreditCard* imported_credit_card;
645 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
646 &imported_credit_card));
647 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
648 ASSERT_EQ(0U, results.size());
649}
650
[email protected]204777552011-01-26 19:46:28651TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) {
[email protected]4fb058092010-11-24 23:52:25652 FormData form;
[email protected]1ecbe862012-10-05 01:29:14653 FormFieldData field;
[email protected]4fb058092010-11-24 23:52:25654 autofill_test::CreateTestFormField(
655 "First name:", "first_name", "George", "text", &field);
656 form.fields.push_back(field);
657 autofill_test::CreateTestFormField(
658 "Last name:", "last_name", "Washington", "text", &field);
659 form.fields.push_back(field);
660 autofill_test::CreateTestFormField(
661 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field);
662 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23663 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29664 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24665 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21666 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
667 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24668 ASSERT_FALSE(imported_credit_card);
[email protected]4fb058092010-11-24 23:52:25669
[email protected]771ad212012-11-29 18:58:33670 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
[email protected]4fb058092010-11-24 23:52:25671 ASSERT_EQ(0U, profiles.size());
672 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
673 ASSERT_EQ(0U, credit_cards.size());
674}
675
[email protected]a36215a2013-04-04 12:35:42676TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressUSA) {
677 // United States addresses must specifiy one address line, a city, state and
678 // zip code.
679 FormData form;
680 FormFieldData field;
681 autofill_test::CreateTestFormField(
682 "Name:", "name", "Barack Obama", "text", &field);
683 form.fields.push_back(field);
684 autofill_test::CreateTestFormField(
685 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
686 form.fields.push_back(field);
687 autofill_test::CreateTestFormField(
688 "City:", "city", "Washington", "text", &field);
689 form.fields.push_back(field);
690 autofill_test::CreateTestFormField(
691 "State:", "state", "DC", "text", &field);
692 form.fields.push_back(field);
693 autofill_test::CreateTestFormField(
694 "Zip:", "zip", "20500", "text", &field);
695 form.fields.push_back(field);
696 autofill_test::CreateTestFormField(
697 "Country:", "country", "USA", "text", &field);
698 form.fields.push_back(field);
699 FormStructure form_structure(form, std::string());
700 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
701 const CreditCard* imported_credit_card;
702 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
703 &imported_credit_card));
704 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
705 ASSERT_EQ(1U, profiles.size());
706}
707
708TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGB) {
709 // British addresses do not require a state/province as the county is usually
710 // not requested on forms.
711 FormData form;
712 FormFieldData field;
713 autofill_test::CreateTestFormField(
714 "Name:", "name", "David Cameron", "text", &field);
715 form.fields.push_back(field);
716 autofill_test::CreateTestFormField(
717 "Address:", "address", "10 Downing Street", "text", &field);
718 form.fields.push_back(field);
719 autofill_test::CreateTestFormField(
720 "City:", "city", "London", "text", &field);
721 form.fields.push_back(field);
722 autofill_test::CreateTestFormField(
723 "Postcode:", "postcode", "SW1A 2AA", "text", &field);
724 form.fields.push_back(field);
725 autofill_test::CreateTestFormField(
726 "Country:", "country", "United Kingdom", "text", &field);
727 form.fields.push_back(field);
728 FormStructure form_structure(form, std::string());
729 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
730 const CreditCard* imported_credit_card;
731 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
732 &imported_credit_card));
733 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
734 ASSERT_EQ(1U, profiles.size());
735}
736
737TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGI) {
738 // Gibraltar has the most minimal set of requirements for a valid address.
739 // There are no cities or provinces and no postal/zip code system.
740 FormData form;
741 FormFieldData field;
742 autofill_test::CreateTestFormField(
743 "Name:", "name", "Sir Adrian Johns", "text", &field);
744 form.fields.push_back(field);
745 autofill_test::CreateTestFormField(
746 "Address:", "address", "The Convent, Main Street", "text", &field);
747 form.fields.push_back(field);
748 autofill_test::CreateTestFormField(
749 "Country:", "country", "Gibraltar", "text", &field);
750 form.fields.push_back(field);
751 FormStructure form_structure(form, std::string());
752 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
753 const CreditCard* imported_credit_card;
754 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
755 &imported_credit_card));
756 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
757 ASSERT_EQ(1U, profiles.size());
758}
759
[email protected]3aa8bec22010-11-23 07:51:28760TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) {
761 FormData form;
[email protected]1ecbe862012-10-05 01:29:14762 FormFieldData field;
[email protected]3aa8bec22010-11-23 07:51:28763 autofill_test::CreateTestFormField(
764 "First name:", "first_name", "George", "text", &field);
765 form.fields.push_back(field);
766 autofill_test::CreateTestFormField(
767 "Last name:", "last_name", "Washington", "text", &field);
768 form.fields.push_back(field);
769 autofill_test::CreateTestFormField(
770 "Phone #:", "home_phone_area_code", "650", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04771 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28772 form.fields.push_back(field);
773 autofill_test::CreateTestFormField(
774 "Phone #:", "home_phone_prefix", "555", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04775 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28776 form.fields.push_back(field);
777 autofill_test::CreateTestFormField(
778 "Phone #:", "home_phone_suffix", "0000", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04779 field.max_length = 4;
[email protected]3aa8bec22010-11-23 07:51:28780 form.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52781 autofill_test::CreateTestFormField(
782 "Address:", "address1", "21 Laussat St", "text", &field);
783 form.fields.push_back(field);
784 autofill_test::CreateTestFormField(
785 "City:", "city", "San Francisco", "text", &field);
786 form.fields.push_back(field);
787 autofill_test::CreateTestFormField(
788 "State:", "state", "California", "text", &field);
789 form.fields.push_back(field);
790 autofill_test::CreateTestFormField(
791 "Zip:", "zip", "94102", "text", &field);
792 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23793 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29794 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24795 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21796 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
797 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24798 ASSERT_FALSE(imported_credit_card);
[email protected]3aa8bec22010-11-23 07:51:28799
[email protected]3813dec2011-05-11 20:56:36800 // Verify that the web database has been updated and the notification sent.
[email protected]3aa8bec22010-11-23 07:51:28801 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36802 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]3aa8bec22010-11-23 07:51:28803 MessageLoop::current()->Run();
804
[email protected]e90c2252011-03-10 12:29:21805 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34806 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52807 "Washington", NULL, NULL, "21 Laussat St", NULL,
[email protected]5c0208c2012-11-28 15:16:13808 "San Francisco", "California", "94102", NULL, "(650) 555-0000");
[email protected]771ad212012-11-29 18:58:33809 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
[email protected]3aa8bec22010-11-23 07:51:28810 ASSERT_EQ(1U, results.size());
811 EXPECT_EQ(0, expected.Compare(*results[0]));
812}
813
[email protected]47e119f02010-04-15 00:46:55814TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
[email protected]e43783402010-11-04 19:45:04815 CreditCard credit_card0;
[email protected]6b44b582012-11-10 06:31:18816 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John"));
[email protected]e43783402010-11-04 19:45:04817 CreditCard credit_card1;
[email protected]6b44b582012-11-10 06:31:18818 credit_card1.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul"));
[email protected]e43783402010-11-04 19:45:04819 CreditCard credit_card2;
[email protected]6b44b582012-11-10 06:31:18820 credit_card2.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo"));
[email protected]e43783402010-11-04 19:45:04821 CreditCard credit_card3;
[email protected]6b44b582012-11-10 06:31:18822 credit_card3.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other"));
[email protected]e43783402010-11-04 19:45:04823 CreditCard credit_card4;
[email protected]6b44b582012-11-10 06:31:18824 credit_card4.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy"));
[email protected]e43783402010-11-04 19:45:04825 CreditCard credit_card5;
[email protected]6b44b582012-11-10 06:31:18826 credit_card5.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio"));
[email protected]47e119f02010-04-15 00:46:55827
[email protected]98a94ee2010-07-12 16:03:22828 // Add the test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36829 personal_data_->AddCreditCard(credit_card0);
830 personal_data_->AddCreditCard(credit_card1);
831 personal_data_->AddCreditCard(credit_card2);
832 personal_data_->AddCreditCard(credit_card3);
833 personal_data_->AddCreditCard(credit_card4);
834 personal_data_->AddCreditCard(credit_card5);
[email protected]47e119f02010-04-15 00:46:55835
[email protected]18f92d4f2010-10-19 00:14:58836 // Reset the PersonalDataManager. This tests that the personal data was saved
837 // to the web database, and that we can load the credit cards from the web
838 // database.
839 ResetPersonalDataManager();
840
[email protected]47e119f02010-04-15 00:46:55841 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
842 ASSERT_EQ(6U, results.size());
[email protected]027dd442011-02-15 23:17:34843 EXPECT_EQ(credit_card0.guid(), results[0]->guid());
844 EXPECT_EQ(credit_card1.guid(), results[1]->guid());
845 EXPECT_EQ(credit_card2.guid(), results[2]->guid());
846 EXPECT_EQ(credit_card3.guid(), results[3]->guid());
847 EXPECT_EQ(credit_card4.guid(), results[4]->guid());
848 EXPECT_EQ(credit_card5.guid(), results[5]->guid());
[email protected]47e119f02010-04-15 00:46:55849}
[email protected]cea1d112010-07-01 00:57:33850
[email protected]f1ed7272010-11-11 21:57:07851TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) {
852 FormData form1;
[email protected]1ecbe862012-10-05 01:29:14853 FormFieldData field;
[email protected]468327f2010-10-04 20:02:29854 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33855 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07856 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29857 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33858 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07859 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29860 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33861 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07862 form1.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52863 autofill_test::CreateTestFormField(
864 "Address:", "address1", "21 Laussat St", "text", &field);
865 form1.fields.push_back(field);
866 autofill_test::CreateTestFormField(
867 "City:", "city", "San Francisco", "text", &field);
868 form1.fields.push_back(field);
869 autofill_test::CreateTestFormField(
870 "State:", "state", "California", "text", &field);
871 form1.fields.push_back(field);
872 autofill_test::CreateTestFormField(
873 "Zip:", "zip", "94102", "text", &field);
874 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33875
[email protected]685d4972013-02-12 01:06:23876 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:29877 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24878 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21879 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
880 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24881 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33882
[email protected]3813dec2011-05-11 20:56:36883 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33884 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36885 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33886 MessageLoop::current()->Run();
887
[email protected]e90c2252011-03-10 12:29:21888 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:34889 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52890 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54891 "San Francisco", "California", "94102", NULL, NULL);
[email protected]771ad212012-11-29 18:58:33892 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:07893 ASSERT_EQ(1U, results1.size());
894 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:33895
896 // Now create a completely different profile.
[email protected]f1ed7272010-11-11 21:57:07897 FormData form2;
[email protected]468327f2010-10-04 20:02:29898 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33899 "First name:", "first_name", "John", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07900 form2.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29901 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33902 "Last name:", "last_name", "Adams", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07903 form2.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:29904 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33905 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07906 form2.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:52907 autofill_test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24908 "Address:", "address1", "22 Laussat St", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52909 form2.fields.push_back(field);
910 autofill_test::CreateTestFormField(
911 "City:", "city", "San Francisco", "text", &field);
912 form2.fields.push_back(field);
913 autofill_test::CreateTestFormField(
914 "State:", "state", "California", "text", &field);
915 form2.fields.push_back(field);
916 autofill_test::CreateTestFormField(
917 "Zip:", "zip", "94102", "text", &field);
918 form2.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33919
[email protected]685d4972013-02-12 01:06:23920 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:29921 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:21922 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
923 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24924 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33925
[email protected]3813dec2011-05-11 20:56:36926 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33927 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36928 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33929 MessageLoop::current()->Run();
930
[email protected]771ad212012-11-29 18:58:33931 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]cea1d112010-07-01 00:57:33932
[email protected]e90c2252011-03-10 12:29:21933 AutofillProfile expected2;
[email protected]027dd442011-02-15 23:17:34934 autofill_test::SetProfileInfo(&expected2, "John", NULL,
[email protected]023e1822011-04-13 15:52:24935 "Adams", "[email protected]", NULL, "22 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54936 "San Francisco", "California", "94102", NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:07937 ASSERT_EQ(2U, results2.size());
938 EXPECT_EQ(0, expected.Compare(*results2[0]));
939 EXPECT_EQ(0, expected2.Compare(*results2[1]));
940}
[email protected]cea1d112010-07-01 00:57:33941
[email protected]023e1822011-04-13 15:52:24942TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) {
943 FormData form1;
[email protected]1ecbe862012-10-05 01:29:14944 FormFieldData field;
[email protected]023e1822011-04-13 15:52:24945 autofill_test::CreateTestFormField(
946 "First name:", "first_name", "George", "text", &field);
947 form1.fields.push_back(field);
948 autofill_test::CreateTestFormField(
949 "Last name:", "last_name", "Washington", "text", &field);
950 form1.fields.push_back(field);
951 autofill_test::CreateTestFormField(
952 "Email:", "email", "[email protected]", "text", &field);
953 form1.fields.push_back(field);
954 autofill_test::CreateTestFormField(
955 "Address:", "address1", "21 Laussat St", "text", &field);
956 form1.fields.push_back(field);
957 autofill_test::CreateTestFormField(
958 "City:", "city", "San Francisco", "text", &field);
959 form1.fields.push_back(field);
960 autofill_test::CreateTestFormField(
961 "State:", "state", "California", "text", &field);
962 form1.fields.push_back(field);
963 autofill_test::CreateTestFormField(
964 "Zip:", "zip", "94102", "text", &field);
965 form1.fields.push_back(field);
966
[email protected]685d4972013-02-12 01:06:23967 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:29968 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]023e1822011-04-13 15:52:24969 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21970 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
971 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24972 ASSERT_FALSE(imported_credit_card);
973
[email protected]3813dec2011-05-11 20:56:36974 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24975 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36976 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24977 MessageLoop::current()->Run();
978
979 AutofillProfile expected;
980 autofill_test::SetProfileInfo(&expected, "George", NULL,
981 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54982 "San Francisco", "California", "94102", NULL, NULL);
[email protected]771ad212012-11-29 18:58:33983 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]023e1822011-04-13 15:52:24984 ASSERT_EQ(1U, results1.size());
985 EXPECT_EQ(0, expected.Compare(*results1[0]));
986
987 // Now create a completely different profile.
988 FormData form2;
989 autofill_test::CreateTestFormField(
990 "First name:", "first_name", "John", "text", &field);
991 form2.fields.push_back(field);
992 autofill_test::CreateTestFormField(
993 "Last name:", "last_name", "Adams", "text", &field);
994 form2.fields.push_back(field);
995 autofill_test::CreateTestFormField(
996 "Email:", "email", "[email protected]", "text", &field);
997 form2.fields.push_back(field);
998 autofill_test::CreateTestFormField(
999 "Address:", "address1", "21 Laussat St", "text", &field);
1000 form2.fields.push_back(field);
1001 autofill_test::CreateTestFormField(
1002 "City:", "city", "San Francisco", "text", &field);
1003 form2.fields.push_back(field);
1004 autofill_test::CreateTestFormField(
1005 "State:", "state", "California", "text", &field);
1006 form2.fields.push_back(field);
1007 autofill_test::CreateTestFormField(
1008 "Zip:", "zip", "94102", "text", &field);
1009 form2.fields.push_back(field);
1010
[email protected]685d4972013-02-12 01:06:231011 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291012 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211013 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1014 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:241015 ASSERT_FALSE(imported_credit_card);
1016
[email protected]3813dec2011-05-11 20:56:361017 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:241018 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361019 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:241020 MessageLoop::current()->Run();
1021
[email protected]771ad212012-11-29 18:58:331022 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]023e1822011-04-13 15:52:241023
1024 // Modify expected to include multi-valued fields.
[email protected]d5ca8fb2013-04-11 17:54:311025 std::vector<base::string16> values;
[email protected]e4364512012-11-29 10:51:061026 expected.GetRawMultiInfo(NAME_FULL, &values);
[email protected]023e1822011-04-13 15:52:241027 values.push_back(ASCIIToUTF16("John Adams"));
[email protected]e4364512012-11-29 10:51:061028 expected.SetRawMultiInfo(NAME_FULL, values);
1029 expected.GetRawMultiInfo(EMAIL_ADDRESS, &values);
[email protected]023e1822011-04-13 15:52:241030 values.push_back(ASCIIToUTF16("[email protected]"));
[email protected]e4364512012-11-29 10:51:061031 expected.SetRawMultiInfo(EMAIL_ADDRESS, values);
[email protected]023e1822011-04-13 15:52:241032
1033 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:001034 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]023e1822011-04-13 15:52:241035}
1036
[email protected]f1ed7272010-11-11 21:57:071037TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) {
1038 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141039 FormFieldData field;
[email protected]468327f2010-10-04 20:02:291040 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:331041 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071042 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:291043 autofill_test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:331044 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071045 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:291046 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071047 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
1048 form1.fields.push_back(field);
[email protected]468327f2010-10-04 20:02:291049 autofill_test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:341050 "Address Line 2:", "address2", "Suite A", "text", &field);
1051 form1.fields.push_back(field);
1052 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521053 "City:", "city", "San Francisco", "text", &field);
1054 form1.fields.push_back(field);
1055 autofill_test::CreateTestFormField(
1056 "State:", "state", "California", "text", &field);
1057 form1.fields.push_back(field);
1058 autofill_test::CreateTestFormField(
1059 "Zip:", "zip", "94102", "text", &field);
1060 form1.fields.push_back(field);
1061 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071062 "Email:", "email", "[email protected]", "text", &field);
1063 form1.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:341064 autofill_test::CreateTestFormField(
[email protected]11c2bdd12011-05-23 18:24:321065 "Phone:", "phone", "6505556666", "text", &field);
[email protected]465d07f2010-11-30 04:52:341066 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:331067
[email protected]685d4972013-02-12 01:06:231068 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291069 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241070 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211071 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1072 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241073 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:331074
[email protected]3813dec2011-05-11 20:56:361075 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:331076 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361077 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:331078 MessageLoop::current()->Run();
1079
[email protected]e90c2252011-03-10 12:29:211080 AutofillProfile expected;
[email protected]5c0208c2012-11-28 15:16:131081 autofill_test::SetProfileInfo(
1082 &expected, "George", NULL, "Washington", "[email protected]", NULL,
1083 "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California",
1084 "94102", NULL, "(650) 555-6666");
[email protected]771ad212012-11-29 18:58:331085 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071086 ASSERT_EQ(1U, results1.size());
1087 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:331088
[email protected]f1ed7272010-11-11 21:57:071089 // Now create an updated profile.
1090 FormData form2;
1091 autofill_test::CreateTestFormField(
1092 "First name:", "first_name", "George", "text", &field);
1093 form2.fields.push_back(field);
1094 autofill_test::CreateTestFormField(
1095 "Last name:", "last_name", "Washington", "text", &field);
1096 form2.fields.push_back(field);
1097 autofill_test::CreateTestFormField(
1098 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
1099 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:341100 autofill_test::CreateTestFormField(
1101 "Address Line 2:", "address2", "Suite A", "text", &field);
1102 form2.fields.push_back(field);
1103 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521104 "City:", "city", "San Francisco", "text", &field);
1105 form2.fields.push_back(field);
1106 autofill_test::CreateTestFormField(
1107 "State:", "state", "California", "text", &field);
1108 form2.fields.push_back(field);
1109 autofill_test::CreateTestFormField(
1110 "Zip:", "zip", "94102", "text", &field);
1111 form2.fields.push_back(field);
1112 autofill_test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:341113 "Email:", "email", "[email protected]", "text", &field);
1114 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071115 // Country gets added.
1116 autofill_test::CreateTestFormField(
1117 "Country:", "country", "USA", "text", &field);
1118 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:341119 // Phone gets updated.
[email protected]f1ed7272010-11-11 21:57:071120 autofill_test::CreateTestFormField(
[email protected]11c2bdd12011-05-23 18:24:321121 "Phone:", "phone", "6502231234", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071122 form2.fields.push_back(field);
1123
[email protected]685d4972013-02-12 01:06:231124 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291125 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211126 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1127 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241128 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071129
[email protected]3813dec2011-05-11 20:56:361130 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071131 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361132 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071133 MessageLoop::current()->Run();
1134
[email protected]771ad212012-11-29 18:58:331135 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071136
[email protected]023e1822011-04-13 15:52:241137 // Add multi-valued phone number to expectation. Also, country gets added.
[email protected]d5ca8fb2013-04-11 17:54:311138 std::vector<base::string16> values;
[email protected]e4364512012-11-29 10:51:061139 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
[email protected]5c0208c2012-11-28 15:16:131140 values.push_back(ASCIIToUTF16("(650) 223-1234"));
[email protected]e4364512012-11-29 10:51:061141 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
[email protected]91b073d2013-01-05 01:30:281142 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
[email protected]f1ed7272010-11-11 21:57:071143 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:001144 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]f1ed7272010-11-11 21:57:071145}
1146
1147TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) {
1148 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141149 FormFieldData field;
[email protected]f1ed7272010-11-11 21:57:071150 autofill_test::CreateTestFormField(
1151 "First name:", "first_name", "George", "text", &field);
1152 form1.fields.push_back(field);
1153 autofill_test::CreateTestFormField(
1154 "Last name:", "last_name", "Washington", "text", &field);
1155 form1.fields.push_back(field);
1156 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521157 "Address Line 1:", "address", "190 High Street", "text", &field);
1158 form1.fields.push_back(field);
1159 autofill_test::CreateTestFormField(
1160 "City:", "city", "Philadelphia", "text", &field);
1161 form1.fields.push_back(field);
1162 autofill_test::CreateTestFormField(
1163 "State:", "state", "Pennsylvania", "text", &field);
1164 form1.fields.push_back(field);
1165 autofill_test::CreateTestFormField(
1166 "Zip:", "zipcode", "19106", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071167 form1.fields.push_back(field);
1168
[email protected]685d4972013-02-12 01:06:231169 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291170 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241171 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211172 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1173 &imported_credit_card));
[email protected]a73830e2011-10-05 01:12:581174 EXPECT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071175
[email protected]3813dec2011-05-11 20:56:361176 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071177 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361178 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071179 MessageLoop::current()->Run();
1180
[email protected]e90c2252011-03-10 12:29:211181 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:341182 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521183 "Washington", NULL, NULL, "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541184 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]771ad212012-11-29 18:58:331185 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071186 ASSERT_EQ(1U, results1.size());
1187 EXPECT_EQ(0, expected.Compare(*results1[0]));
1188
1189 // Submit a form with new data for the first profile.
1190 FormData form2;
1191 autofill_test::CreateTestFormField(
1192 "First name:", "first_name", "George", "text", &field);
1193 form2.fields.push_back(field);
1194 autofill_test::CreateTestFormField(
1195 "Last name:", "last_name", "Washington", "text", &field);
1196 form2.fields.push_back(field);
1197 autofill_test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521198 "Email:", "email", "[email protected]", "text", &field);
1199 form2.fields.push_back(field);
1200 autofill_test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071201 "Address Line 1:", "address", "190 High Street", "text", &field);
1202 form2.fields.push_back(field);
1203 autofill_test::CreateTestFormField(
1204 "City:", "city", "Philadelphia", "text", &field);
1205 form2.fields.push_back(field);
1206 autofill_test::CreateTestFormField(
1207 "State:", "state", "Pennsylvania", "text", &field);
1208 form2.fields.push_back(field);
1209 autofill_test::CreateTestFormField(
1210 "Zip:", "zipcode", "19106", "text", &field);
1211 form2.fields.push_back(field);
1212
[email protected]685d4972013-02-12 01:06:231213 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291214 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211215 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1216 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241217 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071218
[email protected]3813dec2011-05-11 20:56:361219 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071220 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361221 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071222 MessageLoop::current()->Run();
1223
[email protected]771ad212012-11-29 18:58:331224 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071225
[email protected]e90c2252011-03-10 12:29:211226 AutofillProfile expected2;
[email protected]027dd442011-02-15 23:17:341227 autofill_test::SetProfileInfo(&expected2, "George", NULL,
[email protected]cea1d112010-07-01 00:57:331228 "Washington", "[email protected]", NULL, "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541229 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:071230 ASSERT_EQ(1U, results2.size());
1231 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1232}
[email protected]cea1d112010-07-01 00:57:331233
[email protected]f1ed7272010-11-11 21:57:071234TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) {
1235 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141236 FormFieldData field;
[email protected]f1ed7272010-11-11 21:57:071237 autofill_test::CreateTestFormField(
1238 "First name:", "first_name", "George", "text", &field);
1239 form1.fields.push_back(field);
1240 autofill_test::CreateTestFormField(
1241 "Last name:", "last_name", "Washington", "text", &field);
1242 form1.fields.push_back(field);
1243 autofill_test::CreateTestFormField(
1244 "Company:", "company", "Government", "text", &field);
1245 form1.fields.push_back(field);
1246 autofill_test::CreateTestFormField(
1247 "Email:", "email", "[email protected]", "text", &field);
1248 form1.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:521249 autofill_test::CreateTestFormField(
1250 "Address Line 1:", "address", "190 High Street", "text", &field);
1251 form1.fields.push_back(field);
1252 autofill_test::CreateTestFormField(
1253 "City:", "city", "Philadelphia", "text", &field);
1254 form1.fields.push_back(field);
1255 autofill_test::CreateTestFormField(
1256 "State:", "state", "Pennsylvania", "text", &field);
1257 form1.fields.push_back(field);
1258 autofill_test::CreateTestFormField(
1259 "Zip:", "zipcode", "19106", "text", &field);
1260 form1.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071261
[email protected]685d4972013-02-12 01:06:231262 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291263 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241264 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211265 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1266 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241267 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071268
[email protected]3813dec2011-05-11 20:56:361269 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071270 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361271 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071272 MessageLoop::current()->Run();
1273
[email protected]e90c2252011-03-10 12:29:211274 AutofillProfile expected;
[email protected]027dd442011-02-15 23:17:341275 autofill_test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521276 "Washington", "[email protected]", "Government", "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541277 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]771ad212012-11-29 18:58:331278 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071279 ASSERT_EQ(1U, results1.size());
1280 EXPECT_EQ(0, expected.Compare(*results1[0]));
1281
1282 // Submit a form with new data for the first profile.
1283 FormData form2;
1284 autofill_test::CreateTestFormField(
1285 "First name:", "first_name", "George", "text", &field);
1286 form2.fields.push_back(field);
1287 autofill_test::CreateTestFormField(
1288 "Last name:", "last_name", "Washington", "text", &field);
1289 form2.fields.push_back(field);
1290 // Note missing Company field.
1291 autofill_test::CreateTestFormField(
1292 "Email:", "email", "[email protected]", "text", &field);
1293 form2.fields.push_back(field);
[email protected]37ff612e2011-02-03 15:54:521294 autofill_test::CreateTestFormField(
1295 "Address Line 1:", "address", "190 High Street", "text", &field);
1296 form2.fields.push_back(field);
1297 autofill_test::CreateTestFormField(
1298 "City:", "city", "Philadelphia", "text", &field);
1299 form2.fields.push_back(field);
1300 autofill_test::CreateTestFormField(
1301 "State:", "state", "Pennsylvania", "text", &field);
1302 form2.fields.push_back(field);
1303 autofill_test::CreateTestFormField(
1304 "Zip:", "zipcode", "19106", "text", &field);
1305 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071306
[email protected]685d4972013-02-12 01:06:231307 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291308 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211309 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1310 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241311 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071312
[email protected]3813dec2011-05-11 20:56:361313 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071314 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361315 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071316 MessageLoop::current()->Run();
1317
[email protected]771ad212012-11-29 18:58:331318 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071319
1320 // Expect no change.
1321 ASSERT_EQ(1U, results2.size());
1322 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]cea1d112010-07-01 00:57:331323}
[email protected]d7da65d2010-11-11 19:26:051324
[email protected]37ff612e2011-02-03 15:54:521325TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) {
1326 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141327 FormFieldData field;
[email protected]37ff612e2011-02-03 15:54:521328 autofill_test::CreateTestFormField(
1329 "First name:", "first_name", "George", "text", &field);
1330 form1.fields.push_back(field);
1331 autofill_test::CreateTestFormField(
1332 "Last name:", "last_name", "Washington", "text", &field);
1333 form1.fields.push_back(field);
1334 autofill_test::CreateTestFormField(
1335 "Company:", "company", "Government", "text", &field);
1336 form1.fields.push_back(field);
1337 autofill_test::CreateTestFormField(
1338 "Email:", "email", "[email protected]", "text", &field);
1339 form1.fields.push_back(field);
1340 autofill_test::CreateTestFormField(
1341 "Address Line 1:", "address", "190 High Street", "text", &field);
1342 form1.fields.push_back(field);
1343 autofill_test::CreateTestFormField(
1344 "City:", "city", "Philadelphia", "text", &field);
1345 form1.fields.push_back(field);
1346
[email protected]685d4972013-02-12 01:06:231347 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291348 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241349 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211350 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1,
1351 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241352 ASSERT_FALSE(imported_credit_card);
[email protected]414c35482011-02-09 01:26:131353
[email protected]3813dec2011-05-11 20:56:361354 // Note: no refresh here.
[email protected]414c35482011-02-09 01:26:131355
[email protected]771ad212012-11-29 18:58:331356 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
[email protected]414c35482011-02-09 01:26:131357 ASSERT_EQ(0U, profiles.size());
1358 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
1359 ASSERT_EQ(0U, credit_cards.size());
[email protected]37ff612e2011-02-03 15:54:521360}
1361
[email protected]0b5847612011-10-05 03:52:181362TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) {
1363 // Simulate having access to an auxiliary profile.
1364 // |auxiliary_profile| will be owned by |personal_data_|.
1365 AutofillProfile* auxiliary_profile = new AutofillProfile;
1366 autofill_test::SetProfileInfo(auxiliary_profile,
1367 "Tester", "Frederick", "McAddressBookTesterson",
1368 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco",
[email protected]91b073d2013-01-05 01:30:281369 "CA", "94102", "US", "1.415.888.9999");
[email protected]0b5847612011-10-05 03:52:181370 ScopedVector<AutofillProfile>& auxiliary_profiles =
1371 personal_data_->auxiliary_profiles_;
1372 auxiliary_profiles.push_back(auxiliary_profile);
1373
1374 // Simulate a form submission with a subset of the info.
1375 // Note that the phone number format is different from the saved format.
1376 FormData form;
[email protected]1ecbe862012-10-05 01:29:141377 FormFieldData field;
[email protected]0b5847612011-10-05 03:52:181378 autofill_test::CreateTestFormField(
1379 "First name:", "first_name", "Tester", "text", &field);
1380 form.fields.push_back(field);
1381 autofill_test::CreateTestFormField(
1382 "Last name:", "last_name", "McAddressBookTesterson", "text", &field);
1383 form.fields.push_back(field);
1384 autofill_test::CreateTestFormField(
1385 "Email:", "email", "[email protected]", "text", &field);
1386 form.fields.push_back(field);
1387 autofill_test::CreateTestFormField(
1388 "Address:", "address1", "1 Main", "text", &field);
1389 form.fields.push_back(field);
1390 autofill_test::CreateTestFormField(
1391 "City:", "city", "San Francisco", "text", &field);
1392 form.fields.push_back(field);
1393 autofill_test::CreateTestFormField(
1394 "State:", "state", "CA", "text", &field);
1395 form.fields.push_back(field);
1396 autofill_test::CreateTestFormField(
1397 "Zip:", "zip", "94102", "text", &field);
1398 form.fields.push_back(field);
1399 autofill_test::CreateTestFormField(
1400 "Phone:", "phone", "4158889999", "text", &field);
1401 form.fields.push_back(field);
1402
[email protected]685d4972013-02-12 01:06:231403 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:291404 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]0b5847612011-10-05 03:52:181405 const CreditCard* imported_credit_card;
1406 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
1407 &imported_credit_card));
1408 EXPECT_FALSE(imported_credit_card);
1409
1410 // Note: No refresh.
1411
1412 // Expect no change.
1413 const std::vector<AutofillProfile*>& web_profiles =
1414 personal_data_->web_profiles();
1415 EXPECT_EQ(0U, web_profiles.size());
1416 ASSERT_EQ(1U, auxiliary_profiles.size());
1417 EXPECT_EQ(0, auxiliary_profile->Compare(*auxiliary_profiles[0]));
1418}
1419
[email protected]d7da65d2010-11-11 19:26:051420TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) {
1421 FormData form1;
1422
1423 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141424 FormFieldData field;
[email protected]d7da65d2010-11-11 19:26:051425 autofill_test::CreateTestFormField(
1426 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1427 form1.fields.push_back(field);
1428 autofill_test::CreateTestFormField(
1429 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1430 form1.fields.push_back(field);
1431 autofill_test::CreateTestFormField(
1432 "Exp Month:", "exp_month", "01", "text", &field);
1433 form1.fields.push_back(field);
1434 autofill_test::CreateTestFormField(
1435 "Exp Year:", "exp_year", "2011", "text", &field);
1436 form1.fields.push_back(field);
1437
[email protected]685d4972013-02-12 01:06:231438 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291439 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241440 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211441 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1442 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241443 ASSERT_TRUE(imported_credit_card);
1444 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1445 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051446
[email protected]3813dec2011-05-11 20:56:361447 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051448 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361449 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051450 MessageLoop::current()->Run();
1451
1452 CreditCard expected;
1453 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341454 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051455 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1456 ASSERT_EQ(1U, results.size());
1457 EXPECT_EQ(0, expected.Compare(*results[0]));
1458
1459 // Add a second different valid credit card.
1460 FormData form2;
1461 autofill_test::CreateTestFormField(
[email protected]490a6a502011-09-27 17:30:111462 "Name on card:", "name_on_card", "", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051463 form2.fields.push_back(field);
1464 autofill_test::CreateTestFormField(
1465 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field);
1466 form2.fields.push_back(field);
1467 autofill_test::CreateTestFormField(
1468 "Exp Month:", "exp_month", "02", "text", &field);
1469 form2.fields.push_back(field);
1470 autofill_test::CreateTestFormField(
1471 "Exp Year:", "exp_year", "2012", "text", &field);
1472 form2.fields.push_back(field);
1473
[email protected]685d4972013-02-12 01:06:231474 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291475 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211476 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1477 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241478 ASSERT_TRUE(imported_credit_card);
1479 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1480 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051481
[email protected]3813dec2011-05-11 20:56:361482 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051483 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361484 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051485 MessageLoop::current()->Run();
1486
1487 CreditCard expected2;
1488 autofill_test::SetCreditCardInfo(&expected2,
[email protected]490a6a502011-09-27 17:30:111489 "", "5500000000000004", "02", "2012");
[email protected]d7da65d2010-11-11 19:26:051490 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1491 ASSERT_EQ(2U, results2.size());
1492 EXPECT_EQ(0, expected.Compare(*results2[0]));
1493 EXPECT_EQ(0, expected2.Compare(*results2[1]));
1494}
1495
1496TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) {
1497 FormData form1;
1498
1499 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141500 FormFieldData field;
[email protected]d7da65d2010-11-11 19:26:051501 autofill_test::CreateTestFormField(
1502 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1503 form1.fields.push_back(field);
1504 autofill_test::CreateTestFormField(
1505 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1506 form1.fields.push_back(field);
1507 autofill_test::CreateTestFormField(
1508 "Exp Month:", "exp_month", "01", "text", &field);
1509 form1.fields.push_back(field);
1510 autofill_test::CreateTestFormField(
1511 "Exp Year:", "exp_year", "2011", "text", &field);
1512 form1.fields.push_back(field);
1513
[email protected]685d4972013-02-12 01:06:231514 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291515 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241516 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211517 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1518 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241519 ASSERT_TRUE(imported_credit_card);
1520 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1521 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051522
[email protected]3813dec2011-05-11 20:56:361523 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051524 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361525 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051526 MessageLoop::current()->Run();
1527
1528 CreditCard expected;
1529 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341530 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051531 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1532 ASSERT_EQ(1U, results.size());
1533 EXPECT_EQ(0, expected.Compare(*results[0]));
1534
1535 // Add a second different invalid credit card.
1536 FormData form2;
1537 autofill_test::CreateTestFormField(
1538 "Name on card:", "name_on_card", "Jim Johansen", "text", &field);
1539 form2.fields.push_back(field);
1540 autofill_test::CreateTestFormField(
1541 "Card Number:", "card_number", "1000000000000000", "text", &field);
1542 form2.fields.push_back(field);
1543 autofill_test::CreateTestFormField(
1544 "Exp Month:", "exp_month", "02", "text", &field);
1545 form2.fields.push_back(field);
1546 autofill_test::CreateTestFormField(
1547 "Exp Year:", "exp_year", "2012", "text", &field);
1548 form2.fields.push_back(field);
1549
[email protected]685d4972013-02-12 01:06:231550 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291551 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211552 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1553 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241554 ASSERT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051555
1556 // Note: no refresh here.
1557
1558 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1559 ASSERT_EQ(1U, results2.size());
1560 EXPECT_EQ(0, expected.Compare(*results2[0]));
1561}
1562
1563TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) {
1564 FormData form1;
1565
1566 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141567 FormFieldData field;
[email protected]d7da65d2010-11-11 19:26:051568 autofill_test::CreateTestFormField(
1569 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1570 form1.fields.push_back(field);
1571 autofill_test::CreateTestFormField(
1572 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1573 form1.fields.push_back(field);
1574 autofill_test::CreateTestFormField(
1575 "Exp Month:", "exp_month", "01", "text", &field);
1576 form1.fields.push_back(field);
1577 autofill_test::CreateTestFormField(
1578 "Exp Year:", "exp_year", "2011", "text", &field);
1579 form1.fields.push_back(field);
1580
[email protected]685d4972013-02-12 01:06:231581 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291582 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241583 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211584 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1585 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241586 ASSERT_TRUE(imported_credit_card);
1587 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1588 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051589
[email protected]3813dec2011-05-11 20:56:361590 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051591 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361592 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051593 MessageLoop::current()->Run();
1594
1595 CreditCard expected;
1596 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341597 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051598 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1599 ASSERT_EQ(1U, results.size());
1600 EXPECT_EQ(0, expected.Compare(*results[0]));
1601
1602 // Add a second different valid credit card where the year is different but
1603 // the credit card number matches.
1604 FormData form2;
1605 autofill_test::CreateTestFormField(
1606 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1607 form2.fields.push_back(field);
1608 autofill_test::CreateTestFormField(
1609 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field);
1610 form2.fields.push_back(field);
1611 autofill_test::CreateTestFormField(
1612 "Exp Month:", "exp_month", "01", "text", &field);
1613 form2.fields.push_back(field);
1614 autofill_test::CreateTestFormField(
1615 "Exp Year:", "exp_year", "2012", "text", &field);
1616 form2.fields.push_back(field);
1617
[email protected]685d4972013-02-12 01:06:231618 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291619 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211620 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1621 &imported_credit_card));
[email protected]e5f5cf72011-10-04 22:18:061622 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051623
[email protected]3813dec2011-05-11 20:56:361624 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051625 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361626 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051627 MessageLoop::current()->Run();
1628
1629 // Expect that the newer information is saved. In this case the year is
1630 // updated to "2012".
1631 CreditCard expected2;
1632 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341633 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051634 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1635 ASSERT_EQ(1U, results2.size());
1636 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1637}
1638
1639TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) {
1640 FormData form1;
1641
1642 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141643 FormFieldData field;
[email protected]d7da65d2010-11-11 19:26:051644 autofill_test::CreateTestFormField(
1645 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1646 form1.fields.push_back(field);
1647 autofill_test::CreateTestFormField(
1648 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1649 form1.fields.push_back(field);
1650 autofill_test::CreateTestFormField(
1651 "Exp Month:", "exp_month", "01", "text", &field);
1652 form1.fields.push_back(field);
1653 autofill_test::CreateTestFormField(
1654 "Exp Year:", "exp_year", "2011", "text", &field);
1655 form1.fields.push_back(field);
1656
[email protected]685d4972013-02-12 01:06:231657 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291658 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241659 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211660 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1661 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241662 ASSERT_TRUE(imported_credit_card);
1663 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1664 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051665
[email protected]3813dec2011-05-11 20:56:361666 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051667 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361668 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051669 MessageLoop::current()->Run();
1670
1671 CreditCard expected;
1672 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341673 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051674 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1675 ASSERT_EQ(1U, results.size());
1676 EXPECT_EQ(0, expected.Compare(*results[0]));
1677
1678 // Add a second credit card with no number.
1679 FormData form2;
1680 autofill_test::CreateTestFormField(
1681 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1682 form2.fields.push_back(field);
1683 autofill_test::CreateTestFormField(
1684 "Exp Month:", "exp_month", "01", "text", &field);
1685 form2.fields.push_back(field);
1686 autofill_test::CreateTestFormField(
1687 "Exp Year:", "exp_year", "2012", "text", &field);
1688 form2.fields.push_back(field);
1689
[email protected]685d4972013-02-12 01:06:231690 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291691 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211692 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1693 &imported_credit_card));
[email protected]3e6e82da2011-04-06 05:41:341694 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051695
1696 // Note: no refresh here.
1697
1698 // No change is expected.
1699 CreditCard expected2;
1700 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341701 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051702 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1703 ASSERT_EQ(1U, results2.size());
1704 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1705}
1706
1707TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) {
1708 FormData form1;
1709
1710 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141711 FormFieldData field;
[email protected]d7da65d2010-11-11 19:26:051712 autofill_test::CreateTestFormField(
1713 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1714 form1.fields.push_back(field);
1715 autofill_test::CreateTestFormField(
1716 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1717 form1.fields.push_back(field);
1718 autofill_test::CreateTestFormField(
1719 "Exp Month:", "exp_month", "01", "text", &field);
1720 form1.fields.push_back(field);
1721 autofill_test::CreateTestFormField(
1722 "Exp Year:", "exp_year", "2011", "text", &field);
1723 form1.fields.push_back(field);
1724
[email protected]685d4972013-02-12 01:06:231725 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291726 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241727 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211728 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1729 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241730 ASSERT_TRUE(imported_credit_card);
1731 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1732 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051733
[email protected]3813dec2011-05-11 20:56:361734 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051735 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361736 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051737 MessageLoop::current()->Run();
1738
1739 CreditCard expected;
1740 autofill_test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341741 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051742 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1743 ASSERT_EQ(1U, results.size());
1744 EXPECT_EQ(0, expected.Compare(*results[0]));
1745
1746 // Add a second different valid credit card where the name is missing but
1747 // the credit card number matches.
1748 FormData form2;
1749 // Note missing name.
1750 autofill_test::CreateTestFormField(
1751 "Card Number:", "card_number", "4111111111111111", "text", &field);
1752 form2.fields.push_back(field);
1753 autofill_test::CreateTestFormField(
1754 "Exp Month:", "exp_month", "01", "text", &field);
1755 form2.fields.push_back(field);
1756 autofill_test::CreateTestFormField(
1757 "Exp Year:", "exp_year", "2011", "text", &field);
1758 form2.fields.push_back(field);
1759
[email protected]685d4972013-02-12 01:06:231760 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291761 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]e5f5cf72011-10-04 22:18:061762 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1763 &imported_credit_card));
1764 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051765
[email protected]e5f5cf72011-10-04 22:18:061766 // Wait for the refresh, which in this case is a no-op.
1767 EXPECT_CALL(personal_data_observer_,
1768 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1769 MessageLoop::current()->Run();
[email protected]d7da65d2010-11-11 19:26:051770
1771 // No change is expected.
1772 CreditCard expected2;
1773 autofill_test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341774 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051775 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1776 ASSERT_EQ(1U, results2.size());
1777 EXPECT_EQ(0, expected2.Compare(*results2[0]));
[email protected]cdd0d4482011-07-22 04:24:221778
1779 // Add a third credit card where the expiration date is missing.
1780 FormData form3;
1781 autofill_test::CreateTestFormField(
1782 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field);
1783 form3.fields.push_back(field);
1784 autofill_test::CreateTestFormField(
1785 "Card Number:", "card_number", "5555555555554444", "text", &field);
1786 form3.fields.push_back(field);
1787 // Note missing expiration month and year..
1788
[email protected]685d4972013-02-12 01:06:231789 FormStructure form_structure3(form3, std::string());
[email protected]dfd1818d2012-10-26 21:53:291790 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]cdd0d4482011-07-22 04:24:221791 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3,
1792 &imported_credit_card));
1793 ASSERT_FALSE(imported_credit_card);
1794
1795 // Note: no refresh here.
1796
1797 // No change is expected.
1798 CreditCard expected3;
1799 autofill_test::SetCreditCardInfo(&expected3,
1800 "Biggie Smalls", "4111111111111111", "01", "2011");
1801 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
1802 ASSERT_EQ(1U, results3.size());
1803 EXPECT_EQ(0, expected3.Compare(*results2[0]));
[email protected]d7da65d2010-11-11 19:26:051804}
1805
1806TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) {
[email protected]cdd0d4482011-07-22 04:24:221807 // Start with a single valid credit card stored via the preferences.
1808 // Note the empty name.
1809 CreditCard saved_credit_card;
1810 autofill_test::SetCreditCardInfo(&saved_credit_card,
1811 "", "4111111111111111" /* Visa */, "01", "2011");
1812 personal_data_->AddCreditCard(saved_credit_card);
[email protected]d7da65d2010-11-11 19:26:051813
[email protected]3813dec2011-05-11 20:56:361814 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051815 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361816 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051817 MessageLoop::current()->Run();
1818
[email protected]cdd0d4482011-07-22 04:24:221819 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1820 ASSERT_EQ(1U, results1.size());
1821 EXPECT_EQ(saved_credit_card, *results1[0]);
1822
[email protected]d7da65d2010-11-11 19:26:051823
1824 // Add a second different valid credit card where the year is different but
1825 // the credit card number matches.
[email protected]cdd0d4482011-07-22 04:24:221826 FormData form;
[email protected]1ecbe862012-10-05 01:29:141827 FormFieldData field;
[email protected]d7da65d2010-11-11 19:26:051828 autofill_test::CreateTestFormField(
1829 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221830 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051831 autofill_test::CreateTestFormField(
1832 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221833 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051834 autofill_test::CreateTestFormField(
1835 "Exp Month:", "exp_month", "01", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221836 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051837 autofill_test::CreateTestFormField(
[email protected]cdd0d4482011-07-22 04:24:221838 "Exp Year:", "exp_year", "2012", "text", &field);
1839 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051840
[email protected]685d4972013-02-12 01:06:231841 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:291842 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]cdd0d4482011-07-22 04:24:221843 const CreditCard* imported_credit_card;
1844 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
[email protected]2a958552011-05-05 04:01:211845 &imported_credit_card));
[email protected]e5f5cf72011-10-04 22:18:061846 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051847
[email protected]3813dec2011-05-11 20:56:361848 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051849 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361850 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051851 MessageLoop::current()->Run();
1852
1853 // Expect that the newer information is saved. In this case the year is
1854 // added to the existing credit card.
1855 CreditCard expected2;
1856 autofill_test::SetCreditCardInfo(&expected2,
[email protected]cdd0d4482011-07-22 04:24:221857 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051858 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1859 ASSERT_EQ(1U, results2.size());
1860 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1861}
[email protected]ca64d232011-05-06 05:46:001862
[email protected]e5f5cf72011-10-04 22:18:061863// We allow the user to store a credit card number with separators via the UI.
1864// We should not try to re-aggregate the same card with the separators stripped.
1865TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) {
1866 // Start with a single valid credit card stored via the preferences.
1867 // Note the separators in the credit card number.
1868 CreditCard saved_credit_card;
1869 autofill_test::SetCreditCardInfo(&saved_credit_card,
1870 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011");
1871 personal_data_->AddCreditCard(saved_credit_card);
1872
1873 // Verify that the web database has been updated and the notification sent.
1874 EXPECT_CALL(personal_data_observer_,
1875 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1876 MessageLoop::current()->Run();
1877
1878 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1879 ASSERT_EQ(1U, results1.size());
1880 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0]));
1881
1882 // Import the same card info, but with different separators in the number.
1883 FormData form;
[email protected]1ecbe862012-10-05 01:29:141884 FormFieldData field;
[email protected]e5f5cf72011-10-04 22:18:061885 autofill_test::CreateTestFormField(
1886 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1887 form.fields.push_back(field);
1888 autofill_test::CreateTestFormField(
1889 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1890 form.fields.push_back(field);
1891 autofill_test::CreateTestFormField(
1892 "Exp Month:", "exp_month", "01", "text", &field);
1893 form.fields.push_back(field);
1894 autofill_test::CreateTestFormField(
1895 "Exp Year:", "exp_year", "2011", "text", &field);
1896 form.fields.push_back(field);
1897
[email protected]685d4972013-02-12 01:06:231898 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:291899 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]e5f5cf72011-10-04 22:18:061900 const CreditCard* imported_credit_card;
1901 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
1902 &imported_credit_card));
1903 EXPECT_FALSE(imported_credit_card);
1904
1905 // Wait for the refresh, which in this case is a no-op.
1906 EXPECT_CALL(personal_data_observer_,
1907 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1908 MessageLoop::current()->Run();
1909
1910 // Expect that no new card is saved.
1911 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1912 ASSERT_EQ(1U, results2.size());
1913 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0]));
1914}
1915
[email protected]1308c2832011-05-09 18:30:231916TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
[email protected]ca64d232011-05-06 05:46:001917 // Check that there are no available types with no profiles stored.
[email protected]1308c2832011-05-09 18:30:231918 FieldTypeSet non_empty_types;
1919 personal_data_->GetNonEmptyTypes(&non_empty_types);
1920 EXPECT_EQ(0U, non_empty_types.size());
[email protected]ca64d232011-05-06 05:46:001921
1922 // Test with one profile stored.
1923 AutofillProfile profile0;
1924 autofill_test::SetProfileInfo(&profile0,
1925 "Marion", NULL, "Morrison",
1926 "[email protected]", NULL, "123 Zoo St.", NULL, "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:541927 "91601", "US", "14155678910");
[email protected]ca64d232011-05-06 05:46:001928
[email protected]3813dec2011-05-11 20:56:361929 personal_data_->AddProfile(profile0);
1930
1931 // Verify that the web database has been updated and the notification sent.
1932 EXPECT_CALL(personal_data_observer_,
1933 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1934 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001935
[email protected]1308c2832011-05-09 18:30:231936 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]11c2bdd12011-05-23 18:24:321937 EXPECT_EQ(14U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231938 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1939 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1940 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1941 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1942 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1943 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1944 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1945 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1946 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1947 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
[email protected]11c2bdd12011-05-23 18:24:321948 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
[email protected]1308c2832011-05-09 18:30:231949 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1950 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1951 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001952
1953 // Test with multiple profiles stored.
1954 AutofillProfile profile1;
1955 autofill_test::SetProfileInfo(&profile1,
1956 "Josephine", "Alicia", "Saenz",
1957 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:541958 "US", "16502937549");
[email protected]ca64d232011-05-06 05:46:001959
1960 AutofillProfile profile2;
1961 autofill_test::SetProfileInfo(&profile2,
1962 "Josephine", "Alicia", "Saenz",
1963 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:541964 "32801", "US", "16502937549");
[email protected]ca64d232011-05-06 05:46:001965
[email protected]3813dec2011-05-11 20:56:361966 personal_data_->AddProfile(profile1);
1967 personal_data_->AddProfile(profile2);
1968
1969 // Verify that the web database has been updated and the notification sent.
1970 EXPECT_CALL(personal_data_observer_,
1971 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1972 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001973
[email protected]1308c2832011-05-09 18:30:231974 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]4ef55f8c12011-09-17 00:06:541975 EXPECT_EQ(18U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231976 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1977 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1978 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1979 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1980 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1981 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1982 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1983 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1984 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1985 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1986 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1987 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1988 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1989 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1990 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1991 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1992 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1993 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001994
1995 // Test with credit card information also stored.
1996 CreditCard credit_card;
1997 autofill_test::SetCreditCardInfo(&credit_card,
1998 "John Dillinger", "423456789012" /* Visa */,
1999 "01", "2010");
[email protected]3813dec2011-05-11 20:56:362000 personal_data_->AddCreditCard(credit_card);
[email protected]ca64d232011-05-06 05:46:002001
[email protected]3813dec2011-05-11 20:56:362002 // Verify that the web database has been updated and the notification sent.
2003 EXPECT_CALL(personal_data_observer_,
2004 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2005 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:002006
[email protected]1308c2832011-05-09 18:30:232007 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]4ef55f8c12011-09-17 00:06:542008 EXPECT_EQ(25U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:232009 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
2010 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
2011 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
2012 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
2013 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
2014 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
2015 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
2016 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
2017 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
2018 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
2019 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
2020 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
2021 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
2022 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
2023 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
2024 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
2025 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
2026 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]1308c2832011-05-09 18:30:232027 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NAME));
2028 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NUMBER));
2029 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_MONTH));
2030 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_2_DIGIT_YEAR));
2031 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
2032 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR));
2033 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR));
[email protected]ca64d232011-05-06 05:46:002034}
[email protected]343b4fd2011-08-15 19:32:392035
2036TEST_F(PersonalDataManagerTest, CaseInsensitiveMultiValueAggregation) {
2037 FormData form1;
[email protected]1ecbe862012-10-05 01:29:142038 FormFieldData field;
[email protected]343b4fd2011-08-15 19:32:392039 autofill_test::CreateTestFormField(
2040 "First name:", "first_name", "George", "text", &field);
2041 form1.fields.push_back(field);
2042 autofill_test::CreateTestFormField(
2043 "Last name:", "last_name", "Washington", "text", &field);
2044 form1.fields.push_back(field);
2045 autofill_test::CreateTestFormField(
2046 "Email:", "email", "[email protected]", "text", &field);
2047 form1.fields.push_back(field);
2048 autofill_test::CreateTestFormField(
2049 "Address:", "address1", "21 Laussat St", "text", &field);
2050 form1.fields.push_back(field);
2051 autofill_test::CreateTestFormField(
2052 "City:", "city", "San Francisco", "text", &field);
2053 form1.fields.push_back(field);
2054 autofill_test::CreateTestFormField(
2055 "State:", "state", "California", "text", &field);
2056 form1.fields.push_back(field);
2057 autofill_test::CreateTestFormField(
2058 "Zip:", "zip", "94102", "text", &field);
2059 form1.fields.push_back(field);
2060 autofill_test::CreateTestFormField(
2061 "Phone number:", "phone_number", "817-555-6789", "text", &field);
2062 form1.fields.push_back(field);
2063
[email protected]685d4972013-02-12 01:06:232064 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:292065 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]343b4fd2011-08-15 19:32:392066 const CreditCard* imported_credit_card;
2067 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
2068 &imported_credit_card));
2069 ASSERT_FALSE(imported_credit_card);
2070
2071 // Verify that the web database has been updated and the notification sent.
2072 EXPECT_CALL(personal_data_observer_,
2073 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2074 MessageLoop::current()->Run();
2075
2076 AutofillProfile expected;
2077 autofill_test::SetProfileInfo(&expected, "George", NULL,
2078 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]5c0208c2012-11-28 15:16:132079 "San Francisco", "California", "94102", NULL, "(817) 555-6789");
[email protected]771ad212012-11-29 18:58:332080 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]343b4fd2011-08-15 19:32:392081 ASSERT_EQ(1U, results1.size());
2082 EXPECT_EQ(0, expected.Compare(*results1[0]));
2083
2084 // Upper-case the first name and change the phone number.
2085 FormData form2;
2086 autofill_test::CreateTestFormField(
2087 "First name:", "first_name", "GEORGE", "text", &field);
2088 form2.fields.push_back(field);
2089 autofill_test::CreateTestFormField(
2090 "Last name:", "last_name", "Washington", "text", &field);
2091 form2.fields.push_back(field);
2092 autofill_test::CreateTestFormField(
2093 "Email:", "email", "[email protected]", "text", &field);
2094 form2.fields.push_back(field);
2095 autofill_test::CreateTestFormField(
2096 "Address:", "address1", "21 Laussat St", "text", &field);
2097 form2.fields.push_back(field);
2098 autofill_test::CreateTestFormField(
2099 "City:", "city", "San Francisco", "text", &field);
2100 form2.fields.push_back(field);
2101 autofill_test::CreateTestFormField(
2102 "State:", "state", "California", "text", &field);
2103 form2.fields.push_back(field);
2104 autofill_test::CreateTestFormField(
2105 "Zip:", "zip", "94102", "text", &field);
2106 form2.fields.push_back(field);
2107 autofill_test::CreateTestFormField(
2108 "Phone number:", "phone_number", "214-555-1234", "text", &field);
2109 form2.fields.push_back(field);
2110
[email protected]685d4972013-02-12 01:06:232111 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:292112 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]343b4fd2011-08-15 19:32:392113 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
2114 &imported_credit_card));
2115 ASSERT_FALSE(imported_credit_card);
2116
2117 // Verify that the web database has been updated and the notification sent.
2118 EXPECT_CALL(personal_data_observer_,
2119 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2120 MessageLoop::current()->Run();
2121
[email protected]771ad212012-11-29 18:58:332122 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]343b4fd2011-08-15 19:32:392123
2124 // Modify expected to include multi-valued fields.
[email protected]d5ca8fb2013-04-11 17:54:312125 std::vector<base::string16> values;
[email protected]e4364512012-11-29 10:51:062126 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
[email protected]5c0208c2012-11-28 15:16:132127 values.push_back(ASCIIToUTF16("(214) 555-1234"));
[email protected]e4364512012-11-29 10:51:062128 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
[email protected]343b4fd2011-08-15 19:32:392129
2130 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:002131 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]343b4fd2011-08-15 19:32:392132}