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

Unified Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 63053003: Ask libaddressinput for address components to use in requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: let's try this again, android Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
diff --git a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
index 98a6e04a68e40a9b364cc04836ff7e53b3231c48..5339a3f204f14099d9e02740b9797be9f785bfc2 100644
--- a/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/ui/autofill/generated_credit_card_bubble_controller.h"
#include "chrome/browser/ui/autofill/mock_new_credit_card_bubble_controller.h"
#include "chrome/browser/ui/autofill/test_generated_credit_card_bubble_controller.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
@@ -90,17 +91,6 @@ const char kTestCCNumberIncomplete[] = "4111111111";
// Credit card number fails Luhn check.
const char kTestCCNumberInvalid[] = "4111111111111112";
-// Sets the value of |type| in |outputs| to |value|.
-void SetOutputValue(const DetailInputs& inputs,
- ServerFieldType type,
- const base::string16& value,
- FieldValueMap* outputs) {
- for (size_t i = 0; i < inputs.size(); ++i) {
- if (inputs[i].type == type)
- (*outputs)[type] = value;
- }
-}
-
// Copies the initial values from |inputs| into |outputs|.
void CopyInitialValues(const DetailInputs& inputs, FieldValueMap* outputs) {
for (size_t i = 0; i < inputs.size(); ++i) {
@@ -173,6 +163,7 @@ class TestAutofillDialogView : public AutofillDialogView {
}
virtual void UpdateSection(DialogSection section) OVERRIDE {
+ section_updates_[section]++;
EXPECT_GE(updates_started_, 1);
}
@@ -218,8 +209,17 @@ class TestAutofillDialogView : public AutofillDialogView {
save_details_locally_checked_ = checked;
}
+ void ClearSectionUpdates() {
+ section_updates_.clear();
+ }
+
+ std::map<DialogSection, size_t> section_updates() const {
+ return section_updates_;
+ }
+
private:
std::map<DialogSection, FieldValueMap> outputs_;
+ std::map<DialogSection, size_t> section_updates_;
int updates_started_;
bool save_details_locally_checked_;
@@ -304,6 +304,7 @@ class TestAutofillDialogController
MOCK_METHOD0(LoadRiskFingerprintData, void());
using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
using AutofillDialogControllerImpl::IsEditingExistingData;
+ using AutofillDialogControllerImpl::IsManuallyEditingSection;
using AutofillDialogControllerImpl::IsSubmitPausedOn;
using AutofillDialogControllerImpl::NOT_CHECKED;
using AutofillDialogControllerImpl::SignedInState;
@@ -525,11 +526,7 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
const std::string& cc_number,
bool should_pass) {
FieldValueMap outputs;
- const DetailInputs& inputs =
- controller()->RequestedFieldsForSection(section);
-
- SetOutputValue(inputs, CREDIT_CARD_NUMBER,
- ASCIIToUTF16(cc_number), &outputs);
+ outputs[CREDIT_CARD_NUMBER] = UTF8ToUTF16(cc_number);
ValidityMessages messages =
controller()->InputsAreValid(section, outputs);
EXPECT_EQ(should_pass, !messages.HasSureError(CREDIT_CARD_NUMBER));
@@ -574,6 +571,44 @@ class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
return static_cast<SuggestionsMenuModel*>(model);
}
+ void SubmitAndVerifyShippingAndBillingResults() {
+ // Test after setting use billing for shipping.
+ UseBillingForShipping();
+
+ controller()->OnAccept();
+
+ ASSERT_EQ(20U, form_structure()->field_count());
+ EXPECT_EQ(ADDRESS_HOME_COUNTRY,
+ form_structure()->field(11)->Type().GetStorableType());
+ EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(11)->Type().group());
+ EXPECT_EQ(ADDRESS_HOME_COUNTRY,
+ form_structure()->field(18)->Type().GetStorableType());
+ EXPECT_EQ(ADDRESS_HOME, form_structure()->field(18)->Type().group());
+ string16 billing_country = form_structure()->field(11)->value;
+ EXPECT_EQ(2U, billing_country.size());
+ string16 shipping_country = form_structure()->field(18)->value;
+ EXPECT_EQ(2U, shipping_country.size());
+ EXPECT_FALSE(billing_country.empty());
+ EXPECT_FALSE(shipping_country.empty());
+ EXPECT_EQ(billing_country, shipping_country);
+
+ EXPECT_EQ(CREDIT_CARD_NAME,
+ form_structure()->field(1)->Type().GetStorableType());
+ string16 cc_name = form_structure()->field(1)->value;
+ EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
+ EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
+ string16 billing_name = form_structure()->field(6)->value;
+ EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
+ EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
+ string16 shipping_name = form_structure()->field(13)->value;
+
+ EXPECT_FALSE(cc_name.empty());
+ EXPECT_FALSE(billing_name.empty());
+ EXPECT_FALSE(shipping_name.empty());
+ EXPECT_EQ(cc_name, billing_name);
+ EXPECT_EQ(cc_name, shipping_name);
+ }
+
TestAutofillDialogController* controller() { return controller_.get(); }
const FormStructure* form_structure() { return form_structure_; }
@@ -662,50 +697,45 @@ TEST_F(AutofillDialogControllerTest, PhoneNumberValidation) {
}
// Make sure country is United States.
- SetOutputValue(inputs, address, ASCIIToUTF16("United States"), &outputs);
+ outputs[address] = ASCIIToUTF16("United States");
// Existing data should have no errors.
ValidityMessages messages = controller()->InputsAreValid(section, outputs);
EXPECT_FALSE(HasAnyError(messages, phone));
// Input an empty phone number.
- SetOutputValue(inputs, phone, base::string16(), &outputs);
+ outputs[phone] = base::string16();
messages = controller()->InputsAreValid(section, outputs);
EXPECT_TRUE(HasUnsureError(messages, phone));
// Input an invalid phone number.
- SetOutputValue(inputs, phone, ASCIIToUTF16("ABC"), &outputs);
+ outputs[phone] = ASCIIToUTF16("ABC");
messages = controller()->InputsAreValid(section, outputs);
EXPECT_TRUE(messages.HasSureError(phone));
// Input a local phone number.
- SetOutputValue(inputs, phone, ASCIIToUTF16("2155546699"), &outputs);
+ outputs[phone] = ASCIIToUTF16("2155546699");
messages = controller()->InputsAreValid(section, outputs);
EXPECT_FALSE(HasAnyError(messages, phone));
// Input an invalid local phone number.
- SetOutputValue(inputs, phone, ASCIIToUTF16("215554669"), &outputs);
+ outputs[phone] = ASCIIToUTF16("215554669");
messages = controller()->InputsAreValid(section, outputs);
EXPECT_TRUE(messages.HasSureError(phone));
// Input an international phone number.
- SetOutputValue(inputs, phone, ASCIIToUTF16("+33 892 70 12 39"), &outputs);
+ outputs[phone] = ASCIIToUTF16("+33 892 70 12 39");
messages = controller()->InputsAreValid(section, outputs);
EXPECT_FALSE(HasAnyError(messages, phone));
// Input an invalid international phone number.
- SetOutputValue(inputs, phone,
- ASCIIToUTF16("+112333 892 70 12 39"), &outputs);
+ outputs[phone] = ASCIIToUTF16("+112333 892 70 12 39");
messages = controller()->InputsAreValid(section, outputs);
EXPECT_TRUE(messages.HasSureError(phone));
}
}
TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) {
- FieldValueMap outputs;
- const DetailInputs& inputs =
- controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
-
ui::ComboboxModel* exp_year_model =
controller()->ComboboxModelForAutofillType(CREDIT_CARD_EXP_4_DIGIT_YEAR);
ui::ComboboxModel* exp_month_model =
@@ -721,9 +751,9 @@ TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) {
base::string16 other_month_value =
exp_month_model->GetItemAt(exp_month_model->GetItemCount() - 1);
- SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, default_month_value, &outputs);
- SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
- default_year_value, &outputs);
+ FieldValueMap outputs;
+ outputs[CREDIT_CARD_EXP_MONTH] = default_month_value;
+ outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = default_year_value;
// Expiration default values generate unsure validation errors (but not sure).
ValidityMessages messages = controller()->InputsAreValid(SECTION_CC_BILLING,
@@ -732,18 +762,14 @@ TEST_F(AutofillDialogControllerTest, ExpirationDateValidity) {
EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH));
// Expiration date with default month fails.
- SetOutputValue(inputs,
- CREDIT_CARD_EXP_4_DIGIT_YEAR,
- other_year_value,
- &outputs);
+ outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = other_year_value;
messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs);
EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR));
EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH));
// Expiration date with default year fails.
- SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, other_month_value, &outputs);
- SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
- default_year_value, &outputs);
+ outputs[CREDIT_CARD_EXP_MONTH] = other_month_value;
+ outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = default_year_value;
messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs);
EXPECT_TRUE(HasUnsureError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR));
EXPECT_FALSE(HasUnsureError(messages, CREDIT_CARD_EXP_MONTH));
@@ -753,18 +779,15 @@ TEST_F(AutofillDialogControllerTest, BillingNameValidation) {
// Construct FieldValueMap from AutofillProfile data.
SwitchToAutofill();
- FieldValueMap outputs;
- const DetailInputs& inputs =
- controller()->RequestedFieldsForSection(SECTION_BILLING);
-
// Input an empty billing name.
- SetOutputValue(inputs, NAME_BILLING_FULL, base::string16(), &outputs);
+ FieldValueMap outputs;
+ outputs[NAME_BILLING_FULL] = base::string16();
ValidityMessages messages = controller()->InputsAreValid(SECTION_BILLING,
outputs);
EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL));
// Input a non-empty billing name.
- SetOutputValue(inputs, NAME_BILLING_FULL, ASCIIToUTF16("Bob"), &outputs);
+ outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob");
messages = controller()->InputsAreValid(SECTION_BILLING, outputs);
EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL));
@@ -777,40 +800,31 @@ TEST_F(AutofillDialogControllerTest, BillingNameValidation) {
wallet::GetTestWalletItems(wallet::AMEX_DISALLOWED);
controller()->OnDidGetWalletItems(wallet_items.Pass());
- FieldValueMap wallet_outputs;
- const DetailInputs& wallet_inputs =
- controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
-
// Input an empty billing name. Data source should not change this behavior.
- SetOutputValue(wallet_inputs, NAME_BILLING_FULL,
- base::string16(), &wallet_outputs);
+ FieldValueMap wallet_outputs;
+ wallet_outputs[NAME_BILLING_FULL] = base::string16();
messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs);
EXPECT_TRUE(HasUnsureError(messages, NAME_BILLING_FULL));
// Input a one name billing name. Wallet does not currently support this.
- SetOutputValue(wallet_inputs, NAME_BILLING_FULL,
- ASCIIToUTF16("Bob"), &wallet_outputs);
+ wallet_outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob");
messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs);
EXPECT_TRUE(messages.HasSureError(NAME_BILLING_FULL));
// Input a two name billing name.
- SetOutputValue(wallet_inputs, NAME_BILLING_FULL,
- ASCIIToUTF16("Bob Barker"), &wallet_outputs);
+ wallet_outputs[NAME_BILLING_FULL] = ASCIIToUTF16("Bob Barker");
messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs);
EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL));
// Input a more than two name billing name.
- SetOutputValue(wallet_inputs, NAME_BILLING_FULL,
- ASCIIToUTF16("John Jacob Jingleheimer Schmidt"),
- &wallet_outputs);
+ wallet_outputs[NAME_BILLING_FULL] =
+ ASCIIToUTF16("John Jacob Jingleheimer Schmidt"),
messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs);
EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL));
// Input a billing name with lots of crazy whitespace.
- SetOutputValue(
- wallet_inputs, NAME_BILLING_FULL,
+ wallet_outputs[NAME_BILLING_FULL] =
ASCIIToUTF16(" \\n\\r John \\n Jacob Jingleheimer \\t Schmidt "),
- &wallet_outputs);
messages = controller()->InputsAreValid(SECTION_CC_BILLING, wallet_outputs);
EXPECT_FALSE(HasAnyError(messages, NAME_BILLING_FULL));
}
@@ -1137,45 +1151,35 @@ TEST_F(AutofillDialogControllerTest, DontUseBillingAsShipping) {
// Test selecting UseBillingForShipping.
TEST_F(AutofillDialogControllerTest, UseBillingAsShipping) {
SwitchToAutofill();
+
AutofillProfile full_profile(test::GetVerifiedProfile());
- AutofillProfile full_profile2(test::GetVerifiedProfile2());
- CreditCard credit_card(test::GetVerifiedCreditCard());
controller()->GetTestingManager()->AddTestingProfile(&full_profile);
+
+ AutofillProfile full_profile2(test::GetVerifiedProfile2());
controller()->GetTestingManager()->AddTestingProfile(&full_profile2);
+
+ CreditCard credit_card(test::GetVerifiedCreditCard());
controller()->GetTestingManager()->AddTestingCreditCard(&credit_card);
- // Test after setting use billing for shipping.
- UseBillingForShipping();
+ ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_CC));
+ ASSERT_FALSE(controller()->IsManuallyEditingSection(SECTION_BILLING));
- controller()->OnAccept();
- ASSERT_EQ(20U, form_structure()->field_count());
- EXPECT_EQ(ADDRESS_HOME_STATE,
- form_structure()->field(9)->Type().GetStorableType());
- EXPECT_EQ(ADDRESS_BILLING, form_structure()->field(9)->Type().group());
- EXPECT_EQ(ADDRESS_HOME_STATE,
- form_structure()->field(16)->Type().GetStorableType());
- EXPECT_EQ(ADDRESS_HOME, form_structure()->field(16)->Type().group());
- string16 billing_state = form_structure()->field(9)->value;
- string16 shipping_state = form_structure()->field(16)->value;
- EXPECT_FALSE(billing_state.empty());
- EXPECT_FALSE(shipping_state.empty());
- EXPECT_EQ(billing_state, shipping_state);
+ SubmitAndVerifyShippingAndBillingResults();
+}
- EXPECT_EQ(CREDIT_CARD_NAME,
- form_structure()->field(1)->Type().GetStorableType());
- string16 cc_name = form_structure()->field(1)->value;
- EXPECT_EQ(NAME_FULL, form_structure()->field(6)->Type().GetStorableType());
- EXPECT_EQ(NAME_BILLING, form_structure()->field(6)->Type().group());
- string16 billing_name = form_structure()->field(6)->value;
- EXPECT_EQ(NAME_FULL, form_structure()->field(13)->Type().GetStorableType());
- EXPECT_EQ(NAME, form_structure()->field(13)->Type().group());
- string16 shipping_name = form_structure()->field(13)->value;
+TEST_F(AutofillDialogControllerTest, UseBillingAsShippingManualInput) {
+ SwitchToAutofill();
- EXPECT_FALSE(cc_name.empty());
- EXPECT_FALSE(billing_name.empty());
- EXPECT_FALSE(shipping_name.empty());
- EXPECT_EQ(cc_name, billing_name);
- EXPECT_EQ(cc_name, shipping_name);
+ ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_CC));
+ ASSERT_TRUE(controller()->IsManuallyEditingSection(SECTION_BILLING));
+
+ CreditCard credit_card(test::GetVerifiedCreditCard());
+ FillInputs(SECTION_CC, credit_card);
+
+ AutofillProfile full_profile(test::GetVerifiedProfile());
+ FillInputs(SECTION_BILLING, full_profile);
+
+ SubmitAndVerifyShippingAndBillingResults();
}
// Tests that shipping and billing telephone fields are supported, and filled
@@ -2194,12 +2198,11 @@ TEST_F(AutofillDialogControllerTest, WalletExpiredCard) {
EXPECT_TRUE(controller()->IsEditingExistingData(SECTION_CC_BILLING));
- // Use |SetOutputValue()| to put the right ServerFieldTypes into the map.
const DetailInputs& inputs =
controller()->RequestedFieldsForSection(SECTION_CC_BILLING);
FieldValueMap outputs;
CopyInitialValues(inputs, &outputs);
- SetOutputValue(inputs, COMPANY_NAME, ASCIIToUTF16("Bluth Company"), &outputs);
+ outputs[COMPANY_NAME] = ASCIIToUTF16("Bluth Company");
// The local inputs are invalid because the server said so. They'll
// stay invalid until they differ from the remotely fetched model.
@@ -2210,15 +2213,14 @@ TEST_F(AutofillDialogControllerTest, WalletExpiredCard) {
// Make the local input year differ from the instrument.
CopyInitialValues(inputs, &outputs);
- SetOutputValue(inputs, CREDIT_CARD_EXP_4_DIGIT_YEAR,
- ASCIIToUTF16("3002"), &outputs);
+ outputs[CREDIT_CARD_EXP_4_DIGIT_YEAR] = ASCIIToUTF16("3002");
messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs);
EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_MONTH));
EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR));
// Make the local input month differ from the instrument.
CopyInitialValues(inputs, &outputs);
- SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"), &outputs);
+ outputs[CREDIT_CARD_EXP_MONTH] = ASCIIToUTF16("06");
messages = controller()->InputsAreValid(SECTION_CC_BILLING, outputs);
EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_MONTH));
EXPECT_FALSE(HasAnyError(messages, CREDIT_CARD_EXP_4_DIGIT_YEAR));
@@ -2622,7 +2624,7 @@ TEST_F(AutofillDialogControllerTest, InputEditability) {
}
// User changes the billing address; same story.
- SetOutputValue(inputs, ADDRESS_BILLING_ZIP, ASCIIToUTF16("77025"), &outputs);
+ outputs[ADDRESS_BILLING_ZIP] = ASCIIToUTF16("77025");
controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs);
for (size_t i = 0; i < arraysize(sections); ++i) {
const DetailInputs& inputs =
@@ -2639,7 +2641,7 @@ TEST_F(AutofillDialogControllerTest, InputEditability) {
// User changes a detail of the CC itself (expiration date), CVV is now
// editable (and mandatory).
- SetOutputValue(inputs, CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("06"), &outputs);
+ outputs[CREDIT_CARD_EXP_MONTH] = ASCIIToUTF16("06");
controller()->GetView()->SetUserInput(SECTION_CC_BILLING, outputs);
for (size_t i = 0; i < arraysize(sections); ++i) {
const DetailInputs& inputs =
@@ -2704,4 +2706,26 @@ TEST_F(AutofillDialogControllerTest, PassiveAuthFailure) {
EXPECT_FALSE(controller()->ShouldShowSpinner());
}
+TEST_F(AutofillDialogControllerTest, CountryChangeUpdatesSection) {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ ::switches::kEnableAutofillAddressInternationalization);
+ Reset();
+
+ controller()->GetView()->ClearSectionUpdates();
+
+ controller()->ComboboxItemSelected(
+ controller()->ComboboxModelForAutofillType(ADDRESS_HOME_COUNTRY),
+ SECTION_SHIPPING,
+ 3);
+ EXPECT_EQ(1U, controller()->GetView()->section_updates()[SECTION_SHIPPING]);
+ EXPECT_EQ(0U, controller()->GetView()->section_updates()[SECTION_BILLING]);
+
+ controller()->ComboboxItemSelected(
+ controller()->ComboboxModelForAutofillType(ADDRESS_BILLING_COUNTRY),
+ SECTION_BILLING,
+ 3);
+ EXPECT_EQ(1U, controller()->GetView()->section_updates()[SECTION_BILLING]);
+ EXPECT_EQ(1U, controller()->GetView()->section_updates()[SECTION_SHIPPING]);
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698