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