| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 void ExpectFilledField(const char* expected_label, | 298 void ExpectFilledField(const char* expected_label, |
| 299 const char* expected_name, | 299 const char* expected_name, |
| 300 const char* expected_value, | 300 const char* expected_value, |
| 301 const char* expected_form_control_type, | 301 const char* expected_form_control_type, |
| 302 const FormFieldData& field) { | 302 const FormFieldData& field) { |
| 303 SCOPED_TRACE(expected_label); | 303 SCOPED_TRACE(expected_label); |
| 304 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); | 304 EXPECT_EQ(UTF8ToUTF16(expected_label), field.label); |
| 305 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); | 305 EXPECT_EQ(UTF8ToUTF16(expected_name), field.name); |
| 306 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); | 306 EXPECT_EQ(UTF8ToUTF16(expected_value), field.value); |
| 307 EXPECT_EQ(UTF8ToUTF16(expected_form_control_type), field.form_control_type); | 307 EXPECT_EQ(expected_form_control_type, field.form_control_type); |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Verifies that the |filled_form| has been filled with the given data. | 310 // Verifies that the |filled_form| has been filled with the given data. |
| 311 // Verifies address fields if |has_address_fields| is true, and verifies | 311 // Verifies address fields if |has_address_fields| is true, and verifies |
| 312 // credit card fields if |has_credit_card_fields| is true. Verifies both if both | 312 // credit card fields if |has_credit_card_fields| is true. Verifies both if both |
| 313 // are true. |use_month_type| is used for credit card input month type. | 313 // are true. |use_month_type| is used for credit card input month type. |
| 314 void ExpectFilledForm(int page_id, | 314 void ExpectFilledForm(int page_id, |
| 315 const FormData& filled_form, | 315 const FormData& filled_form, |
| 316 int expected_page_id, | 316 int expected_page_id, |
| 317 const char* first, | 317 const char* first, |
| (...skipping 1668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 FormData form; | 1986 FormData form; |
| 1987 form.name = ASCIIToUTF16("MyForm"); | 1987 form.name = ASCIIToUTF16("MyForm"); |
| 1988 form.method = ASCIIToUTF16("POST"); | 1988 form.method = ASCIIToUTF16("POST"); |
| 1989 form.origin = GURL("https://myform.com/form.html"); | 1989 form.origin = GURL("https://myform.com/form.html"); |
| 1990 form.action = GURL("https://myform.com/submit.html"); | 1990 form.action = GURL("https://myform.com/submit.html"); |
| 1991 form.user_submitted = true; | 1991 form.user_submitted = true; |
| 1992 | 1992 |
| 1993 FormFieldData field; | 1993 FormFieldData field; |
| 1994 | 1994 |
| 1995 autofill_test::CreateTestFormField("", "country", "", "text", &field); | 1995 autofill_test::CreateTestFormField("", "country", "", "text", &field); |
| 1996 field.autocomplete_type = ASCIIToUTF16("section-billing country"); | 1996 field.autocomplete_attribute = "section-billing country"; |
| 1997 form.fields.push_back(field); | 1997 form.fields.push_back(field); |
| 1998 | 1998 |
| 1999 autofill_test::CreateTestFormField("", "firstname", "", "text", &field); | 1999 autofill_test::CreateTestFormField("", "firstname", "", "text", &field); |
| 2000 field.autocomplete_type = ASCIIToUTF16("given-name"); | 2000 field.autocomplete_attribute = "given-name"; |
| 2001 form.fields.push_back(field); | 2001 form.fields.push_back(field); |
| 2002 | 2002 |
| 2003 autofill_test::CreateTestFormField("", "lastname", "", "text", &field); | 2003 autofill_test::CreateTestFormField("", "lastname", "", "text", &field); |
| 2004 field.autocomplete_type = ASCIIToUTF16("surname"); | 2004 field.autocomplete_attribute = "family-name"; |
| 2005 form.fields.push_back(field); | 2005 form.fields.push_back(field); |
| 2006 | 2006 |
| 2007 autofill_test::CreateTestFormField("", "address", "", "text", &field); | 2007 autofill_test::CreateTestFormField("", "address", "", "text", &field); |
| 2008 field.autocomplete_type = ASCIIToUTF16("section-billing street-address"); | 2008 field.autocomplete_attribute = "section-billing street-address"; |
| 2009 form.fields.push_back(field); | 2009 form.fields.push_back(field); |
| 2010 | 2010 |
| 2011 autofill_test::CreateTestFormField("", "city", "", "text", &field); | 2011 autofill_test::CreateTestFormField("", "city", "", "text", &field); |
| 2012 field.autocomplete_type = ASCIIToUTF16("section-billing locality"); | 2012 field.autocomplete_attribute = "section-billing locality"; |
| 2013 form.fields.push_back(field); | 2013 form.fields.push_back(field); |
| 2014 | 2014 |
| 2015 autofill_test::CreateTestFormField("", "state", "", "text", &field); | 2015 autofill_test::CreateTestFormField("", "state", "", "text", &field); |
| 2016 field.autocomplete_type = ASCIIToUTF16("section-billing administrative-area"); | 2016 field.autocomplete_attribute = "section-billing region"; |
| 2017 form.fields.push_back(field); | 2017 form.fields.push_back(field); |
| 2018 | 2018 |
| 2019 autofill_test::CreateTestFormField("", "zip", "", "text", &field); | 2019 autofill_test::CreateTestFormField("", "zip", "", "text", &field); |
| 2020 field.autocomplete_type = ASCIIToUTF16("section-billing postal-code"); | 2020 field.autocomplete_attribute = "section-billing postal-code"; |
| 2021 form.fields.push_back(field); | 2021 form.fields.push_back(field); |
| 2022 | 2022 |
| 2023 autofill_test::CreateTestFormField("", "ccname", "", "text", &field); | 2023 autofill_test::CreateTestFormField("", "ccname", "", "text", &field); |
| 2024 field.autocomplete_type = ASCIIToUTF16("section-billing cc-full-name"); | 2024 field.autocomplete_attribute = "section-billing cc-name"; |
| 2025 form.fields.push_back(field); | 2025 form.fields.push_back(field); |
| 2026 | 2026 |
| 2027 autofill_test::CreateTestFormField("", "ccnumber", "", "text", &field); | 2027 autofill_test::CreateTestFormField("", "ccnumber", "", "text", &field); |
| 2028 field.autocomplete_type = ASCIIToUTF16("section-billing cc-number"); | 2028 field.autocomplete_attribute = "section-billing cc-number"; |
| 2029 form.fields.push_back(field); | 2029 form.fields.push_back(field); |
| 2030 | 2030 |
| 2031 autofill_test::CreateTestFormField("", "ccexp", "", "text", &field); | 2031 autofill_test::CreateTestFormField("", "ccexp", "", "text", &field); |
| 2032 field.autocomplete_type = ASCIIToUTF16("section-billing cc-exp"); | 2032 field.autocomplete_attribute = "section-billing cc-exp"; |
| 2033 form.fields.push_back(field); | 2033 form.fields.push_back(field); |
| 2034 | 2034 |
| 2035 autofill_test::CreateTestFormField("", "email", "", "text", &field); | 2035 autofill_test::CreateTestFormField("", "email", "", "text", &field); |
| 2036 field.autocomplete_type = ASCIIToUTF16("email"); | 2036 field.autocomplete_attribute = "email"; |
| 2037 form.fields.push_back(field); | 2037 form.fields.push_back(field); |
| 2038 | 2038 |
| 2039 std::vector<FormData> forms(1, form); | 2039 std::vector<FormData> forms(1, form); |
| 2040 FormsSeen(forms); | 2040 FormsSeen(forms); |
| 2041 | 2041 |
| 2042 // Fill the unnamed section. | 2042 // Fill the unnamed section. |
| 2043 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2043 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2044 GUIDPair empty(std::string(), 0); | 2044 GUIDPair empty(std::string(), 0); |
| 2045 FillAutofillFormData(kDefaultPageID, form, form.fields[1], | 2045 FillAutofillFormData(kDefaultPageID, form, form.fields[1], |
| 2046 PackGUIDs(empty, guid)); | 2046 PackGUIDs(empty, guid)); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2293 form_with_maxlength.origin = GURL("http://myform.com/phone_form.html"); | 2293 form_with_maxlength.origin = GURL("http://myform.com/phone_form.html"); |
| 2294 form_with_maxlength.action = GURL("http://myform.com/phone_submit.html"); | 2294 form_with_maxlength.action = GURL("http://myform.com/phone_submit.html"); |
| 2295 form_with_maxlength.user_submitted = true; | 2295 form_with_maxlength.user_submitted = true; |
| 2296 FormData form_with_autocompletetype = form_with_maxlength; | 2296 FormData form_with_autocompletetype = form_with_maxlength; |
| 2297 form_with_autocompletetype.name = ASCIIToUTF16("MyAutocompletetypePhoneForm"); | 2297 form_with_autocompletetype.name = ASCIIToUTF16("MyAutocompletetypePhoneForm"); |
| 2298 | 2298 |
| 2299 struct { | 2299 struct { |
| 2300 const char* label; | 2300 const char* label; |
| 2301 const char* name; | 2301 const char* name; |
| 2302 size_t max_length; | 2302 size_t max_length; |
| 2303 const char* autocomplete_type; | 2303 const char* autocomplete_attribute; |
| 2304 } test_fields[] = { | 2304 } test_fields[] = { |
| 2305 { "country code", "country_code", 1, "phone-country-code" }, | 2305 { "country code", "country_code", 1, "tel-country-code" }, |
| 2306 { "area code", "area_code", 3, "phone-area-code" }, | 2306 { "area code", "area_code", 3, "tel-area-code" }, |
| 2307 { "phone", "phone_prefix", 3, "phone-local-prefix" }, | 2307 { "phone", "phone_prefix", 3, "tel-local-prefix" }, |
| 2308 { "-", "phone_suffix", 4, "phone-local-suffix" }, | 2308 { "-", "phone_suffix", 4, "tel-local-suffix" }, |
| 2309 { "Phone Extension", "ext", 3, "phone-extension" } | 2309 { "Phone Extension", "ext", 3, "tel-extension" } |
| 2310 }; | 2310 }; |
| 2311 | 2311 |
| 2312 FormFieldData field; | 2312 FormFieldData field; |
| 2313 const size_t default_max_length = field.max_length; | 2313 const size_t default_max_length = field.max_length; |
| 2314 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_fields); ++i) { | 2314 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_fields); ++i) { |
| 2315 autofill_test::CreateTestFormField( | 2315 autofill_test::CreateTestFormField( |
| 2316 test_fields[i].label, test_fields[i].name, "", "text", &field); | 2316 test_fields[i].label, test_fields[i].name, "", "text", &field); |
| 2317 field.max_length = test_fields[i].max_length; | 2317 field.max_length = test_fields[i].max_length; |
| 2318 field.autocomplete_type = string16(); | 2318 field.autocomplete_attribute = std::string(); |
| 2319 form_with_maxlength.fields.push_back(field); | 2319 form_with_maxlength.fields.push_back(field); |
| 2320 | 2320 |
| 2321 field.max_length = default_max_length; | 2321 field.max_length = default_max_length; |
| 2322 field.autocomplete_type = ASCIIToUTF16(test_fields[i].autocomplete_type); | 2322 field.autocomplete_attribute = test_fields[i].autocomplete_attribute; |
| 2323 form_with_autocompletetype.fields.push_back(field); | 2323 form_with_autocompletetype.fields.push_back(field); |
| 2324 } | 2324 } |
| 2325 | 2325 |
| 2326 std::vector<FormData> forms; | 2326 std::vector<FormData> forms; |
| 2327 forms.push_back(form_with_maxlength); | 2327 forms.push_back(form_with_maxlength); |
| 2328 forms.push_back(form_with_autocompletetype); | 2328 forms.push_back(form_with_autocompletetype); |
| 2329 FormsSeen(forms); | 2329 FormsSeen(forms); |
| 2330 | 2330 |
| 2331 // We should be able to fill prefix and suffix fields for US numbers. | 2331 // We should be able to fill prefix and suffix fields for US numbers. |
| 2332 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( | 2332 AutofillProfile* work_profile = autofill_manager_->GetProfileWithGUID( |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2582 // values. | 2582 // values. |
| 2583 TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) { | 2583 TEST_F(AutofillManagerTest, FormSubmittedWithDefaultValues) { |
| 2584 // Set up our form data. | 2584 // Set up our form data. |
| 2585 FormData form; | 2585 FormData form; |
| 2586 CreateTestAddressFormData(&form); | 2586 CreateTestAddressFormData(&form); |
| 2587 form.fields[3].value = ASCIIToUTF16("Enter your address"); | 2587 form.fields[3].value = ASCIIToUTF16("Enter your address"); |
| 2588 | 2588 |
| 2589 // Convert the state field to a <select> popup, to make sure that we only | 2589 // Convert the state field to a <select> popup, to make sure that we only |
| 2590 // reject default values for text fields. | 2590 // reject default values for text fields. |
| 2591 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); | 2591 ASSERT_TRUE(form.fields[6].name == ASCIIToUTF16("state")); |
| 2592 form.fields[6].form_control_type = ASCIIToUTF16("select-one"); | 2592 form.fields[6].form_control_type = "select-one"; |
| 2593 form.fields[6].value = ASCIIToUTF16("Tennessee"); | 2593 form.fields[6].value = ASCIIToUTF16("Tennessee"); |
| 2594 | 2594 |
| 2595 std::vector<FormData> forms(1, form); | 2595 std::vector<FormData> forms(1, form); |
| 2596 FormsSeen(forms); | 2596 FormsSeen(forms); |
| 2597 | 2597 |
| 2598 // Fill the form. | 2598 // Fill the form. |
| 2599 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); | 2599 GUIDPair guid("00000000-0000-0000-0000-000000000001", 0); |
| 2600 GUIDPair empty(std::string(), 0); | 2600 GUIDPair empty(std::string(), 0); |
| 2601 FillAutofillFormData(kDefaultPageID, form, form.fields[3], | 2601 FillAutofillFormData(kDefaultPageID, form, form.fields[3], |
| 2602 PackGUIDs(empty, guid)); | 2602 PackGUIDs(empty, guid)); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3132 AutofillManager* autofill_manager = | 3132 AutofillManager* autofill_manager = |
| 3133 AutofillManager::FromWebContents(contents); | 3133 AutofillManager::FromWebContents(contents); |
| 3134 EXPECT_TRUE(autofill_manager->external_delegate()); | 3134 EXPECT_TRUE(autofill_manager->external_delegate()); |
| 3135 | 3135 |
| 3136 AutocompleteHistoryManager* autocomplete_history_manager = | 3136 AutocompleteHistoryManager* autocomplete_history_manager = |
| 3137 AutocompleteHistoryManager::FromWebContents(contents); | 3137 AutocompleteHistoryManager::FromWebContents(contents); |
| 3138 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); | 3138 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); |
| 3139 } | 3139 } |
| 3140 | 3140 |
| 3141 #endif // OS_ANDROID | 3141 #endif // OS_ANDROID |
| OLD | NEW |