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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 std::vector<FormData> forms = form_cache.ExtractNewForms(); | 1012 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
1013 ASSERT_EQ(1U, forms.size()); | 1013 ASSERT_EQ(1U, forms.size()); |
1014 | 1014 |
1015 // Set the auto-filled attribute. | 1015 // Set the auto-filled attribute. |
1016 WebInputElement firstname = GetInputElementById("firstname"); | 1016 WebInputElement firstname = GetInputElementById("firstname"); |
1017 firstname.setAutofilled(true); | 1017 firstname.setAutofilled(true); |
1018 WebInputElement lastname = GetInputElementById("lastname"); | 1018 WebInputElement lastname = GetInputElementById("lastname"); |
1019 lastname.setAutofilled(true); | 1019 lastname.setAutofilled(true); |
1020 WebInputElement month = GetInputElementById("month"); | 1020 WebInputElement month = GetInputElementById("month"); |
1021 month.setAutofilled(true); | 1021 month.setAutofilled(true); |
1022 WebInputElement textarea = GetInputElementById("textarea"); | 1022 WebFormControlElement textarea = GetFormControlElementById("textarea"); |
1023 textarea.setAutofilled(true); | 1023 textarea.setAutofilled(true); |
1024 | 1024 |
1025 // Set the value of the disabled text input element. | 1025 // Set the value of the disabled text input element. |
1026 WebInputElement notenabled = GetInputElementById("notenabled"); | 1026 WebInputElement notenabled = GetInputElementById("notenabled"); |
1027 notenabled.setValue(WebString::fromUTF8("no clear")); | 1027 notenabled.setValue(WebString::fromUTF8("no clear")); |
1028 | 1028 |
1029 // Clear the form. | 1029 // Clear the form. |
1030 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 1030 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
1031 | 1031 |
1032 // Verify that the auto-filled attribute has been turned off. | 1032 // Verify that the auto-filled attribute has been turned off. |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); | 1996 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); |
1997 | 1997 |
1998 expected.name = ASCIIToUTF16("month"); | 1998 expected.name = ASCIIToUTF16("month"); |
1999 expected.value = ASCIIToUTF16("2011-12"); | 1999 expected.value = ASCIIToUTF16("2011-12"); |
2000 expected.label = ASCIIToUTF16("Card expiration:"); | 2000 expected.label = ASCIIToUTF16("Card expiration:"); |
2001 expected.form_control_type = "month"; | 2001 expected.form_control_type = "month"; |
2002 expected.max_length = 0; | 2002 expected.max_length = 0; |
2003 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); | 2003 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
2004 } | 2004 } |
2005 | 2005 |
| 2006 TEST_F(FormAutofillTest, WebFormElementConsiderNonControlLabelableElements) { |
| 2007 LoadHTML("<form id=form>" |
| 2008 " <label for='progress'>Progress:</label>" |
| 2009 " <progress id='progress'></progress>" |
| 2010 " <label for='firstname'>First name:</label>" |
| 2011 " <input type='text' id='firstname' value='John'>" |
| 2012 "</form>"); |
| 2013 |
| 2014 WebFrame* frame = GetMainFrame(); |
| 2015 ASSERT_NE(nullptr, frame); |
| 2016 |
| 2017 WebFormElement web_form = frame->document().getElementById("form") |
| 2018 .to<WebFormElement>(); |
| 2019 ASSERT_FALSE(web_form.isNull()); |
| 2020 |
| 2021 FormData form; |
| 2022 EXPECT_TRUE(WebFormElementToFormData(web_form, WebFormControlElement(), |
| 2023 EXTRACT_NONE, &form, nullptr)); |
| 2024 |
| 2025 const std::vector<FormFieldData>& fields = form.fields; |
| 2026 ASSERT_EQ(1U, fields.size()); |
| 2027 EXPECT_EQ(ASCIIToUTF16("firstname"), fields[0].name); |
| 2028 } |
| 2029 |
2006 // We should not be able to serialize a form with too many fillable fields. | 2030 // We should not be able to serialize a form with too many fillable fields. |
2007 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { | 2031 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { |
2008 std::string html = | 2032 std::string html = |
2009 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; | 2033 "<FORM name='TestForm' action='http://cnn.com' method='post'>"; |
2010 for (size_t i = 0; i < (kMaxParseableFields + 1); ++i) { | 2034 for (size_t i = 0; i < (kMaxParseableFields + 1); ++i) { |
2011 html += "<INPUT type='text'/>"; | 2035 html += "<INPUT type='text'/>"; |
2012 } | 2036 } |
2013 html += "</FORM>"; | 2037 html += "</FORM>"; |
2014 LoadHTML(html.c_str()); | 2038 LoadHTML(html.c_str()); |
2015 | 2039 |
(...skipping 2082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4098 ASSERT_TRUE(control_elements.empty()); | 4122 ASSERT_TRUE(control_elements.empty()); |
4099 ASSERT_TRUE(fieldsets.empty()); | 4123 ASSERT_TRUE(fieldsets.empty()); |
4100 | 4124 |
4101 FormData form; | 4125 FormData form; |
4102 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( | 4126 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( |
4103 fieldsets, control_elements, nullptr, frame->document(), extract_mask, | 4127 fieldsets, control_elements, nullptr, frame->document(), extract_mask, |
4104 &form, nullptr)); | 4128 &form, nullptr)); |
4105 } | 4129 } |
4106 | 4130 |
4107 } // namespace autofill | 4131 } // namespace autofill |
OLD | NEW |