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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_common_test.h" | 10 #include "chrome/browser/autofill/autofill_common_test.h" |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 EXPECT_CALL(personal_data_observer_, | 450 EXPECT_CALL(personal_data_observer_, |
451 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); | 451 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
452 | 452 |
453 MessageLoop::current()->Run(); | 453 MessageLoop::current()->Run(); |
454 | 454 |
455 const std::vector<AutoFillProfile*>& results1 = personal_data_->profiles(); | 455 const std::vector<AutoFillProfile*>& results1 = personal_data_->profiles(); |
456 ASSERT_EQ(2U, results1.size()); | 456 ASSERT_EQ(2U, results1.size()); |
457 EXPECT_EQ(profile0, *results1.at(0)); | 457 EXPECT_EQ(profile0, *results1.at(0)); |
458 EXPECT_EQ(profile1, *results1.at(1)); | 458 EXPECT_EQ(profile1, *results1.at(1)); |
459 | 459 |
460 AutoFillProfile profile2; | 460 scoped_ptr<AutoFillProfile> profile2(new AutoFillProfile); |
461 autofill_test::SetProfileInfo(&profile2, | 461 autofill_test::SetProfileInfo(profile2.get(), |
462 "Work", "Josephine", "Alicia", "Saenz", | 462 "Work", "Josephine", "Alicia", "Saenz", |
463 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", | 463 "joewayne@me.xyz", "Fox", "1212 Center.", "Bld. 5", "Orlando", "FL", |
464 "32801", "US", "19482937549", "13502849239"); | 464 "32801", "US", "19482937549", "13502849239"); |
465 | 465 |
466 // Adjust all labels. | 466 // Adjust all labels. |
467 profile_pointers.push_back(&profile2); | 467 profile_pointers.push_back(profile2.get()); |
468 AutoFillProfile::AdjustInferredLabels(&profile_pointers); | 468 AutoFillProfile::AdjustInferredLabels(&profile_pointers); |
469 | 469 |
470 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 470 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
471 ASSERT_TRUE(wds); | 471 ASSERT_TRUE(wds); |
472 wds->AddAutoFillProfileGUID(profile2); | 472 wds->AddAutoFillProfileGUID(*profile2.get()); |
473 | 473 |
474 personal_data_->Refresh(); | 474 personal_data_->Refresh(); |
475 | 475 |
476 // Wait for the refresh. | 476 // Wait for the refresh. |
477 EXPECT_CALL(personal_data_observer_, | 477 EXPECT_CALL(personal_data_observer_, |
478 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); | 478 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
479 | 479 |
480 MessageLoop::current()->Run(); | 480 MessageLoop::current()->Run(); |
481 | 481 |
482 const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); | 482 const std::vector<AutoFillProfile*>& results2 = personal_data_->profiles(); |
483 ASSERT_EQ(3U, results2.size()); | 483 ASSERT_EQ(3U, results2.size()); |
484 EXPECT_EQ(profile0, *results2.at(0)); | 484 EXPECT_EQ(profile0, *results2.at(0)); |
485 EXPECT_EQ(profile1, *results2.at(1)); | 485 EXPECT_EQ(profile1, *results2.at(1)); |
486 EXPECT_EQ(profile2, *results2.at(2)); | 486 EXPECT_EQ(*profile2.get(), *results2.at(2)); |
487 | 487 |
488 wds->RemoveAutoFillProfileGUID(profile1.guid()); | 488 wds->RemoveAutoFillProfileGUID(profile1.guid()); |
489 wds->RemoveAutoFillProfileGUID(profile2.guid()); | 489 wds->RemoveAutoFillProfileGUID(profile2->guid()); |
490 | 490 |
491 // Before telling the PDM to refresh, simulate an edit to one of the profiles | 491 // Before telling the PDM to refresh, simulate an edit to one of the profiles |
492 // via a SetProfile update (this would happen if the AutoFill window was | 492 // via a SetProfile update (this would happen if the AutoFill window was |
493 // open with a previous snapshot of the profiles, and something [e.g. sync] | 493 // open with a previous snapshot of the profiles, and something [e.g. sync] |
494 // removed a profile from the browser. In this edge case, we will end up | 494 // removed a profile from the browser. In this edge case, we will end up |
495 // in a consistent state by dropping the write). | 495 // in a consistent state by dropping the write). |
496 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Jo")); | 496 profile2->SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Jo")); |
497 update.clear(); | 497 update.clear(); |
498 update.push_back(profile0); | 498 update.push_back(profile0); |
499 update.push_back(profile1); | 499 update.push_back(profile1); |
500 update.push_back(profile2); | 500 update.push_back(*profile2.get()); |
501 personal_data_->SetProfiles(&update); | 501 personal_data_->SetProfiles(&update); |
502 | 502 |
503 // And wait for the refresh. | 503 // And wait for the refresh. |
504 EXPECT_CALL(personal_data_observer_, | 504 EXPECT_CALL(personal_data_observer_, |
505 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); | 505 OnPersonalDataLoaded()).WillOnce(QuitUIMessageLoop()); |
506 | 506 |
507 MessageLoop::current()->Run(); | 507 MessageLoop::current()->Run(); |
508 | 508 |
509 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); | 509 const std::vector<AutoFillProfile*>& results3 = personal_data_->profiles(); |
510 ASSERT_EQ(1U, results3.size()); | 510 ASSERT_EQ(1U, results3.size()); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, | 717 "Washington", "theprez@gmail.com", NULL, "190 High Street", NULL, |
718 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL); | 718 "Philadelphia", "Pennsylvania", "19106", NULL, NULL, NULL); |
719 EXPECT_EQ(0, expected->Compare(*results3[0])); | 719 EXPECT_EQ(0, expected->Compare(*results3[0])); |
720 | 720 |
721 expected.reset(new AutoFillProfile); | 721 expected.reset(new AutoFillProfile); |
722 autofill_test::SetProfileInfo(expected.get(), NULL, "John", NULL, | 722 autofill_test::SetProfileInfo(expected.get(), NULL, "John", NULL, |
723 "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, | 723 "Adams", "second@gmail.com", NULL, NULL, NULL, NULL, NULL, NULL, NULL, |
724 NULL, NULL); | 724 NULL, NULL); |
725 EXPECT_EQ(0, expected->Compare(*results3[1])); | 725 EXPECT_EQ(0, expected->Compare(*results3[1])); |
726 } | 726 } |
OLD | NEW |