| Index: chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
|
| diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
|
| index 8668c7a2412119ae0b945d16050e9ae9ebd96b67..bd72c29609ae3341835aad0ea88a5cf8f89817f0 100644
|
| --- a/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
|
| +++ b/chrome/browser/autofill/autofill_dialog_controller_mac_unittest.mm
|
| @@ -8,6 +8,7 @@
|
| #import "chrome/browser/autofill/autofill_credit_card_view_controller_mac.h"
|
| #import "chrome/browser/autofill/autofill_dialog_controller_mac.h"
|
| #include "chrome/browser/autofill/autofill_profile.h"
|
| +#include "chrome/browser/autofill/personal_data_manager.h"
|
| #include "chrome/browser/cocoa/browser_test_helper.h"
|
| #import "chrome/browser/cocoa/cocoa_test_helper.h"
|
| #include "chrome/browser/pref_service.h"
|
| @@ -16,11 +17,98 @@
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| namespace {
|
| -class AutoFillDialogObserverTester : public AutoFillDialogObserver {
|
| +
|
| +// Simulated delay (in milliseconds) for web data loading.
|
| +const float kWebDataLoadDelayMilliseconds = 10.0;
|
| +
|
| +// Mock PersonalDataManager that gives back canned profiles and credit cards
|
| +// as well as simulating delayed loading of web data using the
|
| +// |PersonalDataManager::Observer| interface.
|
| +class PersonalDataManagerMock : public PersonalDataManager {
|
| + public:
|
| + PersonalDataManagerMock()
|
| + : observer_(NULL),
|
| + test_data_is_loaded_(true) {}
|
| + virtual ~PersonalDataManagerMock() {}
|
| +
|
| + virtual const std::vector<AutoFillProfile*>& web_profiles() {
|
| + return test_profiles_;
|
| + }
|
| + virtual const std::vector<CreditCard*>& credit_cards() {
|
| + return test_credit_cards_;
|
| + }
|
| + virtual bool IsDataLoaded() const { return test_data_is_loaded_; }
|
| + virtual void SetObserver(PersonalDataManager::Observer* observer) {
|
| + DCHECK(observer);
|
| + observer_ = observer;
|
| +
|
| + // This delay allows the UI loop to run and display intermediate results
|
| + // while the data is loading. When notified that the data is available the
|
| + // UI updates with the new data. 10ms is a nice short amount of time to
|
| + // let the UI thread update but does not slow down the tests too much.
|
| + MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE,
|
| + new MessageLoop::QuitTask,
|
| + kWebDataLoadDelayMilliseconds);
|
| + MessageLoop::current()->Run();
|
| + observer_->OnPersonalDataLoaded();
|
| + }
|
| + virtual void RemoveObserver(PersonalDataManager::Observer* observer) {
|
| + observer_ = NULL;
|
| + }
|
| +
|
| + std::vector<AutoFillProfile*> test_profiles_;
|
| + std::vector<CreditCard*> test_credit_cards_;
|
| + PersonalDataManager::Observer* observer_;
|
| + bool test_data_is_loaded_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerMock);
|
| +};
|
| +
|
| +// Mock profile that gives back our own mock |PersonalDataManager|.
|
| +class ProfileMock : public TestingProfile {
|
| + public:
|
| + ProfileMock() {
|
| + test_manager_.reset(new PersonalDataManagerMock);
|
| + }
|
| + virtual ~ProfileMock() {}
|
| +
|
| + virtual PersonalDataManager* GetPersonalDataManager() {
|
| + return test_manager_.get();
|
| + }
|
| +
|
| + scoped_ptr<PersonalDataManagerMock> test_manager_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ProfileMock);
|
| +};
|
| +
|
| +// Mock browser that gives back our own |BrowserMock| instance as the profile.
|
| +class BrowserMock : public BrowserTestHelper {
|
| + public:
|
| + BrowserMock() {
|
| + test_profile_.reset(new ProfileMock);
|
| + }
|
| + virtual ~BrowserMock() {}
|
| +
|
| + // Override of |BrowserTestHelper::profile()|.
|
| + virtual TestingProfile* profile() const {
|
| + return test_profile_.get();
|
| + }
|
| +
|
| + scoped_ptr<ProfileMock> test_profile_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(BrowserMock);
|
| +};
|
| +
|
| +// Mock observer for the AutoFill settings dialog.
|
| +class AutoFillDialogObserverMock : public AutoFillDialogObserver {
|
| public:
|
| - AutoFillDialogObserverTester()
|
| + AutoFillDialogObserverMock()
|
| : hit_(false) {}
|
| - virtual ~AutoFillDialogObserverTester() {}
|
| + virtual ~AutoFillDialogObserverMock() {}
|
|
|
| virtual void OnAutoFillDialogApply(
|
| std::vector<AutoFillProfile>* profiles,
|
| @@ -43,27 +131,41 @@ class AutoFillDialogObserverTester : public AutoFillDialogObserver {
|
| std::vector<CreditCard> credit_cards_;
|
|
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(AutoFillDialogObserverTester);
|
| + DISALLOW_COPY_AND_ASSIGN(AutoFillDialogObserverMock);
|
| };
|
|
|
| +// Test fixture for setting up and tearing down our dialog controller under
|
| +// test. Also provides helper methods to access the source profiles and
|
| +// credit card information stored in mock |PersonalDataManager|.
|
| class AutoFillDialogControllerTest : public CocoaTest {
|
| public:
|
| - AutoFillDialogControllerTest() {}
|
| + AutoFillDialogControllerTest()
|
| + : controller_(nil),
|
| + imported_profile_(NULL),
|
| + imported_credit_card_(NULL) {
|
| + }
|
|
|
| void LoadDialog() {
|
| controller_ = [AutoFillDialogController
|
| controllerWithObserver:&observer_
|
| - autoFillProfiles:profiles_
|
| - creditCards:credit_cards_
|
| - profile:helper_.profile()];
|
| + profile:helper_.profile()
|
| + importedProfile:imported_profile_
|
| + importedCreditCard:imported_credit_card_];
|
| [controller_ window];
|
| }
|
|
|
| - BrowserTestHelper helper_;
|
| - AutoFillDialogObserverTester observer_;
|
| - AutoFillDialogController* controller_; // weak reference
|
| - std::vector<AutoFillProfile*> profiles_; // weak references within vector
|
| - std::vector<CreditCard*> credit_cards_; // weak references within vector
|
| + std::vector<AutoFillProfile*>& profiles() {
|
| + return helper_.test_profile_->test_manager_->test_profiles_;
|
| + }
|
| + std::vector<CreditCard*>& credit_cards() {
|
| + return helper_.test_profile_->test_manager_->test_credit_cards_;
|
| + }
|
| +
|
| + BrowserMock helper_;
|
| + AutoFillDialogObserverMock observer_;
|
| + AutoFillDialogController* controller_; // weak reference
|
| + AutoFillProfile* imported_profile_; // weak reference
|
| + CreditCard* imported_credit_card_; // weak reference
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(AutoFillDialogControllerTest);
|
| @@ -83,7 +185,7 @@ TEST_F(AutoFillDialogControllerTest, CancelButtonDoesNotInformObserver) {
|
|
|
| TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) {
|
| AutoFillProfile profile;
|
| - profiles_.push_back(&profile);
|
| + profiles().push_back(&profile);
|
| LoadDialog();
|
| [controller_ save:nil];
|
|
|
| @@ -91,13 +193,13 @@ TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match.
|
| - ASSERT_EQ(observer_.profiles_.size(), profiles_.size());
|
| + ASSERT_EQ(observer_.profiles_.size(), profiles().size());
|
|
|
| // Contents should match.
|
| size_t i = 0;
|
| - size_t count = profiles_.size();
|
| + size_t count = profiles().size();
|
| for (i = 0; i < count; i++)
|
| - ASSERT_EQ(observer_.profiles_[i], *profiles_[i]);
|
| + ASSERT_EQ(observer_.profiles_[i], *profiles()[i]);
|
|
|
| // Contents should not match a different profile.
|
| AutoFillProfile different_profile;
|
| @@ -109,7 +211,7 @@ TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) {
|
|
|
| TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalCreditCard) {
|
| CreditCard credit_card(ASCIIToUTF16("myCC"), 345);
|
| - credit_cards_.push_back(&credit_card);
|
| + credit_cards().push_back(&credit_card);
|
| LoadDialog();
|
| [controller_ save:nil];
|
|
|
| @@ -117,14 +219,14 @@ TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalCreditCard) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match.
|
| - ASSERT_EQ(observer_.credit_cards_.size(), credit_cards_.size());
|
| + ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
|
|
|
| // Contents should match. With the exception of the |unique_id|.
|
| size_t i = 0;
|
| - size_t count = credit_cards_.size();
|
| + size_t count = credit_cards().size();
|
| for (i = 0; i < count; i++) {
|
| - credit_cards_[i]->set_unique_id(observer_.credit_cards_[i].unique_id());
|
| - ASSERT_EQ(observer_.credit_cards_[i], *credit_cards_[i]);
|
| + credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id());
|
| + ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]);
|
| }
|
|
|
| // Contents should not match a different profile.
|
| @@ -153,7 +255,7 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
|
| profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA"));
|
| profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552258"));
|
| profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("024087172258"));
|
| - profiles_.push_back(&profile);
|
| + profiles().push_back(&profile);
|
|
|
| LoadDialog();
|
|
|
| @@ -178,8 +280,8 @@ TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) {
|
| ASSERT_TRUE(observer_.hit_);
|
| ASSERT_TRUE(observer_.profiles_.size() == 1);
|
|
|
| - profiles_[0]->set_unique_id(observer_.profiles_[0].unique_id());
|
| - ASSERT_EQ(observer_.profiles_[0], *profiles_[0]);
|
| + profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id());
|
| + ASSERT_EQ(observer_.profiles_[0], *profiles()[0]);
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
|
| @@ -192,7 +294,7 @@ TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
|
| AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), ASCIIToUTF16("2012"));
|
| credit_card.SetInfo(
|
| AutoFillType(CREDIT_CARD_VERIFICATION_CODE), ASCIIToUTF16("222"));
|
| - credit_cards_.push_back(&credit_card);
|
| + credit_cards().push_back(&credit_card);
|
|
|
| LoadDialog();
|
|
|
| @@ -210,17 +312,17 @@ TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) {
|
| ASSERT_TRUE(observer_.hit_);
|
| ASSERT_TRUE(observer_.credit_cards_.size() == 1);
|
|
|
| - credit_cards_[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
|
| - ASSERT_EQ(observer_.credit_cards_[0], *credit_cards_[0]);
|
| + credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
|
| + ASSERT_EQ(observer_.credit_cards_[0], *credit_cards()[0]);
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, TwoProfiles) {
|
| AutoFillProfile profile1(ASCIIToUTF16("One"), 1);
|
| profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
|
| - profiles_.push_back(&profile1);
|
| + profiles().push_back(&profile1);
|
| AutoFillProfile profile2(ASCIIToUTF16("Two"), 2);
|
| profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
|
| - profiles_.push_back(&profile2);
|
| + profiles().push_back(&profile2);
|
| LoadDialog();
|
| [controller_ save:nil];
|
|
|
| @@ -228,23 +330,23 @@ TEST_F(AutoFillDialogControllerTest, TwoProfiles) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match. And should be 2.
|
| - ASSERT_EQ(observer_.profiles_.size(), profiles_.size());
|
| + ASSERT_EQ(observer_.profiles_.size(), profiles().size());
|
| ASSERT_EQ(observer_.profiles_.size(), 2UL);
|
|
|
| // Contents should match. With the exception of the |unique_id|.
|
| - for (size_t i = 0, count = profiles_.size(); i < count; i++) {
|
| - profiles_[i]->set_unique_id(observer_.profiles_[i].unique_id());
|
| - ASSERT_EQ(observer_.profiles_[i], *profiles_[i]);
|
| + for (size_t i = 0, count = profiles().size(); i < count; i++) {
|
| + profiles()[i]->set_unique_id(observer_.profiles_[i].unique_id());
|
| + ASSERT_EQ(observer_.profiles_[i], *profiles()[i]);
|
| }
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, TwoCreditCards) {
|
| CreditCard credit_card1(ASCIIToUTF16("Visa"), 1);
|
| credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
|
| - credit_cards_.push_back(&credit_card1);
|
| + credit_cards().push_back(&credit_card1);
|
| CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2);
|
| credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
|
| - credit_cards_.push_back(&credit_card2);
|
| + credit_cards().push_back(&credit_card2);
|
| LoadDialog();
|
| [controller_ save:nil];
|
|
|
| @@ -252,20 +354,20 @@ TEST_F(AutoFillDialogControllerTest, TwoCreditCards) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match. And should be 2.
|
| - ASSERT_EQ(observer_.credit_cards_.size(), credit_cards_.size());
|
| + ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
|
| ASSERT_EQ(observer_.credit_cards_.size(), 2UL);
|
|
|
| // Contents should match. With the exception of the |unique_id|.
|
| - for (size_t i = 0, count = credit_cards_.size(); i < count; i++) {
|
| - credit_cards_[i]->set_unique_id(observer_.credit_cards_[i].unique_id());
|
| - ASSERT_EQ(observer_.credit_cards_[i], *credit_cards_[i]);
|
| + for (size_t i = 0, count = credit_cards().size(); i < count; i++) {
|
| + credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id());
|
| + ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]);
|
| }
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
|
| AutoFillProfile profile(ASCIIToUTF16("One"), 1);
|
| profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
|
| - profiles_.push_back(&profile);
|
| + profiles().push_back(&profile);
|
| LoadDialog();
|
| [controller_ addNewAddress:nil];
|
| [controller_ save:nil];
|
| @@ -274,7 +376,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match be different. New size should be 2.
|
| - ASSERT_NE(observer_.profiles_.size(), profiles_.size());
|
| + ASSERT_NE(observer_.profiles_.size(), profiles().size());
|
| ASSERT_EQ(observer_.profiles_.size(), 2UL);
|
|
|
| // New address should match.
|
| @@ -285,7 +387,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewProfile) {
|
| TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
|
| CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
|
| credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
|
| - credit_cards_.push_back(&credit_card);
|
| + credit_cards().push_back(&credit_card);
|
| LoadDialog();
|
| [controller_ addNewCreditCard:nil];
|
| [controller_ save:nil];
|
| @@ -294,7 +396,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match be different. New size should be 2.
|
| - ASSERT_NE(observer_.credit_cards_.size(), credit_cards_.size());
|
| + ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size());
|
| ASSERT_EQ(observer_.credit_cards_.size(), 2UL);
|
|
|
| // New address should match.
|
| @@ -305,7 +407,7 @@ TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) {
|
| TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
|
| AutoFillProfile profile(ASCIIToUTF16("One"), 1);
|
| profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
|
| - profiles_.push_back(&profile);
|
| + profiles().push_back(&profile);
|
| LoadDialog();
|
| EXPECT_EQ([[[controller_ addressFormViewControllers] lastObject]
|
| retainCount], 1UL);
|
| @@ -317,14 +419,14 @@ TEST_F(AutoFillDialogControllerTest, DeleteProfile) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match be different. New size should be 0.
|
| - ASSERT_NE(observer_.profiles_.size(), profiles_.size());
|
| + ASSERT_NE(observer_.profiles_.size(), profiles().size());
|
| ASSERT_EQ(observer_.profiles_.size(), 0UL);
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) {
|
| CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
|
| credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
|
| - credit_cards_.push_back(&credit_card);
|
| + credit_cards().push_back(&credit_card);
|
| LoadDialog();
|
| EXPECT_EQ([[[controller_ creditCardFormViewControllers] lastObject]
|
| retainCount], 1UL);
|
| @@ -336,17 +438,17 @@ TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match be different. New size should be 0.
|
| - ASSERT_NE(observer_.credit_cards_.size(), credit_cards_.size());
|
| + ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size());
|
| ASSERT_EQ(observer_.credit_cards_.size(), 0UL);
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) {
|
| AutoFillProfile profile(ASCIIToUTF16("One"), 1);
|
| profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
|
| - profiles_.push_back(&profile);
|
| + profiles().push_back(&profile);
|
| AutoFillProfile profile2(ASCIIToUTF16("Two"), 2);
|
| profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
|
| - profiles_.push_back(&profile2);
|
| + profiles().push_back(&profile2);
|
| LoadDialog();
|
| [controller_ deleteAddress:[[controller_ addressFormViewControllers]
|
| lastObject]];
|
| @@ -356,21 +458,21 @@ TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match be different. New size should be 0.
|
| - ASSERT_NE(observer_.profiles_.size(), profiles_.size());
|
| + ASSERT_NE(observer_.profiles_.size(), profiles().size());
|
| ASSERT_EQ(observer_.profiles_.size(), 1UL);
|
|
|
| // First address should match.
|
| - profiles_[0]->set_unique_id(observer_.profiles_[0].unique_id());
|
| + profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id());
|
| ASSERT_EQ(observer_.profiles_[0], profile);
|
| }
|
|
|
| TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) {
|
| CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
|
| credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
|
| - credit_cards_.push_back(&credit_card);
|
| + credit_cards().push_back(&credit_card);
|
| CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2);
|
| credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
|
| - credit_cards_.push_back(&credit_card2);
|
| + credit_cards().push_back(&credit_card2);
|
| LoadDialog();
|
| [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers]
|
| lastObject]];
|
| @@ -380,11 +482,11 @@ TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) {
|
| ASSERT_TRUE(observer_.hit_);
|
|
|
| // Sizes should match be different. New size should be 0.
|
| - ASSERT_NE(observer_.credit_cards_.size(), credit_cards_.size());
|
| + ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size());
|
| ASSERT_EQ(observer_.credit_cards_.size(), 1UL);
|
|
|
| // First credit card should match.
|
| - credit_cards_[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
|
| + credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id());
|
| ASSERT_EQ(observer_.credit_cards_[0], credit_card);
|
| }
|
|
|
| @@ -433,16 +535,16 @@ TEST_F(AutoFillDialogControllerTest, DefaultsChangingLogic) {
|
| // Two profiles, two credit cards.
|
| AutoFillProfile profile(ASCIIToUTF16("One"), 1);
|
| profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe"));
|
| - profiles_.push_back(&profile);
|
| + profiles().push_back(&profile);
|
| AutoFillProfile profile2(ASCIIToUTF16("Two"), 2);
|
| profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob"));
|
| - profiles_.push_back(&profile2);
|
| + profiles().push_back(&profile2);
|
| CreditCard credit_card(ASCIIToUTF16("Visa"), 1);
|
| credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe"));
|
| - credit_cards_.push_back(&credit_card);
|
| + credit_cards().push_back(&credit_card);
|
| CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2);
|
| credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob"));
|
| - credit_cards_.push_back(&credit_card2);
|
| + credit_cards().push_back(&credit_card2);
|
|
|
| // Invalid defaults for each.
|
| helper_.profile()->GetPrefs()->SetString(
|
| @@ -495,4 +597,60 @@ TEST_F(AutoFillDialogControllerTest, DefaultsChangingLogic) {
|
| GetString(prefs::kAutoFillDefaultCreditCard));
|
| }
|
|
|
| +TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) {
|
| + AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
|
| + profiles().push_back(&profile);
|
| + CreditCard credit_card(ASCIIToUTF16("Visa"), 0);
|
| + credit_cards().push_back(&credit_card);
|
| + helper_.test_profile_->test_manager_->test_data_is_loaded_ = false;
|
| + LoadDialog();
|
| + [controller_ save:nil];
|
| +
|
| + // Should hit our observer.
|
| + ASSERT_TRUE(observer_.hit_);
|
| +
|
| + // Sizes should match.
|
| + ASSERT_EQ(observer_.profiles_.size(), profiles().size());
|
| + ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size());
|
| +
|
| + // Contents should match.
|
| + size_t i = 0;
|
| + size_t count = profiles().size();
|
| + for (i = 0; i < count; i++)
|
| + ASSERT_EQ(observer_.profiles_[i], *profiles()[i]);
|
| + count = credit_cards().size();
|
| + for (i = 0; i < count; i++) {
|
| + ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]);
|
| + }
|
| +}
|
| +
|
| +TEST_F(AutoFillDialogControllerTest, ImportedParameters) {
|
| + AutoFillProfile profile(ASCIIToUTF16("Home"), 0);
|
| + imported_profile_ = &profile;
|
| + CreditCard credit_card(ASCIIToUTF16("Mastercard"), 0);
|
| + imported_credit_card_ = &credit_card;
|
| +
|
| + // Note: when the |imported_*| parameters are supplied the dialog should
|
| + // ignore any profile and credit card information in the
|
| + // |PersonalDataManager|.
|
| + AutoFillProfile profile_ignored(ASCIIToUTF16("Work"), 0);
|
| + profiles().push_back(&profile_ignored);
|
| + CreditCard credit_card_ignored(ASCIIToUTF16("Visa"), 0);
|
| + credit_cards().push_back(&credit_card_ignored);
|
| +
|
| + LoadDialog();
|
| + [controller_ save:nil];
|
| +
|
| + // Should hit our observer.
|
| + ASSERT_TRUE(observer_.hit_);
|
| +
|
| + // Sizes should match.
|
| + ASSERT_EQ(1UL, observer_.profiles_.size());
|
| + ASSERT_EQ(1UL, observer_.credit_cards_.size());
|
| +
|
| + // Contents should match.
|
| + ASSERT_EQ(observer_.profiles_[0], profile);
|
| + ASSERT_EQ(observer_.credit_cards_[0], credit_card);
|
| }
|
| +
|
| +} // namespace
|
|
|