OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "third_party/WebKit/public/web/WebElementCollection.h" | 22 #include "third_party/WebKit/public/web/WebElementCollection.h" |
23 #include "third_party/WebKit/public/web/WebExceptionCode.h" | 23 #include "third_party/WebKit/public/web/WebExceptionCode.h" |
24 #include "third_party/WebKit/public/web/WebFormControlElement.h" | 24 #include "third_party/WebKit/public/web/WebFormControlElement.h" |
25 #include "third_party/WebKit/public/web/WebFormElement.h" | 25 #include "third_party/WebKit/public/web/WebFormElement.h" |
26 #include "third_party/WebKit/public/web/WebInputElement.h" | 26 #include "third_party/WebKit/public/web/WebInputElement.h" |
27 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 27 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
28 #include "third_party/WebKit/public/web/WebSelectElement.h" | 28 #include "third_party/WebKit/public/web/WebSelectElement.h" |
29 #include "third_party/WebKit/public/web/WebTextAreaElement.h" | 29 #include "third_party/WebKit/public/web/WebTextAreaElement.h" |
30 | 30 |
31 using base::ASCIIToUTF16; | 31 using base::ASCIIToUTF16; |
| 32 using blink::WebDocument; |
32 using blink::WebElement; | 33 using blink::WebElement; |
33 using blink::WebExceptionCode; | 34 using blink::WebExceptionCode; |
34 using blink::WebFormControlElement; | 35 using blink::WebFormControlElement; |
35 using blink::WebFormElement; | 36 using blink::WebFormElement; |
36 using blink::WebFrame; | 37 using blink::WebFrame; |
37 using blink::WebInputElement; | 38 using blink::WebInputElement; |
38 using blink::WebSelectElement; | 39 using blink::WebSelectElement; |
39 using blink::WebString; | 40 using blink::WebString; |
40 using blink::WebTextAreaElement; | 41 using blink::WebTextAreaElement; |
41 using blink::WebVector; | 42 using blink::WebVector; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 return "CSS_SELECTOR"; | 96 return "CSS_SELECTOR"; |
96 case WebElementDescriptor::ID: | 97 case WebElementDescriptor::ID: |
97 return "ID"; | 98 return "ID"; |
98 case WebElementDescriptor::NONE: | 99 case WebElementDescriptor::NONE: |
99 return "NONE"; | 100 return "NONE"; |
100 } | 101 } |
101 NOTREACHED(); | 102 NOTREACHED(); |
102 return "UNKNOWN"; | 103 return "UNKNOWN"; |
103 } | 104 } |
104 | 105 |
105 bool ClickElement(const blink::WebDocument& document, | 106 bool ClickElement(const WebDocument& document, |
106 const WebElementDescriptor& element_descriptor) { | 107 const WebElementDescriptor& element_descriptor) { |
107 WebString web_descriptor = WebString::fromUTF8(element_descriptor.descriptor); | 108 WebString web_descriptor = WebString::fromUTF8(element_descriptor.descriptor); |
108 blink::WebElement element; | 109 blink::WebElement element; |
109 | 110 |
110 switch (element_descriptor.retrieval_method) { | 111 switch (element_descriptor.retrieval_method) { |
111 case WebElementDescriptor::CSS_SELECTOR: { | 112 case WebElementDescriptor::CSS_SELECTOR: { |
112 WebExceptionCode ec = 0; | 113 WebExceptionCode ec = 0; |
113 element = document.querySelector(web_descriptor, ec); | 114 element = document.querySelector(web_descriptor, ec); |
114 if (ec) | 115 if (ec) |
115 DVLOG(1) << "Query selector failed. Error code: " << ec << "."; | 116 DVLOG(1) << "Query selector failed. Error code: " << ec << "."; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 LoadHTML(html); | 222 LoadHTML(html); |
222 | 223 |
223 WebFrame* web_frame = GetMainFrame(); | 224 WebFrame* web_frame = GetMainFrame(); |
224 ASSERT_NE(nullptr, web_frame); | 225 ASSERT_NE(nullptr, web_frame); |
225 | 226 |
226 FormCache form_cache; | 227 FormCache form_cache; |
227 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 228 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
228 ASSERT_EQ(1U, forms.size()); | 229 ASSERT_EQ(1U, forms.size()); |
229 | 230 |
230 // Get the input element we want to find. | 231 // Get the input element we want to find. |
231 WebElement element = web_frame->document().getElementById("firstname"); | 232 WebInputElement input_element = GetInputElementById("firstname"); |
232 WebInputElement input_element = element.to<WebInputElement>(); | |
233 | 233 |
234 // Find the form that contains the input element. | 234 // Find the form that contains the input element. |
235 FormData form_data; | 235 FormData form_data; |
236 FormFieldData field; | 236 FormFieldData field; |
237 EXPECT_TRUE(FindFormAndFieldForFormControlElement( | 237 EXPECT_TRUE(FindFormAndFieldForFormControlElement( |
238 input_element, &form_data, &field, autofill::REQUIRE_NONE)); | 238 input_element, &form_data, &field, autofill::REQUIRE_NONE)); |
239 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name); | 239 EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name); |
240 EXPECT_EQ(GURL(web_frame->document().url()), form_data.origin); | 240 EXPECT_EQ(GURL(web_frame->document().url()), form_data.origin); |
241 EXPECT_EQ(GURL("http://buh.com"), form_data.action); | 241 EXPECT_EQ(GURL("http://buh.com"), form_data.action); |
242 | 242 |
(...skipping 27 matching lines...) Expand all Loading... |
270 ValidateFilledField(field_cases[i], get_value_function); | 270 ValidateFilledField(field_cases[i], get_value_function); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 // Validate an Autofilled field. | 274 // Validate an Autofilled field. |
275 void ValidateFilledField(const AutofillFieldCase& field_case, | 275 void ValidateFilledField(const AutofillFieldCase& field_case, |
276 GetValueFunction get_value_function) { | 276 GetValueFunction get_value_function) { |
277 SCOPED_TRACE(base::StringPrintf("Verify autofilled value for field %s", | 277 SCOPED_TRACE(base::StringPrintf("Verify autofilled value for field %s", |
278 field_case.name)); | 278 field_case.name)); |
279 WebString value; | 279 WebString value; |
280 WebFormControlElement element = GetMainFrame()->document().getElementById( | 280 WebFormControlElement element = |
281 ASCIIToUTF16(field_case.name)).to<WebFormControlElement>(); | 281 GetFormControlElementById(ASCIIToUTF16(field_case.name)); |
282 if ((element.formControlType() == "select-one") || | 282 if ((element.formControlType() == "select-one") || |
283 (element.formControlType() == "textarea")) { | 283 (element.formControlType() == "textarea")) { |
284 value = get_value_function(element); | 284 value = get_value_function(element); |
285 } else { | 285 } else { |
286 ASSERT_TRUE(element.formControlType() == "text" || | 286 ASSERT_TRUE(element.formControlType() == "text" || |
287 element.formControlType() == "month"); | 287 element.formControlType() == "month"); |
288 value = get_value_function(element); | 288 value = get_value_function(element); |
289 } | 289 } |
290 | 290 |
291 const WebString expected_value = ASCIIToUTF16(field_case.expected_value); | 291 const WebString expected_value = ASCIIToUTF16(field_case.expected_value); |
292 if (expected_value.isEmpty()) | 292 if (expected_value.isEmpty()) |
293 EXPECT_TRUE(value.isEmpty()); | 293 EXPECT_TRUE(value.isEmpty()); |
294 else | 294 else |
295 EXPECT_EQ(expected_value.utf8(), value.utf8()); | 295 EXPECT_EQ(expected_value.utf8(), value.utf8()); |
296 | 296 |
297 EXPECT_EQ(field_case.should_be_autofilled, element.isAutofilled()); | 297 EXPECT_EQ(field_case.should_be_autofilled, element.isAutofilled()); |
298 } | 298 } |
299 | 299 |
| 300 WebFormControlElement GetFormControlElementById(const WebString& id) { |
| 301 return GetMainFrame()->document().getElementById( |
| 302 id).to<WebFormControlElement>(); |
| 303 } |
| 304 |
| 305 WebInputElement GetInputElementById(const WebString& id) { |
| 306 return GetMainFrame()->document().getElementById( |
| 307 id).to<WebInputElement>(); |
| 308 } |
| 309 |
300 static void FillFormIncludingNonFocusableElementsWrapper( | 310 static void FillFormIncludingNonFocusableElementsWrapper( |
301 const FormData& form, | 311 const FormData& form, |
302 const WebFormControlElement& element) { | 312 const WebFormControlElement& element) { |
303 FillFormIncludingNonFocusableElements(form, element.form()); | 313 FillFormIncludingNonFocusableElements(form, element.form()); |
304 } | 314 } |
305 | 315 |
306 static WebString GetValueWrapper(WebFormControlElement element) { | 316 static WebString GetValueWrapper(WebFormControlElement element) { |
307 if (element.formControlType() == "textarea") | 317 if (element.formControlType() == "textarea") |
308 return element.to<WebTextAreaElement>().value(); | 318 return element.to<WebTextAreaElement>().value(); |
309 | 319 |
(...skipping 17 matching lines...) Expand all Loading... |
327 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); | 337 DISALLOW_COPY_AND_ASSIGN(FormAutofillTest); |
328 }; | 338 }; |
329 | 339 |
330 // We should be able to extract a normal text field. | 340 // We should be able to extract a normal text field. |
331 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { | 341 TEST_F(FormAutofillTest, WebFormControlElementToFormField) { |
332 LoadHTML("<INPUT type='text' id='element' value='value'/>"); | 342 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
333 | 343 |
334 WebFrame* frame = GetMainFrame(); | 344 WebFrame* frame = GetMainFrame(); |
335 ASSERT_NE(nullptr, frame); | 345 ASSERT_NE(nullptr, frame); |
336 | 346 |
337 WebElement web_element = frame->document().getElementById("element"); | 347 WebFormControlElement element = GetFormControlElementById("element"); |
338 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
339 FormFieldData result1; | 348 FormFieldData result1; |
340 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); | 349 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result1); |
341 | 350 |
342 FormFieldData expected; | 351 FormFieldData expected; |
343 expected.form_control_type = "text"; | 352 expected.form_control_type = "text"; |
344 expected.max_length = WebInputElement::defaultMaxLength(); | 353 expected.max_length = WebInputElement::defaultMaxLength(); |
345 | 354 |
346 expected.name = ASCIIToUTF16("element"); | 355 expected.name = ASCIIToUTF16("element"); |
347 expected.value = base::string16(); | 356 expected.value = base::string16(); |
348 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 357 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
349 | 358 |
350 FormFieldData result2; | 359 FormFieldData result2; |
351 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); | 360 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); |
352 | 361 |
353 expected.name = ASCIIToUTF16("element"); | 362 expected.name = ASCIIToUTF16("element"); |
354 expected.value = ASCIIToUTF16("value"); | 363 expected.value = ASCIIToUTF16("value"); |
355 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); | 364 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result2); |
356 } | 365 } |
357 | 366 |
358 // We should be able to extract a text field with autocomplete="off". | 367 // We should be able to extract a text field with autocomplete="off". |
359 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { | 368 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) { |
360 LoadHTML("<INPUT type='text' id='element' value='value'" | 369 LoadHTML("<INPUT type='text' id='element' value='value'" |
361 " autocomplete='off'/>"); | 370 " autocomplete='off'/>"); |
362 | 371 |
363 WebFrame* frame = GetMainFrame(); | 372 WebFrame* frame = GetMainFrame(); |
364 ASSERT_NE(nullptr, frame); | 373 ASSERT_NE(nullptr, frame); |
365 | 374 |
366 WebElement web_element = frame->document().getElementById("element"); | 375 WebFormControlElement element = GetFormControlElementById("element"); |
367 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
368 FormFieldData result; | 376 FormFieldData result; |
369 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 377 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
370 | 378 |
371 FormFieldData expected; | 379 FormFieldData expected; |
372 expected.name = ASCIIToUTF16("element"); | 380 expected.name = ASCIIToUTF16("element"); |
373 expected.value = ASCIIToUTF16("value"); | 381 expected.value = ASCIIToUTF16("value"); |
374 expected.form_control_type = "text"; | 382 expected.form_control_type = "text"; |
375 expected.autocomplete_attribute = "off"; | 383 expected.autocomplete_attribute = "off"; |
376 expected.max_length = WebInputElement::defaultMaxLength(); | 384 expected.max_length = WebInputElement::defaultMaxLength(); |
377 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 385 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
378 } | 386 } |
379 | 387 |
380 // We should be able to extract a text field with maxlength specified. | 388 // We should be able to extract a text field with maxlength specified. |
381 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { | 389 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) { |
382 LoadHTML("<INPUT type='text' id='element' value='value'" | 390 LoadHTML("<INPUT type='text' id='element' value='value'" |
383 " maxlength='5'/>"); | 391 " maxlength='5'/>"); |
384 | 392 |
385 WebFrame* frame = GetMainFrame(); | 393 WebFrame* frame = GetMainFrame(); |
386 ASSERT_NE(nullptr, frame); | 394 ASSERT_NE(nullptr, frame); |
387 | 395 |
388 WebElement web_element = frame->document().getElementById("element"); | 396 WebFormControlElement element = GetFormControlElementById("element"); |
389 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
390 FormFieldData result; | 397 FormFieldData result; |
391 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 398 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
392 | 399 |
393 FormFieldData expected; | 400 FormFieldData expected; |
394 expected.name = ASCIIToUTF16("element"); | 401 expected.name = ASCIIToUTF16("element"); |
395 expected.value = ASCIIToUTF16("value"); | 402 expected.value = ASCIIToUTF16("value"); |
396 expected.form_control_type = "text"; | 403 expected.form_control_type = "text"; |
397 expected.max_length = 5; | 404 expected.max_length = 5; |
398 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 405 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
399 } | 406 } |
400 | 407 |
401 // We should be able to extract a text field that has been autofilled. | 408 // We should be able to extract a text field that has been autofilled. |
402 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { | 409 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) { |
403 LoadHTML("<INPUT type='text' id='element' value='value'/>"); | 410 LoadHTML("<INPUT type='text' id='element' value='value'/>"); |
404 | 411 |
405 WebFrame* frame = GetMainFrame(); | 412 WebFrame* frame = GetMainFrame(); |
406 ASSERT_NE(nullptr, frame); | 413 ASSERT_NE(nullptr, frame); |
407 | 414 |
408 WebElement web_element = frame->document().getElementById("element"); | 415 WebInputElement element = GetInputElementById("element"); |
409 WebInputElement element = web_element.to<WebInputElement>(); | |
410 element.setAutofilled(true); | 416 element.setAutofilled(true); |
411 FormFieldData result; | 417 FormFieldData result; |
412 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 418 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
413 | 419 |
414 FormFieldData expected; | 420 FormFieldData expected; |
415 expected.name = ASCIIToUTF16("element"); | 421 expected.name = ASCIIToUTF16("element"); |
416 expected.value = ASCIIToUTF16("value"); | 422 expected.value = ASCIIToUTF16("value"); |
417 expected.form_control_type = "text"; | 423 expected.form_control_type = "text"; |
418 expected.max_length = WebInputElement::defaultMaxLength(); | 424 expected.max_length = WebInputElement::defaultMaxLength(); |
419 expected.is_autofilled = true; | 425 expected.is_autofilled = true; |
420 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 426 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
421 } | 427 } |
422 | 428 |
423 // We should be able to extract a radio or a checkbox field that has been | 429 // We should be able to extract a radio or a checkbox field that has been |
424 // autofilled. | 430 // autofilled. |
425 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { | 431 TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) { |
426 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" | 432 LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>" |
427 "<INPUT type='radio' id='radio' value='male'/>"); | 433 "<INPUT type='radio' id='radio' value='male'/>"); |
428 | 434 |
429 WebFrame* frame = GetMainFrame(); | 435 WebFrame* frame = GetMainFrame(); |
430 ASSERT_NE(nullptr, frame); | 436 ASSERT_NE(nullptr, frame); |
431 | 437 |
432 WebElement web_element = frame->document().getElementById("checkbox"); | 438 WebInputElement element = GetInputElementById("checkbox"); |
433 WebInputElement element = web_element.to<WebInputElement>(); | |
434 element.setAutofilled(true); | 439 element.setAutofilled(true); |
435 FormFieldData result; | 440 FormFieldData result; |
436 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 441 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
437 | 442 |
438 FormFieldData expected; | 443 FormFieldData expected; |
439 expected.name = ASCIIToUTF16("checkbox"); | 444 expected.name = ASCIIToUTF16("checkbox"); |
440 expected.value = ASCIIToUTF16("mail"); | 445 expected.value = ASCIIToUTF16("mail"); |
441 expected.form_control_type = "checkbox"; | 446 expected.form_control_type = "checkbox"; |
442 expected.is_autofilled = true; | 447 expected.is_autofilled = true; |
443 expected.is_checkable = true; | 448 expected.is_checkable = true; |
444 expected.is_checked = true; | 449 expected.is_checked = true; |
445 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 450 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
446 | 451 |
447 web_element = frame->document().getElementById("radio"); | 452 element = GetInputElementById("radio"); |
448 element = web_element.to<WebInputElement>(); | |
449 element.setAutofilled(true); | 453 element.setAutofilled(true); |
450 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 454 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
451 expected.name = ASCIIToUTF16("radio"); | 455 expected.name = ASCIIToUTF16("radio"); |
452 expected.value = ASCIIToUTF16("male"); | 456 expected.value = ASCIIToUTF16("male"); |
453 expected.form_control_type = "radio"; | 457 expected.form_control_type = "radio"; |
454 expected.is_autofilled = true; | 458 expected.is_autofilled = true; |
455 expected.is_checkable = true; | 459 expected.is_checkable = true; |
456 expected.is_checked = false; | 460 expected.is_checked = false; |
457 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 461 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
458 } | 462 } |
459 | 463 |
460 // We should be able to extract a <select> field. | 464 // We should be able to extract a <select> field. |
461 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { | 465 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) { |
462 LoadHTML("<SELECT id='element'/>" | 466 LoadHTML("<SELECT id='element'/>" |
463 " <OPTION value='CA'>California</OPTION>" | 467 " <OPTION value='CA'>California</OPTION>" |
464 " <OPTION value='TX'>Texas</OPTION>" | 468 " <OPTION value='TX'>Texas</OPTION>" |
465 "</SELECT>"); | 469 "</SELECT>"); |
466 | 470 |
467 WebFrame* frame = GetMainFrame(); | 471 WebFrame* frame = GetMainFrame(); |
468 ASSERT_NE(nullptr, frame); | 472 ASSERT_NE(nullptr, frame); |
469 | 473 |
470 WebElement web_element = frame->document().getElementById("element"); | 474 WebFormControlElement element = GetFormControlElementById("element"); |
471 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
472 FormFieldData result1; | 475 FormFieldData result1; |
473 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); | 476 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); |
474 | 477 |
475 FormFieldData expected; | 478 FormFieldData expected; |
476 expected.name = ASCIIToUTF16("element"); | 479 expected.name = ASCIIToUTF16("element"); |
477 expected.max_length = 0; | 480 expected.max_length = 0; |
478 expected.form_control_type = "select-one"; | 481 expected.form_control_type = "select-one"; |
479 | 482 |
480 expected.value = ASCIIToUTF16("CA"); | 483 expected.value = ASCIIToUTF16("CA"); |
481 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); | 484 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result1); |
(...skipping 28 matching lines...) Expand all Loading... |
510 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { | 513 for (size_t i = 0; i < 2 * kMaxListSize; ++i) { |
511 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" | 514 html += base::StringPrintf("<OPTION value='%" PRIuS "'>" |
512 "%" PRIuS "</OPTION>", i, i); | 515 "%" PRIuS "</OPTION>", i, i); |
513 } | 516 } |
514 html += "</SELECT>"; | 517 html += "</SELECT>"; |
515 LoadHTML(html.c_str()); | 518 LoadHTML(html.c_str()); |
516 | 519 |
517 WebFrame* frame = GetMainFrame(); | 520 WebFrame* frame = GetMainFrame(); |
518 ASSERT_TRUE(frame); | 521 ASSERT_TRUE(frame); |
519 | 522 |
520 WebElement web_element = frame->document().getElementById("element"); | 523 WebFormControlElement element = GetFormControlElementById("element"); |
521 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
522 FormFieldData result; | 524 FormFieldData result; |
523 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result); | 525 WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result); |
524 | 526 |
525 EXPECT_TRUE(result.option_values.empty()); | 527 EXPECT_TRUE(result.option_values.empty()); |
526 EXPECT_TRUE(result.option_contents.empty()); | 528 EXPECT_TRUE(result.option_contents.empty()); |
527 } | 529 } |
528 | 530 |
529 // We should be able to extract a <textarea> field. | 531 // We should be able to extract a <textarea> field. |
530 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { | 532 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) { |
531 LoadHTML("<TEXTAREA id='element'>" | 533 LoadHTML("<TEXTAREA id='element'>" |
532 "This element's value " | 534 "This element's value " |
533 "spans multiple lines." | 535 "spans multiple lines." |
534 "</TEXTAREA>"); | 536 "</TEXTAREA>"); |
535 | 537 |
536 WebFrame* frame = GetMainFrame(); | 538 WebFrame* frame = GetMainFrame(); |
537 ASSERT_NE(nullptr, frame); | 539 ASSERT_NE(nullptr, frame); |
538 | 540 |
539 WebElement web_element = frame->document().getElementById("element"); | 541 WebFormControlElement element = GetFormControlElementById("element"); |
540 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
541 FormFieldData result_sans_value; | 542 FormFieldData result_sans_value; |
542 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, | 543 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, |
543 &result_sans_value); | 544 &result_sans_value); |
544 | 545 |
545 FormFieldData expected; | 546 FormFieldData expected; |
546 expected.name = ASCIIToUTF16("element"); | 547 expected.name = ASCIIToUTF16("element"); |
547 expected.max_length = 0; | 548 expected.max_length = 0; |
548 expected.form_control_type = "textarea"; | 549 expected.form_control_type = "textarea"; |
549 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 550 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
550 | 551 |
551 FormFieldData result_with_value; | 552 FormFieldData result_with_value; |
552 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, | 553 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, |
553 &result_with_value); | 554 &result_with_value); |
554 expected.value = ASCIIToUTF16("This element's value\n" | 555 expected.value = ASCIIToUTF16("This element's value\n" |
555 "spans multiple lines."); | 556 "spans multiple lines."); |
556 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 557 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
557 } | 558 } |
558 | 559 |
559 // We should be able to extract an <input type="month"> field. | 560 // We should be able to extract an <input type="month"> field. |
560 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { | 561 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) { |
561 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); | 562 LoadHTML("<INPUT type='month' id='element' value='2011-12'>"); |
562 | 563 |
563 WebFrame* frame = GetMainFrame(); | 564 WebFrame* frame = GetMainFrame(); |
564 ASSERT_NE(nullptr, frame); | 565 ASSERT_NE(nullptr, frame); |
565 | 566 |
566 WebElement web_element = frame->document().getElementById("element"); | 567 WebFormControlElement element = GetFormControlElementById("element"); |
567 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
568 FormFieldData result_sans_value; | 568 FormFieldData result_sans_value; |
569 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, | 569 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, |
570 &result_sans_value); | 570 &result_sans_value); |
571 | 571 |
572 FormFieldData expected; | 572 FormFieldData expected; |
573 expected.name = ASCIIToUTF16("element"); | 573 expected.name = ASCIIToUTF16("element"); |
574 expected.max_length = 0; | 574 expected.max_length = 0; |
575 expected.form_control_type = "month"; | 575 expected.form_control_type = "month"; |
576 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); | 576 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_sans_value); |
577 | 577 |
578 FormFieldData result_with_value; | 578 FormFieldData result_with_value; |
579 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, | 579 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, |
580 &result_with_value); | 580 &result_with_value); |
581 expected.value = ASCIIToUTF16("2011-12"); | 581 expected.value = ASCIIToUTF16("2011-12"); |
582 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); | 582 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result_with_value); |
583 } | 583 } |
584 | 584 |
585 // We should not extract the value for non-text and non-select fields. | 585 // We should not extract the value for non-text and non-select fields. |
586 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { | 586 TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) { |
587 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 587 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
588 " <INPUT type='hidden' id='hidden' value='apple'/>" | 588 " <INPUT type='hidden' id='hidden' value='apple'/>" |
589 " <INPUT type='submit' id='submit' value='Send'/>" | 589 " <INPUT type='submit' id='submit' value='Send'/>" |
590 "</FORM>"); | 590 "</FORM>"); |
591 | 591 |
592 WebFrame* frame = GetMainFrame(); | 592 WebFrame* frame = GetMainFrame(); |
593 ASSERT_NE(nullptr, frame); | 593 ASSERT_NE(nullptr, frame); |
594 | 594 |
595 WebElement web_element = frame->document().getElementById("hidden"); | 595 WebFormControlElement element = GetFormControlElementById("hidden"); |
596 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
597 FormFieldData result; | 596 FormFieldData result; |
598 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 597 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
599 | 598 |
600 FormFieldData expected; | 599 FormFieldData expected; |
601 expected.max_length = 0; | 600 expected.max_length = 0; |
602 | 601 |
603 expected.name = ASCIIToUTF16("hidden"); | 602 expected.name = ASCIIToUTF16("hidden"); |
604 expected.form_control_type = "hidden"; | 603 expected.form_control_type = "hidden"; |
605 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 604 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
606 | 605 |
607 web_element = frame->document().getElementById("submit"); | 606 element = GetFormControlElementById("submit"); |
608 element = web_element.to<WebFormControlElement>(); | |
609 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 607 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
610 expected.name = ASCIIToUTF16("submit"); | 608 expected.name = ASCIIToUTF16("submit"); |
611 expected.form_control_type = "submit"; | 609 expected.form_control_type = "submit"; |
612 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 610 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
613 } | 611 } |
614 | 612 |
615 // We should be able to extract password fields. | 613 // We should be able to extract password fields. |
616 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { | 614 TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) { |
617 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 615 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
618 " <INPUT type='password' id='password' value='secret'/>" | 616 " <INPUT type='password' id='password' value='secret'/>" |
619 "</FORM>"); | 617 "</FORM>"); |
620 | 618 |
621 WebFrame* frame = GetMainFrame(); | 619 WebFrame* frame = GetMainFrame(); |
622 ASSERT_NE(nullptr, frame); | 620 ASSERT_NE(nullptr, frame); |
623 | 621 |
624 WebElement web_element = frame->document().getElementById("password"); | 622 WebFormControlElement element = GetFormControlElementById("password"); |
625 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
626 FormFieldData result; | 623 FormFieldData result; |
627 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 624 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
628 | 625 |
629 FormFieldData expected; | 626 FormFieldData expected; |
630 expected.max_length = WebInputElement::defaultMaxLength(); | 627 expected.max_length = WebInputElement::defaultMaxLength(); |
631 expected.name = ASCIIToUTF16("password"); | 628 expected.name = ASCIIToUTF16("password"); |
632 expected.form_control_type = "password"; | 629 expected.form_control_type = "password"; |
633 expected.value = ASCIIToUTF16("secret"); | 630 expected.value = ASCIIToUTF16("secret"); |
634 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 631 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
635 } | 632 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 { "experimental", "text", "" }, | 684 { "experimental", "text", "" }, |
688 // <select> elements should behave no differently from text fields here. | 685 // <select> elements should behave no differently from text fields here. |
689 { "select", "select-one", "state" }, | 686 { "select", "select-one", "state" }, |
690 // <textarea> elements should also behave no differently from text fields. | 687 // <textarea> elements should also behave no differently from text fields. |
691 { "textarea", "textarea", "street-address" }, | 688 { "textarea", "textarea", "street-address" }, |
692 // Very long attribute values should be replaced by a default string, to | 689 // Very long attribute values should be replaced by a default string, to |
693 // prevent malicious websites from DOSing the browser process. | 690 // prevent malicious websites from DOSing the browser process. |
694 { "malicious", "text", "x-max-data-length-exceeded" }, | 691 { "malicious", "text", "x-max-data-length-exceeded" }, |
695 }; | 692 }; |
696 | 693 |
| 694 WebDocument document = frame->document(); |
697 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 695 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
698 WebElement web_element = frame->document().getElementById( | 696 WebFormControlElement element = |
699 ASCIIToUTF16(test_cases[i].element_id)); | 697 GetFormControlElementById(ASCIIToUTF16(test_cases[i].element_id)); |
700 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
701 FormFieldData result; | 698 FormFieldData result; |
702 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result); | 699 WebFormControlElementToFormField(element, autofill::EXTRACT_NONE, &result); |
703 | 700 |
704 FormFieldData expected; | 701 FormFieldData expected; |
705 expected.name = ASCIIToUTF16(test_cases[i].element_id); | 702 expected.name = ASCIIToUTF16(test_cases[i].element_id); |
706 expected.form_control_type = test_cases[i].form_control_type; | 703 expected.form_control_type = test_cases[i].form_control_type; |
707 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute; | 704 expected.autocomplete_attribute = test_cases[i].autocomplete_attribute; |
708 if (test_cases[i].form_control_type == "text") | 705 if (test_cases[i].form_control_type == "text") |
709 expected.max_length = WebInputElement::defaultMaxLength(); | 706 expected.max_length = WebInputElement::defaultMaxLength(); |
710 else | 707 else |
711 expected.max_length = 0; | 708 expected.max_length = 0; |
712 | 709 |
713 SCOPED_TRACE(test_cases[i].element_id); | 710 SCOPED_TRACE(test_cases[i].element_id); |
714 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 711 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
715 } | 712 } |
716 } | 713 } |
717 | 714 |
718 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { | 715 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { |
719 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" | 716 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" |
720 "<FORM>" | 717 "<FORM>" |
721 " <INPUT type='text' id='element'>" | 718 " <INPUT type='text' id='element'>" |
722 "</FORM>"); | 719 "</FORM>"); |
723 | 720 |
724 WebFrame* frame = GetMainFrame(); | 721 WebFrame* frame = GetMainFrame(); |
725 ASSERT_NE(nullptr, frame); | 722 ASSERT_NE(nullptr, frame); |
726 | 723 |
727 WebElement web_element = frame->document().getElementById("element"); | 724 WebFormControlElement element = GetFormControlElementById("element"); |
728 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
729 | 725 |
730 FormFieldData result; | 726 FormFieldData result; |
731 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 727 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
732 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 728 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
733 } | 729 } |
734 | 730 |
735 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { | 731 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { |
736 LoadHTML("<FORM>" | 732 LoadHTML("<FORM>" |
737 " <INPUT dir='rtl' type='text' id='element'/>" | 733 " <INPUT dir='rtl' type='text' id='element'/>" |
738 "</FORM>"); | 734 "</FORM>"); |
739 | 735 |
740 WebFrame* frame = GetMainFrame(); | 736 WebFrame* frame = GetMainFrame(); |
741 ASSERT_NE(nullptr, frame); | 737 ASSERT_NE(nullptr, frame); |
742 | 738 |
743 WebElement web_element = frame->document().getElementById("element"); | 739 WebFormControlElement element = GetFormControlElementById("element"); |
744 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
745 | 740 |
746 FormFieldData result; | 741 FormFieldData result; |
747 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 742 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
748 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 743 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
749 } | 744 } |
750 | 745 |
751 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { | 746 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { |
752 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" | 747 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" |
753 "<FORM>" | 748 "<FORM>" |
754 " <INPUT type='text' id='element'/>" | 749 " <INPUT type='text' id='element'/>" |
755 "</FORM>"); | 750 "</FORM>"); |
756 | 751 |
757 WebFrame* frame = GetMainFrame(); | 752 WebFrame* frame = GetMainFrame(); |
758 ASSERT_NE(nullptr, frame); | 753 ASSERT_NE(nullptr, frame); |
759 | 754 |
760 WebElement web_element = frame->document().getElementById("element"); | 755 WebFormControlElement element = GetFormControlElementById("element"); |
761 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
762 | 756 |
763 FormFieldData result; | 757 FormFieldData result; |
764 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 758 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
765 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 759 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
766 } | 760 } |
767 | 761 |
768 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { | 762 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { |
769 LoadHTML("<FORM dir='rtl'>" | 763 LoadHTML("<FORM dir='rtl'>" |
770 " <INPUT type='text' id='element'/>" | 764 " <INPUT type='text' id='element'/>" |
771 "</FORM>"); | 765 "</FORM>"); |
772 | 766 |
773 WebFrame* frame = GetMainFrame(); | 767 WebFrame* frame = GetMainFrame(); |
774 ASSERT_NE(nullptr, frame); | 768 ASSERT_NE(nullptr, frame); |
775 | 769 |
776 WebElement web_element = frame->document().getElementById("element"); | 770 WebFormControlElement element = GetFormControlElementById("element"); |
777 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
778 | 771 |
779 FormFieldData result; | 772 FormFieldData result; |
780 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 773 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
781 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 774 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
782 } | 775 } |
783 | 776 |
784 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { | 777 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { |
785 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" | 778 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" |
786 "<FORM dir='rtl'>" | 779 "<FORM dir='rtl'>" |
787 " <INPUT type='text' id='element'/>" | 780 " <INPUT type='text' id='element'/>" |
788 "</FORM>"); | 781 "</FORM>"); |
789 | 782 |
790 WebFrame* frame = GetMainFrame(); | 783 WebFrame* frame = GetMainFrame(); |
791 ASSERT_NE(nullptr, frame); | 784 ASSERT_NE(nullptr, frame); |
792 | 785 |
793 WebElement web_element = frame->document().getElementById("element"); | 786 WebFormControlElement element = GetFormControlElementById("element"); |
794 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
795 | 787 |
796 FormFieldData result; | 788 FormFieldData result; |
797 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 789 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
798 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 790 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
799 } | 791 } |
800 | 792 |
801 TEST_F(FormAutofillTest, | 793 TEST_F(FormAutofillTest, |
802 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { | 794 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { |
803 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" | 795 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" |
804 "<FORM dir='rtl'>" | 796 "<FORM dir='rtl'>" |
805 " <INPUT type='text' id='element'/>" | 797 " <INPUT type='text' id='element'/>" |
806 "</FORM>"); | 798 "</FORM>"); |
807 | 799 |
808 WebFrame* frame = GetMainFrame(); | 800 WebFrame* frame = GetMainFrame(); |
809 ASSERT_NE(nullptr, frame); | 801 ASSERT_NE(nullptr, frame); |
810 | 802 |
811 WebElement web_element = frame->document().getElementById("element"); | 803 WebFormControlElement element = GetFormControlElementById("element"); |
812 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
813 | 804 |
814 FormFieldData result; | 805 FormFieldData result; |
815 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 806 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
816 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | 807 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
817 } | 808 } |
818 | 809 |
819 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { | 810 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { |
820 LoadHTML("<FORM style='direction:ltr'>" | 811 LoadHTML("<FORM style='direction:ltr'>" |
821 " <SPAN dir='rtl'>" | 812 " <SPAN dir='rtl'>" |
822 " <INPUT type='text' id='element'/>" | 813 " <INPUT type='text' id='element'/>" |
823 " </SPAN>" | 814 " </SPAN>" |
824 "</FORM>"); | 815 "</FORM>"); |
825 | 816 |
826 WebFrame* frame = GetMainFrame(); | 817 WebFrame* frame = GetMainFrame(); |
827 ASSERT_NE(nullptr, frame); | 818 ASSERT_NE(nullptr, frame); |
828 | 819 |
829 WebElement web_element = frame->document().getElementById("element"); | 820 WebFormControlElement element = GetFormControlElementById("element"); |
830 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
831 | 821 |
832 FormFieldData result; | 822 FormFieldData result; |
833 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | 823 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
834 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | 824 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
835 } | 825 } |
836 | 826 |
837 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 827 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
838 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" | 828 LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>" |
839 " <LABEL for='firstname'>First name:</LABEL>" | 829 " <LABEL for='firstname'>First name:</LABEL>" |
840 " <INPUT type='text' id='firstname' value='John'/>" | 830 " <INPUT type='text' id='firstname' value='John'/>" |
(...skipping 19 matching lines...) Expand all Loading... |
860 " <INPUT type='hidden' id='notvisible' value='apple'/>" | 850 " <INPUT type='hidden' id='notvisible' value='apple'/>" |
861 "</FORM>"); | 851 "</FORM>"); |
862 | 852 |
863 WebFrame* frame = GetMainFrame(); | 853 WebFrame* frame = GetMainFrame(); |
864 ASSERT_NE(nullptr, frame); | 854 ASSERT_NE(nullptr, frame); |
865 | 855 |
866 WebVector<WebFormElement> forms; | 856 WebVector<WebFormElement> forms; |
867 frame->document().forms(forms); | 857 frame->document().forms(forms); |
868 ASSERT_EQ(1U, forms.size()); | 858 ASSERT_EQ(1U, forms.size()); |
869 | 859 |
870 WebElement element = frame->document().getElementById("firstname"); | 860 WebInputElement input_element = GetInputElementById("firstname"); |
871 WebInputElement input_element = element.to<WebInputElement>(); | |
872 | 861 |
873 FormData form; | 862 FormData form; |
874 FormFieldData field; | 863 FormFieldData field; |
875 EXPECT_TRUE(WebFormElementToFormData(forms[0], | 864 EXPECT_TRUE(WebFormElementToFormData(forms[0], |
876 input_element, | 865 input_element, |
877 autofill::REQUIRE_NONE, | 866 autofill::REQUIRE_NONE, |
878 autofill::EXTRACT_VALUE, | 867 autofill::EXTRACT_VALUE, |
879 &form, | 868 &form, |
880 &field)); | 869 &field)); |
881 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 870 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 html += "</FORM>"; | 928 html += "</FORM>"; |
940 LoadHTML(html.c_str()); | 929 LoadHTML(html.c_str()); |
941 | 930 |
942 WebFrame* frame = GetMainFrame(); | 931 WebFrame* frame = GetMainFrame(); |
943 ASSERT_NE(nullptr, frame); | 932 ASSERT_NE(nullptr, frame); |
944 | 933 |
945 WebVector<WebFormElement> forms; | 934 WebVector<WebFormElement> forms; |
946 frame->document().forms(forms); | 935 frame->document().forms(forms); |
947 ASSERT_EQ(1U, forms.size()); | 936 ASSERT_EQ(1U, forms.size()); |
948 | 937 |
949 WebElement element = frame->document().getElementById("firstname"); | 938 WebInputElement input_element = GetInputElementById("firstname"); |
950 WebInputElement input_element = element.to<WebInputElement>(); | |
951 | 939 |
952 FormData form; | 940 FormData form; |
953 FormFieldData field; | 941 FormFieldData field; |
954 EXPECT_FALSE(WebFormElementToFormData(forms[0], | 942 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
955 input_element, | 943 input_element, |
956 autofill::REQUIRE_NONE, | 944 autofill::REQUIRE_NONE, |
957 autofill::EXTRACT_VALUE, | 945 autofill::EXTRACT_VALUE, |
958 &form, | 946 &form, |
959 &field)); | 947 &field)); |
960 } | 948 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 "</FORM>"); | 1278 "</FORM>"); |
1291 | 1279 |
1292 WebFrame* web_frame = GetMainFrame(); | 1280 WebFrame* web_frame = GetMainFrame(); |
1293 ASSERT_NE(nullptr, web_frame); | 1281 ASSERT_NE(nullptr, web_frame); |
1294 | 1282 |
1295 FormCache form_cache; | 1283 FormCache form_cache; |
1296 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 1284 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
1297 ASSERT_EQ(1U, forms.size()); | 1285 ASSERT_EQ(1U, forms.size()); |
1298 | 1286 |
1299 // Get the input element we want to find. | 1287 // Get the input element we want to find. |
1300 WebElement element = web_frame->document().getElementById("firstname"); | 1288 WebInputElement input_element = GetInputElementById("firstname"); |
1301 WebInputElement input_element = element.to<WebInputElement>(); | |
1302 | 1289 |
1303 // Find the form and verify it's the correct form. | 1290 // Find the form and verify it's the correct form. |
1304 FormData form; | 1291 FormData form; |
1305 FormFieldData field; | 1292 FormFieldData field; |
1306 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 1293 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
1307 &form, | 1294 &form, |
1308 &field, | 1295 &field, |
1309 autofill::REQUIRE_NONE)); | 1296 autofill::REQUIRE_NONE)); |
1310 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1297 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1311 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 1298 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 "textarea-nonempty", | 1516 "textarea-nonempty", |
1530 "Go\naway!", | 1517 "Go\naway!", |
1531 "", | 1518 "", |
1532 false, | 1519 false, |
1533 "some multi-\nline value", | 1520 "some multi-\nline value", |
1534 "Go\naway!"}, | 1521 "Go\naway!"}, |
1535 }; | 1522 }; |
1536 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | 1523 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
1537 FillForm, &GetValueWrapper); | 1524 FillForm, &GetValueWrapper); |
1538 // Verify preview selection. | 1525 // Verify preview selection. |
1539 WebInputElement firstname = GetMainFrame()->document(). | 1526 WebInputElement firstname = GetInputElementById("firstname"); |
1540 getElementById("firstname").to<WebInputElement>(); | |
1541 EXPECT_EQ(16, firstname.selectionStart()); | 1527 EXPECT_EQ(16, firstname.selectionStart()); |
1542 EXPECT_EQ(16, firstname.selectionEnd()); | 1528 EXPECT_EQ(16, firstname.selectionEnd()); |
1543 } | 1529 } |
1544 | 1530 |
1545 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { | 1531 TEST_F(FormAutofillTest, FillFormIncludingNonFocusableElements) { |
1546 static const AutofillFieldCase field_cases[] = { | 1532 static const AutofillFieldCase field_cases[] = { |
1547 // fields: form_control_type, name, initial_value, autocomplete_attribute, | 1533 // fields: form_control_type, name, initial_value, autocomplete_attribute, |
1548 // should_be_autofilled, autofill_value, expected_value | 1534 // should_be_autofilled, autofill_value, expected_value |
1549 | 1535 |
1550 // Regular empty fields (firstname & lastname) should be autofilled. | 1536 // Regular empty fields (firstname & lastname) should be autofilled. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 "Go\naway!", | 1673 "Go\naway!", |
1688 "", | 1674 "", |
1689 false, | 1675 false, |
1690 "suggested multi-\nline value", | 1676 "suggested multi-\nline value", |
1691 ""}, | 1677 ""}, |
1692 }; | 1678 }; |
1693 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), | 1679 TestFormFillFunctions(kFormHtml, field_cases, arraysize(field_cases), |
1694 &PreviewForm, &GetSuggestedValueWrapper); | 1680 &PreviewForm, &GetSuggestedValueWrapper); |
1695 | 1681 |
1696 // Verify preview selection. | 1682 // Verify preview selection. |
1697 WebInputElement firstname = GetMainFrame()->document(). | 1683 WebInputElement firstname = GetInputElementById("firstname"); |
1698 getElementById("firstname").to<WebInputElement>(); | |
1699 EXPECT_EQ(0, firstname.selectionStart()); | 1684 EXPECT_EQ(0, firstname.selectionStart()); |
1700 EXPECT_EQ(19, firstname.selectionEnd()); | 1685 EXPECT_EQ(19, firstname.selectionEnd()); |
1701 } | 1686 } |
1702 | 1687 |
1703 TEST_F(FormAutofillTest, Labels) { | 1688 TEST_F(FormAutofillTest, Labels) { |
1704 ExpectJohnSmithLabels( | 1689 ExpectJohnSmithLabels( |
1705 "<FORM name='TestForm' action='http://cnn.com' method='post'>" | 1690 "<FORM name='TestForm' action='http://cnn.com' method='post'>" |
1706 " <LABEL for='firstname'> First name: </LABEL>" | 1691 " <LABEL for='firstname'> First name: </LABEL>" |
1707 " <INPUT type='text' id='firstname' value='John'/>" | 1692 " <INPUT type='text' id='firstname' value='John'/>" |
1708 " <LABEL for='lastname'> Last name: </LABEL>" | 1693 " <LABEL for='lastname'> Last name: </LABEL>" |
(...skipping 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2569 "</FORM>"); | 2554 "</FORM>"); |
2570 | 2555 |
2571 WebFrame* web_frame = GetMainFrame(); | 2556 WebFrame* web_frame = GetMainFrame(); |
2572 ASSERT_NE(nullptr, web_frame); | 2557 ASSERT_NE(nullptr, web_frame); |
2573 | 2558 |
2574 FormCache form_cache; | 2559 FormCache form_cache; |
2575 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 2560 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
2576 ASSERT_EQ(1U, forms.size()); | 2561 ASSERT_EQ(1U, forms.size()); |
2577 | 2562 |
2578 // Get the input element we want to find. | 2563 // Get the input element we want to find. |
2579 WebElement element = web_frame->document().getElementById("firstname"); | 2564 WebInputElement input_element = GetInputElementById("firstname"); |
2580 WebInputElement input_element = element.to<WebInputElement>(); | |
2581 | 2565 |
2582 // Find the form that contains the input element. | 2566 // Find the form that contains the input element. |
2583 FormData form; | 2567 FormData form; |
2584 FormFieldData field; | 2568 FormFieldData field; |
2585 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 2569 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
2586 &form, | 2570 &form, |
2587 &field, | 2571 &field, |
2588 autofill::REQUIRE_NONE)); | 2572 autofill::REQUIRE_NONE)); |
2589 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2573 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2590 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2574 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 "</FORM>"); | 2652 "</FORM>"); |
2669 | 2653 |
2670 WebFrame* web_frame = GetMainFrame(); | 2654 WebFrame* web_frame = GetMainFrame(); |
2671 ASSERT_NE(nullptr, web_frame); | 2655 ASSERT_NE(nullptr, web_frame); |
2672 | 2656 |
2673 FormCache form_cache; | 2657 FormCache form_cache; |
2674 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 2658 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
2675 ASSERT_EQ(1U, forms.size()); | 2659 ASSERT_EQ(1U, forms.size()); |
2676 | 2660 |
2677 // Get the input element we want to find. | 2661 // Get the input element we want to find. |
2678 WebElement element = web_frame->document().getElementById("firstname"); | 2662 WebInputElement input_element = GetInputElementById("firstname"); |
2679 WebInputElement input_element = element.to<WebInputElement>(); | |
2680 | 2663 |
2681 // Find the form that contains the input element. | 2664 // Find the form that contains the input element. |
2682 FormData form; | 2665 FormData form; |
2683 FormFieldData field; | 2666 FormFieldData field; |
2684 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 2667 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
2685 &form, | 2668 &form, |
2686 &field, | 2669 &field, |
2687 autofill::REQUIRE_NONE)); | 2670 autofill::REQUIRE_NONE)); |
2688 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2671 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2689 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2672 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2748 "</FORM>"); | 2731 "</FORM>"); |
2749 | 2732 |
2750 WebFrame* web_frame = GetMainFrame(); | 2733 WebFrame* web_frame = GetMainFrame(); |
2751 ASSERT_NE(nullptr, web_frame); | 2734 ASSERT_NE(nullptr, web_frame); |
2752 | 2735 |
2753 FormCache form_cache; | 2736 FormCache form_cache; |
2754 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 2737 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
2755 ASSERT_EQ(1U, forms.size()); | 2738 ASSERT_EQ(1U, forms.size()); |
2756 | 2739 |
2757 // Get the input element we want to find. | 2740 // Get the input element we want to find. |
2758 WebElement element = web_frame->document().getElementById("firstname"); | 2741 WebInputElement input_element = GetInputElementById("firstname"); |
2759 WebInputElement input_element = element.to<WebInputElement>(); | |
2760 | 2742 |
2761 // Find the form that contains the input element. | 2743 // Find the form that contains the input element. |
2762 FormData form; | 2744 FormData form; |
2763 FormFieldData field; | 2745 FormFieldData field; |
2764 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 2746 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
2765 &form, | 2747 &form, |
2766 &field, | 2748 &field, |
2767 autofill::REQUIRE_NONE)); | 2749 autofill::REQUIRE_NONE)); |
2768 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 2750 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
2769 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2751 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2837 "</FORM>"); | 2819 "</FORM>"); |
2838 | 2820 |
2839 WebFrame* web_frame = GetMainFrame(); | 2821 WebFrame* web_frame = GetMainFrame(); |
2840 ASSERT_NE(nullptr, web_frame); | 2822 ASSERT_NE(nullptr, web_frame); |
2841 | 2823 |
2842 FormCache form_cache; | 2824 FormCache form_cache; |
2843 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 2825 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
2844 ASSERT_EQ(2U, forms.size()); | 2826 ASSERT_EQ(2U, forms.size()); |
2845 | 2827 |
2846 // Get the input element we want to find. | 2828 // Get the input element we want to find. |
2847 WebElement element = web_frame->document().getElementById("apple"); | 2829 WebInputElement input_element = GetInputElementById("apple"); |
2848 WebInputElement input_element = element.to<WebInputElement>(); | |
2849 | 2830 |
2850 // Find the form that contains the input element. | 2831 // Find the form that contains the input element. |
2851 FormData form; | 2832 FormData form; |
2852 FormFieldData field; | 2833 FormFieldData field; |
2853 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 2834 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
2854 &form, | 2835 &form, |
2855 &field, | 2836 &field, |
2856 autofill::REQUIRE_NONE)); | 2837 autofill::REQUIRE_NONE)); |
2857 EXPECT_EQ(base::string16(), form.name); | 2838 EXPECT_EQ(base::string16(), form.name); |
2858 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); | 2839 EXPECT_EQ(GURL(web_frame->document().url()), form.origin); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3059 "</FORM>"); | 3040 "</FORM>"); |
3060 | 3041 |
3061 WebFrame* web_frame = GetMainFrame(); | 3042 WebFrame* web_frame = GetMainFrame(); |
3062 ASSERT_NE(nullptr, web_frame); | 3043 ASSERT_NE(nullptr, web_frame); |
3063 | 3044 |
3064 FormCache form_cache; | 3045 FormCache form_cache; |
3065 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3046 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3066 ASSERT_EQ(1U, forms.size()); | 3047 ASSERT_EQ(1U, forms.size()); |
3067 | 3048 |
3068 // Get the input element we want to find. | 3049 // Get the input element we want to find. |
3069 WebElement element = web_frame->document().getElementById("firstname"); | 3050 WebInputElement input_element = GetInputElementById("firstname"); |
3070 WebInputElement input_element = element.to<WebInputElement>(); | |
3071 | 3051 |
3072 // Simulate typing by modifying the field value. | 3052 // Simulate typing by modifying the field value. |
3073 input_element.setValue(ASCIIToUTF16("Wy")); | 3053 input_element.setValue(ASCIIToUTF16("Wy")); |
3074 | 3054 |
3075 // Find the form that contains the input element. | 3055 // Find the form that contains the input element. |
3076 FormData form; | 3056 FormData form; |
3077 FormFieldData field; | 3057 FormFieldData field; |
3078 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, | 3058 EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element, |
3079 &form, | 3059 &form, |
3080 &field, | 3060 &field, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3173 "</FORM>"); | 3153 "</FORM>"); |
3174 | 3154 |
3175 WebFrame* web_frame = GetMainFrame(); | 3155 WebFrame* web_frame = GetMainFrame(); |
3176 ASSERT_NE(nullptr, web_frame); | 3156 ASSERT_NE(nullptr, web_frame); |
3177 | 3157 |
3178 FormCache form_cache; | 3158 FormCache form_cache; |
3179 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3159 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3180 ASSERT_EQ(1U, forms.size()); | 3160 ASSERT_EQ(1U, forms.size()); |
3181 | 3161 |
3182 // Set the auto-filled attribute. | 3162 // Set the auto-filled attribute. |
3183 WebInputElement firstname = | 3163 WebInputElement firstname = GetInputElementById("firstname"); |
3184 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3185 firstname.setAutofilled(true); | 3164 firstname.setAutofilled(true); |
3186 WebInputElement lastname = | 3165 WebInputElement lastname = GetInputElementById("lastname"); |
3187 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3188 lastname.setAutofilled(true); | 3166 lastname.setAutofilled(true); |
3189 WebInputElement month = | 3167 WebInputElement month = GetInputElementById("month"); |
3190 web_frame->document().getElementById("month").to<WebInputElement>(); | |
3191 month.setAutofilled(true); | 3168 month.setAutofilled(true); |
3192 WebInputElement textarea = | 3169 WebInputElement textarea = GetInputElementById("textarea"); |
3193 web_frame->document().getElementById("textarea").to<WebInputElement>(); | |
3194 textarea.setAutofilled(true); | 3170 textarea.setAutofilled(true); |
3195 | 3171 |
3196 // Set the value of the disabled text input element. | 3172 // Set the value of the disabled text input element. |
3197 WebInputElement notenabled = | 3173 WebInputElement notenabled = GetInputElementById("notenabled"); |
3198 web_frame->document().getElementById("notenabled").to<WebInputElement>(); | |
3199 notenabled.setValue(WebString::fromUTF8("no clear")); | 3174 notenabled.setValue(WebString::fromUTF8("no clear")); |
3200 | 3175 |
3201 // Clear the form. | 3176 // Clear the form. |
3202 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 3177 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
3203 | 3178 |
3204 // Verify that the auto-filled attribute has been turned off. | 3179 // Verify that the auto-filled attribute has been turned off. |
3205 EXPECT_FALSE(firstname.isAutofilled()); | 3180 EXPECT_FALSE(firstname.isAutofilled()); |
3206 | 3181 |
3207 // Verify the form is cleared. | 3182 // Verify the form is cleared. |
3208 FormData form2; | 3183 FormData form2; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3285 "</FORM>"); | 3260 "</FORM>"); |
3286 | 3261 |
3287 WebFrame* web_frame = GetMainFrame(); | 3262 WebFrame* web_frame = GetMainFrame(); |
3288 ASSERT_NE(nullptr, web_frame); | 3263 ASSERT_NE(nullptr, web_frame); |
3289 | 3264 |
3290 FormCache form_cache; | 3265 FormCache form_cache; |
3291 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3266 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3292 ASSERT_EQ(1U, forms.size()); | 3267 ASSERT_EQ(1U, forms.size()); |
3293 | 3268 |
3294 // Set the auto-filled attribute. | 3269 // Set the auto-filled attribute. |
3295 WebInputElement firstname = | 3270 WebInputElement firstname = GetInputElementById("firstname"); |
3296 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3297 firstname.setAutofilled(true); | 3271 firstname.setAutofilled(true); |
3298 WebInputElement lastname = | 3272 WebInputElement lastname = GetInputElementById("lastname"); |
3299 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3300 lastname.setAutofilled(true); | 3273 lastname.setAutofilled(true); |
3301 | 3274 |
3302 // Set the value and auto-filled attribute of the state element. | 3275 // Set the value and auto-filled attribute of the state element. |
3303 WebSelectElement state = | 3276 WebSelectElement state = |
3304 web_frame->document().getElementById("state").to<WebSelectElement>(); | 3277 web_frame->document().getElementById("state").to<WebSelectElement>(); |
3305 state.setValue(WebString::fromUTF8("AK")); | 3278 state.setValue(WebString::fromUTF8("AK")); |
3306 state.setAutofilled(true); | 3279 state.setAutofilled(true); |
3307 | 3280 |
3308 // Clear the form. | 3281 // Clear the form. |
3309 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 3282 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3361 "</FORM>"); | 3334 "</FORM>"); |
3362 | 3335 |
3363 WebFrame* web_frame = GetMainFrame(); | 3336 WebFrame* web_frame = GetMainFrame(); |
3364 ASSERT_NE(nullptr, web_frame); | 3337 ASSERT_NE(nullptr, web_frame); |
3365 | 3338 |
3366 FormCache form_cache; | 3339 FormCache form_cache; |
3367 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3340 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3368 ASSERT_EQ(1U, forms.size()); | 3341 ASSERT_EQ(1U, forms.size()); |
3369 | 3342 |
3370 // Set the auto-filled attribute. | 3343 // Set the auto-filled attribute. |
3371 WebInputElement firstname = | 3344 WebInputElement firstname = GetInputElementById("firstname"); |
3372 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3373 firstname.setAutofilled(true); | 3345 firstname.setAutofilled(true); |
3374 WebInputElement lastname = | 3346 WebInputElement lastname = GetInputElementById("lastname"); |
3375 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3376 lastname.setAutofilled(true); | 3347 lastname.setAutofilled(true); |
3377 WebInputElement email = | 3348 WebInputElement email = GetInputElementById("email"); |
3378 web_frame->document().getElementById("email").to<WebInputElement>(); | |
3379 email.setAutofilled(true); | 3349 email.setAutofilled(true); |
3380 WebInputElement email2 = | 3350 WebInputElement email2 = GetInputElementById("email2"); |
3381 web_frame->document().getElementById("email2").to<WebInputElement>(); | |
3382 email2.setAutofilled(true); | 3351 email2.setAutofilled(true); |
3383 WebInputElement phone = | 3352 WebInputElement phone = GetInputElementById("phone"); |
3384 web_frame->document().getElementById("phone").to<WebInputElement>(); | |
3385 phone.setAutofilled(true); | 3353 phone.setAutofilled(true); |
3386 | 3354 |
3387 // Set the suggested values on two of the elements. | 3355 // Set the suggested values on two of the elements. |
3388 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3356 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3389 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3357 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3390 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3358 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3391 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3359 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3392 | 3360 |
3393 // Clear the previewed fields. | 3361 // Clear the previewed fields. |
3394 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); | 3362 EXPECT_TRUE(ClearPreviewedFormWithElement(lastname, false)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3428 "</FORM>"); | 3396 "</FORM>"); |
3429 | 3397 |
3430 WebFrame* web_frame = GetMainFrame(); | 3398 WebFrame* web_frame = GetMainFrame(); |
3431 ASSERT_NE(nullptr, web_frame); | 3399 ASSERT_NE(nullptr, web_frame); |
3432 | 3400 |
3433 FormCache form_cache; | 3401 FormCache form_cache; |
3434 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3402 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3435 ASSERT_EQ(1U, forms.size()); | 3403 ASSERT_EQ(1U, forms.size()); |
3436 | 3404 |
3437 // Set the auto-filled attribute. | 3405 // Set the auto-filled attribute. |
3438 WebInputElement firstname = | 3406 WebInputElement firstname = GetInputElementById("firstname"); |
3439 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3440 firstname.setAutofilled(true); | 3407 firstname.setAutofilled(true); |
3441 WebInputElement lastname = | 3408 WebInputElement lastname = GetInputElementById("lastname"); |
3442 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3443 lastname.setAutofilled(true); | 3409 lastname.setAutofilled(true); |
3444 WebInputElement email = | 3410 WebInputElement email = GetInputElementById("email"); |
3445 web_frame->document().getElementById("email").to<WebInputElement>(); | |
3446 email.setAutofilled(true); | 3411 email.setAutofilled(true); |
3447 WebInputElement email2 = | 3412 WebInputElement email2 = GetInputElementById("email2"); |
3448 web_frame->document().getElementById("email2").to<WebInputElement>(); | |
3449 email2.setAutofilled(true); | 3413 email2.setAutofilled(true); |
3450 WebInputElement phone = | 3414 WebInputElement phone = GetInputElementById("phone"); |
3451 web_frame->document().getElementById("phone").to<WebInputElement>(); | |
3452 phone.setAutofilled(true); | 3415 phone.setAutofilled(true); |
3453 | 3416 |
3454 | 3417 |
3455 // Set the suggested values on all of the elements. | 3418 // Set the suggested values on all of the elements. |
3456 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | 3419 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
3457 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3420 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3458 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3421 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3459 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3422 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3460 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3423 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3461 | 3424 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3495 "</FORM>"); | 3458 "</FORM>"); |
3496 | 3459 |
3497 WebFrame* web_frame = GetMainFrame(); | 3460 WebFrame* web_frame = GetMainFrame(); |
3498 ASSERT_NE(nullptr, web_frame); | 3461 ASSERT_NE(nullptr, web_frame); |
3499 | 3462 |
3500 FormCache form_cache; | 3463 FormCache form_cache; |
3501 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3464 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3502 ASSERT_EQ(1U, forms.size()); | 3465 ASSERT_EQ(1U, forms.size()); |
3503 | 3466 |
3504 // Set the auto-filled attribute. | 3467 // Set the auto-filled attribute. |
3505 WebInputElement firstname = | 3468 WebInputElement firstname = GetInputElementById("firstname"); |
3506 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3507 firstname.setAutofilled(true); | 3469 firstname.setAutofilled(true); |
3508 WebInputElement lastname = | 3470 WebInputElement lastname = GetInputElementById("lastname"); |
3509 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3510 lastname.setAutofilled(true); | 3471 lastname.setAutofilled(true); |
3511 WebInputElement email = | 3472 WebInputElement email = GetInputElementById("email"); |
3512 web_frame->document().getElementById("email").to<WebInputElement>(); | |
3513 email.setAutofilled(true); | 3473 email.setAutofilled(true); |
3514 WebInputElement email2 = | 3474 WebInputElement email2 = GetInputElementById("email2"); |
3515 web_frame->document().getElementById("email2").to<WebInputElement>(); | |
3516 email2.setAutofilled(true); | 3475 email2.setAutofilled(true); |
3517 WebInputElement phone = | 3476 WebInputElement phone = GetInputElementById("phone"); |
3518 web_frame->document().getElementById("phone").to<WebInputElement>(); | |
3519 phone.setAutofilled(true); | 3477 phone.setAutofilled(true); |
3520 | 3478 |
3521 // Set the suggested values on all of the elements. | 3479 // Set the suggested values on all of the elements. |
3522 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); | 3480 firstname.setSuggestedValue(ASCIIToUTF16("Wyatt")); |
3523 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); | 3481 lastname.setSuggestedValue(ASCIIToUTF16("Earp")); |
3524 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3482 email.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3525 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); | 3483 email2.setSuggestedValue(ASCIIToUTF16("wyatt@earp.com")); |
3526 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); | 3484 phone.setSuggestedValue(ASCIIToUTF16("650-777-9999")); |
3527 | 3485 |
3528 // Clear the previewed fields. | 3486 // Clear the previewed fields. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3563 "</FORM>"); | 3521 "</FORM>"); |
3564 | 3522 |
3565 WebFrame* web_frame = GetMainFrame(); | 3523 WebFrame* web_frame = GetMainFrame(); |
3566 ASSERT_NE(nullptr, web_frame); | 3524 ASSERT_NE(nullptr, web_frame); |
3567 | 3525 |
3568 FormCache form_cache; | 3526 FormCache form_cache; |
3569 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); | 3527 std::vector<FormData> forms = form_cache.ExtractNewForms(*web_frame); |
3570 ASSERT_EQ(1U, forms.size()); | 3528 ASSERT_EQ(1U, forms.size()); |
3571 | 3529 |
3572 // Set the autofilled attribute. | 3530 // Set the autofilled attribute. |
3573 WebInputElement firstname = | 3531 WebInputElement firstname = GetInputElementById("firstname"); |
3574 web_frame->document().getElementById("firstname").to<WebInputElement>(); | |
3575 firstname.setAutofilled(false); | 3532 firstname.setAutofilled(false); |
3576 WebInputElement lastname = | 3533 WebInputElement lastname = GetInputElementById("lastname"); |
3577 web_frame->document().getElementById("lastname").to<WebInputElement>(); | |
3578 lastname.setAutofilled(true); | 3534 lastname.setAutofilled(true); |
3579 WebInputElement email = | 3535 WebInputElement email = GetInputElementById("email"); |
3580 web_frame->document().getElementById("email").to<WebInputElement>(); | |
3581 email.setAutofilled(true); | 3536 email.setAutofilled(true); |
3582 WebInputElement phone = | 3537 WebInputElement phone = GetInputElementById("phone"); |
3583 web_frame->document().getElementById("phone").to<WebInputElement>(); | |
3584 phone.setAutofilled(true); | 3538 phone.setAutofilled(true); |
3585 | 3539 |
3586 // Clear the fields. | 3540 // Clear the fields. |
3587 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); | 3541 EXPECT_TRUE(form_cache.ClearFormWithElement(firstname)); |
3588 | 3542 |
3589 // Verify only autofilled fields are cleared. | 3543 // Verify only autofilled fields are cleared. |
3590 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); | 3544 EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value()); |
3591 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); | 3545 EXPECT_TRUE(firstname.suggestedValue().isEmpty()); |
3592 EXPECT_FALSE(firstname.isAutofilled()); | 3546 EXPECT_FALSE(firstname.isAutofilled()); |
3593 EXPECT_TRUE(lastname.value().isEmpty()); | 3547 EXPECT_TRUE(lastname.value().isEmpty()); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3888 frame->document().all(), &fieldsets); | 3842 frame->document().all(), &fieldsets); |
3889 ASSERT_EQ(0U, control_elements.size()); | 3843 ASSERT_EQ(0U, control_elements.size()); |
3890 ASSERT_EQ(0U, fieldsets.size()); | 3844 ASSERT_EQ(0U, fieldsets.size()); |
3891 | 3845 |
3892 FormData form; | 3846 FormData form; |
3893 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( | 3847 EXPECT_FALSE(UnownedFormElementsAndFieldSetsToFormData( |
3894 fieldsets, control_elements, dummy_origin, extract_mask, &form)); | 3848 fieldsets, control_elements, dummy_origin, extract_mask, &form)); |
3895 } | 3849 } |
3896 | 3850 |
3897 } // namespace autofill | 3851 } // namespace autofill |
OLD | NEW |