| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 489 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 490 | 490 |
| 491 expected.name = ASCIIToUTF16("state"); | 491 expected.name = ASCIIToUTF16("state"); |
| 492 expected.value = ASCIIToUTF16("CA"); | 492 expected.value = ASCIIToUTF16("CA"); |
| 493 expected.label = ASCIIToUTF16("State:"); | 493 expected.label = ASCIIToUTF16("State:"); |
| 494 expected.form_control_type = ASCIIToUTF16("select-one"); | 494 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 495 expected.max_length = 0; | 495 expected.max_length = 0; |
| 496 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 496 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 497 } | 497 } |
| 498 | 498 |
| 499 // We should not be able to serialize a form with too many fillable fields. |
| 500 TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) { |
| 501 std::string html = |
| 502 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"; |
| 503 for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) { |
| 504 html += "<INPUT type=\"text\"/>"; |
| 505 } |
| 506 html += "</FORM>"; |
| 507 LoadHTML(html.c_str()); |
| 508 |
| 509 WebFrame* frame = GetMainFrame(); |
| 510 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 511 |
| 512 WebVector<WebFormElement> forms; |
| 513 frame->document().forms(forms); |
| 514 ASSERT_EQ(1U, forms.size()); |
| 515 |
| 516 WebElement element = frame->document().getElementById("firstname"); |
| 517 WebInputElement input_element = element.to<WebInputElement>(); |
| 518 |
| 519 FormData form; |
| 520 FormField field; |
| 521 EXPECT_FALSE(WebFormElementToFormData(forms[0], |
| 522 input_element, |
| 523 autofill::REQUIRE_NONE, |
| 524 autofill::EXTRACT_VALUE, |
| 525 &form, |
| 526 &field)); |
| 527 } |
| 528 |
| 499 TEST_F(FormAutofillTest, ExtractForms) { | 529 TEST_F(FormAutofillTest, ExtractForms) { |
| 500 ExpectJohnSmithLabels( | 530 ExpectJohnSmithLabels( |
| 501 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 531 "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 502 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 532 " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 503 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 533 " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 504 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" | 534 " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>" |
| 505 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" | 535 " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>" |
| 506 "</FORM>"); | 536 "</FORM>"); |
| 507 } | 537 } |
| 508 | 538 |
| (...skipping 2395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2904 expected.form_control_type = ASCIIToUTF16("text"); | 2934 expected.form_control_type = ASCIIToUTF16("text"); |
| 2905 expected.max_length = WebInputElement::defaultMaxLength(); | 2935 expected.max_length = WebInputElement::defaultMaxLength(); |
| 2906 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); | 2936 EXPECT_FORM_FIELD_EQUALS(expected, fields[1]); |
| 2907 | 2937 |
| 2908 expected.name = ASCIIToUTF16("country"); | 2938 expected.name = ASCIIToUTF16("country"); |
| 2909 expected.value = ASCIIToUTF16("AL"); | 2939 expected.value = ASCIIToUTF16("AL"); |
| 2910 expected.form_control_type = ASCIIToUTF16("select-one"); | 2940 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 2911 expected.max_length = 0; | 2941 expected.max_length = 0; |
| 2912 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); | 2942 EXPECT_FORM_FIELD_EQUALS(expected, fields[2]); |
| 2913 } | 2943 } |
| OLD | NEW |