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