| 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 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 5 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
| 6 #import "chrome/browser/autofill/autofill_address_view_controller_mac.h" | 6 #import "chrome/browser/autofill/autofill_address_view_controller_mac.h" |
| 7 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 7 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
| 8 #import "chrome/browser/autofill/autofill_credit_card_view_controller_mac.h" | 8 #import "chrome/browser/autofill/autofill_credit_card_view_controller_mac.h" |
| 9 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" | 9 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" |
| 10 #include "chrome/browser/autofill/autofill_profile.h" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
| 11 #include "chrome/browser/autofill/personal_data_manager.h" |
| 11 #include "chrome/browser/cocoa/browser_test_helper.h" | 12 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 12 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 13 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 13 #include "chrome/browser/pref_service.h" | 14 #include "chrome/browser/pref_service.h" |
| 14 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 class AutoFillDialogObserverTester : public AutoFillDialogObserver { | 20 |
| 21 // Simulated delay (in milliseconds) for web data loading. |
| 22 const float kWebDataLoadDelayMilliseconds = 10.0; |
| 23 |
| 24 // Mock PersonalDataManager that gives back canned profiles and credit cards |
| 25 // as well as simulating delayed loading of web data using the |
| 26 // |PersonalDataManager::Observer| interface. |
| 27 class PersonalDataManagerMock : public PersonalDataManager { |
| 20 public: | 28 public: |
| 21 AutoFillDialogObserverTester() | 29 PersonalDataManagerMock() |
| 30 : observer_(NULL), |
| 31 test_data_is_loaded_(true) {} |
| 32 virtual ~PersonalDataManagerMock() {} |
| 33 |
| 34 virtual const std::vector<AutoFillProfile*>& web_profiles() { |
| 35 return test_profiles_; |
| 36 } |
| 37 virtual const std::vector<CreditCard*>& credit_cards() { |
| 38 return test_credit_cards_; |
| 39 } |
| 40 virtual bool IsDataLoaded() const { return test_data_is_loaded_; } |
| 41 virtual void SetObserver(PersonalDataManager::Observer* observer) { |
| 42 DCHECK(observer); |
| 43 observer_ = observer; |
| 44 |
| 45 // This delay allows the UI loop to run and display intermediate results |
| 46 // while the data is loading. When notified that the data is available the |
| 47 // UI updates with the new data. 10ms is a nice short amount of time to |
| 48 // let the UI thread update but does not slow down the tests too much. |
| 49 MessageLoop::current()->PostDelayedTask( |
| 50 FROM_HERE, |
| 51 new MessageLoop::QuitTask, |
| 52 kWebDataLoadDelayMilliseconds); |
| 53 MessageLoop::current()->Run(); |
| 54 observer_->OnPersonalDataLoaded(); |
| 55 } |
| 56 virtual void RemoveObserver(PersonalDataManager::Observer* observer) { |
| 57 observer_ = NULL; |
| 58 } |
| 59 |
| 60 std::vector<AutoFillProfile*> test_profiles_; |
| 61 std::vector<CreditCard*> test_credit_cards_; |
| 62 PersonalDataManager::Observer* observer_; |
| 63 bool test_data_is_loaded_; |
| 64 |
| 65 private: |
| 66 DISALLOW_COPY_AND_ASSIGN(PersonalDataManagerMock); |
| 67 }; |
| 68 |
| 69 // Mock profile that gives back our own mock |PersonalDataManager|. |
| 70 class ProfileMock : public TestingProfile { |
| 71 public: |
| 72 ProfileMock() { |
| 73 test_manager_.reset(new PersonalDataManagerMock); |
| 74 } |
| 75 virtual ~ProfileMock() {} |
| 76 |
| 77 virtual PersonalDataManager* GetPersonalDataManager() { |
| 78 return test_manager_.get(); |
| 79 } |
| 80 |
| 81 scoped_ptr<PersonalDataManagerMock> test_manager_; |
| 82 |
| 83 private: |
| 84 DISALLOW_COPY_AND_ASSIGN(ProfileMock); |
| 85 }; |
| 86 |
| 87 // Mock browser that gives back our own |BrowserMock| instance as the profile. |
| 88 class BrowserMock : public BrowserTestHelper { |
| 89 public: |
| 90 BrowserMock() { |
| 91 test_profile_.reset(new ProfileMock); |
| 92 } |
| 93 virtual ~BrowserMock() {} |
| 94 |
| 95 // Override of |BrowserTestHelper::profile()|. |
| 96 virtual TestingProfile* profile() const { |
| 97 return test_profile_.get(); |
| 98 } |
| 99 |
| 100 scoped_ptr<ProfileMock> test_profile_; |
| 101 |
| 102 private: |
| 103 DISALLOW_COPY_AND_ASSIGN(BrowserMock); |
| 104 }; |
| 105 |
| 106 // Mock observer for the AutoFill settings dialog. |
| 107 class AutoFillDialogObserverMock : public AutoFillDialogObserver { |
| 108 public: |
| 109 AutoFillDialogObserverMock() |
| 22 : hit_(false) {} | 110 : hit_(false) {} |
| 23 virtual ~AutoFillDialogObserverTester() {} | 111 virtual ~AutoFillDialogObserverMock() {} |
| 24 | 112 |
| 25 virtual void OnAutoFillDialogApply( | 113 virtual void OnAutoFillDialogApply( |
| 26 std::vector<AutoFillProfile>* profiles, | 114 std::vector<AutoFillProfile>* profiles, |
| 27 std::vector<CreditCard>* credit_cards) { | 115 std::vector<CreditCard>* credit_cards) { |
| 28 hit_ = true; | 116 hit_ = true; |
| 29 | 117 |
| 30 std::vector<AutoFillProfile>::iterator i; | 118 std::vector<AutoFillProfile>::iterator i; |
| 31 profiles_.clear(); | 119 profiles_.clear(); |
| 32 for (i = profiles->begin(); i != profiles->end(); ++i) | 120 for (i = profiles->begin(); i != profiles->end(); ++i) |
| 33 profiles_.push_back(*i); | 121 profiles_.push_back(*i); |
| 34 | 122 |
| 35 std::vector<CreditCard>::iterator j; | 123 std::vector<CreditCard>::iterator j; |
| 36 credit_cards_.clear(); | 124 credit_cards_.clear(); |
| 37 for (j = credit_cards->begin(); j != credit_cards->end(); ++j) | 125 for (j = credit_cards->begin(); j != credit_cards->end(); ++j) |
| 38 credit_cards_.push_back(*j); | 126 credit_cards_.push_back(*j); |
| 39 } | 127 } |
| 40 | 128 |
| 41 bool hit_; | 129 bool hit_; |
| 42 std::vector<AutoFillProfile> profiles_; | 130 std::vector<AutoFillProfile> profiles_; |
| 43 std::vector<CreditCard> credit_cards_; | 131 std::vector<CreditCard> credit_cards_; |
| 44 | 132 |
| 45 private: | 133 private: |
| 46 DISALLOW_COPY_AND_ASSIGN(AutoFillDialogObserverTester); | 134 DISALLOW_COPY_AND_ASSIGN(AutoFillDialogObserverMock); |
| 47 }; | 135 }; |
| 48 | 136 |
| 137 // Test fixture for setting up and tearing down our dialog controller under |
| 138 // test. Also provides helper methods to access the source profiles and |
| 139 // credit card information stored in mock |PersonalDataManager|. |
| 49 class AutoFillDialogControllerTest : public CocoaTest { | 140 class AutoFillDialogControllerTest : public CocoaTest { |
| 50 public: | 141 public: |
| 51 AutoFillDialogControllerTest() {} | 142 AutoFillDialogControllerTest() |
| 143 : controller_(nil), |
| 144 imported_profile_(NULL), |
| 145 imported_credit_card_(NULL) { |
| 146 } |
| 52 | 147 |
| 53 void LoadDialog() { | 148 void LoadDialog() { |
| 54 controller_ = [AutoFillDialogController | 149 controller_ = [AutoFillDialogController |
| 55 controllerWithObserver:&observer_ | 150 controllerWithObserver:&observer_ |
| 56 autoFillProfiles:profiles_ | 151 profile:helper_.profile() |
| 57 creditCards:credit_cards_ | 152 importedProfile:imported_profile_ |
| 58 profile:helper_.profile()]; | 153 importedCreditCard:imported_credit_card_]; |
| 59 [controller_ window]; | 154 [controller_ window]; |
| 60 } | 155 } |
| 61 | 156 |
| 62 BrowserTestHelper helper_; | 157 std::vector<AutoFillProfile*>& profiles() { |
| 63 AutoFillDialogObserverTester observer_; | 158 return helper_.test_profile_->test_manager_->test_profiles_; |
| 64 AutoFillDialogController* controller_; // weak reference | 159 } |
| 65 std::vector<AutoFillProfile*> profiles_; // weak references within vector | 160 std::vector<CreditCard*>& credit_cards() { |
| 66 std::vector<CreditCard*> credit_cards_; // weak references within vector | 161 return helper_.test_profile_->test_manager_->test_credit_cards_; |
| 162 } |
| 163 |
| 164 BrowserMock helper_; |
| 165 AutoFillDialogObserverMock observer_; |
| 166 AutoFillDialogController* controller_; // weak reference |
| 167 AutoFillProfile* imported_profile_; // weak reference |
| 168 CreditCard* imported_credit_card_; // weak reference |
| 67 | 169 |
| 68 private: | 170 private: |
| 69 DISALLOW_COPY_AND_ASSIGN(AutoFillDialogControllerTest); | 171 DISALLOW_COPY_AND_ASSIGN(AutoFillDialogControllerTest); |
| 70 }; | 172 }; |
| 71 | 173 |
| 72 TEST_F(AutoFillDialogControllerTest, SaveButtonInformsObserver) { | 174 TEST_F(AutoFillDialogControllerTest, SaveButtonInformsObserver) { |
| 73 LoadDialog(); | 175 LoadDialog(); |
| 74 [controller_ save:nil]; | 176 [controller_ save:nil]; |
| 75 ASSERT_TRUE(observer_.hit_); | 177 ASSERT_TRUE(observer_.hit_); |
| 76 } | 178 } |
| 77 | 179 |
| 78 TEST_F(AutoFillDialogControllerTest, CancelButtonDoesNotInformObserver) { | 180 TEST_F(AutoFillDialogControllerTest, CancelButtonDoesNotInformObserver) { |
| 79 LoadDialog(); | 181 LoadDialog(); |
| 80 [controller_ cancel:nil]; | 182 [controller_ cancel:nil]; |
| 81 ASSERT_FALSE(observer_.hit_); | 183 ASSERT_FALSE(observer_.hit_); |
| 82 } | 184 } |
| 83 | 185 |
| 84 TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) { | 186 TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) { |
| 85 AutoFillProfile profile; | 187 AutoFillProfile profile; |
| 86 profiles_.push_back(&profile); | 188 profiles().push_back(&profile); |
| 87 LoadDialog(); | 189 LoadDialog(); |
| 88 [controller_ save:nil]; | 190 [controller_ save:nil]; |
| 89 | 191 |
| 90 // Should hit our observer. | 192 // Should hit our observer. |
| 91 ASSERT_TRUE(observer_.hit_); | 193 ASSERT_TRUE(observer_.hit_); |
| 92 | 194 |
| 93 // Sizes should match. | 195 // Sizes should match. |
| 94 ASSERT_EQ(observer_.profiles_.size(), profiles_.size()); | 196 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); |
| 95 | 197 |
| 96 // Contents should match. | 198 // Contents should match. |
| 97 size_t i = 0; | 199 size_t i = 0; |
| 98 size_t count = profiles_.size(); | 200 size_t count = profiles().size(); |
| 99 for (i = 0; i < count; i++) | 201 for (i = 0; i < count; i++) |
| 100 ASSERT_EQ(observer_.profiles_[i], *profiles_[i]); | 202 ASSERT_EQ(observer_.profiles_[i], *profiles()[i]); |
| 101 | 203 |
| 102 // Contents should not match a different profile. | 204 // Contents should not match a different profile. |
| 103 AutoFillProfile different_profile; | 205 AutoFillProfile different_profile; |
| 104 different_profile.set_label(ASCIIToUTF16("different")); | 206 different_profile.set_label(ASCIIToUTF16("different")); |
| 105 different_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("joe")); | 207 different_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("joe")); |
| 106 for (i = 0; i < count; i++) | 208 for (i = 0; i < count; i++) |
| 107 ASSERT_NE(observer_.profiles_[i], different_profile); | 209 ASSERT_NE(observer_.profiles_[i], different_profile); |
| 108 } | 210 } |
| 109 | 211 |
| 110 TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalCreditCard) { | 212 TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalCreditCard) { |
| 111 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); | 213 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); |
| 112 credit_cards_.push_back(&credit_card); | 214 credit_cards().push_back(&credit_card); |
| 113 LoadDialog(); | 215 LoadDialog(); |
| 114 [controller_ save:nil]; | 216 [controller_ save:nil]; |
| 115 | 217 |
| 116 // Should hit our observer. | 218 // Should hit our observer. |
| 117 ASSERT_TRUE(observer_.hit_); | 219 ASSERT_TRUE(observer_.hit_); |
| 118 | 220 |
| 119 // Sizes should match. | 221 // Sizes should match. |
| 120 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards_.size()); | 222 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); |
| 121 | 223 |
| 122 // Contents should match. With the exception of the |unique_id|. | 224 // Contents should match. With the exception of the |unique_id|. |
| 123 size_t i = 0; | 225 size_t i = 0; |
| 124 size_t count = credit_cards_.size(); | 226 size_t count = credit_cards().size(); |
| 125 for (i = 0; i < count; i++) { | 227 for (i = 0; i < count; i++) { |
| 126 credit_cards_[i]->set_unique_id(observer_.credit_cards_[i].unique_id()); | 228 credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id()); |
| 127 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards_[i]); | 229 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]); |
| 128 } | 230 } |
| 129 | 231 |
| 130 // Contents should not match a different profile. | 232 // Contents should not match a different profile. |
| 131 CreditCard different_credit_card(ASCIIToUTF16("different"), 0); | 233 CreditCard different_credit_card(ASCIIToUTF16("different"), 0); |
| 132 different_credit_card.SetInfo( | 234 different_credit_card.SetInfo( |
| 133 AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234")); | 235 AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234")); |
| 134 for (i = 0; i < count; i++) | 236 for (i = 0; i < count; i++) |
| 135 ASSERT_NE(observer_.credit_cards_[i], different_credit_card); | 237 ASSERT_NE(observer_.credit_cards_[i], different_credit_card); |
| 136 } | 238 } |
| 137 | 239 |
| 138 TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) { | 240 TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) { |
| 139 AutoFillProfile profile(ASCIIToUTF16("Home"), 17); | 241 AutoFillProfile profile(ASCIIToUTF16("Home"), 17); |
| 140 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("David")); | 242 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("David")); |
| 141 profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("C")); | 243 profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("C")); |
| 142 profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Holloway")); | 244 profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Holloway")); |
| 143 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), | 245 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), |
| 144 ASCIIToUTF16("dhollowa@chromium.org")); | 246 ASCIIToUTF16("dhollowa@chromium.org")); |
| 145 profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google Inc.")); | 247 profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google Inc.")); |
| 146 profile.SetInfo( | 248 profile.SetInfo( |
| 147 AutoFillType(ADDRESS_HOME_LINE1), ASCIIToUTF16("1122 Mountain View Road"))
; | 249 AutoFillType(ADDRESS_HOME_LINE1), ASCIIToUTF16("1122 Mountain View Road"))
; |
| 148 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("Suite #1")); | 250 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("Suite #1")); |
| 149 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), | 251 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), |
| 150 ASCIIToUTF16("Mountain View")); | 252 ASCIIToUTF16("Mountain View")); |
| 151 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); | 253 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); |
| 152 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("94111")); | 254 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("94111")); |
| 153 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA")); | 255 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA")); |
| 154 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552
258")); | 256 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552
258")); |
| 155 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("0240871722
58")); | 257 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("0240871722
58")); |
| 156 profiles_.push_back(&profile); | 258 profiles().push_back(&profile); |
| 157 | 259 |
| 158 LoadDialog(); | 260 LoadDialog(); |
| 159 | 261 |
| 160 AutoFillAddressModel* am = [[[controller_ addressFormViewControllers] | 262 AutoFillAddressModel* am = [[[controller_ addressFormViewControllers] |
| 161 objectAtIndex:0] addressModel]; | 263 objectAtIndex:0] addressModel]; |
| 162 EXPECT_TRUE([[am label] isEqualToString:@"Home"]); | 264 EXPECT_TRUE([[am label] isEqualToString:@"Home"]); |
| 163 EXPECT_TRUE([[am firstName] isEqualToString:@"David"]); | 265 EXPECT_TRUE([[am firstName] isEqualToString:@"David"]); |
| 164 EXPECT_TRUE([[am middleName] isEqualToString:@"C"]); | 266 EXPECT_TRUE([[am middleName] isEqualToString:@"C"]); |
| 165 EXPECT_TRUE([[am lastName] isEqualToString:@"Holloway"]); | 267 EXPECT_TRUE([[am lastName] isEqualToString:@"Holloway"]); |
| 166 EXPECT_TRUE([[am email] isEqualToString:@"dhollowa@chromium.org"]); | 268 EXPECT_TRUE([[am email] isEqualToString:@"dhollowa@chromium.org"]); |
| 167 EXPECT_TRUE([[am companyName] isEqualToString:@"Google Inc."]); | 269 EXPECT_TRUE([[am companyName] isEqualToString:@"Google Inc."]); |
| 168 EXPECT_TRUE([[am addressLine1] isEqualToString:@"1122 Mountain View Road"]); | 270 EXPECT_TRUE([[am addressLine1] isEqualToString:@"1122 Mountain View Road"]); |
| 169 EXPECT_TRUE([[am addressLine2] isEqualToString:@"Suite #1"]); | 271 EXPECT_TRUE([[am addressLine2] isEqualToString:@"Suite #1"]); |
| 170 EXPECT_TRUE([[am addressCity] isEqualToString:@"Mountain View"]); | 272 EXPECT_TRUE([[am addressCity] isEqualToString:@"Mountain View"]); |
| 171 EXPECT_TRUE([[am addressState] isEqualToString:@"CA"]); | 273 EXPECT_TRUE([[am addressState] isEqualToString:@"CA"]); |
| 172 EXPECT_TRUE([[am addressZip] isEqualToString:@"94111"]); | 274 EXPECT_TRUE([[am addressZip] isEqualToString:@"94111"]); |
| 173 EXPECT_TRUE([[am phoneWholeNumber] isEqualToString:@"014155552258"]); | 275 EXPECT_TRUE([[am phoneWholeNumber] isEqualToString:@"014155552258"]); |
| 174 EXPECT_TRUE([[am faxWholeNumber] isEqualToString:@"024087172258"]); | 276 EXPECT_TRUE([[am faxWholeNumber] isEqualToString:@"024087172258"]); |
| 175 | 277 |
| 176 [controller_ save:nil]; | 278 [controller_ save:nil]; |
| 177 | 279 |
| 178 ASSERT_TRUE(observer_.hit_); | 280 ASSERT_TRUE(observer_.hit_); |
| 179 ASSERT_TRUE(observer_.profiles_.size() == 1); | 281 ASSERT_TRUE(observer_.profiles_.size() == 1); |
| 180 | 282 |
| 181 profiles_[0]->set_unique_id(observer_.profiles_[0].unique_id()); | 283 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
| 182 ASSERT_EQ(observer_.profiles_[0], *profiles_[0]); | 284 ASSERT_EQ(observer_.profiles_[0], *profiles()[0]); |
| 183 } | 285 } |
| 184 | 286 |
| 185 TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) { | 287 TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) { |
| 186 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); | 288 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); |
| 187 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("DCH")); | 289 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("DCH")); |
| 188 credit_card.SetInfo( | 290 credit_card.SetInfo( |
| 189 AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234 5678 9101 1121")); | 291 AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234 5678 9101 1121")); |
| 190 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01")); | 292 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01")); |
| 191 credit_card.SetInfo( | 293 credit_card.SetInfo( |
| 192 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), ASCIIToUTF16("2012")); | 294 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), ASCIIToUTF16("2012")); |
| 193 credit_card.SetInfo( | 295 credit_card.SetInfo( |
| 194 AutoFillType(CREDIT_CARD_VERIFICATION_CODE), ASCIIToUTF16("222")); | 296 AutoFillType(CREDIT_CARD_VERIFICATION_CODE), ASCIIToUTF16("222")); |
| 195 credit_cards_.push_back(&credit_card); | 297 credit_cards().push_back(&credit_card); |
| 196 | 298 |
| 197 LoadDialog(); | 299 LoadDialog(); |
| 198 | 300 |
| 199 AutoFillCreditCardModel* cm = [[[controller_ creditCardFormViewControllers] | 301 AutoFillCreditCardModel* cm = [[[controller_ creditCardFormViewControllers] |
| 200 objectAtIndex:0] creditCardModel]; | 302 objectAtIndex:0] creditCardModel]; |
| 201 EXPECT_TRUE([[cm label] isEqualToString:@"myCC"]); | 303 EXPECT_TRUE([[cm label] isEqualToString:@"myCC"]); |
| 202 EXPECT_TRUE([[cm nameOnCard] isEqualToString:@"DCH"]); | 304 EXPECT_TRUE([[cm nameOnCard] isEqualToString:@"DCH"]); |
| 203 EXPECT_TRUE([[cm creditCardNumber] isEqualToString:@"1234 5678 9101 1121"]); | 305 EXPECT_TRUE([[cm creditCardNumber] isEqualToString:@"1234 5678 9101 1121"]); |
| 204 EXPECT_TRUE([[cm expirationMonth] isEqualToString:@"01"]); | 306 EXPECT_TRUE([[cm expirationMonth] isEqualToString:@"01"]); |
| 205 EXPECT_TRUE([[cm expirationYear] isEqualToString:@"2012"]); | 307 EXPECT_TRUE([[cm expirationYear] isEqualToString:@"2012"]); |
| 206 EXPECT_TRUE([[cm cvcCode] isEqualToString:@"222"]); | 308 EXPECT_TRUE([[cm cvcCode] isEqualToString:@"222"]); |
| 207 | 309 |
| 208 [controller_ save:nil]; | 310 [controller_ save:nil]; |
| 209 | 311 |
| 210 ASSERT_TRUE(observer_.hit_); | 312 ASSERT_TRUE(observer_.hit_); |
| 211 ASSERT_TRUE(observer_.credit_cards_.size() == 1); | 313 ASSERT_TRUE(observer_.credit_cards_.size() == 1); |
| 212 | 314 |
| 213 credit_cards_[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); | 315 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
| 214 ASSERT_EQ(observer_.credit_cards_[0], *credit_cards_[0]); | 316 ASSERT_EQ(observer_.credit_cards_[0], *credit_cards()[0]); |
| 215 } | 317 } |
| 216 | 318 |
| 217 TEST_F(AutoFillDialogControllerTest, TwoProfiles) { | 319 TEST_F(AutoFillDialogControllerTest, TwoProfiles) { |
| 218 AutoFillProfile profile1(ASCIIToUTF16("One"), 1); | 320 AutoFillProfile profile1(ASCIIToUTF16("One"), 1); |
| 219 profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 321 profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
| 220 profiles_.push_back(&profile1); | 322 profiles().push_back(&profile1); |
| 221 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); | 323 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
| 222 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); | 324 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
| 223 profiles_.push_back(&profile2); | 325 profiles().push_back(&profile2); |
| 224 LoadDialog(); | 326 LoadDialog(); |
| 225 [controller_ save:nil]; | 327 [controller_ save:nil]; |
| 226 | 328 |
| 227 // Should hit our observer. | 329 // Should hit our observer. |
| 228 ASSERT_TRUE(observer_.hit_); | 330 ASSERT_TRUE(observer_.hit_); |
| 229 | 331 |
| 230 // Sizes should match. And should be 2. | 332 // Sizes should match. And should be 2. |
| 231 ASSERT_EQ(observer_.profiles_.size(), profiles_.size()); | 333 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); |
| 232 ASSERT_EQ(observer_.profiles_.size(), 2UL); | 334 ASSERT_EQ(observer_.profiles_.size(), 2UL); |
| 233 | 335 |
| 234 // Contents should match. With the exception of the |unique_id|. | 336 // Contents should match. With the exception of the |unique_id|. |
| 235 for (size_t i = 0, count = profiles_.size(); i < count; i++) { | 337 for (size_t i = 0, count = profiles().size(); i < count; i++) { |
| 236 profiles_[i]->set_unique_id(observer_.profiles_[i].unique_id()); | 338 profiles()[i]->set_unique_id(observer_.profiles_[i].unique_id()); |
| 237 ASSERT_EQ(observer_.profiles_[i], *profiles_[i]); | 339 ASSERT_EQ(observer_.profiles_[i], *profiles()[i]); |
| 238 } | 340 } |
| 239 } | 341 } |
| 240 | 342 |
| 241 TEST_F(AutoFillDialogControllerTest, TwoCreditCards) { | 343 TEST_F(AutoFillDialogControllerTest, TwoCreditCards) { |
| 242 CreditCard credit_card1(ASCIIToUTF16("Visa"), 1); | 344 CreditCard credit_card1(ASCIIToUTF16("Visa"), 1); |
| 243 credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 345 credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
| 244 credit_cards_.push_back(&credit_card1); | 346 credit_cards().push_back(&credit_card1); |
| 245 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); | 347 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
| 246 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 348 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
| 247 credit_cards_.push_back(&credit_card2); | 349 credit_cards().push_back(&credit_card2); |
| 248 LoadDialog(); | 350 LoadDialog(); |
| 249 [controller_ save:nil]; | 351 [controller_ save:nil]; |
| 250 | 352 |
| 251 // Should hit our observer. | 353 // Should hit our observer. |
| 252 ASSERT_TRUE(observer_.hit_); | 354 ASSERT_TRUE(observer_.hit_); |
| 253 | 355 |
| 254 // Sizes should match. And should be 2. | 356 // Sizes should match. And should be 2. |
| 255 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards_.size()); | 357 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); |
| 256 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); | 358 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); |
| 257 | 359 |
| 258 // Contents should match. With the exception of the |unique_id|. | 360 // Contents should match. With the exception of the |unique_id|. |
| 259 for (size_t i = 0, count = credit_cards_.size(); i < count; i++) { | 361 for (size_t i = 0, count = credit_cards().size(); i < count; i++) { |
| 260 credit_cards_[i]->set_unique_id(observer_.credit_cards_[i].unique_id()); | 362 credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id()); |
| 261 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards_[i]); | 363 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]); |
| 262 } | 364 } |
| 263 } | 365 } |
| 264 | 366 |
| 265 TEST_F(AutoFillDialogControllerTest, AddNewProfile) { | 367 TEST_F(AutoFillDialogControllerTest, AddNewProfile) { |
| 266 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 368 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
| 267 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 369 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
| 268 profiles_.push_back(&profile); | 370 profiles().push_back(&profile); |
| 269 LoadDialog(); | 371 LoadDialog(); |
| 270 [controller_ addNewAddress:nil]; | 372 [controller_ addNewAddress:nil]; |
| 271 [controller_ save:nil]; | 373 [controller_ save:nil]; |
| 272 | 374 |
| 273 // Should hit our observer. | 375 // Should hit our observer. |
| 274 ASSERT_TRUE(observer_.hit_); | 376 ASSERT_TRUE(observer_.hit_); |
| 275 | 377 |
| 276 // Sizes should match be different. New size should be 2. | 378 // Sizes should match be different. New size should be 2. |
| 277 ASSERT_NE(observer_.profiles_.size(), profiles_.size()); | 379 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
| 278 ASSERT_EQ(observer_.profiles_.size(), 2UL); | 380 ASSERT_EQ(observer_.profiles_.size(), 2UL); |
| 279 | 381 |
| 280 // New address should match. | 382 // New address should match. |
| 281 AutoFillProfile new_profile(ASCIIToUTF16("New address"), 0); | 383 AutoFillProfile new_profile(ASCIIToUTF16("New address"), 0); |
| 282 ASSERT_EQ(observer_.profiles_[1], new_profile); | 384 ASSERT_EQ(observer_.profiles_[1], new_profile); |
| 283 } | 385 } |
| 284 | 386 |
| 285 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { | 387 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { |
| 286 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 388 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
| 287 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 389 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
| 288 credit_cards_.push_back(&credit_card); | 390 credit_cards().push_back(&credit_card); |
| 289 LoadDialog(); | 391 LoadDialog(); |
| 290 [controller_ addNewCreditCard:nil]; | 392 [controller_ addNewCreditCard:nil]; |
| 291 [controller_ save:nil]; | 393 [controller_ save:nil]; |
| 292 | 394 |
| 293 // Should hit our observer. | 395 // Should hit our observer. |
| 294 ASSERT_TRUE(observer_.hit_); | 396 ASSERT_TRUE(observer_.hit_); |
| 295 | 397 |
| 296 // Sizes should match be different. New size should be 2. | 398 // Sizes should match be different. New size should be 2. |
| 297 ASSERT_NE(observer_.credit_cards_.size(), credit_cards_.size()); | 399 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
| 298 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); | 400 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); |
| 299 | 401 |
| 300 // New address should match. | 402 // New address should match. |
| 301 CreditCard new_credit_card(ASCIIToUTF16("New credit card"), 0); | 403 CreditCard new_credit_card(ASCIIToUTF16("New credit card"), 0); |
| 302 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); | 404 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); |
| 303 } | 405 } |
| 304 | 406 |
| 305 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { | 407 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { |
| 306 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 408 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
| 307 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 409 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
| 308 profiles_.push_back(&profile); | 410 profiles().push_back(&profile); |
| 309 LoadDialog(); | 411 LoadDialog(); |
| 310 EXPECT_EQ([[[controller_ addressFormViewControllers] lastObject] | 412 EXPECT_EQ([[[controller_ addressFormViewControllers] lastObject] |
| 311 retainCount], 1UL); | 413 retainCount], 1UL); |
| 312 [controller_ deleteAddress:[[controller_ addressFormViewControllers] | 414 [controller_ deleteAddress:[[controller_ addressFormViewControllers] |
| 313 lastObject]]; | 415 lastObject]]; |
| 314 [controller_ save:nil]; | 416 [controller_ save:nil]; |
| 315 | 417 |
| 316 // Should hit our observer. | 418 // Should hit our observer. |
| 317 ASSERT_TRUE(observer_.hit_); | 419 ASSERT_TRUE(observer_.hit_); |
| 318 | 420 |
| 319 // Sizes should match be different. New size should be 0. | 421 // Sizes should match be different. New size should be 0. |
| 320 ASSERT_NE(observer_.profiles_.size(), profiles_.size()); | 422 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
| 321 ASSERT_EQ(observer_.profiles_.size(), 0UL); | 423 ASSERT_EQ(observer_.profiles_.size(), 0UL); |
| 322 } | 424 } |
| 323 | 425 |
| 324 TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) { | 426 TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) { |
| 325 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 427 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
| 326 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 428 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
| 327 credit_cards_.push_back(&credit_card); | 429 credit_cards().push_back(&credit_card); |
| 328 LoadDialog(); | 430 LoadDialog(); |
| 329 EXPECT_EQ([[[controller_ creditCardFormViewControllers] lastObject] | 431 EXPECT_EQ([[[controller_ creditCardFormViewControllers] lastObject] |
| 330 retainCount], 1UL); | 432 retainCount], 1UL); |
| 331 [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers] | 433 [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers] |
| 332 lastObject]]; | 434 lastObject]]; |
| 333 [controller_ save:nil]; | 435 [controller_ save:nil]; |
| 334 | 436 |
| 335 // Should hit our observer. | 437 // Should hit our observer. |
| 336 ASSERT_TRUE(observer_.hit_); | 438 ASSERT_TRUE(observer_.hit_); |
| 337 | 439 |
| 338 // Sizes should match be different. New size should be 0. | 440 // Sizes should match be different. New size should be 0. |
| 339 ASSERT_NE(observer_.credit_cards_.size(), credit_cards_.size()); | 441 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
| 340 ASSERT_EQ(observer_.credit_cards_.size(), 0UL); | 442 ASSERT_EQ(observer_.credit_cards_.size(), 0UL); |
| 341 } | 443 } |
| 342 | 444 |
| 343 TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) { | 445 TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) { |
| 344 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 446 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
| 345 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 447 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
| 346 profiles_.push_back(&profile); | 448 profiles().push_back(&profile); |
| 347 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); | 449 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
| 348 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); | 450 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
| 349 profiles_.push_back(&profile2); | 451 profiles().push_back(&profile2); |
| 350 LoadDialog(); | 452 LoadDialog(); |
| 351 [controller_ deleteAddress:[[controller_ addressFormViewControllers] | 453 [controller_ deleteAddress:[[controller_ addressFormViewControllers] |
| 352 lastObject]]; | 454 lastObject]]; |
| 353 [controller_ save:nil]; | 455 [controller_ save:nil]; |
| 354 | 456 |
| 355 // Should hit our observer. | 457 // Should hit our observer. |
| 356 ASSERT_TRUE(observer_.hit_); | 458 ASSERT_TRUE(observer_.hit_); |
| 357 | 459 |
| 358 // Sizes should match be different. New size should be 0. | 460 // Sizes should match be different. New size should be 0. |
| 359 ASSERT_NE(observer_.profiles_.size(), profiles_.size()); | 461 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
| 360 ASSERT_EQ(observer_.profiles_.size(), 1UL); | 462 ASSERT_EQ(observer_.profiles_.size(), 1UL); |
| 361 | 463 |
| 362 // First address should match. | 464 // First address should match. |
| 363 profiles_[0]->set_unique_id(observer_.profiles_[0].unique_id()); | 465 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
| 364 ASSERT_EQ(observer_.profiles_[0], profile); | 466 ASSERT_EQ(observer_.profiles_[0], profile); |
| 365 } | 467 } |
| 366 | 468 |
| 367 TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) { | 469 TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) { |
| 368 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 470 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
| 369 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 471 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
| 370 credit_cards_.push_back(&credit_card); | 472 credit_cards().push_back(&credit_card); |
| 371 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); | 473 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
| 372 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 474 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
| 373 credit_cards_.push_back(&credit_card2); | 475 credit_cards().push_back(&credit_card2); |
| 374 LoadDialog(); | 476 LoadDialog(); |
| 375 [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers] | 477 [controller_ deleteCreditCard:[[controller_ creditCardFormViewControllers] |
| 376 lastObject]]; | 478 lastObject]]; |
| 377 [controller_ save:nil]; | 479 [controller_ save:nil]; |
| 378 | 480 |
| 379 // Should hit our observer. | 481 // Should hit our observer. |
| 380 ASSERT_TRUE(observer_.hit_); | 482 ASSERT_TRUE(observer_.hit_); |
| 381 | 483 |
| 382 // Sizes should match be different. New size should be 0. | 484 // Sizes should match be different. New size should be 0. |
| 383 ASSERT_NE(observer_.credit_cards_.size(), credit_cards_.size()); | 485 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
| 384 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); | 486 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); |
| 385 | 487 |
| 386 // First credit card should match. | 488 // First credit card should match. |
| 387 credit_cards_[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); | 489 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
| 388 ASSERT_EQ(observer_.credit_cards_[0], credit_card); | 490 ASSERT_EQ(observer_.credit_cards_[0], credit_card); |
| 389 } | 491 } |
| 390 | 492 |
| 391 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesFalse) { | 493 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesFalse) { |
| 392 LoadDialog(); | 494 LoadDialog(); |
| 393 [controller_ save:nil]; | 495 [controller_ save:nil]; |
| 394 | 496 |
| 395 // Should hit our observer. | 497 // Should hit our observer. |
| 396 ASSERT_TRUE(observer_.hit_); | 498 ASSERT_TRUE(observer_.hit_); |
| 397 | 499 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 426 | 528 |
| 427 // Auxiliary profiles setting should be unchanged. | 529 // Auxiliary profiles setting should be unchanged. |
| 428 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 530 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
| 429 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 531 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
| 430 } | 532 } |
| 431 | 533 |
| 432 TEST_F(AutoFillDialogControllerTest, DefaultsChangingLogic) { | 534 TEST_F(AutoFillDialogControllerTest, DefaultsChangingLogic) { |
| 433 // Two profiles, two credit cards. | 535 // Two profiles, two credit cards. |
| 434 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 536 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
| 435 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 537 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
| 436 profiles_.push_back(&profile); | 538 profiles().push_back(&profile); |
| 437 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); | 539 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
| 438 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); | 540 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
| 439 profiles_.push_back(&profile2); | 541 profiles().push_back(&profile2); |
| 440 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 542 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
| 441 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 543 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
| 442 credit_cards_.push_back(&credit_card); | 544 credit_cards().push_back(&credit_card); |
| 443 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); | 545 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
| 444 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 546 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
| 445 credit_cards_.push_back(&credit_card2); | 547 credit_cards().push_back(&credit_card2); |
| 446 | 548 |
| 447 // Invalid defaults for each. | 549 // Invalid defaults for each. |
| 448 helper_.profile()->GetPrefs()->SetString( | 550 helper_.profile()->GetPrefs()->SetString( |
| 449 prefs::kAutoFillDefaultProfile, L"xxxx"); | 551 prefs::kAutoFillDefaultProfile, L"xxxx"); |
| 450 helper_.profile()->GetPrefs()->SetString( | 552 helper_.profile()->GetPrefs()->SetString( |
| 451 prefs::kAutoFillDefaultCreditCard, L"yyyy"); | 553 prefs::kAutoFillDefaultCreditCard, L"yyyy"); |
| 452 | 554 |
| 453 // Start 'em up. | 555 // Start 'em up. |
| 454 LoadDialog(); | 556 LoadDialog(); |
| 455 | 557 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // Save and that should end up in the prefs. | 590 // Save and that should end up in the prefs. |
| 489 [controller_ save:nil]; | 591 [controller_ save:nil]; |
| 490 ASSERT_TRUE(observer_.hit_); | 592 ASSERT_TRUE(observer_.hit_); |
| 491 | 593 |
| 492 ASSERT_EQ(L"One", helper_.profile()->GetPrefs()-> | 594 ASSERT_EQ(L"One", helper_.profile()->GetPrefs()-> |
| 493 GetString(prefs::kAutoFillDefaultProfile)); | 595 GetString(prefs::kAutoFillDefaultProfile)); |
| 494 ASSERT_EQ(L"Visa", helper_.profile()->GetPrefs()-> | 596 ASSERT_EQ(L"Visa", helper_.profile()->GetPrefs()-> |
| 495 GetString(prefs::kAutoFillDefaultCreditCard)); | 597 GetString(prefs::kAutoFillDefaultCreditCard)); |
| 496 } | 598 } |
| 497 | 599 |
| 600 TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) { |
| 601 AutoFillProfile profile(ASCIIToUTF16("Home"), 0); |
| 602 profiles().push_back(&profile); |
| 603 CreditCard credit_card(ASCIIToUTF16("Visa"), 0); |
| 604 credit_cards().push_back(&credit_card); |
| 605 helper_.test_profile_->test_manager_->test_data_is_loaded_ = false; |
| 606 LoadDialog(); |
| 607 [controller_ save:nil]; |
| 608 |
| 609 // Should hit our observer. |
| 610 ASSERT_TRUE(observer_.hit_); |
| 611 |
| 612 // Sizes should match. |
| 613 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); |
| 614 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); |
| 615 |
| 616 // Contents should match. |
| 617 size_t i = 0; |
| 618 size_t count = profiles().size(); |
| 619 for (i = 0; i < count; i++) |
| 620 ASSERT_EQ(observer_.profiles_[i], *profiles()[i]); |
| 621 count = credit_cards().size(); |
| 622 for (i = 0; i < count; i++) { |
| 623 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]); |
| 624 } |
| 498 } | 625 } |
| 626 |
| 627 TEST_F(AutoFillDialogControllerTest, ImportedParameters) { |
| 628 AutoFillProfile profile(ASCIIToUTF16("Home"), 0); |
| 629 imported_profile_ = &profile; |
| 630 CreditCard credit_card(ASCIIToUTF16("Mastercard"), 0); |
| 631 imported_credit_card_ = &credit_card; |
| 632 |
| 633 // Note: when the |imported_*| parameters are supplied the dialog should |
| 634 // ignore any profile and credit card information in the |
| 635 // |PersonalDataManager|. |
| 636 AutoFillProfile profile_ignored(ASCIIToUTF16("Work"), 0); |
| 637 profiles().push_back(&profile_ignored); |
| 638 CreditCard credit_card_ignored(ASCIIToUTF16("Visa"), 0); |
| 639 credit_cards().push_back(&credit_card_ignored); |
| 640 |
| 641 LoadDialog(); |
| 642 [controller_ save:nil]; |
| 643 |
| 644 // Should hit our observer. |
| 645 ASSERT_TRUE(observer_.hit_); |
| 646 |
| 647 // Sizes should match. |
| 648 ASSERT_EQ(1UL, observer_.profiles_.size()); |
| 649 ASSERT_EQ(1UL, observer_.credit_cards_.size()); |
| 650 |
| 651 // Contents should match. |
| 652 ASSERT_EQ(observer_.profiles_[0], profile); |
| 653 ASSERT_EQ(observer_.credit_cards_[0], credit_card); |
| 654 } |
| 655 |
| 656 } // namespace |
| OLD | NEW |