[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 42fe7bf2 | 2010-12-17 21:44:47 | [diff] [blame] | 5 | #include <string> |
| 6 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 7 | #include "base/basictypes.h" |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 8 | #include "base/guid.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 10 | #include "base/message_loop.h" |
[email protected] | fabb4ba | 2013-03-20 20:32:05 | [diff] [blame] | 11 | #include "base/synchronization/waitable_event.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 12 | #include "base/utf_string_conversions.h" |
[email protected] | bf925774 | 2011-08-11 21:01:15 | [diff] [blame] | 13 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 14 | #include "chrome/test/base/testing_profile.h" |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 15 | #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] | ece282a | 2013-04-11 04:39:57 | [diff] [blame] | 21 | #include "components/autofill/browser/webdata/autofill_webdata_service.h" |
[email protected] | edf48d4 | 2013-03-07 05:44:43 | [diff] [blame] | 22 | #include "components/autofill/common/form_data.h" |
[email protected] | da84fa4 | 2013-03-24 20:57:36 | [diff] [blame] | 23 | #include "components/webdata/encryptor/encryptor.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 24 | #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] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 27 | #include "content/public/browser/notification_types.h" |
[email protected] | b8d4833 | 2012-06-03 21:59:53 | [diff] [blame] | 28 | #include "content/public/test/mock_notification_observer.h" |
[email protected] | e97882f | 2012-06-04 02:23:17 | [diff] [blame] | 29 | #include "content/public/test/test_browser_thread.h" |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 30 | #include "testing/gmock/include/gmock/gmock.h" |
| 31 | #include "testing/gtest/include/gtest/gtest.h" |
| 32 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 33 | using content::BrowserThread; |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 34 | |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 35 | namespace autofill { |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 36 | namespace { |
| 37 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 38 | ACTION(QuitUIMessageLoop) { |
[email protected] | faec631 | 2010-10-05 03:35:34 | [diff] [blame] | 39 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 40 | MessageLoop::current()->Quit(); |
| 41 | } |
| 42 | |
[email protected] | a7e585a | 2011-08-08 20:32:54 | [diff] [blame] | 43 | class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 44 | public: |
| 45 | PersonalDataLoadedObserverMock() {} |
| 46 | virtual ~PersonalDataLoadedObserverMock() {} |
| 47 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 48 | MOCK_METHOD0(OnPersonalDataChanged, void()); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 49 | }; |
| 50 | |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 51 | // 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. |
| 54 | class TestAutofillMetrics : public AutofillMetrics { |
| 55 | public: |
| 56 | TestAutofillMetrics() {} |
| 57 | virtual ~TestAutofillMetrics() {} |
| 58 | }; |
| 59 | |
| 60 | } // anonymous namespace |
| 61 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 62 | class PersonalDataManagerTest : public testing::Test { |
| 63 | protected: |
| 64 | PersonalDataManagerTest() |
[email protected] | faec631 | 2010-10-05 03:35:34 | [diff] [blame] | 65 | : ui_thread_(BrowserThread::UI, &message_loop_), |
| 66 | db_thread_(BrowserThread::DB) { |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | virtual void SetUp() { |
| 70 | db_thread_.Start(); |
| 71 | |
| 72 | profile_.reset(new TestingProfile); |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 73 | profile_->CreateWebDataService(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 74 | |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 75 | test::DisableSystemServices(profile_.get()); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 76 | ResetPersonalDataManager(); |
| 77 | } |
| 78 | |
| 79 | virtual void TearDown() { |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 80 | // Destruction order is imposed explicitly here. |
| 81 | personal_data_.reset(NULL); |
| 82 | profile_.reset(NULL); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 83 | |
[email protected] | fabb4ba | 2013-03-20 20:32:05 | [diff] [blame] | 84 | // 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] | a778709f | 2011-12-10 00:28:17 | [diff] [blame] | 90 | MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 91 | MessageLoop::current()->Run(); |
[email protected] | fabb4ba | 2013-03-20 20:32:05 | [diff] [blame] | 92 | db_thread_.Stop(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void ResetPersonalDataManager() { |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 96 | personal_data_.reset(new PersonalDataManager("en-US")); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 97 | personal_data_->Init(profile_.get()); |
[email protected] | 412bde7 | 2013-02-07 06:06:24 | [diff] [blame] | 98 | personal_data_->AddObserver(&personal_data_observer_); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 99 | |
| 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] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 104 | } |
| 105 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 106 | MessageLoopForUI message_loop_; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 107 | content::TestBrowserThread ui_thread_; |
| 108 | content::TestBrowserThread db_thread_; |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 109 | scoped_ptr<TestingProfile> profile_; |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 110 | scoped_ptr<PersonalDataManager> personal_data_; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 111 | content::NotificationRegistrar registrar_; |
[email protected] | b8d4833 | 2012-06-03 21:59:53 | [diff] [blame] | 112 | content::MockNotificationObserver observer_; |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 113 | PersonalDataLoadedObserverMock personal_data_observer_; |
| 114 | }; |
| 115 | |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 116 | TEST_F(PersonalDataManagerTest, AddProfile) { |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 117 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 118 | test::SetProfileInfo(&profile0, |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 119 | "John", "Mitchell", "Smith", |
| 120 | "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
[email protected] | 91b073d | 2013-01-05 01:30:28 | [diff] [blame] | 121 | "94102", "US", "4158889999"); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 122 | |
| 123 | // Add profile0 to the database. |
| 124 | personal_data_->AddProfile(profile0); |
| 125 | |
| 126 | // Reload the database. |
| 127 | ResetPersonalDataManager(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 128 | |
| 129 | // Verify the addition. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 130 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 131 | ASSERT_EQ(1U, results1.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 132 | EXPECT_EQ(0, profile0.Compare(*results1[0])); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 133 | |
| 134 | // Add profile with identical values. Duplicates should not get saved. |
| 135 | AutofillProfile profile0a = profile0; |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 136 | profile0a.set_guid(base::GenerateGUID()); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 137 | personal_data_->AddProfile(profile0a); |
| 138 | |
| 139 | // Reload the database. |
| 140 | ResetPersonalDataManager(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 141 | |
| 142 | // Verify the non-addition. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 143 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 144 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 145 | EXPECT_EQ(0, profile0.Compare(*results2[0])); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 146 | |
| 147 | // New profile with different email. |
| 148 | AutofillProfile profile1 = profile0; |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 149 | profile1.set_guid(base::GenerateGUID()); |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 150 | profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("[email protected]")); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 151 | |
| 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] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 159 | |
| 160 | // Verify the addition. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 161 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 162 | ASSERT_EQ(2U, results3.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 163 | EXPECT_EQ(0, profile0.Compare(*results3[0])); |
| 164 | EXPECT_EQ(0, profile1.Compare(*results3[1])); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 167 | TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 168 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 169 | test::SetProfileInfo(&profile0, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 170 | "Marion", "Mitchell", "Morrison", |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 171 | "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 172 | "91601", "US", "12345678910"); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 173 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 174 | AutofillProfile profile1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 175 | test::SetProfileInfo(&profile1, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 176 | "Josephine", "Alicia", "Saenz", |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 177 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 178 | "US", "19482937549"); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 179 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 180 | AutofillProfile profile2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 181 | test::SetProfileInfo(&profile2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 182 | "Josephine", "Alicia", "Saenz", |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 183 | "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 184 | "32801", "US", "19482937549"); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 185 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 186 | // Add two test profiles to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 187 | 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] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 194 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 195 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 196 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 197 | EXPECT_EQ(0, profile0.Compare(*results1[0])); |
| 198 | EXPECT_EQ(0, profile1.Compare(*results1[1])); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 199 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 200 | // Update, remove, and add. |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 201 | profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 202 | personal_data_->UpdateProfile(profile0); |
[email protected] | 8da04b85 | 2012-11-16 22:10:39 | [diff] [blame] | 203 | personal_data_->RemoveByGUID(profile1.guid()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 204 | 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] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 210 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 211 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 212 | ASSERT_EQ(2U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 213 | EXPECT_EQ(0, profile0.Compare(*results2[0])); |
| 214 | EXPECT_EQ(0, profile2.Compare(*results2[1])); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 215 | |
| 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] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 221 | // Verify that we've loaded the profiles from the web database. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 222 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 223 | ASSERT_EQ(2U, results3.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 224 | EXPECT_EQ(0, profile0.Compare(*results3[0])); |
| 225 | EXPECT_EQ(0, profile2.Compare(*results3[1])); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 226 | } |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 227 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 228 | TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
| 229 | CreditCard credit_card0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 230 | test::SetCreditCardInfo(&credit_card0, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 231 | "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 232 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 233 | CreditCard credit_card1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 234 | test::SetCreditCardInfo(&credit_card1, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 235 | "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 236 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 237 | CreditCard credit_card2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 238 | test::SetCreditCardInfo(&credit_card2, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 239 | "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 240 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 241 | // Add two test credit cards to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 242 | 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] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 249 | |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 250 | const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); |
| 251 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 252 | EXPECT_EQ(0, credit_card0.Compare(*results1[0])); |
| 253 | EXPECT_EQ(0, credit_card1.Compare(*results1[1])); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 254 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 255 | // Update, remove, and add. |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 256 | credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 257 | personal_data_->UpdateCreditCard(credit_card0); |
[email protected] | 8da04b85 | 2012-11-16 22:10:39 | [diff] [blame] | 258 | personal_data_->RemoveByGUID(credit_card1.guid()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 259 | 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] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 265 | |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 266 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 267 | ASSERT_EQ(2U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 268 | EXPECT_EQ(credit_card0, *results2[0]); |
| 269 | EXPECT_EQ(credit_card2, *results2[1]); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 270 | |
| 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] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 276 | // 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] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 279 | EXPECT_EQ(credit_card0, *results3[0]); |
| 280 | EXPECT_EQ(credit_card2, *results3[1]); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 281 | } |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 282 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 283 | TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 284 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 285 | test::SetProfileInfo(&profile0, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 286 | "Marion", "Mitchell", "Morrison", |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 287 | "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 288 | "91601", "US", "12345678910"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 289 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 290 | AutofillProfile profile1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 291 | test::SetProfileInfo(&profile1, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 292 | "Josephine", "Alicia", "Saenz", |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 293 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 294 | "US", "19482937549"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 295 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 296 | CreditCard credit_card0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 297 | test::SetCreditCardInfo(&credit_card0, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 298 | "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 299 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 300 | CreditCard credit_card1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 301 | test::SetCreditCardInfo(&credit_card1, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 302 | "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 303 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 304 | // Add two test profiles to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 305 | 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] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 312 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 313 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 314 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 315 | EXPECT_EQ(0, profile0.Compare(*results1[0])); |
| 316 | EXPECT_EQ(0, profile1.Compare(*results1[1])); |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 317 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 318 | // Add two test credit cards to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 319 | personal_data_->AddCreditCard(credit_card0); |
| 320 | personal_data_->AddCreditCard(credit_card1); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 321 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 322 | // 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] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 326 | |
| 327 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 328 | ASSERT_EQ(2U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 329 | EXPECT_EQ(credit_card0, *results2[0]); |
| 330 | EXPECT_EQ(credit_card1, *results2[1]); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 331 | |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 332 | // 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] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 337 | guids.insert(credit_card0.guid()); |
| 338 | guids.insert(credit_card1.guid()); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 339 | EXPECT_EQ(4U, guids.size()); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 342 | // Test for http://crbug.com/50047. Makes sure that guids are populated |
| 343 | // correctly on load. |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 344 | TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 345 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 346 | test::SetProfileInfo(&profile0, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 347 | "y", "", "", "", "", "", "", "", "", "", "", ""); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 348 | |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 349 | // Add the profile0 to the db. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 350 | personal_data_->AddProfile(profile0); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 351 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 352 | // Verify that the web database has been updated and the notification sent. |
| 353 | EXPECT_CALL(personal_data_observer_, |
| 354 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 355 | MessageLoop::current()->Run(); |
| 356 | |
| 357 | // Verify that we've loaded the profiles from the web database. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 358 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 359 | ASSERT_EQ(1U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 360 | EXPECT_EQ(0, profile0.Compare(*results2[0])); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 361 | |
| 362 | // Add a new profile. |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 363 | AutofillProfile profile1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 364 | test::SetProfileInfo(&profile1, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 365 | "z", "", "", "", "", "", "", "", "", "", "", ""); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 366 | personal_data_->AddProfile(profile1); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 367 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 368 | // 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] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 374 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 375 | ASSERT_EQ(2U, results3.size()); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 376 | EXPECT_NE(results3[0]->guid(), results3[1]->guid()); |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 377 | EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); |
| 378 | EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 381 | TEST_F(PersonalDataManagerTest, SetEmptyProfile) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 382 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 383 | test::SetProfileInfo(&profile0, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 384 | "", "", "", "", "", "", "", "", "", "", "", ""); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 385 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 386 | // Add the empty profile to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 387 | personal_data_->AddProfile(profile0); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 388 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 389 | // Note: no refresh here. |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 390 | |
| 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] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 396 | // Verify that we've loaded the profiles from the web database. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 397 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 398 | ASSERT_EQ(0U, results2.size()); |
| 399 | } |
| 400 | |
| 401 | TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 402 | CreditCard credit_card0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 403 | test::SetCreditCardInfo(&credit_card0, "", "", "", ""); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 404 | |
| 405 | // Add the empty credit card to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 406 | personal_data_->AddCreditCard(credit_card0); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 407 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 408 | // Note: no refresh here. |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 409 | |
| 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] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 415 | // 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] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 420 | TEST_F(PersonalDataManagerTest, Refresh) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 421 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 422 | test::SetProfileInfo(&profile0, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 423 | "Marion", "Mitchell", "Morrison", |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 424 | "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 425 | "91601", "US", "12345678910"); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 426 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 427 | AutofillProfile profile1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 428 | test::SetProfileInfo(&profile1, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 429 | "Josephine", "Alicia", "Saenz", |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 430 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 431 | "US", "19482937549"); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 432 | |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 433 | // Add the test profiles to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 434 | personal_data_->AddProfile(profile0); |
| 435 | personal_data_->AddProfile(profile1); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 436 | |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 437 | // Labels depend on other profiles in the list - update labels manually. |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 438 | std::vector<AutofillProfile *> profile_pointers; |
[email protected] | 9f32144 | 2010-10-25 23:53:53 | [diff] [blame] | 439 | profile_pointers.push_back(&profile0); |
| 440 | profile_pointers.push_back(&profile1); |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 441 | AutofillProfile::AdjustInferredLabels(&profile_pointers); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 442 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 443 | // Verify that the web database has been updated and the notification sent. |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 444 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 445 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 446 | MessageLoop::current()->Run(); |
| 447 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 448 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 449 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 450 | EXPECT_EQ(profile0, *results1[0]); |
| 451 | EXPECT_EQ(profile1, *results1[1]); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 452 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 453 | AutofillProfile profile2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 454 | test::SetProfileInfo(&profile2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 455 | "Josephine", "Alicia", "Saenz", |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 456 | "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 457 | "32801", "US", "19482937549"); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 458 | |
[email protected] | 9f32144 | 2010-10-25 23:53:53 | [diff] [blame] | 459 | // Adjust all labels. |
[email protected] | 61f25cd0e | 2010-11-07 05:23:50 | [diff] [blame] | 460 | profile_pointers.push_back(&profile2); |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 461 | AutofillProfile::AdjustInferredLabels(&profile_pointers); |
[email protected] | 9f32144 | 2010-10-25 23:53:53 | [diff] [blame] | 462 | |
[email protected] | e2b3105 | 2013-03-25 01:49:37 | [diff] [blame] | 463 | scoped_refptr<AutofillWebDataService> wds = |
| 464 | AutofillWebDataService::FromBrowserContext(profile_.get()); |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 465 | ASSERT_TRUE(wds.get()); |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 466 | wds->AddAutofillProfile(profile2); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 467 | |
| 468 | personal_data_->Refresh(); |
| 469 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 470 | // Verify that the web database has been updated and the notification sent. |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 471 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 472 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 473 | MessageLoop::current()->Run(); |
| 474 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 475 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 476 | ASSERT_EQ(3U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 477 | EXPECT_EQ(profile0, *results2[0]); |
| 478 | EXPECT_EQ(profile1, *results2[1]); |
| 479 | EXPECT_EQ(profile2, *results2[2]); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 480 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 481 | wds->RemoveAutofillProfile(profile1.guid()); |
| 482 | wds->RemoveAutofillProfile(profile2.guid()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 483 | |
| 484 | // Before telling the PDM to refresh, simulate an edit to one of the profiles |
[email protected] | 663bd9e | 2011-03-21 01:07:01 | [diff] [blame] | 485 | // via a SetProfile update (this would happen if the Autofill window was |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 486 | // 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] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 489 | profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 490 | personal_data_->UpdateProfile(profile0); |
| 491 | personal_data_->AddProfile(profile1); |
| 492 | personal_data_->AddProfile(profile2); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 493 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 494 | // Verify that the web database has been updated and the notification sent. |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 495 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 496 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 497 | MessageLoop::current()->Run(); |
| 498 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 499 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 500 | ASSERT_EQ(1U, results3.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 501 | EXPECT_EQ(profile0, *results2[0]); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 502 | } |
[email protected] | 83723f0 | 2010-04-07 17:33:10 | [diff] [blame] | 503 | |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 504 | TEST_F(PersonalDataManagerTest, ImportFormData) { |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 505 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 506 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 507 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 508 | "First name:", "first_name", "George", "text", &field); |
| 509 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 510 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 511 | "Last name:", "last_name", "Washington", "text", &field); |
| 512 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 513 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 514 | "Email:", "email", "[email protected]", "text", &field); |
| 515 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 516 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 517 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 518 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 519 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 520 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 521 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 522 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 523 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 524 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 525 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 526 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 527 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 528 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 529 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 530 | ASSERT_FALSE(imported_credit_card); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 531 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 532 | // Verify that the web database has been updated and the notification sent. |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 533 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 534 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 535 | MessageLoop::current()->Run(); |
| 536 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 537 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 538 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 539 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 540 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 541 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 542 | ASSERT_EQ(1U, results.size()); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 543 | EXPECT_EQ(0, expected.Compare(*results[0])); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 544 | } |
| 545 | |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 546 | TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) { |
| 547 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 548 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 549 | test::CreateTestFormField( |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 550 | "First name:", "first_name", "George", "text", &field); |
| 551 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 552 | test::CreateTestFormField( |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 553 | "Last name:", "last_name", "Washington", "text", &field); |
| 554 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 555 | test::CreateTestFormField("Email:", "email", "bogus", "text", &field); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 556 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 557 | test::CreateTestFormField( |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 558 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 559 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 560 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 561 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 562 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 563 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 564 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 565 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 566 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 567 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 568 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 569 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure, |
| 570 | &imported_credit_card)); |
[email protected] | ca9bdeb | 2011-03-17 20:01:41 | [diff] [blame] | 571 | ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 572 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 573 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
[email protected] | ca9bdeb | 2011-03-17 20:01:41 | [diff] [blame] | 574 | ASSERT_EQ(0U, results.size()); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 575 | } |
| 576 | |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 577 | // Tests that a 'confirm email' field does not block profile import. |
| 578 | TEST_F(PersonalDataManagerTest, ImportFormDataTwoEmails) { |
| 579 | FormData form; |
| 580 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 581 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 582 | "Name:", "name", "George Washington", "text", &field); |
| 583 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 584 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 585 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 586 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 587 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 588 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 589 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 590 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 591 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 592 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 593 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 594 | "Email:", "email", "[email protected]", "text", &field); |
| 595 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 596 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 597 | "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. |
| 609 | TEST_F(PersonalDataManagerTest, ImportFormDataTwoDifferentEmails) { |
| 610 | FormData form; |
| 611 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 612 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 613 | "Name:", "name", "George Washington", "text", &field); |
| 614 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 615 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 616 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 617 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 618 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 619 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 620 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 621 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 622 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 623 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 624 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 625 | "Email:", "email", "[email protected]", "text", &field); |
| 626 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 627 | test::CreateTestFormField( |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 628 | "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] | 20477755 | 2011-01-26 19:46:28 | [diff] [blame] | 639 | TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) { |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 640 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 641 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 642 | test::CreateTestFormField( |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 643 | "First name:", "first_name", "George", "text", &field); |
| 644 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 645 | test::CreateTestFormField( |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 646 | "Last name:", "last_name", "Washington", "text", &field); |
| 647 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 648 | test::CreateTestFormField( |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 649 | "Card number:", "card_number", "4111 1111 1111 1111", "text", &field); |
| 650 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 651 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 652 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 653 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 654 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure, |
| 655 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 656 | ASSERT_FALSE(imported_credit_card); |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 657 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 658 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 659 | 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] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 664 | TEST_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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 669 | test::CreateTestFormField("Name:", "name", "Barack Obama", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 670 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 671 | test::CreateTestFormField( |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 672 | "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); |
| 673 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 674 | test::CreateTestFormField("City:", "city", "Washington", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 675 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 676 | test::CreateTestFormField("State:", "state", "DC", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 677 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 678 | test::CreateTestFormField("Zip:", "zip", "20500", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 679 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 680 | test::CreateTestFormField("Country:", "country", "USA", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 681 | 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 | |
| 691 | TEST_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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 696 | test::CreateTestFormField("Name:", "name", "David Cameron", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 697 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 698 | test::CreateTestFormField( |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 699 | "Address:", "address", "10 Downing Street", "text", &field); |
| 700 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 701 | test::CreateTestFormField("City:", "city", "London", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 702 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 703 | test::CreateTestFormField( |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 704 | "Postcode:", "postcode", "SW1A 2AA", "text", &field); |
| 705 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 706 | test::CreateTestFormField( |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 707 | "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 | |
| 718 | TEST_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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 723 | test::CreateTestFormField( |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 724 | "Name:", "name", "Sir Adrian Johns", "text", &field); |
| 725 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 726 | test::CreateTestFormField( |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 727 | "Address:", "address", "The Convent, Main Street", "text", &field); |
| 728 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 729 | test::CreateTestFormField("Country:", "country", "Gibraltar", "text", &field); |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 730 | 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] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 740 | TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) { |
| 741 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 742 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 743 | test::CreateTestFormField( |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 744 | "First name:", "first_name", "George", "text", &field); |
| 745 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 746 | test::CreateTestFormField( |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 747 | "Last name:", "last_name", "Washington", "text", &field); |
| 748 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 749 | test::CreateTestFormField( |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 750 | "Phone #:", "home_phone_area_code", "650", "text", &field); |
[email protected] | e2aaa81 | 2011-03-08 18:46:04 | [diff] [blame] | 751 | field.max_length = 3; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 752 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 753 | test::CreateTestFormField( |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 754 | "Phone #:", "home_phone_prefix", "555", "text", &field); |
[email protected] | e2aaa81 | 2011-03-08 18:46:04 | [diff] [blame] | 755 | field.max_length = 3; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 756 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 757 | test::CreateTestFormField( |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 758 | "Phone #:", "home_phone_suffix", "0000", "text", &field); |
[email protected] | e2aaa81 | 2011-03-08 18:46:04 | [diff] [blame] | 759 | field.max_length = 4; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 760 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 761 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 762 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 763 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 764 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 765 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 766 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 767 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 768 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 769 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 770 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 771 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 772 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 773 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 774 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 775 | ASSERT_FALSE(imported_credit_card); |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 776 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 777 | // Verify that the web database has been updated and the notification sent. |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 778 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 779 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 780 | MessageLoop::current()->Run(); |
| 781 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 782 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 783 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 784 | "Washington", NULL, NULL, "21 Laussat St", NULL, |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 785 | "San Francisco", "California", "94102", NULL, "(650) 555-0000"); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 786 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 787 | ASSERT_EQ(1U, results.size()); |
| 788 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 789 | } |
| 790 | |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 791 | TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 792 | CreditCard credit_card0; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 793 | credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 794 | CreditCard credit_card1; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 795 | credit_card1.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 796 | CreditCard credit_card2; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 797 | credit_card2.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 798 | CreditCard credit_card3; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 799 | credit_card3.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 800 | CreditCard credit_card4; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 801 | credit_card4.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 802 | CreditCard credit_card5; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 803 | credit_card5.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio")); |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 804 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 805 | // Add the test credit cards to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 806 | 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] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 812 | |
[email protected] | 18f92d4f | 2010-10-19 00:14:58 | [diff] [blame] | 813 | // 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] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 818 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 819 | ASSERT_EQ(6U, results.size()); |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 820 | 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] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 826 | } |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 827 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 828 | TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) { |
| 829 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 830 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 831 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 832 | "First name:", "first_name", "George", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 833 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 834 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 835 | "Last name:", "last_name", "Washington", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 836 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 837 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 838 | "Email:", "email", "[email protected]", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 839 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 840 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 841 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 842 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 843 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 844 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 845 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 846 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 847 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 848 | form1.fields.push_back(field); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 849 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 850 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 851 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 852 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 853 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 854 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 855 | ASSERT_FALSE(imported_credit_card); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 856 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 857 | // Verify that the web database has been updated and the notification sent. |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 858 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 859 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 860 | MessageLoop::current()->Run(); |
| 861 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 862 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 863 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 864 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 865 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 866 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 867 | ASSERT_EQ(1U, results1.size()); |
| 868 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 869 | |
| 870 | // Now create a completely different profile. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 871 | FormData form2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 872 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 873 | "First name:", "first_name", "John", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 874 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 875 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 876 | "Last name:", "last_name", "Adams", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 877 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 878 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 879 | "Email:", "email", "[email protected]", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 880 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 881 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 882 | "Address:", "address1", "22 Laussat St", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 883 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 884 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 885 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 886 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 887 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 888 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 889 | form2.fields.push_back(field); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 890 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 891 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 892 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 893 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 894 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 895 | ASSERT_FALSE(imported_credit_card); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 896 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 897 | // Verify that the web database has been updated and the notification sent. |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 898 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 899 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 900 | MessageLoop::current()->Run(); |
| 901 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 902 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 903 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 904 | AutofillProfile expected2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 905 | test::SetProfileInfo(&expected2, "John", NULL, |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 906 | "Adams", "[email protected]", NULL, "22 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 907 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 908 | ASSERT_EQ(2U, results2.size()); |
| 909 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 910 | EXPECT_EQ(0, expected2.Compare(*results2[1])); |
| 911 | } |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 912 | |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 913 | TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) { |
| 914 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 915 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 916 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 917 | "First name:", "first_name", "George", "text", &field); |
| 918 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 919 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 920 | "Last name:", "last_name", "Washington", "text", &field); |
| 921 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 922 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 923 | "Email:", "email", "[email protected]", "text", &field); |
| 924 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 925 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 926 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 927 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 928 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 929 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 930 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 931 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 932 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 933 | form1.fields.push_back(field); |
| 934 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 935 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 936 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 937 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 938 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 939 | &imported_credit_card)); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 940 | ASSERT_FALSE(imported_credit_card); |
| 941 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 942 | // Verify that the web database has been updated and the notification sent. |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 943 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 944 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 945 | MessageLoop::current()->Run(); |
| 946 | |
| 947 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 948 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 949 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 950 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 951 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 952 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 957 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 958 | "First name:", "first_name", "John", "text", &field); |
| 959 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 960 | test::CreateTestFormField("Last name:", "last_name", "Adams", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 961 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 962 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 963 | "Email:", "email", "[email protected]", "text", &field); |
| 964 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 965 | test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 966 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 967 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 968 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 969 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 970 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 971 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 972 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 973 | form2.fields.push_back(field); |
| 974 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 975 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 976 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 977 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 978 | &imported_credit_card)); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 979 | ASSERT_FALSE(imported_credit_card); |
| 980 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 981 | // Verify that the web database has been updated and the notification sent. |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 982 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 983 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 984 | MessageLoop::current()->Run(); |
| 985 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 986 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 987 | |
| 988 | // Modify expected to include multi-valued fields. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 989 | std::vector<base::string16> values; |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 990 | expected.GetRawMultiInfo(NAME_FULL, &values); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 991 | values.push_back(ASCIIToUTF16("John Adams")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 992 | expected.SetRawMultiInfo(NAME_FULL, values); |
| 993 | expected.GetRawMultiInfo(EMAIL_ADDRESS, &values); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 994 | values.push_back(ASCIIToUTF16("[email protected]")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 995 | expected.SetRawMultiInfo(EMAIL_ADDRESS, values); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 996 | |
| 997 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 998 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 999 | } |
| 1000 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1001 | TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) { |
| 1002 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1003 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1004 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1005 | "First name:", "first_name", "George", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1006 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1007 | test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1008 | "Last name:", "last_name", "Washington", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1009 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1010 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1011 | "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); |
| 1012 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1013 | test::CreateTestFormField( |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1014 | "Address Line 2:", "address2", "Suite A", "text", &field); |
| 1015 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1016 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1017 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1018 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1019 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1020 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1021 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1022 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1023 | "Email:", "email", "[email protected]", "text", &field); |
| 1024 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1025 | test::CreateTestFormField("Phone:", "phone", "6505556666", "text", &field); |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1026 | form1.fields.push_back(field); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1027 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1028 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1029 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1030 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1031 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1032 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1033 | ASSERT_FALSE(imported_credit_card); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1034 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1035 | // Verify that the web database has been updated and the notification sent. |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1036 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1037 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1038 | MessageLoop::current()->Run(); |
| 1039 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1040 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1041 | test::SetProfileInfo( |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 1042 | &expected, "George", NULL, "Washington", "[email protected]", NULL, |
| 1043 | "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California", |
| 1044 | "94102", NULL, "(650) 555-6666"); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1045 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1046 | ASSERT_EQ(1U, results1.size()); |
| 1047 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1048 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1049 | // Now create an updated profile. |
| 1050 | FormData form2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1051 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1052 | "First name:", "first_name", "George", "text", &field); |
| 1053 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1054 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1055 | "Last name:", "last_name", "Washington", "text", &field); |
| 1056 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1057 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1058 | "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); |
| 1059 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1060 | test::CreateTestFormField( |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1061 | "Address Line 2:", "address2", "Suite A", "text", &field); |
| 1062 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1063 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1064 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1065 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1066 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1067 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1068 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1069 | test::CreateTestFormField( |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1070 | "Email:", "email", "[email protected]", "text", &field); |
| 1071 | form2.fields.push_back(field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1072 | // Country gets added. |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1073 | test::CreateTestFormField("Country:", "country", "USA", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1074 | form2.fields.push_back(field); |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1075 | // Phone gets updated. |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1076 | test::CreateTestFormField("Phone:", "phone", "6502231234", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1077 | form2.fields.push_back(field); |
| 1078 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1079 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1080 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1081 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1082 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1083 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1084 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1085 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1086 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1087 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1088 | MessageLoop::current()->Run(); |
| 1089 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1090 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1091 | |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1092 | // Add multi-valued phone number to expectation. Also, country gets added. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 1093 | std::vector<base::string16> values; |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1094 | expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 1095 | values.push_back(ASCIIToUTF16("(650) 223-1234")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1096 | expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
[email protected] | 91b073d | 2013-01-05 01:30:28 | [diff] [blame] | 1097 | expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1098 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 1099 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) { |
| 1103 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1104 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1105 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1106 | "First name:", "first_name", "George", "text", &field); |
| 1107 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1108 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1109 | "Last name:", "last_name", "Washington", "text", &field); |
| 1110 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1111 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1112 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1113 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1114 | test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1115 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1116 | test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1117 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1118 | test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1119 | form1.fields.push_back(field); |
| 1120 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1121 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1122 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1123 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1124 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1125 | &imported_credit_card)); |
[email protected] | a73830e | 2011-10-05 01:12:58 | [diff] [blame] | 1126 | EXPECT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1127 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1128 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1129 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1130 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1131 | MessageLoop::current()->Run(); |
| 1132 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1133 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1134 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1135 | "Washington", NULL, NULL, "190 High Street", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1136 | "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1137 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1138 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1143 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1144 | "First name:", "first_name", "George", "text", &field); |
| 1145 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1146 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1147 | "Last name:", "last_name", "Washington", "text", &field); |
| 1148 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1149 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1150 | "Email:", "email", "[email protected]", "text", &field); |
| 1151 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1152 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1153 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1154 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1155 | test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1156 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1157 | test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1158 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1159 | test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1160 | form2.fields.push_back(field); |
| 1161 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1162 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1163 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1164 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1165 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1166 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1167 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1168 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1169 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1170 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1171 | MessageLoop::current()->Run(); |
| 1172 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1173 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1174 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1175 | AutofillProfile expected2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1176 | test::SetProfileInfo(&expected2, "George", NULL, |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1177 | "Washington", "[email protected]", NULL, "190 High Street", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1178 | "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1179 | ASSERT_EQ(1U, results2.size()); |
| 1180 | EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1181 | } |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1182 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1183 | TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) { |
| 1184 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1185 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1186 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1187 | "First name:", "first_name", "George", "text", &field); |
| 1188 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1189 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1190 | "Last name:", "last_name", "Washington", "text", &field); |
| 1191 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1192 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1193 | "Company:", "company", "Government", "text", &field); |
| 1194 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1195 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1196 | "Email:", "email", "[email protected]", "text", &field); |
| 1197 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1198 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1199 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1200 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1201 | test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1202 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1203 | test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1204 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1205 | test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1206 | form1.fields.push_back(field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1207 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1208 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1209 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1210 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1211 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1212 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1213 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1214 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1215 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1216 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1217 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1218 | MessageLoop::current()->Run(); |
| 1219 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1220 | AutofillProfile expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1221 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1222 | "Washington", "[email protected]", "Government", "190 High Street", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1223 | "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1224 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1225 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1230 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1231 | "First name:", "first_name", "George", "text", &field); |
| 1232 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1233 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1234 | "Last name:", "last_name", "Washington", "text", &field); |
| 1235 | form2.fields.push_back(field); |
| 1236 | // Note missing Company field. |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1237 | test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1238 | "Email:", "email", "[email protected]", "text", &field); |
| 1239 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1240 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1241 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1242 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1243 | test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1244 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1245 | test::CreateTestFormField("State:", "state", "Pennsylvania", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1246 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1247 | test::CreateTestFormField("Zip:", "zipcode", "19106", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1248 | form2.fields.push_back(field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1249 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1250 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1251 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1252 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1253 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1254 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1255 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1256 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1257 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1258 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1259 | MessageLoop::current()->Run(); |
| 1260 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1261 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1262 | |
| 1263 | // Expect no change. |
| 1264 | ASSERT_EQ(1U, results2.size()); |
| 1265 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1266 | } |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1267 | |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1268 | TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) { |
| 1269 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1270 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1271 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1272 | "First name:", "first_name", "George", "text", &field); |
| 1273 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1274 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1275 | "Last name:", "last_name", "Washington", "text", &field); |
| 1276 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1277 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1278 | "Company:", "company", "Government", "text", &field); |
| 1279 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1280 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1281 | "Email:", "email", "[email protected]", "text", &field); |
| 1282 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1283 | test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1284 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1285 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1286 | test::CreateTestFormField("City:", "city", "Philadelphia", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1287 | form1.fields.push_back(field); |
| 1288 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1289 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1290 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1291 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1292 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, |
| 1293 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1294 | ASSERT_FALSE(imported_credit_card); |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 1295 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1296 | // Note: no refresh here. |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 1297 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1298 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 1299 | 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] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1302 | } |
| 1303 | |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1304 | TEST_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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1308 | test::SetProfileInfo(auxiliary_profile, |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1309 | "Tester", "Frederick", "McAddressBookTesterson", |
| 1310 | "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", |
[email protected] | 91b073d | 2013-01-05 01:30:28 | [diff] [blame] | 1311 | "CA", "94102", "US", "1.415.888.9999"); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1312 | 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] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1319 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1320 | test::CreateTestFormField( |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1321 | "First name:", "first_name", "Tester", "text", &field); |
| 1322 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1323 | test::CreateTestFormField( |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1324 | "Last name:", "last_name", "McAddressBookTesterson", "text", &field); |
| 1325 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1326 | test::CreateTestFormField( |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1327 | "Email:", "email", "[email protected]", "text", &field); |
| 1328 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1329 | test::CreateTestFormField("Address:", "address1", "1 Main", "text", &field); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1330 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1331 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1332 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1333 | test::CreateTestFormField("State:", "state", "CA", "text", &field); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1334 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1335 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1336 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1337 | test::CreateTestFormField("Phone:", "phone", "4158889999", "text", &field); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1338 | form.fields.push_back(field); |
| 1339 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1340 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1341 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1342 | 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] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1357 | TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) { |
| 1358 | FormData form1; |
| 1359 | |
| 1360 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1361 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1362 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1363 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1364 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1365 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1366 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1367 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1368 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1369 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1370 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1371 | form1.fields.push_back(field); |
| 1372 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1373 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1374 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1375 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1376 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1377 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1378 | ASSERT_TRUE(imported_credit_card); |
| 1379 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1380 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1381 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1382 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1383 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1384 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1385 | MessageLoop::current()->Run(); |
| 1386 | |
| 1387 | CreditCard expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1388 | test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1389 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1390 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1396 | test::CreateTestFormField( |
[email protected] | 490a6a50 | 2011-09-27 17:30:11 | [diff] [blame] | 1397 | "Name on card:", "name_on_card", "", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1398 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1399 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1400 | "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field); |
| 1401 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1402 | test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1403 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1404 | test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1405 | form2.fields.push_back(field); |
| 1406 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1407 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1408 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1409 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1410 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1411 | ASSERT_TRUE(imported_credit_card); |
| 1412 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1413 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1414 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1415 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1416 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1417 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1418 | MessageLoop::current()->Run(); |
| 1419 | |
| 1420 | CreditCard expected2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1421 | test::SetCreditCardInfo(&expected2,"", "5500000000000004", "02", "2012"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1422 | 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 | |
| 1428 | TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) { |
| 1429 | FormData form1; |
| 1430 | |
| 1431 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1432 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1433 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1434 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1435 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1436 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1437 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1438 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1439 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1440 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1441 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1442 | form1.fields.push_back(field); |
| 1443 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1444 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1445 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1446 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1447 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1448 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1449 | ASSERT_TRUE(imported_credit_card); |
| 1450 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1451 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1452 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1453 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1454 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1455 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1456 | MessageLoop::current()->Run(); |
| 1457 | |
| 1458 | CreditCard expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1459 | test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1460 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1461 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1467 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1468 | "Name on card:", "name_on_card", "Jim Johansen", "text", &field); |
| 1469 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1470 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1471 | "Card Number:", "card_number", "1000000000000000", "text", &field); |
| 1472 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1473 | test::CreateTestFormField("Exp Month:", "exp_month", "02", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1474 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1475 | test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1476 | form2.fields.push_back(field); |
| 1477 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1478 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1479 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1480 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
| 1481 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1482 | ASSERT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1483 | |
| 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 | |
| 1491 | TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { |
| 1492 | FormData form1; |
| 1493 | |
| 1494 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1495 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1496 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1497 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1498 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1499 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1500 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1501 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1502 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1503 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1504 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1505 | form1.fields.push_back(field); |
| 1506 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1507 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1508 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1509 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1510 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1511 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1512 | ASSERT_TRUE(imported_credit_card); |
| 1513 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1514 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1515 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1516 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1517 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1518 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1519 | MessageLoop::current()->Run(); |
| 1520 | |
| 1521 | CreditCard expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1522 | test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1523 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1524 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1531 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1532 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1533 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1534 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1535 | "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field); |
| 1536 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1537 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1538 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1539 | test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1540 | form2.fields.push_back(field); |
| 1541 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1542 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1543 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1544 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1545 | &imported_credit_card)); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1546 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1547 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1548 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1549 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1550 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1551 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1556 | test::SetCreditCardInfo(&expected2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1557 | "Biggie Smalls", "4111111111111111", "01", "2012"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1558 | 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 | |
| 1563 | TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) { |
| 1564 | FormData form1; |
| 1565 | |
| 1566 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1567 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1568 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1569 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1570 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1571 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1572 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1573 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1574 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1575 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1576 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1577 | form1.fields.push_back(field); |
| 1578 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1579 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1580 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1581 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1582 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1583 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1584 | ASSERT_TRUE(imported_credit_card); |
| 1585 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1586 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1587 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1588 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1589 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1590 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1591 | MessageLoop::current()->Run(); |
| 1592 | |
| 1593 | CreditCard expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1594 | test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1595 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1596 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1602 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1603 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1604 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1605 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1606 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1607 | test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1608 | form2.fields.push_back(field); |
| 1609 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1610 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1611 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1612 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
| 1613 | &imported_credit_card)); |
[email protected] | 3e6e82da | 2011-04-06 05:41:34 | [diff] [blame] | 1614 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1615 | |
| 1616 | // Note: no refresh here. |
| 1617 | |
| 1618 | // No change is expected. |
| 1619 | CreditCard expected2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1620 | test::SetCreditCardInfo(&expected2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1621 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1622 | 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 | |
| 1627 | TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) { |
| 1628 | FormData form1; |
| 1629 | |
| 1630 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1631 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1632 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1633 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1634 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1635 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1636 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1637 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1638 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1639 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1640 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1641 | form1.fields.push_back(field); |
| 1642 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1643 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1644 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1645 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1646 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1647 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1648 | ASSERT_TRUE(imported_credit_card); |
| 1649 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1650 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1651 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1652 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1653 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1654 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1655 | MessageLoop::current()->Run(); |
| 1656 | |
| 1657 | CreditCard expected; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1658 | test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1659 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1660 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1668 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1669 | "Card Number:", "card_number", "4111111111111111", "text", &field); |
| 1670 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1671 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1672 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1673 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1674 | form2.fields.push_back(field); |
| 1675 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1676 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1677 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1678 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1679 | &imported_credit_card)); |
| 1680 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1681 | |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1682 | // 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] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1686 | |
| 1687 | // No change is expected. |
| 1688 | CreditCard expected2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1689 | test::SetCreditCardInfo(&expected2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1690 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1691 | 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] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1694 | |
| 1695 | // Add a third credit card where the expiration date is missing. |
| 1696 | FormData form3; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1697 | test::CreateTestFormField( |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1698 | "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); |
| 1699 | form3.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1700 | test::CreateTestFormField( |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1701 | "Card Number:", "card_number", "5555555555554444", "text", &field); |
| 1702 | form3.fields.push_back(field); |
| 1703 | // Note missing expiration month and year.. |
| 1704 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1705 | FormStructure form_structure3(form3, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1706 | form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1707 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1715 | test::SetCreditCardInfo(&expected3, |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1716 | "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] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1723 | // Start with a single valid credit card stored via the preferences. |
| 1724 | // Note the empty name. |
| 1725 | CreditCard saved_credit_card; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1726 | test::SetCreditCardInfo(&saved_credit_card, |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1727 | "", "4111111111111111" /* Visa */, "01", "2011"); |
| 1728 | personal_data_->AddCreditCard(saved_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1729 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1730 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1731 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1732 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1733 | MessageLoop::current()->Run(); |
| 1734 | |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1735 | 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] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1739 | |
| 1740 | // Add a second different valid credit card where the year is different but |
| 1741 | // the credit card number matches. |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1742 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1743 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1744 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1745 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1746 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1747 | test::CreateTestFormField( |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1748 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1749 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1750 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1751 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1752 | test::CreateTestFormField("Exp Year:", "exp_year", "2012", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1753 | form.fields.push_back(field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1754 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1755 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1756 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1757 | const CreditCard* imported_credit_card; |
| 1758 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1759 | &imported_credit_card)); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1760 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1761 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1762 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1763 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1764 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1765 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1770 | test::SetCreditCardInfo(&expected2, |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1771 | "Biggie Smalls", "4111111111111111", "01", "2012"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1772 | 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1776 | |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1777 | // 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. |
| 1779 | TEST_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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1783 | test::SetCreditCardInfo(&saved_credit_card, |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1784 | "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] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1798 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1799 | test::CreateTestFormField( |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1800 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1801 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1802 | test::CreateTestFormField( |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1803 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1804 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1805 | test::CreateTestFormField("Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1806 | form.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1807 | test::CreateTestFormField("Exp Year:", "exp_year", "2011", "text", &field); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1808 | form.fields.push_back(field); |
| 1809 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1810 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1811 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1812 | 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] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1828 | TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1829 | // Check that there are no available types with no profiles stored. |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1830 | FieldTypeSet non_empty_types; |
| 1831 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
| 1832 | EXPECT_EQ(0U, non_empty_types.size()); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1833 | |
| 1834 | // Test with one profile stored. |
| 1835 | AutofillProfile profile0; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1836 | test::SetProfileInfo(&profile0, |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1837 | "Marion", NULL, "Morrison", |
| 1838 | "[email protected]", NULL, "123 Zoo St.", NULL, "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1839 | "91601", "US", "14155678910"); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1840 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1841 | 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1847 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1848 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 1849 | EXPECT_EQ(14U, non_empty_types.size()); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1850 | 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] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 1860 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1861 | 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1864 | |
| 1865 | // Test with multiple profiles stored. |
| 1866 | AutofillProfile profile1; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1867 | test::SetProfileInfo(&profile1, |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1868 | "Josephine", "Alicia", "Saenz", |
| 1869 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1870 | "US", "16502937549"); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1871 | |
| 1872 | AutofillProfile profile2; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1873 | test::SetProfileInfo(&profile2, |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1874 | "Josephine", "Alicia", "Saenz", |
| 1875 | "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1876 | "32801", "US", "16502937549"); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1877 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1878 | 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1885 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1886 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1887 | EXPECT_EQ(18U, non_empty_types.size()); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1888 | 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1906 | |
| 1907 | // Test with credit card information also stored. |
| 1908 | CreditCard credit_card; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1909 | test::SetCreditCardInfo(&credit_card, |
| 1910 | "John Dillinger", "423456789012" /* Visa */, |
| 1911 | "01", "2010"); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1912 | personal_data_->AddCreditCard(credit_card); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1913 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1914 | // 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1918 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1919 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1920 | EXPECT_EQ(25U, non_empty_types.size()); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1921 | 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] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1939 | 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] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1946 | } |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1947 | |
| 1948 | TEST_F(PersonalDataManagerTest, CaseInsensitiveMultiValueAggregation) { |
| 1949 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1950 | FormFieldData field; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1951 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1952 | "First name:", "first_name", "George", "text", &field); |
| 1953 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1954 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1955 | "Last name:", "last_name", "Washington", "text", &field); |
| 1956 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1957 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1958 | "Email:", "email", "[email protected]", "text", &field); |
| 1959 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1960 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1961 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 1962 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1963 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1964 | "City:", "city", "San Francisco", "text", &field); |
| 1965 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1966 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1967 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1968 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1969 | "Zip:", "zip", "94102", "text", &field); |
| 1970 | form1.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1971 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1972 | "Phone number:", "phone_number", "817-555-6789", "text", &field); |
| 1973 | form1.fields.push_back(field); |
| 1974 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1975 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1976 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1977 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1988 | test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1989 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 1990 | "San Francisco", "California", "94102", NULL, "(817) 555-6789"); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1991 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1992 | 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] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 1997 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 1998 | "First name:", "first_name", "GEORGE", "text", &field); |
| 1999 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2000 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2001 | "Last name:", "last_name", "Washington", "text", &field); |
| 2002 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2003 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2004 | "Email:", "email", "[email protected]", "text", &field); |
| 2005 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2006 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2007 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 2008 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2009 | test::CreateTestFormField("City:", "city", "San Francisco", "text", &field); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2010 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2011 | test::CreateTestFormField("State:", "state", "California", "text", &field); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2012 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2013 | test::CreateTestFormField("Zip:", "zip", "94102", "text", &field); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2014 | form2.fields.push_back(field); |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2015 | test::CreateTestFormField( |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2016 | "Phone number:", "phone_number", "214-555-1234", "text", &field); |
| 2017 | form2.fields.push_back(field); |
| 2018 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 2019 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 2020 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2021 | 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] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 2030 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2031 | |
| 2032 | // Modify expected to include multi-valued fields. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 2033 | std::vector<base::string16> values; |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 2034 | expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 2035 | values.push_back(ASCIIToUTF16("(214) 555-1234")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 2036 | expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2037 | |
| 2038 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 2039 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2040 | } |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 2041 | |
| 2042 | } // namespace autofill |