| 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 callback, | 456 callback, |
| 457 mock_new_card_bubble_controller_.get()))->AsWeakPtr(); | 457 mock_new_card_bubble_controller_.get()))->AsWeakPtr(); |
| 458 controller_->Init(profile()); | 458 controller_->Init(profile()); |
| 459 } | 459 } |
| 460 | 460 |
| 461 // Creates a new controller for |form_data| and sets up some initial wallet | 461 // Creates a new controller for |form_data| and sets up some initial wallet |
| 462 // data for it. | 462 // data for it. |
| 463 void SetUpControllerWithFormData(const FormData& form_data) { | 463 void SetUpControllerWithFormData(const FormData& form_data) { |
| 464 ResetControllerWithFormData(form_data); | 464 ResetControllerWithFormData(form_data); |
| 465 controller()->Show(); | 465 controller()->Show(); |
| 466 if (!profile()->GetPrefs()->GetBoolean( | 466 if (controller() && |
| 467 !profile()->GetPrefs()->GetBoolean( |
| 467 ::prefs::kAutofillDialogPayWithoutWallet)) { | 468 ::prefs::kAutofillDialogPayWithoutWallet)) { |
| 468 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); | 469 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems()); |
| 469 controller()->OnDidFetchWalletCookieValue(std::string()); | 470 controller()->OnDidFetchWalletCookieValue(std::string()); |
| 470 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 471 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
| 471 } | 472 } |
| 472 } | 473 } |
| 473 | 474 |
| 474 // Fills the inputs in SECTION_CC with data. | 475 // Fills the inputs in SECTION_CC with data. |
| 475 void FillCreditCardInputs() { | 476 void FillCreditCardInputs() { |
| 476 FieldValueMap cc_outputs; | 477 FieldValueMap cc_outputs; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 | 671 |
| 671 // Used to record when new card bubbles would show. Created in |Reset()|. | 672 // Used to record when new card bubbles would show. Created in |Reset()|. |
| 672 scoped_ptr<MockNewCreditCardBubbleController> | 673 scoped_ptr<MockNewCreditCardBubbleController> |
| 673 mock_new_card_bubble_controller_; | 674 mock_new_card_bubble_controller_; |
| 674 | 675 |
| 675 scoped_ptr<ScopedTestingLocalState> scoped_local_state_; | 676 scoped_ptr<ScopedTestingLocalState> scoped_local_state_; |
| 676 }; | 677 }; |
| 677 | 678 |
| 678 } // namespace | 679 } // namespace |
| 679 | 680 |
| 681 TEST_F(AutofillDialogControllerTest, RefuseToShowWithNoAutocompleteAttributes) { |
| 682 FormFieldData email_field; |
| 683 email_field.name = ASCIIToUTF16("email"); |
| 684 FormFieldData cc_field; |
| 685 cc_field.name = ASCIIToUTF16("cc"); |
| 686 FormFieldData billing_field; |
| 687 billing_field.name = ASCIIToUTF16("billing name"); |
| 688 |
| 689 FormData form_data; |
| 690 form_data.fields.push_back(email_field); |
| 691 form_data.fields.push_back(cc_field); |
| 692 form_data.fields.push_back(billing_field); |
| 693 |
| 694 SetUpControllerWithFormData(form_data); |
| 695 EXPECT_FALSE(controller()); |
| 696 } |
| 697 |
| 698 TEST_F(AutofillDialogControllerTest, RefuseToShowWithNoCcField) { |
| 699 FormFieldData shipping_tel; |
| 700 shipping_tel.autocomplete_attribute = "shipping tel"; |
| 701 |
| 702 FormData form_data; |
| 703 form_data.fields.push_back(shipping_tel); |
| 704 |
| 705 SetUpControllerWithFormData(form_data); |
| 706 EXPECT_FALSE(controller()); |
| 707 |
| 708 // Any cc- field will do. |
| 709 FormFieldData cc_field; |
| 710 cc_field.autocomplete_attribute = "cc-csc"; |
| 711 form_data.fields.push_back(cc_field); |
| 712 |
| 713 SetUpControllerWithFormData(form_data); |
| 714 EXPECT_TRUE(controller()); |
| 715 } |
| 716 |
| 680 // Ensure the default ValidityMessage has the expected values. | 717 // Ensure the default ValidityMessage has the expected values. |
| 681 TEST_F(AutofillDialogControllerTest, DefaultValidityMessage) { | 718 TEST_F(AutofillDialogControllerTest, DefaultValidityMessage) { |
| 682 ValidityMessages messages; | 719 ValidityMessages messages; |
| 683 ValidityMessage message = messages.GetMessageOrDefault(UNKNOWN_TYPE); | 720 ValidityMessage message = messages.GetMessageOrDefault(UNKNOWN_TYPE); |
| 684 EXPECT_FALSE(message.sure); | 721 EXPECT_FALSE(message.sure); |
| 685 EXPECT_TRUE(message.text.empty()); | 722 EXPECT_TRUE(message.text.empty()); |
| 686 } | 723 } |
| 687 | 724 |
| 688 // This test makes sure nothing falls over when fields are being validity- | 725 // This test makes sure nothing falls over when fields are being validity- |
| 689 // checked. | 726 // checked. |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 SubmitAndVerifyShippingAndBillingResults(); | 1341 SubmitAndVerifyShippingAndBillingResults(); |
| 1305 } | 1342 } |
| 1306 | 1343 |
| 1307 // Tests that shipping and billing telephone fields are supported, and filled | 1344 // Tests that shipping and billing telephone fields are supported, and filled |
| 1308 // in by their respective profiles. http://crbug.com/244515 | 1345 // in by their respective profiles. http://crbug.com/244515 |
| 1309 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { | 1346 TEST_F(AutofillDialogControllerTest, BillingVsShippingPhoneNumber) { |
| 1310 FormFieldData shipping_tel; | 1347 FormFieldData shipping_tel; |
| 1311 shipping_tel.autocomplete_attribute = "shipping tel"; | 1348 shipping_tel.autocomplete_attribute = "shipping tel"; |
| 1312 FormFieldData billing_tel; | 1349 FormFieldData billing_tel; |
| 1313 billing_tel.autocomplete_attribute = "billing tel"; | 1350 billing_tel.autocomplete_attribute = "billing tel"; |
| 1351 FormFieldData cc_field; |
| 1352 cc_field.autocomplete_attribute = "cc-csc"; |
| 1314 | 1353 |
| 1315 FormData form_data; | 1354 FormData form_data; |
| 1316 form_data.fields.push_back(shipping_tel); | 1355 form_data.fields.push_back(shipping_tel); |
| 1317 form_data.fields.push_back(billing_tel); | 1356 form_data.fields.push_back(billing_tel); |
| 1357 form_data.fields.push_back(cc_field); |
| 1318 SetUpControllerWithFormData(form_data); | 1358 SetUpControllerWithFormData(form_data); |
| 1319 | 1359 |
| 1320 SwitchToAutofill(); | 1360 SwitchToAutofill(); |
| 1321 | 1361 |
| 1322 // The profile that will be chosen for the shipping section. | 1362 // The profile that will be chosen for the shipping section. |
| 1323 AutofillProfile shipping_profile(test::GetVerifiedProfile()); | 1363 AutofillProfile shipping_profile(test::GetVerifiedProfile()); |
| 1324 // The profile that will be chosen for the billing section. | 1364 // The profile that will be chosen for the billing section. |
| 1325 AutofillProfile billing_profile(test::GetVerifiedProfile2()); | 1365 AutofillProfile billing_profile(test::GetVerifiedProfile2()); |
| 1326 CreditCard credit_card(test::GetVerifiedCreditCard()); | 1366 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1327 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); | 1367 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); |
| 1328 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); | 1368 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); |
| 1329 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1369 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
| 1330 ui::MenuModel* billing_model = | 1370 ui::MenuModel* billing_model = |
| 1331 controller()->MenuModelForSection(SECTION_BILLING); | 1371 controller()->MenuModelForSection(SECTION_BILLING); |
| 1332 billing_model->ActivatedAt(1); | 1372 billing_model->ActivatedAt(1); |
| 1333 | 1373 |
| 1334 controller()->OnAccept(); | 1374 controller()->OnAccept(); |
| 1335 ASSERT_EQ(2U, form_structure()->field_count()); | 1375 ASSERT_EQ(3U, form_structure()->field_count()); |
| 1336 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 1376 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
| 1337 form_structure()->field(0)->Type().GetStorableType()); | 1377 form_structure()->field(0)->Type().GetStorableType()); |
| 1338 EXPECT_EQ(PHONE_HOME, form_structure()->field(0)->Type().group()); | 1378 EXPECT_EQ(PHONE_HOME, form_structure()->field(0)->Type().group()); |
| 1339 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, | 1379 EXPECT_EQ(PHONE_HOME_WHOLE_NUMBER, |
| 1340 form_structure()->field(1)->Type().GetStorableType()); | 1380 form_structure()->field(1)->Type().GetStorableType()); |
| 1341 EXPECT_EQ(PHONE_BILLING, form_structure()->field(1)->Type().group()); | 1381 EXPECT_EQ(PHONE_BILLING, form_structure()->field(1)->Type().group()); |
| 1342 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), | 1382 EXPECT_EQ(shipping_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), |
| 1343 form_structure()->field(0)->value); | 1383 form_structure()->field(0)->value); |
| 1344 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), | 1384 EXPECT_EQ(billing_profile.GetRawInfo(PHONE_HOME_WHOLE_NUMBER), |
| 1345 form_structure()->field(1)->value); | 1385 form_structure()->field(1)->value); |
| 1346 EXPECT_NE(form_structure()->field(1)->value, | 1386 EXPECT_NE(form_structure()->field(1)->value, |
| 1347 form_structure()->field(0)->value); | 1387 form_structure()->field(0)->value); |
| 1348 } | 1388 } |
| 1349 | 1389 |
| 1350 // Similar to the above, but tests that street-address (i.e. all lines of the | 1390 // Similar to the above, but tests that street-address (i.e. all lines of the |
| 1351 // street address) is successfully filled for both shipping and billing | 1391 // street address) is successfully filled for both shipping and billing |
| 1352 // sections. | 1392 // sections. |
| 1353 TEST_F(AutofillDialogControllerTest, BillingVsShippingStreetAddress) { | 1393 TEST_F(AutofillDialogControllerTest, BillingVsShippingStreetAddress) { |
| 1354 FormFieldData shipping_address; | 1394 FormFieldData shipping_address; |
| 1355 shipping_address.autocomplete_attribute = "shipping street-address"; | 1395 shipping_address.autocomplete_attribute = "shipping street-address"; |
| 1356 FormFieldData billing_address; | 1396 FormFieldData billing_address; |
| 1357 billing_address.autocomplete_attribute = "billing street-address"; | 1397 billing_address.autocomplete_attribute = "billing street-address"; |
| 1358 FormFieldData shipping_address_textarea; | 1398 FormFieldData shipping_address_textarea; |
| 1359 shipping_address_textarea.autocomplete_attribute = "shipping street-address"; | 1399 shipping_address_textarea.autocomplete_attribute = "shipping street-address"; |
| 1360 shipping_address_textarea.form_control_type = "textarea"; | 1400 shipping_address_textarea.form_control_type = "textarea"; |
| 1361 FormFieldData billing_address_textarea; | 1401 FormFieldData billing_address_textarea; |
| 1362 billing_address_textarea.autocomplete_attribute = "billing street-address"; | 1402 billing_address_textarea.autocomplete_attribute = "billing street-address"; |
| 1363 billing_address_textarea.form_control_type = "textarea"; | 1403 billing_address_textarea.form_control_type = "textarea"; |
| 1404 FormFieldData cc_field; |
| 1405 cc_field.autocomplete_attribute = "cc-csc"; |
| 1364 | 1406 |
| 1365 FormData form_data; | 1407 FormData form_data; |
| 1366 form_data.fields.push_back(shipping_address); | 1408 form_data.fields.push_back(shipping_address); |
| 1367 form_data.fields.push_back(billing_address); | 1409 form_data.fields.push_back(billing_address); |
| 1368 form_data.fields.push_back(shipping_address_textarea); | 1410 form_data.fields.push_back(shipping_address_textarea); |
| 1369 form_data.fields.push_back(billing_address_textarea); | 1411 form_data.fields.push_back(billing_address_textarea); |
| 1412 form_data.fields.push_back(cc_field); |
| 1370 SetUpControllerWithFormData(form_data); | 1413 SetUpControllerWithFormData(form_data); |
| 1371 | 1414 |
| 1372 SwitchToAutofill(); | 1415 SwitchToAutofill(); |
| 1373 | 1416 |
| 1374 // The profile that will be chosen for the shipping section. | 1417 // The profile that will be chosen for the shipping section. |
| 1375 AutofillProfile shipping_profile(test::GetVerifiedProfile()); | 1418 AutofillProfile shipping_profile(test::GetVerifiedProfile()); |
| 1376 // The profile that will be chosen for the billing section. | 1419 // The profile that will be chosen for the billing section. |
| 1377 AutofillProfile billing_profile(test::GetVerifiedProfile2()); | 1420 AutofillProfile billing_profile(test::GetVerifiedProfile2()); |
| 1378 CreditCard credit_card(test::GetVerifiedCreditCard()); | 1421 CreditCard credit_card(test::GetVerifiedCreditCard()); |
| 1379 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); | 1422 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); |
| 1380 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); | 1423 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); |
| 1381 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | 1424 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); |
| 1382 ui::MenuModel* billing_model = | 1425 ui::MenuModel* billing_model = |
| 1383 controller()->MenuModelForSection(SECTION_BILLING); | 1426 controller()->MenuModelForSection(SECTION_BILLING); |
| 1384 billing_model->ActivatedAt(1); | 1427 billing_model->ActivatedAt(1); |
| 1385 | 1428 |
| 1386 controller()->OnAccept(); | 1429 controller()->OnAccept(); |
| 1387 ASSERT_EQ(4U, form_structure()->field_count()); | 1430 ASSERT_EQ(5U, form_structure()->field_count()); |
| 1388 EXPECT_EQ(ADDRESS_HOME_STREET_ADDRESS, | 1431 EXPECT_EQ(ADDRESS_HOME_STREET_ADDRESS, |
| 1389 form_structure()->field(0)->Type().GetStorableType()); | 1432 form_structure()->field(0)->Type().GetStorableType()); |
| 1390 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(0)->Type().group()); | 1433 EXPECT_EQ(ADDRESS_HOME, form_structure()->field(0)->Type().group()); |
| 1391 EXPECT_EQ(ADDRESS_HOME_STREET_ADDRESS, | 1434 EXPECT_EQ(ADDRESS_HOME_STREET_ADDRESS, |
| 1392 form_structure()->field(1)->Type().GetStorableType()); | 1435 form_structure()->field(1)->Type().GetStorableType()); |
| 1393 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(1)->Type().group()); | 1436 EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(1)->Type().group()); |
| 1394 // Inexact matching; single-line inputs get the address data concatenated but | 1437 // Inexact matching; single-line inputs get the address data concatenated but |
| 1395 // separated by commas. | 1438 // separated by commas. |
| 1396 EXPECT_TRUE(StartsWith(form_structure()->field(0)->value, | 1439 EXPECT_TRUE(StartsWith(form_structure()->field(0)->value, |
| 1397 shipping_profile.GetRawInfo(ADDRESS_HOME_LINE1), | 1440 shipping_profile.GetRawInfo(ADDRESS_HOME_LINE1), |
| (...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3275 // text content. Thus the first two options should be recognized. | 3318 // text content. Thus the first two options should be recognized. |
| 3276 FormData form_data; | 3319 FormData form_data; |
| 3277 FormFieldData field; | 3320 FormFieldData field; |
| 3278 field.autocomplete_attribute = "billing country"; | 3321 field.autocomplete_attribute = "billing country"; |
| 3279 field.option_contents.push_back(ASCIIToUTF16("Down Under")); | 3322 field.option_contents.push_back(ASCIIToUTF16("Down Under")); |
| 3280 field.option_values.push_back(ASCIIToUTF16("AU")); | 3323 field.option_values.push_back(ASCIIToUTF16("AU")); |
| 3281 field.option_contents.push_back(ASCIIToUTF16("Fr")); | 3324 field.option_contents.push_back(ASCIIToUTF16("Fr")); |
| 3282 field.option_values.push_back(ASCIIToUTF16("")); | 3325 field.option_values.push_back(ASCIIToUTF16("")); |
| 3283 field.option_contents.push_back(ASCIIToUTF16("Germany")); | 3326 field.option_contents.push_back(ASCIIToUTF16("Germany")); |
| 3284 field.option_values.push_back(ASCIIToUTF16("GRMNY")); | 3327 field.option_values.push_back(ASCIIToUTF16("GRMNY")); |
| 3328 |
| 3329 FormFieldData cc_field; |
| 3330 cc_field.autocomplete_attribute = "cc-csc"; |
| 3331 |
| 3285 form_data.fields.push_back(field); | 3332 form_data.fields.push_back(field); |
| 3333 form_data.fields.push_back(cc_field); |
| 3286 ResetControllerWithFormData(form_data); | 3334 ResetControllerWithFormData(form_data); |
| 3287 controller()->Show(); | 3335 controller()->Show(); |
| 3288 | 3336 |
| 3289 // Shipping model shouldn't have changed. | 3337 // Shipping model shouldn't have changed. |
| 3290 shipping_country_model = | 3338 shipping_country_model = |
| 3291 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY); | 3339 controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY); |
| 3292 EXPECT_EQ(default_number_of_countries, | 3340 EXPECT_EQ(default_number_of_countries, |
| 3293 shipping_country_model->GetItemCount()); | 3341 shipping_country_model->GetItemCount()); |
| 3294 // Billing model now only has two items. | 3342 // Billing model now only has two items. |
| 3295 ui::ComboboxModel* billing_country_model = | 3343 ui::ComboboxModel* billing_country_model = |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3411 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(2); | 3459 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(2); |
| 3412 | 3460 |
| 3413 FieldValueMap outputs; | 3461 FieldValueMap outputs; |
| 3414 outputs[NAME_FULL] = ASCIIToUTF16("madonna"); | 3462 outputs[NAME_FULL] = ASCIIToUTF16("madonna"); |
| 3415 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); | 3463 controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs); |
| 3416 | 3464 |
| 3417 ASSERT_NO_FATAL_FAILURE(SwitchToAutofill()); | 3465 ASSERT_NO_FATAL_FAILURE(SwitchToAutofill()); |
| 3418 } | 3466 } |
| 3419 | 3467 |
| 3420 } // namespace autofill | 3468 } // namespace autofill |
| OLD | NEW |