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