| OLD | NEW |
| 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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 1478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 FormFieldData field; | 1489 FormFieldData field; |
| 1490 field.autocomplete_attribute.assign(attributes[i]); | 1490 field.autocomplete_attribute.assign(attributes[i]); |
| 1491 form_data.fields.push_back(field); | 1491 form_data.fields.push_back(field); |
| 1492 } | 1492 } |
| 1493 | 1493 |
| 1494 SetUpControllerWithFormData(form_data); | 1494 SetUpControllerWithFormData(form_data); |
| 1495 SwitchToAutofill(); | 1495 SwitchToAutofill(); |
| 1496 | 1496 |
| 1497 // Billing. | 1497 // Billing. |
| 1498 AutofillProfile test_profile(test::GetVerifiedProfile()); | 1498 AutofillProfile test_profile(test::GetVerifiedProfile()); |
| 1499 test_profile.SetRawInfo(NAME_FULL, ASCIIToUTF16("Fabian Jackson von Nacho")); | 1499 test_profile.SetInfo(AutofillType(NAME_FULL), |
| 1500 ASCIIToUTF16("Fabian Jackson von Nacho"), |
| 1501 "en-US"); |
| 1500 controller()->GetTestingManager()->AddTestingProfile(&test_profile); | 1502 controller()->GetTestingManager()->AddTestingProfile(&test_profile); |
| 1501 | 1503 |
| 1502 // Credit card. | 1504 // Credit card. |
| 1503 CreditCard credit_card(test::GetVerifiedCreditCard()); | 1505 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1504 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1506 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
| 1505 | 1507 |
| 1506 // Make shipping name different from billing. | 1508 // Make shipping name different from billing. |
| 1507 AutofillProfile test_profile2(test::GetVerifiedProfile2()); | 1509 AutofillProfile test_profile2(test::GetVerifiedProfile2()); |
| 1508 test_profile2.SetRawInfo(NAME_FULL, ASCIIToUTF16("Don Ford")); | 1510 test_profile2.SetInfo(AutofillType(NAME_FULL), |
| 1511 ASCIIToUTF16("Don Ford"), |
| 1512 "en-US"); |
| 1509 controller()->GetTestingManager()->AddTestingProfile(&test_profile2); | 1513 controller()->GetTestingManager()->AddTestingProfile(&test_profile2); |
| 1510 ui::MenuModel* shipping_model = | 1514 ui::MenuModel* shipping_model = |
| 1511 controller()->MenuModelForSection(SECTION_SHIPPING); | 1515 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 1512 shipping_model->ActivatedAt(2); | 1516 shipping_model->ActivatedAt(2); |
| 1513 | 1517 |
| 1514 controller()->OnAccept(); | 1518 controller()->OnAccept(); |
| 1515 | 1519 |
| 1516 EXPECT_EQ(NAME_FULL, form_structure()->field(0)->Type().GetStorableType()); | 1520 EXPECT_EQ(NAME_FULL, form_structure()->field(0)->Type().GetStorableType()); |
| 1517 EXPECT_EQ(ASCIIToUTF16("Don Ford"), | 1521 EXPECT_EQ(ASCIIToUTF16("Don Ford"), |
| 1518 form_structure()->field(0)->value); | 1522 form_structure()->field(0)->value); |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2393 // And that the shipping suggestions menu has less selections. | 2397 // And that the shipping suggestions menu has less selections. |
| 2394 EXPECT_EQ( | 2398 EXPECT_EQ( |
| 2395 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 2399 2, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
| 2396 | 2400 |
| 2397 // Additionally, editing fields should not show Autofill popups. | 2401 // Additionally, editing fields should not show Autofill popups. |
| 2398 ASSERT_NO_FATAL_FAILURE(controller()->UserEditedOrActivatedInput( | 2402 ASSERT_NO_FATAL_FAILURE(controller()->UserEditedOrActivatedInput( |
| 2399 SECTION_BILLING, | 2403 SECTION_BILLING, |
| 2400 NAME_BILLING_FULL, | 2404 NAME_BILLING_FULL, |
| 2401 gfx::NativeView(), | 2405 gfx::NativeView(), |
| 2402 gfx::Rect(), | 2406 gfx::Rect(), |
| 2403 verified_profile.GetRawInfo(NAME_FULL).substr(0, 1), | 2407 verified_profile.GetInfo(AutofillType(NAME_FULL), "en-US").substr(0, 1), |
| 2404 true)); | 2408 true)); |
| 2405 EXPECT_EQ(UNKNOWN_TYPE, controller()->popup_input_type()); | 2409 EXPECT_EQ(UNKNOWN_TYPE, controller()->popup_input_type()); |
| 2406 } | 2410 } |
| 2407 | 2411 |
| 2408 // Tests that user is prompted when using instrument with minimal address. | 2412 // Tests that user is prompted when using instrument with minimal address. |
| 2409 TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) { | 2413 TEST_F(AutofillDialogControllerTest, UpgradeMinimalAddress) { |
| 2410 // A minimal address being selected should trigger error validation in the | 2414 // A minimal address being selected should trigger error validation in the |
| 2411 // view. Called once for each incomplete suggestion. | 2415 // view. Called once for each incomplete suggestion. |
| 2412 EXPECT_CALL(*controller()->GetView(), UpdateForErrors()); | 2416 EXPECT_CALL(*controller()->GetView(), UpdateForErrors()); |
| 2413 | 2417 |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2923 AutofillProfile test_profile(test::GetVerifiedProfile()); | 2927 AutofillProfile test_profile(test::GetVerifiedProfile()); |
| 2924 FillInputs(SECTION_BILLING, test_profile); | 2928 FillInputs(SECTION_BILLING, test_profile); |
| 2925 | 2929 |
| 2926 UseBillingForShipping(); | 2930 UseBillingForShipping(); |
| 2927 | 2931 |
| 2928 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true); | 2932 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true); |
| 2929 controller()->OnAccept(); | 2933 controller()->OnAccept(); |
| 2930 | 2934 |
| 2931 TestPersonalDataManager* test_pdm = controller()->GetTestingManager(); | 2935 TestPersonalDataManager* test_pdm = controller()->GetTestingManager(); |
| 2932 const CreditCard& imported_card = test_pdm->imported_credit_card(); | 2936 const CreditCard& imported_card = test_pdm->imported_credit_card(); |
| 2933 EXPECT_EQ(test_profile.GetRawInfo(NAME_FULL), | 2937 EXPECT_EQ(test_profile.GetInfo(AutofillType(NAME_FULL), "en-US"), |
| 2934 imported_card.GetRawInfo(CREDIT_CARD_NAME)); | 2938 imported_card.GetRawInfo(CREDIT_CARD_NAME)); |
| 2935 } | 2939 } |
| 2936 | 2940 |
| 2937 TEST_F(AutofillDialogControllerTest, SaveCreditCardIncludesName_WithBilling) { | 2941 TEST_F(AutofillDialogControllerTest, SaveCreditCardIncludesName_WithBilling) { |
| 2938 SwitchToAutofill(); | 2942 SwitchToAutofill(); |
| 2939 | 2943 |
| 2940 TestPersonalDataManager* test_pdm = controller()->GetTestingManager(); | 2944 TestPersonalDataManager* test_pdm = controller()->GetTestingManager(); |
| 2941 AutofillProfile test_profile(test::GetVerifiedProfile()); | 2945 AutofillProfile test_profile(test::GetVerifiedProfile()); |
| 2942 | 2946 |
| 2943 EXPECT_CALL(*controller()->GetView(), ModelChanged()); | 2947 EXPECT_CALL(*controller()->GetView(), ModelChanged()); |
| 2944 test_pdm->AddTestingProfile(&test_profile); | 2948 test_pdm->AddTestingProfile(&test_profile); |
| 2945 ASSERT_TRUE(controller()->MenuModelForSection(SECTION_BILLING)); | 2949 ASSERT_TRUE(controller()->MenuModelForSection(SECTION_BILLING)); |
| 2946 | 2950 |
| 2947 CreditCard test_credit_card(test::GetVerifiedCreditCard()); | 2951 CreditCard test_credit_card(test::GetVerifiedCreditCard()); |
| 2948 FillInputs(SECTION_CC, test_credit_card); | 2952 FillInputs(SECTION_CC, test_credit_card); |
| 2949 | 2953 |
| 2950 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true); | 2954 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true); |
| 2951 controller()->OnAccept(); | 2955 controller()->OnAccept(); |
| 2952 | 2956 |
| 2953 const CreditCard& imported_card = test_pdm->imported_credit_card(); | 2957 const CreditCard& imported_card = test_pdm->imported_credit_card(); |
| 2954 EXPECT_EQ(test_profile.GetRawInfo(NAME_FULL), | 2958 EXPECT_EQ(test_profile.GetInfo(AutofillType(NAME_FULL), "en-US"), |
| 2955 imported_card.GetRawInfo(CREDIT_CARD_NAME)); | 2959 imported_card.GetRawInfo(CREDIT_CARD_NAME)); |
| 2956 | 2960 |
| 2957 controller()->ViewClosed(); | 2961 controller()->ViewClosed(); |
| 2958 } | 2962 } |
| 2959 | 2963 |
| 2960 TEST_F(AutofillDialogControllerTest, InputEditability) { | 2964 TEST_F(AutofillDialogControllerTest, InputEditability) { |
| 2961 // Empty wallet items: all fields are editable. | 2965 // Empty wallet items: all fields are editable. |
| 2962 scoped_ptr<wallet::WalletItems> items = | 2966 scoped_ptr<wallet::WalletItems> items = |
| 2963 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); | 2967 wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED); |
| 2964 controller()->OnDidGetWalletItems(items.Pass()); | 2968 controller()->OnDidGetWalletItems(items.Pass()); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3353 const ServerFieldType type = inputs[i].type; | 3357 const ServerFieldType type = inputs[i].type; |
| 3354 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); | 3358 outputs[type] = full_profile.GetInfo(AutofillType(type), "en-US"); |
| 3355 } | 3359 } |
| 3356 controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs); | 3360 controller()->GetView()->SetUserInput(SECTION_SHIPPING, outputs); |
| 3357 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true); | 3361 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(true); |
| 3358 controller()->OnAccept(); | 3362 controller()->OnAccept(); |
| 3359 | 3363 |
| 3360 // Profiles saved while rules are unavailable shouldn't be verified. | 3364 // Profiles saved while rules are unavailable shouldn't be verified. |
| 3361 const AutofillProfile& imported_profile = | 3365 const AutofillProfile& imported_profile = |
| 3362 controller()->GetTestingManager()->imported_profile(); | 3366 controller()->GetTestingManager()->imported_profile(); |
| 3363 ASSERT_EQ(imported_profile.GetRawInfo(NAME_FULL), | 3367 ASSERT_EQ(imported_profile.GetInfo(AutofillType(NAME_FULL), "en-US"), |
| 3364 full_profile.GetRawInfo(NAME_FULL)); | 3368 full_profile.GetInfo(AutofillType(NAME_FULL), "en-US")); |
| 3365 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec()); | 3369 EXPECT_EQ(imported_profile.origin(), GURL(kSourceUrl).GetOrigin().spec()); |
| 3366 EXPECT_FALSE(imported_profile.IsVerified()); | 3370 EXPECT_FALSE(imported_profile.IsVerified()); |
| 3367 } | 3371 } |
| 3368 | 3372 |
| 3369 TEST_F(AutofillDialogControllerTest, LimitedCountryChoices) { | 3373 TEST_F(AutofillDialogControllerTest, LimitedCountryChoices) { |
| 3370 ui::ComboboxModel* shipping_country_model = | 3374 ui::ComboboxModel* shipping_country_model = |
| 3371 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY); | 3375 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY); |
| 3372 const int default_number_of_countries = | 3376 const int default_number_of_countries = |
| 3373 shipping_country_model->GetItemCount(); | 3377 shipping_country_model->GetItemCount(); |
| 3374 // We show a lot of countries by default, but the exact number doesn't matter. | 3378 // We show a lot of countries by default, but the exact number doesn't matter. |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3662 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); | 3666 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(2)->value); |
| 3663 EXPECT_EQ(ADDRESS_HOME_COUNTRY, | 3667 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 3664 form_structure()->field(3)->Type().GetStorableType()); | 3668 form_structure()->field(3)->Type().GetStorableType()); |
| 3665 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); | 3669 EXPECT_EQ(ASCIIToUTF16("US"), form_structure()->field(3)->value); |
| 3666 EXPECT_EQ(ADDRESS_HOME_COUNTRY, | 3670 EXPECT_EQ(ADDRESS_HOME_COUNTRY, |
| 3667 form_structure()->field(4)->Type().GetStorableType()); | 3671 form_structure()->field(4)->Type().GetStorableType()); |
| 3668 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); | 3672 EXPECT_EQ(ASCIIToUTF16("United States"), form_structure()->field(4)->value); |
| 3669 } | 3673 } |
| 3670 | 3674 |
| 3671 } // namespace autofill | 3675 } // namespace autofill |
| OLD | NEW |