OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "chrome/browser/autofill/autofill_common_unittest.h" | 9 #include "chrome/browser/autofill/autofill_common_unittest.h" |
10 #include "chrome/browser/autofill/autofill_profile.h" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // Determine uniqueness by inserting all of the IDs into a set and verifying | 327 // Determine uniqueness by inserting all of the IDs into a set and verifying |
328 // the size of the set matches the number of IDs. | 328 // the size of the set matches the number of IDs. |
329 std::set<int> ids; | 329 std::set<int> ids; |
330 ids.insert(profile0.unique_id()); | 330 ids.insert(profile0.unique_id()); |
331 ids.insert(profile1.unique_id()); | 331 ids.insert(profile1.unique_id()); |
332 ids.insert(creditcard0.unique_id()); | 332 ids.insert(creditcard0.unique_id()); |
333 ids.insert(creditcard1.unique_id()); | 333 ids.insert(creditcard1.unique_id()); |
334 EXPECT_EQ(4U, ids.size()); | 334 EXPECT_EQ(4U, ids.size()); |
335 } | 335 } |
336 | 336 |
| 337 // Test care for 50047. Makes sure that unique_ids_ is populated correctly on |
| 338 // load. |
| 339 TEST_F(PersonalDataManagerTest, PopulateUniqueIDsOnLoad) { |
| 340 AutoFillProfile profile0(string16(), 0); |
| 341 autofill_unittest::SetProfileInfo(&profile0, |
| 342 "", "y", "", "", "", "", "", "", "", "", "", "", "", ""); |
| 343 |
| 344 // This will verify that the web database has been loaded and the notification |
| 345 // sent out. |
| 346 EXPECT_CALL(personal_data_observer_, |
| 347 OnPersonalDataLoaded()).WillRepeatedly(QuitUIMessageLoop()); |
| 348 |
| 349 // The message loop will exit when the mock observer is notified. |
| 350 MessageLoop::current()->Run(); |
| 351 |
| 352 // Add the profile0 to the db. |
| 353 std::vector<AutoFillProfile> update; |
| 354 update.push_back(profile0); |
| 355 personal_data_->SetProfiles(&update); |
| 356 |
| 357 // Reset the PersonalDataManager. This recreates PersonalDataManager, which |
| 358 // should populate unique_ids_. |
| 359 ResetPersonalDataManager(); |
| 360 |
| 361 // The message loop will exit when the PersonalDataLoadedObserver is notified. |
| 362 MessageLoop::current()->Run(); |
| 363 |
| 364 // Verify that we've loaded the profiles from the web database. |
| 365 const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); |
| 366 ASSERT_EQ(1U, results2.size()); |
| 367 |
| 368 // Add a new profile. |
| 369 AutoFillProfile profile1(string16(), 0); |
| 370 autofill_unittest::SetProfileInfo(&profile1, |
| 371 "", "y", "", "", "", "", "", "", "", "", "", "", "", ""); |
| 372 update.clear(); |
| 373 update.push_back(*results2[0]); |
| 374 update.push_back(profile1); |
| 375 personal_data_->SetProfiles(&update); |
| 376 |
| 377 // Make sure the two profiles have different ids (and neither equal to 0, |
| 378 // which is an invalid id). |
| 379 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); |
| 380 ASSERT_EQ(2U, results3.size()); |
| 381 EXPECT_NE(results3[0]->unique_id(), results3[1]->unique_id()); |
| 382 EXPECT_NE(0, results3[0]->unique_id()); |
| 383 EXPECT_NE(0, results3[1]->unique_id()); |
| 384 } |
| 385 |
337 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { | 386 TEST_F(PersonalDataManagerTest, SetEmptyProfile) { |
338 AutoFillProfile profile0(string16(), 0); | 387 AutoFillProfile profile0(string16(), 0); |
339 autofill_unittest::SetProfileInfo(&profile0, | 388 autofill_unittest::SetProfileInfo(&profile0, |
340 "", "", "", "", "", "", "", "", "", "", "", "", "", ""); | 389 "", "", "", "", "", "", "", "", "", "", "", "", "", ""); |
341 | 390 |
342 // This will verify that the web database has been loaded and the notification | 391 // This will verify that the web database has been loaded and the notification |
343 // sent out. | 392 // sent out. |
344 EXPECT_CALL(personal_data_observer_, | 393 EXPECT_CALL(personal_data_observer_, |
345 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); | 394 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
346 | 395 |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, | 786 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, |
738 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL); | 787 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL); |
739 EXPECT_EQ(*expected, *results3[0]); | 788 EXPECT_EQ(*expected, *results3[0]); |
740 | 789 |
741 expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2)); | 790 expected.reset(new AutoFillProfile(ASCIIToUTF16("Unlabeled2"), 2)); |
742 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL, | 791 autofill_unittest::SetProfileInfo(expected.get(), "Unlabeled2", "John", NULL, |
743 "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 792 "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
744 NULL, NULL); | 793 NULL, NULL); |
745 EXPECT_EQ(*expected, *results3[1]); | 794 EXPECT_EQ(*expected, *results3[1]); |
746 } | 795 } |
OLD | NEW |