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