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

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: Created 7 years, 7 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
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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 controller()->InputValidityMessage(iter->type, string16()); 405 controller()->InputValidityMessage(iter->type, string16());
406 } 406 }
407 } 407 }
408 } 408 }
409 409
410 // Test for phone number validation. 410 // Test for phone number validation.
411 TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) { 411 TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) {
412 // Construct DetailOutputMap from existing data. 412 // Construct DetailOutputMap from existing data.
413 SwitchToAutofill(); 413 SwitchToAutofill();
414 414
415 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
416
417 AutofillProfile full_profile(test::GetFullProfile()); 415 AutofillProfile full_profile(test::GetFullProfile());
418 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 416 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
419 controller()->EditClickedForSection(SECTION_SHIPPING); 417 controller()->EditClickedForSection(SECTION_SHIPPING);
420 418
421 DetailOutputMap outputs; 419 DetailOutputMap outputs;
422 const DetailInputs& inputs = 420 const DetailInputs& inputs =
423 controller()->RequestedFieldsForSection(SECTION_SHIPPING); 421 controller()->RequestedFieldsForSection(SECTION_SHIPPING);
424 422
425 // Make sure country is United States. 423 // Make sure country is United States.
426 SetOutputValue(inputs, &outputs, ADDRESS_HOME_COUNTRY, "United States"); 424 SetOutputValue(inputs, &outputs, ADDRESS_HOME_COUNTRY, "United States");
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 472
475 // Input an invalid international phone number. 473 // Input an invalid international phone number.
476 SetOutputValue(inputs, &outputs, PHONE_HOME_WHOLE_NUMBER, 474 SetOutputValue(inputs, &outputs, PHONE_HOME_WHOLE_NUMBER,
477 "+112333 892 70 12 39"); 475 "+112333 892 70 12 39");
478 validity_data = 476 validity_data =
479 controller()->InputsAreValid(outputs, 477 controller()->InputsAreValid(outputs,
480 AutofillDialogController::VALIDATE_EDIT); 478 AutofillDialogController::VALIDATE_EDIT);
481 EXPECT_EQ(1U, validity_data.count(PHONE_HOME_WHOLE_NUMBER)); 479 EXPECT_EQ(1U, validity_data.count(PHONE_HOME_WHOLE_NUMBER));
482 } 480 }
483 481
482 TEST_F(AutofillDialogControllerTest, CardHolderNameValidation) {
483 // Construct DetailOutputMap from AutofillProfile data.
484 SwitchToAutofill();
485
486 AutofillProfile full_profile(test::GetFullProfile());
487 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
488 controller()->EditClickedForSection(SECTION_SHIPPING);
489
490 DetailOutputMap outputs;
491 const DetailInputs& inputs =
492 controller()->RequestedFieldsForSection(SECTION_CC);
493
494 // Input an empty card holder name with VALIDATE_FINAL.
495 SetOutputValue(inputs, &outputs, CREDIT_CARD_NAME, "");
496 ValidityData validity_data =
497 controller()->InputsAreValid(outputs,
498 AutofillDialogController::VALIDATE_FINAL);
499 EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
500
501 // Input an empty card holder name with VALIDATE_EDIT.
502 validity_data =
503 controller()->InputsAreValid(outputs,
504 AutofillDialogController::VALIDATE_EDIT);
505 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
506
507 // Input a non-empty card holder name.
508 SetOutputValue(inputs, &outputs, CREDIT_CARD_NAME, "Bob");
509 validity_data =
510 controller()->InputsAreValid(outputs,
511 AutofillDialogController::VALIDATE_FINAL);
512 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
513
514 // Switch to Wallet which only considers names with with at least two names to
515 // be valid.
516 SwitchToWallet();
517
518 // Setup some wallet state.
519 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
520 wallet_items->AddAddress(wallet::GetTestShippingAddress());
521 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
522 controller()->OnDidGetWalletItems(wallet_items.Pass());
523
524 controller()->EditClickedForSection(SECTION_CC_BILLING);
525
526 DetailOutputMap wallet_outputs;
527 const DetailInputs& wallet_inputs =
528 controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
529
530 // Input an empty card holder name with VALIDATE_FINAL. Data source should not
531 // change this behavior.
532 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME, "");
533 validity_data =
534 controller()->InputsAreValid(wallet_outputs,
535 AutofillDialogController::VALIDATE_FINAL);
536 EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
537
538 // Input an empty card holder name with VALIDATE_EDIT. Data source should not
539 // change this behavior.
540 validity_data =
541 controller()->InputsAreValid(wallet_outputs,
542 AutofillDialogController::VALIDATE_EDIT);
543 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
544
545 // Input a one name card holder name. Wallet does not currently support this.
546 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME, "Bob");
547 validity_data =
548 controller()->InputsAreValid(wallet_outputs,
549 AutofillDialogController::VALIDATE_FINAL);
550 EXPECT_EQ(1U, validity_data.count(CREDIT_CARD_NAME));
551
552 // Input a two name card holder name.
553 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
554 "Bob Barker");
555 validity_data =
556 controller()->InputsAreValid(wallet_outputs,
557 AutofillDialogController::VALIDATE_FINAL);
558 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
559
560 // Input a more than two name card holder name.
561 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
562 "John Jacob Jingleheimer Schmidt");
563 validity_data =
564 controller()->InputsAreValid(wallet_outputs,
565 AutofillDialogController::VALIDATE_FINAL);
566 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
567
568 // Input a card holder name with lots of crazy whitespace.
569 SetOutputValue(wallet_inputs, &wallet_outputs, CREDIT_CARD_NAME,
570 " \\n\\r John \\n Jacob Jingleheimer \\t Schmidt ");
571 validity_data =
572 controller()->InputsAreValid(wallet_outputs,
573 AutofillDialogController::VALIDATE_FINAL);
574 EXPECT_EQ(0U, validity_data.count(CREDIT_CARD_NAME));
575 }
576
484 TEST_F(AutofillDialogControllerTest, AutofillProfiles) { 577 TEST_F(AutofillDialogControllerTest, AutofillProfiles) {
485 ui::MenuModel* shipping_model = 578 ui::MenuModel* shipping_model =
486 controller()->MenuModelForSection(SECTION_SHIPPING); 579 controller()->MenuModelForSection(SECTION_SHIPPING);
487 // Since the PersonalDataManager is empty, this should only have the 580 // Since the PersonalDataManager is empty, this should only have the
488 // "use billing", "add new" and "manage" menu items. 581 // "use billing", "add new" and "manage" menu items.
489 EXPECT_EQ(3, shipping_model->GetItemCount()); 582 EXPECT_EQ(3, shipping_model->GetItemCount());
490 // On the other hand, the other models should be NULL when there's no 583 // On the other hand, the other models should be NULL when there's no
491 // suggestion. 584 // suggestion.
492 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC)); 585 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC));
493 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING)); 586 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_BILLING));
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1389 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1297 1390
1298 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 1391 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
1299 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 1392 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
1300 1393
1301 profile()->set_incognito(true); 1394 profile()->set_incognito(true);
1302 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 1395 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
1303 } 1396 }
1304 1397
1305 } // namespace autofill 1398 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698