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

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

Issue 23882013: [rAc] Persist selection of newly added cards and addresses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests, add a test Created 7 years, 3 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 <map> 5 #include <map>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 DetailOutputMap cc_outputs; 453 DetailOutputMap cc_outputs;
454 const DetailInputs& cc_inputs = 454 const DetailInputs& cc_inputs =
455 controller()->RequestedFieldsForSection(SECTION_CC); 455 controller()->RequestedFieldsForSection(SECTION_CC);
456 for (size_t i = 0; i < cc_inputs.size(); ++i) { 456 for (size_t i = 0; i < cc_inputs.size(); ++i) {
457 cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ? 457 cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ?
458 ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11"); 458 ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11");
459 } 459 }
460 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs); 460 controller()->GetView()->SetUserInput(SECTION_CC, cc_outputs);
461 } 461 }
462 462
463 // Activates the 'Add new foo' option from the |section|'s suggestions
464 // dropdown and fills the |section|'s inputs with the data from the
465 // |data_model|. If |section| is SECTION_CC, also fills in '123' for the CVC.
466 void FillInputs(DialogSection section, const AutofillDataModel& data_model) {
467 // Select the 'Add new foo' option.
468 ui::MenuModel* model = GetMenuModelForSection(section);
469 model->ActivatedAt(model->GetItemCount() - 2);
470
471 // Fill the inputs.
472 DetailOutputMap outputs;
473 const DetailInputs& inputs =
474 controller()->RequestedFieldsForSection(section);
475 for (size_t i = 0; i < inputs.size(); ++i) {
476 ServerFieldType type = inputs[i].type;
477 base::string16 output;
478 if (type == CREDIT_CARD_VERIFICATION_CODE)
479 output = ASCIIToUTF16("123");
480 else
481 output = data_model.GetInfo(AutofillType(type), "en-US");
482 outputs[&inputs[i]] = output;
483 }
484 controller()->GetView()->SetUserInput(section, outputs);
485 }
486
463 std::vector<DialogNotification> NotificationsOfType( 487 std::vector<DialogNotification> NotificationsOfType(
464 DialogNotification::Type type) { 488 DialogNotification::Type type) {
465 std::vector<DialogNotification> right_type; 489 std::vector<DialogNotification> right_type;
466 const std::vector<DialogNotification>& notifications = 490 const std::vector<DialogNotification>& notifications =
467 controller()->CurrentNotifications(); 491 controller()->CurrentNotifications();
468 for (size_t i = 0; i < notifications.size(); ++i) { 492 for (size_t i = 0; i < notifications.size(); ++i) {
469 if (notifications[i].type() == type) 493 if (notifications[i].type() == type)
470 right_type.push_back(notifications[i]); 494 right_type.push_back(notifications[i]);
471 } 495 }
472 return right_type; 496 return right_type;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 const DetailInputs& inputs = 555 const DetailInputs& inputs =
532 controller()->RequestedFieldsForSection(section); 556 controller()->RequestedFieldsForSection(section);
533 for (DetailInputs::const_iterator it = inputs.begin(); it != inputs.end(); 557 for (DetailInputs::const_iterator it = inputs.begin(); it != inputs.end();
534 ++it) { 558 ++it) {
535 if (it->type == type) 559 if (it->type == type)
536 return true; 560 return true;
537 } 561 }
538 return false; 562 return false;
539 } 563 }
540 564
565 SuggestionsMenuModel* GetMenuModelForSection(DialogSection section) {
566 ui::MenuModel* model = controller()->MenuModelForSection(section);
567 return static_cast<SuggestionsMenuModel*>(model);
568 }
569
541 TestAutofillDialogController* controller() { return controller_.get(); } 570 TestAutofillDialogController* controller() { return controller_.get(); }
542 571
543 const FormStructure* form_structure() { return form_structure_; } 572 const FormStructure* form_structure() { return form_structure_; }
544 573
545 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() { 574 TestGeneratedCreditCardBubbleController* test_generated_bubble_controller() {
546 return test_generated_bubble_controller_; 575 return test_generated_bubble_controller_;
547 } 576 }
548 577
549 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { 578 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() {
550 return mock_new_card_bubble_controller_.get(); 579 return mock_new_card_bubble_controller_.get();
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 928 verified_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
900 controller()->GetTestingManager()->AddTestingProfile(&verified_profile); 929 controller()->GetTestingManager()->AddTestingProfile(&verified_profile);
901 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING); 930 shipping_model = controller()->MenuModelForSection(SECTION_SHIPPING);
902 ASSERT_TRUE(shipping_model); 931 ASSERT_TRUE(shipping_model);
903 EXPECT_EQ(4, shipping_model->GetItemCount()); 932 EXPECT_EQ(4, shipping_model->GetItemCount());
904 } 933 }
905 934
906 // Makes sure that the choice of which Autofill profile to use for each section 935 // Makes sure that the choice of which Autofill profile to use for each section
907 // is sticky. 936 // is sticky.
908 TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) { 937 TEST_F(AutofillDialogControllerTest, AutofillProfileDefaults) {
909 AutofillProfile full_profile(test::GetFullProfile()); 938 AutofillProfile profile(test::GetVerifiedProfile());
910 full_profile.set_origin(kSettingsOrigin); 939 AutofillProfile profile2(test::GetVerifiedProfile2());
911 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 940 controller()->GetTestingManager()->AddTestingProfile(&profile);
912 AutofillProfile full_profile2(test::GetFullProfile2()); 941 controller()->GetTestingManager()->AddTestingProfile(&profile2);
913 full_profile2.set_origin(kSettingsOrigin);
914 controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
915 942
916 // Until a selection has been made, the default shipping suggestion is the 943 // Until a selection has been made, the default shipping suggestion is the
917 // first one (after "use billing"). 944 // first one (after "use billing").
918 SuggestionsMenuModel* shipping_model = static_cast<SuggestionsMenuModel*>( 945 SuggestionsMenuModel* shipping_model =
919 controller()->MenuModelForSection(SECTION_SHIPPING)); 946 GetMenuModelForSection(SECTION_SHIPPING);
920 EXPECT_EQ(1, shipping_model->checked_item()); 947 EXPECT_EQ(1, shipping_model->checked_item());
921 948
922 for (int i = 2; i >= 0; --i) { 949 for (int i = 2; i >= 0; --i) {
923 shipping_model = static_cast<SuggestionsMenuModel*>( 950 shipping_model = GetMenuModelForSection(SECTION_SHIPPING);
924 controller()->MenuModelForSection(SECTION_SHIPPING));
925 shipping_model->ExecuteCommand(i, 0); 951 shipping_model->ExecuteCommand(i, 0);
926 FillCreditCardInputs(); 952 FillCreditCardInputs();
927 controller()->OnAccept(); 953 controller()->OnAccept();
928 954
929 Reset(); 955 Reset();
930 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 956 controller()->GetTestingManager()->AddTestingProfile(&profile);
931 controller()->GetTestingManager()->AddTestingProfile(&full_profile2); 957 controller()->GetTestingManager()->AddTestingProfile(&profile2);
932 shipping_model = static_cast<SuggestionsMenuModel*>( 958 shipping_model = GetMenuModelForSection(SECTION_SHIPPING);
933 controller()->MenuModelForSection(SECTION_SHIPPING));
934 EXPECT_EQ(i, shipping_model->checked_item()); 959 EXPECT_EQ(i, shipping_model->checked_item());
935 } 960 }
936 961
937 // Try again, but don't add the default profile to the PDM. The dialog 962 // Try again, but don't add the default profile to the PDM. The dialog
938 // should fall back to the first profile. 963 // should fall back to the first profile.
939 shipping_model->ExecuteCommand(2, 0); 964 shipping_model->ExecuteCommand(2, 0);
940 FillCreditCardInputs(); 965 FillCreditCardInputs();
941 controller()->OnAccept(); 966 controller()->OnAccept();
942 Reset(); 967 Reset();
943 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 968 controller()->GetTestingManager()->AddTestingProfile(&profile);
944 shipping_model = static_cast<SuggestionsMenuModel*>( 969 shipping_model = GetMenuModelForSection(SECTION_SHIPPING);
945 controller()->MenuModelForSection(SECTION_SHIPPING));
946 EXPECT_EQ(1, shipping_model->checked_item()); 970 EXPECT_EQ(1, shipping_model->checked_item());
947 } 971 }
948 972
973 // Makes sure that a newly added Autofill profile becomes set as the default
974 // choice for the next run.
975 TEST_F(AutofillDialogControllerTest, NewAutofillProfileIsDefault) {
976 SwitchToAutofill();
977
978 AutofillProfile profile(test::GetVerifiedProfile());
979 CreditCard credit_card(test::GetVerifiedCreditCard());
980 controller()->GetTestingManager()->AddTestingProfile(&profile);
981 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
982
983 // Until a selection has been made, the default suggestion is the first one.
984 // For the shipping section, this follows the "use billing" suggestion.
985 EXPECT_EQ(0, GetMenuModelForSection(SECTION_CC)->checked_item());
986 EXPECT_EQ(1, GetMenuModelForSection(SECTION_SHIPPING)->checked_item());
987
988 // Fill in the shipping and credit card sections with new data.
989 AutofillProfile new_profile(test::GetVerifiedProfile2());
990 CreditCard new_credit_card(test::GetVerifiedCreditCard2());
991 FillInputs(SECTION_SHIPPING, new_profile);
992 FillInputs(SECTION_CC, new_credit_card);
993 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true);
994 controller()->OnAccept();
995
996 // Update the |new_profile| and |new_credit_card|'s guids to the saved ones.
997 new_profile.set_guid(
998 controller()->GetTestingManager()->imported_profile().guid());
999 new_credit_card.set_guid(
1000 controller()->GetTestingManager()->imported_credit_card().guid());
1001
1002 // Reload the dialog. The newly added address and credit card should now be
1003 // set as the defaults.
1004 Reset();
1005 controller()->GetTestingManager()->AddTestingProfile(&profile);
1006 controller()->GetTestingManager()->AddTestingProfile(&new_profile);
1007 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
1008 controller()->GetTestingManager()->AddTestingCreditCard(&new_credit_card);
1009
1010 // Until a selection has been made, the default suggestion is the first one.
1011 // For the shipping section, this follows the "use billing" suggestion.
1012 EXPECT_EQ(1, GetMenuModelForSection(SECTION_CC)->checked_item());
1013 EXPECT_EQ(2, GetMenuModelForSection(SECTION_SHIPPING)->checked_item());
1014 }
1015
949 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) { 1016 TEST_F(AutofillDialogControllerTest, AutofillProfileVariants) {
950 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1); 1017 EXPECT_CALL(*controller()->GetView(), ModelChanged()).Times(1);
951 ui::MenuModel* shipping_model = 1018 ui::MenuModel* shipping_model =
952 controller()->MenuModelForSection(SECTION_SHIPPING); 1019 controller()->MenuModelForSection(SECTION_SHIPPING);
953 ASSERT_TRUE(!!shipping_model); 1020 ASSERT_TRUE(!!shipping_model);
954 EXPECT_EQ(3, shipping_model->GetItemCount()); 1021 EXPECT_EQ(3, shipping_model->GetItemCount());
955 1022
956 // Set up some variant data. 1023 // Set up some variant data.
957 AutofillProfile full_profile(test::GetVerifiedProfile()); 1024 AutofillProfile full_profile(test::GetVerifiedProfile());
958 std::vector<string16> names; 1025 std::vector<string16> names;
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 1485
1419 // Checks that clicking the Manage menu item opens a new tab with a different 1486 // Checks that clicking the Manage menu item opens a new tab with a different
1420 // URL for Wallet and Autofill. 1487 // URL for Wallet and Autofill.
1421 TEST_F(AutofillDialogControllerTest, ManageItem) { 1488 TEST_F(AutofillDialogControllerTest, ManageItem) {
1422 AutofillProfile full_profile(test::GetVerifiedProfile()); 1489 AutofillProfile full_profile(test::GetVerifiedProfile());
1423 full_profile.set_origin(kSettingsOrigin); 1490 full_profile.set_origin(kSettingsOrigin);
1424 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16()); 1491 full_profile.SetRawInfo(ADDRESS_HOME_LINE2, string16());
1425 controller()->GetTestingManager()->AddTestingProfile(&full_profile); 1492 controller()->GetTestingManager()->AddTestingProfile(&full_profile);
1426 SwitchToAutofill(); 1493 SwitchToAutofill();
1427 1494
1428 SuggestionsMenuModel* shipping = static_cast<SuggestionsMenuModel*>( 1495 SuggestionsMenuModel* shipping = GetMenuModelForSection(SECTION_SHIPPING);
1429 controller()->MenuModelForSection(SECTION_SHIPPING));
1430 shipping->ExecuteCommand(shipping->GetItemCount() - 1, 0); 1496 shipping->ExecuteCommand(shipping->GetItemCount() - 1, 0);
1431 GURL autofill_manage_url = controller()->open_tab_url(); 1497 GURL autofill_manage_url = controller()->open_tab_url();
1432 EXPECT_EQ("chrome", autofill_manage_url.scheme()); 1498 EXPECT_EQ("chrome", autofill_manage_url.scheme());
1433 1499
1434 SwitchToWallet(); 1500 SwitchToWallet();
1435 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 1501 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
1436 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 1502 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
1437 controller()->OnDidGetWalletItems(wallet_items.Pass()); 1503 controller()->OnDidGetWalletItems(wallet_items.Pass());
1438 1504
1439 controller()->SuggestionItemSelected(shipping, shipping->GetItemCount() - 1); 1505 controller()->SuggestionItemSelected(shipping, shipping->GetItemCount() - 1);
1440 GURL wallet_manage_addresses_url = controller()->open_tab_url(); 1506 GURL wallet_manage_addresses_url = controller()->open_tab_url();
1441 EXPECT_EQ("https", wallet_manage_addresses_url.scheme()); 1507 EXPECT_EQ("https", wallet_manage_addresses_url.scheme());
1442 1508
1443 SuggestionsMenuModel* billing = static_cast<SuggestionsMenuModel*>( 1509 SuggestionsMenuModel* billing = GetMenuModelForSection(SECTION_CC_BILLING);
1444 controller()->MenuModelForSection(SECTION_CC_BILLING));
1445 controller()->SuggestionItemSelected(billing, billing->GetItemCount() - 1); 1510 controller()->SuggestionItemSelected(billing, billing->GetItemCount() - 1);
1446 GURL wallet_manage_instruments_url = controller()->open_tab_url(); 1511 GURL wallet_manage_instruments_url = controller()->open_tab_url();
1447 EXPECT_EQ("https", wallet_manage_instruments_url.scheme()); 1512 EXPECT_EQ("https", wallet_manage_instruments_url.scheme());
1448 1513
1449 EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url); 1514 EXPECT_NE(autofill_manage_url, wallet_manage_instruments_url);
1450 EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url); 1515 EXPECT_NE(wallet_manage_instruments_url, wallet_manage_addresses_url);
1451 } 1516 }
1452 1517
1453 // Tests that adding an autofill profile and then submitting works. 1518 // Tests that adding an autofill profile and then submitting works.
1454 TEST_F(AutofillDialogControllerTest, AddAutofillProfile) { 1519 TEST_F(AutofillDialogControllerTest, AddAutofillProfile) {
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
2358 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 2423 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2359 2424
2360 // End the submit button delay. 2425 // End the submit button delay.
2361 controller()->SimulateSubmitButtonDelayEnd(); 2426 controller()->SimulateSubmitButtonDelayEnd();
2362 2427
2363 EXPECT_FALSE(controller()->ShouldShowSpinner()); 2428 EXPECT_FALSE(controller()->ShouldShowSpinner());
2364 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); 2429 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2365 } 2430 }
2366 2431
2367 } // namespace autofill 2432 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc ('k') | components/autofill/core/browser/autofill_common_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698