[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] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 35 | namespace { |
| 36 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 37 | ACTION(QuitUIMessageLoop) { |
[email protected] | faec631 | 2010-10-05 03:35:34 | [diff] [blame] | 38 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 39 | MessageLoop::current()->Quit(); |
| 40 | } |
| 41 | |
[email protected] | a7e585a | 2011-08-08 20:32:54 | [diff] [blame] | 42 | class PersonalDataLoadedObserverMock : public PersonalDataManagerObserver { |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 43 | public: |
| 44 | PersonalDataLoadedObserverMock() {} |
| 45 | virtual ~PersonalDataLoadedObserverMock() {} |
| 46 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 47 | MOCK_METHOD0(OnPersonalDataChanged, void()); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 48 | }; |
| 49 | |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 50 | // Unlike the base AutofillMetrics, exposes copy and assignment constructors, |
| 51 | // which are handy for briefer test code. The AutofillMetrics class is |
| 52 | // stateless, so this is safe. |
| 53 | class TestAutofillMetrics : public AutofillMetrics { |
| 54 | public: |
| 55 | TestAutofillMetrics() {} |
| 56 | virtual ~TestAutofillMetrics() {} |
| 57 | }; |
| 58 | |
| 59 | } // anonymous namespace |
| 60 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 61 | class PersonalDataManagerTest : public testing::Test { |
| 62 | protected: |
| 63 | PersonalDataManagerTest() |
[email protected] | faec631 | 2010-10-05 03:35:34 | [diff] [blame] | 64 | : ui_thread_(BrowserThread::UI, &message_loop_), |
| 65 | db_thread_(BrowserThread::DB) { |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | virtual void SetUp() { |
| 69 | db_thread_.Start(); |
| 70 | |
| 71 | profile_.reset(new TestingProfile); |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 72 | profile_->CreateWebDataService(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 73 | |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 74 | autofill_test::DisableSystemServices(profile_.get()); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 75 | ResetPersonalDataManager(); |
| 76 | } |
| 77 | |
| 78 | virtual void TearDown() { |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 79 | // Destruction order is imposed explicitly here. |
| 80 | personal_data_.reset(NULL); |
| 81 | profile_.reset(NULL); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 82 | |
[email protected] | fabb4ba | 2013-03-20 20:32:05 | [diff] [blame] | 83 | // Schedule another task on the DB thread to notify us that it's safe to |
| 84 | // stop the thread. |
| 85 | base::WaitableEvent done(false, false); |
| 86 | BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 87 | base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
| 88 | done.Wait(); |
[email protected] | a778709f | 2011-12-10 00:28:17 | [diff] [blame] | 89 | MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 90 | MessageLoop::current()->Run(); |
[email protected] | fabb4ba | 2013-03-20 20:32:05 | [diff] [blame] | 91 | db_thread_.Stop(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void ResetPersonalDataManager() { |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 95 | personal_data_.reset(new PersonalDataManager("en-US")); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 96 | personal_data_->Init(profile_.get()); |
[email protected] | 412bde7 | 2013-02-07 06:06:24 | [diff] [blame] | 97 | personal_data_->AddObserver(&personal_data_observer_); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 98 | |
| 99 | // Verify that the web database has been updated and the notification sent. |
| 100 | EXPECT_CALL(personal_data_observer_, |
| 101 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 102 | MessageLoop::current()->Run(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 105 | MessageLoopForUI message_loop_; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 106 | content::TestBrowserThread ui_thread_; |
| 107 | content::TestBrowserThread db_thread_; |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 108 | scoped_ptr<TestingProfile> profile_; |
[email protected] | ea9edcb0 | 2011-09-23 22:05:04 | [diff] [blame] | 109 | scoped_ptr<PersonalDataManager> personal_data_; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 110 | content::NotificationRegistrar registrar_; |
[email protected] | b8d4833 | 2012-06-03 21:59:53 | [diff] [blame] | 111 | content::MockNotificationObserver observer_; |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 112 | PersonalDataLoadedObserverMock personal_data_observer_; |
| 113 | }; |
| 114 | |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 115 | TEST_F(PersonalDataManagerTest, AddProfile) { |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 116 | AutofillProfile profile0; |
| 117 | autofill_test::SetProfileInfo(&profile0, |
| 118 | "John", "Mitchell", "Smith", |
| 119 | "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
[email protected] | 91b073d | 2013-01-05 01:30:28 | [diff] [blame] | 120 | "94102", "US", "4158889999"); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 121 | |
| 122 | // Add profile0 to the database. |
| 123 | personal_data_->AddProfile(profile0); |
| 124 | |
| 125 | // Reload the database. |
| 126 | ResetPersonalDataManager(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 127 | |
| 128 | // Verify the addition. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 129 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 130 | ASSERT_EQ(1U, results1.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 131 | EXPECT_EQ(0, profile0.Compare(*results1[0])); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 132 | |
| 133 | // Add profile with identical values. Duplicates should not get saved. |
| 134 | AutofillProfile profile0a = profile0; |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 135 | profile0a.set_guid(base::GenerateGUID()); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 136 | personal_data_->AddProfile(profile0a); |
| 137 | |
| 138 | // Reload the database. |
| 139 | ResetPersonalDataManager(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 140 | |
| 141 | // Verify the non-addition. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 142 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 143 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 144 | EXPECT_EQ(0, profile0.Compare(*results2[0])); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 145 | |
| 146 | // New profile with different email. |
| 147 | AutofillProfile profile1 = profile0; |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 148 | profile1.set_guid(base::GenerateGUID()); |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 149 | profile1.SetRawInfo(EMAIL_ADDRESS, ASCIIToUTF16("[email protected]")); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 150 | |
| 151 | // Add the different profile. This should save as a separate profile. |
| 152 | // Note that if this same profile was "merged" it would collapse to one |
| 153 | // profile with a multi-valued entry for email. |
| 154 | personal_data_->AddProfile(profile1); |
| 155 | |
| 156 | // Reload the database. |
| 157 | ResetPersonalDataManager(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 158 | |
| 159 | // Verify the addition. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 160 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 161 | ASSERT_EQ(2U, results3.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 162 | EXPECT_EQ(0, profile0.Compare(*results3[0])); |
| 163 | EXPECT_EQ(0, profile1.Compare(*results3[1])); |
[email protected] | 0ed984b | 2011-04-28 01:22:02 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 166 | TEST_F(PersonalDataManagerTest, AddUpdateRemoveProfiles) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 167 | AutofillProfile profile0; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 168 | autofill_test::SetProfileInfo(&profile0, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 169 | "Marion", "Mitchell", "Morrison", |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 170 | "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 171 | "91601", "US", "12345678910"); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 172 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 173 | AutofillProfile profile1; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 174 | autofill_test::SetProfileInfo(&profile1, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 175 | "Josephine", "Alicia", "Saenz", |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 176 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 177 | "US", "19482937549"); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 178 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 179 | AutofillProfile profile2; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 180 | autofill_test::SetProfileInfo(&profile2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 181 | "Josephine", "Alicia", "Saenz", |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 182 | "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 183 | "32801", "US", "19482937549"); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 184 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 185 | // Add two test profiles to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 186 | personal_data_->AddProfile(profile0); |
| 187 | personal_data_->AddProfile(profile1); |
| 188 | |
| 189 | // Verify that the web database has been updated and the notification sent. |
| 190 | EXPECT_CALL(personal_data_observer_, |
| 191 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 192 | MessageLoop::current()->Run(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 193 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 194 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 195 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 196 | EXPECT_EQ(0, profile0.Compare(*results1[0])); |
| 197 | EXPECT_EQ(0, profile1.Compare(*results1[1])); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 198 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 199 | // Update, remove, and add. |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 200 | profile0.SetRawInfo(NAME_FIRST, ASCIIToUTF16("John")); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 201 | personal_data_->UpdateProfile(profile0); |
[email protected] | 8da04b85 | 2012-11-16 22:10:39 | [diff] [blame] | 202 | personal_data_->RemoveByGUID(profile1.guid()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 203 | personal_data_->AddProfile(profile2); |
| 204 | |
| 205 | // Verify that the web database has been updated and the notification sent. |
| 206 | EXPECT_CALL(personal_data_observer_, |
| 207 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 208 | MessageLoop::current()->Run(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 209 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 210 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 211 | ASSERT_EQ(2U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 212 | EXPECT_EQ(0, profile0.Compare(*results2[0])); |
| 213 | EXPECT_EQ(0, profile2.Compare(*results2[1])); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 214 | |
| 215 | // Reset the PersonalDataManager. This tests that the personal data was saved |
| 216 | // to the web database, and that we can load the profiles from the web |
| 217 | // database. |
| 218 | ResetPersonalDataManager(); |
| 219 | |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 220 | // Verify that we've loaded the profiles from the web database. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 221 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 222 | ASSERT_EQ(2U, results3.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 223 | EXPECT_EQ(0, profile0.Compare(*results3[0])); |
| 224 | EXPECT_EQ(0, profile2.Compare(*results3[1])); |
[email protected] | 2609bc1 | 2010-01-24 08:32:55 | [diff] [blame] | 225 | } |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 226 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 227 | TEST_F(PersonalDataManagerTest, AddUpdateRemoveCreditCards) { |
| 228 | CreditCard credit_card0; |
| 229 | autofill_test::SetCreditCardInfo(&credit_card0, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 230 | "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 231 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 232 | CreditCard credit_card1; |
| 233 | autofill_test::SetCreditCardInfo(&credit_card1, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 234 | "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 235 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 236 | CreditCard credit_card2; |
| 237 | autofill_test::SetCreditCardInfo(&credit_card2, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 238 | "Clyde Barrow", "347666888555" /* American Express */, "04", "2015"); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 239 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 240 | // Add two test credit cards to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 241 | personal_data_->AddCreditCard(credit_card0); |
| 242 | personal_data_->AddCreditCard(credit_card1); |
| 243 | |
| 244 | // Verify that the web database has been updated and the notification sent. |
| 245 | EXPECT_CALL(personal_data_observer_, |
| 246 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 247 | MessageLoop::current()->Run(); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 248 | |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 249 | const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); |
| 250 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 251 | EXPECT_EQ(0, credit_card0.Compare(*results1[0])); |
| 252 | EXPECT_EQ(0, credit_card1.Compare(*results1[1])); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 253 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 254 | // Update, remove, and add. |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 255 | credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Joe")); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 256 | personal_data_->UpdateCreditCard(credit_card0); |
[email protected] | 8da04b85 | 2012-11-16 22:10:39 | [diff] [blame] | 257 | personal_data_->RemoveByGUID(credit_card1.guid()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 258 | personal_data_->AddCreditCard(credit_card2); |
| 259 | |
| 260 | // Verify that the web database has been updated and the notification sent. |
| 261 | EXPECT_CALL(personal_data_observer_, |
| 262 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 263 | MessageLoop::current()->Run(); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 264 | |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 265 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 266 | ASSERT_EQ(2U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 267 | EXPECT_EQ(credit_card0, *results2[0]); |
| 268 | EXPECT_EQ(credit_card2, *results2[1]); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 269 | |
| 270 | // Reset the PersonalDataManager. This tests that the personal data was saved |
| 271 | // to the web database, and that we can load the credit cards from the web |
| 272 | // database. |
| 273 | ResetPersonalDataManager(); |
| 274 | |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 275 | // Verify that we've loaded the credit cards from the web database. |
| 276 | const std::vector<CreditCard*>& results3 = personal_data_->credit_cards(); |
| 277 | ASSERT_EQ(2U, results3.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 278 | EXPECT_EQ(credit_card0, *results3[0]); |
| 279 | EXPECT_EQ(credit_card2, *results3[1]); |
[email protected] | f11f621 | 2010-01-25 20:47:20 | [diff] [blame] | 280 | } |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 281 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 282 | TEST_F(PersonalDataManagerTest, AddProfilesAndCreditCards) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 283 | AutofillProfile profile0; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 284 | autofill_test::SetProfileInfo(&profile0, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 285 | "Marion", "Mitchell", "Morrison", |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 286 | "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 287 | "91601", "US", "12345678910"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 288 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 289 | AutofillProfile profile1; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 290 | autofill_test::SetProfileInfo(&profile1, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 291 | "Josephine", "Alicia", "Saenz", |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 292 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 293 | "US", "19482937549"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 294 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 295 | CreditCard credit_card0; |
| 296 | autofill_test::SetCreditCardInfo(&credit_card0, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 297 | "John Dillinger", "423456789012" /* Visa */, "01", "2010"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 298 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 299 | CreditCard credit_card1; |
| 300 | autofill_test::SetCreditCardInfo(&credit_card1, |
[email protected] | 2a13edd | 2010-10-26 22:52:54 | [diff] [blame] | 301 | "Bonnie Parker", "518765432109" /* Mastercard */, "12", "2012"); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 302 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 303 | // Add two test profiles to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 304 | personal_data_->AddProfile(profile0); |
| 305 | personal_data_->AddProfile(profile1); |
| 306 | |
| 307 | // Verify that the web database has been updated and the notification sent. |
| 308 | EXPECT_CALL(personal_data_observer_, |
| 309 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 310 | MessageLoop::current()->Run(); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 311 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 312 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 313 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 314 | EXPECT_EQ(0, profile0.Compare(*results1[0])); |
| 315 | EXPECT_EQ(0, profile1.Compare(*results1[1])); |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 316 | |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 317 | // Add two test credit cards to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 318 | personal_data_->AddCreditCard(credit_card0); |
| 319 | personal_data_->AddCreditCard(credit_card1); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 320 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 321 | // Verify that the web database has been updated and the notification sent. |
| 322 | EXPECT_CALL(personal_data_observer_, |
| 323 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 324 | MessageLoop::current()->Run(); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 325 | |
| 326 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 327 | ASSERT_EQ(2U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 328 | EXPECT_EQ(credit_card0, *results2[0]); |
| 329 | EXPECT_EQ(credit_card1, *results2[1]); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 330 | |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 331 | // Determine uniqueness by inserting all of the GUIDs into a set and verifying |
| 332 | // the size of the set matches the number of GUIDs. |
| 333 | std::set<std::string> guids; |
| 334 | guids.insert(profile0.guid()); |
| 335 | guids.insert(profile1.guid()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 336 | guids.insert(credit_card0.guid()); |
| 337 | guids.insert(credit_card1.guid()); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 338 | EXPECT_EQ(4U, guids.size()); |
[email protected] | 542e199 | 2010-07-14 18:25:52 | [diff] [blame] | 339 | } |
| 340 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 341 | // Test for http://crbug.com/50047. Makes sure that guids are populated |
| 342 | // correctly on load. |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 343 | TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 344 | AutofillProfile profile0; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 345 | autofill_test::SetProfileInfo(&profile0, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 346 | "y", "", "", "", "", "", "", "", "", "", "", ""); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 347 | |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 348 | // Add the profile0 to the db. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 349 | personal_data_->AddProfile(profile0); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 350 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 351 | // Verify that the web database has been updated and the notification sent. |
| 352 | EXPECT_CALL(personal_data_observer_, |
| 353 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 354 | MessageLoop::current()->Run(); |
| 355 | |
| 356 | // Verify that we've loaded the profiles from the web database. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 357 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 358 | ASSERT_EQ(1U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 359 | EXPECT_EQ(0, profile0.Compare(*results2[0])); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 360 | |
| 361 | // Add a new profile. |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 362 | AutofillProfile profile1; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 363 | autofill_test::SetProfileInfo(&profile1, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 364 | "z", "", "", "", "", "", "", "", "", "", "", ""); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 365 | personal_data_->AddProfile(profile1); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 366 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 367 | // Verify that the web database has been updated and the notification sent. |
| 368 | EXPECT_CALL(personal_data_observer_, |
| 369 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 370 | MessageLoop::current()->Run(); |
| 371 | |
| 372 | // Make sure the two profiles have different GUIDs, both valid. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 373 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 374 | ASSERT_EQ(2U, results3.size()); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 375 | EXPECT_NE(results3[0]->guid(), results3[1]->guid()); |
[email protected] | 7e49ad3 | 2012-06-14 14:22:07 | [diff] [blame] | 376 | EXPECT_TRUE(base::IsValidGUID(results3[0]->guid())); |
| 377 | EXPECT_TRUE(base::IsValidGUID(results3[1]->guid())); |
[email protected] | 7c543fd | 2010-07-24 02:44:59 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 380 | TEST_F(PersonalDataManagerTest, SetEmptyProfile) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 381 | AutofillProfile profile0; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 382 | autofill_test::SetProfileInfo(&profile0, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 383 | "", "", "", "", "", "", "", "", "", "", "", ""); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 384 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 385 | // Add the empty profile to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 386 | personal_data_->AddProfile(profile0); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 387 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 388 | // Note: no refresh here. |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 389 | |
| 390 | // Reset the PersonalDataManager. This tests that the personal data was saved |
| 391 | // to the web database, and that we can load the profiles from the web |
| 392 | // database. |
| 393 | ResetPersonalDataManager(); |
| 394 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 395 | // Verify that we've loaded the profiles from the web database. |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 396 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 397 | ASSERT_EQ(0U, results2.size()); |
| 398 | } |
| 399 | |
| 400 | TEST_F(PersonalDataManagerTest, SetEmptyCreditCard) { |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 401 | CreditCard credit_card0; |
| 402 | autofill_test::SetCreditCardInfo(&credit_card0, "", "", "", ""); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 403 | |
| 404 | // Add the empty credit card to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 405 | personal_data_->AddCreditCard(credit_card0); |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 406 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 407 | // Note: no refresh here. |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 408 | |
| 409 | // Reset the PersonalDataManager. This tests that the personal data was saved |
| 410 | // to the web database, and that we can load the credit cards from the web |
| 411 | // database. |
| 412 | ResetPersonalDataManager(); |
| 413 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 414 | // Verify that we've loaded the credit cards from the web database. |
| 415 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 416 | ASSERT_EQ(0U, results2.size()); |
| 417 | } |
| 418 | |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 419 | TEST_F(PersonalDataManagerTest, Refresh) { |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 420 | AutofillProfile profile0; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 421 | autofill_test::SetProfileInfo(&profile0, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 422 | "Marion", "Mitchell", "Morrison", |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 423 | "[email protected]", "Fox", "123 Zoo St.", "unit 5", "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 424 | "91601", "US", "12345678910"); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 425 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 426 | AutofillProfile profile1; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 427 | autofill_test::SetProfileInfo(&profile1, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 428 | "Josephine", "Alicia", "Saenz", |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 429 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 430 | "US", "19482937549"); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 431 | |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 432 | // Add the test profiles to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 433 | personal_data_->AddProfile(profile0); |
| 434 | personal_data_->AddProfile(profile1); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 435 | |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 436 | // Labels depend on other profiles in the list - update labels manually. |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 437 | std::vector<AutofillProfile *> profile_pointers; |
[email protected] | 9f32144 | 2010-10-25 23:53:53 | [diff] [blame] | 438 | profile_pointers.push_back(&profile0); |
| 439 | profile_pointers.push_back(&profile1); |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 440 | AutofillProfile::AdjustInferredLabels(&profile_pointers); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 441 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 442 | // Verify that the web database has been updated and the notification sent. |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 443 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 444 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 445 | MessageLoop::current()->Run(); |
| 446 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 447 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 448 | ASSERT_EQ(2U, results1.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 449 | EXPECT_EQ(profile0, *results1[0]); |
| 450 | EXPECT_EQ(profile1, *results1[1]); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 451 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 452 | AutofillProfile profile2; |
[email protected] | 61f25cd0e | 2010-11-07 05:23:50 | [diff] [blame] | 453 | autofill_test::SetProfileInfo(&profile2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 454 | "Josephine", "Alicia", "Saenz", |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 455 | "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 456 | "32801", "US", "19482937549"); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 457 | |
[email protected] | 9f32144 | 2010-10-25 23:53:53 | [diff] [blame] | 458 | // Adjust all labels. |
[email protected] | 61f25cd0e | 2010-11-07 05:23:50 | [diff] [blame] | 459 | profile_pointers.push_back(&profile2); |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 460 | AutofillProfile::AdjustInferredLabels(&profile_pointers); |
[email protected] | 9f32144 | 2010-10-25 23:53:53 | [diff] [blame] | 461 | |
[email protected] | e2b3105 | 2013-03-25 01:49:37 | [diff] [blame] | 462 | scoped_refptr<AutofillWebDataService> wds = |
| 463 | AutofillWebDataService::FromBrowserContext(profile_.get()); |
[email protected] | d07edd4 | 2012-05-14 23:49:46 | [diff] [blame] | 464 | ASSERT_TRUE(wds.get()); |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 465 | wds->AddAutofillProfile(profile2); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 466 | |
| 467 | personal_data_->Refresh(); |
| 468 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 469 | // Verify that the web database has been updated and the notification sent. |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 470 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 471 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 472 | MessageLoop::current()->Run(); |
| 473 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 474 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 475 | ASSERT_EQ(3U, results2.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 476 | EXPECT_EQ(profile0, *results2[0]); |
| 477 | EXPECT_EQ(profile1, *results2[1]); |
| 478 | EXPECT_EQ(profile2, *results2[2]); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 479 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 480 | wds->RemoveAutofillProfile(profile1.guid()); |
| 481 | wds->RemoveAutofillProfile(profile2.guid()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 482 | |
| 483 | // 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] | 484 | // via a SetProfile update (this would happen if the Autofill window was |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 485 | // open with a previous snapshot of the profiles, and something [e.g. sync] |
| 486 | // removed a profile from the browser. In this edge case, we will end up |
| 487 | // in a consistent state by dropping the write). |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 488 | profile2.SetRawInfo(NAME_FIRST, ASCIIToUTF16("Jo")); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 489 | personal_data_->UpdateProfile(profile0); |
| 490 | personal_data_->AddProfile(profile1); |
| 491 | personal_data_->AddProfile(profile2); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 492 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 493 | // Verify that the web database has been updated and the notification sent. |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 494 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 495 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 496 | MessageLoop::current()->Run(); |
| 497 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 498 | const std::vector<AutofillProfile*>& results3 = personal_data_->GetProfiles(); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 499 | ASSERT_EQ(1U, results3.size()); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 500 | EXPECT_EQ(profile0, *results2[0]); |
[email protected] | e0976a7 | 2010-04-02 01:25:24 | [diff] [blame] | 501 | } |
[email protected] | 83723f0 | 2010-04-07 17:33:10 | [diff] [blame] | 502 | |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 503 | TEST_F(PersonalDataManagerTest, ImportFormData) { |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 504 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 505 | FormFieldData field; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 506 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 507 | "First name:", "first_name", "George", "text", &field); |
| 508 | form.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 509 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 510 | "Last name:", "last_name", "Washington", "text", &field); |
| 511 | form.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 512 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 513 | "Email:", "email", "[email protected]", "text", &field); |
| 514 | form.fields.push_back(field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 515 | autofill_test::CreateTestFormField( |
| 516 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 517 | form.fields.push_back(field); |
| 518 | autofill_test::CreateTestFormField( |
| 519 | "City:", "city", "San Francisco", "text", &field); |
| 520 | form.fields.push_back(field); |
| 521 | autofill_test::CreateTestFormField( |
| 522 | "State:", "state", "California", "text", &field); |
| 523 | form.fields.push_back(field); |
| 524 | autofill_test::CreateTestFormField( |
| 525 | "Zip:", "zip", "94102", "text", &field); |
| 526 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 527 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 528 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 529 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 530 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 531 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 532 | ASSERT_FALSE(imported_credit_card); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 533 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 534 | // Verify that the web database has been updated and the notification sent. |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 535 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 536 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 537 | MessageLoop::current()->Run(); |
| 538 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 539 | AutofillProfile expected; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 540 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 541 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 542 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 543 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 544 | ASSERT_EQ(1U, results.size()); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 545 | EXPECT_EQ(0, expected.Compare(*results[0])); |
[email protected] | ce78c1f9 | 2010-04-09 02:23:26 | [diff] [blame] | 546 | } |
| 547 | |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 548 | TEST_F(PersonalDataManagerTest, ImportFormDataBadEmail) { |
| 549 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 550 | FormFieldData field; |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 551 | autofill_test::CreateTestFormField( |
| 552 | "First name:", "first_name", "George", "text", &field); |
| 553 | form.fields.push_back(field); |
| 554 | autofill_test::CreateTestFormField( |
| 555 | "Last name:", "last_name", "Washington", "text", &field); |
| 556 | form.fields.push_back(field); |
| 557 | autofill_test::CreateTestFormField( |
| 558 | "Email:", "email", "bogus", "text", &field); |
| 559 | form.fields.push_back(field); |
| 560 | autofill_test::CreateTestFormField( |
| 561 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 562 | form.fields.push_back(field); |
| 563 | autofill_test::CreateTestFormField( |
| 564 | "City:", "city", "San Francisco", "text", &field); |
| 565 | form.fields.push_back(field); |
| 566 | autofill_test::CreateTestFormField( |
| 567 | "State:", "state", "California", "text", &field); |
| 568 | form.fields.push_back(field); |
| 569 | autofill_test::CreateTestFormField( |
| 570 | "Zip:", "zip", "94102", "text", &field); |
| 571 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 572 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 573 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 574 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 575 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure, |
| 576 | &imported_credit_card)); |
[email protected] | ca9bdeb | 2011-03-17 20:01:41 | [diff] [blame] | 577 | ASSERT_EQ(static_cast<CreditCard*>(NULL), imported_credit_card); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 578 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 579 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
[email protected] | ca9bdeb | 2011-03-17 20:01:41 | [diff] [blame] | 580 | ASSERT_EQ(0U, results.size()); |
[email protected] | a2a1baf | 2011-02-03 20:22:00 | [diff] [blame] | 581 | } |
| 582 | |
[email protected] | ad651d38 | 2013-04-10 06:31:22 | [diff] [blame] | 583 | // Tests that a 'confirm email' field does not block profile import. |
| 584 | TEST_F(PersonalDataManagerTest, ImportFormDataTwoEmails) { |
| 585 | FormData form; |
| 586 | FormFieldData field; |
| 587 | autofill_test::CreateTestFormField( |
| 588 | "Name:", "name", "George Washington", "text", &field); |
| 589 | form.fields.push_back(field); |
| 590 | autofill_test::CreateTestFormField( |
| 591 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 592 | form.fields.push_back(field); |
| 593 | autofill_test::CreateTestFormField( |
| 594 | "City:", "city", "San Francisco", "text", &field); |
| 595 | form.fields.push_back(field); |
| 596 | autofill_test::CreateTestFormField( |
| 597 | "State:", "state", "California", "text", &field); |
| 598 | form.fields.push_back(field); |
| 599 | autofill_test::CreateTestFormField( |
| 600 | "Zip:", "zip", "94102", "text", &field); |
| 601 | form.fields.push_back(field); |
| 602 | autofill_test::CreateTestFormField( |
| 603 | "Email:", "email", "[email protected]", "text", &field); |
| 604 | form.fields.push_back(field); |
| 605 | autofill_test::CreateTestFormField( |
| 606 | "Confirm email:", "confirm_email", "[email protected]", "text", &field); |
| 607 | form.fields.push_back(field); |
| 608 | FormStructure form_structure(form, std::string()); |
| 609 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 610 | const CreditCard* imported_credit_card; |
| 611 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 612 | &imported_credit_card)); |
| 613 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
| 614 | ASSERT_EQ(1U, results.size()); |
| 615 | } |
| 616 | |
| 617 | // Tests two email fields containing different values blocks provile import. |
| 618 | TEST_F(PersonalDataManagerTest, ImportFormDataTwoDifferentEmails) { |
| 619 | FormData form; |
| 620 | FormFieldData field; |
| 621 | autofill_test::CreateTestFormField( |
| 622 | "Name:", "name", "George Washington", "text", &field); |
| 623 | form.fields.push_back(field); |
| 624 | autofill_test::CreateTestFormField( |
| 625 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 626 | form.fields.push_back(field); |
| 627 | autofill_test::CreateTestFormField( |
| 628 | "City:", "city", "San Francisco", "text", &field); |
| 629 | form.fields.push_back(field); |
| 630 | autofill_test::CreateTestFormField( |
| 631 | "State:", "state", "California", "text", &field); |
| 632 | form.fields.push_back(field); |
| 633 | autofill_test::CreateTestFormField( |
| 634 | "Zip:", "zip", "94102", "text", &field); |
| 635 | form.fields.push_back(field); |
| 636 | autofill_test::CreateTestFormField( |
| 637 | "Email:", "email", "[email protected]", "text", &field); |
| 638 | form.fields.push_back(field); |
| 639 | autofill_test::CreateTestFormField( |
| 640 | "Email:", "email2", "[email protected]", "text", &field); |
| 641 | form.fields.push_back(field); |
| 642 | FormStructure form_structure(form, std::string()); |
| 643 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 644 | const CreditCard* imported_credit_card; |
| 645 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure, |
| 646 | &imported_credit_card)); |
| 647 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
| 648 | ASSERT_EQ(0U, results.size()); |
| 649 | } |
| 650 | |
[email protected] | 20477755 | 2011-01-26 19:46:28 | [diff] [blame] | 651 | TEST_F(PersonalDataManagerTest, ImportFormDataNotEnoughFilledFields) { |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 652 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 653 | FormFieldData field; |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 654 | autofill_test::CreateTestFormField( |
| 655 | "First name:", "first_name", "George", "text", &field); |
| 656 | form.fields.push_back(field); |
| 657 | autofill_test::CreateTestFormField( |
| 658 | "Last name:", "last_name", "Washington", "text", &field); |
| 659 | form.fields.push_back(field); |
| 660 | autofill_test::CreateTestFormField( |
| 661 | "Card number:", "card_number", "4111 1111 1111 1111", "text", &field); |
| 662 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 663 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 664 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 665 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 666 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure, |
| 667 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 668 | ASSERT_FALSE(imported_credit_card); |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 669 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 670 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
[email protected] | 4fb05809 | 2010-11-24 23:52:25 | [diff] [blame] | 671 | ASSERT_EQ(0U, profiles.size()); |
| 672 | const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); |
| 673 | ASSERT_EQ(0U, credit_cards.size()); |
| 674 | } |
| 675 | |
[email protected] | a36215a | 2013-04-04 12:35:42 | [diff] [blame] | 676 | TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressUSA) { |
| 677 | // United States addresses must specifiy one address line, a city, state and |
| 678 | // zip code. |
| 679 | FormData form; |
| 680 | FormFieldData field; |
| 681 | autofill_test::CreateTestFormField( |
| 682 | "Name:", "name", "Barack Obama", "text", &field); |
| 683 | form.fields.push_back(field); |
| 684 | autofill_test::CreateTestFormField( |
| 685 | "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); |
| 686 | form.fields.push_back(field); |
| 687 | autofill_test::CreateTestFormField( |
| 688 | "City:", "city", "Washington", "text", &field); |
| 689 | form.fields.push_back(field); |
| 690 | autofill_test::CreateTestFormField( |
| 691 | "State:", "state", "DC", "text", &field); |
| 692 | form.fields.push_back(field); |
| 693 | autofill_test::CreateTestFormField( |
| 694 | "Zip:", "zip", "20500", "text", &field); |
| 695 | form.fields.push_back(field); |
| 696 | autofill_test::CreateTestFormField( |
| 697 | "Country:", "country", "USA", "text", &field); |
| 698 | form.fields.push_back(field); |
| 699 | FormStructure form_structure(form, std::string()); |
| 700 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 701 | const CreditCard* imported_credit_card; |
| 702 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 703 | &imported_credit_card)); |
| 704 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 705 | ASSERT_EQ(1U, profiles.size()); |
| 706 | } |
| 707 | |
| 708 | TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGB) { |
| 709 | // British addresses do not require a state/province as the county is usually |
| 710 | // not requested on forms. |
| 711 | FormData form; |
| 712 | FormFieldData field; |
| 713 | autofill_test::CreateTestFormField( |
| 714 | "Name:", "name", "David Cameron", "text", &field); |
| 715 | form.fields.push_back(field); |
| 716 | autofill_test::CreateTestFormField( |
| 717 | "Address:", "address", "10 Downing Street", "text", &field); |
| 718 | form.fields.push_back(field); |
| 719 | autofill_test::CreateTestFormField( |
| 720 | "City:", "city", "London", "text", &field); |
| 721 | form.fields.push_back(field); |
| 722 | autofill_test::CreateTestFormField( |
| 723 | "Postcode:", "postcode", "SW1A 2AA", "text", &field); |
| 724 | form.fields.push_back(field); |
| 725 | autofill_test::CreateTestFormField( |
| 726 | "Country:", "country", "United Kingdom", "text", &field); |
| 727 | form.fields.push_back(field); |
| 728 | FormStructure form_structure(form, std::string()); |
| 729 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 730 | const CreditCard* imported_credit_card; |
| 731 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 732 | &imported_credit_card)); |
| 733 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 734 | ASSERT_EQ(1U, profiles.size()); |
| 735 | } |
| 736 | |
| 737 | TEST_F(PersonalDataManagerTest, ImportFormMinimumAddressGI) { |
| 738 | // Gibraltar has the most minimal set of requirements for a valid address. |
| 739 | // There are no cities or provinces and no postal/zip code system. |
| 740 | FormData form; |
| 741 | FormFieldData field; |
| 742 | autofill_test::CreateTestFormField( |
| 743 | "Name:", "name", "Sir Adrian Johns", "text", &field); |
| 744 | form.fields.push_back(field); |
| 745 | autofill_test::CreateTestFormField( |
| 746 | "Address:", "address", "The Convent, Main Street", "text", &field); |
| 747 | form.fields.push_back(field); |
| 748 | autofill_test::CreateTestFormField( |
| 749 | "Country:", "country", "Gibraltar", "text", &field); |
| 750 | form.fields.push_back(field); |
| 751 | FormStructure form_structure(form, std::string()); |
| 752 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
| 753 | const CreditCard* imported_credit_card; |
| 754 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 755 | &imported_credit_card)); |
| 756 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
| 757 | ASSERT_EQ(1U, profiles.size()); |
| 758 | } |
| 759 | |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 760 | TEST_F(PersonalDataManagerTest, ImportPhoneNumberSplitAcrossMultipleFields) { |
| 761 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 762 | FormFieldData field; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 763 | autofill_test::CreateTestFormField( |
| 764 | "First name:", "first_name", "George", "text", &field); |
| 765 | form.fields.push_back(field); |
| 766 | autofill_test::CreateTestFormField( |
| 767 | "Last name:", "last_name", "Washington", "text", &field); |
| 768 | form.fields.push_back(field); |
| 769 | autofill_test::CreateTestFormField( |
| 770 | "Phone #:", "home_phone_area_code", "650", "text", &field); |
[email protected] | e2aaa81 | 2011-03-08 18:46:04 | [diff] [blame] | 771 | field.max_length = 3; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 772 | form.fields.push_back(field); |
| 773 | autofill_test::CreateTestFormField( |
| 774 | "Phone #:", "home_phone_prefix", "555", "text", &field); |
[email protected] | e2aaa81 | 2011-03-08 18:46:04 | [diff] [blame] | 775 | field.max_length = 3; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 776 | form.fields.push_back(field); |
| 777 | autofill_test::CreateTestFormField( |
| 778 | "Phone #:", "home_phone_suffix", "0000", "text", &field); |
[email protected] | e2aaa81 | 2011-03-08 18:46:04 | [diff] [blame] | 779 | field.max_length = 4; |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 780 | form.fields.push_back(field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 781 | autofill_test::CreateTestFormField( |
| 782 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 783 | form.fields.push_back(field); |
| 784 | autofill_test::CreateTestFormField( |
| 785 | "City:", "city", "San Francisco", "text", &field); |
| 786 | form.fields.push_back(field); |
| 787 | autofill_test::CreateTestFormField( |
| 788 | "State:", "state", "California", "text", &field); |
| 789 | form.fields.push_back(field); |
| 790 | autofill_test::CreateTestFormField( |
| 791 | "Zip:", "zip", "94102", "text", &field); |
| 792 | form.fields.push_back(field); |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 793 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 794 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 795 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 796 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 797 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 798 | ASSERT_FALSE(imported_credit_card); |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 799 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 800 | // Verify that the web database has been updated and the notification sent. |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 801 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 802 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 803 | MessageLoop::current()->Run(); |
| 804 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 805 | AutofillProfile expected; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 806 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 807 | "Washington", NULL, NULL, "21 Laussat St", NULL, |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 808 | "San Francisco", "California", "94102", NULL, "(650) 555-0000"); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 809 | const std::vector<AutofillProfile*>& results = personal_data_->GetProfiles(); |
[email protected] | 3aa8bec2 | 2010-11-23 07:51:28 | [diff] [blame] | 810 | ASSERT_EQ(1U, results.size()); |
| 811 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 812 | } |
| 813 | |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 814 | TEST_F(PersonalDataManagerTest, SetUniqueCreditCardLabels) { |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 815 | CreditCard credit_card0; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 816 | credit_card0.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("John")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 817 | CreditCard credit_card1; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 818 | credit_card1.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 819 | CreditCard credit_card2; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 820 | credit_card2.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ringo")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 821 | CreditCard credit_card3; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 822 | credit_card3.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Other")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 823 | CreditCard credit_card4; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 824 | credit_card4.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Ozzy")); |
[email protected] | e4378340 | 2010-11-04 19:45:04 | [diff] [blame] | 825 | CreditCard credit_card5; |
[email protected] | 6b44b58 | 2012-11-10 06:31:18 | [diff] [blame] | 826 | credit_card5.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Dio")); |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 827 | |
[email protected] | 98a94ee | 2010-07-12 16:03:22 | [diff] [blame] | 828 | // Add the test credit cards to the database. |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 829 | personal_data_->AddCreditCard(credit_card0); |
| 830 | personal_data_->AddCreditCard(credit_card1); |
| 831 | personal_data_->AddCreditCard(credit_card2); |
| 832 | personal_data_->AddCreditCard(credit_card3); |
| 833 | personal_data_->AddCreditCard(credit_card4); |
| 834 | personal_data_->AddCreditCard(credit_card5); |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 835 | |
[email protected] | 18f92d4f | 2010-10-19 00:14:58 | [diff] [blame] | 836 | // Reset the PersonalDataManager. This tests that the personal data was saved |
| 837 | // to the web database, and that we can load the credit cards from the web |
| 838 | // database. |
| 839 | ResetPersonalDataManager(); |
| 840 | |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 841 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 842 | ASSERT_EQ(6U, results.size()); |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 843 | EXPECT_EQ(credit_card0.guid(), results[0]->guid()); |
| 844 | EXPECT_EQ(credit_card1.guid(), results[1]->guid()); |
| 845 | EXPECT_EQ(credit_card2.guid(), results[2]->guid()); |
| 846 | EXPECT_EQ(credit_card3.guid(), results[3]->guid()); |
| 847 | EXPECT_EQ(credit_card4.guid(), results[4]->guid()); |
| 848 | EXPECT_EQ(credit_card5.guid(), results[5]->guid()); |
[email protected] | 47e119f0 | 2010-04-15 00:46:55 | [diff] [blame] | 849 | } |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 850 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 851 | TEST_F(PersonalDataManagerTest, AggregateTwoDifferentProfiles) { |
| 852 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 853 | FormFieldData field; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 854 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 855 | "First name:", "first_name", "George", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 856 | form1.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 857 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 858 | "Last name:", "last_name", "Washington", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 859 | form1.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 860 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 861 | "Email:", "email", "[email protected]", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 862 | form1.fields.push_back(field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 863 | autofill_test::CreateTestFormField( |
| 864 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 865 | form1.fields.push_back(field); |
| 866 | autofill_test::CreateTestFormField( |
| 867 | "City:", "city", "San Francisco", "text", &field); |
| 868 | form1.fields.push_back(field); |
| 869 | autofill_test::CreateTestFormField( |
| 870 | "State:", "state", "California", "text", &field); |
| 871 | form1.fields.push_back(field); |
| 872 | autofill_test::CreateTestFormField( |
| 873 | "Zip:", "zip", "94102", "text", &field); |
| 874 | form1.fields.push_back(field); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 875 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 876 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 877 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 878 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 879 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 880 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 881 | ASSERT_FALSE(imported_credit_card); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 882 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 883 | // Verify that the web database has been updated and the notification sent. |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 884 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 885 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 886 | MessageLoop::current()->Run(); |
| 887 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 888 | AutofillProfile expected; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 889 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 890 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 891 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 892 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 893 | ASSERT_EQ(1U, results1.size()); |
| 894 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 895 | |
| 896 | // Now create a completely different profile. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 897 | FormData form2; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 898 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 899 | "First name:", "first_name", "John", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 900 | form2.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 901 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 902 | "Last name:", "last_name", "Adams", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 903 | form2.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 904 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 905 | "Email:", "email", "[email protected]", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 906 | form2.fields.push_back(field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 907 | autofill_test::CreateTestFormField( |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 908 | "Address:", "address1", "22 Laussat St", "text", &field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 909 | form2.fields.push_back(field); |
| 910 | autofill_test::CreateTestFormField( |
| 911 | "City:", "city", "San Francisco", "text", &field); |
| 912 | form2.fields.push_back(field); |
| 913 | autofill_test::CreateTestFormField( |
| 914 | "State:", "state", "California", "text", &field); |
| 915 | form2.fields.push_back(field); |
| 916 | autofill_test::CreateTestFormField( |
| 917 | "Zip:", "zip", "94102", "text", &field); |
| 918 | form2.fields.push_back(field); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 919 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 920 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 921 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 922 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 923 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 924 | ASSERT_FALSE(imported_credit_card); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 925 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 926 | // Verify that the web database has been updated and the notification sent. |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 927 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 928 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 929 | MessageLoop::current()->Run(); |
| 930 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 931 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 932 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 933 | AutofillProfile expected2; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 934 | autofill_test::SetProfileInfo(&expected2, "John", NULL, |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 935 | "Adams", "[email protected]", NULL, "22 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 936 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 937 | ASSERT_EQ(2U, results2.size()); |
| 938 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 939 | EXPECT_EQ(0, expected2.Compare(*results2[1])); |
| 940 | } |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 941 | |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 942 | TEST_F(PersonalDataManagerTest, AggregateTwoProfilesWithMultiValue) { |
| 943 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 944 | FormFieldData field; |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 945 | autofill_test::CreateTestFormField( |
| 946 | "First name:", "first_name", "George", "text", &field); |
| 947 | form1.fields.push_back(field); |
| 948 | autofill_test::CreateTestFormField( |
| 949 | "Last name:", "last_name", "Washington", "text", &field); |
| 950 | form1.fields.push_back(field); |
| 951 | autofill_test::CreateTestFormField( |
| 952 | "Email:", "email", "[email protected]", "text", &field); |
| 953 | form1.fields.push_back(field); |
| 954 | autofill_test::CreateTestFormField( |
| 955 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 956 | form1.fields.push_back(field); |
| 957 | autofill_test::CreateTestFormField( |
| 958 | "City:", "city", "San Francisco", "text", &field); |
| 959 | form1.fields.push_back(field); |
| 960 | autofill_test::CreateTestFormField( |
| 961 | "State:", "state", "California", "text", &field); |
| 962 | form1.fields.push_back(field); |
| 963 | autofill_test::CreateTestFormField( |
| 964 | "Zip:", "zip", "94102", "text", &field); |
| 965 | form1.fields.push_back(field); |
| 966 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 967 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 968 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 969 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 970 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 971 | &imported_credit_card)); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 972 | ASSERT_FALSE(imported_credit_card); |
| 973 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 974 | // Verify that the web database has been updated and the notification sent. |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 975 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 976 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 977 | MessageLoop::current()->Run(); |
| 978 | |
| 979 | AutofillProfile expected; |
| 980 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
| 981 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 982 | "San Francisco", "California", "94102", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 983 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 984 | ASSERT_EQ(1U, results1.size()); |
| 985 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
| 986 | |
| 987 | // Now create a completely different profile. |
| 988 | FormData form2; |
| 989 | autofill_test::CreateTestFormField( |
| 990 | "First name:", "first_name", "John", "text", &field); |
| 991 | form2.fields.push_back(field); |
| 992 | autofill_test::CreateTestFormField( |
| 993 | "Last name:", "last_name", "Adams", "text", &field); |
| 994 | form2.fields.push_back(field); |
| 995 | autofill_test::CreateTestFormField( |
| 996 | "Email:", "email", "[email protected]", "text", &field); |
| 997 | form2.fields.push_back(field); |
| 998 | autofill_test::CreateTestFormField( |
| 999 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 1000 | form2.fields.push_back(field); |
| 1001 | autofill_test::CreateTestFormField( |
| 1002 | "City:", "city", "San Francisco", "text", &field); |
| 1003 | form2.fields.push_back(field); |
| 1004 | autofill_test::CreateTestFormField( |
| 1005 | "State:", "state", "California", "text", &field); |
| 1006 | form2.fields.push_back(field); |
| 1007 | autofill_test::CreateTestFormField( |
| 1008 | "Zip:", "zip", "94102", "text", &field); |
| 1009 | form2.fields.push_back(field); |
| 1010 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1011 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1012 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1013 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1014 | &imported_credit_card)); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1015 | ASSERT_FALSE(imported_credit_card); |
| 1016 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1017 | // Verify that the web database has been updated and the notification sent. |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1018 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1019 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1020 | MessageLoop::current()->Run(); |
| 1021 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1022 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1023 | |
| 1024 | // Modify expected to include multi-valued fields. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 1025 | std::vector<base::string16> values; |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1026 | expected.GetRawMultiInfo(NAME_FULL, &values); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1027 | values.push_back(ASCIIToUTF16("John Adams")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1028 | expected.SetRawMultiInfo(NAME_FULL, values); |
| 1029 | expected.GetRawMultiInfo(EMAIL_ADDRESS, &values); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1030 | values.push_back(ASCIIToUTF16("[email protected]")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1031 | expected.SetRawMultiInfo(EMAIL_ADDRESS, values); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1032 | |
| 1033 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 1034 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1035 | } |
| 1036 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1037 | TEST_F(PersonalDataManagerTest, AggregateSameProfileWithConflict) { |
| 1038 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1039 | FormFieldData field; |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 1040 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1041 | "First name:", "first_name", "George", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1042 | form1.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 1043 | autofill_test::CreateTestFormField( |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1044 | "Last name:", "last_name", "Washington", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1045 | form1.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 1046 | autofill_test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1047 | "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); |
| 1048 | form1.fields.push_back(field); |
[email protected] | 468327f | 2010-10-04 20:02:29 | [diff] [blame] | 1049 | autofill_test::CreateTestFormField( |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1050 | "Address Line 2:", "address2", "Suite A", "text", &field); |
| 1051 | form1.fields.push_back(field); |
| 1052 | autofill_test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1053 | "City:", "city", "San Francisco", "text", &field); |
| 1054 | form1.fields.push_back(field); |
| 1055 | autofill_test::CreateTestFormField( |
| 1056 | "State:", "state", "California", "text", &field); |
| 1057 | form1.fields.push_back(field); |
| 1058 | autofill_test::CreateTestFormField( |
| 1059 | "Zip:", "zip", "94102", "text", &field); |
| 1060 | form1.fields.push_back(field); |
| 1061 | autofill_test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1062 | "Email:", "email", "[email protected]", "text", &field); |
| 1063 | form1.fields.push_back(field); |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1064 | autofill_test::CreateTestFormField( |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 1065 | "Phone:", "phone", "6505556666", "text", &field); |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1066 | form1.fields.push_back(field); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1067 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1068 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1069 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1070 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1071 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1072 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1073 | ASSERT_FALSE(imported_credit_card); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1074 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1075 | // Verify that the web database has been updated and the notification sent. |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1076 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1077 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1078 | MessageLoop::current()->Run(); |
| 1079 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1080 | AutofillProfile expected; |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 1081 | autofill_test::SetProfileInfo( |
| 1082 | &expected, "George", NULL, "Washington", "[email protected]", NULL, |
| 1083 | "1600 Pennsylvania Avenue", "Suite A", "San Francisco", "California", |
| 1084 | "94102", NULL, "(650) 555-6666"); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1085 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1086 | ASSERT_EQ(1U, results1.size()); |
| 1087 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1088 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1089 | // Now create an updated profile. |
| 1090 | FormData form2; |
| 1091 | autofill_test::CreateTestFormField( |
| 1092 | "First name:", "first_name", "George", "text", &field); |
| 1093 | form2.fields.push_back(field); |
| 1094 | autofill_test::CreateTestFormField( |
| 1095 | "Last name:", "last_name", "Washington", "text", &field); |
| 1096 | form2.fields.push_back(field); |
| 1097 | autofill_test::CreateTestFormField( |
| 1098 | "Address:", "address", "1600 Pennsylvania Avenue", "text", &field); |
| 1099 | form2.fields.push_back(field); |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1100 | autofill_test::CreateTestFormField( |
| 1101 | "Address Line 2:", "address2", "Suite A", "text", &field); |
| 1102 | form2.fields.push_back(field); |
| 1103 | autofill_test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1104 | "City:", "city", "San Francisco", "text", &field); |
| 1105 | form2.fields.push_back(field); |
| 1106 | autofill_test::CreateTestFormField( |
| 1107 | "State:", "state", "California", "text", &field); |
| 1108 | form2.fields.push_back(field); |
| 1109 | autofill_test::CreateTestFormField( |
| 1110 | "Zip:", "zip", "94102", "text", &field); |
| 1111 | form2.fields.push_back(field); |
| 1112 | autofill_test::CreateTestFormField( |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1113 | "Email:", "email", "[email protected]", "text", &field); |
| 1114 | form2.fields.push_back(field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1115 | // Country gets added. |
| 1116 | autofill_test::CreateTestFormField( |
| 1117 | "Country:", "country", "USA", "text", &field); |
| 1118 | form2.fields.push_back(field); |
[email protected] | 465d07f | 2010-11-30 04:52:34 | [diff] [blame] | 1119 | // Phone gets updated. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1120 | autofill_test::CreateTestFormField( |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 1121 | "Phone:", "phone", "6502231234", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1122 | form2.fields.push_back(field); |
| 1123 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1124 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1125 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1126 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1127 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1128 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1129 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1130 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1131 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1132 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1133 | MessageLoop::current()->Run(); |
| 1134 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1135 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1136 | |
[email protected] | 023e182 | 2011-04-13 15:52:24 | [diff] [blame] | 1137 | // Add multi-valued phone number to expectation. Also, country gets added. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 1138 | std::vector<base::string16> values; |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1139 | expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 1140 | values.push_back(ASCIIToUTF16("(650) 223-1234")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 1141 | expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
[email protected] | 91b073d | 2013-01-05 01:30:28 | [diff] [blame] | 1142 | expected.SetRawInfo(ADDRESS_HOME_COUNTRY, ASCIIToUTF16("US")); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1143 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 1144 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInOld) { |
| 1148 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1149 | FormFieldData field; |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1150 | autofill_test::CreateTestFormField( |
| 1151 | "First name:", "first_name", "George", "text", &field); |
| 1152 | form1.fields.push_back(field); |
| 1153 | autofill_test::CreateTestFormField( |
| 1154 | "Last name:", "last_name", "Washington", "text", &field); |
| 1155 | form1.fields.push_back(field); |
| 1156 | autofill_test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1157 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1158 | form1.fields.push_back(field); |
| 1159 | autofill_test::CreateTestFormField( |
| 1160 | "City:", "city", "Philadelphia", "text", &field); |
| 1161 | form1.fields.push_back(field); |
| 1162 | autofill_test::CreateTestFormField( |
| 1163 | "State:", "state", "Pennsylvania", "text", &field); |
| 1164 | form1.fields.push_back(field); |
| 1165 | autofill_test::CreateTestFormField( |
| 1166 | "Zip:", "zipcode", "19106", "text", &field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1167 | form1.fields.push_back(field); |
| 1168 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1169 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1170 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1171 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1172 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1173 | &imported_credit_card)); |
[email protected] | a73830e | 2011-10-05 01:12:58 | [diff] [blame] | 1174 | EXPECT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1175 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1176 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1177 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1178 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1179 | MessageLoop::current()->Run(); |
| 1180 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1181 | AutofillProfile expected; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1182 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1183 | "Washington", NULL, NULL, "190 High Street", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1184 | "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1185 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1186 | ASSERT_EQ(1U, results1.size()); |
| 1187 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
| 1188 | |
| 1189 | // Submit a form with new data for the first profile. |
| 1190 | FormData form2; |
| 1191 | autofill_test::CreateTestFormField( |
| 1192 | "First name:", "first_name", "George", "text", &field); |
| 1193 | form2.fields.push_back(field); |
| 1194 | autofill_test::CreateTestFormField( |
| 1195 | "Last name:", "last_name", "Washington", "text", &field); |
| 1196 | form2.fields.push_back(field); |
| 1197 | autofill_test::CreateTestFormField( |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1198 | "Email:", "email", "[email protected]", "text", &field); |
| 1199 | form2.fields.push_back(field); |
| 1200 | autofill_test::CreateTestFormField( |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1201 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1202 | form2.fields.push_back(field); |
| 1203 | autofill_test::CreateTestFormField( |
| 1204 | "City:", "city", "Philadelphia", "text", &field); |
| 1205 | form2.fields.push_back(field); |
| 1206 | autofill_test::CreateTestFormField( |
| 1207 | "State:", "state", "Pennsylvania", "text", &field); |
| 1208 | form2.fields.push_back(field); |
| 1209 | autofill_test::CreateTestFormField( |
| 1210 | "Zip:", "zipcode", "19106", "text", &field); |
| 1211 | form2.fields.push_back(field); |
| 1212 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1213 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1214 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1215 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1216 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1217 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1218 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1219 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1220 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1221 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1222 | MessageLoop::current()->Run(); |
| 1223 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1224 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1225 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1226 | AutofillProfile expected2; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1227 | autofill_test::SetProfileInfo(&expected2, "George", NULL, |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1228 | "Washington", "[email protected]", NULL, "190 High Street", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1229 | "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1230 | ASSERT_EQ(1U, results2.size()); |
| 1231 | EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1232 | } |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1233 | |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1234 | TEST_F(PersonalDataManagerTest, AggregateProfileWithMissingInfoInNew) { |
| 1235 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1236 | FormFieldData field; |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1237 | autofill_test::CreateTestFormField( |
| 1238 | "First name:", "first_name", "George", "text", &field); |
| 1239 | form1.fields.push_back(field); |
| 1240 | autofill_test::CreateTestFormField( |
| 1241 | "Last name:", "last_name", "Washington", "text", &field); |
| 1242 | form1.fields.push_back(field); |
| 1243 | autofill_test::CreateTestFormField( |
| 1244 | "Company:", "company", "Government", "text", &field); |
| 1245 | form1.fields.push_back(field); |
| 1246 | autofill_test::CreateTestFormField( |
| 1247 | "Email:", "email", "[email protected]", "text", &field); |
| 1248 | form1.fields.push_back(field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1249 | autofill_test::CreateTestFormField( |
| 1250 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1251 | form1.fields.push_back(field); |
| 1252 | autofill_test::CreateTestFormField( |
| 1253 | "City:", "city", "Philadelphia", "text", &field); |
| 1254 | form1.fields.push_back(field); |
| 1255 | autofill_test::CreateTestFormField( |
| 1256 | "State:", "state", "Pennsylvania", "text", &field); |
| 1257 | form1.fields.push_back(field); |
| 1258 | autofill_test::CreateTestFormField( |
| 1259 | "Zip:", "zipcode", "19106", "text", &field); |
| 1260 | form1.fields.push_back(field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1261 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1262 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1263 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1264 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1265 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1266 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1267 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1268 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1269 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1270 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1271 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1272 | MessageLoop::current()->Run(); |
| 1273 | |
[email protected] | e90c225 | 2011-03-10 12:29:21 | [diff] [blame] | 1274 | AutofillProfile expected; |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1275 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1276 | "Washington", "[email protected]", "Government", "190 High Street", NULL, |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1277 | "Philadelphia", "Pennsylvania", "19106", NULL, NULL); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1278 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1279 | ASSERT_EQ(1U, results1.size()); |
| 1280 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
| 1281 | |
| 1282 | // Submit a form with new data for the first profile. |
| 1283 | FormData form2; |
| 1284 | autofill_test::CreateTestFormField( |
| 1285 | "First name:", "first_name", "George", "text", &field); |
| 1286 | form2.fields.push_back(field); |
| 1287 | autofill_test::CreateTestFormField( |
| 1288 | "Last name:", "last_name", "Washington", "text", &field); |
| 1289 | form2.fields.push_back(field); |
| 1290 | // Note missing Company field. |
| 1291 | autofill_test::CreateTestFormField( |
| 1292 | "Email:", "email", "[email protected]", "text", &field); |
| 1293 | form2.fields.push_back(field); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1294 | autofill_test::CreateTestFormField( |
| 1295 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1296 | form2.fields.push_back(field); |
| 1297 | autofill_test::CreateTestFormField( |
| 1298 | "City:", "city", "Philadelphia", "text", &field); |
| 1299 | form2.fields.push_back(field); |
| 1300 | autofill_test::CreateTestFormField( |
| 1301 | "State:", "state", "Pennsylvania", "text", &field); |
| 1302 | form2.fields.push_back(field); |
| 1303 | autofill_test::CreateTestFormField( |
| 1304 | "Zip:", "zipcode", "19106", "text", &field); |
| 1305 | form2.fields.push_back(field); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1306 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1307 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1308 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1309 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1310 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1311 | ASSERT_FALSE(imported_credit_card); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1312 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1313 | // Verify that the web database has been updated and the notification sent. |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1314 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1315 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1316 | MessageLoop::current()->Run(); |
| 1317 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1318 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | f1ed727 | 2010-11-11 21:57:07 | [diff] [blame] | 1319 | |
| 1320 | // Expect no change. |
| 1321 | ASSERT_EQ(1U, results2.size()); |
| 1322 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 1323 | } |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1324 | |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1325 | TEST_F(PersonalDataManagerTest, AggregateProfileWithInsufficientAddress) { |
| 1326 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1327 | FormFieldData field; |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1328 | autofill_test::CreateTestFormField( |
| 1329 | "First name:", "first_name", "George", "text", &field); |
| 1330 | form1.fields.push_back(field); |
| 1331 | autofill_test::CreateTestFormField( |
| 1332 | "Last name:", "last_name", "Washington", "text", &field); |
| 1333 | form1.fields.push_back(field); |
| 1334 | autofill_test::CreateTestFormField( |
| 1335 | "Company:", "company", "Government", "text", &field); |
| 1336 | form1.fields.push_back(field); |
| 1337 | autofill_test::CreateTestFormField( |
| 1338 | "Email:", "email", "[email protected]", "text", &field); |
| 1339 | form1.fields.push_back(field); |
| 1340 | autofill_test::CreateTestFormField( |
| 1341 | "Address Line 1:", "address", "190 High Street", "text", &field); |
| 1342 | form1.fields.push_back(field); |
| 1343 | autofill_test::CreateTestFormField( |
| 1344 | "City:", "city", "Philadelphia", "text", &field); |
| 1345 | form1.fields.push_back(field); |
| 1346 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1347 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1348 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1349 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1350 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure1, |
| 1351 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1352 | ASSERT_FALSE(imported_credit_card); |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 1353 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1354 | // Note: no refresh here. |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 1355 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 1356 | const std::vector<AutofillProfile*>& profiles = personal_data_->GetProfiles(); |
[email protected] | 414c3548 | 2011-02-09 01:26:13 | [diff] [blame] | 1357 | ASSERT_EQ(0U, profiles.size()); |
| 1358 | const std::vector<CreditCard*>& credit_cards = personal_data_->credit_cards(); |
| 1359 | ASSERT_EQ(0U, credit_cards.size()); |
[email protected] | 37ff612e | 2011-02-03 15:54:52 | [diff] [blame] | 1360 | } |
| 1361 | |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1362 | TEST_F(PersonalDataManagerTest, AggregateExistingAuxiliaryProfile) { |
| 1363 | // Simulate having access to an auxiliary profile. |
| 1364 | // |auxiliary_profile| will be owned by |personal_data_|. |
| 1365 | AutofillProfile* auxiliary_profile = new AutofillProfile; |
| 1366 | autofill_test::SetProfileInfo(auxiliary_profile, |
| 1367 | "Tester", "Frederick", "McAddressBookTesterson", |
| 1368 | "[email protected]", "Acme Inc.", "1 Main", "Apt A", "San Francisco", |
[email protected] | 91b073d | 2013-01-05 01:30:28 | [diff] [blame] | 1369 | "CA", "94102", "US", "1.415.888.9999"); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1370 | ScopedVector<AutofillProfile>& auxiliary_profiles = |
| 1371 | personal_data_->auxiliary_profiles_; |
| 1372 | auxiliary_profiles.push_back(auxiliary_profile); |
| 1373 | |
| 1374 | // Simulate a form submission with a subset of the info. |
| 1375 | // Note that the phone number format is different from the saved format. |
| 1376 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1377 | FormFieldData field; |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1378 | autofill_test::CreateTestFormField( |
| 1379 | "First name:", "first_name", "Tester", "text", &field); |
| 1380 | form.fields.push_back(field); |
| 1381 | autofill_test::CreateTestFormField( |
| 1382 | "Last name:", "last_name", "McAddressBookTesterson", "text", &field); |
| 1383 | form.fields.push_back(field); |
| 1384 | autofill_test::CreateTestFormField( |
| 1385 | "Email:", "email", "[email protected]", "text", &field); |
| 1386 | form.fields.push_back(field); |
| 1387 | autofill_test::CreateTestFormField( |
| 1388 | "Address:", "address1", "1 Main", "text", &field); |
| 1389 | form.fields.push_back(field); |
| 1390 | autofill_test::CreateTestFormField( |
| 1391 | "City:", "city", "San Francisco", "text", &field); |
| 1392 | form.fields.push_back(field); |
| 1393 | autofill_test::CreateTestFormField( |
| 1394 | "State:", "state", "CA", "text", &field); |
| 1395 | form.fields.push_back(field); |
| 1396 | autofill_test::CreateTestFormField( |
| 1397 | "Zip:", "zip", "94102", "text", &field); |
| 1398 | form.fields.push_back(field); |
| 1399 | autofill_test::CreateTestFormField( |
| 1400 | "Phone:", "phone", "4158889999", "text", &field); |
| 1401 | form.fields.push_back(field); |
| 1402 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1403 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1404 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 0b584761 | 2011-10-05 03:52:18 | [diff] [blame] | 1405 | const CreditCard* imported_credit_card; |
| 1406 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 1407 | &imported_credit_card)); |
| 1408 | EXPECT_FALSE(imported_credit_card); |
| 1409 | |
| 1410 | // Note: No refresh. |
| 1411 | |
| 1412 | // Expect no change. |
| 1413 | const std::vector<AutofillProfile*>& web_profiles = |
| 1414 | personal_data_->web_profiles(); |
| 1415 | EXPECT_EQ(0U, web_profiles.size()); |
| 1416 | ASSERT_EQ(1U, auxiliary_profiles.size()); |
| 1417 | EXPECT_EQ(0, auxiliary_profile->Compare(*auxiliary_profiles[0])); |
| 1418 | } |
| 1419 | |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1420 | TEST_F(PersonalDataManagerTest, AggregateTwoDifferentCreditCards) { |
| 1421 | FormData form1; |
| 1422 | |
| 1423 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1424 | FormFieldData field; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1425 | autofill_test::CreateTestFormField( |
| 1426 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1427 | form1.fields.push_back(field); |
| 1428 | autofill_test::CreateTestFormField( |
| 1429 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1430 | form1.fields.push_back(field); |
| 1431 | autofill_test::CreateTestFormField( |
| 1432 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1433 | form1.fields.push_back(field); |
| 1434 | autofill_test::CreateTestFormField( |
| 1435 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1436 | form1.fields.push_back(field); |
| 1437 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1438 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1439 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1440 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1441 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1442 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1443 | ASSERT_TRUE(imported_credit_card); |
| 1444 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1445 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1446 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1447 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1448 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1449 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1450 | MessageLoop::current()->Run(); |
| 1451 | |
| 1452 | CreditCard expected; |
| 1453 | autofill_test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1454 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1455 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 1456 | ASSERT_EQ(1U, results.size()); |
| 1457 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1458 | |
| 1459 | // Add a second different valid credit card. |
| 1460 | FormData form2; |
| 1461 | autofill_test::CreateTestFormField( |
[email protected] | 490a6a50 | 2011-09-27 17:30:11 | [diff] [blame] | 1462 | "Name on card:", "name_on_card", "", "text", &field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1463 | form2.fields.push_back(field); |
| 1464 | autofill_test::CreateTestFormField( |
| 1465 | "Card Number:", "card_number", "5500 0000 0000 0004", "text", &field); |
| 1466 | form2.fields.push_back(field); |
| 1467 | autofill_test::CreateTestFormField( |
| 1468 | "Exp Month:", "exp_month", "02", "text", &field); |
| 1469 | form2.fields.push_back(field); |
| 1470 | autofill_test::CreateTestFormField( |
| 1471 | "Exp Year:", "exp_year", "2012", "text", &field); |
| 1472 | form2.fields.push_back(field); |
| 1473 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1474 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1475 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1476 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1477 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1478 | ASSERT_TRUE(imported_credit_card); |
| 1479 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1480 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1481 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1482 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1483 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1484 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1485 | MessageLoop::current()->Run(); |
| 1486 | |
| 1487 | CreditCard expected2; |
| 1488 | autofill_test::SetCreditCardInfo(&expected2, |
[email protected] | 490a6a50 | 2011-09-27 17:30:11 | [diff] [blame] | 1489 | "", "5500000000000004", "02", "2012"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1490 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1491 | ASSERT_EQ(2U, results2.size()); |
| 1492 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 1493 | EXPECT_EQ(0, expected2.Compare(*results2[1])); |
| 1494 | } |
| 1495 | |
| 1496 | TEST_F(PersonalDataManagerTest, AggregateInvalidCreditCard) { |
| 1497 | FormData form1; |
| 1498 | |
| 1499 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1500 | FormFieldData field; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1501 | autofill_test::CreateTestFormField( |
| 1502 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1503 | form1.fields.push_back(field); |
| 1504 | autofill_test::CreateTestFormField( |
| 1505 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1506 | form1.fields.push_back(field); |
| 1507 | autofill_test::CreateTestFormField( |
| 1508 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1509 | form1.fields.push_back(field); |
| 1510 | autofill_test::CreateTestFormField( |
| 1511 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1512 | form1.fields.push_back(field); |
| 1513 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1514 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1515 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1516 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1517 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1518 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1519 | ASSERT_TRUE(imported_credit_card); |
| 1520 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1521 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1522 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1523 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1524 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1525 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1526 | MessageLoop::current()->Run(); |
| 1527 | |
| 1528 | CreditCard expected; |
| 1529 | autofill_test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1530 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1531 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 1532 | ASSERT_EQ(1U, results.size()); |
| 1533 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1534 | |
| 1535 | // Add a second different invalid credit card. |
| 1536 | FormData form2; |
| 1537 | autofill_test::CreateTestFormField( |
| 1538 | "Name on card:", "name_on_card", "Jim Johansen", "text", &field); |
| 1539 | form2.fields.push_back(field); |
| 1540 | autofill_test::CreateTestFormField( |
| 1541 | "Card Number:", "card_number", "1000000000000000", "text", &field); |
| 1542 | form2.fields.push_back(field); |
| 1543 | autofill_test::CreateTestFormField( |
| 1544 | "Exp Month:", "exp_month", "02", "text", &field); |
| 1545 | form2.fields.push_back(field); |
| 1546 | autofill_test::CreateTestFormField( |
| 1547 | "Exp Year:", "exp_year", "2012", "text", &field); |
| 1548 | form2.fields.push_back(field); |
| 1549 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1550 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1551 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1552 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
| 1553 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1554 | ASSERT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1555 | |
| 1556 | // Note: no refresh here. |
| 1557 | |
| 1558 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1559 | ASSERT_EQ(1U, results2.size()); |
| 1560 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
| 1561 | } |
| 1562 | |
| 1563 | TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithConflict) { |
| 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] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1568 | autofill_test::CreateTestFormField( |
| 1569 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1570 | form1.fields.push_back(field); |
| 1571 | autofill_test::CreateTestFormField( |
| 1572 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1573 | form1.fields.push_back(field); |
| 1574 | autofill_test::CreateTestFormField( |
| 1575 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1576 | form1.fields.push_back(field); |
| 1577 | autofill_test::CreateTestFormField( |
| 1578 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1579 | form1.fields.push_back(field); |
| 1580 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1581 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1582 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1583 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1584 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1585 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1586 | ASSERT_TRUE(imported_credit_card); |
| 1587 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1588 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1589 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1590 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1591 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1592 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1593 | MessageLoop::current()->Run(); |
| 1594 | |
| 1595 | CreditCard expected; |
| 1596 | autofill_test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1597 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1598 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 1599 | ASSERT_EQ(1U, results.size()); |
| 1600 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1601 | |
| 1602 | // Add a second different valid credit card where the year is different but |
| 1603 | // the credit card number matches. |
| 1604 | FormData form2; |
| 1605 | autofill_test::CreateTestFormField( |
| 1606 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1607 | form2.fields.push_back(field); |
| 1608 | autofill_test::CreateTestFormField( |
| 1609 | "Card Number:", "card_number", "4111 1111 1111 1111", "text", &field); |
| 1610 | form2.fields.push_back(field); |
| 1611 | autofill_test::CreateTestFormField( |
| 1612 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1613 | form2.fields.push_back(field); |
| 1614 | autofill_test::CreateTestFormField( |
| 1615 | "Exp Year:", "exp_year", "2012", "text", &field); |
| 1616 | form2.fields.push_back(field); |
| 1617 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1618 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1619 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1620 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1621 | &imported_credit_card)); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1622 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1623 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1624 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1625 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1626 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1627 | MessageLoop::current()->Run(); |
| 1628 | |
| 1629 | // Expect that the newer information is saved. In this case the year is |
| 1630 | // updated to "2012". |
| 1631 | CreditCard expected2; |
| 1632 | autofill_test::SetCreditCardInfo(&expected2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1633 | "Biggie Smalls", "4111111111111111", "01", "2012"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1634 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1635 | ASSERT_EQ(1U, results2.size()); |
| 1636 | EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1637 | } |
| 1638 | |
| 1639 | TEST_F(PersonalDataManagerTest, AggregateEmptyCreditCardWithConflict) { |
| 1640 | FormData form1; |
| 1641 | |
| 1642 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1643 | FormFieldData field; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1644 | autofill_test::CreateTestFormField( |
| 1645 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1646 | form1.fields.push_back(field); |
| 1647 | autofill_test::CreateTestFormField( |
| 1648 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1649 | form1.fields.push_back(field); |
| 1650 | autofill_test::CreateTestFormField( |
| 1651 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1652 | form1.fields.push_back(field); |
| 1653 | autofill_test::CreateTestFormField( |
| 1654 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1655 | form1.fields.push_back(field); |
| 1656 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1657 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1658 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1659 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1660 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1661 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1662 | ASSERT_TRUE(imported_credit_card); |
| 1663 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1664 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1665 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1666 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1667 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1668 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1669 | MessageLoop::current()->Run(); |
| 1670 | |
| 1671 | CreditCard expected; |
| 1672 | autofill_test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1673 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1674 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 1675 | ASSERT_EQ(1U, results.size()); |
| 1676 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1677 | |
| 1678 | // Add a second credit card with no number. |
| 1679 | FormData form2; |
| 1680 | autofill_test::CreateTestFormField( |
| 1681 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1682 | form2.fields.push_back(field); |
| 1683 | autofill_test::CreateTestFormField( |
| 1684 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1685 | form2.fields.push_back(field); |
| 1686 | autofill_test::CreateTestFormField( |
| 1687 | "Exp Year:", "exp_year", "2012", "text", &field); |
| 1688 | form2.fields.push_back(field); |
| 1689 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1690 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1691 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1692 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure2, |
| 1693 | &imported_credit_card)); |
[email protected] | 3e6e82da | 2011-04-06 05:41:34 | [diff] [blame] | 1694 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1695 | |
| 1696 | // Note: no refresh here. |
| 1697 | |
| 1698 | // No change is expected. |
| 1699 | CreditCard expected2; |
| 1700 | autofill_test::SetCreditCardInfo(&expected2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1701 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1702 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1703 | ASSERT_EQ(1U, results2.size()); |
| 1704 | EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1705 | } |
| 1706 | |
| 1707 | TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInNew) { |
| 1708 | FormData form1; |
| 1709 | |
| 1710 | // Start with a single valid credit card form. |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1711 | FormFieldData field; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1712 | autofill_test::CreateTestFormField( |
| 1713 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1714 | form1.fields.push_back(field); |
| 1715 | autofill_test::CreateTestFormField( |
| 1716 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1717 | form1.fields.push_back(field); |
| 1718 | autofill_test::CreateTestFormField( |
| 1719 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1720 | form1.fields.push_back(field); |
| 1721 | autofill_test::CreateTestFormField( |
| 1722 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1723 | form1.fields.push_back(field); |
| 1724 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1725 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1726 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1727 | const CreditCard* imported_credit_card; |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1728 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 1729 | &imported_credit_card)); |
[email protected] | abcdf1a | 2011-02-04 23:12:24 | [diff] [blame] | 1730 | ASSERT_TRUE(imported_credit_card); |
| 1731 | personal_data_->SaveImportedCreditCard(*imported_credit_card); |
| 1732 | delete imported_credit_card; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1733 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1734 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1735 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1736 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1737 | MessageLoop::current()->Run(); |
| 1738 | |
| 1739 | CreditCard expected; |
| 1740 | autofill_test::SetCreditCardInfo(&expected, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1741 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1742 | const std::vector<CreditCard*>& results = personal_data_->credit_cards(); |
| 1743 | ASSERT_EQ(1U, results.size()); |
| 1744 | EXPECT_EQ(0, expected.Compare(*results[0])); |
| 1745 | |
| 1746 | // Add a second different valid credit card where the name is missing but |
| 1747 | // the credit card number matches. |
| 1748 | FormData form2; |
| 1749 | // Note missing name. |
| 1750 | autofill_test::CreateTestFormField( |
| 1751 | "Card Number:", "card_number", "4111111111111111", "text", &field); |
| 1752 | form2.fields.push_back(field); |
| 1753 | autofill_test::CreateTestFormField( |
| 1754 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1755 | form2.fields.push_back(field); |
| 1756 | autofill_test::CreateTestFormField( |
| 1757 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1758 | form2.fields.push_back(field); |
| 1759 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1760 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1761 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1762 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 1763 | &imported_credit_card)); |
| 1764 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1765 | |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1766 | // Wait for the refresh, which in this case is a no-op. |
| 1767 | EXPECT_CALL(personal_data_observer_, |
| 1768 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1769 | MessageLoop::current()->Run(); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1770 | |
| 1771 | // No change is expected. |
| 1772 | CreditCard expected2; |
| 1773 | autofill_test::SetCreditCardInfo(&expected2, |
[email protected] | 027dd44 | 2011-02-15 23:17:34 | [diff] [blame] | 1774 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1775 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1776 | ASSERT_EQ(1U, results2.size()); |
| 1777 | EXPECT_EQ(0, expected2.Compare(*results2[0])); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1778 | |
| 1779 | // Add a third credit card where the expiration date is missing. |
| 1780 | FormData form3; |
| 1781 | autofill_test::CreateTestFormField( |
| 1782 | "Name on card:", "name_on_card", "Johnny McEnroe", "text", &field); |
| 1783 | form3.fields.push_back(field); |
| 1784 | autofill_test::CreateTestFormField( |
| 1785 | "Card Number:", "card_number", "5555555555554444", "text", &field); |
| 1786 | form3.fields.push_back(field); |
| 1787 | // Note missing expiration month and year.. |
| 1788 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1789 | FormStructure form_structure3(form3, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1790 | form_structure3.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1791 | EXPECT_FALSE(personal_data_->ImportFormData(form_structure3, |
| 1792 | &imported_credit_card)); |
| 1793 | ASSERT_FALSE(imported_credit_card); |
| 1794 | |
| 1795 | // Note: no refresh here. |
| 1796 | |
| 1797 | // No change is expected. |
| 1798 | CreditCard expected3; |
| 1799 | autofill_test::SetCreditCardInfo(&expected3, |
| 1800 | "Biggie Smalls", "4111111111111111", "01", "2011"); |
| 1801 | const std::vector<CreditCard*>& results3 = personal_data_->credit_cards(); |
| 1802 | ASSERT_EQ(1U, results3.size()); |
| 1803 | EXPECT_EQ(0, expected3.Compare(*results2[0])); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | TEST_F(PersonalDataManagerTest, AggregateCreditCardWithMissingInfoInOld) { |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1807 | // Start with a single valid credit card stored via the preferences. |
| 1808 | // Note the empty name. |
| 1809 | CreditCard saved_credit_card; |
| 1810 | autofill_test::SetCreditCardInfo(&saved_credit_card, |
| 1811 | "", "4111111111111111" /* Visa */, "01", "2011"); |
| 1812 | personal_data_->AddCreditCard(saved_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1813 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1814 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1815 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1816 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1817 | MessageLoop::current()->Run(); |
| 1818 | |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1819 | const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); |
| 1820 | ASSERT_EQ(1U, results1.size()); |
| 1821 | EXPECT_EQ(saved_credit_card, *results1[0]); |
| 1822 | |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1823 | |
| 1824 | // Add a second different valid credit card where the year is different but |
| 1825 | // the credit card number matches. |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1826 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1827 | FormFieldData field; |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1828 | autofill_test::CreateTestFormField( |
| 1829 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1830 | form.fields.push_back(field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1831 | autofill_test::CreateTestFormField( |
| 1832 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1833 | form.fields.push_back(field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1834 | autofill_test::CreateTestFormField( |
| 1835 | "Exp Month:", "exp_month", "01", "text", &field); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1836 | form.fields.push_back(field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1837 | autofill_test::CreateTestFormField( |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1838 | "Exp Year:", "exp_year", "2012", "text", &field); |
| 1839 | form.fields.push_back(field); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1840 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1841 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1842 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1843 | const CreditCard* imported_credit_card; |
| 1844 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
[email protected] | 2a95855 | 2011-05-05 04:01:21 | [diff] [blame] | 1845 | &imported_credit_card)); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1846 | EXPECT_FALSE(imported_credit_card); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1847 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1848 | // Verify that the web database has been updated and the notification sent. |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1849 | EXPECT_CALL(personal_data_observer_, |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1850 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1851 | MessageLoop::current()->Run(); |
| 1852 | |
| 1853 | // Expect that the newer information is saved. In this case the year is |
| 1854 | // added to the existing credit card. |
| 1855 | CreditCard expected2; |
| 1856 | autofill_test::SetCreditCardInfo(&expected2, |
[email protected] | cdd0d448 | 2011-07-22 04:24:22 | [diff] [blame] | 1857 | "Biggie Smalls", "4111111111111111", "01", "2012"); |
[email protected] | d7da65d | 2010-11-11 19:26:05 | [diff] [blame] | 1858 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1859 | ASSERT_EQ(1U, results2.size()); |
| 1860 | EXPECT_EQ(0, expected2.Compare(*results2[0])); |
| 1861 | } |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1862 | |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1863 | // We allow the user to store a credit card number with separators via the UI. |
| 1864 | // We should not try to re-aggregate the same card with the separators stripped. |
| 1865 | TEST_F(PersonalDataManagerTest, AggregateSameCreditCardWithSeparators) { |
| 1866 | // Start with a single valid credit card stored via the preferences. |
| 1867 | // Note the separators in the credit card number. |
| 1868 | CreditCard saved_credit_card; |
| 1869 | autofill_test::SetCreditCardInfo(&saved_credit_card, |
| 1870 | "Biggie Smalls", "4111 1111 1111 1111" /* Visa */, "01", "2011"); |
| 1871 | personal_data_->AddCreditCard(saved_credit_card); |
| 1872 | |
| 1873 | // Verify that the web database has been updated and the notification sent. |
| 1874 | EXPECT_CALL(personal_data_observer_, |
| 1875 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1876 | MessageLoop::current()->Run(); |
| 1877 | |
| 1878 | const std::vector<CreditCard*>& results1 = personal_data_->credit_cards(); |
| 1879 | ASSERT_EQ(1U, results1.size()); |
| 1880 | EXPECT_EQ(0, saved_credit_card.Compare(*results1[0])); |
| 1881 | |
| 1882 | // Import the same card info, but with different separators in the number. |
| 1883 | FormData form; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 1884 | FormFieldData field; |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1885 | autofill_test::CreateTestFormField( |
| 1886 | "Name on card:", "name_on_card", "Biggie Smalls", "text", &field); |
| 1887 | form.fields.push_back(field); |
| 1888 | autofill_test::CreateTestFormField( |
| 1889 | "Card Number:", "card_number", "4111-1111-1111-1111", "text", &field); |
| 1890 | form.fields.push_back(field); |
| 1891 | autofill_test::CreateTestFormField( |
| 1892 | "Exp Month:", "exp_month", "01", "text", &field); |
| 1893 | form.fields.push_back(field); |
| 1894 | autofill_test::CreateTestFormField( |
| 1895 | "Exp Year:", "exp_year", "2011", "text", &field); |
| 1896 | form.fields.push_back(field); |
| 1897 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 1898 | FormStructure form_structure(form, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 1899 | form_structure.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | e5f5cf7 | 2011-10-04 22:18:06 | [diff] [blame] | 1900 | const CreditCard* imported_credit_card; |
| 1901 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure, |
| 1902 | &imported_credit_card)); |
| 1903 | EXPECT_FALSE(imported_credit_card); |
| 1904 | |
| 1905 | // Wait for the refresh, which in this case is a no-op. |
| 1906 | EXPECT_CALL(personal_data_observer_, |
| 1907 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1908 | MessageLoop::current()->Run(); |
| 1909 | |
| 1910 | // Expect that no new card is saved. |
| 1911 | const std::vector<CreditCard*>& results2 = personal_data_->credit_cards(); |
| 1912 | ASSERT_EQ(1U, results2.size()); |
| 1913 | EXPECT_EQ(0, saved_credit_card.Compare(*results2[0])); |
| 1914 | } |
| 1915 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1916 | TEST_F(PersonalDataManagerTest, GetNonEmptyTypes) { |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1917 | // Check that there are no available types with no profiles stored. |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1918 | FieldTypeSet non_empty_types; |
| 1919 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
| 1920 | EXPECT_EQ(0U, non_empty_types.size()); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1921 | |
| 1922 | // Test with one profile stored. |
| 1923 | AutofillProfile profile0; |
| 1924 | autofill_test::SetProfileInfo(&profile0, |
| 1925 | "Marion", NULL, "Morrison", |
| 1926 | "[email protected]", NULL, "123 Zoo St.", NULL, "Hollywood", "CA", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1927 | "91601", "US", "14155678910"); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1928 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1929 | personal_data_->AddProfile(profile0); |
| 1930 | |
| 1931 | // Verify that the web database has been updated and the notification sent. |
| 1932 | EXPECT_CALL(personal_data_observer_, |
| 1933 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1934 | MessageLoop::current()->Run(); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1935 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1936 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 1937 | EXPECT_EQ(14U, non_empty_types.size()); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1938 | EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
| 1939 | EXPECT_TRUE(non_empty_types.count(NAME_LAST)); |
| 1940 | EXPECT_TRUE(non_empty_types.count(NAME_FULL)); |
| 1941 | EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); |
| 1942 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); |
| 1943 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); |
| 1944 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE)); |
| 1945 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); |
| 1946 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); |
| 1947 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 1948 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1949 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); |
| 1950 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); |
| 1951 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1952 | |
| 1953 | // Test with multiple profiles stored. |
| 1954 | AutofillProfile profile1; |
| 1955 | autofill_test::SetProfileInfo(&profile1, |
| 1956 | "Josephine", "Alicia", "Saenz", |
| 1957 | "[email protected]", "Fox", "903 Apple Ct.", NULL, "Orlando", "FL", "32801", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1958 | "US", "16502937549"); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1959 | |
| 1960 | AutofillProfile profile2; |
| 1961 | autofill_test::SetProfileInfo(&profile2, |
| 1962 | "Josephine", "Alicia", "Saenz", |
| 1963 | "[email protected]", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1964 | "32801", "US", "16502937549"); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1965 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 1966 | personal_data_->AddProfile(profile1); |
| 1967 | personal_data_->AddProfile(profile2); |
| 1968 | |
| 1969 | // Verify that the web database has been updated and the notification sent. |
| 1970 | EXPECT_CALL(personal_data_observer_, |
| 1971 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 1972 | MessageLoop::current()->Run(); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1973 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1974 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 1975 | EXPECT_EQ(18U, non_empty_types.size()); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 1976 | EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
| 1977 | EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); |
| 1978 | EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); |
| 1979 | EXPECT_TRUE(non_empty_types.count(NAME_LAST)); |
| 1980 | EXPECT_TRUE(non_empty_types.count(NAME_FULL)); |
| 1981 | EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); |
| 1982 | EXPECT_TRUE(non_empty_types.count(COMPANY_NAME)); |
| 1983 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); |
| 1984 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2)); |
| 1985 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); |
| 1986 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE)); |
| 1987 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); |
| 1988 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); |
| 1989 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); |
| 1990 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); |
| 1991 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); |
| 1992 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); |
| 1993 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 1994 | |
| 1995 | // Test with credit card information also stored. |
| 1996 | CreditCard credit_card; |
| 1997 | autofill_test::SetCreditCardInfo(&credit_card, |
| 1998 | "John Dillinger", "423456789012" /* Visa */, |
| 1999 | "01", "2010"); |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 2000 | personal_data_->AddCreditCard(credit_card); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 2001 | |
[email protected] | 3813dec | 2011-05-11 20:56:36 | [diff] [blame] | 2002 | // Verify that the web database has been updated and the notification sent. |
| 2003 | EXPECT_CALL(personal_data_observer_, |
| 2004 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 2005 | MessageLoop::current()->Run(); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 2006 | |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 2007 | personal_data_->GetNonEmptyTypes(&non_empty_types); |
[email protected] | 4ef55f8c1 | 2011-09-17 00:06:54 | [diff] [blame] | 2008 | EXPECT_EQ(25U, non_empty_types.size()); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 2009 | EXPECT_TRUE(non_empty_types.count(NAME_FIRST)); |
| 2010 | EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE)); |
| 2011 | EXPECT_TRUE(non_empty_types.count(NAME_MIDDLE_INITIAL)); |
| 2012 | EXPECT_TRUE(non_empty_types.count(NAME_LAST)); |
| 2013 | EXPECT_TRUE(non_empty_types.count(NAME_FULL)); |
| 2014 | EXPECT_TRUE(non_empty_types.count(EMAIL_ADDRESS)); |
| 2015 | EXPECT_TRUE(non_empty_types.count(COMPANY_NAME)); |
| 2016 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE1)); |
| 2017 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_LINE2)); |
| 2018 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_CITY)); |
| 2019 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_STATE)); |
| 2020 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_ZIP)); |
| 2021 | EXPECT_TRUE(non_empty_types.count(ADDRESS_HOME_COUNTRY)); |
| 2022 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_NUMBER)); |
| 2023 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_CODE)); |
| 2024 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_COUNTRY_CODE)); |
| 2025 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_CITY_AND_NUMBER)); |
| 2026 | EXPECT_TRUE(non_empty_types.count(PHONE_HOME_WHOLE_NUMBER)); |
[email protected] | 1308c283 | 2011-05-09 18:30:23 | [diff] [blame] | 2027 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NAME)); |
| 2028 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_NUMBER)); |
| 2029 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_MONTH)); |
| 2030 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_2_DIGIT_YEAR)); |
| 2031 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 2032 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR)); |
| 2033 | EXPECT_TRUE(non_empty_types.count(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR)); |
[email protected] | ca64d23 | 2011-05-06 05:46:00 | [diff] [blame] | 2034 | } |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2035 | |
| 2036 | TEST_F(PersonalDataManagerTest, CaseInsensitiveMultiValueAggregation) { |
| 2037 | FormData form1; |
[email protected] | 1ecbe86 | 2012-10-05 01:29:14 | [diff] [blame] | 2038 | FormFieldData field; |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2039 | autofill_test::CreateTestFormField( |
| 2040 | "First name:", "first_name", "George", "text", &field); |
| 2041 | form1.fields.push_back(field); |
| 2042 | autofill_test::CreateTestFormField( |
| 2043 | "Last name:", "last_name", "Washington", "text", &field); |
| 2044 | form1.fields.push_back(field); |
| 2045 | autofill_test::CreateTestFormField( |
| 2046 | "Email:", "email", "[email protected]", "text", &field); |
| 2047 | form1.fields.push_back(field); |
| 2048 | autofill_test::CreateTestFormField( |
| 2049 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 2050 | form1.fields.push_back(field); |
| 2051 | autofill_test::CreateTestFormField( |
| 2052 | "City:", "city", "San Francisco", "text", &field); |
| 2053 | form1.fields.push_back(field); |
| 2054 | autofill_test::CreateTestFormField( |
| 2055 | "State:", "state", "California", "text", &field); |
| 2056 | form1.fields.push_back(field); |
| 2057 | autofill_test::CreateTestFormField( |
| 2058 | "Zip:", "zip", "94102", "text", &field); |
| 2059 | form1.fields.push_back(field); |
| 2060 | autofill_test::CreateTestFormField( |
| 2061 | "Phone number:", "phone_number", "817-555-6789", "text", &field); |
| 2062 | form1.fields.push_back(field); |
| 2063 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 2064 | FormStructure form_structure1(form1, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 2065 | form_structure1.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2066 | const CreditCard* imported_credit_card; |
| 2067 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure1, |
| 2068 | &imported_credit_card)); |
| 2069 | ASSERT_FALSE(imported_credit_card); |
| 2070 | |
| 2071 | // Verify that the web database has been updated and the notification sent. |
| 2072 | EXPECT_CALL(personal_data_observer_, |
| 2073 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 2074 | MessageLoop::current()->Run(); |
| 2075 | |
| 2076 | AutofillProfile expected; |
| 2077 | autofill_test::SetProfileInfo(&expected, "George", NULL, |
| 2078 | "Washington", "[email protected]", NULL, "21 Laussat St", NULL, |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 2079 | "San Francisco", "California", "94102", NULL, "(817) 555-6789"); |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 2080 | const std::vector<AutofillProfile*>& results1 = personal_data_->GetProfiles(); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2081 | ASSERT_EQ(1U, results1.size()); |
| 2082 | EXPECT_EQ(0, expected.Compare(*results1[0])); |
| 2083 | |
| 2084 | // Upper-case the first name and change the phone number. |
| 2085 | FormData form2; |
| 2086 | autofill_test::CreateTestFormField( |
| 2087 | "First name:", "first_name", "GEORGE", "text", &field); |
| 2088 | form2.fields.push_back(field); |
| 2089 | autofill_test::CreateTestFormField( |
| 2090 | "Last name:", "last_name", "Washington", "text", &field); |
| 2091 | form2.fields.push_back(field); |
| 2092 | autofill_test::CreateTestFormField( |
| 2093 | "Email:", "email", "[email protected]", "text", &field); |
| 2094 | form2.fields.push_back(field); |
| 2095 | autofill_test::CreateTestFormField( |
| 2096 | "Address:", "address1", "21 Laussat St", "text", &field); |
| 2097 | form2.fields.push_back(field); |
| 2098 | autofill_test::CreateTestFormField( |
| 2099 | "City:", "city", "San Francisco", "text", &field); |
| 2100 | form2.fields.push_back(field); |
| 2101 | autofill_test::CreateTestFormField( |
| 2102 | "State:", "state", "California", "text", &field); |
| 2103 | form2.fields.push_back(field); |
| 2104 | autofill_test::CreateTestFormField( |
| 2105 | "Zip:", "zip", "94102", "text", &field); |
| 2106 | form2.fields.push_back(field); |
| 2107 | autofill_test::CreateTestFormField( |
| 2108 | "Phone number:", "phone_number", "214-555-1234", "text", &field); |
| 2109 | form2.fields.push_back(field); |
| 2110 | |
[email protected] | 685d497 | 2013-02-12 01:06:23 | [diff] [blame] | 2111 | FormStructure form_structure2(form2, std::string()); |
[email protected] | dfd1818d | 2012-10-26 21:53:29 | [diff] [blame] | 2112 | form_structure2.DetermineHeuristicTypes(TestAutofillMetrics()); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2113 | EXPECT_TRUE(personal_data_->ImportFormData(form_structure2, |
| 2114 | &imported_credit_card)); |
| 2115 | ASSERT_FALSE(imported_credit_card); |
| 2116 | |
| 2117 | // Verify that the web database has been updated and the notification sent. |
| 2118 | EXPECT_CALL(personal_data_observer_, |
| 2119 | OnPersonalDataChanged()).WillOnce(QuitUIMessageLoop()); |
| 2120 | MessageLoop::current()->Run(); |
| 2121 | |
[email protected] | 771ad21 | 2012-11-29 18:58:33 | [diff] [blame] | 2122 | const std::vector<AutofillProfile*>& results2 = personal_data_->GetProfiles(); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2123 | |
| 2124 | // Modify expected to include multi-valued fields. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 2125 | std::vector<base::string16> values; |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 2126 | expected.GetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
[email protected] | 5c0208c | 2012-11-28 15:16:13 | [diff] [blame] | 2127 | values.push_back(ASCIIToUTF16("(214) 555-1234")); |
[email protected] | e436451 | 2012-11-29 10:51:06 | [diff] [blame] | 2128 | expected.SetRawMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2129 | |
| 2130 | ASSERT_EQ(1U, results2.size()); |
[email protected] | f2cd836 | 2012-01-23 22:34:00 | [diff] [blame] | 2131 | EXPECT_EQ(0, expected.Compare(*results2[0])); |
[email protected] | 343b4fd | 2011-08-15 19:32:39 | [diff] [blame] | 2132 | } |