blob: 99ad37422e6b87e699a82b8f44a19eaa68d0993a [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]e217c5632013-04-12 19:11:4835namespace autofill {
[email protected]dfd1818d2012-10-26 21:53:2936namespace {
37
[email protected]2609bc12010-01-24 08:32:5538ACTION(QuitUIMessageLoop) {
[email protected]faec6312010-10-05 03:35:3439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[email protected]2609bc12010-01-24 08:32:5540 MessageLoop::current()->Quit();
41}
42
[email protected]a7e585a2011-08-08 20:32:5443class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver {
[email protected]2609bc12010-01-24 08:32:5544 public:
45 PersonalDataLoadedObserverMock() {}
46 virtual ~PersonalDataLoadedObserverMock() {}
47
[email protected]3813dec2011-05-11 20:56:3648 MOCK_METHOD0(OnPersonalDataChanged, void());
[email protected]2609bc12010-01-24 08:32:5549};
50
[email protected]dfd1818d2012-10-26 21:53:2951// Unlike the base AutofillMetrics, exposes copy and assignment constructors,
52// which are handy for briefer test code. The AutofillMetrics class is
53// stateless, so this is safe.
54class TestAutofillMetrics : public AutofillMetrics {
55 public:
56 TestAutofillMetrics() {}
57 virtual ~TestAutofillMetrics() {}
58};
59
60} // anonymous namespace
61
[email protected]2609bc12010-01-24 08:32:5562class PersonalDataManagerTest : public testing::Test {
63 protected:
64 PersonalDataManagerTest()
[email protected]faec6312010-10-05 03:35:3465 : ui_thread_(BrowserThread::UI, &message_loop_),
66 db_thread_(BrowserThread::DB) {
[email protected]2609bc12010-01-24 08:32:5567 }
68
69 virtual void SetUp() {
70 db_thread_.Start();
71
72 profile_.reset(new TestingProfile);
[email protected]d07edd42012-05-14 23:49:4673 profile_->CreateWebDataService();
[email protected]2609bc12010-01-24 08:32:5574
[email protected]e217c5632013-04-12 19:11:4875 test::DisableSystemServices(profile_.get());
[email protected]2609bc12010-01-24 08:32:5576 ResetPersonalDataManager();
77 }
78
79 virtual void TearDown() {
[email protected]ea9edcb02011-09-23 22:05:0480 // Destruction order is imposed explicitly here.
81 personal_data_.reset(NULL);
82 profile_.reset(NULL);
[email protected]2609bc12010-01-24 08:32:5583
[email protected]fabb4ba2013-03-20 20:32:0584 // Schedule another task on the DB thread to notify us that it's safe to
85 // stop the thread.
86 base::WaitableEvent done(false, false);
87 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
88 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
89 done.Wait();
[email protected]a778709f2011-12-10 00:28:1790 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
[email protected]2609bc12010-01-24 08:32:5591 MessageLoop::current()->Run();
[email protected]fabb4ba2013-03-20 20:32:0592 db_thread_.Stop();
[email protected]2609bc12010-01-24 08:32:5593 }
94
95 void ResetPersonalDataManager() {
[email protected]0b2f513b2013-04-05 20:13:2396 personal_data_.reset(new PersonalDataManager("en-US"));
[email protected]e0976a72010-04-02 01:25:2497 personal_data_->Init(profile_.get());
[email protected]412bde72013-02-07 06:06:2498 personal_data_->AddObserver(&personal_data_observer_);
[email protected]3813dec2011-05-11 20:56:3699
100 // Verify that the web database has been updated and the notification sent.
101 EXPECT_CALL(personal_data_observer_,
102 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
103 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55104 }
105
[email protected]2609bc12010-01-24 08:32:55106 MessageLoopForUI message_loop_;
[email protected]c38831a12011-10-28 12:44:49107 content::TestBrowserThread ui_thread_;
108 content::TestBrowserThread db_thread_;
[email protected]2609bc12010-01-24 08:32:55109 scoped_ptr<TestingProfile> profile_;
[email protected]ea9edcb02011-09-23 22:05:04110 scoped_ptr<PersonalDataManager> personal_data_;
[email protected]6c2381d2011-10-19 02:52:53111 content::NotificationRegistrar registrar_;
[email protected]b8d48332012-06-03 21:59:53112 content::MockNotificationObserver observer_;
[email protected]2609bc12010-01-24 08:32:55113 PersonalDataLoadedObserverMock personal_data_observer_;
114};
115
[email protected]0ed984b2011-04-28 01:22:02116TEST_F(PersonalDataManagerTest, AddProfile) {
[email protected]0ed984b2011-04-28 01:22:02117 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:48118 test::SetProfileInfo(&profile0,
[email protected]0ed984b2011-04-28 01:22:02119 "John", "Mitchell", "Smith",
120 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA",
[email protected]91b073d2013-01-05 01:30:28121 "94102", "US", "4158889999");
[email protected]0ed984b2011-04-28 01:22:02122
123 // Add profile0 to the database.
124 personal_data_->AddProfile(profile0);
125
126 // Reload the database.
127 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02128
129 // Verify the addition.
[email protected]771ad212012-11-29 18:58:33130 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]0ed984b2011-04-28 01:22:02131 ASSERT_EQ(1U, results1.size());
[email protected]f2cd8362012-01-23 22:34:00132 EXPECT_EQ(0, profile0.Compare(*results1[0]));
[email protected]0ed984b2011-04-28 01:22:02133
134 // Add profile with identical values. Duplicates should not get saved.
135 AutofillProfile profile0a = profile0;
[email protected]7e49ad32012-06-14 14:22:07136 profile0a.set_guid(base::GenerateGUID());
[email protected]0ed984b2011-04-28 01:22:02137 personal_data_->AddProfile(profile0a);
138
139 // Reload the database.
140 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02141
142 // Verify the non-addition.
[email protected]771ad212012-11-29 18:58:33143 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]0ed984b2011-04-28 01:22:02144 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:00145 EXPECT_EQ(0, profile0.Compare(*results2[0]));
[email protected]0ed984b2011-04-28 01:22:02146
147 // New profile with different email.
148 AutofillProfile profile1 = profile0;
[email protected]7e49ad32012-06-14 14:22:07149 profile1.set_guid(base::GenerateGUID());
[email protected]6b44b582012-11-10 06:31:18150 profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("[email protected]"));
[email protected]0ed984b2011-04-28 01:22:02151
152 // Add the different profile. This should save as a separate profile.
153 // Note that if this same profile was "merged" it would collapse to one
154 // profile with a multi-valued entry for email.
155 personal_data_->AddProfile(profile1);
156
157 // Reload the database.
158 ResetPersonalDataManager();
[email protected]0ed984b2011-04-28 01:22:02159
160 // Verify the addition.
[email protected]771ad212012-11-29 18:58:33161 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]0ed984b2011-04-28 01:22:02162 ASSERT_EQ(2U, results3.size());
[email protected]f2cd8362012-01-23 22:34:00163 EXPECT_EQ(0, profile0.Compare(*results3[0]));
164 EXPECT_EQ(0, profile1.Compare(*results3[1]));
[email protected]0ed984b2011-04-28 01:22:02165}
166
[email protected]3813dec2011-05-11 20:56:36167TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) {
[email protected]e90c2252011-03-10 12:29:21168 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:48169 test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34170 "Marion", "Mitchell", "Morrison",
[email protected]2609bc12010-01-24 08:32:55171 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54172 "91601", "US", "12345678910");
[email protected]2609bc12010-01-24 08:32:55173
[email protected]e90c2252011-03-10 12:29:21174 AutofillProfile profile1;
[email protected]e217c5632013-04-12 19:11:48175 test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34176 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55177 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54178 "US", "19482937549");
[email protected]2609bc12010-01-24 08:32:55179
[email protected]e90c2252011-03-10 12:29:21180 AutofillProfile profile2;
[email protected]e217c5632013-04-12 19:11:48181 test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34182 "Josephine", "Alicia", "Saenz",
[email protected]2609bc12010-01-24 08:32:55183 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:54184 "32801", "US", "19482937549");
[email protected]2609bc12010-01-24 08:32:55185
[email protected]542e1992010-07-14 18:25:52186 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36187 personal_data_->AddProfile(profile0);
188 personal_data_->AddProfile(profile1);
189
190 // Verify that the web database has been updated and the notification sent.
191 EXPECT_CALL(personal_data_observer_,
192 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
193 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55194
[email protected]771ad212012-11-29 18:58:33195 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]2609bc12010-01-24 08:32:55196 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36197 EXPECT_EQ(0, profile0.Compare(*results1[0]));
198 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]2609bc12010-01-24 08:32:55199
[email protected]3813dec2011-05-11 20:56:36200 // Update, remove, and add.
[email protected]6b44b582012-11-10 06:31:18201 profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John"));
[email protected]3813dec2011-05-11 20:56:36202 personal_data_->UpdateProfile(profile0);
[email protected]8da04b852012-11-16 22:10:39203 personal_data_->RemoveByGUID(profile1.guid());
[email protected]3813dec2011-05-11 20:56:36204 personal_data_->AddProfile(profile2);
205
206 // Verify that the web database has been updated and the notification sent.
207 EXPECT_CALL(personal_data_observer_,
208 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
209 MessageLoop::current()->Run();
[email protected]2609bc12010-01-24 08:32:55210
[email protected]771ad212012-11-29 18:58:33211 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]2609bc12010-01-24 08:32:55212 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36213 EXPECT_EQ(0, profile0.Compare(*results2[0]));
214 EXPECT_EQ(0, profile2.Compare(*results2[1]));
[email protected]2609bc12010-01-24 08:32:55215
216 // Reset the PersonalDataManager. This tests that the personal data was saved
217 // to the web database, and that we can load the profiles from the web
218 // database.
219 ResetPersonalDataManager();
220
[email protected]2609bc12010-01-24 08:32:55221 // Verify that we've loaded the profiles from the web database.
[email protected]771ad212012-11-29 18:58:33222 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]2609bc12010-01-24 08:32:55223 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36224 EXPECT_EQ(0, profile0.Compare(*results3[0]));
225 EXPECT_EQ(0, profile2.Compare(*results3[1]));
[email protected]2609bc12010-01-24 08:32:55226}
[email protected]f11f6212010-01-25 20:47:20227
[email protected]3813dec2011-05-11 20:56:36228TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) {
229 CreditCard credit_card0;
[email protected]e217c5632013-04-12 19:11:48230 test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54231 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]f11f6212010-01-25 20:47:20232
[email protected]3813dec2011-05-11 20:56:36233 CreditCard credit_card1;
[email protected]e217c5632013-04-12 19:11:48234 test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54235 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]f11f6212010-01-25 20:47:20236
[email protected]3813dec2011-05-11 20:56:36237 CreditCard credit_card2;
[email protected]e217c5632013-04-12 19:11:48238 test::SetCreditCardInfo(&credit_card2,
[email protected]2a13edd2010-10-26 22:52:54239 "Clyde Barrow", "347666888555" /* American Express */, "04", "2015");
[email protected]f11f6212010-01-25 20:47:20240
[email protected]542e1992010-07-14 18:25:52241 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36242 personal_data_->AddCreditCard(credit_card0);
243 personal_data_->AddCreditCard(credit_card1);
244
245 // Verify that the web database has been updated and the notification sent.
246 EXPECT_CALL(personal_data_observer_,
247 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
248 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20249
[email protected]f11f6212010-01-25 20:47:20250 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
251 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36252 EXPECT_EQ(0, credit_card0.Compare(*results1[0]));
253 EXPECT_EQ(0, credit_card1.Compare(*results1[1]));
[email protected]f11f6212010-01-25 20:47:20254
[email protected]3813dec2011-05-11 20:56:36255 // Update, remove, and add.
[email protected]6b44b582012-11-10 06:31:18256 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe"));
[email protected]3813dec2011-05-11 20:56:36257 personal_data_->UpdateCreditCard(credit_card0);
[email protected]8da04b852012-11-16 22:10:39258 personal_data_->RemoveByGUID(credit_card1.guid());
[email protected]3813dec2011-05-11 20:56:36259 personal_data_->AddCreditCard(credit_card2);
260
261 // Verify that the web database has been updated and the notification sent.
262 EXPECT_CALL(personal_data_observer_,
263 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
264 MessageLoop::current()->Run();
[email protected]f11f6212010-01-25 20:47:20265
[email protected]f11f6212010-01-25 20:47:20266 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
267 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36268 EXPECT_EQ(credit_card0, *results2[0]);
269 EXPECT_EQ(credit_card2, *results2[1]);
[email protected]f11f6212010-01-25 20:47:20270
271 // Reset the PersonalDataManager. This tests that the personal data was saved
272 // to the web database, and that we can load the credit cards from the web
273 // database.
274 ResetPersonalDataManager();
275
[email protected]f11f6212010-01-25 20:47:20276 // Verify that we've loaded the credit cards from the web database.
277 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
278 ASSERT_EQ(2U, results3.size());
[email protected]3813dec2011-05-11 20:56:36279 EXPECT_EQ(credit_card0, *results3[0]);
280 EXPECT_EQ(credit_card2, *results3[1]);
[email protected]f11f6212010-01-25 20:47:20281}
[email protected]e0976a72010-04-02 01:25:24282
[email protected]3813dec2011-05-11 20:56:36283TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) {
[email protected]e90c2252011-03-10 12:29:21284 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:48285 test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34286 "Marion", "Mitchell", "Morrison",
[email protected]542e1992010-07-14 18:25:52287 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54288 "91601", "US", "12345678910");
[email protected]542e1992010-07-14 18:25:52289
[email protected]e90c2252011-03-10 12:29:21290 AutofillProfile profile1;
[email protected]e217c5632013-04-12 19:11:48291 test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34292 "Josephine", "Alicia", "Saenz",
[email protected]542e1992010-07-14 18:25:52293 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54294 "US", "19482937549");
[email protected]542e1992010-07-14 18:25:52295
[email protected]3813dec2011-05-11 20:56:36296 CreditCard credit_card0;
[email protected]e217c5632013-04-12 19:11:48297 test::SetCreditCardInfo(&credit_card0,
[email protected]2a13edd2010-10-26 22:52:54298 "John Dillinger", "423456789012" /* Visa */, "01", "2010");
[email protected]542e1992010-07-14 18:25:52299
[email protected]3813dec2011-05-11 20:56:36300 CreditCard credit_card1;
[email protected]e217c5632013-04-12 19:11:48301 test::SetCreditCardInfo(&credit_card1,
[email protected]2a13edd2010-10-26 22:52:54302 "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012");
[email protected]542e1992010-07-14 18:25:52303
[email protected]542e1992010-07-14 18:25:52304 // Add two test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36305 personal_data_->AddProfile(profile0);
306 personal_data_->AddProfile(profile1);
307
308 // Verify that the web database has been updated and the notification sent.
309 EXPECT_CALL(personal_data_observer_,
310 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
311 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52312
[email protected]771ad212012-11-29 18:58:33313 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]542e1992010-07-14 18:25:52314 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36315 EXPECT_EQ(0, profile0.Compare(*results1[0]));
316 EXPECT_EQ(0, profile1.Compare(*results1[1]));
[email protected]414c35482011-02-09 01:26:13317
[email protected]542e1992010-07-14 18:25:52318 // Add two test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36319 personal_data_->AddCreditCard(credit_card0);
320 personal_data_->AddCreditCard(credit_card1);
[email protected]542e1992010-07-14 18:25:52321
[email protected]3813dec2011-05-11 20:56:36322 // Verify that the web database has been updated and the notification sent.
323 EXPECT_CALL(personal_data_observer_,
324 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
325 MessageLoop::current()->Run();
[email protected]542e1992010-07-14 18:25:52326
327 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
328 ASSERT_EQ(2U, results2.size());
[email protected]3813dec2011-05-11 20:56:36329 EXPECT_EQ(credit_card0, *results2[0]);
330 EXPECT_EQ(credit_card1, *results2[1]);
[email protected]542e1992010-07-14 18:25:52331
[email protected]e43783402010-11-04 19:45:04332 // Determine uniqueness by inserting all of the GUIDs into a set and verifying
333 // the size of the set matches the number of GUIDs.
334 std::set<std::string> guids;
335 guids.insert(profile0.guid());
336 guids.insert(profile1.guid());
[email protected]3813dec2011-05-11 20:56:36337 guids.insert(credit_card0.guid());
338 guids.insert(credit_card1.guid());
[email protected]e43783402010-11-04 19:45:04339 EXPECT_EQ(4U, guids.size());
[email protected]542e1992010-07-14 18:25:52340}
341
[email protected]3813dec2011-05-11 20:56:36342// Test for http://crbug.com/50047. Makes sure that guids are populated
343// correctly on load.
[email protected]7c543fd2010-07-24 02:44:59344TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) {
[email protected]e90c2252011-03-10 12:29:21345 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:48346 test::SetProfileInfo(&profile0,
[email protected]4ef55f8c12011-09-17 00:06:54347 "y", "", "", "", "", "", "", "", "", "", "", "");
[email protected]7c543fd2010-07-24 02:44:59348
[email protected]7c543fd2010-07-24 02:44:59349 // Add the profile0 to the db.
[email protected]3813dec2011-05-11 20:56:36350 personal_data_->AddProfile(profile0);
[email protected]7c543fd2010-07-24 02:44:59351
[email protected]3813dec2011-05-11 20:56:36352 // Verify that the web database has been updated and the notification sent.
353 EXPECT_CALL(personal_data_observer_,
354 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]7c543fd2010-07-24 02:44:59355 MessageLoop::current()->Run();
356
357 // Verify that we've loaded the profiles from the web database.
[email protected]771ad212012-11-29 18:58:33358 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]7c543fd2010-07-24 02:44:59359 ASSERT_EQ(1U, results2.size());
[email protected]3813dec2011-05-11 20:56:36360 EXPECT_EQ(0, profile0.Compare(*results2[0]));
[email protected]7c543fd2010-07-24 02:44:59361
362 // Add a new profile.
[email protected]e90c2252011-03-10 12:29:21363 AutofillProfile profile1;
[email protected]e217c5632013-04-12 19:11:48364 test::SetProfileInfo(&profile1,
[email protected]4ef55f8c12011-09-17 00:06:54365 "z", "", "", "", "", "", "", "", "", "", "", "");
[email protected]3813dec2011-05-11 20:56:36366 personal_data_->AddProfile(profile1);
[email protected]7c543fd2010-07-24 02:44:59367
[email protected]3813dec2011-05-11 20:56:36368 // Verify that the web database has been updated and the notification sent.
369 EXPECT_CALL(personal_data_observer_,
370 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
371 MessageLoop::current()->Run();
372
373 // Make sure the two profiles have different GUIDs, both valid.
[email protected]771ad212012-11-29 18:58:33374 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]7c543fd2010-07-24 02:44:59375 ASSERT_EQ(2U, results3.size());
[email protected]e43783402010-11-04 19:45:04376 EXPECT_NE(results3[0]->guid(), results3[1]->guid());
[email protected]7e49ad32012-06-14 14:22:07377 EXPECT_TRUE(base::IsValidGUID(results3[0]->guid()));
378 EXPECT_TRUE(base::IsValidGUID(results3[1]->guid()));
[email protected]7c543fd2010-07-24 02:44:59379}
380
[email protected]98a94ee2010-07-12 16:03:22381TEST_F(PersonalDataManagerTest, SetEmptyProfile) {
[email protected]e90c2252011-03-10 12:29:21382 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:48383 test::SetProfileInfo(&profile0,
[email protected]4ef55f8c12011-09-17 00:06:54384 "", "", "", "", "", "", "", "", "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22385
[email protected]98a94ee2010-07-12 16:03:22386 // Add the empty profile to the database.
[email protected]3813dec2011-05-11 20:56:36387 personal_data_->AddProfile(profile0);
[email protected]98a94ee2010-07-12 16:03:22388
[email protected]3813dec2011-05-11 20:56:36389 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22390
391 // Reset the PersonalDataManager. This tests that the personal data was saved
392 // to the web database, and that we can load the profiles from the web
393 // database.
394 ResetPersonalDataManager();
395
[email protected]98a94ee2010-07-12 16:03:22396 // Verify that we've loaded the profiles from the web database.
[email protected]771ad212012-11-29 18:58:33397 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]98a94ee2010-07-12 16:03:22398 ASSERT_EQ(0U, results2.size());
399}
400
401TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) {
[email protected]3813dec2011-05-11 20:56:36402 CreditCard credit_card0;
[email protected]e217c5632013-04-12 19:11:48403 test::SetCreditCardInfo(&credit_card0, "", "", "", "");
[email protected]98a94ee2010-07-12 16:03:22404
405 // Add the empty credit card to the database.
[email protected]3813dec2011-05-11 20:56:36406 personal_data_->AddCreditCard(credit_card0);
[email protected]98a94ee2010-07-12 16:03:22407
[email protected]3813dec2011-05-11 20:56:36408 // Note: no refresh here.
[email protected]98a94ee2010-07-12 16:03:22409
410 // Reset the PersonalDataManager. This tests that the personal data was saved
411 // to the web database, and that we can load the credit cards from the web
412 // database.
413 ResetPersonalDataManager();
414
[email protected]98a94ee2010-07-12 16:03:22415 // Verify that we've loaded the credit cards from the web database.
416 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
417 ASSERT_EQ(0U, results2.size());
418}
419
[email protected]e0976a72010-04-02 01:25:24420TEST_F(PersonalDataManagerTest, Refresh) {
[email protected]e90c2252011-03-10 12:29:21421 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:48422 test::SetProfileInfo(&profile0,
[email protected]027dd442011-02-15 23:17:34423 "Marion", "Mitchell", "Morrison",
[email protected]e0976a72010-04-02 01:25:24424 "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:54425 "91601", "US", "12345678910");
[email protected]e0976a72010-04-02 01:25:24426
[email protected]e90c2252011-03-10 12:29:21427 AutofillProfile profile1;
[email protected]e217c5632013-04-12 19:11:48428 test::SetProfileInfo(&profile1,
[email protected]027dd442011-02-15 23:17:34429 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24430 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:54431 "US", "19482937549");
[email protected]e0976a72010-04-02 01:25:24432
[email protected]e0976a72010-04-02 01:25:24433 // Add the test profiles to the database.
[email protected]3813dec2011-05-11 20:56:36434 personal_data_->AddProfile(profile0);
435 personal_data_->AddProfile(profile1);
[email protected]e0976a72010-04-02 01:25:24436
[email protected]e43783402010-11-04 19:45:04437 // Labels depend on other profiles in the list - update labels manually.
[email protected]e90c2252011-03-10 12:29:21438 std::vector<AutofillProfile *> profile_pointers;
[email protected]9f321442010-10-25 23:53:53439 profile_pointers.push_back(&profile0);
440 profile_pointers.push_back(&profile1);
[email protected]e90c2252011-03-10 12:29:21441 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]e0976a72010-04-02 01:25:24442
[email protected]3813dec2011-05-11 20:56:36443 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24444 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36445 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24446 MessageLoop::current()->Run();
447
[email protected]771ad212012-11-29 18:58:33448 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]e0976a72010-04-02 01:25:24449 ASSERT_EQ(2U, results1.size());
[email protected]3813dec2011-05-11 20:56:36450 EXPECT_EQ(profile0, *results1[0]);
451 EXPECT_EQ(profile1, *results1[1]);
[email protected]e0976a72010-04-02 01:25:24452
[email protected]e90c2252011-03-10 12:29:21453 AutofillProfile profile2;
[email protected]e217c5632013-04-12 19:11:48454 test::SetProfileInfo(&profile2,
[email protected]027dd442011-02-15 23:17:34455 "Josephine", "Alicia", "Saenz",
[email protected]e0976a72010-04-02 01:25:24456 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:54457 "32801", "US", "19482937549");
[email protected]e0976a72010-04-02 01:25:24458
[email protected]9f321442010-10-25 23:53:53459 // Adjust all labels.
[email protected]61f25cd0e2010-11-07 05:23:50460 profile_pointers.push_back(&profile2);
[email protected]e90c2252011-03-10 12:29:21461 AutofillProfile::AdjustInferredLabels(&profile_pointers);
[email protected]9f321442010-10-25 23:53:53462
[email protected]e2b31052013-03-25 01:49:37463 scoped_refptr<AutofillWebDataService> wds =
464 AutofillWebDataService::FromBrowserContext(profile_.get());
[email protected]d07edd42012-05-14 23:49:46465 ASSERT_TRUE(wds.get());
[email protected]e90c2252011-03-10 12:29:21466 wds->AddAutofillProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24467
468 personal_data_->Refresh();
469
[email protected]3813dec2011-05-11 20:56:36470 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24471 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36472 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24473 MessageLoop::current()->Run();
474
[email protected]771ad212012-11-29 18:58:33475 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]e0976a72010-04-02 01:25:24476 ASSERT_EQ(3U, results2.size());
[email protected]3813dec2011-05-11 20:56:36477 EXPECT_EQ(profile0, *results2[0]);
478 EXPECT_EQ(profile1, *results2[1]);
479 EXPECT_EQ(profile2, *results2[2]);
[email protected]e0976a72010-04-02 01:25:24480
[email protected]e90c2252011-03-10 12:29:21481 wds->RemoveAutofillProfile(profile1.guid());
482 wds->RemoveAutofillProfile(profile2.guid());
[email protected]e0976a72010-04-02 01:25:24483
484 // Before telling the PDM to refresh, simulate an edit to one of the profiles
[email protected]663bd9e2011-03-21 01:07:01485 // via a SetProfile update (this would happen if the Autofill window was
[email protected]e0976a72010-04-02 01:25:24486 // open with a previous snapshot of the profiles, and something [e.g. sync]
487 // removed a profile from the browser. In this edge case, we will end up
488 // in a consistent state by dropping the write).
[email protected]6b44b582012-11-10 06:31:18489 profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo"));
[email protected]3813dec2011-05-11 20:56:36490 personal_data_->UpdateProfile(profile0);
491 personal_data_->AddProfile(profile1);
492 personal_data_->AddProfile(profile2);
[email protected]e0976a72010-04-02 01:25:24493
[email protected]3813dec2011-05-11 20:56:36494 // Verify that the web database has been updated and the notification sent.
[email protected]e0976a72010-04-02 01:25:24495 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36496 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]e0976a72010-04-02 01:25:24497 MessageLoop::current()->Run();
498
[email protected]771ad212012-11-29 18:58:33499 const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles();
[email protected]e0976a72010-04-02 01:25:24500 ASSERT_EQ(1U, results3.size());
[email protected]3813dec2011-05-11 20:56:36501 EXPECT_EQ(profile0, *results2[0]);
[email protected]e0976a72010-04-02 01:25:24502}
[email protected]83723f02010-04-07 17:33:10503
[email protected]ce78c1f92010-04-09 02:23:26504TEST_F(PersonalDataManagerTest, ImportFormData) {
[email protected]cea1d112010-07-01 00:57:33505 FormData form;
[email protected]1ecbe862012-10-05 01:29:14506 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48507 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33508 "First name:", "first_name", "George", "text", &field);
509 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48510 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33511 "Last name:", "last_name", "Washington", "text", &field);
512 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48513 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33514 "Email:", "email", "[email protected]", "text", &field);
515 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48516 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52517 "Address:", "address1", "21 Laussat St", "text", &field);
518 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48519 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52520 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48521 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52522 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48523 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52524 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23525 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29526 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24527 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21528 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
529 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24530 ASSERT_FALSE(imported_credit_card);
[email protected]ce78c1f92010-04-09 02:23:26531
[email protected]3813dec2011-05-11 20:56:36532 // Verify that the web database has been updated and the notification sent.
[email protected]ce78c1f92010-04-09 02:23:26533 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36534 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]ce78c1f92010-04-09 02:23:26535 MessageLoop::current()->Run();
536
[email protected]e90c2252011-03-10 12:29:21537 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:48538 test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52539 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54540 "San Francisco", "California", "94102", NULL, NULL);
[email protected]771ad212012-11-29 18:58:33541 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
[email protected]ce78c1f92010-04-09 02:23:26542 ASSERT_EQ(1U, results.size());
[email protected]e43783402010-11-04 19:45:04543 EXPECT_EQ(0, expected.Compare(*results[0]));
[email protected]ce78c1f92010-04-09 02:23:26544}
545
[email protected]a2a1baf2011-02-03 20:22:00546TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) {
547 FormData form;
[email protected]1ecbe862012-10-05 01:29:14548 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48549 test::CreateTestFormField(
[email protected]a2a1baf2011-02-03 20:22:00550 "First name:", "first_name", "George", "text", &field);
551 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48552 test::CreateTestFormField(
[email protected]a2a1baf2011-02-03 20:22:00553 "Last name:", "last_name", "Washington", "text", &field);
554 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48555 test::CreateTestFormField("Email:", "email", "bogus", "text", &field);
[email protected]a2a1baf2011-02-03 20:22:00556 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48557 test::CreateTestFormField(
[email protected]a2a1baf2011-02-03 20:22:00558 "Address:", "address1", "21 Laussat St", "text", &field);
559 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48560 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]a2a1baf2011-02-03 20:22:00561 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48562 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]a2a1baf2011-02-03 20:22:00563 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48564 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]a2a1baf2011-02-03 20:22:00565 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23566 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29567 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24568 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21569 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
570 &imported_credit_card));
[email protected]ca9bdeb2011-03-17 20:01:41571 ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card);
[email protected]a2a1baf2011-02-03 20:22:00572
[email protected]771ad212012-11-29 18:58:33573 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
[email protected]ca9bdeb2011-03-17 20:01:41574 ASSERT_EQ(0U, results.size());
[email protected]a2a1baf2011-02-03 20:22:00575}
576
[email protected]ad651d382013-04-10 06:31:22577// Tests that a 'confirm email' field does not block profile import.
578TEST_F(PersonalDataManagerTest, ImportFormDataTwoEmails) {
579 FormData form;
580 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48581 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22582 "Name:", "name", "George Washington", "text", &field);
583 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48584 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22585 "Address:", "address1", "21 Laussat St", "text", &field);
586 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48587 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]ad651d382013-04-10 06:31:22588 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48589 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]ad651d382013-04-10 06:31:22590 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48591 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]ad651d382013-04-10 06:31:22592 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48593 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22594 "Email:", "email", "[email protected]", "text", &field);
595 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48596 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22597 "Confirm email:", "confirm_email", "[email protected]", "text", &field);
598 form.fields.push_back(field);
599 FormStructure form_structure(form, std::string());
600 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
601 const CreditCard* imported_credit_card;
602 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
603 &imported_credit_card));
604 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
605 ASSERT_EQ(1U, results.size());
606}
607
608// Tests two email fields containing different values blocks provile import.
609TEST_F(PersonalDataManagerTest, ImportFormDataTwoDifferentEmails) {
610 FormData form;
611 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48612 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22613 "Name:", "name", "George Washington", "text", &field);
614 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48615 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22616 "Address:", "address1", "21 Laussat St", "text", &field);
617 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48618 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]ad651d382013-04-10 06:31:22619 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48620 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]ad651d382013-04-10 06:31:22621 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48622 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]ad651d382013-04-10 06:31:22623 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48624 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22625 "Email:", "email", "[email protected]", "text", &field);
626 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48627 test::CreateTestFormField(
[email protected]ad651d382013-04-10 06:31:22628 "Email:", "email2", "[email protected]", "text", &field);
629 form.fields.push_back(field);
630 FormStructure form_structure(form, std::string());
631 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
632 const CreditCard* imported_credit_card;
633 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
634 &imported_credit_card));
635 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
636 ASSERT_EQ(0U, results.size());
637}
638
[email protected]204777552011-01-26 19:46:28639TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) {
[email protected]4fb058092010-11-24 23:52:25640 FormData form;
[email protected]1ecbe862012-10-05 01:29:14641 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48642 test::CreateTestFormField(
[email protected]4fb058092010-11-24 23:52:25643 "First name:", "first_name", "George", "text", &field);
644 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48645 test::CreateTestFormField(
[email protected]4fb058092010-11-24 23:52:25646 "Last name:", "last_name", "Washington", "text", &field);
647 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48648 test::CreateTestFormField(
[email protected]4fb058092010-11-24 23:52:25649 "Card number:", "card_number", "4111 1111 1111 1111", "text", &field);
650 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23651 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29652 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24653 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21654 EXPECT_FALSE(personal_data_->ImportFormData(form_structure,
655 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24656 ASSERT_FALSE(imported_credit_card);
[email protected]4fb058092010-11-24 23:52:25657
[email protected]771ad212012-11-29 18:58:33658 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
[email protected]4fb058092010-11-24 23:52:25659 ASSERT_EQ(0U, profiles.size());
660 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
661 ASSERT_EQ(0U, credit_cards.size());
662}
663
[email protected]a36215a2013-04-04 12:35:42664TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressUSA) {
665 // United States addresses must specifiy one address line, a city, state and
666 // zip code.
667 FormData form;
668 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48669 test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field);
[email protected]a36215a2013-04-04 12:35:42670 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48671 test::CreateTestFormField(
[email protected]a36215a2013-04-04 12:35:42672 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
673 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48674 test::CreateTestFormField("City:", "city", "Washington", "text", &field);
[email protected]a36215a2013-04-04 12:35:42675 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48676 test::CreateTestFormField("State:", "state", "DC", "text", &field);
[email protected]a36215a2013-04-04 12:35:42677 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48678 test::CreateTestFormField("Zip:", "zip", "20500", "text", &field);
[email protected]a36215a2013-04-04 12:35:42679 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48680 test::CreateTestFormField("Country:", "country", "USA", "text", &field);
[email protected]a36215a2013-04-04 12:35:42681 form.fields.push_back(field);
682 FormStructure form_structure(form, std::string());
683 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
684 const CreditCard* imported_credit_card;
685 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
686 &imported_credit_card));
687 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
688 ASSERT_EQ(1U, profiles.size());
689}
690
691TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGB) {
692 // British addresses do not require a state/province as the county is usually
693 // not requested on forms.
694 FormData form;
695 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48696 test::CreateTestFormField("Name:", "name", "David Cameron", "text", &field);
[email protected]a36215a2013-04-04 12:35:42697 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48698 test::CreateTestFormField(
[email protected]a36215a2013-04-04 12:35:42699 "Address:", "address", "10 Downing Street", "text", &field);
700 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48701 test::CreateTestFormField("City:", "city", "London", "text", &field);
[email protected]a36215a2013-04-04 12:35:42702 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48703 test::CreateTestFormField(
[email protected]a36215a2013-04-04 12:35:42704 "Postcode:", "postcode", "SW1A 2AA", "text", &field);
705 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48706 test::CreateTestFormField(
[email protected]a36215a2013-04-04 12:35:42707 "Country:", "country", "United Kingdom", "text", &field);
708 form.fields.push_back(field);
709 FormStructure form_structure(form, std::string());
710 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
711 const CreditCard* imported_credit_card;
712 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
713 &imported_credit_card));
714 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
715 ASSERT_EQ(1U, profiles.size());
716}
717
718TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGI) {
719 // Gibraltar has the most minimal set of requirements for a valid address.
720 // There are no cities or provinces and no postal/zip code system.
721 FormData form;
722 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48723 test::CreateTestFormField(
[email protected]a36215a2013-04-04 12:35:42724 "Name:", "name", "Sir Adrian Johns", "text", &field);
725 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48726 test::CreateTestFormField(
[email protected]a36215a2013-04-04 12:35:42727 "Address:", "address", "The Convent, Main Street", "text", &field);
728 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48729 test::CreateTestFormField("Country:", "country", "Gibraltar", "text", &field);
[email protected]a36215a2013-04-04 12:35:42730 form.fields.push_back(field);
731 FormStructure form_structure(form, std::string());
732 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
733 const CreditCard* imported_credit_card;
734 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
735 &imported_credit_card));
736 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
737 ASSERT_EQ(1U, profiles.size());
738}
739
[email protected]3aa8bec22010-11-23 07:51:28740TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) {
741 FormData form;
[email protected]1ecbe862012-10-05 01:29:14742 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48743 test::CreateTestFormField(
[email protected]3aa8bec22010-11-23 07:51:28744 "First name:", "first_name", "George", "text", &field);
745 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48746 test::CreateTestFormField(
[email protected]3aa8bec22010-11-23 07:51:28747 "Last name:", "last_name", "Washington", "text", &field);
748 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48749 test::CreateTestFormField(
[email protected]3aa8bec22010-11-23 07:51:28750 "Phone #:", "home_phone_area_code", "650", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04751 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28752 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48753 test::CreateTestFormField(
[email protected]3aa8bec22010-11-23 07:51:28754 "Phone #:", "home_phone_prefix", "555", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04755 field.max_length = 3;
[email protected]3aa8bec22010-11-23 07:51:28756 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48757 test::CreateTestFormField(
[email protected]3aa8bec22010-11-23 07:51:28758 "Phone #:", "home_phone_suffix", "0000", "text", &field);
[email protected]e2aaa812011-03-08 18:46:04759 field.max_length = 4;
[email protected]3aa8bec22010-11-23 07:51:28760 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48761 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52762 "Address:", "address1", "21 Laussat St", "text", &field);
763 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48764 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52765 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48766 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52767 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48768 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52769 form.fields.push_back(field);
[email protected]685d4972013-02-12 01:06:23770 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:29771 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24772 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21773 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
774 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24775 ASSERT_FALSE(imported_credit_card);
[email protected]3aa8bec22010-11-23 07:51:28776
[email protected]3813dec2011-05-11 20:56:36777 // Verify that the web database has been updated and the notification sent.
[email protected]3aa8bec22010-11-23 07:51:28778 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36779 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]3aa8bec22010-11-23 07:51:28780 MessageLoop::current()->Run();
781
[email protected]e90c2252011-03-10 12:29:21782 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:48783 test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52784 "Washington", NULL, NULL, "21 Laussat St", NULL,
[email protected]5c0208c2012-11-28 15:16:13785 "San Francisco", "California", "94102", NULL, "(650) 555-0000");
[email protected]771ad212012-11-29 18:58:33786 const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles();
[email protected]3aa8bec22010-11-23 07:51:28787 ASSERT_EQ(1U, results.size());
788 EXPECT_EQ(0, expected.Compare(*results[0]));
789}
790
[email protected]47e119f02010-04-15 00:46:55791TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) {
[email protected]e43783402010-11-04 19:45:04792 CreditCard credit_card0;
[email protected]6b44b582012-11-10 06:31:18793 credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John"));
[email protected]e43783402010-11-04 19:45:04794 CreditCard credit_card1;
[email protected]6b44b582012-11-10 06:31:18795 credit_card1.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul"));
[email protected]e43783402010-11-04 19:45:04796 CreditCard credit_card2;
[email protected]6b44b582012-11-10 06:31:18797 credit_card2.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo"));
[email protected]e43783402010-11-04 19:45:04798 CreditCard credit_card3;
[email protected]6b44b582012-11-10 06:31:18799 credit_card3.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other"));
[email protected]e43783402010-11-04 19:45:04800 CreditCard credit_card4;
[email protected]6b44b582012-11-10 06:31:18801 credit_card4.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy"));
[email protected]e43783402010-11-04 19:45:04802 CreditCard credit_card5;
[email protected]6b44b582012-11-10 06:31:18803 credit_card5.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio"));
[email protected]47e119f02010-04-15 00:46:55804
[email protected]98a94ee2010-07-12 16:03:22805 // Add the test credit cards to the database.
[email protected]3813dec2011-05-11 20:56:36806 personal_data_->AddCreditCard(credit_card0);
807 personal_data_->AddCreditCard(credit_card1);
808 personal_data_->AddCreditCard(credit_card2);
809 personal_data_->AddCreditCard(credit_card3);
810 personal_data_->AddCreditCard(credit_card4);
811 personal_data_->AddCreditCard(credit_card5);
[email protected]47e119f02010-04-15 00:46:55812
[email protected]18f92d4f2010-10-19 00:14:58813 // Reset the PersonalDataManager. This tests that the personal data was saved
814 // to the web database, and that we can load the credit cards from the web
815 // database.
816 ResetPersonalDataManager();
817
[email protected]47e119f02010-04-15 00:46:55818 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
819 ASSERT_EQ(6U, results.size());
[email protected]027dd442011-02-15 23:17:34820 EXPECT_EQ(credit_card0.guid(), results[0]->guid());
821 EXPECT_EQ(credit_card1.guid(), results[1]->guid());
822 EXPECT_EQ(credit_card2.guid(), results[2]->guid());
823 EXPECT_EQ(credit_card3.guid(), results[3]->guid());
824 EXPECT_EQ(credit_card4.guid(), results[4]->guid());
825 EXPECT_EQ(credit_card5.guid(), results[5]->guid());
[email protected]47e119f02010-04-15 00:46:55826}
[email protected]cea1d112010-07-01 00:57:33827
[email protected]f1ed7272010-11-11 21:57:07828TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) {
829 FormData form1;
[email protected]1ecbe862012-10-05 01:29:14830 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48831 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33832 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07833 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48834 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33835 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07836 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48837 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33838 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07839 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48840 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:52841 "Address:", "address1", "21 Laussat St", "text", &field);
842 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48843 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52844 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48845 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52846 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48847 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52848 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33849
[email protected]685d4972013-02-12 01:06:23850 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:29851 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:24852 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21853 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
854 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24855 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33856
[email protected]3813dec2011-05-11 20:56:36857 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33858 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36859 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33860 MessageLoop::current()->Run();
861
[email protected]e90c2252011-03-10 12:29:21862 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:48863 test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:52864 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54865 "San Francisco", "California", "94102", NULL, NULL);
[email protected]771ad212012-11-29 18:58:33866 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:07867 ASSERT_EQ(1U, results1.size());
868 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:33869
870 // Now create a completely different profile.
[email protected]f1ed7272010-11-11 21:57:07871 FormData form2;
[email protected]e217c5632013-04-12 19:11:48872 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33873 "First name:", "first_name", "John", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07874 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48875 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33876 "Last name:", "last_name", "Adams", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07877 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48878 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:33879 "Email:", "email", "[email protected]", "text", &field);
[email protected]f1ed7272010-11-11 21:57:07880 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48881 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24882 "Address:", "address1", "22 Laussat St", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52883 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48884 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52885 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48886 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52887 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48888 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]37ff612e2011-02-03 15:54:52889 form2.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:33890
[email protected]685d4972013-02-12 01:06:23891 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:29892 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:21893 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
894 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:24895 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:33896
[email protected]3813dec2011-05-11 20:56:36897 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:33898 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36899 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:33900 MessageLoop::current()->Run();
901
[email protected]771ad212012-11-29 18:58:33902 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]cea1d112010-07-01 00:57:33903
[email protected]e90c2252011-03-10 12:29:21904 AutofillProfile expected2;
[email protected]e217c5632013-04-12 19:11:48905 test::SetProfileInfo(&expected2, "John", NULL,
[email protected]023e1822011-04-13 15:52:24906 "Adams", "[email protected]", NULL, "22 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54907 "San Francisco", "California", "94102", NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:07908 ASSERT_EQ(2U, results2.size());
909 EXPECT_EQ(0, expected.Compare(*results2[0]));
910 EXPECT_EQ(0, expected2.Compare(*results2[1]));
911}
[email protected]cea1d112010-07-01 00:57:33912
[email protected]023e1822011-04-13 15:52:24913TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) {
914 FormData form1;
[email protected]1ecbe862012-10-05 01:29:14915 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:48916 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24917 "First name:", "first_name", "George", "text", &field);
918 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48919 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24920 "Last name:", "last_name", "Washington", "text", &field);
921 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48922 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24923 "Email:", "email", "[email protected]", "text", &field);
924 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48925 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24926 "Address:", "address1", "21 Laussat St", "text", &field);
927 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48928 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]023e1822011-04-13 15:52:24929 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48930 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]023e1822011-04-13 15:52:24931 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48932 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]023e1822011-04-13 15:52:24933 form1.fields.push_back(field);
934
[email protected]685d4972013-02-12 01:06:23935 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:29936 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]023e1822011-04-13 15:52:24937 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:21938 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
939 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24940 ASSERT_FALSE(imported_credit_card);
941
[email protected]3813dec2011-05-11 20:56:36942 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24943 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36944 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24945 MessageLoop::current()->Run();
946
947 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:48948 test::SetProfileInfo(&expected, "George", NULL,
[email protected]023e1822011-04-13 15:52:24949 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]4ef55f8c12011-09-17 00:06:54950 "San Francisco", "California", "94102", NULL, NULL);
[email protected]771ad212012-11-29 18:58:33951 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]023e1822011-04-13 15:52:24952 ASSERT_EQ(1U, results1.size());
953 EXPECT_EQ(0, expected.Compare(*results1[0]));
954
955 // Now create a completely different profile.
956 FormData form2;
[email protected]e217c5632013-04-12 19:11:48957 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24958 "First name:", "first_name", "John", "text", &field);
959 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48960 test::CreateTestFormField("Last name:", "last_name", "Adams", "text", &field);
[email protected]023e1822011-04-13 15:52:24961 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48962 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24963 "Email:", "email", "[email protected]", "text", &field);
964 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48965 test::CreateTestFormField(
[email protected]023e1822011-04-13 15:52:24966 "Address:", "address1", "21 Laussat St", "text", &field);
967 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48968 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]023e1822011-04-13 15:52:24969 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48970 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]023e1822011-04-13 15:52:24971 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:48972 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]023e1822011-04-13 15:52:24973 form2.fields.push_back(field);
974
[email protected]685d4972013-02-12 01:06:23975 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:29976 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:21977 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
978 &imported_credit_card));
[email protected]023e1822011-04-13 15:52:24979 ASSERT_FALSE(imported_credit_card);
980
[email protected]3813dec2011-05-11 20:56:36981 // Verify that the web database has been updated and the notification sent.
[email protected]023e1822011-04-13 15:52:24982 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:36983 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]023e1822011-04-13 15:52:24984 MessageLoop::current()->Run();
985
[email protected]771ad212012-11-29 18:58:33986 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]023e1822011-04-13 15:52:24987
988 // Modify expected to include multi-valued fields.
[email protected]d5ca8fb2013-04-11 17:54:31989 std::vector<base::string16> values;
[email protected]e4364512012-11-29 10:51:06990 expected.GetRawMultiInfo(NAME_FULL, &values);
[email protected]023e1822011-04-13 15:52:24991 values.push_back(ASCIIToUTF16("John Adams"));
[email protected]e4364512012-11-29 10:51:06992 expected.SetRawMultiInfo(NAME_FULL, values);
993 expected.GetRawMultiInfo(EMAIL_ADDRESS, &values);
[email protected]023e1822011-04-13 15:52:24994 values.push_back(ASCIIToUTF16("[email protected]"));
[email protected]e4364512012-11-29 10:51:06995 expected.SetRawMultiInfo(EMAIL_ADDRESS, values);
[email protected]023e1822011-04-13 15:52:24996
997 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:00998 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]023e1822011-04-13 15:52:24999}
1000
[email protected]f1ed7272010-11-11 21:57:071001TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) {
1002 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141003 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481004 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:331005 "First name:", "first_name", "George", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071006 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481007 test::CreateTestFormField(
[email protected]cea1d112010-07-01 00:57:331008 "Last name:", "last_name", "Washington", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071009 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481010 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071011 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
1012 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481013 test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:341014 "Address Line 2:", "address2", "Suite A", "text", &field);
1015 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481016 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521017 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481018 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521019 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481020 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521021 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481022 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071023 "Email:", "email", "[email protected]", "text", &field);
1024 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481025 test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field);
[email protected]465d07f2010-11-30 04:52:341026 form1.fields.push_back(field);
[email protected]cea1d112010-07-01 00:57:331027
[email protected]685d4972013-02-12 01:06:231028 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291029 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241030 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211031 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1032 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241033 ASSERT_FALSE(imported_credit_card);
[email protected]cea1d112010-07-01 00:57:331034
[email protected]3813dec2011-05-11 20:56:361035 // Verify that the web database has been updated and the notification sent.
[email protected]cea1d112010-07-01 00:57:331036 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361037 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]cea1d112010-07-01 00:57:331038 MessageLoop::current()->Run();
1039
[email protected]e90c2252011-03-10 12:29:211040 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:481041 test::SetProfileInfo(
[email protected]5c0208c2012-11-28 15:16:131042 &expected, "George", NULL, "Washington", "[email protected]", NULL,
1043 "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California",
1044 "94102", NULL, "(650) 555-6666");
[email protected]771ad212012-11-29 18:58:331045 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071046 ASSERT_EQ(1U, results1.size());
1047 EXPECT_EQ(0, expected.Compare(*results1[0]));
[email protected]cea1d112010-07-01 00:57:331048
[email protected]f1ed7272010-11-11 21:57:071049 // Now create an updated profile.
1050 FormData form2;
[email protected]e217c5632013-04-12 19:11:481051 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071052 "First name:", "first_name", "George", "text", &field);
1053 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481054 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071055 "Last name:", "last_name", "Washington", "text", &field);
1056 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481057 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071058 "Address:", "address", "1600 Pennsylvania Avenue", "text", &field);
1059 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481060 test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:341061 "Address Line 2:", "address2", "Suite A", "text", &field);
1062 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481063 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521064 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481065 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521066 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481067 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521068 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481069 test::CreateTestFormField(
[email protected]465d07f2010-11-30 04:52:341070 "Email:", "email", "[email protected]", "text", &field);
1071 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071072 // Country gets added.
[email protected]e217c5632013-04-12 19:11:481073 test::CreateTestFormField("Country:", "country", "USA", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071074 form2.fields.push_back(field);
[email protected]465d07f2010-11-30 04:52:341075 // Phone gets updated.
[email protected]e217c5632013-04-12 19:11:481076 test::CreateTestFormField("Phone:", "phone", "6502231234", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071077 form2.fields.push_back(field);
1078
[email protected]685d4972013-02-12 01:06:231079 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291080 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211081 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1082 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241083 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071084
[email protected]3813dec2011-05-11 20:56:361085 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071086 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361087 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071088 MessageLoop::current()->Run();
1089
[email protected]771ad212012-11-29 18:58:331090 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071091
[email protected]023e1822011-04-13 15:52:241092 // Add multi-valued phone number to expectation. Also, country gets added.
[email protected]d5ca8fb2013-04-11 17:54:311093 std::vector<base::string16> values;
[email protected]e4364512012-11-29 10:51:061094 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
[email protected]5c0208c2012-11-28 15:16:131095 values.push_back(ASCIIToUTF16("(650) 223-1234"));
[email protected]e4364512012-11-29 10:51:061096 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
[email protected]91b073d2013-01-05 01:30:281097 expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US"));
[email protected]f1ed7272010-11-11 21:57:071098 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:001099 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]f1ed7272010-11-11 21:57:071100}
1101
1102TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) {
1103 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141104 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481105 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071106 "First name:", "first_name", "George", "text", &field);
1107 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481108 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071109 "Last name:", "last_name", "Washington", "text", &field);
1110 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481111 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521112 "Address Line 1:", "address", "190 High Street", "text", &field);
1113 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481114 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521115 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481116 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521117 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481118 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071119 form1.fields.push_back(field);
1120
[email protected]685d4972013-02-12 01:06:231121 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291122 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241123 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211124 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1125 &imported_credit_card));
[email protected]a73830e2011-10-05 01:12:581126 EXPECT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071127
[email protected]3813dec2011-05-11 20:56:361128 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071129 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361130 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071131 MessageLoop::current()->Run();
1132
[email protected]e90c2252011-03-10 12:29:211133 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:481134 test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521135 "Washington", NULL, NULL, "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541136 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]771ad212012-11-29 18:58:331137 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071138 ASSERT_EQ(1U, results1.size());
1139 EXPECT_EQ(0, expected.Compare(*results1[0]));
1140
1141 // Submit a form with new data for the first profile.
1142 FormData form2;
[email protected]e217c5632013-04-12 19:11:481143 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071144 "First name:", "first_name", "George", "text", &field);
1145 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481146 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071147 "Last name:", "last_name", "Washington", "text", &field);
1148 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481149 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521150 "Email:", "email", "[email protected]", "text", &field);
1151 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481152 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071153 "Address Line 1:", "address", "190 High Street", "text", &field);
1154 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481155 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071156 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481157 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071158 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481159 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
[email protected]f1ed7272010-11-11 21:57:071160 form2.fields.push_back(field);
1161
[email protected]685d4972013-02-12 01:06:231162 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291163 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211164 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1165 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241166 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071167
[email protected]3813dec2011-05-11 20:56:361168 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071169 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361170 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071171 MessageLoop::current()->Run();
1172
[email protected]771ad212012-11-29 18:58:331173 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071174
[email protected]e90c2252011-03-10 12:29:211175 AutofillProfile expected2;
[email protected]e217c5632013-04-12 19:11:481176 test::SetProfileInfo(&expected2, "George", NULL,
[email protected]cea1d112010-07-01 00:57:331177 "Washington", "[email protected]", NULL, "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541178 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]f1ed7272010-11-11 21:57:071179 ASSERT_EQ(1U, results2.size());
1180 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1181}
[email protected]cea1d112010-07-01 00:57:331182
[email protected]f1ed7272010-11-11 21:57:071183TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) {
1184 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141185 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481186 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071187 "First name:", "first_name", "George", "text", &field);
1188 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481189 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071190 "Last name:", "last_name", "Washington", "text", &field);
1191 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481192 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071193 "Company:", "company", "Government", "text", &field);
1194 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481195 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071196 "Email:", "email", "[email protected]", "text", &field);
1197 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481198 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521199 "Address Line 1:", "address", "190 High Street", "text", &field);
1200 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481201 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521202 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481203 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521204 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481205 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521206 form1.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071207
[email protected]685d4972013-02-12 01:06:231208 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291209 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241210 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211211 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1212 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241213 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071214
[email protected]3813dec2011-05-11 20:56:361215 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071216 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361217 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071218 MessageLoop::current()->Run();
1219
[email protected]e90c2252011-03-10 12:29:211220 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:481221 test::SetProfileInfo(&expected, "George", NULL,
[email protected]37ff612e2011-02-03 15:54:521222 "Washington", "[email protected]", "Government", "190 High Street", NULL,
[email protected]4ef55f8c12011-09-17 00:06:541223 "Philadelphia", "Pennsylvania", "19106", NULL, NULL);
[email protected]771ad212012-11-29 18:58:331224 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071225 ASSERT_EQ(1U, results1.size());
1226 EXPECT_EQ(0, expected.Compare(*results1[0]));
1227
1228 // Submit a form with new data for the first profile.
1229 FormData form2;
[email protected]e217c5632013-04-12 19:11:481230 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071231 "First name:", "first_name", "George", "text", &field);
1232 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481233 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071234 "Last name:", "last_name", "Washington", "text", &field);
1235 form2.fields.push_back(field);
1236 // Note missing Company field.
[email protected]e217c5632013-04-12 19:11:481237 test::CreateTestFormField(
[email protected]f1ed7272010-11-11 21:57:071238 "Email:", "email", "[email protected]", "text", &field);
1239 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481240 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521241 "Address Line 1:", "address", "190 High Street", "text", &field);
1242 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481243 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521244 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481245 test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521246 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481247 test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521248 form2.fields.push_back(field);
[email protected]f1ed7272010-11-11 21:57:071249
[email protected]685d4972013-02-12 01:06:231250 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291251 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211252 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1253 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241254 ASSERT_FALSE(imported_credit_card);
[email protected]f1ed7272010-11-11 21:57:071255
[email protected]3813dec2011-05-11 20:56:361256 // Verify that the web database has been updated and the notification sent.
[email protected]f1ed7272010-11-11 21:57:071257 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361258 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]f1ed7272010-11-11 21:57:071259 MessageLoop::current()->Run();
1260
[email protected]771ad212012-11-29 18:58:331261 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]f1ed7272010-11-11 21:57:071262
1263 // Expect no change.
1264 ASSERT_EQ(1U, results2.size());
1265 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]cea1d112010-07-01 00:57:331266}
[email protected]d7da65d2010-11-11 19:26:051267
[email protected]37ff612e2011-02-03 15:54:521268TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) {
1269 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141270 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481271 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521272 "First name:", "first_name", "George", "text", &field);
1273 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481274 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521275 "Last name:", "last_name", "Washington", "text", &field);
1276 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481277 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521278 "Company:", "company", "Government", "text", &field);
1279 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481280 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521281 "Email:", "email", "[email protected]", "text", &field);
1282 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481283 test::CreateTestFormField(
[email protected]37ff612e2011-02-03 15:54:521284 "Address Line 1:", "address", "190 High Street", "text", &field);
1285 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481286 test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field);
[email protected]37ff612e2011-02-03 15:54:521287 form1.fields.push_back(field);
1288
[email protected]685d4972013-02-12 01:06:231289 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291290 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241291 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211292 EXPECT_FALSE(personal_data_->ImportFormData(form_structure1,
1293 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241294 ASSERT_FALSE(imported_credit_card);
[email protected]414c35482011-02-09 01:26:131295
[email protected]3813dec2011-05-11 20:56:361296 // Note: no refresh here.
[email protected]414c35482011-02-09 01:26:131297
[email protected]771ad212012-11-29 18:58:331298 const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles();
[email protected]414c35482011-02-09 01:26:131299 ASSERT_EQ(0U, profiles.size());
1300 const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards();
1301 ASSERT_EQ(0U, credit_cards.size());
[email protected]37ff612e2011-02-03 15:54:521302}
1303
[email protected]0b5847612011-10-05 03:52:181304TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) {
1305 // Simulate having access to an auxiliary profile.
1306 // |auxiliary_profile| will be owned by |personal_data_|.
1307 AutofillProfile* auxiliary_profile = new AutofillProfile;
[email protected]e217c5632013-04-12 19:11:481308 test::SetProfileInfo(auxiliary_profile,
[email protected]0b5847612011-10-05 03:52:181309 "Tester", "Frederick", "McAddressBookTesterson",
1310 "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco",
[email protected]91b073d2013-01-05 01:30:281311 "CA", "94102", "US", "1.415.888.9999");
[email protected]0b5847612011-10-05 03:52:181312 ScopedVector<AutofillProfile>& auxiliary_profiles =
1313 personal_data_->auxiliary_profiles_;
1314 auxiliary_profiles.push_back(auxiliary_profile);
1315
1316 // Simulate a form submission with a subset of the info.
1317 // Note that the phone number format is different from the saved format.
1318 FormData form;
[email protected]1ecbe862012-10-05 01:29:141319 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481320 test::CreateTestFormField(
[email protected]0b5847612011-10-05 03:52:181321 "First name:", "first_name", "Tester", "text", &field);
1322 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481323 test::CreateTestFormField(
[email protected]0b5847612011-10-05 03:52:181324 "Last name:", "last_name", "McAddressBookTesterson", "text", &field);
1325 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481326 test::CreateTestFormField(
[email protected]0b5847612011-10-05 03:52:181327 "Email:", "email", "[email protected]", "text", &field);
1328 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481329 test::CreateTestFormField("Address:", "address1", "1 Main", "text", &field);
[email protected]0b5847612011-10-05 03:52:181330 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481331 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]0b5847612011-10-05 03:52:181332 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481333 test::CreateTestFormField("State:", "state", "CA", "text", &field);
[email protected]0b5847612011-10-05 03:52:181334 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481335 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]0b5847612011-10-05 03:52:181336 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481337 test::CreateTestFormField("Phone:", "phone", "4158889999", "text", &field);
[email protected]0b5847612011-10-05 03:52:181338 form.fields.push_back(field);
1339
[email protected]685d4972013-02-12 01:06:231340 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:291341 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]0b5847612011-10-05 03:52:181342 const CreditCard* imported_credit_card;
1343 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
1344 &imported_credit_card));
1345 EXPECT_FALSE(imported_credit_card);
1346
1347 // Note: No refresh.
1348
1349 // Expect no change.
1350 const std::vector<AutofillProfile*>& web_profiles =
1351 personal_data_->web_profiles();
1352 EXPECT_EQ(0U, web_profiles.size());
1353 ASSERT_EQ(1U, auxiliary_profiles.size());
1354 EXPECT_EQ(0, auxiliary_profile->Compare(*auxiliary_profiles[0]));
1355}
1356
[email protected]d7da65d2010-11-11 19:26:051357TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) {
1358 FormData form1;
1359
1360 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141361 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481362 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051363 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1364 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481365 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051366 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1367 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481368 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051369 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481370 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051371 form1.fields.push_back(field);
1372
[email protected]685d4972013-02-12 01:06:231373 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291374 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241375 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211376 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1377 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241378 ASSERT_TRUE(imported_credit_card);
1379 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1380 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051381
[email protected]3813dec2011-05-11 20:56:361382 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051383 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361384 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051385 MessageLoop::current()->Run();
1386
1387 CreditCard expected;
[email protected]e217c5632013-04-12 19:11:481388 test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341389 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051390 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1391 ASSERT_EQ(1U, results.size());
1392 EXPECT_EQ(0, expected.Compare(*results[0]));
1393
1394 // Add a second different valid credit card.
1395 FormData form2;
[email protected]e217c5632013-04-12 19:11:481396 test::CreateTestFormField(
[email protected]490a6a502011-09-27 17:30:111397 "Name on card:", "name_on_card", "", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051398 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481399 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051400 "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field);
1401 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481402 test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051403 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481404 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051405 form2.fields.push_back(field);
1406
[email protected]685d4972013-02-12 01:06:231407 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291408 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211409 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1410 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241411 ASSERT_TRUE(imported_credit_card);
1412 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1413 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051414
[email protected]3813dec2011-05-11 20:56:361415 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051416 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361417 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051418 MessageLoop::current()->Run();
1419
1420 CreditCard expected2;
[email protected]e217c5632013-04-12 19:11:481421 test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012");
[email protected]d7da65d2010-11-11 19:26:051422 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1423 ASSERT_EQ(2U, results2.size());
1424 EXPECT_EQ(0, expected.Compare(*results2[0]));
1425 EXPECT_EQ(0, expected2.Compare(*results2[1]));
1426}
1427
1428TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) {
1429 FormData form1;
1430
1431 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141432 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481433 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051434 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1435 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481436 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051437 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1438 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481439 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051440 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481441 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051442 form1.fields.push_back(field);
1443
[email protected]685d4972013-02-12 01:06:231444 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291445 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241446 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211447 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1448 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241449 ASSERT_TRUE(imported_credit_card);
1450 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1451 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051452
[email protected]3813dec2011-05-11 20:56:361453 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051454 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361455 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051456 MessageLoop::current()->Run();
1457
1458 CreditCard expected;
[email protected]e217c5632013-04-12 19:11:481459 test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341460 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051461 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1462 ASSERT_EQ(1U, results.size());
1463 EXPECT_EQ(0, expected.Compare(*results[0]));
1464
1465 // Add a second different invalid credit card.
1466 FormData form2;
[email protected]e217c5632013-04-12 19:11:481467 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051468 "Name on card:", "name_on_card", "Jim Johansen", "text", &field);
1469 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481470 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051471 "Card Number:", "card_number", "1000000000000000", "text", &field);
1472 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481473 test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051474 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481475 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051476 form2.fields.push_back(field);
1477
[email protected]685d4972013-02-12 01:06:231478 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291479 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211480 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1481 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241482 ASSERT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051483
1484 // Note: no refresh here.
1485
1486 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1487 ASSERT_EQ(1U, results2.size());
1488 EXPECT_EQ(0, expected.Compare(*results2[0]));
1489}
1490
1491TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) {
1492 FormData form1;
1493
1494 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141495 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481496 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051497 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1498 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481499 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051500 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1501 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481502 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051503 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481504 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051505 form1.fields.push_back(field);
1506
[email protected]685d4972013-02-12 01:06:231507 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291508 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241509 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211510 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1511 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241512 ASSERT_TRUE(imported_credit_card);
1513 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1514 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051515
[email protected]3813dec2011-05-11 20:56:361516 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051517 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361518 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051519 MessageLoop::current()->Run();
1520
1521 CreditCard expected;
[email protected]e217c5632013-04-12 19:11:481522 test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341523 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051524 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1525 ASSERT_EQ(1U, results.size());
1526 EXPECT_EQ(0, expected.Compare(*results[0]));
1527
1528 // Add a second different valid credit card where the year is different but
1529 // the credit card number matches.
1530 FormData form2;
[email protected]e217c5632013-04-12 19:11:481531 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051532 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1533 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481534 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051535 "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field);
1536 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481537 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051538 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481539 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051540 form2.fields.push_back(field);
1541
[email protected]685d4972013-02-12 01:06:231542 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291543 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211544 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1545 &imported_credit_card));
[email protected]e5f5cf72011-10-04 22:18:061546 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051547
[email protected]3813dec2011-05-11 20:56:361548 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051549 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361550 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051551 MessageLoop::current()->Run();
1552
1553 // Expect that the newer information is saved. In this case the year is
1554 // updated to "2012".
1555 CreditCard expected2;
[email protected]e217c5632013-04-12 19:11:481556 test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341557 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051558 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1559 ASSERT_EQ(1U, results2.size());
1560 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1561}
1562
1563TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) {
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]e217c5632013-04-12 19:11:481568 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051569 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1570 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481571 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051572 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1573 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481574 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051575 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481576 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051577 form1.fields.push_back(field);
1578
[email protected]685d4972013-02-12 01:06:231579 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291580 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241581 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211582 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1583 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241584 ASSERT_TRUE(imported_credit_card);
1585 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1586 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051587
[email protected]3813dec2011-05-11 20:56:361588 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051589 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361590 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051591 MessageLoop::current()->Run();
1592
1593 CreditCard expected;
[email protected]e217c5632013-04-12 19:11:481594 test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341595 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051596 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1597 ASSERT_EQ(1U, results.size());
1598 EXPECT_EQ(0, expected.Compare(*results[0]));
1599
1600 // Add a second credit card with no number.
1601 FormData form2;
[email protected]e217c5632013-04-12 19:11:481602 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051603 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1604 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481605 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051606 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481607 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051608 form2.fields.push_back(field);
1609
[email protected]685d4972013-02-12 01:06:231610 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291611 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]2a958552011-05-05 04:01:211612 EXPECT_FALSE(personal_data_->ImportFormData(form_structure2,
1613 &imported_credit_card));
[email protected]3e6e82da2011-04-06 05:41:341614 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051615
1616 // Note: no refresh here.
1617
1618 // No change is expected.
1619 CreditCard expected2;
[email protected]e217c5632013-04-12 19:11:481620 test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341621 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051622 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1623 ASSERT_EQ(1U, results2.size());
1624 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1625}
1626
1627TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) {
1628 FormData form1;
1629
1630 // Start with a single valid credit card form.
[email protected]1ecbe862012-10-05 01:29:141631 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481632 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051633 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1634 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481635 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051636 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1637 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481638 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051639 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481640 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051641 form1.fields.push_back(field);
1642
[email protected]685d4972013-02-12 01:06:231643 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291644 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]abcdf1a2011-02-04 23:12:241645 const CreditCard* imported_credit_card;
[email protected]2a958552011-05-05 04:01:211646 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1647 &imported_credit_card));
[email protected]abcdf1a2011-02-04 23:12:241648 ASSERT_TRUE(imported_credit_card);
1649 personal_data_->SaveImportedCreditCard(*imported_credit_card);
1650 delete imported_credit_card;
[email protected]d7da65d2010-11-11 19:26:051651
[email protected]3813dec2011-05-11 20:56:361652 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051653 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361654 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051655 MessageLoop::current()->Run();
1656
1657 CreditCard expected;
[email protected]e217c5632013-04-12 19:11:481658 test::SetCreditCardInfo(&expected,
[email protected]027dd442011-02-15 23:17:341659 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051660 const std::vector<CreditCard*>& results = personal_data_->credit_cards();
1661 ASSERT_EQ(1U, results.size());
1662 EXPECT_EQ(0, expected.Compare(*results[0]));
1663
1664 // Add a second different valid credit card where the name is missing but
1665 // the credit card number matches.
1666 FormData form2;
1667 // Note missing name.
[email protected]e217c5632013-04-12 19:11:481668 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051669 "Card Number:", "card_number", "4111111111111111", "text", &field);
1670 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481671 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051672 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481673 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]d7da65d2010-11-11 19:26:051674 form2.fields.push_back(field);
1675
[email protected]685d4972013-02-12 01:06:231676 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:291677 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]e5f5cf72011-10-04 22:18:061678 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
1679 &imported_credit_card));
1680 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051681
[email protected]e5f5cf72011-10-04 22:18:061682 // Wait for the refresh, which in this case is a no-op.
1683 EXPECT_CALL(personal_data_observer_,
1684 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1685 MessageLoop::current()->Run();
[email protected]d7da65d2010-11-11 19:26:051686
1687 // No change is expected.
1688 CreditCard expected2;
[email protected]e217c5632013-04-12 19:11:481689 test::SetCreditCardInfo(&expected2,
[email protected]027dd442011-02-15 23:17:341690 "Biggie Smalls", "4111111111111111", "01", "2011");
[email protected]d7da65d2010-11-11 19:26:051691 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1692 ASSERT_EQ(1U, results2.size());
1693 EXPECT_EQ(0, expected2.Compare(*results2[0]));
[email protected]cdd0d4482011-07-22 04:24:221694
1695 // Add a third credit card where the expiration date is missing.
1696 FormData form3;
[email protected]e217c5632013-04-12 19:11:481697 test::CreateTestFormField(
[email protected]cdd0d4482011-07-22 04:24:221698 "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field);
1699 form3.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481700 test::CreateTestFormField(
[email protected]cdd0d4482011-07-22 04:24:221701 "Card Number:", "card_number", "5555555555554444", "text", &field);
1702 form3.fields.push_back(field);
1703 // Note missing expiration month and year..
1704
[email protected]685d4972013-02-12 01:06:231705 FormStructure form_structure3(form3, std::string());
[email protected]dfd1818d2012-10-26 21:53:291706 form_structure3.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]cdd0d4482011-07-22 04:24:221707 EXPECT_FALSE(personal_data_->ImportFormData(form_structure3,
1708 &imported_credit_card));
1709 ASSERT_FALSE(imported_credit_card);
1710
1711 // Note: no refresh here.
1712
1713 // No change is expected.
1714 CreditCard expected3;
[email protected]e217c5632013-04-12 19:11:481715 test::SetCreditCardInfo(&expected3,
[email protected]cdd0d4482011-07-22 04:24:221716 "Biggie Smalls", "4111111111111111", "01", "2011");
1717 const std::vector<CreditCard*>& results3 = personal_data_->credit_cards();
1718 ASSERT_EQ(1U, results3.size());
1719 EXPECT_EQ(0, expected3.Compare(*results2[0]));
[email protected]d7da65d2010-11-11 19:26:051720}
1721
1722TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) {
[email protected]cdd0d4482011-07-22 04:24:221723 // Start with a single valid credit card stored via the preferences.
1724 // Note the empty name.
1725 CreditCard saved_credit_card;
[email protected]e217c5632013-04-12 19:11:481726 test::SetCreditCardInfo(&saved_credit_card,
[email protected]cdd0d4482011-07-22 04:24:221727 "", "4111111111111111" /* Visa */, "01", "2011");
1728 personal_data_->AddCreditCard(saved_credit_card);
[email protected]d7da65d2010-11-11 19:26:051729
[email protected]3813dec2011-05-11 20:56:361730 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051731 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361732 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051733 MessageLoop::current()->Run();
1734
[email protected]cdd0d4482011-07-22 04:24:221735 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1736 ASSERT_EQ(1U, results1.size());
1737 EXPECT_EQ(saved_credit_card, *results1[0]);
1738
[email protected]d7da65d2010-11-11 19:26:051739
1740 // Add a second different valid credit card where the year is different but
1741 // the credit card number matches.
[email protected]cdd0d4482011-07-22 04:24:221742 FormData form;
[email protected]1ecbe862012-10-05 01:29:141743 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481744 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051745 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221746 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481747 test::CreateTestFormField(
[email protected]d7da65d2010-11-11 19:26:051748 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221749 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481750 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221751 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481752 test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field);
[email protected]cdd0d4482011-07-22 04:24:221753 form.fields.push_back(field);
[email protected]d7da65d2010-11-11 19:26:051754
[email protected]685d4972013-02-12 01:06:231755 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:291756 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]cdd0d4482011-07-22 04:24:221757 const CreditCard* imported_credit_card;
1758 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
[email protected]2a958552011-05-05 04:01:211759 &imported_credit_card));
[email protected]e5f5cf72011-10-04 22:18:061760 EXPECT_FALSE(imported_credit_card);
[email protected]d7da65d2010-11-11 19:26:051761
[email protected]3813dec2011-05-11 20:56:361762 // Verify that the web database has been updated and the notification sent.
[email protected]d7da65d2010-11-11 19:26:051763 EXPECT_CALL(personal_data_observer_,
[email protected]3813dec2011-05-11 20:56:361764 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
[email protected]d7da65d2010-11-11 19:26:051765 MessageLoop::current()->Run();
1766
1767 // Expect that the newer information is saved. In this case the year is
1768 // added to the existing credit card.
1769 CreditCard expected2;
[email protected]e217c5632013-04-12 19:11:481770 test::SetCreditCardInfo(&expected2,
[email protected]cdd0d4482011-07-22 04:24:221771 "Biggie Smalls", "4111111111111111", "01", "2012");
[email protected]d7da65d2010-11-11 19:26:051772 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1773 ASSERT_EQ(1U, results2.size());
1774 EXPECT_EQ(0, expected2.Compare(*results2[0]));
1775}
[email protected]ca64d232011-05-06 05:46:001776
[email protected]e5f5cf72011-10-04 22:18:061777// We allow the user to store a credit card number with separators via the UI.
1778// We should not try to re-aggregate the same card with the separators stripped.
1779TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) {
1780 // Start with a single valid credit card stored via the preferences.
1781 // Note the separators in the credit card number.
1782 CreditCard saved_credit_card;
[email protected]e217c5632013-04-12 19:11:481783 test::SetCreditCardInfo(&saved_credit_card,
[email protected]e5f5cf72011-10-04 22:18:061784 "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011");
1785 personal_data_->AddCreditCard(saved_credit_card);
1786
1787 // Verify that the web database has been updated and the notification sent.
1788 EXPECT_CALL(personal_data_observer_,
1789 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1790 MessageLoop::current()->Run();
1791
1792 const std::vector<CreditCard*>& results1 = personal_data_->credit_cards();
1793 ASSERT_EQ(1U, results1.size());
1794 EXPECT_EQ(0, saved_credit_card.Compare(*results1[0]));
1795
1796 // Import the same card info, but with different separators in the number.
1797 FormData form;
[email protected]1ecbe862012-10-05 01:29:141798 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481799 test::CreateTestFormField(
[email protected]e5f5cf72011-10-04 22:18:061800 "Name on card:", "name_on_card", "Biggie Smalls", "text", &field);
1801 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481802 test::CreateTestFormField(
[email protected]e5f5cf72011-10-04 22:18:061803 "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field);
1804 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481805 test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field);
[email protected]e5f5cf72011-10-04 22:18:061806 form.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481807 test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field);
[email protected]e5f5cf72011-10-04 22:18:061808 form.fields.push_back(field);
1809
[email protected]685d4972013-02-12 01:06:231810 FormStructure form_structure(form, std::string());
[email protected]dfd1818d2012-10-26 21:53:291811 form_structure.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]e5f5cf72011-10-04 22:18:061812 const CreditCard* imported_credit_card;
1813 EXPECT_TRUE(personal_data_->ImportFormData(form_structure,
1814 &imported_credit_card));
1815 EXPECT_FALSE(imported_credit_card);
1816
1817 // Wait for the refresh, which in this case is a no-op.
1818 EXPECT_CALL(personal_data_observer_,
1819 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1820 MessageLoop::current()->Run();
1821
1822 // Expect that no new card is saved.
1823 const std::vector<CreditCard*>& results2 = personal_data_->credit_cards();
1824 ASSERT_EQ(1U, results2.size());
1825 EXPECT_EQ(0, saved_credit_card.Compare(*results2[0]));
1826}
1827
[email protected]1308c2832011-05-09 18:30:231828TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) {
[email protected]ca64d232011-05-06 05:46:001829 // Check that there are no available types with no profiles stored.
[email protected]1308c2832011-05-09 18:30:231830 FieldTypeSet non_empty_types;
1831 personal_data_->GetNonEmptyTypes(&non_empty_types);
1832 EXPECT_EQ(0U, non_empty_types.size());
[email protected]ca64d232011-05-06 05:46:001833
1834 // Test with one profile stored.
1835 AutofillProfile profile0;
[email protected]e217c5632013-04-12 19:11:481836 test::SetProfileInfo(&profile0,
[email protected]ca64d232011-05-06 05:46:001837 "Marion", NULL, "Morrison",
1838 "[email protected]", NULL, "123 Zoo St.", NULL, "Hollywood", "CA",
[email protected]4ef55f8c12011-09-17 00:06:541839 "91601", "US", "14155678910");
[email protected]ca64d232011-05-06 05:46:001840
[email protected]3813dec2011-05-11 20:56:361841 personal_data_->AddProfile(profile0);
1842
1843 // Verify that the web database has been updated and the notification sent.
1844 EXPECT_CALL(personal_data_observer_,
1845 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1846 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001847
[email protected]1308c2832011-05-09 18:30:231848 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]11c2bdd12011-05-23 18:24:321849 EXPECT_EQ(14U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231850 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1851 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1852 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1853 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1854 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1855 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1856 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1857 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1858 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1859 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
[email protected]11c2bdd12011-05-23 18:24:321860 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
[email protected]1308c2832011-05-09 18:30:231861 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1862 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1863 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001864
1865 // Test with multiple profiles stored.
1866 AutofillProfile profile1;
[email protected]e217c5632013-04-12 19:11:481867 test::SetProfileInfo(&profile1,
[email protected]ca64d232011-05-06 05:46:001868 "Josephine", "Alicia", "Saenz",
1869 "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801",
[email protected]4ef55f8c12011-09-17 00:06:541870 "US", "16502937549");
[email protected]ca64d232011-05-06 05:46:001871
1872 AutofillProfile profile2;
[email protected]e217c5632013-04-12 19:11:481873 test::SetProfileInfo(&profile2,
[email protected]ca64d232011-05-06 05:46:001874 "Josephine", "Alicia", "Saenz",
1875 "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL",
[email protected]4ef55f8c12011-09-17 00:06:541876 "32801", "US", "16502937549");
[email protected]ca64d232011-05-06 05:46:001877
[email protected]3813dec2011-05-11 20:56:361878 personal_data_->AddProfile(profile1);
1879 personal_data_->AddProfile(profile2);
1880
1881 // Verify that the web database has been updated and the notification sent.
1882 EXPECT_CALL(personal_data_observer_,
1883 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1884 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001885
[email protected]1308c2832011-05-09 18:30:231886 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]4ef55f8c12011-09-17 00:06:541887 EXPECT_EQ(18U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231888 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1889 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1890 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1891 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1892 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1893 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1894 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1895 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1896 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1897 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1898 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1899 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1900 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1901 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1902 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1903 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1904 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1905 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]ca64d232011-05-06 05:46:001906
1907 // Test with credit card information also stored.
1908 CreditCard credit_card;
[email protected]e217c5632013-04-12 19:11:481909 test::SetCreditCardInfo(&credit_card,
1910 "John Dillinger", "423456789012" /* Visa */,
1911 "01", "2010");
[email protected]3813dec2011-05-11 20:56:361912 personal_data_->AddCreditCard(credit_card);
[email protected]ca64d232011-05-06 05:46:001913
[email protected]3813dec2011-05-11 20:56:361914 // Verify that the web database has been updated and the notification sent.
1915 EXPECT_CALL(personal_data_observer_,
1916 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1917 MessageLoop::current()->Run();
[email protected]ca64d232011-05-06 05:46:001918
[email protected]1308c2832011-05-09 18:30:231919 personal_data_->GetNonEmptyTypes(&non_empty_types);
[email protected]4ef55f8c12011-09-17 00:06:541920 EXPECT_EQ(25U, non_empty_types.size());
[email protected]1308c2832011-05-09 18:30:231921 EXPECT_TRUE(non_empty_types.count(NAME_FIRST));
1922 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE));
1923 EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL));
1924 EXPECT_TRUE(non_empty_types.count(NAME_LAST));
1925 EXPECT_TRUE(non_empty_types.count(NAME_FULL));
1926 EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS));
1927 EXPECT_TRUE(non_empty_types.count(COMPANY_NAME));
1928 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1));
1929 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2));
1930 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY));
1931 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE));
1932 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP));
1933 EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY));
1934 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER));
1935 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE));
1936 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE));
1937 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER));
1938 EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER));
[email protected]1308c2832011-05-09 18:30:231939 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NAME));
1940 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NUMBER));
1941 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_MONTH));
1942 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_2_DIGIT_YEAR));
1943 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1944 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR));
1945 EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR));
[email protected]ca64d232011-05-06 05:46:001946}
[email protected]343b4fd2011-08-15 19:32:391947
1948TEST_F(PersonalDataManagerTest, CaseInsensitiveMultiValueAggregation) {
1949 FormData form1;
[email protected]1ecbe862012-10-05 01:29:141950 FormFieldData field;
[email protected]e217c5632013-04-12 19:11:481951 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391952 "First name:", "first_name", "George", "text", &field);
1953 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481954 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391955 "Last name:", "last_name", "Washington", "text", &field);
1956 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481957 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391958 "Email:", "email", "[email protected]", "text", &field);
1959 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481960 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391961 "Address:", "address1", "21 Laussat St", "text", &field);
1962 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481963 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391964 "City:", "city", "San Francisco", "text", &field);
1965 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481966 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]343b4fd2011-08-15 19:32:391967 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481968 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391969 "Zip:", "zip", "94102", "text", &field);
1970 form1.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:481971 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391972 "Phone number:", "phone_number", "817-555-6789", "text", &field);
1973 form1.fields.push_back(field);
1974
[email protected]685d4972013-02-12 01:06:231975 FormStructure form_structure1(form1, std::string());
[email protected]dfd1818d2012-10-26 21:53:291976 form_structure1.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]343b4fd2011-08-15 19:32:391977 const CreditCard* imported_credit_card;
1978 EXPECT_TRUE(personal_data_->ImportFormData(form_structure1,
1979 &imported_credit_card));
1980 ASSERT_FALSE(imported_credit_card);
1981
1982 // Verify that the web database has been updated and the notification sent.
1983 EXPECT_CALL(personal_data_observer_,
1984 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
1985 MessageLoop::current()->Run();
1986
1987 AutofillProfile expected;
[email protected]e217c5632013-04-12 19:11:481988 test::SetProfileInfo(&expected, "George", NULL,
[email protected]343b4fd2011-08-15 19:32:391989 "Washington", "[email protected]", NULL, "21 Laussat St", NULL,
[email protected]5c0208c2012-11-28 15:16:131990 "San Francisco", "California", "94102", NULL, "(817) 555-6789");
[email protected]771ad212012-11-29 18:58:331991 const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles();
[email protected]343b4fd2011-08-15 19:32:391992 ASSERT_EQ(1U, results1.size());
1993 EXPECT_EQ(0, expected.Compare(*results1[0]));
1994
1995 // Upper-case the first name and change the phone number.
1996 FormData form2;
[email protected]e217c5632013-04-12 19:11:481997 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:391998 "First name:", "first_name", "GEORGE", "text", &field);
1999 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482000 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:392001 "Last name:", "last_name", "Washington", "text", &field);
2002 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482003 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:392004 "Email:", "email", "[email protected]", "text", &field);
2005 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482006 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:392007 "Address:", "address1", "21 Laussat St", "text", &field);
2008 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482009 test::CreateTestFormField("City:", "city", "San Francisco", "text", &field);
[email protected]343b4fd2011-08-15 19:32:392010 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482011 test::CreateTestFormField("State:", "state", "California", "text", &field);
[email protected]343b4fd2011-08-15 19:32:392012 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482013 test::CreateTestFormField("Zip:", "zip", "94102", "text", &field);
[email protected]343b4fd2011-08-15 19:32:392014 form2.fields.push_back(field);
[email protected]e217c5632013-04-12 19:11:482015 test::CreateTestFormField(
[email protected]343b4fd2011-08-15 19:32:392016 "Phone number:", "phone_number", "214-555-1234", "text", &field);
2017 form2.fields.push_back(field);
2018
[email protected]685d4972013-02-12 01:06:232019 FormStructure form_structure2(form2, std::string());
[email protected]dfd1818d2012-10-26 21:53:292020 form_structure2.DetermineHeuristicTypes(TestAutofillMetrics());
[email protected]343b4fd2011-08-15 19:32:392021 EXPECT_TRUE(personal_data_->ImportFormData(form_structure2,
2022 &imported_credit_card));
2023 ASSERT_FALSE(imported_credit_card);
2024
2025 // Verify that the web database has been updated and the notification sent.
2026 EXPECT_CALL(personal_data_observer_,
2027 OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop());
2028 MessageLoop::current()->Run();
2029
[email protected]771ad212012-11-29 18:58:332030 const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles();
[email protected]343b4fd2011-08-15 19:32:392031
2032 // Modify expected to include multi-valued fields.
[email protected]d5ca8fb2013-04-11 17:54:312033 std::vector<base::string16> values;
[email protected]e4364512012-11-29 10:51:062034 expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
[email protected]5c0208c2012-11-28 15:16:132035 values.push_back(ASCIIToUTF16("(214) 555-1234"));
[email protected]e4364512012-11-29 10:51:062036 expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values);
[email protected]343b4fd2011-08-15 19:32:392037
2038 ASSERT_EQ(1U, results2.size());
[email protected]f2cd8362012-01-23 22:34:002039 EXPECT_EQ(0, expected.Compare(*results2[0]));
[email protected]343b4fd2011-08-15 19:32:392040}
[email protected]e217c5632013-04-12 19:11:482041
2042} // namespace autofill