Chromium Code Reviews| Index: components/autofill/core/browser/autofill_manager_unittest.cc |
| diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc |
| index 487eb1084fabbe40b69366b83d8448538aadb3c1..935df37fbec755e481eac9d0921b54c133e15946 100644 |
| --- a/components/autofill/core/browser/autofill_manager_unittest.cc |
| +++ b/components/autofill/core/browser/autofill_manager_unittest.cc |
| @@ -35,6 +35,7 @@ |
| #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| #include "components/autofill/core/common/autofill_pref_names.h" |
| #include "components/autofill/core/common/autofill_switches.h" |
| +#include "components/autofill/core/common/autofill_util.h" |
| #include "components/autofill/core/common/form_data.h" |
| #include "components/autofill/core/common/form_field_data.h" |
| #include "grit/components_strings.h" |
| @@ -1895,6 +1896,89 @@ TEST_F(AutofillManagerTest, FillAddressAndCreditCardForm) { |
| } |
| } |
| +// Test that non credit card related fields with the autocomplete attribute set |
| +// to off are not filled on desktop. |
| +TEST_F(AutofillManagerTest, FillAddressForm_AutocompleteOff) { |
| + FormData address_form; |
| + address_form.name = ASCIIToUTF16("MyForm"); |
| + address_form.origin = GURL("https://myform.com/form.html"); |
| + address_form.action = GURL("https://myform.com/submit.html"); |
| + FormFieldData field; |
| + test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| + address_form.fields.push_back(field); |
| + test::CreateTestFormField("Middle name", "middle", "", "text", &field); |
| + field.should_autocomplete = false; |
| + address_form.fields.push_back(field); |
| + test::CreateTestFormField("Last name", "lastname", "", "text", &field); |
| + field.should_autocomplete = true; |
| + address_form.fields.push_back(field); |
| + test::CreateTestFormField("Address Line 1", "addr1", "", "text", &field); |
| + field.should_autocomplete = false; |
| + address_form.fields.push_back(field); |
| + std::vector<FormData> address_forms(1, address_form); |
| + FormsSeen(address_forms); |
| + |
| + // Fill the address form. |
| + const char guid[] = "00000000-0000-0000-0000-000000000001"; |
| + int response_page_id = 0; |
| + FormData response_data; |
| + FillAutofillFormDataAndSaveResults( |
| + kDefaultPageID, address_form, address_form.fields[0], |
| + MakeFrontendID(std::string(), guid), &response_page_id, &response_data); |
| + |
| + // The fist name should be filled. |
| + ExpectFilledField("First name", "firstname", "Elvis", "text", |
| + response_data.fields[0]); |
| + |
| + // The middle name should not be filled on desktop. |
| + if (IsOnDesktop()) { |
| + ExpectFilledField("Middle name", "middle", "", "text", |
| + response_data.fields[1]); |
| + } else { |
| + ExpectFilledField("Middle name", "middle", "Aaron", "text", |
| + response_data.fields[1]); |
| + } |
| + |
| + // The last name should be filled. |
| + ExpectFilledField("Last name", "lastname", "Presley", "text", |
| + response_data.fields[2]); |
| + |
| + // The address line 1 should not be filled on desktop. |
| + if (IsOnDesktop()) { |
| + ExpectFilledField("Address Line 1", "addr1", "", "text", |
| + response_data.fields[3]); |
| + } else { |
| + ExpectFilledField("Address Line 1", "addr1", "3734 Elvis Presley Blvd.", |
| + "text", response_data.fields[3]); |
| + } |
| +} |
| + |
| +// Test that credit card fields are filled even if they have the autocomplete |
| +// attribute set to off. |
| +TEST_F(AutofillManagerTest, FillCreditCardForm_AutocompleteOff) { |
| + // Set up our form data. |
| + FormData form; |
| + CreateTestCreditCardFormData(&form, true, false); |
| + |
| + // Set the autocomplete=off on all fields. |
| + for (FormFieldData field : form.fields) |
| + field.should_autocomplete = false; |
| + |
| + std::vector<FormData> forms(1, form); |
| + FormsSeen(forms); |
| + |
| + const char guid[] = "00000000-0000-0000-0000-000000000004"; |
| + int response_page_id = 0; |
| + FormData response_data; |
| + FillAutofillFormDataAndSaveResults(kDefaultPageID, form, *form.fields.begin(), |
| + MakeFrontendID(guid, std::string()), |
| + &response_page_id, &response_data); |
| + |
| + // All fields should be filled. |
| + ExpectFilledCreditCardFormElvis(response_page_id, response_data, |
| + kDefaultPageID, false); |
| +} |
| + |
| // Test that non-focusable field is ignored while inferring boundaries between |
| // sections: http://crbug.com/231160 |
| TEST_F(AutofillManagerTest, FillFormWithNonFocusableFields) { |
| @@ -3870,4 +3954,49 @@ TEST_F(AutofillManagerTest, ShouldUploadForm) { |
| EXPECT_FALSE(autofill_manager_->ShouldUploadForm(form_structure_3)); |
| } |
| +// Verify that no suggestions are shown on desktop for non credit card related |
| +// fields if the form has the autocomplete attribute set to off. |
|
Mathieu
2015/11/27 16:14:33
fix comment. "if the initiating field has autocomp
sebsg
2015/11/27 19:26:21
Done.
|
| +TEST_F(AutofillManagerTest, DisplaySuggestions_AutocompleteOffOnField) { |
|
Mathieu
2015/11/27 16:14:33
Let's have this test be non-credit card only, and
sebsg
2015/11/27 19:26:21
Done.
|
| + // Set up a mixed form. |
| + FormData mixed_form; |
| + mixed_form.name = ASCIIToUTF16("MyForm"); |
| + mixed_form.origin = GURL("https://myform.com/form.html"); |
| + mixed_form.action = GURL("https://myform.com/submit.html"); |
| + FormFieldData field; |
| + test::CreateTestFormField("First name", "firstname", "", "text", &field); |
| + field.should_autocomplete = false; |
| + mixed_form.fields.push_back(field); |
| + test::CreateTestFormField("Last name", "lastname", "", "text", &field); |
| + field.should_autocomplete = false; |
| + mixed_form.fields.push_back(field); |
| + test::CreateTestFormField("Name on Card", "nameoncard", "", "text", &field); |
| + mixed_form.fields.push_back(field); |
| + field.should_autocomplete = false; |
| + test::CreateTestFormField("Card Number", "cardnumber", "", "text", &field); |
| + field.should_autocomplete = false; |
| + mixed_form.fields.push_back(field); |
| + std::vector<FormData> mixed_forms(1, mixed_form); |
| + FormsSeen(mixed_forms); |
| + |
| + GetAutofillSuggestions(mixed_form, mixed_form.fields[0]); |
| + if (IsOnDesktop()) { |
| + EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| + } else { |
| + EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| + } |
| + |
| + GetAutofillSuggestions(mixed_form, mixed_form.fields[1]); |
| + if (IsOnDesktop()) { |
| + EXPECT_FALSE(external_delegate_->on_suggestions_returned_seen()); |
| + } else { |
| + EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| + } |
| + |
| + GetAutofillSuggestions(mixed_form, mixed_form.fields[2]); |
| + EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| + |
| + GetAutofillSuggestions(mixed_form, mixed_form.fields[3]); |
| + EXPECT_TRUE(external_delegate_->on_suggestions_returned_seen()); |
| +} |
| + |
| } // namespace autofill |