OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/ref_counted.h" | 5 #include "base/ref_counted.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 8 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
9 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" | 9 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" |
10 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 10 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 class AutoFillDialogControllerTest : public CocoaTest { | 144 class AutoFillDialogControllerTest : public CocoaTest { |
145 public: | 145 public: |
146 AutoFillDialogControllerTest() | 146 AutoFillDialogControllerTest() |
147 : controller_(nil), | 147 : controller_(nil), |
148 imported_profile_(NULL), | 148 imported_profile_(NULL), |
149 imported_credit_card_(NULL) { | 149 imported_credit_card_(NULL) { |
150 } | 150 } |
151 | 151 |
152 void LoadDialog() { | 152 void LoadDialog() { |
153 controller_ = [AutoFillDialogController | 153 controller_ = [AutoFillDialogController |
154 controllerWithObserver:&observer_ | 154 controllerWithObserver:&observer_ profile:helper_.profile()]; |
155 profile:helper_.profile() | 155 [controller_ runModelessDialog]; |
156 importedProfile:imported_profile_ | |
157 importedCreditCard:imported_credit_card_]; | |
158 [controller_ window]; | |
159 } | 156 } |
160 | 157 |
161 std::vector<AutoFillProfile*>& profiles() { | 158 std::vector<AutoFillProfile*>& profiles() { |
162 return helper_.test_profile_->test_manager_->test_profiles_; | 159 return helper_.test_profile_->test_manager_->test_profiles_; |
163 } | 160 } |
164 std::vector<CreditCard*>& credit_cards() { | 161 std::vector<CreditCard*>& credit_cards() { |
165 return helper_.test_profile_->test_manager_->test_credit_cards_; | 162 return helper_.test_profile_->test_manager_->test_credit_cards_; |
166 } | 163 } |
167 | 164 |
168 BrowserMock helper_; | 165 BrowserMock helper_; |
169 AutoFillDialogObserverMock observer_; | 166 AutoFillDialogObserverMock observer_; |
170 AutoFillDialogController* controller_; // weak reference | 167 AutoFillDialogController* controller_; // weak reference |
171 AutoFillProfile* imported_profile_; // weak reference | 168 AutoFillProfile* imported_profile_; // weak reference |
172 CreditCard* imported_credit_card_; // weak reference | 169 CreditCard* imported_credit_card_; // weak reference |
173 | 170 |
174 private: | 171 private: |
175 DISALLOW_COPY_AND_ASSIGN(AutoFillDialogControllerTest); | 172 DISALLOW_COPY_AND_ASSIGN(AutoFillDialogControllerTest); |
176 }; | 173 }; |
177 | 174 |
178 TEST_F(AutoFillDialogControllerTest, SaveButtonInformsObserver) { | 175 TEST_F(AutoFillDialogControllerTest, CloseButtonDoesNotInformObserver) { |
179 LoadDialog(); | 176 LoadDialog(); |
180 [controller_ save:nil]; | 177 [controller_ closeDialog]; |
181 ASSERT_TRUE(observer_.hit_); | |
182 } | |
183 | |
184 TEST_F(AutoFillDialogControllerTest, CancelButtonDoesNotInformObserver) { | |
185 LoadDialog(); | |
186 [controller_ cancel:nil]; | |
187 ASSERT_FALSE(observer_.hit_); | 178 ASSERT_FALSE(observer_.hit_); |
188 } | 179 } |
189 | 180 |
190 TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalProfile) { | 181 TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverProfiles) { |
191 AutoFillProfile profile; | 182 AutoFillProfile profile; |
192 profiles().push_back(&profile); | 183 profiles().push_back(&profile); |
193 LoadDialog(); | 184 LoadDialog(); |
194 [controller_ save:nil]; | 185 [controller_ closeDialog]; |
195 | 186 |
196 // Should hit our observer. | 187 // Should not hit our observer. |
197 ASSERT_TRUE(observer_.hit_); | 188 ASSERT_FALSE(observer_.hit_); |
198 | 189 |
199 // Sizes should match. | 190 // Observer should not have profiles. |
200 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); | 191 ASSERT_EQ(0UL, observer_.profiles_.size()); |
201 | |
202 // Contents should match. | |
203 size_t i = 0; | |
204 size_t count = profiles().size(); | |
205 for (i = 0; i < count; i++) | |
206 ASSERT_EQ(observer_.profiles_[i], *profiles()[i]); | |
207 | |
208 // Contents should not match a different profile. | |
209 AutoFillProfile different_profile; | |
210 different_profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("joe")); | |
211 for (i = 0; i < count; i++) | |
212 ASSERT_NE(observer_.profiles_[i], different_profile); | |
213 } | 192 } |
214 | 193 |
215 TEST_F(AutoFillDialogControllerTest, NoEditsGiveBackOriginalCreditCard) { | 194 TEST_F(AutoFillDialogControllerTest, NoEditsDoNotChangeObserverCreditCards) { |
216 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); | 195 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); |
217 credit_cards().push_back(&credit_card); | 196 credit_cards().push_back(&credit_card); |
218 LoadDialog(); | 197 LoadDialog(); |
219 [controller_ save:nil]; | 198 [controller_ closeDialog]; |
220 | 199 |
221 // Should hit our observer. | 200 // Should not hit our observer. |
222 ASSERT_TRUE(observer_.hit_); | 201 ASSERT_FALSE(observer_.hit_); |
223 | 202 |
224 // Sizes should match. | 203 // Observer should not have credit cards. |
225 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); | 204 ASSERT_EQ(0UL, observer_.credit_cards_.size()); |
226 | |
227 // Contents should match. With the exception of the |unique_id|. | |
228 size_t i = 0; | |
229 size_t count = credit_cards().size(); | |
230 for (i = 0; i < count; i++) { | |
231 credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id()); | |
232 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]); | |
233 } | |
234 | |
235 // Contents should not match a different profile. | |
236 CreditCard different_credit_card(ASCIIToUTF16("different"), 0); | |
237 different_credit_card.SetInfo( | |
238 AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234")); | |
239 for (i = 0; i < count; i++) | |
240 ASSERT_NE(observer_.credit_cards_[i], different_credit_card); | |
241 } | 205 } |
242 | 206 |
243 TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) { | 207 TEST_F(AutoFillDialogControllerTest, AutoFillDataMutation) { |
244 AutoFillProfile profile(ASCIIToUTF16("Home"), 17); | 208 AutoFillProfile profile(ASCIIToUTF16("Home"), 17); |
245 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John")); | 209 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("John")); |
246 profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("C")); | 210 profile.SetInfo(AutoFillType(NAME_MIDDLE), ASCIIToUTF16("C")); |
247 profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith")); | 211 profile.SetInfo(AutoFillType(NAME_LAST), ASCIIToUTF16("Smith")); |
248 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), | 212 profile.SetInfo(AutoFillType(EMAIL_ADDRESS), |
249 ASCIIToUTF16("john@chromium.org")); | 213 ASCIIToUTF16("john@chromium.org")); |
250 profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google Inc.")); | 214 profile.SetInfo(AutoFillType(COMPANY_NAME), ASCIIToUTF16("Google Inc.")); |
251 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), | 215 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE1), |
252 ASCIIToUTF16("1122 Mountain View Road")); | 216 ASCIIToUTF16("1122 Mountain View Road")); |
253 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("Suite #1")); | 217 profile.SetInfo(AutoFillType(ADDRESS_HOME_LINE2), ASCIIToUTF16("Suite #1")); |
254 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), | 218 profile.SetInfo(AutoFillType(ADDRESS_HOME_CITY), |
255 ASCIIToUTF16("Mountain View")); | 219 ASCIIToUTF16("Mountain View")); |
256 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); | 220 profile.SetInfo(AutoFillType(ADDRESS_HOME_STATE), ASCIIToUTF16("CA")); |
257 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("94111")); | 221 profile.SetInfo(AutoFillType(ADDRESS_HOME_ZIP), ASCIIToUTF16("94111")); |
258 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA")); | 222 profile.SetInfo(AutoFillType(ADDRESS_HOME_COUNTRY), ASCIIToUTF16("USA")); |
259 profile.SetInfo( | 223 profile.SetInfo(AutoFillType(PHONE_HOME_WHOLE_NUMBER), |
260 AutoFillType(PHONE_HOME_WHOLE_NUMBER), ASCIIToUTF16("014155552258")); | 224 ASCIIToUTF16("014155552258")); |
261 profile.SetInfo( | 225 profile.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), |
262 AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("024087172258")); | 226 ASCIIToUTF16("024087172258")); |
263 profiles().push_back(&profile); | 227 profiles().push_back(&profile); |
264 | 228 |
265 LoadDialog(); | 229 LoadDialog(); |
266 [controller_ selectAddressAtIndex:0]; | 230 [controller_ selectAddressAtIndex:0]; |
267 [controller_ editSelection:nil]; | 231 [controller_ editSelection:nil]; |
268 | 232 |
269 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; | 233 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; |
270 ASSERT_TRUE(sheet != nil); | 234 ASSERT_TRUE(sheet != nil); |
271 AutoFillAddressModel* am = [sheet addressModel]; | 235 AutoFillAddressModel* am = [sheet addressModel]; |
272 EXPECT_TRUE([[am fullName] isEqualToString:@"John C Smith"]); | 236 EXPECT_TRUE([[am fullName] isEqualToString:@"John C Smith"]); |
273 EXPECT_TRUE([[am email] isEqualToString:@"john@chromium.org"]); | 237 EXPECT_TRUE([[am email] isEqualToString:@"john@chromium.org"]); |
274 EXPECT_TRUE([[am companyName] isEqualToString:@"Google Inc."]); | 238 EXPECT_TRUE([[am companyName] isEqualToString:@"Google Inc."]); |
275 EXPECT_TRUE([[am addressLine1] isEqualToString:@"1122 Mountain View Road"]); | 239 EXPECT_TRUE([[am addressLine1] isEqualToString:@"1122 Mountain View Road"]); |
276 EXPECT_TRUE([[am addressLine2] isEqualToString:@"Suite #1"]); | 240 EXPECT_TRUE([[am addressLine2] isEqualToString:@"Suite #1"]); |
277 EXPECT_TRUE([[am addressCity] isEqualToString:@"Mountain View"]); | 241 EXPECT_TRUE([[am addressCity] isEqualToString:@"Mountain View"]); |
278 EXPECT_TRUE([[am addressState] isEqualToString:@"CA"]); | 242 EXPECT_TRUE([[am addressState] isEqualToString:@"CA"]); |
279 EXPECT_TRUE([[am addressZip] isEqualToString:@"94111"]); | 243 EXPECT_TRUE([[am addressZip] isEqualToString:@"94111"]); |
280 EXPECT_TRUE([[am phoneWholeNumber] isEqualToString:@"014155552258"]); | 244 EXPECT_TRUE([[am phoneWholeNumber] isEqualToString:@"014155552258"]); |
281 EXPECT_TRUE([[am faxWholeNumber] isEqualToString:@"024087172258"]); | 245 EXPECT_TRUE([[am faxWholeNumber] isEqualToString:@"024087172258"]); |
282 | 246 |
283 [sheet save:nil]; | 247 [sheet save:nil]; |
284 [controller_ save:nil]; | 248 [controller_ closeDialog]; |
285 | 249 |
286 ASSERT_TRUE(observer_.hit_); | 250 ASSERT_TRUE(observer_.hit_); |
287 ASSERT_TRUE(observer_.profiles_.size() == 1); | 251 ASSERT_TRUE(observer_.profiles_.size() == 1); |
288 | 252 |
289 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); | 253 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
290 // Do not compare labels. Label is a derived field. | 254 // Do not compare labels. Label is a derived field. |
291 observer_.profiles_[0].set_label(string16()); | 255 observer_.profiles_[0].set_label(string16()); |
292 profiles()[0]->set_label(string16()); | 256 profiles()[0]->set_label(string16()); |
293 ASSERT_EQ(observer_.profiles_[0], *profiles()[0]); | 257 ASSERT_EQ(observer_.profiles_[0], *profiles()[0]); |
294 } | 258 } |
295 | 259 |
296 TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) { | 260 TEST_F(AutoFillDialogControllerTest, CreditCardDataMutation) { |
297 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); | 261 CreditCard credit_card(ASCIIToUTF16("myCC"), 345); |
298 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("DCH")); | 262 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("DCH")); |
299 credit_card.SetInfo( | 263 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NUMBER), |
300 AutoFillType(CREDIT_CARD_NUMBER), ASCIIToUTF16("1234 5678 9101 1121")); | 264 ASCIIToUTF16("1234 5678 9101 1121")); |
301 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01")); | 265 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), ASCIIToUTF16("01")); |
302 credit_card.SetInfo( | 266 credit_card.SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
303 AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), ASCIIToUTF16("2012")); | 267 ASCIIToUTF16("2012")); |
304 credit_cards().push_back(&credit_card); | 268 credit_cards().push_back(&credit_card); |
305 | 269 |
306 LoadDialog(); | 270 LoadDialog(); |
307 [controller_ selectCreditCardAtIndex:0]; | 271 [controller_ selectCreditCardAtIndex:0]; |
308 [controller_ editSelection:nil]; | 272 [controller_ editSelection:nil]; |
309 | 273 |
310 AutoFillCreditCardSheetController* sheet = | 274 AutoFillCreditCardSheetController* sheet = |
311 [controller_ creditCardSheetController]; | 275 [controller_ creditCardSheetController]; |
312 ASSERT_TRUE(sheet != nil); | 276 ASSERT_TRUE(sheet != nil); |
313 AutoFillCreditCardModel* cm = [sheet creditCardModel]; | 277 AutoFillCreditCardModel* cm = [sheet creditCardModel]; |
314 EXPECT_TRUE([[cm nameOnCard] isEqualToString:@"DCH"]); | 278 EXPECT_TRUE([[cm nameOnCard] isEqualToString:@"DCH"]); |
315 EXPECT_TRUE([[cm creditCardNumber] isEqualToString:@"1234 5678 9101 1121"]); | 279 EXPECT_TRUE([[cm creditCardNumber] isEqualToString:@"1234 5678 9101 1121"]); |
316 EXPECT_TRUE([[cm expirationMonth] isEqualToString:@"01"]); | 280 EXPECT_TRUE([[cm expirationMonth] isEqualToString:@"01"]); |
317 EXPECT_TRUE([[cm expirationYear] isEqualToString:@"2012"]); | 281 EXPECT_TRUE([[cm expirationYear] isEqualToString:@"2012"]); |
318 | 282 |
319 // Check that user-visible text is obfuscated. | 283 // Check that user-visible text is obfuscated. |
320 NSTextField* numberField = [sheet creditCardNumberField]; | 284 NSTextField* numberField = [sheet creditCardNumberField]; |
321 ASSERT_TRUE(numberField != nil); | 285 ASSERT_TRUE(numberField != nil); |
322 EXPECT_TRUE([[numberField stringValue] isEqualToString:@"************1121"]); | 286 EXPECT_TRUE([[numberField stringValue] isEqualToString:@"************1121"]); |
323 | 287 |
324 [sheet save:nil]; | 288 [sheet save:nil]; |
325 [controller_ save:nil]; | 289 [controller_ closeDialog]; |
326 | 290 |
327 ASSERT_TRUE(observer_.hit_); | 291 ASSERT_TRUE(observer_.hit_); |
328 ASSERT_TRUE(observer_.credit_cards_.size() == 1); | 292 ASSERT_TRUE(observer_.credit_cards_.size() == 1); |
329 | 293 |
330 // Don't compare unique ids. | 294 // Don't compare unique ids. |
331 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); | 295 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
332 ASSERT_EQ(observer_.credit_cards_[0], *credit_cards()[0]); | 296 ASSERT_EQ(observer_.credit_cards_[0], *credit_cards()[0]); |
333 } | 297 } |
334 | 298 |
335 TEST_F(AutoFillDialogControllerTest, TwoProfiles) { | 299 TEST_F(AutoFillDialogControllerTest, TwoProfiles) { |
336 AutoFillProfile profile1(ASCIIToUTF16("One"), 1); | 300 AutoFillProfile profile1(ASCIIToUTF16("One"), 1); |
337 profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 301 profile1.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
338 profiles().push_back(&profile1); | 302 profiles().push_back(&profile1); |
339 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); | 303 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
340 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); | 304 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
341 profiles().push_back(&profile2); | 305 profiles().push_back(&profile2); |
342 LoadDialog(); | 306 LoadDialog(); |
343 [controller_ save:nil]; | 307 [controller_ closeDialog]; |
344 | 308 |
345 // Should hit our observer. | 309 // Should not hit our observer. |
346 ASSERT_TRUE(observer_.hit_); | 310 ASSERT_FALSE(observer_.hit_); |
347 | 311 |
348 // Sizes should match. And should be 2. | 312 // Sizes should match. And should be 2. |
349 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); | 313 ASSERT_EQ([controller_ profiles].size(), profiles().size()); |
350 ASSERT_EQ(observer_.profiles_.size(), 2UL); | 314 ASSERT_EQ([controller_ profiles].size(), 2UL); |
351 | 315 |
352 // Contents should match. With the exception of the |unique_id|. | 316 // Contents should match. With the exception of the |unique_id|. |
353 for (size_t i = 0, count = profiles().size(); i < count; i++) { | 317 for (size_t i = 0, count = profiles().size(); i < count; i++) { |
354 profiles()[i]->set_unique_id(observer_.profiles_[i].unique_id()); | 318 profiles()[i]->set_unique_id([controller_ profiles][i].unique_id()); |
355 | 319 |
356 // Do not compare labels. Label is a derived field. | 320 // Do not compare labels. Label is a derived field. |
357 observer_.profiles_[i].set_label(string16()); | 321 [controller_ profiles][i].set_label(string16()); |
358 profiles()[i]->set_label(string16()); | 322 profiles()[i]->set_label(string16()); |
359 ASSERT_EQ(observer_.profiles_[i], *profiles()[i]); | 323 ASSERT_EQ([controller_ profiles][i], *profiles()[i]); |
360 } | 324 } |
361 } | 325 } |
362 | 326 |
363 TEST_F(AutoFillDialogControllerTest, TwoCreditCards) { | 327 TEST_F(AutoFillDialogControllerTest, TwoCreditCards) { |
364 CreditCard credit_card1(ASCIIToUTF16("Visa"), 1); | 328 CreditCard credit_card1(ASCIIToUTF16("Visa"), 1); |
365 credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 329 credit_card1.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
366 credit_cards().push_back(&credit_card1); | 330 credit_cards().push_back(&credit_card1); |
367 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); | 331 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
368 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 332 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
369 credit_cards().push_back(&credit_card2); | 333 credit_cards().push_back(&credit_card2); |
370 LoadDialog(); | 334 LoadDialog(); |
371 [controller_ save:nil]; | 335 [controller_ closeDialog]; |
372 | 336 |
373 // Should hit our observer. | 337 // Should not hit our observer. |
374 ASSERT_TRUE(observer_.hit_); | 338 ASSERT_FALSE(observer_.hit_); |
375 | 339 |
376 // Sizes should match. And should be 2. | 340 // Sizes should match. And should be 2. |
377 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); | 341 ASSERT_EQ([controller_ creditCards].size(), credit_cards().size()); |
378 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); | 342 ASSERT_EQ([controller_ creditCards].size(), 2UL); |
379 | 343 |
380 // Contents should match. With the exception of the |unique_id|. | 344 // Contents should match. With the exception of the |unique_id|. |
381 for (size_t i = 0, count = credit_cards().size(); i < count; i++) { | 345 for (size_t i = 0, count = credit_cards().size(); i < count; i++) { |
382 credit_cards()[i]->set_unique_id(observer_.credit_cards_[i].unique_id()); | 346 credit_cards()[i]->set_unique_id([controller_ creditCards][i].unique_id()); |
383 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]); | 347 ASSERT_EQ([controller_ creditCards][i], *credit_cards()[i]); |
384 } | 348 } |
385 } | 349 } |
386 | 350 |
387 TEST_F(AutoFillDialogControllerTest, AddNewProfile) { | 351 TEST_F(AutoFillDialogControllerTest, AddNewProfile) { |
388 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 352 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
389 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 353 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
390 profiles().push_back(&profile); | 354 profiles().push_back(&profile); |
391 LoadDialog(); | 355 LoadDialog(); |
392 [controller_ addNewAddress:nil]; | 356 [controller_ addNewAddress:nil]; |
393 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; | 357 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; |
394 ASSERT_TRUE(sheet != nil); | 358 ASSERT_TRUE(sheet != nil); |
395 AutoFillAddressModel* model = [sheet addressModel]; | 359 AutoFillAddressModel* model = [sheet addressModel]; |
396 ASSERT_TRUE(model != nil); | 360 ASSERT_TRUE(model != nil); |
397 [model setFullName:@"Don"]; | 361 [model setFullName:@"Don"]; |
398 [sheet save:nil]; | 362 [sheet save:nil]; |
399 [controller_ save:nil]; | 363 [controller_ closeDialog]; |
400 | 364 |
401 // Should hit our observer. | 365 // Should hit our observer. |
402 ASSERT_TRUE(observer_.hit_); | 366 ASSERT_TRUE(observer_.hit_); |
403 | 367 |
404 // Sizes should be different. New size should be 2. | 368 // Sizes should be different. New size should be 2. |
405 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 369 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
406 ASSERT_EQ(observer_.profiles_.size(), 2UL); | 370 ASSERT_EQ(observer_.profiles_.size(), 2UL); |
407 | 371 |
408 // New address should match. Don't compare labels. | 372 // New address should match. Don't compare labels. |
409 AutoFillProfile new_profile; | 373 AutoFillProfile new_profile; |
410 new_profile.SetInfo(AutoFillType(NAME_FULL), ASCIIToUTF16("Don")); | 374 new_profile.SetInfo(AutoFillType(NAME_FULL), ASCIIToUTF16("Don")); |
411 observer_.profiles_[1].set_label(string16()); | 375 observer_.profiles_[1].set_label(string16()); |
412 ASSERT_EQ(observer_.profiles_[1], new_profile); | 376 ASSERT_EQ(observer_.profiles_[1], new_profile); |
413 } | 377 } |
414 | 378 |
415 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { | 379 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { |
416 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 380 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
417 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 381 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
418 credit_cards().push_back(&credit_card); | 382 credit_cards().push_back(&credit_card); |
419 LoadDialog(); | 383 LoadDialog(); |
420 [controller_ addNewCreditCard:nil]; | 384 [controller_ addNewCreditCard:nil]; |
421 AutoFillCreditCardSheetController* sheet = | 385 AutoFillCreditCardSheetController* sheet = |
422 [controller_ creditCardSheetController]; | 386 [controller_ creditCardSheetController]; |
423 ASSERT_TRUE(sheet != nil); | 387 ASSERT_TRUE(sheet != nil); |
424 AutoFillCreditCardModel* model = [sheet creditCardModel]; | 388 AutoFillCreditCardModel* model = [sheet creditCardModel]; |
425 ASSERT_TRUE(model != nil); | 389 ASSERT_TRUE(model != nil); |
426 [model setNameOnCard:@"Don"]; | 390 [model setNameOnCard:@"Don"]; |
427 [sheet save:nil]; | 391 [sheet save:nil]; |
428 [controller_ save:nil]; | 392 [controller_ closeDialog]; |
429 | 393 |
430 // Should hit our observer. | 394 // Should hit our observer. |
431 ASSERT_TRUE(observer_.hit_); | 395 ASSERT_TRUE(observer_.hit_); |
432 | 396 |
433 // Sizes should be different. New size should be 2. | 397 // Sizes should be different. New size should be 2. |
434 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 398 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
435 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); | 399 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); |
436 | 400 |
437 // New credit card should match. Don't compare labels. | 401 // New credit card should match. Don't compare labels. |
438 CreditCard new_credit_card; | 402 CreditCard new_credit_card; |
439 new_credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Don")); | 403 new_credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Don")); |
440 observer_.credit_cards_[1].set_label(string16()); | 404 observer_.credit_cards_[1].set_label(string16()); |
441 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); | 405 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); |
442 } | 406 } |
443 | 407 |
444 TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) { | 408 TEST_F(AutoFillDialogControllerTest, AddNewEmptyProfile) { |
445 AutoFillProfile profile(string16(), 1); | 409 AutoFillProfile profile(string16(), 1); |
446 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 410 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
447 profiles().push_back(&profile); | 411 profiles().push_back(&profile); |
448 LoadDialog(); | 412 LoadDialog(); |
449 [controller_ addNewAddress:nil]; | 413 [controller_ addNewAddress:nil]; |
450 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; | 414 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; |
451 ASSERT_TRUE(sheet != nil); | 415 ASSERT_TRUE(sheet != nil); |
452 [sheet save:nil]; | 416 [sheet save:nil]; |
453 [controller_ save:nil]; | 417 [controller_ closeDialog]; |
454 | 418 |
455 // Should hit our observer. | 419 // Should not hit our observer. |
456 ASSERT_TRUE(observer_.hit_); | 420 ASSERT_FALSE(observer_.hit_); |
457 | 421 |
458 // Sizes should be same. Empty profile should not be saved. | 422 // Empty profile should not be saved. |
459 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); | 423 ASSERT_EQ(0UL, observer_.profiles_.size()); |
460 ASSERT_EQ(observer_.profiles_.size(), 1UL); | |
461 | |
462 // Profile should match original. | |
463 observer_.profiles_[0].set_label(string16()); | |
464 ASSERT_EQ(observer_.profiles_[0], profile); | |
465 } | 424 } |
466 | 425 |
467 TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) { | 426 TEST_F(AutoFillDialogControllerTest, AddNewEmptyCreditCard) { |
468 CreditCard credit_card(string16(), 1); | 427 CreditCard credit_card(string16(), 1); |
469 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 428 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
470 credit_cards().push_back(&credit_card); | 429 credit_cards().push_back(&credit_card); |
471 LoadDialog(); | 430 LoadDialog(); |
472 [controller_ addNewCreditCard:nil]; | 431 [controller_ addNewCreditCard:nil]; |
473 AutoFillCreditCardSheetController* sheet = | 432 AutoFillCreditCardSheetController* sheet = |
474 [controller_ creditCardSheetController]; | 433 [controller_ creditCardSheetController]; |
475 ASSERT_TRUE(sheet != nil); | 434 ASSERT_TRUE(sheet != nil); |
476 [sheet save:nil]; | 435 [sheet save:nil]; |
477 [controller_ save:nil]; | 436 [controller_ closeDialog]; |
478 | 437 |
479 // Should hit our observer. | 438 // Should hit our observer. |
480 ASSERT_TRUE(observer_.hit_); | 439 ASSERT_FALSE(observer_.hit_); |
481 | 440 |
482 // Sizes should be same. Empty credit card should not be saved. | 441 // Empty credit card should not be saved. |
483 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); | 442 ASSERT_EQ(0UL, observer_.credit_cards_.size()); |
484 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); | |
485 | |
486 // Credit card should match original. | |
487 observer_.credit_cards_[0].set_label(string16()); | |
488 ASSERT_EQ(observer_.credit_cards_[0], credit_card); | |
489 } | 443 } |
490 | 444 |
491 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { | 445 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { |
492 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 446 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
493 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 447 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
494 profiles().push_back(&profile); | 448 profiles().push_back(&profile); |
495 LoadDialog(); | 449 LoadDialog(); |
496 [controller_ selectAddressAtIndex:0]; | 450 [controller_ selectAddressAtIndex:0]; |
497 [controller_ deleteSelection:nil]; | 451 [controller_ deleteSelection:nil]; |
498 [controller_ save:nil]; | 452 [controller_ closeDialog]; |
499 | 453 |
500 // Should hit our observer. | 454 // Should hit our observer. |
501 ASSERT_TRUE(observer_.hit_); | 455 ASSERT_TRUE(observer_.hit_); |
502 | 456 |
503 // Sizes should be different. New size should be 0. | 457 // Sizes should be different. New size should be 0. |
504 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 458 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
505 ASSERT_EQ(observer_.profiles_.size(), 0UL); | 459 ASSERT_EQ(observer_.profiles_.size(), 0UL); |
506 } | 460 } |
507 | 461 |
508 TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) { | 462 TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) { |
509 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 463 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
510 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 464 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
511 credit_cards().push_back(&credit_card); | 465 credit_cards().push_back(&credit_card); |
512 LoadDialog(); | 466 LoadDialog(); |
513 [controller_ selectCreditCardAtIndex:0]; | 467 [controller_ selectCreditCardAtIndex:0]; |
514 [controller_ deleteSelection:nil]; | 468 [controller_ deleteSelection:nil]; |
515 [controller_ save:nil]; | 469 [controller_ closeDialog]; |
516 | 470 |
517 // Should hit our observer. | 471 // Should hit our observer. |
518 ASSERT_TRUE(observer_.hit_); | 472 ASSERT_TRUE(observer_.hit_); |
519 | 473 |
520 // Sizes should be different. New size should be 0. | 474 // Sizes should be different. New size should be 0. |
521 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 475 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
522 ASSERT_EQ(observer_.credit_cards_.size(), 0UL); | 476 ASSERT_EQ(observer_.credit_cards_.size(), 0UL); |
523 } | 477 } |
524 | 478 |
525 TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) { | 479 TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) { |
526 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 480 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
527 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 481 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
528 profiles().push_back(&profile); | 482 profiles().push_back(&profile); |
529 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); | 483 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
530 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); | 484 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
531 profiles().push_back(&profile2); | 485 profiles().push_back(&profile2); |
532 LoadDialog(); | 486 LoadDialog(); |
533 [controller_ selectAddressAtIndex:1]; | 487 [controller_ selectAddressAtIndex:1]; |
534 [controller_ deleteSelection:nil]; | 488 [controller_ deleteSelection:nil]; |
535 [controller_ save:nil]; | 489 [controller_ closeDialog]; |
536 | 490 |
537 // Should hit our observer. | 491 // Should hit our observer. |
538 ASSERT_TRUE(observer_.hit_); | 492 ASSERT_TRUE(observer_.hit_); |
539 | 493 |
540 // Sizes should be different. New size should be 1. | 494 // Sizes should be different. New size should be 1. |
541 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 495 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
542 ASSERT_EQ(observer_.profiles_.size(), 1UL); | 496 ASSERT_EQ(observer_.profiles_.size(), 1UL); |
543 | 497 |
544 // First address should match. | 498 // First address should match. |
545 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); | 499 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
546 | 500 |
547 // Do not compare labels. Label is a derived field. | 501 // Do not compare labels. Label is a derived field. |
548 observer_.profiles_[0].set_label(string16()); | 502 observer_.profiles_[0].set_label(string16()); |
549 profile.set_label(string16()); | 503 profile.set_label(string16()); |
550 ASSERT_EQ(observer_.profiles_[0], profile); | 504 ASSERT_EQ(observer_.profiles_[0], profile); |
551 } | 505 } |
552 | 506 |
553 TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) { | 507 TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) { |
554 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 508 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
555 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 509 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
556 credit_cards().push_back(&credit_card); | 510 credit_cards().push_back(&credit_card); |
557 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); | 511 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
558 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 512 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
559 credit_cards().push_back(&credit_card2); | 513 credit_cards().push_back(&credit_card2); |
560 LoadDialog(); | 514 LoadDialog(); |
561 [controller_ selectCreditCardAtIndex:1]; | 515 [controller_ selectCreditCardAtIndex:1]; |
562 [controller_ deleteSelection:nil]; | 516 [controller_ deleteSelection:nil]; |
563 [controller_ save:nil]; | 517 [controller_ closeDialog]; |
564 | 518 |
565 // Should hit our observer. | 519 // Should hit our observer. |
566 ASSERT_TRUE(observer_.hit_); | 520 ASSERT_TRUE(observer_.hit_); |
567 | 521 |
568 // Sizes should be different. New size should be 1. | 522 // Sizes should be different. New size should be 1. |
569 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 523 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
570 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); | 524 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); |
571 | 525 |
572 // First credit card should match. | 526 // First credit card should match. |
573 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); | 527 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
(...skipping 15 matching lines...) Expand all Loading... |
589 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 543 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
590 credit_cards().push_back(&credit_card2); | 544 credit_cards().push_back(&credit_card2); |
591 | 545 |
592 LoadDialog(); | 546 LoadDialog(); |
593 [controller_ selectAddressAtIndex:1]; | 547 [controller_ selectAddressAtIndex:1]; |
594 [controller_ addSelectedCreditCardAtIndex:0]; | 548 [controller_ addSelectedCreditCardAtIndex:0]; |
595 ASSERT_FALSE([controller_ editButtonEnabled]); | 549 ASSERT_FALSE([controller_ editButtonEnabled]); |
596 [controller_ deleteSelection:nil]; | 550 [controller_ deleteSelection:nil]; |
597 [controller_ selectAddressAtIndex:0]; | 551 [controller_ selectAddressAtIndex:0]; |
598 ASSERT_TRUE([controller_ editButtonEnabled]); | 552 ASSERT_TRUE([controller_ editButtonEnabled]); |
599 [controller_ save:nil]; | 553 [controller_ closeDialog]; |
600 | 554 |
601 // Should hit our observer. | 555 // Should hit our observer. |
602 ASSERT_TRUE(observer_.hit_); | 556 ASSERT_TRUE(observer_.hit_); |
603 | 557 |
604 // Sizes should be different. New size should be 1. | 558 // Sizes should be different. New size should be 1. |
605 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 559 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
606 ASSERT_EQ(observer_.profiles_.size(), 1UL); | 560 ASSERT_EQ(observer_.profiles_.size(), 1UL); |
607 | 561 |
608 // Sizes should be different. New size should be 1. | 562 // Sizes should be different. New size should be 1. |
609 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 563 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
610 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); | 564 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); |
611 | 565 |
612 // First address should match. | 566 // First address should match. |
613 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); | 567 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
614 | 568 |
615 // Do not compare labels. Label is a derived field. | 569 // Do not compare labels. Label is a derived field. |
616 observer_.profiles_[0].set_label(string16()); | 570 observer_.profiles_[0].set_label(string16()); |
617 profile.set_label(string16()); | 571 profile.set_label(string16()); |
618 ASSERT_EQ(observer_.profiles_[0], profile); | 572 ASSERT_EQ(observer_.profiles_[0], profile); |
619 | 573 |
620 // Second credit card should match. | 574 // Second credit card should match. |
621 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); | 575 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
622 ASSERT_EQ(observer_.credit_cards_[0], credit_card2); | 576 ASSERT_EQ(observer_.credit_cards_[0], credit_card2); |
623 } | 577 } |
624 | 578 |
625 // Auxilliary profiles are enabled by default. | 579 // Auxilliary profiles are enabled by default. |
626 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesTrue) { | 580 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesTrue) { |
627 LoadDialog(); | 581 LoadDialog(); |
628 [controller_ save:nil]; | 582 [controller_ closeDialog]; |
629 | 583 |
630 // Should hit our observer. | 584 // Should not hit our observer. |
631 ASSERT_TRUE(observer_.hit_); | 585 ASSERT_FALSE(observer_.hit_); |
632 | 586 |
633 // Auxiliary profiles setting should be unchanged. | 587 // Auxiliary profiles setting should be unchanged. |
634 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 588 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
635 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 589 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
636 } | 590 } |
637 | 591 |
638 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesFalse) { | 592 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesFalse) { |
639 helper_.profile()->GetPrefs()->SetBoolean( | 593 helper_.profile()->GetPrefs()->SetBoolean( |
640 prefs::kAutoFillAuxiliaryProfilesEnabled, false); | 594 prefs::kAutoFillAuxiliaryProfilesEnabled, false); |
641 LoadDialog(); | 595 LoadDialog(); |
642 [controller_ save:nil]; | 596 [controller_ closeDialog]; |
643 | 597 |
644 // Should hit our observer. | 598 // Should not hit our observer. |
645 ASSERT_TRUE(observer_.hit_); | 599 ASSERT_FALSE(observer_.hit_); |
646 | 600 |
647 // Auxiliary profiles setting should be unchanged. | 601 // Auxiliary profiles setting should be unchanged. |
648 ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean( | 602 ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean( |
649 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 603 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
650 } | 604 } |
651 | 605 |
652 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesChanged) { | 606 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesChanged) { |
653 helper_.profile()->GetPrefs()->SetBoolean( | 607 helper_.profile()->GetPrefs()->SetBoolean( |
654 prefs::kAutoFillAuxiliaryProfilesEnabled, false); | 608 prefs::kAutoFillAuxiliaryProfilesEnabled, false); |
655 LoadDialog(); | 609 LoadDialog(); |
656 [controller_ setAuxiliaryEnabled:YES]; | 610 [controller_ setAuxiliaryEnabled:YES]; |
657 [controller_ save:nil]; | 611 [controller_ closeDialog]; |
658 | 612 |
659 // Should hit our observer. | 613 // Should not hit our observer. |
660 ASSERT_TRUE(observer_.hit_); | 614 ASSERT_FALSE(observer_.hit_); |
661 | 615 |
662 // Auxiliary profiles setting should be unchanged. | 616 // Auxiliary profiles setting should be unchanged. |
663 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 617 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
664 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 618 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
665 } | 619 } |
666 | 620 |
667 TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) { | 621 TEST_F(AutoFillDialogControllerTest, WaitForDataToLoad) { |
668 AutoFillProfile profile(ASCIIToUTF16("Home"), 0); | 622 AutoFillProfile profile(ASCIIToUTF16("Home"), 0); |
669 profiles().push_back(&profile); | 623 profiles().push_back(&profile); |
670 CreditCard credit_card(ASCIIToUTF16("Visa"), 0); | 624 CreditCard credit_card(ASCIIToUTF16("Visa"), 0); |
671 credit_cards().push_back(&credit_card); | 625 credit_cards().push_back(&credit_card); |
672 helper_.test_profile_->test_manager_->test_data_is_loaded_ = false; | 626 helper_.test_profile_->test_manager_->test_data_is_loaded_ = false; |
673 LoadDialog(); | 627 LoadDialog(); |
674 [controller_ save:nil]; | 628 [controller_ closeDialog]; |
675 | 629 |
676 // Should hit our observer. | 630 // Should not hit our observer. |
677 ASSERT_TRUE(observer_.hit_); | 631 ASSERT_FALSE(observer_.hit_); |
678 | 632 |
679 // Sizes should match. | 633 // Sizes should match. |
680 ASSERT_EQ(observer_.profiles_.size(), profiles().size()); | 634 ASSERT_EQ([controller_ profiles].size(), profiles().size()); |
681 ASSERT_EQ(observer_.credit_cards_.size(), credit_cards().size()); | 635 ASSERT_EQ([controller_ creditCards].size(), credit_cards().size()); |
682 | 636 |
683 // Contents should match. | 637 // Contents should match. |
684 size_t i = 0; | 638 size_t i = 0; |
685 size_t count = profiles().size(); | 639 size_t count = profiles().size(); |
686 for (i = 0; i < count; i++) { | 640 for (i = 0; i < count; i++) { |
687 // Do not compare labels. Label is a derived field. | 641 // Do not compare labels. Label is a derived field. |
688 observer_.profiles_[i].set_label(string16()); | 642 [controller_ profiles][i].set_label(string16()); |
689 profiles()[i]->set_label(string16()); | 643 profiles()[i]->set_label(string16()); |
690 ASSERT_EQ(observer_.profiles_[i], *profiles()[i]); | 644 ASSERT_EQ([controller_ profiles][i], *profiles()[i]); |
691 } | 645 } |
692 count = credit_cards().size(); | 646 count = credit_cards().size(); |
693 for (i = 0; i < count; i++) { | 647 for (i = 0; i < count; i++) { |
694 ASSERT_EQ(observer_.credit_cards_[i], *credit_cards()[i]); | 648 ASSERT_EQ([controller_ creditCards][i], *credit_cards()[i]); |
695 } | 649 } |
696 } | 650 } |
697 | 651 |
698 TEST_F(AutoFillDialogControllerTest, ImportedParameters) { | |
699 AutoFillProfile profile(ASCIIToUTF16("Home"), 0); | |
700 imported_profile_ = &profile; | |
701 CreditCard credit_card(ASCIIToUTF16("Mastercard"), 0); | |
702 imported_credit_card_ = &credit_card; | |
703 | |
704 // Note: when the |imported_*| parameters are supplied the dialog should | |
705 // ignore any profile and credit card information in the | |
706 // |PersonalDataManager|. | |
707 AutoFillProfile profile_ignored(ASCIIToUTF16("Work"), 0); | |
708 profiles().push_back(&profile_ignored); | |
709 CreditCard credit_card_ignored(ASCIIToUTF16("Visa"), 0); | |
710 credit_cards().push_back(&credit_card_ignored); | |
711 | |
712 LoadDialog(); | |
713 [controller_ save:nil]; | |
714 | |
715 // Should hit our observer. | |
716 ASSERT_TRUE(observer_.hit_); | |
717 | |
718 // Sizes should match. | |
719 ASSERT_EQ(1UL, observer_.profiles_.size()); | |
720 ASSERT_EQ(1UL, observer_.credit_cards_.size()); | |
721 | |
722 // Do not compare labels. Label is a derived field. | |
723 observer_.profiles_[0].set_label(string16()); | |
724 profile.set_label(string16()); | |
725 | |
726 // Contents should match. | |
727 ASSERT_EQ(observer_.profiles_[0], profile); | |
728 ASSERT_EQ(observer_.credit_cards_[0], credit_card); | |
729 } | |
730 | |
731 // AutoFill is enabled by default. | 652 // AutoFill is enabled by default. |
732 TEST_F(AutoFillDialogControllerTest, AutoFillEnabledTrue) { | 653 TEST_F(AutoFillDialogControllerTest, AutoFillEnabledTrue) { |
733 LoadDialog(); | 654 LoadDialog(); |
734 [controller_ save:nil]; | 655 [controller_ closeDialog]; |
735 | 656 |
736 // Should hit our observer. | 657 // Should not hit our observer. |
737 ASSERT_TRUE(observer_.hit_); | 658 ASSERT_FALSE(observer_.hit_); |
738 | 659 |
739 // AutoFill enabled setting should be unchanged. | 660 // AutoFill enabled setting should be unchanged. |
740 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 661 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
741 prefs::kAutoFillEnabled)); | 662 prefs::kAutoFillEnabled)); |
742 } | 663 } |
743 | 664 |
744 TEST_F(AutoFillDialogControllerTest, AutoFillEnabledFalse) { | 665 TEST_F(AutoFillDialogControllerTest, AutoFillEnabledFalse) { |
745 helper_.profile()->GetPrefs()->SetBoolean(prefs::kAutoFillEnabled, false); | 666 helper_.profile()->GetPrefs()->SetBoolean(prefs::kAutoFillEnabled, false); |
746 LoadDialog(); | 667 LoadDialog(); |
747 [controller_ save:nil]; | 668 [controller_ closeDialog]; |
748 | 669 |
749 // Should hit our observer. | 670 // Should not hit our observer. |
750 ASSERT_TRUE(observer_.hit_); | 671 ASSERT_FALSE(observer_.hit_); |
751 | 672 |
752 // AutoFill enabled setting should be unchanged. | 673 // AutoFill enabled setting should be unchanged. |
753 ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean( | 674 ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean( |
754 prefs::kAutoFillEnabled)); | 675 prefs::kAutoFillEnabled)); |
755 } | 676 } |
756 | 677 |
757 TEST_F(AutoFillDialogControllerTest, AutoFillEnabledChanged) { | 678 TEST_F(AutoFillDialogControllerTest, AutoFillEnabledChanged) { |
758 helper_.profile()->GetPrefs()->SetBoolean( | 679 helper_.profile()->GetPrefs()->SetBoolean( |
759 prefs::kAutoFillAuxiliaryProfilesEnabled, false); | 680 prefs::kAutoFillAuxiliaryProfilesEnabled, false); |
760 LoadDialog(); | 681 LoadDialog(); |
761 [controller_ setAutoFillEnabled:YES]; | 682 [controller_ setAutoFillEnabled:YES]; |
762 [controller_ save:nil]; | 683 [controller_ closeDialog]; |
763 | 684 |
764 // Should hit our observer. | 685 // Should not hit our observer. |
765 ASSERT_TRUE(observer_.hit_); | 686 ASSERT_FALSE(observer_.hit_); |
766 | 687 |
767 // Auxiliary profiles setting should be unchanged. | 688 // Auxiliary profiles setting should be unchanged. |
768 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 689 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
769 prefs::kAutoFillEnabled)); | 690 prefs::kAutoFillEnabled)); |
770 } | 691 } |
771 | 692 |
772 TEST_F(AutoFillDialogControllerTest, PolicyRefresh) { | 693 TEST_F(AutoFillDialogControllerTest, PolicyRefresh) { |
773 LoadDialog(); | 694 LoadDialog(); |
774 ASSERT_FALSE([controller_ autoFillManaged]); | 695 ASSERT_FALSE([controller_ autoFillManaged]); |
775 | 696 |
776 // Disable AutoFill through configuration policy. | 697 // Disable AutoFill through configuration policy. |
777 helper_.profile()->GetTestingPrefService()->SetManagedPref( | 698 helper_.profile()->GetTestingPrefService()->SetManagedPref( |
778 prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); | 699 prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); |
779 ASSERT_TRUE([controller_ autoFillManaged]); | 700 ASSERT_TRUE([controller_ autoFillManaged]); |
780 ASSERT_FALSE([controller_ autoFillEnabled]); | 701 ASSERT_FALSE([controller_ autoFillEnabled]); |
781 | 702 |
782 // Enabling through policy should switch to enabled but not editable. | 703 // Enabling through policy should switch to enabled but not editable. |
783 helper_.profile()->GetTestingPrefService()->SetManagedPref( | 704 helper_.profile()->GetTestingPrefService()->SetManagedPref( |
784 prefs::kAutoFillEnabled, Value::CreateBooleanValue(true)); | 705 prefs::kAutoFillEnabled, Value::CreateBooleanValue(true)); |
785 ASSERT_TRUE([controller_ autoFillManaged]); | 706 ASSERT_TRUE([controller_ autoFillManaged]); |
786 ASSERT_TRUE([controller_ autoFillEnabled]); | 707 ASSERT_TRUE([controller_ autoFillEnabled]); |
787 | 708 |
788 [controller_ cancel:nil]; | 709 [controller_ closeDialog]; |
789 } | 710 } |
790 | 711 |
791 TEST_F(AutoFillDialogControllerTest, PolicyDisabledAndSave) { | 712 TEST_F(AutoFillDialogControllerTest, PolicyDisabledAndSave) { |
792 // Disable AutoFill through configuration policy. | 713 // Disable AutoFill through configuration policy. |
793 helper_.profile()->GetTestingPrefService()->SetManagedPref( | 714 helper_.profile()->GetTestingPrefService()->SetManagedPref( |
794 prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); | 715 prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); |
795 helper_.profile()->GetPrefs()->SetBoolean( | 716 helper_.profile()->GetPrefs()->SetBoolean( |
796 prefs::kAutoFillAuxiliaryProfilesEnabled, false); | 717 prefs::kAutoFillAuxiliaryProfilesEnabled, false); |
797 LoadDialog(); | 718 LoadDialog(); |
798 | 719 |
799 // Save should be disabled. | 720 // Save should be disabled. |
800 ASSERT_TRUE([controller_ autoFillManagedAndDisabled]); | 721 ASSERT_TRUE([controller_ autoFillManagedAndDisabled]); |
801 | 722 |
802 [controller_ setAuxiliaryEnabled:YES]; | 723 [controller_ setAuxiliaryEnabled:YES]; |
803 [controller_ save:nil]; | 724 [controller_ closeDialog]; |
804 | 725 |
805 // Observer should not have been called. | 726 // Observer should not have been called. |
806 ASSERT_FALSE(observer_.hit_); | 727 ASSERT_FALSE(observer_.hit_); |
807 | 728 |
808 // Auxiliary profiles setting should be unchanged. | 729 // Auxiliary profiles setting should be unchanged. |
809 ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean( | 730 ASSERT_FALSE(helper_.profile()->GetPrefs()->GetBoolean( |
810 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 731 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
811 } | 732 } |
812 | 733 |
813 TEST_F(AutoFillDialogControllerTest, PolicyEnabledAndSave) { | 734 TEST_F(AutoFillDialogControllerTest, PolicyEnabledAndSave) { |
814 // Enable AutoFill through configuration policy. | 735 // Enable AutoFill through configuration policy. |
815 helper_.profile()->GetTestingPrefService()->SetManagedPref( | 736 helper_.profile()->GetTestingPrefService()->SetManagedPref( |
816 prefs::kAutoFillEnabled, Value::CreateBooleanValue(true)); | 737 prefs::kAutoFillEnabled, Value::CreateBooleanValue(true)); |
817 helper_.profile()->GetPrefs()->SetBoolean( | 738 helper_.profile()->GetPrefs()->SetBoolean( |
818 prefs::kAutoFillAuxiliaryProfilesEnabled, false); | 739 prefs::kAutoFillAuxiliaryProfilesEnabled, false); |
819 LoadDialog(); | 740 LoadDialog(); |
820 | 741 |
821 // Save should be enabled. | 742 // Save should be enabled. |
822 ASSERT_FALSE([controller_ autoFillManagedAndDisabled]); | 743 ASSERT_FALSE([controller_ autoFillManagedAndDisabled]); |
823 | 744 |
824 [controller_ setAuxiliaryEnabled:YES]; | 745 [controller_ setAuxiliaryEnabled:YES]; |
825 [controller_ save:nil]; | 746 [controller_ closeDialog]; |
826 | 747 |
827 // Observer should have been notified. | 748 // Observer should not have been notified. |
828 ASSERT_TRUE(observer_.hit_); | 749 ASSERT_FALSE(observer_.hit_); |
829 | 750 |
830 // Auxiliary profiles setting should have been saved. | 751 // Auxiliary profiles setting should have been saved. |
831 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 752 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
832 prefs::kAutoFillAuxiliaryProfilesEnabled)); | 753 prefs::kAutoFillAuxiliaryProfilesEnabled)); |
833 } | 754 } |
834 | 755 |
835 } // namespace | 756 } // namespace |
OLD | NEW |