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