Chromium Code Reviews| Index: chrome/browser/autofill/personal_data_manager_unittest.cc |
| diff --git a/chrome/browser/autofill/personal_data_manager_unittest.cc b/chrome/browser/autofill/personal_data_manager_unittest.cc |
| index 4c031b6d41ab29885eac16e39eeea34e4c33c444..81289ae7b192cb071d15d8a22832f07898b802ab 100644 |
| --- a/chrome/browser/autofill/personal_data_manager_unittest.cc |
| +++ b/chrome/browser/autofill/personal_data_manager_unittest.cc |
| @@ -87,6 +87,79 @@ class PersonalDataManagerTest : public testing::Test { |
| PersonalDataLoadedObserverMock personal_data_observer_; |
| }; |
| +TEST_F(PersonalDataManagerTest, AddProfile) { |
| + AutofillProfile profile0; |
| + autofill_test::SetProfileInfo(&profile0, |
| + "John", "Mitchell", "Smith", |
| + "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
| + "94102", "USA", "4158889999", "4152223333"); |
| + |
| + // This will verify that the web database has been loaded and the notification |
| + // sent out. |
| + EXPECT_CALL(personal_data_observer_, |
| + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| + |
| + // The message loop will exit when the mock observer is notified. |
| + MessageLoop::current()->Run(); |
|
Ilya Sherman
2011/04/27 23:32:43
nit: Please move lines 97-103 to the top of the fu
dhollowa
2011/04/28 00:08:46
Done.
|
| + |
| + // Add profile0 to the database. |
| + personal_data_->AddProfile(profile0); |
| + |
| + // Reload the database. |
| + ResetPersonalDataManager(); |
| + EXPECT_CALL(personal_data_observer_, |
| + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| + MessageLoop::current()->Run(); |
| + |
| + // Verify the addition. |
| + const std::vector<AutofillProfile*>& results1 = personal_data_->profiles(); |
| + ASSERT_EQ(1U, results1.size()); |
| + EXPECT_EQ(0, profile0.CompareMulti(*results1.at(0))); |
| + |
| + AutofillProfile profile0a; |
| + autofill_test::SetProfileInfo(&profile0a, |
| + "John", "Mitchell", "Smith", |
| + "j@s.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
| + "94102", "USA", "4158889999", "4152223333"); |
| + // Add profile with identical values. Duplicates should not get saved. |
| + personal_data_->AddProfile(profile0a); |
|
Ilya Sherman
2011/04/27 23:32:43
nit: Why not just """personal_data_->AddProfile(pr
dhollowa
2011/04/28 00:08:46
To ensure that the same guid values don't cause re
|
| + |
| + // Reload the database. |
| + ResetPersonalDataManager(); |
| + EXPECT_CALL(personal_data_observer_, |
| + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| + MessageLoop::current()->Run(); |
| + |
| + // Verify the non-addition. |
| + const std::vector<AutofillProfile*>& results2 = personal_data_->profiles(); |
| + ASSERT_EQ(1U, results2.size()); |
| + EXPECT_EQ(0, profile0.CompareMulti(*results2.at(0))); |
| + |
| + // New profile with different email. |
| + AutofillProfile profile1; |
| + autofill_test::SetProfileInfo(&profile1, |
| + "John", "Mitchell", "Smith", |
| + "john@smith.com", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", |
| + "94102", "USA", "4158889999", "4152223333"); |
|
Ilya Sherman
2011/04/27 23:32:43
nit: This would be tidier if written as:
Autofill
dhollowa
2011/04/28 00:08:46
Done. But the guid has to be accounted for.
|
| + |
| + // Add the different profile. This should save as a separate profile. |
| + // Note that if this same profile was "merged" it would collapse to one |
| + // profile with a multi-valued entry for email. |
| + personal_data_->AddProfile(profile1); |
| + |
| + // Reload the database. |
| + ResetPersonalDataManager(); |
| + EXPECT_CALL(personal_data_observer_, |
| + OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
| + MessageLoop::current()->Run(); |
| + |
| + // Verify the addition. |
| + const std::vector<AutofillProfile*>& results3 = personal_data_->profiles(); |
| + ASSERT_EQ(2U, results3.size()); |
| + EXPECT_EQ(0, profile0.CompareMulti(*results3.at(0))); |
| + EXPECT_EQ(0, profile1.CompareMulti(*results3.at(1))); |
| +} |
| + |
| // TODO(jhawkins): Test SetProfiles w/out a WebDataService in the profile. |
| TEST_F(PersonalDataManagerTest, SetProfiles) { |
| AutofillProfile profile0; |