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 #import "chrome/browser/autofill/autofill_address_model_mac.h" | 6 #import "chrome/browser/autofill/autofill_address_model_mac.h" |
7 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" | 7 #import "chrome/browser/autofill/autofill_address_sheet_controller_mac.h" |
8 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" | 8 #import "chrome/browser/autofill/autofill_credit_card_model_mac.h" |
9 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" | 9 #import "chrome/browser/autofill/autofill_credit_card_sheet_controller_mac.h" |
10 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" | 10 #import "chrome/browser/autofill/autofill_dialog_controller_mac.h" |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 LoadDialog(); | 382 LoadDialog(); |
383 [controller_ addNewAddress:nil]; | 383 [controller_ addNewAddress:nil]; |
384 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; | 384 AutoFillAddressSheetController* sheet = [controller_ addressSheetController]; |
385 ASSERT_TRUE(sheet != nil); | 385 ASSERT_TRUE(sheet != nil); |
386 [sheet save:nil]; | 386 [sheet save:nil]; |
387 [controller_ save:nil]; | 387 [controller_ save:nil]; |
388 | 388 |
389 // Should hit our observer. | 389 // Should hit our observer. |
390 ASSERT_TRUE(observer_.hit_); | 390 ASSERT_TRUE(observer_.hit_); |
391 | 391 |
392 // Sizes should match be different. New size should be 2. | 392 // Sizes should be different. New size should be 2. |
393 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 393 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
394 ASSERT_EQ(observer_.profiles_.size(), 2UL); | 394 ASSERT_EQ(observer_.profiles_.size(), 2UL); |
395 | 395 |
396 // New address should match. | 396 // New address should match. |
397 AutoFillProfile new_profile; | 397 AutoFillProfile new_profile; |
398 ASSERT_EQ(observer_.profiles_[1], new_profile); | 398 ASSERT_EQ(observer_.profiles_[1], new_profile); |
399 } | 399 } |
400 | 400 |
401 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { | 401 TEST_F(AutoFillDialogControllerTest, AddNewCreditCard) { |
402 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 402 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
403 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 403 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
404 credit_cards().push_back(&credit_card); | 404 credit_cards().push_back(&credit_card); |
405 LoadDialog(); | 405 LoadDialog(); |
406 [controller_ addNewCreditCard:nil]; | 406 [controller_ addNewCreditCard:nil]; |
407 AutoFillCreditCardSheetController* sheet = | 407 AutoFillCreditCardSheetController* sheet = |
408 [controller_ creditCardSheetController]; | 408 [controller_ creditCardSheetController]; |
409 ASSERT_TRUE(sheet != nil); | 409 ASSERT_TRUE(sheet != nil); |
410 [sheet save:nil]; | 410 [sheet save:nil]; |
411 [controller_ save:nil]; | 411 [controller_ save:nil]; |
412 | 412 |
413 // Should hit our observer. | 413 // Should hit our observer. |
414 ASSERT_TRUE(observer_.hit_); | 414 ASSERT_TRUE(observer_.hit_); |
415 | 415 |
416 // Sizes should match be different. New size should be 2. | 416 // Sizes should be different. New size should be 2. |
417 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 417 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
418 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); | 418 ASSERT_EQ(observer_.credit_cards_.size(), 2UL); |
419 | 419 |
420 // New address should match. | 420 // New address should match. |
421 CreditCard new_credit_card; | 421 CreditCard new_credit_card; |
422 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); | 422 ASSERT_EQ(observer_.credit_cards_[1], new_credit_card); |
423 } | 423 } |
424 | 424 |
425 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { | 425 TEST_F(AutoFillDialogControllerTest, DeleteProfile) { |
426 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 426 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
427 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 427 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
428 profiles().push_back(&profile); | 428 profiles().push_back(&profile); |
429 LoadDialog(); | 429 LoadDialog(); |
430 [controller_ selectAddressAtIndex:0]; | 430 [controller_ selectAddressAtIndex:0]; |
431 [controller_ deleteSelection:nil]; | 431 [controller_ deleteSelection:nil]; |
432 [controller_ save:nil]; | 432 [controller_ save:nil]; |
433 | 433 |
434 // Should hit our observer. | 434 // Should hit our observer. |
435 ASSERT_TRUE(observer_.hit_); | 435 ASSERT_TRUE(observer_.hit_); |
436 | 436 |
437 // Sizes should match be different. New size should be 0. | 437 // Sizes should be different. New size should be 0. |
438 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 438 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
439 ASSERT_EQ(observer_.profiles_.size(), 0UL); | 439 ASSERT_EQ(observer_.profiles_.size(), 0UL); |
440 } | 440 } |
441 | 441 |
442 TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) { | 442 TEST_F(AutoFillDialogControllerTest, DeleteCreditCard) { |
443 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 443 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
444 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 444 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
445 credit_cards().push_back(&credit_card); | 445 credit_cards().push_back(&credit_card); |
446 LoadDialog(); | 446 LoadDialog(); |
447 [controller_ selectCreditCardAtIndex:0]; | 447 [controller_ selectCreditCardAtIndex:0]; |
448 [controller_ deleteSelection:nil]; | 448 [controller_ deleteSelection:nil]; |
449 [controller_ save:nil]; | 449 [controller_ save:nil]; |
450 | 450 |
451 // Should hit our observer. | 451 // Should hit our observer. |
452 ASSERT_TRUE(observer_.hit_); | 452 ASSERT_TRUE(observer_.hit_); |
453 | 453 |
454 // Sizes should match be different. New size should be 0. | 454 // Sizes should be different. New size should be 0. |
455 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 455 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
456 ASSERT_EQ(observer_.credit_cards_.size(), 0UL); | 456 ASSERT_EQ(observer_.credit_cards_.size(), 0UL); |
457 } | 457 } |
458 | 458 |
459 TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) { | 459 TEST_F(AutoFillDialogControllerTest, TwoProfilesDeleteOne) { |
460 AutoFillProfile profile(ASCIIToUTF16("One"), 1); | 460 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
461 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); | 461 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
462 profiles().push_back(&profile); | 462 profiles().push_back(&profile); |
463 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); | 463 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
464 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); | 464 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
465 profiles().push_back(&profile2); | 465 profiles().push_back(&profile2); |
466 LoadDialog(); | 466 LoadDialog(); |
467 [controller_ selectAddressAtIndex:1]; | 467 [controller_ selectAddressAtIndex:1]; |
468 [controller_ deleteSelection:nil]; | 468 [controller_ deleteSelection:nil]; |
469 [controller_ save:nil]; | 469 [controller_ save:nil]; |
470 | 470 |
471 // Should hit our observer. | 471 // Should hit our observer. |
472 ASSERT_TRUE(observer_.hit_); | 472 ASSERT_TRUE(observer_.hit_); |
473 | 473 |
474 // Sizes should match be different. New size should be 0. | 474 // Sizes should be different. New size should be 1. |
475 ASSERT_NE(observer_.profiles_.size(), profiles().size()); | 475 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
476 ASSERT_EQ(observer_.profiles_.size(), 1UL); | 476 ASSERT_EQ(observer_.profiles_.size(), 1UL); |
477 | 477 |
478 // First address should match. | 478 // First address should match. |
479 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); | 479 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
480 | 480 |
481 // Do not compare labels. Label is a derived field. | 481 // Do not compare labels. Label is a derived field. |
482 observer_.profiles_[0].set_label(string16()); | 482 observer_.profiles_[0].set_label(string16()); |
483 profile.set_label(string16()); | 483 profile.set_label(string16()); |
484 ASSERT_EQ(observer_.profiles_[0], profile); | 484 ASSERT_EQ(observer_.profiles_[0], profile); |
485 } | 485 } |
486 | 486 |
487 TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) { | 487 TEST_F(AutoFillDialogControllerTest, TwoCreditCardsDeleteOne) { |
488 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); | 488 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
489 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); | 489 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
490 credit_cards().push_back(&credit_card); | 490 credit_cards().push_back(&credit_card); |
491 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); | 491 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
492 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); | 492 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
493 credit_cards().push_back(&credit_card2); | 493 credit_cards().push_back(&credit_card2); |
494 LoadDialog(); | 494 LoadDialog(); |
495 [controller_ selectCreditCardAtIndex:1]; | 495 [controller_ selectCreditCardAtIndex:1]; |
496 [controller_ deleteSelection:nil]; | 496 [controller_ deleteSelection:nil]; |
497 [controller_ save:nil]; | 497 [controller_ save:nil]; |
498 | 498 |
499 // Should hit our observer. | 499 // Should hit our observer. |
500 ASSERT_TRUE(observer_.hit_); | 500 ASSERT_TRUE(observer_.hit_); |
501 | 501 |
502 // Sizes should match be different. New size should be 0. | 502 // Sizes should be different. New size should be 1. |
503 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); | 503 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
504 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); | 504 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); |
505 | 505 |
506 // First credit card should match. | 506 // First credit card should match. |
507 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); | 507 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
508 ASSERT_EQ(observer_.credit_cards_[0], credit_card); | 508 ASSERT_EQ(observer_.credit_cards_[0], credit_card); |
509 } | 509 } |
510 | 510 |
| 511 TEST_F(AutoFillDialogControllerTest, DeleteMultiple) { |
| 512 AutoFillProfile profile(ASCIIToUTF16("One"), 1); |
| 513 profile.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Joe")); |
| 514 profiles().push_back(&profile); |
| 515 AutoFillProfile profile2(ASCIIToUTF16("Two"), 2); |
| 516 profile2.SetInfo(AutoFillType(NAME_FIRST), ASCIIToUTF16("Bob")); |
| 517 profiles().push_back(&profile2); |
| 518 |
| 519 CreditCard credit_card(ASCIIToUTF16("Visa"), 1); |
| 520 credit_card.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Joe")); |
| 521 credit_cards().push_back(&credit_card); |
| 522 CreditCard credit_card2(ASCIIToUTF16("Mastercard"), 2); |
| 523 credit_card2.SetInfo(AutoFillType(CREDIT_CARD_NAME), ASCIIToUTF16("Bob")); |
| 524 credit_cards().push_back(&credit_card2); |
| 525 |
| 526 LoadDialog(); |
| 527 [controller_ selectAddressAtIndex:1]; |
| 528 [controller_ addSelectedCreditCardAtIndex:0]; |
| 529 ASSERT_FALSE([controller_ editButtonEnabled]); |
| 530 [controller_ deleteSelection:nil]; |
| 531 [controller_ selectAddressAtIndex:0]; |
| 532 ASSERT_TRUE([controller_ editButtonEnabled]); |
| 533 [controller_ save:nil]; |
| 534 |
| 535 // Should hit our observer. |
| 536 ASSERT_TRUE(observer_.hit_); |
| 537 |
| 538 // Sizes should be different. New size should be 1. |
| 539 ASSERT_NE(observer_.profiles_.size(), profiles().size()); |
| 540 ASSERT_EQ(observer_.profiles_.size(), 1UL); |
| 541 |
| 542 // Sizes should be different. New size should be 1. |
| 543 ASSERT_NE(observer_.credit_cards_.size(), credit_cards().size()); |
| 544 ASSERT_EQ(observer_.credit_cards_.size(), 1UL); |
| 545 |
| 546 // First address should match. |
| 547 profiles()[0]->set_unique_id(observer_.profiles_[0].unique_id()); |
| 548 |
| 549 // Do not compare labels. Label is a derived field. |
| 550 observer_.profiles_[0].set_label(string16()); |
| 551 profile.set_label(string16()); |
| 552 ASSERT_EQ(observer_.profiles_[0], profile); |
| 553 |
| 554 // Second credit card should match. |
| 555 credit_cards()[0]->set_unique_id(observer_.credit_cards_[0].unique_id()); |
| 556 ASSERT_EQ(observer_.credit_cards_[0], credit_card2); |
| 557 } |
| 558 |
511 // Auxilliary profiles are enabled by default. | 559 // Auxilliary profiles are enabled by default. |
512 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesTrue) { | 560 TEST_F(AutoFillDialogControllerTest, AuxiliaryProfilesTrue) { |
513 LoadDialog(); | 561 LoadDialog(); |
514 [controller_ save:nil]; | 562 [controller_ save:nil]; |
515 | 563 |
516 // Should hit our observer. | 564 // Should hit our observer. |
517 ASSERT_TRUE(observer_.hit_); | 565 ASSERT_TRUE(observer_.hit_); |
518 | 566 |
519 // Auxiliary profiles setting should be unchanged. | 567 // Auxiliary profiles setting should be unchanged. |
520 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 568 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 | 697 |
650 // Should hit our observer. | 698 // Should hit our observer. |
651 ASSERT_TRUE(observer_.hit_); | 699 ASSERT_TRUE(observer_.hit_); |
652 | 700 |
653 // Auxiliary profiles setting should be unchanged. | 701 // Auxiliary profiles setting should be unchanged. |
654 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( | 702 ASSERT_TRUE(helper_.profile()->GetPrefs()->GetBoolean( |
655 prefs::kAutoFillEnabled)); | 703 prefs::kAutoFillEnabled)); |
656 } | 704 } |
657 | 705 |
658 } // namespace | 706 } // namespace |
OLD | NEW |