OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
7 #include "chrome/renderer/form_manager.h" | 7 #include "chrome/renderer/form_manager.h" |
8 #include "chrome/test/render_view_test.h" | 8 #include "chrome/test/render_view_test.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" | 10 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" |
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); | 1581 EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
1582 EXPECT_EQ(GURL(web_frame->url()), form.origin); | 1582 EXPECT_EQ(GURL(web_frame->url()), form.origin); |
1583 EXPECT_EQ(GURL("http://buh.com"), form.action); | 1583 EXPECT_EQ(GURL("http://buh.com"), form.action); |
1584 | 1584 |
1585 const std::vector<FormField>& fields = form.fields; | 1585 const std::vector<FormField>& fields = form.fields; |
1586 ASSERT_EQ(3U, fields.size()); | 1586 ASSERT_EQ(3U, fields.size()); |
1587 EXPECT_EQ(FormField(string16(), | 1587 EXPECT_EQ(FormField(string16(), |
1588 ASCIIToUTF16("firstname"), | 1588 ASCIIToUTF16("firstname"), |
1589 string16(), | 1589 string16(), |
1590 ASCIIToUTF16("text"), | 1590 ASCIIToUTF16("text"), |
1591 20), | 1591 5), |
1592 fields[0]); | 1592 fields[0]); |
1593 EXPECT_EQ(FormField(string16(), | 1593 EXPECT_EQ(FormField(string16(), |
1594 ASCIIToUTF16("lastname"), | 1594 ASCIIToUTF16("lastname"), |
1595 string16(), | 1595 string16(), |
1596 ASCIIToUTF16("text"), | 1596 ASCIIToUTF16("text"), |
1597 20), | 1597 5), |
1598 fields[1]); | 1598 fields[1]); |
1599 EXPECT_EQ(FormField(string16(), | 1599 EXPECT_EQ(FormField(string16(), |
1600 ASCIIToUTF16("reply-send"), | 1600 ASCIIToUTF16("reply-send"), |
1601 ASCIIToUTF16("Send"), | 1601 ASCIIToUTF16("Send"), |
1602 ASCIIToUTF16("submit"), | 1602 ASCIIToUTF16("submit"), |
1603 0), | 1603 0), |
1604 fields[2]); | 1604 fields[2]); |
1605 | 1605 |
1606 // Fill the form. | 1606 // Fill the form. |
1607 form.fields[0].set_value(ASCIIToUTF16("Brother")); | 1607 form.fields[0].set_value(ASCIIToUTF16("Brother")); |
1608 form.fields[1].set_value(ASCIIToUTF16("Jonathan")); | 1608 form.fields[1].set_value(ASCIIToUTF16("Jonathan")); |
1609 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); | 1609 EXPECT_TRUE(form_manager.FillForm(form, WebNode())); |
1610 | 1610 |
1611 // Find the newly-filled form that contains the input element. | 1611 // Find the newly-filled form that contains the input element. |
1612 FormData form2; | 1612 FormData form2; |
1613 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( | 1613 EXPECT_TRUE(form_manager.FindFormWithFormControlElement( |
1614 input_element, FormManager::REQUIRE_NONE, &form2)); | 1614 input_element, FormManager::REQUIRE_NONE, &form2)); |
1615 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); | 1615 EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); |
1616 EXPECT_EQ(GURL(web_frame->url()), form2.origin); | 1616 EXPECT_EQ(GURL(web_frame->url()), form2.origin); |
1617 EXPECT_EQ(GURL("http://buh.com"), form2.action); | 1617 EXPECT_EQ(GURL("http://buh.com"), form2.action); |
1618 | 1618 |
1619 const std::vector<FormField>& fields2 = form2.fields; | 1619 const std::vector<FormField>& fields2 = form2.fields; |
1620 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( | 1620 EXPECT_TRUE(fields2[0].StrictlyEqualsHack( |
1621 FormField(string16(), | 1621 FormField(string16(), |
1622 ASCIIToUTF16("firstname"), | 1622 ASCIIToUTF16("firstname"), |
1623 ASCIIToUTF16("Broth"), | 1623 ASCIIToUTF16("Broth"), |
1624 ASCIIToUTF16("text"), | 1624 ASCIIToUTF16("text"), |
1625 20))); | 1625 5))); |
1626 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( | 1626 EXPECT_TRUE(fields2[1].StrictlyEqualsHack( |
1627 FormField(string16(), | 1627 FormField(string16(), |
1628 ASCIIToUTF16("lastname"), | 1628 ASCIIToUTF16("lastname"), |
1629 ASCIIToUTF16("Jonat"), | 1629 ASCIIToUTF16("Jonat"), |
1630 ASCIIToUTF16("text"), | 1630 ASCIIToUTF16("text"), |
1631 20))); | 1631 5))); |
1632 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( | 1632 EXPECT_TRUE(fields2[2].StrictlyEqualsHack( |
1633 FormField(string16(), | 1633 FormField(string16(), |
1634 ASCIIToUTF16("reply-send"), | 1634 ASCIIToUTF16("reply-send"), |
1635 string16(), | 1635 string16(), |
1636 ASCIIToUTF16("submit"), | 1636 ASCIIToUTF16("submit"), |
1637 0))); | 1637 0))); |
1638 } | 1638 } |
1639 | 1639 |
1640 // This test uses negative values of the maxlength attribute for input elements. | 1640 // This test uses negative values of the maxlength attribute for input elements. |
1641 // In this case, the maxlength of the input elements is set to the default | 1641 // In this case, the maxlength of the input elements is set to the default |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 } | 2325 } |
2326 | 2326 |
2327 | 2327 |
2328 TEST_F(FormManagerTest, SizeFields) { | 2328 TEST_F(FormManagerTest, SizeFields) { |
2329 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 2329 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
2330 " Phone:" | 2330 " Phone:" |
2331 " <input type=\"text\" size=\"3\" name=\"dayphone1\">" | 2331 " <input type=\"text\" size=\"3\" name=\"dayphone1\">" |
2332 " -" | 2332 " -" |
2333 " <input type=\"text\" size=\"3\" name=\"dayphone2\">" | 2333 " <input type=\"text\" size=\"3\" name=\"dayphone2\">" |
2334 " -" | 2334 " -" |
2335 " <input type=\"text\" size=\"4\" name=\"dayphone3\">" | 2335 " <input type=\"text\" maxlength=\"4\" size=\"5\"" |
| 2336 " name=\"dayphone3\">" |
2336 " ext.:" | 2337 " ext.:" |
2337 " <input type=\"text\" size=\"5\" name=\"dayphone4\">" | 2338 " <input type=\"text\" size=\"5\" name=\"dayphone4\">" |
2338 " <input type=\"text\" name=\"default1\">" | 2339 " <input type=\"text\" name=\"default1\">" |
2339 " <input type=\"text\" size=\"-1\" name=\"invalid1\">" | 2340 " <input type=\"text\" size=\"-1\" name=\"invalid1\">" |
2340 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" | 2341 " <input type=\"submit\" name=\"reply-send\" value=\"Send\">" |
2341 "</FORM>"); | 2342 "</FORM>"); |
2342 | 2343 |
2343 | |
2344 WebFrame* frame = GetMainFrame(); | 2344 WebFrame* frame = GetMainFrame(); |
2345 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | 2345 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
2346 | 2346 |
2347 WebVector<WebFormElement> forms; | 2347 WebVector<WebFormElement> forms; |
2348 frame->forms(forms); | 2348 frame->forms(forms); |
2349 ASSERT_EQ(1U, forms.size()); | 2349 ASSERT_EQ(1U, forms.size()); |
2350 | 2350 |
2351 FormData form; | 2351 FormData form; |
2352 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], | 2352 EXPECT_TRUE(FormManager::WebFormElementToFormData(forms[0], |
2353 FormManager::REQUIRE_NONE, | 2353 FormManager::REQUIRE_NONE, |
(...skipping 10 matching lines...) Expand all Loading... |
2364 string16(), | 2364 string16(), |
2365 ASCIIToUTF16("text"), | 2365 ASCIIToUTF16("text"), |
2366 3), | 2366 3), |
2367 fields[0]); | 2367 fields[0]); |
2368 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2368 EXPECT_EQ(FormField(ASCIIToUTF16("-"), |
2369 ASCIIToUTF16("dayphone2"), | 2369 ASCIIToUTF16("dayphone2"), |
2370 string16(), | 2370 string16(), |
2371 ASCIIToUTF16("text"), | 2371 ASCIIToUTF16("text"), |
2372 3), | 2372 3), |
2373 fields[1]); | 2373 fields[1]); |
| 2374 // |maxlength| takes precedence to |size| |
2374 EXPECT_EQ(FormField(ASCIIToUTF16("-"), | 2375 EXPECT_EQ(FormField(ASCIIToUTF16("-"), |
2375 ASCIIToUTF16("dayphone3"), | 2376 ASCIIToUTF16("dayphone3"), |
2376 string16(), | 2377 string16(), |
2377 ASCIIToUTF16("text"), | 2378 ASCIIToUTF16("text"), |
2378 4), | 2379 4), |
2379 fields[2]); | 2380 fields[2]); |
2380 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), | 2381 EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"), |
2381 ASCIIToUTF16("dayphone4"), | 2382 ASCIIToUTF16("dayphone4"), |
2382 string16(), | 2383 string16(), |
2383 ASCIIToUTF16("text"), | 2384 ASCIIToUTF16("text"), |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2972 0))); | 2973 0))); |
2973 EXPECT_TRUE(fields[3].StrictlyEqualsHack( | 2974 EXPECT_TRUE(fields[3].StrictlyEqualsHack( |
2974 FormField(string16(), | 2975 FormField(string16(), |
2975 ASCIIToUTF16("reply-send"), | 2976 ASCIIToUTF16("reply-send"), |
2976 string16(), | 2977 string16(), |
2977 ASCIIToUTF16("submit"), | 2978 ASCIIToUTF16("submit"), |
2978 0))); | 2979 0))); |
2979 } | 2980 } |
2980 | 2981 |
2981 } // namespace | 2982 } // namespace |
OLD | NEW |