Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 15401005: Force at least first and last name for CREDIT_CARD_NAME when using Wallet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing windows compile Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/guid.h" 5 #include "base/guid.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 controller()->InputValidityMessage(iter->type, string16()); 423 controller()->InputValidityMessage(iter->type, string16());
424 } 424 }
425 } 425 }
426 } 426 }
427 427
428 // Test for phone number validation. 428 // Test for phone number validation.
429 TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) { 429 TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) {
430 // Construct DetailOutputMap from existing data. 430 // Construct DetailOutputMap from existing data.
431 SwitchToAutofill(); 431 SwitchToAutofill();
432 432
433 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
434
435 AutofillProfile full_profile(test::GetVerifiedProfile()); 433 AutofillProfile full_profile(test::GetVerifiedProfile());
436 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 434 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
437 controller()->EditClickedForSection(SECTION_SHIPPING); 435 controller()->EditClickedForSection(SECTION_SHIPPING);
438 436
439 DetailOutputMap outputs; 437 DetailOutputMap outputs;
440 const DetailInputs& inputs = 438 const DetailInputs& inputs =
441 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 439 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
442 440
443 // Make sure country is United States. 441 // Make sure country is United States.
444 SetOutputValue(inputs, &outputs, ADDRESS_HOME_COUNTRY, "United States"); 442 SetOutputValue(inputs, &outputs, ADDRESS_HOME_COUNTRY, "United States");
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 490
493 // Input an invalid international phone number. 491 // Input an invalid international phone number.
494 SetOutputValue(inputs, &outputs, PHONE_HOME_WHOLE_NUMBER, 492 SetOutputValue(inputs, &outputs, PHONE_HOME_WHOLE_NUMBER,
495 "+112333 892 70 12 39"); 493 "+112333 892 70 12 39");
496 validity_data = 494 validity_data =
497 controller()->InputsAreValid(outputs, 495 controller()->InputsAreValid(outputs,
498 AutofillDialogController::VALIDATE_EDIT); 496 AutofillDialogController::VALIDATE_EDIT);
499 EXPECT_EQ(1U, validity_data.count(PHONE_HOME_WHOLE_NUMBER)); 497 EXPECT_EQ(1U, validity_data.count(PHONE_HOME_WHOLE_NUMBER));
500 } 498 }
501 499
500 TEST_F(AutofillDialogControllerTest, CardHolderNameValidation) {
501 // Construct DetailOutputMap from AutofillProfile data.
502 SwitchToAutofill();
503
504 AutofillProfile full_profile(test::GetVerifiedProfile());
505 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
506 controller()->EditClickedForSection(SECTION_SHIPPING);
507
508 DetailOutputMap outputs;
509 const DetailInputs& inputs =
510 controller()->RequestedFieldsForSection(SECTION_CC);
511
512 // Input an empty card holder name with VALIDATE_FINAL.
513 SetOutputValue(inputs, &outputs, CREDIT_CARD_NAME, "");
514 ValidityData validity_data =
515 controller()->InputsAreValid(outputs,
516 AutofillDialogController::VALIDATE_FINAL);
517 EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
518
519 // Input an empty card holder name with VALIDATE_EDIT.
520 validity_data =
521 controller()->InputsAreValid(outputs,
522 AutofillDialogController::VALIDATE_EDIT);
523 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
524
525 // Input a non-empty card holder name.
526 SetOutputValue(inputs, &outputs, CREDIT_CARD_NAME, "Bob");
527 validity_data =
528 controller()->InputsAreValid(outputs,
529 AutofillDialogController::VALIDATE_FINAL);
530 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
531
532 // Switch to Wallet which only considers names with with at least two names to
533 // be valid.
534 SwitchToWallet();
535
536 // Setup some wallet state.
537 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
538 wallet_items->AddAddress(wallet::GetTestShippingAddress());
539 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
540 controller()->OnDidGetWalletItems(wallet_items.Pass());
541
542 controller()->EditClickedForSection(SECTION_CC_BILLING);
543
544 DetailOutputMap wallet_outputs;
545 const DetailInputs& wallet_inputs =
546 controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
547
548 // Input an empty card holder name with VALIDATE_FINAL. Data source should not
549 // change this behavior.
550 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME, "");
551 validity_data =
552 controller()->InputsAreValid(wallet_outputs,
553 AutofillDialogController::VALIDATE_FINAL);
554 EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
555
556 // Input an empty card holder name with VALIDATE_EDIT. Data source should not
557 // change this behavior.
558 validity_data =
559 controller()->InputsAreValid(wallet_outputs,
560 AutofillDialogController::VALIDATE_EDIT);
561 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
562
563 // Input a one name card holder name. Wallet does not currently support this.
564 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME, "Bob");
565 validity_data =
566 controller()->InputsAreValid(wallet_outputs,
567 AutofillDialogController::VALIDATE_FINAL);
568 EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
569
570 // Input a two name card holder name.
571 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
572 "Bob Barker");
573 validity_data =
574 controller()->InputsAreValid(wallet_outputs,
575 AutofillDialogController::VALIDATE_FINAL);
576 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
577
578 // Input a more than two name card holder name.
579 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
580 "John Jacob Jingleheimer Schmidt");
581 validity_data =
582 controller()->InputsAreValid(wallet_outputs,
583 AutofillDialogController::VALIDATE_FINAL);
584 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
585
586 // Input a card holder name with lots of crazy whitespace.
587 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
588 " \\n\\r John \\n Jacob Jingleheimer \\t Schmidt ");
589 validity_data =
590 controller()->InputsAreValid(wallet_outputs,
591 AutofillDialogController::VALIDATE_FINAL);
592 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
593 }
594
502 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { 595 TEST_F(AutofillDialogControllerTest, AutofillProfiles) {
503 ui::MenuModel* shipping_model = 596 ui::MenuModel* shipping_model =
504 controller()->MenuModelForSection(SECTION_SHIPPING); 597 controller()->MenuModelForSection(SECTION_SHIPPING);
505 // Since the PersonalDataManager is empty, this should only have the 598 // Since the PersonalDataManager is empty, this should only have the
506 // "use billing", "add new" and "manage" menu items. 599 // "use billing", "add new" and "manage" menu items.
507 ASSERT_TRUE(shipping_model); 600 ASSERT_TRUE(shipping_model);
508 EXPECT_EQ(3, shipping_model->GetItemCount()); 601 EXPECT_EQ(3, shipping_model->GetItemCount());
509 // On the other hand, the other models should be NULL when there's no 602 // On the other hand, the other models should be NULL when there's no
510 // suggestion. 603 // suggestion.
511 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 604 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 controller()->OnDidGetWalletItems( 1670 controller()->OnDidGetWalletItems(
1578 wallet::WalletItems::CreateWalletItems(dict).Pass()); 1671 wallet::WalletItems::CreateWalletItems(dict).Pass());
1579 1672
1580 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); 1673 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
1581 // "Same as billing" and "Add address...". 1674 // "Same as billing" and "Add address...".
1582 EXPECT_EQ( 1675 EXPECT_EQ(
1583 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 1676 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
1584 } 1677 }
1585 1678
1586 } // namespace autofill 1679 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698