| 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/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/form_data.h" |
| 12 #include "chrome/renderer/autofill/form_autofill_util.h" | 13 #include "chrome/renderer/autofill/form_autofill_util.h" |
| 13 #include "chrome/renderer/autofill/form_cache.h" | 14 #include "chrome/renderer/autofill/form_cache.h" |
| 14 #include "chrome/test/base/chrome_render_view_test.h" | 15 #include "chrome/test/base/chrome_render_view_test.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement
.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSelectElement.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" |
| 25 #include "webkit/forms/form_data.h" | |
| 26 #include "webkit/glue/web_io_operators.h" | 26 #include "webkit/glue/web_io_operators.h" |
| 27 | 27 |
| 28 using WebKit::WebDocument; | 28 using WebKit::WebDocument; |
| 29 using WebKit::WebElement; | 29 using WebKit::WebElement; |
| 30 using WebKit::WebFormControlElement; | 30 using WebKit::WebFormControlElement; |
| 31 using WebKit::WebFormElement; | 31 using WebKit::WebFormElement; |
| 32 using WebKit::WebFrame; | 32 using WebKit::WebFrame; |
| 33 using WebKit::WebInputElement; | 33 using WebKit::WebInputElement; |
| 34 using WebKit::WebSelectElement; | 34 using WebKit::WebSelectElement; |
| 35 using WebKit::WebNode; | 35 using WebKit::WebNode; |
| 36 using WebKit::WebString; | 36 using WebKit::WebString; |
| 37 using WebKit::WebVector; | 37 using WebKit::WebVector; |
| 38 | 38 |
| 39 using autofill::ClearPreviewedFormWithElement; | 39 using autofill::ClearPreviewedFormWithElement; |
| 40 using autofill::FillForm; | 40 using autofill::FillForm; |
| 41 using autofill::FindFormAndFieldForInputElement; | 41 using autofill::FindFormAndFieldForInputElement; |
| 42 using autofill::FormWithElementIsAutofilled; | 42 using autofill::FormWithElementIsAutofilled; |
| 43 using autofill::FormCache; | 43 using autofill::FormCache; |
| 44 using autofill::PreviewForm; | 44 using autofill::PreviewForm; |
| 45 using autofill::WebFormControlElementToFormField; | 45 using autofill::WebFormControlElementToFormField; |
| 46 | 46 |
| 47 using webkit::forms::FormData; | |
| 48 using webkit::forms::FormField; | |
| 49 | |
| 50 class FormAutofillTest : public ChromeRenderViewTest { | 47 class FormAutofillTest : public ChromeRenderViewTest { |
| 51 public: | 48 public: |
| 52 FormAutofillTest() : ChromeRenderViewTest() {} | 49 FormAutofillTest() : ChromeRenderViewTest() {} |
| 53 virtual ~FormAutofillTest() {} | 50 virtual ~FormAutofillTest() {} |
| 54 | 51 |
| 55 void ExpectLabels(const char* html, | 52 void ExpectLabels(const char* html, |
| 56 const std::vector<string16>& labels, | 53 const std::vector<string16>& labels, |
| 57 const std::vector<string16>& names, | 54 const std::vector<string16>& names, |
| 58 const std::vector<string16>& values) { | 55 const std::vector<string16>& values) { |
| 59 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text")); | 56 std::vector<string16> control_types(labels.size(), ASCIIToUTF16("text")); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 FormCache form_cache; | 74 FormCache form_cache; |
| 78 std::vector<FormData> forms; | 75 std::vector<FormData> forms; |
| 79 form_cache.ExtractForms(*web_frame, &forms); | 76 form_cache.ExtractForms(*web_frame, &forms); |
| 80 ASSERT_EQ(1U, forms.size()); | 77 ASSERT_EQ(1U, forms.size()); |
| 81 | 78 |
| 82 const FormData& form = forms[0]; | 79 const FormData& form = forms[0]; |
| 83 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 80 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 84 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 81 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 85 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 82 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 86 | 83 |
| 87 const std::vector<FormField>& fields = form.fields; | 84 const std::vector<FormFieldData>& fields = form.fields; |
| 88 ASSERT_EQ(labels.size(), fields.size()); | 85 ASSERT_EQ(labels.size(), fields.size()); |
| 89 for (size_t i = 0; i < labels.size(); ++i) { | 86 for (size_t i = 0; i < labels.size(); ++i) { |
| 90 int max_length = control_types[i] == ASCIIToUTF16("text") ? | 87 int max_length = control_types[i] == ASCIIToUTF16("text") ? |
| 91 WebInputElement::defaultMaxLength() : 0; | 88 WebInputElement::defaultMaxLength() : 0; |
| 92 FormField expected; | 89 FormFieldData expected; |
| 93 expected.label = labels[i]; | 90 expected.label = labels[i]; |
| 94 expected.name = names[i]; | 91 expected.name = names[i]; |
| 95 expected.value = values[i]; | 92 expected.value = values[i]; |
| 96 expected.form_control_type = control_types[i]; | 93 expected.form_control_type = control_types[i]; |
| 97 expected.max_length = max_length; | 94 expected.max_length = max_length; |
| 98 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); | 95 SCOPED_TRACE(StringPrintf("i: %" PRIuS, i)); |
| 99 EXPECT_FORM_FIELD_EQUALS(expected, fields[i]); | 96 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]); |
| 100 } | 97 } |
| 101 } | 98 } |
| 102 | 99 |
| 103 void ExpectJohnSmithLabels(const char* html) { | 100 void ExpectJohnSmithLabels(const char* html) { |
| 104 std::vector<string16> labels, names, values; | 101 std::vector<string16> labels, names, values; |
| 105 | 102 |
| 106 labels.push_back(ASCIIToUTF16("First name:")); | 103 labels.push_back(ASCIIToUTF16("First name:")); |
| 107 names.push_back(ASCIIToUTF16("firstname")); | 104 names.push_back(ASCIIToUTF16("firstname")); |
| 108 values.push_back(ASCIIToUTF16("John")); | 105 values.push_back(ASCIIToUTF16("John")); |
| 109 | 106 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 124 | 121 |
| 125 // We should be able to extract a normal text field. | 122 // We should be able to extract a normal text field. |
| 126 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { | 123 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { |
| 127 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 124 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); |
| 128 | 125 |
| 129 WebFrame* frame = GetMainFrame(); | 126 WebFrame* frame = GetMainFrame(); |
| 130 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 127 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 131 | 128 |
| 132 WebElement web_element = frame->document().getElementById("element"); | 129 WebElement web_element = frame->document().getElementById("element"); |
| 133 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 130 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 134 FormField result1; | 131 FormFieldData result1; |
| 135 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 132 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); |
| 136 | 133 |
| 137 FormField expected; | 134 FormFieldData expected; |
| 138 expected.form_control_type = ASCIIToUTF16("text"); | 135 expected.form_control_type = ASCIIToUTF16("text"); |
| 139 expected.max_length = WebInputElement::defaultMaxLength(); | 136 expected.max_length = WebInputElement::defaultMaxLength(); |
| 140 | 137 |
| 141 expected.name = ASCIIToUTF16("element"); | 138 expected.name = ASCIIToUTF16("element"); |
| 142 expected.value = string16(); | 139 expected.value = string16(); |
| 143 EXPECT_FORM_FIELD_EQUALS(expected, result1); | 140 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
| 144 | 141 |
| 145 FormField result2; | 142 FormFieldData result2; |
| 146 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); | 143 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); |
| 147 | 144 |
| 148 expected.name = ASCIIToUTF16("element"); | 145 expected.name = ASCIIToUTF16("element"); |
| 149 expected.value = ASCIIToUTF16("value"); | 146 expected.value = ASCIIToUTF16("value"); |
| 150 EXPECT_FORM_FIELD_EQUALS(expected, result2); | 147 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
| 151 } | 148 } |
| 152 | 149 |
| 153 // We should be able to extract a text field with autocomplete="off". | 150 // We should be able to extract a text field with autocomplete="off". |
| 154 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { | 151 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { |
| 155 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 152 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
| 156 " autocomplete=\"off\"/>"); | 153 " autocomplete=\"off\"/>"); |
| 157 | 154 |
| 158 WebFrame* frame = GetMainFrame(); | 155 WebFrame* frame = GetMainFrame(); |
| 159 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 156 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 160 | 157 |
| 161 WebElement web_element = frame->document().getElementById("element"); | 158 WebElement web_element = frame->document().getElementById("element"); |
| 162 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 159 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 163 FormField result; | 160 FormFieldData result; |
| 164 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 161 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 165 | 162 |
| 166 FormField expected; | 163 FormFieldData expected; |
| 167 expected.name = ASCIIToUTF16("element"); | 164 expected.name = ASCIIToUTF16("element"); |
| 168 expected.value = ASCIIToUTF16("value"); | 165 expected.value = ASCIIToUTF16("value"); |
| 169 expected.form_control_type = ASCIIToUTF16("text"); | 166 expected.form_control_type = ASCIIToUTF16("text"); |
| 170 expected.max_length = WebInputElement::defaultMaxLength(); | 167 expected.max_length = WebInputElement::defaultMaxLength(); |
| 171 EXPECT_FORM_FIELD_EQUALS(expected, result); | 168 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 172 } | 169 } |
| 173 | 170 |
| 174 // We should be able to extract a text field with maxlength specified. | 171 // We should be able to extract a text field with maxlength specified. |
| 175 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { | 172 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { |
| 176 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" | 173 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"" |
| 177 " maxlength=\"5\"/>"); | 174 " maxlength=\"5\"/>"); |
| 178 | 175 |
| 179 WebFrame* frame = GetMainFrame(); | 176 WebFrame* frame = GetMainFrame(); |
| 180 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 177 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 181 | 178 |
| 182 WebElement web_element = frame->document().getElementById("element"); | 179 WebElement web_element = frame->document().getElementById("element"); |
| 183 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 180 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 184 FormField result; | 181 FormFieldData result; |
| 185 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 182 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 186 | 183 |
| 187 FormField expected; | 184 FormFieldData expected; |
| 188 expected.name = ASCIIToUTF16("element"); | 185 expected.name = ASCIIToUTF16("element"); |
| 189 expected.value = ASCIIToUTF16("value"); | 186 expected.value = ASCIIToUTF16("value"); |
| 190 expected.form_control_type = ASCIIToUTF16("text"); | 187 expected.form_control_type = ASCIIToUTF16("text"); |
| 191 expected.max_length = 5; | 188 expected.max_length = 5; |
| 192 EXPECT_FORM_FIELD_EQUALS(expected, result); | 189 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 193 } | 190 } |
| 194 | 191 |
| 195 // We should be able to extract a text field that has been autofilled. | 192 // We should be able to extract a text field that has been autofilled. |
| 196 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { | 193 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { |
| 197 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); | 194 LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>"); |
| 198 | 195 |
| 199 WebFrame* frame = GetMainFrame(); | 196 WebFrame* frame = GetMainFrame(); |
| 200 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 197 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 201 | 198 |
| 202 WebElement web_element = frame->document().getElementById("element"); | 199 WebElement web_element = frame->document().getElementById("element"); |
| 203 WebInputElement element = web_element.to<WebInputElement>(); | 200 WebInputElement element = web_element.to<WebInputElement>(); |
| 204 element.setAutofilled(true); | 201 element.setAutofilled(true); |
| 205 FormField result; | 202 FormFieldData result; |
| 206 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 203 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 207 | 204 |
| 208 FormField expected; | 205 FormFieldData expected; |
| 209 expected.name = ASCIIToUTF16("element"); | 206 expected.name = ASCIIToUTF16("element"); |
| 210 expected.value = ASCIIToUTF16("value"); | 207 expected.value = ASCIIToUTF16("value"); |
| 211 expected.form_control_type = ASCIIToUTF16("text"); | 208 expected.form_control_type = ASCIIToUTF16("text"); |
| 212 expected.max_length = WebInputElement::defaultMaxLength(); | 209 expected.max_length = WebInputElement::defaultMaxLength(); |
| 213 expected.is_autofilled = true; | 210 expected.is_autofilled = true; |
| 214 EXPECT_FORM_FIELD_EQUALS(expected, result); | 211 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 215 } | 212 } |
| 216 | 213 |
| 217 // We should be able to extract a <select> field. | 214 // We should be able to extract a <select> field. |
| 218 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 215 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
| 219 LoadHTML("<SELECT id=\"element\"/>" | 216 LoadHTML("<SELECT id=\"element\"/>" |
| 220 " <OPTION value=\"CA\">California</OPTION>" | 217 " <OPTION value=\"CA\">California</OPTION>" |
| 221 " <OPTION value=\"TX\">Texas</OPTION>" | 218 " <OPTION value=\"TX\">Texas</OPTION>" |
| 222 "</SELECT>"); | 219 "</SELECT>"); |
| 223 | 220 |
| 224 WebFrame* frame = GetMainFrame(); | 221 WebFrame* frame = GetMainFrame(); |
| 225 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 222 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 226 | 223 |
| 227 WebElement web_element = frame->document().getElementById("element"); | 224 WebElement web_element = frame->document().getElementById("element"); |
| 228 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 225 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 229 FormField result1; | 226 FormFieldData result1; |
| 230 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); | 227 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); |
| 231 | 228 |
| 232 FormField expected; | 229 FormFieldData expected; |
| 233 expected.name = ASCIIToUTF16("element"); | 230 expected.name = ASCIIToUTF16("element"); |
| 234 expected.max_length = 0; | 231 expected.max_length = 0; |
| 235 expected.form_control_type = ASCIIToUTF16("select-one"); | 232 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 236 | 233 |
| 237 expected.value = ASCIIToUTF16("CA"); | 234 expected.value = ASCIIToUTF16("CA"); |
| 238 EXPECT_FORM_FIELD_EQUALS(expected, result1); | 235 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
| 239 | 236 |
| 240 FormField result2; | 237 FormFieldData result2; |
| 241 WebFormControlElementToFormField( | 238 WebFormControlElementToFormField( |
| 242 element, | 239 element, |
| 243 static_cast<autofill::ExtractMask>(autofill::EXTRACT_VALUE | | 240 static_cast<autofill::ExtractMask>(autofill::EXTRACT_VALUE | |
| 244 autofill::EXTRACT_OPTION_TEXT), | 241 autofill::EXTRACT_OPTION_TEXT), |
| 245 &result2); | 242 &result2); |
| 246 expected.value = ASCIIToUTF16("California"); | 243 expected.value = ASCIIToUTF16("California"); |
| 247 EXPECT_FORM_FIELD_EQUALS(expected, result2); | 244 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
| 248 | 245 |
| 249 FormField result3; | 246 FormFieldData result3; |
| 250 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, | 247 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, |
| 251 &result3); | 248 &result3); |
| 252 expected.value = string16(); | 249 expected.value = string16(); |
| 253 EXPECT_FORM_FIELD_EQUALS(expected, result3); | 250 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3); |
| 254 | 251 |
| 255 ASSERT_EQ(2U, result3.option_values.size()); | 252 ASSERT_EQ(2U, result3.option_values.size()); |
| 256 ASSERT_EQ(2U, result3.option_contents.size()); | 253 ASSERT_EQ(2U, result3.option_contents.size()); |
| 257 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); | 254 EXPECT_EQ(ASCIIToUTF16("CA"), result3.option_values[0]); |
| 258 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); | 255 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); |
| 259 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); | 256 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); |
| 260 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); | 257 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); |
| 261 } | 258 } |
| 262 | 259 |
| 263 // We should not extract the value for non-text and non-select fields. | 260 // We should not extract the value for non-text and non-select fields. |
| 264 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { | 261 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { |
| 265 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 262 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 266 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" | 263 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" |
| 267 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" | 264 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" |
| 268 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" | 265 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" |
| 269 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" | 266 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" |
| 270 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" | 267 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" |
| 271 "</FORM>"); | 268 "</FORM>"); |
| 272 | 269 |
| 273 WebFrame* frame = GetMainFrame(); | 270 WebFrame* frame = GetMainFrame(); |
| 274 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 271 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 275 | 272 |
| 276 WebElement web_element = frame->document().getElementById("hidden"); | 273 WebElement web_element = frame->document().getElementById("hidden"); |
| 277 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 274 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 278 FormField result; | 275 FormFieldData result; |
| 279 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 276 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 280 | 277 |
| 281 FormField expected; | 278 FormFieldData expected; |
| 282 expected.max_length = 0; | 279 expected.max_length = 0; |
| 283 | 280 |
| 284 expected.name = ASCIIToUTF16("hidden"); | 281 expected.name = ASCIIToUTF16("hidden"); |
| 285 expected.form_control_type = ASCIIToUTF16("hidden"); | 282 expected.form_control_type = ASCIIToUTF16("hidden"); |
| 286 EXPECT_FORM_FIELD_EQUALS(expected, result); | 283 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 287 | 284 |
| 288 web_element = frame->document().getElementById("password"); | 285 web_element = frame->document().getElementById("password"); |
| 289 element = web_element.to<WebFormControlElement>(); | 286 element = web_element.to<WebFormControlElement>(); |
| 290 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 287 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 291 expected.name = ASCIIToUTF16("password"); | 288 expected.name = ASCIIToUTF16("password"); |
| 292 expected.form_control_type = ASCIIToUTF16("password"); | 289 expected.form_control_type = ASCIIToUTF16("password"); |
| 293 EXPECT_FORM_FIELD_EQUALS(expected, result); | 290 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 294 | 291 |
| 295 web_element = frame->document().getElementById("checkbox"); | 292 web_element = frame->document().getElementById("checkbox"); |
| 296 element = web_element.to<WebFormControlElement>(); | 293 element = web_element.to<WebFormControlElement>(); |
| 297 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 294 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 298 expected.name = ASCIIToUTF16("checkbox"); | 295 expected.name = ASCIIToUTF16("checkbox"); |
| 299 expected.form_control_type = ASCIIToUTF16("checkbox"); | 296 expected.form_control_type = ASCIIToUTF16("checkbox"); |
| 300 EXPECT_FORM_FIELD_EQUALS(expected, result); | 297 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 301 | 298 |
| 302 web_element = frame->document().getElementById("radio"); | 299 web_element = frame->document().getElementById("radio"); |
| 303 element = web_element.to<WebFormControlElement>(); | 300 element = web_element.to<WebFormControlElement>(); |
| 304 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 301 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 305 expected.name = ASCIIToUTF16("radio"); | 302 expected.name = ASCIIToUTF16("radio"); |
| 306 expected.form_control_type = ASCIIToUTF16("radio"); | 303 expected.form_control_type = ASCIIToUTF16("radio"); |
| 307 EXPECT_FORM_FIELD_EQUALS(expected, result); | 304 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 308 | 305 |
| 309 | 306 |
| 310 web_element = frame->document().getElementById("submit"); | 307 web_element = frame->document().getElementById("submit"); |
| 311 element = web_element.to<WebFormControlElement>(); | 308 element = web_element.to<WebFormControlElement>(); |
| 312 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 309 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 313 expected.name = ASCIIToUTF16("submit"); | 310 expected.name = ASCIIToUTF16("submit"); |
| 314 expected.form_control_type = ASCIIToUTF16("submit"); | 311 expected.form_control_type = ASCIIToUTF16("submit"); |
| 315 EXPECT_FORM_FIELD_EQUALS(expected, result); | 312 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 316 } | 313 } |
| 317 | 314 |
| 318 // We should be able to extract the autocompletetype attribute. | 315 // We should be able to extract the autocompletetype attribute. |
| 319 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { | 316 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { |
| 320 std::string html = | 317 std::string html = |
| 321 "<INPUT type=\"text\" id=\"absent\"/>" | 318 "<INPUT type=\"text\" id=\"absent\"/>" |
| 322 "<INPUT type=\"text\" id=\"empty\" x-autocompletetype=\"\"/>" | 319 "<INPUT type=\"text\" id=\"empty\" x-autocompletetype=\"\"/>" |
| 323 "<INPUT type=\"text\" id=\"whitespace\" x-autocompletetype=\" \"/>" | 320 "<INPUT type=\"text\" id=\"whitespace\" x-autocompletetype=\" \"/>" |
| 324 "<INPUT type=\"text\" id=\"regular\" x-autocompletetype=\"email\"/>" | 321 "<INPUT type=\"text\" id=\"regular\" x-autocompletetype=\"email\"/>" |
| 325 "<INPUT type=\"text\" id=\"multi-valued\" " | 322 "<INPUT type=\"text\" id=\"multi-valued\" " |
| 326 " x-autocompletetype=\"x-confirm-email email\"/>" | 323 " x-autocompletetype=\"x-confirm-email email\"/>" |
| 327 "<INPUT type=\"text\" id=\"unprefixed\" autocompletetype=\"email\"/>" | 324 "<INPUT type=\"text\" id=\"unprefixed\" autocompletetype=\"email\"/>" |
| 328 "<SELECT id=\"select\" x-autocompletetype=\"state\"/>" | 325 "<SELECT id=\"select\" x-autocompletetype=\"state\"/>" |
| 329 " <OPTION value=\"CA\">California</OPTION>" | 326 " <OPTION value=\"CA\">California</OPTION>" |
| 330 " <OPTION value=\"TX\">Texas</OPTION>" | 327 " <OPTION value=\"TX\">Texas</OPTION>" |
| 331 "</SELECT>"; | 328 "</SELECT>"; |
| 332 html += | 329 html += |
| 333 "<INPUT type=\"text\" id=\"malicious\" x-autocompletetype=\"" + | 330 "<INPUT type=\"text\" id=\"malicious\" x-autocompletetype=\"" + |
| 334 std::string(10000, 'x') + "\"/>"; | 331 std::string(10000, 'x') + "\"/>"; |
| 335 LoadHTML(html.c_str()); | 332 LoadHTML(html.c_str()); |
| 336 | 333 |
| 337 WebFrame* frame = GetMainFrame(); | 334 WebFrame* frame = GetMainFrame(); |
| 338 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 335 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 339 | 336 |
| 340 // An absent attribute is equivalent to an empty one. | 337 // An absent attribute is equivalent to an empty one. |
| 341 WebElement web_element = frame->document().getElementById("absent"); | 338 WebElement web_element = frame->document().getElementById("absent"); |
| 342 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 339 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 343 FormField result1; | 340 FormFieldData result1; |
| 344 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 341 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); |
| 345 | 342 |
| 346 FormField expected; | 343 FormFieldData expected; |
| 347 expected.name = ASCIIToUTF16("absent"); | 344 expected.name = ASCIIToUTF16("absent"); |
| 348 expected.form_control_type = ASCIIToUTF16("text"); | 345 expected.form_control_type = ASCIIToUTF16("text"); |
| 349 expected.autocomplete_type = string16(); | 346 expected.autocomplete_type = string16(); |
| 350 expected.max_length = WebInputElement::defaultMaxLength(); | 347 expected.max_length = WebInputElement::defaultMaxLength(); |
| 351 EXPECT_FORM_FIELD_EQUALS(expected, result1); | 348 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
| 352 | 349 |
| 353 web_element = frame->document().getElementById("empty"); | 350 web_element = frame->document().getElementById("empty"); |
| 354 element = web_element.to<WebFormControlElement>(); | 351 element = web_element.to<WebFormControlElement>(); |
| 355 FormField result2; | 352 FormFieldData result2; |
| 356 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result2); | 353 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result2); |
| 357 expected.name = ASCIIToUTF16("empty"); | 354 expected.name = ASCIIToUTF16("empty"); |
| 358 expected.form_control_type = ASCIIToUTF16("text"); | 355 expected.form_control_type = ASCIIToUTF16("text"); |
| 359 expected.autocomplete_type = string16(); | 356 expected.autocomplete_type = string16(); |
| 360 expected.max_length = WebInputElement::defaultMaxLength(); | 357 expected.max_length = WebInputElement::defaultMaxLength(); |
| 361 EXPECT_FORM_FIELD_EQUALS(expected, result2); | 358 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
| 362 | 359 |
| 363 // The renderer should trim whitespace. | 360 // The renderer should trim whitespace. |
| 364 web_element = frame->document().getElementById("whitespace"); | 361 web_element = frame->document().getElementById("whitespace"); |
| 365 element = web_element.to<WebFormControlElement>(); | 362 element = web_element.to<WebFormControlElement>(); |
| 366 FormField result3; | 363 FormFieldData result3; |
| 367 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result3); | 364 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result3); |
| 368 expected.name = ASCIIToUTF16("whitespace"); | 365 expected.name = ASCIIToUTF16("whitespace"); |
| 369 expected.form_control_type = ASCIIToUTF16("text"); | 366 expected.form_control_type = ASCIIToUTF16("text"); |
| 370 expected.autocomplete_type = string16(); | 367 expected.autocomplete_type = string16(); |
| 371 expected.max_length = WebInputElement::defaultMaxLength(); | 368 expected.max_length = WebInputElement::defaultMaxLength(); |
| 372 EXPECT_FORM_FIELD_EQUALS(expected, result3); | 369 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result3); |
| 373 | 370 |
| 374 // Common case: exactly one type specified. | 371 // Common case: exactly one type specified. |
| 375 web_element = frame->document().getElementById("regular"); | 372 web_element = frame->document().getElementById("regular"); |
| 376 element = web_element.to<WebFormControlElement>(); | 373 element = web_element.to<WebFormControlElement>(); |
| 377 FormField result4; | 374 FormFieldData result4; |
| 378 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result4); | 375 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result4); |
| 379 expected.name = ASCIIToUTF16("regular"); | 376 expected.name = ASCIIToUTF16("regular"); |
| 380 expected.form_control_type = ASCIIToUTF16("text"); | 377 expected.form_control_type = ASCIIToUTF16("text"); |
| 381 expected.autocomplete_type = ASCIIToUTF16("email"); | 378 expected.autocomplete_type = ASCIIToUTF16("email"); |
| 382 expected.max_length = WebInputElement::defaultMaxLength(); | 379 expected.max_length = WebInputElement::defaultMaxLength(); |
| 383 EXPECT_FORM_FIELD_EQUALS(expected, result4); | 380 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result4); |
| 384 | 381 |
| 385 // Verify that we correctly extract fallback types as well. | 382 // Verify that we correctly extract fallback types as well. |
| 386 web_element = frame->document().getElementById("multi-valued"); | 383 web_element = frame->document().getElementById("multi-valued"); |
| 387 element = web_element.to<WebFormControlElement>(); | 384 element = web_element.to<WebFormControlElement>(); |
| 388 FormField result5; | 385 FormFieldData result5; |
| 389 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result5); | 386 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result5); |
| 390 expected.name = ASCIIToUTF16("multi-valued"); | 387 expected.name = ASCIIToUTF16("multi-valued"); |
| 391 expected.form_control_type = ASCIIToUTF16("text"); | 388 expected.form_control_type = ASCIIToUTF16("text"); |
| 392 expected.autocomplete_type = ASCIIToUTF16("x-confirm-email email"); | 389 expected.autocomplete_type = ASCIIToUTF16("x-confirm-email email"); |
| 393 expected.max_length = WebInputElement::defaultMaxLength(); | 390 expected.max_length = WebInputElement::defaultMaxLength(); |
| 394 EXPECT_FORM_FIELD_EQUALS(expected, result5); | 391 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result5); |
| 395 | 392 |
| 396 // The attribute is not yet part of the HTML standard, so we only recognize | 393 // The attribute is not yet part of the HTML standard, so we only recognize |
| 397 // the prefixed version -- 'x-autocompletetype' -- and not the unprefixed one. | 394 // the prefixed version -- 'x-autocompletetype' -- and not the unprefixed one. |
| 398 web_element = frame->document().getElementById("unprefixed"); | 395 web_element = frame->document().getElementById("unprefixed"); |
| 399 element = web_element.to<WebFormControlElement>(); | 396 element = web_element.to<WebFormControlElement>(); |
| 400 FormField result6; | 397 FormFieldData result6; |
| 401 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result6); | 398 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result6); |
| 402 expected.name = ASCIIToUTF16("unprefixed"); | 399 expected.name = ASCIIToUTF16("unprefixed"); |
| 403 expected.form_control_type = ASCIIToUTF16("text"); | 400 expected.form_control_type = ASCIIToUTF16("text"); |
| 404 expected.autocomplete_type = string16(); | 401 expected.autocomplete_type = string16(); |
| 405 expected.max_length = WebInputElement::defaultMaxLength(); | 402 expected.max_length = WebInputElement::defaultMaxLength(); |
| 406 EXPECT_FORM_FIELD_EQUALS(expected, result6); | 403 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result6); |
| 407 | 404 |
| 408 // <select> elements should behave no differently from text fields here. | 405 // <select> elements should behave no differently from text fields here. |
| 409 web_element = frame->document().getElementById("select"); | 406 web_element = frame->document().getElementById("select"); |
| 410 element = web_element.to<WebFormControlElement>(); | 407 element = web_element.to<WebFormControlElement>(); |
| 411 FormField result7; | 408 FormFieldData result7; |
| 412 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result7); | 409 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result7); |
| 413 expected.name = ASCIIToUTF16("select"); | 410 expected.name = ASCIIToUTF16("select"); |
| 414 expected.form_control_type = ASCIIToUTF16("select-one"); | 411 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 415 expected.autocomplete_type = ASCIIToUTF16("state"); | 412 expected.autocomplete_type = ASCIIToUTF16("state"); |
| 416 expected.max_length = 0; | 413 expected.max_length = 0; |
| 417 EXPECT_FORM_FIELD_EQUALS(expected, result7); | 414 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result7); |
| 418 | 415 |
| 419 // Very long attribute values should be replaced by a default string, to | 416 // Very long attribute values should be replaced by a default string, to |
| 420 // prevent malicious websites from DOSing the browser process. | 417 // prevent malicious websites from DOSing the browser process. |
| 421 web_element = frame->document().getElementById("malicious"); | 418 web_element = frame->document().getElementById("malicious"); |
| 422 element = web_element.to<WebFormControlElement>(); | 419 element = web_element.to<WebFormControlElement>(); |
| 423 FormField result8; | 420 FormFieldData result8; |
| 424 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result8); | 421 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result8); |
| 425 expected.name = ASCIIToUTF16("malicious"); | 422 expected.name = ASCIIToUTF16("malicious"); |
| 426 expected.form_control_type = ASCIIToUTF16("text"); | 423 expected.form_control_type = ASCIIToUTF16("text"); |
| 427 expected.autocomplete_type = ASCIIToUTF16("x-max-data-length-exceeded"); | 424 expected.autocomplete_type = ASCIIToUTF16("x-max-data-length-exceeded"); |
| 428 expected.max_length = WebInputElement::defaultMaxLength(); | 425 expected.max_length = WebInputElement::defaultMaxLength(); |
| 429 EXPECT_FORM_FIELD_EQUALS(expected, result8); | 426 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result8); |
| 430 } | 427 } |
| 431 | 428 |
| 432 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 429 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
| 433 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 430 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 434 " <LABEL for=\"firstname\">First name:</LABEL>" | 431 " <LABEL for=\"firstname\">First name:</LABEL>" |
| 435 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 432 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 436 " <LABEL for=\"lastname\">Last name:</LABEL>" | 433 " <LABEL for=\"lastname\">Last name:</LABEL>" |
| 437 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 434 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 438 " <LABEL for=\"state\">State:</LABEL>" | 435 " <LABEL for=\"state\">State:</LABEL>" |
| 439 " <SELECT id=\"state\"/>" | 436 " <SELECT id=\"state\"/>" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 452 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 449 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 453 | 450 |
| 454 WebVector<WebFormElement> forms; | 451 WebVector<WebFormElement> forms; |
| 455 frame->document().forms(forms); | 452 frame->document().forms(forms); |
| 456 ASSERT_EQ(1U, forms.size()); | 453 ASSERT_EQ(1U, forms.size()); |
| 457 | 454 |
| 458 WebElement element = frame->document().getElementById("firstname"); | 455 WebElement element = frame->document().getElementById("firstname"); |
| 459 WebInputElement input_element = element.to<WebInputElement>(); | 456 WebInputElement input_element = element.to<WebInputElement>(); |
| 460 | 457 |
| 461 FormData form; | 458 FormData form; |
| 462 FormField field; | 459 FormFieldData field; |
| 463 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 460 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 464 input_element, | 461 input_element, |
| 465 autofill::REQUIRE_NONE, | 462 autofill::REQUIRE_NONE, |
| 466 autofill::EXTRACT_VALUE, | 463 autofill::EXTRACT_VALUE, |
| 467 &form, | 464 &form, |
| 468 &field)); | 465 &field)); |
| 469 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 466 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 470 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 467 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 471 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 468 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 472 | 469 |
| 473 const std::vector<FormField>& fields = form.fields; | 470 const std::vector<FormFieldData>& fields = form.fields; |
| 474 ASSERT_EQ(3U, fields.size()); | 471 ASSERT_EQ(3U, fields.size()); |
| 475 | 472 |
| 476 FormField expected; | 473 FormFieldData expected; |
| 477 expected.name = ASCIIToUTF16("firstname"); | 474 expected.name = ASCIIToUTF16("firstname"); |
| 478 expected.value = ASCIIToUTF16("John"); | 475 expected.value = ASCIIToUTF16("John"); |
| 479 expected.label = ASCIIToUTF16("First name:"); | 476 expected.label = ASCIIToUTF16("First name:"); |
| 480 expected.form_control_type = ASCIIToUTF16("text"); | 477 expected.form_control_type = ASCIIToUTF16("text"); |
| 481 expected.max_length = WebInputElement::defaultMaxLength(); | 478 expected.max_length = WebInputElement::defaultMaxLength(); |
| 482 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 479 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 483 | 480 |
| 484 expected.name = ASCIIToUTF16("lastname"); | 481 expected.name = ASCIIToUTF16("lastname"); |
| 485 expected.value = ASCIIToUTF16("Smith"); | 482 expected.value = ASCIIToUTF16("Smith"); |
| 486 expected.label = ASCIIToUTF16("Last name:"); | 483 expected.label = ASCIIToUTF16("Last name:"); |
| 487 expected.form_control_type = ASCIIToUTF16("text"); | 484 expected.form_control_type = ASCIIToUTF16("text"); |
| 488 expected.max_length = WebInputElement::defaultMaxLength(); | 485 expected.max_length = WebInputElement::defaultMaxLength(); |
| 489 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 486 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 490 | 487 |
| 491 expected.name = ASCIIToUTF16("state"); | 488 expected.name = ASCIIToUTF16("state"); |
| 492 expected.value = ASCIIToUTF16("CA"); | 489 expected.value = ASCIIToUTF16("CA"); |
| 493 expected.label = ASCIIToUTF16("State:"); | 490 expected.label = ASCIIToUTF16("State:"); |
| 494 expected.form_control_type = ASCIIToUTF16("select-one"); | 491 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 495 expected.max_length = 0; | 492 expected.max_length = 0; |
| 496 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 493 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 497 } | 494 } |
| 498 | 495 |
| 499 // We should not be able to serialize a form with too many fillable fields. | 496 // We should not be able to serialize a form with too many fillable fields. |
| 500 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { | 497 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { |
| 501 std::string html = | 498 std::string html = |
| 502 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"; | 499 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"; |
| 503 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { | 500 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { |
| 504 html += "<INPUT type=\"text\"/>"; | 501 html += "<INPUT type=\"text\"/>"; |
| 505 } | 502 } |
| 506 html += "</FORM>"; | 503 html += "</FORM>"; |
| 507 LoadHTML(html.c_str()); | 504 LoadHTML(html.c_str()); |
| 508 | 505 |
| 509 WebFrame* frame = GetMainFrame(); | 506 WebFrame* frame = GetMainFrame(); |
| 510 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 507 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 511 | 508 |
| 512 WebVector<WebFormElement> forms; | 509 WebVector<WebFormElement> forms; |
| 513 frame->document().forms(forms); | 510 frame->document().forms(forms); |
| 514 ASSERT_EQ(1U, forms.size()); | 511 ASSERT_EQ(1U, forms.size()); |
| 515 | 512 |
| 516 WebElement element = frame->document().getElementById("firstname"); | 513 WebElement element = frame->document().getElementById("firstname"); |
| 517 WebInputElement input_element = element.to<WebInputElement>(); | 514 WebInputElement input_element = element.to<WebInputElement>(); |
| 518 | 515 |
| 519 FormData form; | 516 FormData form; |
| 520 FormField field; | 517 FormFieldData field; |
| 521 EXPECT_FALSE(WebFormElementToFormData(forms[0], | 518 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
| 522 input_element, | 519 input_element, |
| 523 autofill::REQUIRE_NONE, | 520 autofill::REQUIRE_NONE, |
| 524 autofill::EXTRACT_VALUE, | 521 autofill::EXTRACT_VALUE, |
| 525 &form, | 522 &form, |
| 526 &field)); | 523 &field)); |
| 527 } | 524 } |
| 528 | 525 |
| 529 TEST_F(FormAutofillTest, ExtractForms) { | 526 TEST_F(FormAutofillTest, ExtractForms) { |
| 530 ExpectJohnSmithLabels( | 527 ExpectJohnSmithLabels( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 557 std::vector<FormData> forms; | 554 std::vector<FormData> forms; |
| 558 form_cache.ExtractForms(*web_frame, &forms); | 555 form_cache.ExtractForms(*web_frame, &forms); |
| 559 ASSERT_EQ(2U, forms.size()); | 556 ASSERT_EQ(2U, forms.size()); |
| 560 | 557 |
| 561 // First form. | 558 // First form. |
| 562 const FormData& form = forms[0]; | 559 const FormData& form = forms[0]; |
| 563 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 560 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 564 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 561 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 565 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 562 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 566 | 563 |
| 567 const std::vector<FormField>& fields = form.fields; | 564 const std::vector<FormFieldData>& fields = form.fields; |
| 568 ASSERT_EQ(3U, fields.size()); | 565 ASSERT_EQ(3U, fields.size()); |
| 569 | 566 |
| 570 FormField expected; | 567 FormFieldData expected; |
| 571 expected.form_control_type = ASCIIToUTF16("text"); | 568 expected.form_control_type = ASCIIToUTF16("text"); |
| 572 expected.max_length = WebInputElement::defaultMaxLength(); | 569 expected.max_length = WebInputElement::defaultMaxLength(); |
| 573 | 570 |
| 574 expected.name = ASCIIToUTF16("firstname"); | 571 expected.name = ASCIIToUTF16("firstname"); |
| 575 expected.value = ASCIIToUTF16("John"); | 572 expected.value = ASCIIToUTF16("John"); |
| 576 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 573 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 577 | 574 |
| 578 expected.name = ASCIIToUTF16("lastname"); | 575 expected.name = ASCIIToUTF16("lastname"); |
| 579 expected.value = ASCIIToUTF16("Smith"); | 576 expected.value = ASCIIToUTF16("Smith"); |
| 580 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 577 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 581 | 578 |
| 582 expected.name = ASCIIToUTF16("email"); | 579 expected.name = ASCIIToUTF16("email"); |
| 583 expected.value = ASCIIToUTF16("john@example.com"); | 580 expected.value = ASCIIToUTF16("john@example.com"); |
| 584 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 581 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 585 | 582 |
| 586 // Second form. | 583 // Second form. |
| 587 const FormData& form2 = forms[1]; | 584 const FormData& form2 = forms[1]; |
| 588 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); | 585 EXPECT_EQ(ASCIIToUTF16("TestForm2"), form2.name); |
| 589 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 586 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 590 EXPECT_EQ(GURL("http://zoo.com"), form2.action); | 587 EXPECT_EQ(GURL("http://zoo.com"), form2.action); |
| 591 | 588 |
| 592 const std::vector<FormField>& fields2 = form2.fields; | 589 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 593 ASSERT_EQ(3U, fields2.size()); | 590 ASSERT_EQ(3U, fields2.size()); |
| 594 | 591 |
| 595 expected.name = ASCIIToUTF16("firstname"); | 592 expected.name = ASCIIToUTF16("firstname"); |
| 596 expected.value = ASCIIToUTF16("Jack"); | 593 expected.value = ASCIIToUTF16("Jack"); |
| 597 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 594 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 598 | 595 |
| 599 expected.name = ASCIIToUTF16("lastname"); | 596 expected.name = ASCIIToUTF16("lastname"); |
| 600 expected.value = ASCIIToUTF16("Adams"); | 597 expected.value = ASCIIToUTF16("Adams"); |
| 601 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 598 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 602 | 599 |
| 603 expected.name = ASCIIToUTF16("email"); | 600 expected.name = ASCIIToUTF16("email"); |
| 604 expected.value = ASCIIToUTF16("jack@example.com"); | 601 expected.value = ASCIIToUTF16("jack@example.com"); |
| 605 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 602 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 606 } | 603 } |
| 607 | 604 |
| 608 // We should not extract a form if it has too few fillable fields. | 605 // We should not extract a form if it has too few fillable fields. |
| 609 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { | 606 TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { |
| 610 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 607 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 611 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 608 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 612 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 609 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 613 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 610 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 614 "</FORM>"); | 611 "</FORM>"); |
| 615 | 612 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 669 |
| 673 FormData form; | 670 FormData form; |
| 674 EXPECT_TRUE(WebFormElementToFormData( | 671 EXPECT_TRUE(WebFormElementToFormData( |
| 675 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE, | 672 web_form, WebFormControlElement(), autofill::REQUIRE_AUTOCOMPLETE, |
| 676 autofill::EXTRACT_VALUE, &form, NULL)); | 673 autofill::EXTRACT_VALUE, &form, NULL)); |
| 677 | 674 |
| 678 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 675 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 679 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 676 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 680 EXPECT_EQ(GURL("http://abc.com"), form.action); | 677 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 681 | 678 |
| 682 const std::vector<FormField>& fields = form.fields; | 679 const std::vector<FormFieldData>& fields = form.fields; |
| 683 ASSERT_EQ(3U, fields.size()); | 680 ASSERT_EQ(3U, fields.size()); |
| 684 | 681 |
| 685 FormField expected; | 682 FormFieldData expected; |
| 686 expected.form_control_type = ASCIIToUTF16("text"); | 683 expected.form_control_type = ASCIIToUTF16("text"); |
| 687 expected.max_length = WebInputElement::defaultMaxLength(); | 684 expected.max_length = WebInputElement::defaultMaxLength(); |
| 688 | 685 |
| 689 expected.name = ASCIIToUTF16("middlename"); | 686 expected.name = ASCIIToUTF16("middlename"); |
| 690 expected.value = ASCIIToUTF16("Jack"); | 687 expected.value = ASCIIToUTF16("Jack"); |
| 691 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 688 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 692 | 689 |
| 693 expected.name = ASCIIToUTF16("lastname"); | 690 expected.name = ASCIIToUTF16("lastname"); |
| 694 expected.value = ASCIIToUTF16("Smith"); | 691 expected.value = ASCIIToUTF16("Smith"); |
| 695 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 692 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 696 | 693 |
| 697 expected.name = ASCIIToUTF16("email"); | 694 expected.name = ASCIIToUTF16("email"); |
| 698 expected.value = ASCIIToUTF16("john@example.com"); | 695 expected.value = ASCIIToUTF16("john@example.com"); |
| 699 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 696 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 700 } | 697 } |
| 701 } | 698 } |
| 702 | 699 |
| 703 TEST_F(FormAutofillTest, FindForm) { | 700 TEST_F(FormAutofillTest, FindForm) { |
| 704 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 701 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 705 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 702 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 706 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 703 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 707 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"" | 704 " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"" |
| 708 "autocomplete=\"off\" />" | 705 "autocomplete=\"off\" />" |
| 709 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>" | 706 " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>" |
| 710 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 707 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 711 "</FORM>"); | 708 "</FORM>"); |
| 712 | 709 |
| 713 WebFrame* web_frame = GetMainFrame(); | 710 WebFrame* web_frame = GetMainFrame(); |
| 714 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 711 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 715 | 712 |
| 716 FormCache form_cache; | 713 FormCache form_cache; |
| 717 std::vector<FormData> forms; | 714 std::vector<FormData> forms; |
| 718 form_cache.ExtractForms(*web_frame, &forms); | 715 form_cache.ExtractForms(*web_frame, &forms); |
| 719 ASSERT_EQ(1U, forms.size()); | 716 ASSERT_EQ(1U, forms.size()); |
| 720 | 717 |
| 721 // Get the input element we want to find. | 718 // Get the input element we want to find. |
| 722 WebElement element = web_frame->document().getElementById("firstname"); | 719 WebElement element = web_frame->document().getElementById("firstname"); |
| 723 WebInputElement input_element = element.to<WebInputElement>(); | 720 WebInputElement input_element = element.to<WebInputElement>(); |
| 724 | 721 |
| 725 // Find the form and verify it's the correct form. | 722 // Find the form and verify it's the correct form. |
| 726 FormData form; | 723 FormData form; |
| 727 FormField field; | 724 FormFieldData field; |
| 728 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 725 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 729 autofill::REQUIRE_NONE)); | 726 autofill::REQUIRE_NONE)); |
| 730 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 727 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 731 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 728 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 732 EXPECT_EQ(GURL("http://buh.com"), form.action); | 729 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 733 | 730 |
| 734 const std::vector<FormField>& fields = form.fields; | 731 const std::vector<FormFieldData>& fields = form.fields; |
| 735 ASSERT_EQ(4U, fields.size()); | 732 ASSERT_EQ(4U, fields.size()); |
| 736 | 733 |
| 737 FormField expected; | 734 FormFieldData expected; |
| 738 expected.form_control_type = ASCIIToUTF16("text"); | 735 expected.form_control_type = ASCIIToUTF16("text"); |
| 739 expected.max_length = WebInputElement::defaultMaxLength(); | 736 expected.max_length = WebInputElement::defaultMaxLength(); |
| 740 | 737 |
| 741 expected.name = ASCIIToUTF16("firstname"); | 738 expected.name = ASCIIToUTF16("firstname"); |
| 742 expected.value = ASCIIToUTF16("John"); | 739 expected.value = ASCIIToUTF16("John"); |
| 743 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 740 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 744 EXPECT_FORM_FIELD_EQUALS(expected, field); | 741 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 745 | 742 |
| 746 expected.name = ASCIIToUTF16("lastname"); | 743 expected.name = ASCIIToUTF16("lastname"); |
| 747 expected.value = ASCIIToUTF16("Smith"); | 744 expected.value = ASCIIToUTF16("Smith"); |
| 748 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 745 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 749 | 746 |
| 750 expected.name = ASCIIToUTF16("email"); | 747 expected.name = ASCIIToUTF16("email"); |
| 751 expected.value = ASCIIToUTF16("john@example.com"); | 748 expected.value = ASCIIToUTF16("john@example.com"); |
| 752 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 749 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 753 | 750 |
| 754 expected.name = ASCIIToUTF16("phone"); | 751 expected.name = ASCIIToUTF16("phone"); |
| 755 expected.value = ASCIIToUTF16("1.800.555.1234"); | 752 expected.value = ASCIIToUTF16("1.800.555.1234"); |
| 756 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); | 753 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 757 | 754 |
| 758 // Try again, but require autocomplete. | 755 // Try again, but require autocomplete. |
| 759 FormData form2; | 756 FormData form2; |
| 760 FormField field2; | 757 FormFieldData field2; |
| 761 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 758 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
| 762 autofill::REQUIRE_AUTOCOMPLETE)); | 759 autofill::REQUIRE_AUTOCOMPLETE)); |
| 763 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 760 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 764 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 761 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 765 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 762 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 766 | 763 |
| 767 const std::vector<FormField>& fields2 = form2.fields; | 764 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 768 ASSERT_EQ(3U, fields2.size()); | 765 ASSERT_EQ(3U, fields2.size()); |
| 769 | 766 |
| 770 expected.form_control_type = ASCIIToUTF16("text"); | 767 expected.form_control_type = ASCIIToUTF16("text"); |
| 771 expected.max_length = WebInputElement::defaultMaxLength(); | 768 expected.max_length = WebInputElement::defaultMaxLength(); |
| 772 | 769 |
| 773 expected.name = ASCIIToUTF16("firstname"); | 770 expected.name = ASCIIToUTF16("firstname"); |
| 774 expected.value = ASCIIToUTF16("John"); | 771 expected.value = ASCIIToUTF16("John"); |
| 775 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 772 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 776 EXPECT_FORM_FIELD_EQUALS(expected, field); | 773 EXPECT_FORM_FIELD_DATA_EQUALS(expected, field); |
| 777 | 774 |
| 778 expected.name = ASCIIToUTF16("lastname"); | 775 expected.name = ASCIIToUTF16("lastname"); |
| 779 expected.value = ASCIIToUTF16("Smith"); | 776 expected.value = ASCIIToUTF16("Smith"); |
| 780 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 777 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 781 | 778 |
| 782 expected.name = ASCIIToUTF16("phone"); | 779 expected.name = ASCIIToUTF16("phone"); |
| 783 expected.value = ASCIIToUTF16("1.800.555.1234"); | 780 expected.value = ASCIIToUTF16("1.800.555.1234"); |
| 784 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 781 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 785 } | 782 } |
| 786 | 783 |
| 787 TEST_F(FormAutofillTest, FillForm) { | 784 TEST_F(FormAutofillTest, FillForm) { |
| 788 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 785 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 789 " <INPUT type=\"text\" id=\"firstname\"/>" | 786 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 790 " <INPUT type=\"text\" id=\"lastname\"/>" | 787 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 791 " <INPUT type=\"hidden\" id=\"imhidden\"/>" | 788 " <INPUT type=\"hidden\" id=\"imhidden\"/>" |
| 792 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" | 789 " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>" |
| 793 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" | 790 " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>" |
| 794 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" | 791 " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 806 std::vector<FormData> forms; | 803 std::vector<FormData> forms; |
| 807 form_cache.ExtractForms(*web_frame, &forms); | 804 form_cache.ExtractForms(*web_frame, &forms); |
| 808 ASSERT_EQ(1U, forms.size()); | 805 ASSERT_EQ(1U, forms.size()); |
| 809 | 806 |
| 810 // Get the input element we want to find. | 807 // Get the input element we want to find. |
| 811 WebElement element = web_frame->document().getElementById("firstname"); | 808 WebElement element = web_frame->document().getElementById("firstname"); |
| 812 WebInputElement input_element = element.to<WebInputElement>(); | 809 WebInputElement input_element = element.to<WebInputElement>(); |
| 813 | 810 |
| 814 // Find the form that contains the input element. | 811 // Find the form that contains the input element. |
| 815 FormData form; | 812 FormData form; |
| 816 FormField field; | 813 FormFieldData field; |
| 817 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 814 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 818 autofill::REQUIRE_AUTOCOMPLETE)); | 815 autofill::REQUIRE_AUTOCOMPLETE)); |
| 819 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 816 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 820 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 817 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 821 EXPECT_EQ(GURL("http://buh.com"), form.action); | 818 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 822 | 819 |
| 823 const std::vector<FormField>& fields = form.fields; | 820 const std::vector<FormFieldData>& fields = form.fields; |
| 824 ASSERT_EQ(7U, fields.size()); | 821 ASSERT_EQ(7U, fields.size()); |
| 825 | 822 |
| 826 FormField expected; | 823 FormFieldData expected; |
| 827 expected.form_control_type = ASCIIToUTF16("text"); | 824 expected.form_control_type = ASCIIToUTF16("text"); |
| 828 expected.max_length = WebInputElement::defaultMaxLength(); | 825 expected.max_length = WebInputElement::defaultMaxLength(); |
| 829 | 826 |
| 830 expected.name = ASCIIToUTF16("firstname"); | 827 expected.name = ASCIIToUTF16("firstname"); |
| 831 expected.value = string16(); | 828 expected.value = string16(); |
| 832 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 829 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 833 | 830 |
| 834 expected.name = ASCIIToUTF16("lastname"); | 831 expected.name = ASCIIToUTF16("lastname"); |
| 835 expected.value = string16(); | 832 expected.value = string16(); |
| 836 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 833 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 837 | 834 |
| 838 expected.name = ASCIIToUTF16("notempty"); | 835 expected.name = ASCIIToUTF16("notempty"); |
| 839 expected.value = ASCIIToUTF16("Hi"); | 836 expected.value = ASCIIToUTF16("Hi"); |
| 840 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 837 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 841 | 838 |
| 842 expected.name = ASCIIToUTF16("notenabled"); | 839 expected.name = ASCIIToUTF16("notenabled"); |
| 843 expected.value = string16(); | 840 expected.value = string16(); |
| 844 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); | 841 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 845 | 842 |
| 846 expected.name = ASCIIToUTF16("readonly"); | 843 expected.name = ASCIIToUTF16("readonly"); |
| 847 expected.value = string16(); | 844 expected.value = string16(); |
| 848 EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); | 845 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); |
| 849 | 846 |
| 850 expected.name = ASCIIToUTF16("invisible"); | 847 expected.name = ASCIIToUTF16("invisible"); |
| 851 expected.value = string16(); | 848 expected.value = string16(); |
| 852 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); | 849 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
| 853 | 850 |
| 854 expected.name = ASCIIToUTF16("displaynone"); | 851 expected.name = ASCIIToUTF16("displaynone"); |
| 855 expected.value = string16(); | 852 expected.value = string16(); |
| 856 EXPECT_FORM_FIELD_EQUALS(expected, fields[6]); | 853 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[6]); |
| 857 | 854 |
| 858 // Fill the form. | 855 // Fill the form. |
| 859 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 856 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 860 form.fields[1].value = ASCIIToUTF16("Earp"); | 857 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 861 form.fields[2].value = ASCIIToUTF16("Alpha"); | 858 form.fields[2].value = ASCIIToUTF16("Alpha"); |
| 862 form.fields[3].value = ASCIIToUTF16("Beta"); | 859 form.fields[3].value = ASCIIToUTF16("Beta"); |
| 863 form.fields[4].value = ASCIIToUTF16("Gamma"); | 860 form.fields[4].value = ASCIIToUTF16("Gamma"); |
| 864 form.fields[5].value = ASCIIToUTF16("Delta"); | 861 form.fields[5].value = ASCIIToUTF16("Delta"); |
| 865 form.fields[6].value = ASCIIToUTF16("Epsilon"); | 862 form.fields[6].value = ASCIIToUTF16("Epsilon"); |
| 866 FillForm(form, input_element); | 863 FillForm(form, input_element); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 std::vector<FormData> forms; | 930 std::vector<FormData> forms; |
| 934 form_cache.ExtractForms(*web_frame, &forms); | 931 form_cache.ExtractForms(*web_frame, &forms); |
| 935 ASSERT_EQ(1U, forms.size()); | 932 ASSERT_EQ(1U, forms.size()); |
| 936 | 933 |
| 937 // Get the input element we want to find. | 934 // Get the input element we want to find. |
| 938 WebElement element = web_frame->document().getElementById("firstname"); | 935 WebElement element = web_frame->document().getElementById("firstname"); |
| 939 WebInputElement input_element = element.to<WebInputElement>(); | 936 WebInputElement input_element = element.to<WebInputElement>(); |
| 940 | 937 |
| 941 // Find the form that contains the input element. | 938 // Find the form that contains the input element. |
| 942 FormData form; | 939 FormData form; |
| 943 FormField field; | 940 FormFieldData field; |
| 944 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 941 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 945 autofill::REQUIRE_AUTOCOMPLETE)); | 942 autofill::REQUIRE_AUTOCOMPLETE)); |
| 946 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 943 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 947 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 944 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 948 EXPECT_EQ(GURL("http://buh.com"), form.action); | 945 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 949 | 946 |
| 950 const std::vector<FormField>& fields = form.fields; | 947 const std::vector<FormFieldData>& fields = form.fields; |
| 951 ASSERT_EQ(4U, fields.size()); | 948 ASSERT_EQ(4U, fields.size()); |
| 952 | 949 |
| 953 FormField expected; | 950 FormFieldData expected; |
| 954 expected.form_control_type = ASCIIToUTF16("text"); | 951 expected.form_control_type = ASCIIToUTF16("text"); |
| 955 expected.max_length = WebInputElement::defaultMaxLength(); | 952 expected.max_length = WebInputElement::defaultMaxLength(); |
| 956 | 953 |
| 957 expected.name = ASCIIToUTF16("firstname"); | 954 expected.name = ASCIIToUTF16("firstname"); |
| 958 expected.value = string16(); | 955 expected.value = string16(); |
| 959 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 956 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 960 | 957 |
| 961 expected.name = ASCIIToUTF16("lastname"); | 958 expected.name = ASCIIToUTF16("lastname"); |
| 962 expected.value = string16(); | 959 expected.value = string16(); |
| 963 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 960 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 964 | 961 |
| 965 expected.name = ASCIIToUTF16("notempty"); | 962 expected.name = ASCIIToUTF16("notempty"); |
| 966 expected.value = ASCIIToUTF16("Hi"); | 963 expected.value = ASCIIToUTF16("Hi"); |
| 967 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 964 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 968 | 965 |
| 969 expected.name = ASCIIToUTF16("notenabled"); | 966 expected.name = ASCIIToUTF16("notenabled"); |
| 970 expected.value = string16(); | 967 expected.value = string16(); |
| 971 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); | 968 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 972 | 969 |
| 973 // Preview the form. | 970 // Preview the form. |
| 974 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 971 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 975 form.fields[1].value = ASCIIToUTF16("Earp"); | 972 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 976 form.fields[2].value = ASCIIToUTF16("Alpha"); | 973 form.fields[2].value = ASCIIToUTF16("Alpha"); |
| 977 form.fields[3].value = ASCIIToUTF16("Beta"); | 974 form.fields[3].value = ASCIIToUTF16("Beta"); |
| 978 PreviewForm(form, input_element); | 975 PreviewForm(form, input_element); |
| 979 | 976 |
| 980 // Verify the previewed elements. | 977 // Verify the previewed elements. |
| 981 WebDocument document = web_frame->document(); | 978 WebDocument document = web_frame->document(); |
| (...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 std::vector<FormData> forms; | 1881 std::vector<FormData> forms; |
| 1885 form_cache.ExtractForms(*web_frame, &forms); | 1882 form_cache.ExtractForms(*web_frame, &forms); |
| 1886 ASSERT_EQ(1U, forms.size()); | 1883 ASSERT_EQ(1U, forms.size()); |
| 1887 | 1884 |
| 1888 // Get the input element we want to find. | 1885 // Get the input element we want to find. |
| 1889 WebElement element = web_frame->document().getElementById("firstname"); | 1886 WebElement element = web_frame->document().getElementById("firstname"); |
| 1890 WebInputElement input_element = element.to<WebInputElement>(); | 1887 WebInputElement input_element = element.to<WebInputElement>(); |
| 1891 | 1888 |
| 1892 // Find the form that contains the input element. | 1889 // Find the form that contains the input element. |
| 1893 FormData form; | 1890 FormData form; |
| 1894 FormField field; | 1891 FormFieldData field; |
| 1895 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 1892 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 1896 autofill::REQUIRE_NONE)); | 1893 autofill::REQUIRE_NONE)); |
| 1897 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1894 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1898 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1895 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1899 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1896 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1900 | 1897 |
| 1901 const std::vector<FormField>& fields = form.fields; | 1898 const std::vector<FormFieldData>& fields = form.fields; |
| 1902 ASSERT_EQ(3U, fields.size()); | 1899 ASSERT_EQ(3U, fields.size()); |
| 1903 | 1900 |
| 1904 FormField expected; | 1901 FormFieldData expected; |
| 1905 expected.form_control_type = ASCIIToUTF16("text"); | 1902 expected.form_control_type = ASCIIToUTF16("text"); |
| 1906 | 1903 |
| 1907 expected.name = ASCIIToUTF16("firstname"); | 1904 expected.name = ASCIIToUTF16("firstname"); |
| 1908 expected.max_length = 5; | 1905 expected.max_length = 5; |
| 1909 expected.is_autofilled = false; | 1906 expected.is_autofilled = false; |
| 1910 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 1907 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 1911 | 1908 |
| 1912 expected.name = ASCIIToUTF16("lastname"); | 1909 expected.name = ASCIIToUTF16("lastname"); |
| 1913 expected.max_length = 7; | 1910 expected.max_length = 7; |
| 1914 expected.is_autofilled = false; | 1911 expected.is_autofilled = false; |
| 1915 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 1912 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 1916 | 1913 |
| 1917 expected.name = ASCIIToUTF16("email"); | 1914 expected.name = ASCIIToUTF16("email"); |
| 1918 expected.max_length = 9; | 1915 expected.max_length = 9; |
| 1919 expected.is_autofilled = false; | 1916 expected.is_autofilled = false; |
| 1920 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 1917 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 1921 | 1918 |
| 1922 // Fill the form. | 1919 // Fill the form. |
| 1923 form.fields[0].value = ASCIIToUTF16("Brother"); | 1920 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 1924 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 1921 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 1925 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 1922 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 1926 FillForm(form, input_element); | 1923 FillForm(form, input_element); |
| 1927 | 1924 |
| 1928 // Find the newly-filled form that contains the input element. | 1925 // Find the newly-filled form that contains the input element. |
| 1929 FormData form2; | 1926 FormData form2; |
| 1930 FormField field2; | 1927 FormFieldData field2; |
| 1931 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 1928 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
| 1932 autofill::REQUIRE_NONE)); | 1929 autofill::REQUIRE_NONE)); |
| 1933 | 1930 |
| 1934 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1931 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 1935 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 1932 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 1936 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1933 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 1937 | 1934 |
| 1938 const std::vector<FormField>& fields2 = form2.fields; | 1935 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 1939 ASSERT_EQ(3U, fields2.size()); | 1936 ASSERT_EQ(3U, fields2.size()); |
| 1940 | 1937 |
| 1941 expected.form_control_type = ASCIIToUTF16("text"); | 1938 expected.form_control_type = ASCIIToUTF16("text"); |
| 1942 | 1939 |
| 1943 expected.name = ASCIIToUTF16("firstname"); | 1940 expected.name = ASCIIToUTF16("firstname"); |
| 1944 expected.value = ASCIIToUTF16("Broth"); | 1941 expected.value = ASCIIToUTF16("Broth"); |
| 1945 expected.max_length = 5; | 1942 expected.max_length = 5; |
| 1946 expected.is_autofilled = true; | 1943 expected.is_autofilled = true; |
| 1947 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 1944 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 1948 | 1945 |
| 1949 expected.name = ASCIIToUTF16("lastname"); | 1946 expected.name = ASCIIToUTF16("lastname"); |
| 1950 expected.value = ASCIIToUTF16("Jonatha"); | 1947 expected.value = ASCIIToUTF16("Jonatha"); |
| 1951 expected.max_length = 7; | 1948 expected.max_length = 7; |
| 1952 expected.is_autofilled = true; | 1949 expected.is_autofilled = true; |
| 1953 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 1950 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 1954 | 1951 |
| 1955 expected.name = ASCIIToUTF16("email"); | 1952 expected.name = ASCIIToUTF16("email"); |
| 1956 expected.value = ASCIIToUTF16("brotherj@"); | 1953 expected.value = ASCIIToUTF16("brotherj@"); |
| 1957 expected.max_length = 9; | 1954 expected.max_length = 9; |
| 1958 expected.is_autofilled = true; | 1955 expected.is_autofilled = true; |
| 1959 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 1956 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 1960 } | 1957 } |
| 1961 | 1958 |
| 1962 // This test uses negative values of the maxlength attribute for input elements. | 1959 // This test uses negative values of the maxlength attribute for input elements. |
| 1963 // In this case, the maxlength of the input elements is set to the default | 1960 // In this case, the maxlength of the input elements is set to the default |
| 1964 // maxlength (defined in WebKit.) | 1961 // maxlength (defined in WebKit.) |
| 1965 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { | 1962 TEST_F(FormAutofillTest, FillFormNegativeMaxLength) { |
| 1966 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 1963 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 1967 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" | 1964 " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>" |
| 1968 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" | 1965 " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>" |
| 1969 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" | 1966 " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>" |
| 1970 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 1967 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 1971 "</FORM>"); | 1968 "</FORM>"); |
| 1972 | 1969 |
| 1973 WebFrame* web_frame = GetMainFrame(); | 1970 WebFrame* web_frame = GetMainFrame(); |
| 1974 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 1971 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 1975 | 1972 |
| 1976 FormCache form_cache; | 1973 FormCache form_cache; |
| 1977 std::vector<FormData> forms; | 1974 std::vector<FormData> forms; |
| 1978 form_cache.ExtractForms(*web_frame, &forms); | 1975 form_cache.ExtractForms(*web_frame, &forms); |
| 1979 ASSERT_EQ(1U, forms.size()); | 1976 ASSERT_EQ(1U, forms.size()); |
| 1980 | 1977 |
| 1981 // Get the input element we want to find. | 1978 // Get the input element we want to find. |
| 1982 WebElement element = web_frame->document().getElementById("firstname"); | 1979 WebElement element = web_frame->document().getElementById("firstname"); |
| 1983 WebInputElement input_element = element.to<WebInputElement>(); | 1980 WebInputElement input_element = element.to<WebInputElement>(); |
| 1984 | 1981 |
| 1985 // Find the form that contains the input element. | 1982 // Find the form that contains the input element. |
| 1986 FormData form; | 1983 FormData form; |
| 1987 FormField field; | 1984 FormFieldData field; |
| 1988 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 1985 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 1989 autofill::REQUIRE_NONE)); | 1986 autofill::REQUIRE_NONE)); |
| 1990 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1987 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 1991 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1988 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 1992 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1989 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 1993 | 1990 |
| 1994 const std::vector<FormField>& fields = form.fields; | 1991 const std::vector<FormFieldData>& fields = form.fields; |
| 1995 ASSERT_EQ(3U, fields.size()); | 1992 ASSERT_EQ(3U, fields.size()); |
| 1996 | 1993 |
| 1997 FormField expected; | 1994 FormFieldData expected; |
| 1998 expected.form_control_type = ASCIIToUTF16("text"); | 1995 expected.form_control_type = ASCIIToUTF16("text"); |
| 1999 expected.max_length = WebInputElement::defaultMaxLength(); | 1996 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2000 | 1997 |
| 2001 expected.name = ASCIIToUTF16("firstname"); | 1998 expected.name = ASCIIToUTF16("firstname"); |
| 2002 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 1999 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2003 | 2000 |
| 2004 expected.name = ASCIIToUTF16("lastname"); | 2001 expected.name = ASCIIToUTF16("lastname"); |
| 2005 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2002 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2006 | 2003 |
| 2007 expected.name = ASCIIToUTF16("email"); | 2004 expected.name = ASCIIToUTF16("email"); |
| 2008 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2005 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2009 | 2006 |
| 2010 // Fill the form. | 2007 // Fill the form. |
| 2011 form.fields[0].value = ASCIIToUTF16("Brother"); | 2008 form.fields[0].value = ASCIIToUTF16("Brother"); |
| 2012 form.fields[1].value = ASCIIToUTF16("Jonathan"); | 2009 form.fields[1].value = ASCIIToUTF16("Jonathan"); |
| 2013 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); | 2010 form.fields[2].value = ASCIIToUTF16("brotherj@example.com"); |
| 2014 FillForm(form, input_element); | 2011 FillForm(form, input_element); |
| 2015 | 2012 |
| 2016 // Find the newly-filled form that contains the input element. | 2013 // Find the newly-filled form that contains the input element. |
| 2017 FormData form2; | 2014 FormData form2; |
| 2018 FormField field2; | 2015 FormFieldData field2; |
| 2019 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 2016 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
| 2020 autofill::REQUIRE_NONE)); | 2017 autofill::REQUIRE_NONE)); |
| 2021 | 2018 |
| 2022 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2019 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2023 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2020 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2024 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2021 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2025 | 2022 |
| 2026 const std::vector<FormField>& fields2 = form2.fields; | 2023 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 2027 ASSERT_EQ(3U, fields2.size()); | 2024 ASSERT_EQ(3U, fields2.size()); |
| 2028 | 2025 |
| 2029 expected.name = ASCIIToUTF16("firstname"); | 2026 expected.name = ASCIIToUTF16("firstname"); |
| 2030 expected.value = ASCIIToUTF16("Brother"); | 2027 expected.value = ASCIIToUTF16("Brother"); |
| 2031 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2028 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2032 | 2029 |
| 2033 expected.name = ASCIIToUTF16("lastname"); | 2030 expected.name = ASCIIToUTF16("lastname"); |
| 2034 expected.value = ASCIIToUTF16("Jonathan"); | 2031 expected.value = ASCIIToUTF16("Jonathan"); |
| 2035 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2032 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2036 | 2033 |
| 2037 expected.name = ASCIIToUTF16("email"); | 2034 expected.name = ASCIIToUTF16("email"); |
| 2038 expected.value = ASCIIToUTF16("brotherj@example.com"); | 2035 expected.value = ASCIIToUTF16("brotherj@example.com"); |
| 2039 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2036 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2040 } | 2037 } |
| 2041 | 2038 |
| 2042 TEST_F(FormAutofillTest, FillFormEmptyName) { | 2039 TEST_F(FormAutofillTest, FillFormEmptyName) { |
| 2043 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2040 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2044 " <INPUT type=\"text\" id=\"firstname\"/>" | 2041 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2045 " <INPUT type=\"text\" id=\"lastname\"/>" | 2042 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2046 " <INPUT type=\"text\" id=\"email\"/>" | 2043 " <INPUT type=\"text\" id=\"email\"/>" |
| 2047 " <INPUT type=\"submit\" value=\"Send\"/>" | 2044 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 2048 "</FORM>"); | 2045 "</FORM>"); |
| 2049 | 2046 |
| 2050 WebFrame* web_frame = GetMainFrame(); | 2047 WebFrame* web_frame = GetMainFrame(); |
| 2051 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); | 2048 ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame); |
| 2052 | 2049 |
| 2053 FormCache form_cache; | 2050 FormCache form_cache; |
| 2054 std::vector<FormData> forms; | 2051 std::vector<FormData> forms; |
| 2055 form_cache.ExtractForms(*web_frame, &forms); | 2052 form_cache.ExtractForms(*web_frame, &forms); |
| 2056 ASSERT_EQ(1U, forms.size()); | 2053 ASSERT_EQ(1U, forms.size()); |
| 2057 | 2054 |
| 2058 // Get the input element we want to find. | 2055 // Get the input element we want to find. |
| 2059 WebElement element = web_frame->document().getElementById("firstname"); | 2056 WebElement element = web_frame->document().getElementById("firstname"); |
| 2060 WebInputElement input_element = element.to<WebInputElement>(); | 2057 WebInputElement input_element = element.to<WebInputElement>(); |
| 2061 | 2058 |
| 2062 // Find the form that contains the input element. | 2059 // Find the form that contains the input element. |
| 2063 FormData form; | 2060 FormData form; |
| 2064 FormField field; | 2061 FormFieldData field; |
| 2065 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 2062 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 2066 autofill::REQUIRE_NONE)); | 2063 autofill::REQUIRE_NONE)); |
| 2067 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2064 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2068 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2065 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2069 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2066 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 2070 | 2067 |
| 2071 const std::vector<FormField>& fields = form.fields; | 2068 const std::vector<FormFieldData>& fields = form.fields; |
| 2072 ASSERT_EQ(3U, fields.size()); | 2069 ASSERT_EQ(3U, fields.size()); |
| 2073 | 2070 |
| 2074 FormField expected; | 2071 FormFieldData expected; |
| 2075 expected.form_control_type = ASCIIToUTF16("text"); | 2072 expected.form_control_type = ASCIIToUTF16("text"); |
| 2076 expected.max_length = WebInputElement::defaultMaxLength(); | 2073 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2077 | 2074 |
| 2078 expected.name = ASCIIToUTF16("firstname"); | 2075 expected.name = ASCIIToUTF16("firstname"); |
| 2079 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2076 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2080 | 2077 |
| 2081 expected.name = ASCIIToUTF16("lastname"); | 2078 expected.name = ASCIIToUTF16("lastname"); |
| 2082 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2079 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2083 | 2080 |
| 2084 expected.name = ASCIIToUTF16("email"); | 2081 expected.name = ASCIIToUTF16("email"); |
| 2085 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2082 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2086 | 2083 |
| 2087 // Fill the form. | 2084 // Fill the form. |
| 2088 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2085 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 2089 form.fields[1].value = ASCIIToUTF16("Earp"); | 2086 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 2090 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2087 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 2091 FillForm(form, input_element); | 2088 FillForm(form, input_element); |
| 2092 | 2089 |
| 2093 // Find the newly-filled form that contains the input element. | 2090 // Find the newly-filled form that contains the input element. |
| 2094 FormData form2; | 2091 FormData form2; |
| 2095 FormField field2; | 2092 FormFieldData field2; |
| 2096 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 2093 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
| 2097 autofill::REQUIRE_NONE)); | 2094 autofill::REQUIRE_NONE)); |
| 2098 | 2095 |
| 2099 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2096 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2100 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2097 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2101 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2098 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2102 | 2099 |
| 2103 const std::vector<FormField>& fields2 = form2.fields; | 2100 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 2104 ASSERT_EQ(3U, fields2.size()); | 2101 ASSERT_EQ(3U, fields2.size()); |
| 2105 | 2102 |
| 2106 expected.form_control_type = ASCIIToUTF16("text"); | 2103 expected.form_control_type = ASCIIToUTF16("text"); |
| 2107 expected.max_length = WebInputElement::defaultMaxLength(); | 2104 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2108 | 2105 |
| 2109 expected.name = ASCIIToUTF16("firstname"); | 2106 expected.name = ASCIIToUTF16("firstname"); |
| 2110 expected.value = ASCIIToUTF16("Wyatt"); | 2107 expected.value = ASCIIToUTF16("Wyatt"); |
| 2111 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2108 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2112 | 2109 |
| 2113 expected.name = ASCIIToUTF16("lastname"); | 2110 expected.name = ASCIIToUTF16("lastname"); |
| 2114 expected.value = ASCIIToUTF16("Earp"); | 2111 expected.value = ASCIIToUTF16("Earp"); |
| 2115 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2112 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2116 | 2113 |
| 2117 expected.name = ASCIIToUTF16("email"); | 2114 expected.name = ASCIIToUTF16("email"); |
| 2118 expected.value = ASCIIToUTF16("wyatt@example.com"); | 2115 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 2119 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2116 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2120 } | 2117 } |
| 2121 | 2118 |
| 2122 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { | 2119 TEST_F(FormAutofillTest, FillFormEmptyFormNames) { |
| 2123 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" | 2120 LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">" |
| 2124 " <INPUT type=\"text\" id=\"firstname\"/>" | 2121 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2125 " <INPUT type=\"text\" id=\"middlename\"/>" | 2122 " <INPUT type=\"text\" id=\"middlename\"/>" |
| 2126 " <INPUT type=\"text\" id=\"lastname\"/>" | 2123 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2127 " <INPUT type=\"submit\" value=\"Send\"/>" | 2124 " <INPUT type=\"submit\" value=\"Send\"/>" |
| 2128 "</FORM>" | 2125 "</FORM>" |
| 2129 "<FORM action=\"http://abc.com\" method=\"post\">" | 2126 "<FORM action=\"http://abc.com\" method=\"post\">" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2140 std::vector<FormData> forms; | 2137 std::vector<FormData> forms; |
| 2141 form_cache.ExtractForms(*web_frame, &forms); | 2138 form_cache.ExtractForms(*web_frame, &forms); |
| 2142 ASSERT_EQ(2U, forms.size()); | 2139 ASSERT_EQ(2U, forms.size()); |
| 2143 | 2140 |
| 2144 // Get the input element we want to find. | 2141 // Get the input element we want to find. |
| 2145 WebElement element = web_frame->document().getElementById("apple"); | 2142 WebElement element = web_frame->document().getElementById("apple"); |
| 2146 WebInputElement input_element = element.to<WebInputElement>(); | 2143 WebInputElement input_element = element.to<WebInputElement>(); |
| 2147 | 2144 |
| 2148 // Find the form that contains the input element. | 2145 // Find the form that contains the input element. |
| 2149 FormData form; | 2146 FormData form; |
| 2150 FormField field; | 2147 FormFieldData field; |
| 2151 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 2148 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 2152 autofill::REQUIRE_NONE)); | 2149 autofill::REQUIRE_NONE)); |
| 2153 EXPECT_EQ(string16(), form.name); | 2150 EXPECT_EQ(string16(), form.name); |
| 2154 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2151 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2155 EXPECT_EQ(GURL("http://abc.com"), form.action); | 2152 EXPECT_EQ(GURL("http://abc.com"), form.action); |
| 2156 | 2153 |
| 2157 const std::vector<FormField>& fields = form.fields; | 2154 const std::vector<FormFieldData>& fields = form.fields; |
| 2158 ASSERT_EQ(3U, fields.size()); | 2155 ASSERT_EQ(3U, fields.size()); |
| 2159 | 2156 |
| 2160 FormField expected; | 2157 FormFieldData expected; |
| 2161 expected.form_control_type = ASCIIToUTF16("text"); | 2158 expected.form_control_type = ASCIIToUTF16("text"); |
| 2162 expected.max_length = WebInputElement::defaultMaxLength(); | 2159 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2163 | 2160 |
| 2164 expected.name = ASCIIToUTF16("apple"); | 2161 expected.name = ASCIIToUTF16("apple"); |
| 2165 expected.is_autofilled = false; | 2162 expected.is_autofilled = false; |
| 2166 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2163 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2167 | 2164 |
| 2168 expected.name = ASCIIToUTF16("banana"); | 2165 expected.name = ASCIIToUTF16("banana"); |
| 2169 expected.is_autofilled = false; | 2166 expected.is_autofilled = false; |
| 2170 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2167 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2171 | 2168 |
| 2172 expected.name = ASCIIToUTF16("cantelope"); | 2169 expected.name = ASCIIToUTF16("cantelope"); |
| 2173 expected.is_autofilled = false; | 2170 expected.is_autofilled = false; |
| 2174 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2171 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2175 | 2172 |
| 2176 // Fill the form. | 2173 // Fill the form. |
| 2177 form.fields[0].value = ASCIIToUTF16("Red"); | 2174 form.fields[0].value = ASCIIToUTF16("Red"); |
| 2178 form.fields[1].value = ASCIIToUTF16("Yellow"); | 2175 form.fields[1].value = ASCIIToUTF16("Yellow"); |
| 2179 form.fields[2].value = ASCIIToUTF16("Also Yellow"); | 2176 form.fields[2].value = ASCIIToUTF16("Also Yellow"); |
| 2180 FillForm(form, input_element); | 2177 FillForm(form, input_element); |
| 2181 | 2178 |
| 2182 // Find the newly-filled form that contains the input element. | 2179 // Find the newly-filled form that contains the input element. |
| 2183 FormData form2; | 2180 FormData form2; |
| 2184 FormField field2; | 2181 FormFieldData field2; |
| 2185 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 2182 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
| 2186 autofill::REQUIRE_NONE)); | 2183 autofill::REQUIRE_NONE)); |
| 2187 | 2184 |
| 2188 EXPECT_EQ(string16(), form2.name); | 2185 EXPECT_EQ(string16(), form2.name); |
| 2189 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2186 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2190 EXPECT_EQ(GURL("http://abc.com"), form2.action); | 2187 EXPECT_EQ(GURL("http://abc.com"), form2.action); |
| 2191 | 2188 |
| 2192 const std::vector<FormField>& fields2 = form2.fields; | 2189 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 2193 ASSERT_EQ(3U, fields2.size()); | 2190 ASSERT_EQ(3U, fields2.size()); |
| 2194 | 2191 |
| 2195 expected.name = ASCIIToUTF16("apple"); | 2192 expected.name = ASCIIToUTF16("apple"); |
| 2196 expected.value = ASCIIToUTF16("Red"); | 2193 expected.value = ASCIIToUTF16("Red"); |
| 2197 expected.is_autofilled = true; | 2194 expected.is_autofilled = true; |
| 2198 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 2195 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 2199 | 2196 |
| 2200 expected.name = ASCIIToUTF16("banana"); | 2197 expected.name = ASCIIToUTF16("banana"); |
| 2201 expected.value = ASCIIToUTF16("Yellow"); | 2198 expected.value = ASCIIToUTF16("Yellow"); |
| 2202 expected.is_autofilled = true; | 2199 expected.is_autofilled = true; |
| 2203 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 2200 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 2204 | 2201 |
| 2205 expected.name = ASCIIToUTF16("cantelope"); | 2202 expected.name = ASCIIToUTF16("cantelope"); |
| 2206 expected.value = ASCIIToUTF16("Also Yellow"); | 2203 expected.value = ASCIIToUTF16("Also Yellow"); |
| 2207 expected.is_autofilled = true; | 2204 expected.is_autofilled = true; |
| 2208 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 2205 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 2209 } | 2206 } |
| 2210 | 2207 |
| 2211 TEST_F(FormAutofillTest, ThreePartPhone) { | 2208 TEST_F(FormAutofillTest, ThreePartPhone) { |
| 2212 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2209 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2213 " Phone:" | 2210 " Phone:" |
| 2214 " <input type=\"text\" name=\"dayphone1\">" | 2211 " <input type=\"text\" name=\"dayphone1\">" |
| 2215 " -" | 2212 " -" |
| 2216 " <input type=\"text\" name=\"dayphone2\">" | 2213 " <input type=\"text\" name=\"dayphone2\">" |
| 2217 " -" | 2214 " -" |
| 2218 " <input type=\"text\" name=\"dayphone3\">" | 2215 " <input type=\"text\" name=\"dayphone3\">" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2233 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 2230 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 2234 WebFormControlElement(), | 2231 WebFormControlElement(), |
| 2235 autofill::REQUIRE_NONE, | 2232 autofill::REQUIRE_NONE, |
| 2236 autofill::EXTRACT_VALUE, | 2233 autofill::EXTRACT_VALUE, |
| 2237 &form, | 2234 &form, |
| 2238 NULL)); | 2235 NULL)); |
| 2239 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2236 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2240 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2237 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2241 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2238 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2242 | 2239 |
| 2243 const std::vector<FormField>& fields = form.fields; | 2240 const std::vector<FormFieldData>& fields = form.fields; |
| 2244 ASSERT_EQ(4U, fields.size()); | 2241 ASSERT_EQ(4U, fields.size()); |
| 2245 | 2242 |
| 2246 FormField expected; | 2243 FormFieldData expected; |
| 2247 expected.form_control_type = ASCIIToUTF16("text"); | 2244 expected.form_control_type = ASCIIToUTF16("text"); |
| 2248 expected.max_length = WebInputElement::defaultMaxLength(); | 2245 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2249 | 2246 |
| 2250 expected.label = ASCIIToUTF16("Phone:"); | 2247 expected.label = ASCIIToUTF16("Phone:"); |
| 2251 expected.name = ASCIIToUTF16("dayphone1"); | 2248 expected.name = ASCIIToUTF16("dayphone1"); |
| 2252 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2249 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2253 | 2250 |
| 2254 expected.label = ASCIIToUTF16("-"); | 2251 expected.label = ASCIIToUTF16("-"); |
| 2255 expected.name = ASCIIToUTF16("dayphone2"); | 2252 expected.name = ASCIIToUTF16("dayphone2"); |
| 2256 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2253 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2257 | 2254 |
| 2258 expected.label = ASCIIToUTF16("-"); | 2255 expected.label = ASCIIToUTF16("-"); |
| 2259 expected.name = ASCIIToUTF16("dayphone3"); | 2256 expected.name = ASCIIToUTF16("dayphone3"); |
| 2260 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2257 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2261 | 2258 |
| 2262 expected.label = ASCIIToUTF16("ext.:"); | 2259 expected.label = ASCIIToUTF16("ext.:"); |
| 2263 expected.name = ASCIIToUTF16("dayphone4"); | 2260 expected.name = ASCIIToUTF16("dayphone4"); |
| 2264 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); | 2261 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 2265 } | 2262 } |
| 2266 | 2263 |
| 2267 | 2264 |
| 2268 TEST_F(FormAutofillTest, MaxLengthFields) { | 2265 TEST_F(FormAutofillTest, MaxLengthFields) { |
| 2269 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2266 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 2270 " Phone:" | 2267 " Phone:" |
| 2271 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" | 2268 " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">" |
| 2272 " -" | 2269 " -" |
| 2273 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" | 2270 " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">" |
| 2274 " -" | 2271 " -" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2292 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 2289 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 2293 WebFormControlElement(), | 2290 WebFormControlElement(), |
| 2294 autofill::REQUIRE_NONE, | 2291 autofill::REQUIRE_NONE, |
| 2295 autofill::EXTRACT_VALUE, | 2292 autofill::EXTRACT_VALUE, |
| 2296 &form, | 2293 &form, |
| 2297 NULL)); | 2294 NULL)); |
| 2298 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2295 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2299 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2296 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2300 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2297 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2301 | 2298 |
| 2302 const std::vector<FormField>& fields = form.fields; | 2299 const std::vector<FormFieldData>& fields = form.fields; |
| 2303 ASSERT_EQ(6U, fields.size()); | 2300 ASSERT_EQ(6U, fields.size()); |
| 2304 | 2301 |
| 2305 FormField expected; | 2302 FormFieldData expected; |
| 2306 expected.form_control_type = ASCIIToUTF16("text"); | 2303 expected.form_control_type = ASCIIToUTF16("text"); |
| 2307 | 2304 |
| 2308 expected.label = ASCIIToUTF16("Phone:"); | 2305 expected.label = ASCIIToUTF16("Phone:"); |
| 2309 expected.name = ASCIIToUTF16("dayphone1"); | 2306 expected.name = ASCIIToUTF16("dayphone1"); |
| 2310 expected.max_length = 3; | 2307 expected.max_length = 3; |
| 2311 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2308 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2312 | 2309 |
| 2313 expected.label = ASCIIToUTF16("-"); | 2310 expected.label = ASCIIToUTF16("-"); |
| 2314 expected.name = ASCIIToUTF16("dayphone2"); | 2311 expected.name = ASCIIToUTF16("dayphone2"); |
| 2315 expected.max_length = 3; | 2312 expected.max_length = 3; |
| 2316 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2313 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2317 | 2314 |
| 2318 expected.label = ASCIIToUTF16("-"); | 2315 expected.label = ASCIIToUTF16("-"); |
| 2319 expected.name = ASCIIToUTF16("dayphone3"); | 2316 expected.name = ASCIIToUTF16("dayphone3"); |
| 2320 expected.max_length = 4; | 2317 expected.max_length = 4; |
| 2321 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2318 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2322 | 2319 |
| 2323 expected.label = ASCIIToUTF16("ext.:"); | 2320 expected.label = ASCIIToUTF16("ext.:"); |
| 2324 expected.name = ASCIIToUTF16("dayphone4"); | 2321 expected.name = ASCIIToUTF16("dayphone4"); |
| 2325 expected.max_length = 5; | 2322 expected.max_length = 5; |
| 2326 EXPECT_FORM_FIELD_EQUALS(expected, fields[3]); | 2323 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]); |
| 2327 | 2324 |
| 2328 // When unspecified |size|, default is returned. | 2325 // When unspecified |size|, default is returned. |
| 2329 expected.label = string16(); | 2326 expected.label = string16(); |
| 2330 expected.name = ASCIIToUTF16("default1"); | 2327 expected.name = ASCIIToUTF16("default1"); |
| 2331 expected.max_length = WebInputElement::defaultMaxLength(); | 2328 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2332 EXPECT_FORM_FIELD_EQUALS(expected, fields[4]); | 2329 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[4]); |
| 2333 | 2330 |
| 2334 // When invalid |size|, default is returned. | 2331 // When invalid |size|, default is returned. |
| 2335 expected.label = string16(); | 2332 expected.label = string16(); |
| 2336 expected.name = ASCIIToUTF16("invalid1"); | 2333 expected.name = ASCIIToUTF16("invalid1"); |
| 2337 expected.max_length = WebInputElement::defaultMaxLength(); | 2334 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2338 EXPECT_FORM_FIELD_EQUALS(expected, fields[5]); | 2335 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[5]); |
| 2339 } | 2336 } |
| 2340 | 2337 |
| 2341 // This test re-creates the experience of typing in a field then selecting a | 2338 // This test re-creates the experience of typing in a field then selecting a |
| 2342 // profile from the Autofill suggestions popup. The field that is being typed | 2339 // profile from the Autofill suggestions popup. The field that is being typed |
| 2343 // into should be filled even though it's not technically empty. | 2340 // into should be filled even though it's not technically empty. |
| 2344 TEST_F(FormAutofillTest, FillFormNonEmptyField) { | 2341 TEST_F(FormAutofillTest, FillFormNonEmptyField) { |
| 2345 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2342 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2346 " <INPUT type=\"text\" id=\"firstname\"/>" | 2343 " <INPUT type=\"text\" id=\"firstname\"/>" |
| 2347 " <INPUT type=\"text\" id=\"lastname\"/>" | 2344 " <INPUT type=\"text\" id=\"lastname\"/>" |
| 2348 " <INPUT type=\"text\" id=\"email\"/>" | 2345 " <INPUT type=\"text\" id=\"email\"/>" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2359 | 2356 |
| 2360 // Get the input element we want to find. | 2357 // Get the input element we want to find. |
| 2361 WebElement element = web_frame->document().getElementById("firstname"); | 2358 WebElement element = web_frame->document().getElementById("firstname"); |
| 2362 WebInputElement input_element = element.to<WebInputElement>(); | 2359 WebInputElement input_element = element.to<WebInputElement>(); |
| 2363 | 2360 |
| 2364 // Simulate typing by modifying the field value. | 2361 // Simulate typing by modifying the field value. |
| 2365 input_element.setValue(ASCIIToUTF16("Wy")); | 2362 input_element.setValue(ASCIIToUTF16("Wy")); |
| 2366 | 2363 |
| 2367 // Find the form that contains the input element. | 2364 // Find the form that contains the input element. |
| 2368 FormData form; | 2365 FormData form; |
| 2369 FormField field; | 2366 FormFieldData field; |
| 2370 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, | 2367 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field, |
| 2371 autofill::REQUIRE_NONE)); | 2368 autofill::REQUIRE_NONE)); |
| 2372 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2369 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2373 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2370 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
| 2374 EXPECT_EQ(GURL("http://buh.com"), form.action); | 2371 EXPECT_EQ(GURL("http://buh.com"), form.action); |
| 2375 | 2372 |
| 2376 const std::vector<FormField>& fields = form.fields; | 2373 const std::vector<FormFieldData>& fields = form.fields; |
| 2377 ASSERT_EQ(3U, fields.size()); | 2374 ASSERT_EQ(3U, fields.size()); |
| 2378 | 2375 |
| 2379 FormField expected; | 2376 FormFieldData expected; |
| 2380 expected.form_control_type = ASCIIToUTF16("text"); | 2377 expected.form_control_type = ASCIIToUTF16("text"); |
| 2381 expected.max_length = WebInputElement::defaultMaxLength(); | 2378 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2382 | 2379 |
| 2383 expected.name = ASCIIToUTF16("firstname"); | 2380 expected.name = ASCIIToUTF16("firstname"); |
| 2384 expected.value = ASCIIToUTF16("Wy"); | 2381 expected.value = ASCIIToUTF16("Wy"); |
| 2385 expected.is_autofilled = false; | 2382 expected.is_autofilled = false; |
| 2386 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2383 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2387 | 2384 |
| 2388 expected.name = ASCIIToUTF16("lastname"); | 2385 expected.name = ASCIIToUTF16("lastname"); |
| 2389 expected.value = string16(); | 2386 expected.value = string16(); |
| 2390 expected.is_autofilled = false; | 2387 expected.is_autofilled = false; |
| 2391 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2388 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2392 | 2389 |
| 2393 expected.name = ASCIIToUTF16("email"); | 2390 expected.name = ASCIIToUTF16("email"); |
| 2394 expected.value = string16(); | 2391 expected.value = string16(); |
| 2395 expected.is_autofilled = false; | 2392 expected.is_autofilled = false; |
| 2396 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2393 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2397 | 2394 |
| 2398 // Preview the form and verify that the cursor position has been updated. | 2395 // Preview the form and verify that the cursor position has been updated. |
| 2399 form.fields[0].value = ASCIIToUTF16("Wyatt"); | 2396 form.fields[0].value = ASCIIToUTF16("Wyatt"); |
| 2400 form.fields[1].value = ASCIIToUTF16("Earp"); | 2397 form.fields[1].value = ASCIIToUTF16("Earp"); |
| 2401 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); | 2398 form.fields[2].value = ASCIIToUTF16("wyatt@example.com"); |
| 2402 PreviewForm(form, input_element); | 2399 PreviewForm(form, input_element); |
| 2403 EXPECT_EQ(2, input_element.selectionStart()); | 2400 EXPECT_EQ(2, input_element.selectionStart()); |
| 2404 EXPECT_EQ(5, input_element.selectionEnd()); | 2401 EXPECT_EQ(5, input_element.selectionEnd()); |
| 2405 | 2402 |
| 2406 // Fill the form. | 2403 // Fill the form. |
| 2407 FillForm(form, input_element); | 2404 FillForm(form, input_element); |
| 2408 | 2405 |
| 2409 // Find the newly-filled form that contains the input element. | 2406 // Find the newly-filled form that contains the input element. |
| 2410 FormData form2; | 2407 FormData form2; |
| 2411 FormField field2; | 2408 FormFieldData field2; |
| 2412 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, | 2409 EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2, |
| 2413 autofill::REQUIRE_NONE)); | 2410 autofill::REQUIRE_NONE)); |
| 2414 | 2411 |
| 2415 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2412 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2416 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2413 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2417 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2414 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2418 | 2415 |
| 2419 const std::vector<FormField>& fields2 = form2.fields; | 2416 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 2420 ASSERT_EQ(3U, fields2.size()); | 2417 ASSERT_EQ(3U, fields2.size()); |
| 2421 | 2418 |
| 2422 expected.name = ASCIIToUTF16("firstname"); | 2419 expected.name = ASCIIToUTF16("firstname"); |
| 2423 expected.value = ASCIIToUTF16("Wyatt"); | 2420 expected.value = ASCIIToUTF16("Wyatt"); |
| 2424 expected.is_autofilled = true; | 2421 expected.is_autofilled = true; |
| 2425 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 2422 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 2426 | 2423 |
| 2427 expected.name = ASCIIToUTF16("lastname"); | 2424 expected.name = ASCIIToUTF16("lastname"); |
| 2428 expected.value = ASCIIToUTF16("Earp"); | 2425 expected.value = ASCIIToUTF16("Earp"); |
| 2429 expected.is_autofilled = true; | 2426 expected.is_autofilled = true; |
| 2430 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 2427 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 2431 | 2428 |
| 2432 expected.name = ASCIIToUTF16("email"); | 2429 expected.name = ASCIIToUTF16("email"); |
| 2433 expected.value = ASCIIToUTF16("wyatt@example.com"); | 2430 expected.value = ASCIIToUTF16("wyatt@example.com"); |
| 2434 expected.is_autofilled = true; | 2431 expected.is_autofilled = true; |
| 2435 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 2432 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 2436 | 2433 |
| 2437 // Verify that the cursor position has been updated. | 2434 // Verify that the cursor position has been updated. |
| 2438 EXPECT_EQ(5, input_element.selectionStart()); | 2435 EXPECT_EQ(5, input_element.selectionStart()); |
| 2439 EXPECT_EQ(5, input_element.selectionEnd()); | 2436 EXPECT_EQ(5, input_element.selectionEnd()); |
| 2440 } | 2437 } |
| 2441 | 2438 |
| 2442 TEST_F(FormAutofillTest, ClearFormWithNode) { | 2439 TEST_F(FormAutofillTest, ClearFormWithNode) { |
| 2443 LoadHTML( | 2440 LoadHTML( |
| 2444 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2441 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2445 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2442 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2468 notenabled.setValue(WebString::fromUTF8("no clear")); | 2465 notenabled.setValue(WebString::fromUTF8("no clear")); |
| 2469 | 2466 |
| 2470 // Clear the form. | 2467 // Clear the form. |
| 2471 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 2468 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 2472 | 2469 |
| 2473 // Verify that the auto-filled attribute has been turned off. | 2470 // Verify that the auto-filled attribute has been turned off. |
| 2474 EXPECT_FALSE(firstname.isAutofilled()); | 2471 EXPECT_FALSE(firstname.isAutofilled()); |
| 2475 | 2472 |
| 2476 // Verify the form is cleared. | 2473 // Verify the form is cleared. |
| 2477 FormData form2; | 2474 FormData form2; |
| 2478 FormField field2; | 2475 FormFieldData field2; |
| 2479 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2, | 2476 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2, |
| 2480 autofill::REQUIRE_NONE)); | 2477 autofill::REQUIRE_NONE)); |
| 2481 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2478 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2482 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2479 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2483 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2480 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2484 | 2481 |
| 2485 const std::vector<FormField>& fields2 = form2.fields; | 2482 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 2486 ASSERT_EQ(4U, fields2.size()); | 2483 ASSERT_EQ(4U, fields2.size()); |
| 2487 | 2484 |
| 2488 FormField expected; | 2485 FormFieldData expected; |
| 2489 expected.form_control_type = ASCIIToUTF16("text"); | 2486 expected.form_control_type = ASCIIToUTF16("text"); |
| 2490 expected.max_length = WebInputElement::defaultMaxLength(); | 2487 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2491 | 2488 |
| 2492 expected.name = ASCIIToUTF16("firstname"); | 2489 expected.name = ASCIIToUTF16("firstname"); |
| 2493 expected.value = string16(); | 2490 expected.value = string16(); |
| 2494 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 2491 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 2495 | 2492 |
| 2496 expected.name = ASCIIToUTF16("lastname"); | 2493 expected.name = ASCIIToUTF16("lastname"); |
| 2497 expected.value = string16(); | 2494 expected.value = string16(); |
| 2498 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 2495 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 2499 | 2496 |
| 2500 expected.name = ASCIIToUTF16("noAC"); | 2497 expected.name = ASCIIToUTF16("noAC"); |
| 2501 expected.value = string16(); | 2498 expected.value = string16(); |
| 2502 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 2499 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 2503 | 2500 |
| 2504 expected.name = ASCIIToUTF16("notenabled"); | 2501 expected.name = ASCIIToUTF16("notenabled"); |
| 2505 expected.value = ASCIIToUTF16("no clear"); | 2502 expected.value = ASCIIToUTF16("no clear"); |
| 2506 EXPECT_FORM_FIELD_EQUALS(expected, fields2[3]); | 2503 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[3]); |
| 2507 | 2504 |
| 2508 // Verify that the cursor position has been updated. | 2505 // Verify that the cursor position has been updated. |
| 2509 EXPECT_EQ(0, firstname.selectionStart()); | 2506 EXPECT_EQ(0, firstname.selectionStart()); |
| 2510 EXPECT_EQ(0, firstname.selectionEnd()); | 2507 EXPECT_EQ(0, firstname.selectionEnd()); |
| 2511 } | 2508 } |
| 2512 | 2509 |
| 2513 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { | 2510 TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) { |
| 2514 LoadHTML( | 2511 LoadHTML( |
| 2515 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2512 "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2516 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2513 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2543 select_element.setValue(WebString::fromUTF8("AK")); | 2540 select_element.setValue(WebString::fromUTF8("AK")); |
| 2544 | 2541 |
| 2545 // Clear the form. | 2542 // Clear the form. |
| 2546 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 2543 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
| 2547 | 2544 |
| 2548 // Verify that the auto-filled attribute has been turned off. | 2545 // Verify that the auto-filled attribute has been turned off. |
| 2549 EXPECT_FALSE(firstname.isAutofilled()); | 2546 EXPECT_FALSE(firstname.isAutofilled()); |
| 2550 | 2547 |
| 2551 // Verify the form is cleared. | 2548 // Verify the form is cleared. |
| 2552 FormData form2; | 2549 FormData form2; |
| 2553 FormField field2; | 2550 FormFieldData field2; |
| 2554 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2, | 2551 EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2, |
| 2555 autofill::REQUIRE_NONE)); | 2552 autofill::REQUIRE_NONE)); |
| 2556 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 2553 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
| 2557 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); | 2554 EXPECT_EQ(GURL(web_frame->document().url()), form2.origin); |
| 2558 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 2555 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
| 2559 | 2556 |
| 2560 const std::vector<FormField>& fields2 = form2.fields; | 2557 const std::vector<FormFieldData>& fields2 = form2.fields; |
| 2561 ASSERT_EQ(3U, fields2.size()); | 2558 ASSERT_EQ(3U, fields2.size()); |
| 2562 | 2559 |
| 2563 FormField expected; | 2560 FormFieldData expected; |
| 2564 | 2561 |
| 2565 expected.name = ASCIIToUTF16("firstname"); | 2562 expected.name = ASCIIToUTF16("firstname"); |
| 2566 expected.value = string16(); | 2563 expected.value = string16(); |
| 2567 expected.form_control_type = ASCIIToUTF16("text"); | 2564 expected.form_control_type = ASCIIToUTF16("text"); |
| 2568 expected.max_length = WebInputElement::defaultMaxLength(); | 2565 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2569 EXPECT_FORM_FIELD_EQUALS(expected, fields2[0]); | 2566 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]); |
| 2570 | 2567 |
| 2571 expected.name = ASCIIToUTF16("lastname"); | 2568 expected.name = ASCIIToUTF16("lastname"); |
| 2572 expected.value = string16(); | 2569 expected.value = string16(); |
| 2573 expected.form_control_type = ASCIIToUTF16("text"); | 2570 expected.form_control_type = ASCIIToUTF16("text"); |
| 2574 expected.max_length = WebInputElement::defaultMaxLength(); | 2571 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2575 EXPECT_FORM_FIELD_EQUALS(expected, fields2[1]); | 2572 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]); |
| 2576 | 2573 |
| 2577 expected.name = ASCIIToUTF16("state"); | 2574 expected.name = ASCIIToUTF16("state"); |
| 2578 expected.value = ASCIIToUTF16("?"); | 2575 expected.value = ASCIIToUTF16("?"); |
| 2579 expected.form_control_type = ASCIIToUTF16("select-one"); | 2576 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 2580 expected.max_length = 0; | 2577 expected.max_length = 0; |
| 2581 EXPECT_FORM_FIELD_EQUALS(expected, fields2[2]); | 2578 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]); |
| 2582 | 2579 |
| 2583 // Verify that the cursor position has been updated. | 2580 // Verify that the cursor position has been updated. |
| 2584 EXPECT_EQ(0, firstname.selectionStart()); | 2581 EXPECT_EQ(0, firstname.selectionStart()); |
| 2585 EXPECT_EQ(0, firstname.selectionEnd()); | 2582 EXPECT_EQ(0, firstname.selectionEnd()); |
| 2586 } | 2583 } |
| 2587 | 2584 |
| 2588 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { | 2585 TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
| 2589 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" | 2586 LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">" |
| 2590 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" | 2587 " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>" |
| 2591 " <INPUT type=\"text\" id=\"lastname\"/>" | 2588 " <INPUT type=\"text\" id=\"lastname\"/>" |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2879 // Extract the country select-one value as text. | 2876 // Extract the country select-one value as text. |
| 2880 EXPECT_TRUE(WebFormElementToFormData( | 2877 EXPECT_TRUE(WebFormElementToFormData( |
| 2881 forms[0], WebFormControlElement(), autofill::REQUIRE_NONE, | 2878 forms[0], WebFormControlElement(), autofill::REQUIRE_NONE, |
| 2882 static_cast<autofill::ExtractMask>( | 2879 static_cast<autofill::ExtractMask>( |
| 2883 autofill::EXTRACT_VALUE | autofill::EXTRACT_OPTION_TEXT), | 2880 autofill::EXTRACT_VALUE | autofill::EXTRACT_OPTION_TEXT), |
| 2884 &form, NULL)); | 2881 &form, NULL)); |
| 2885 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2882 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2886 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2883 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2887 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2884 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2888 | 2885 |
| 2889 const std::vector<FormField>& fields = form.fields; | 2886 const std::vector<FormFieldData>& fields = form.fields; |
| 2890 ASSERT_EQ(3U, fields.size()); | 2887 ASSERT_EQ(3U, fields.size()); |
| 2891 | 2888 |
| 2892 FormField expected; | 2889 FormFieldData expected; |
| 2893 | 2890 |
| 2894 expected.name = ASCIIToUTF16("firstname"); | 2891 expected.name = ASCIIToUTF16("firstname"); |
| 2895 expected.value = ASCIIToUTF16("John"); | 2892 expected.value = ASCIIToUTF16("John"); |
| 2896 expected.form_control_type = ASCIIToUTF16("text"); | 2893 expected.form_control_type = ASCIIToUTF16("text"); |
| 2897 expected.max_length = WebInputElement::defaultMaxLength(); | 2894 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2898 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2895 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2899 | 2896 |
| 2900 expected.name = ASCIIToUTF16("lastname"); | 2897 expected.name = ASCIIToUTF16("lastname"); |
| 2901 expected.value = ASCIIToUTF16("Smith"); | 2898 expected.value = ASCIIToUTF16("Smith"); |
| 2902 expected.form_control_type = ASCIIToUTF16("text"); | 2899 expected.form_control_type = ASCIIToUTF16("text"); |
| 2903 expected.max_length = WebInputElement::defaultMaxLength(); | 2900 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2904 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2901 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2905 | 2902 |
| 2906 expected.name = ASCIIToUTF16("country"); | 2903 expected.name = ASCIIToUTF16("country"); |
| 2907 expected.value = ASCIIToUTF16("Albania"); | 2904 expected.value = ASCIIToUTF16("Albania"); |
| 2908 expected.form_control_type = ASCIIToUTF16("select-one"); | 2905 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 2909 expected.max_length = 0; | 2906 expected.max_length = 0; |
| 2910 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2907 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2911 | 2908 |
| 2912 form.fields.clear(); | 2909 form.fields.clear(); |
| 2913 // Extract the country select-one value as value. | 2910 // Extract the country select-one value as value. |
| 2914 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 2911 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
| 2915 WebFormControlElement(), | 2912 WebFormControlElement(), |
| 2916 autofill::REQUIRE_NONE, | 2913 autofill::REQUIRE_NONE, |
| 2917 autofill::EXTRACT_VALUE, | 2914 autofill::EXTRACT_VALUE, |
| 2918 &form, | 2915 &form, |
| 2919 NULL)); | 2916 NULL)); |
| 2920 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2917 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
| 2921 EXPECT_EQ(GURL(frame->document().url()), form.origin); | 2918 EXPECT_EQ(GURL(frame->document().url()), form.origin); |
| 2922 EXPECT_EQ(GURL("http://cnn.com"), form.action); | 2919 EXPECT_EQ(GURL("http://cnn.com"), form.action); |
| 2923 | 2920 |
| 2924 ASSERT_EQ(3U, fields.size()); | 2921 ASSERT_EQ(3U, fields.size()); |
| 2925 | 2922 |
| 2926 expected.name = ASCIIToUTF16("firstname"); | 2923 expected.name = ASCIIToUTF16("firstname"); |
| 2927 expected.value = ASCIIToUTF16("John"); | 2924 expected.value = ASCIIToUTF16("John"); |
| 2928 expected.form_control_type = ASCIIToUTF16("text"); | 2925 expected.form_control_type = ASCIIToUTF16("text"); |
| 2929 expected.max_length = WebInputElement::defaultMaxLength(); | 2926 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2930 EXPECT_FORM_FIELD_EQUALS(expected, fields[0]); | 2927 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]); |
| 2931 | 2928 |
| 2932 expected.name = ASCIIToUTF16("lastname"); | 2929 expected.name = ASCIIToUTF16("lastname"); |
| 2933 expected.value = ASCIIToUTF16("Smith"); | 2930 expected.value = ASCIIToUTF16("Smith"); |
| 2934 expected.form_control_type = ASCIIToUTF16("text"); | 2931 expected.form_control_type = ASCIIToUTF16("text"); |
| 2935 expected.max_length = WebInputElement::defaultMaxLength(); | 2932 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2936 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2933 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 2937 | 2934 |
| 2938 expected.name = ASCIIToUTF16("country"); | 2935 expected.name = ASCIIToUTF16("country"); |
| 2939 expected.value = ASCIIToUTF16("AL"); | 2936 expected.value = ASCIIToUTF16("AL"); |
| 2940 expected.form_control_type = ASCIIToUTF16("select-one"); | 2937 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 2941 expected.max_length = 0; | 2938 expected.max_length = 0; |
| 2942 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2939 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 2943 } | 2940 } |
| OLD | NEW |