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" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 FormFieldData expected; | 206 FormFieldData expected; |
207 expected.name = ASCIIToUTF16("element"); | 207 expected.name = ASCIIToUTF16("element"); |
208 expected.value = ASCIIToUTF16("value"); | 208 expected.value = ASCIIToUTF16("value"); |
209 expected.form_control_type = "text"; | 209 expected.form_control_type = "text"; |
210 expected.max_length = WebInputElement::defaultMaxLength(); | 210 expected.max_length = WebInputElement::defaultMaxLength(); |
211 expected.is_autofilled = true; | 211 expected.is_autofilled = true; |
212 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 212 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
213 } | 213 } |
214 | 214 |
| 215 // We should be able to extract a radio or a checkbox field that has been |
| 216 // autofilled. |
| 217 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { |
| 218 LoadHTML("<INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" |
| 219 "<INPUT type=\"radio\" id=\"radio\" value=\"male\"/>"); |
| 220 |
| 221 WebFrame* frame = GetMainFrame(); |
| 222 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 223 |
| 224 WebElement web_element = frame->document().getElementById("checkbox"); |
| 225 WebInputElement element = web_element.to<WebInputElement>(); |
| 226 element.setAutofilled(true); |
| 227 FormFieldData result; |
| 228 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 229 |
| 230 FormFieldData expected; |
| 231 expected.name = ASCIIToUTF16("checkbox"); |
| 232 expected.value = ASCIIToUTF16("mail"); |
| 233 expected.form_control_type = "checkbox"; |
| 234 expected.is_autofilled = true; |
| 235 expected.is_checkable = true; |
| 236 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 237 |
| 238 web_element = frame->document().getElementById("radio"); |
| 239 element = web_element.to<WebInputElement>(); |
| 240 element.setAutofilled(true); |
| 241 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 242 expected.name = ASCIIToUTF16("radio"); |
| 243 expected.value = ASCIIToUTF16("male"); |
| 244 expected.form_control_type = "radio"; |
| 245 expected.is_autofilled = true; |
| 246 expected.is_checkable = true; |
| 247 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
| 248 } |
| 249 |
215 // We should be able to extract a <select> field. | 250 // We should be able to extract a <select> field. |
216 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 251 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
217 LoadHTML("<SELECT id=\"element\"/>" | 252 LoadHTML("<SELECT id=\"element\"/>" |
218 " <OPTION value=\"CA\">California</OPTION>" | 253 " <OPTION value=\"CA\">California</OPTION>" |
219 " <OPTION value=\"TX\">Texas</OPTION>" | 254 " <OPTION value=\"TX\">Texas</OPTION>" |
220 "</SELECT>"); | 255 "</SELECT>"); |
221 | 256 |
222 WebFrame* frame = GetMainFrame(); | 257 WebFrame* frame = GetMainFrame(); |
223 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 258 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
224 | 259 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); | 291 EXPECT_EQ(ASCIIToUTF16("California"), result3.option_contents[0]); |
257 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); | 292 EXPECT_EQ(ASCIIToUTF16("TX"), result3.option_values[1]); |
258 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); | 293 EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]); |
259 } | 294 } |
260 | 295 |
261 // We should not extract the value for non-text and non-select fields. | 296 // We should not extract the value for non-text and non-select fields. |
262 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { | 297 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { |
263 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 298 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
264 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" | 299 " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>" |
265 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" | 300 " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>" |
266 " <INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\"/>" | |
267 " <INPUT type=\"radio\" id=\"radio\" value=\"male\"/>" | |
268 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" | 301 " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>" |
269 "</FORM>"); | 302 "</FORM>"); |
270 | 303 |
271 WebFrame* frame = GetMainFrame(); | 304 WebFrame* frame = GetMainFrame(); |
272 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 305 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
273 | 306 |
274 WebElement web_element = frame->document().getElementById("hidden"); | 307 WebElement web_element = frame->document().getElementById("hidden"); |
275 WebFormControlElement element = web_element.to<WebFormControlElement>(); | 308 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
276 FormFieldData result; | 309 FormFieldData result; |
277 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 310 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
278 | 311 |
279 FormFieldData expected; | 312 FormFieldData expected; |
280 expected.max_length = 0; | 313 expected.max_length = 0; |
281 | 314 |
282 expected.name = ASCIIToUTF16("hidden"); | 315 expected.name = ASCIIToUTF16("hidden"); |
283 expected.form_control_type = "hidden"; | 316 expected.form_control_type = "hidden"; |
284 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 317 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
285 | 318 |
286 web_element = frame->document().getElementById("password"); | 319 web_element = frame->document().getElementById("password"); |
287 element = web_element.to<WebFormControlElement>(); | 320 element = web_element.to<WebFormControlElement>(); |
288 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 321 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
289 expected.name = ASCIIToUTF16("password"); | 322 expected.name = ASCIIToUTF16("password"); |
290 expected.form_control_type = "password"; | 323 expected.form_control_type = "password"; |
291 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 324 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
292 | 325 |
293 web_element = frame->document().getElementById("checkbox"); | |
294 element = web_element.to<WebFormControlElement>(); | |
295 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
296 expected.name = ASCIIToUTF16("checkbox"); | |
297 expected.form_control_type = "checkbox"; | |
298 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | |
299 | |
300 web_element = frame->document().getElementById("radio"); | |
301 element = web_element.to<WebFormControlElement>(); | |
302 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
303 expected.name = ASCIIToUTF16("radio"); | |
304 expected.form_control_type = "radio"; | |
305 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | |
306 | |
307 | |
308 web_element = frame->document().getElementById("submit"); | 326 web_element = frame->document().getElementById("submit"); |
309 element = web_element.to<WebFormControlElement>(); | 327 element = web_element.to<WebFormControlElement>(); |
310 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 328 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
311 expected.name = ASCIIToUTF16("submit"); | 329 expected.name = ASCIIToUTF16("submit"); |
312 expected.form_control_type = "submit"; | 330 expected.form_control_type = "submit"; |
313 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 331 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
314 } | 332 } |
315 | 333 |
316 // We should be able to extract the autocompletetype attribute. | 334 // We should be able to extract the autocompletetype attribute. |
317 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { | 335 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) { |
(...skipping 2577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2895 expected.form_control_type = "text"; | 2913 expected.form_control_type = "text"; |
2896 expected.max_length = WebInputElement::defaultMaxLength(); | 2914 expected.max_length = WebInputElement::defaultMaxLength(); |
2897 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 2915 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
2898 | 2916 |
2899 expected.name = ASCIIToUTF16("country"); | 2917 expected.name = ASCIIToUTF16("country"); |
2900 expected.value = ASCIIToUTF16("AL"); | 2918 expected.value = ASCIIToUTF16("AL"); |
2901 expected.form_control_type = "select-one"; | 2919 expected.form_control_type = "select-one"; |
2902 expected.max_length = 0; | 2920 expected.max_length = 0; |
2903 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 2921 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
2904 } | 2922 } |
OLD | NEW |