summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-20 00:18:35 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-20 00:18:35 +0000
commited5d53af280ce9b7a1412a38d0b2f96e8433e4d2 (patch)
tree9cb263f209cdb6ce77e97eed3f2ea1460b9d40e5
parent1ed23e569ff71b26d70b5f02a59fa3a621b3620b (diff)
downloadchromium_src-ed5d53af280ce9b7a1412a38d0b2f96e8433e4d2.zip
chromium_src-ed5d53af280ce9b7a1412a38d0b2f96e8433e4d2.tar.gz
chromium_src-ed5d53af280ce9b7a1412a38d0b2f96e8433e4d2.tar.bz2
Autofill: Prefer maxLength to size attribute for form filling heuristics.
BUG=63440 TEST=browser_tests --gtest_filter=FormManagerTest.* Review URL: http://codereview.chromium.org/5137004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66850 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_manager.cc4
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc10
-rw-r--r--chrome/common/render_messages.cc8
-rw-r--r--chrome/renderer/form_manager.cc2
-rw-r--r--chrome/renderer/form_manager_browsertest.cc249
-rw-r--r--chrome/renderer/render_view_browsertest.cc19
-rw-r--r--webkit/glue/form_field.cc16
-rw-r--r--webkit/glue/form_field.h8
8 files changed, 163 insertions, 153 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index 50b31a0..6e0db6b 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -605,12 +605,12 @@ void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile,
bool has_valid_suffix_and_prefix = (number.length() ==
(kAutoFillPhoneNumberPrefixCount + kAutoFillPhoneNumberSuffixCount));
if (has_valid_suffix_and_prefix &&
- field->size() == kAutoFillPhoneNumberPrefixCount) {
+ field->max_length() == kAutoFillPhoneNumberPrefixCount) {
number = number.substr(kAutoFillPhoneNumberPrefixOffset,
kAutoFillPhoneNumberPrefixCount);
field->set_value(number);
} else if (has_valid_suffix_and_prefix &&
- field->size() == kAutoFillPhoneNumberSuffixCount) {
+ field->max_length() == kAutoFillPhoneNumberSuffixCount) {
number = number.substr(kAutoFillPhoneNumberSuffixOffset,
kAutoFillPhoneNumberSuffixCount);
field->set_value(number);
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index 2a0e9e4..e830fa3 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -1338,23 +1338,23 @@ TEST_F(AutoFillManagerTest, FillPhoneNumber) {
autofill_test::CreateTestFormField(
"country code", "country code", "", "text", &field);
- field.set_size(1);
+ field.set_max_length(1);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"area code", "area code", "", "text", &field);
- field.set_size(3);
+ field.set_max_length(3);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"phone", "phone prefix", "1", "text", &field);
- field.set_size(3);
+ field.set_max_length(3);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"-", "phone suffix", "", "text", &field);
- field.set_size(4);
+ field.set_max_length(4);
form.fields.push_back(field);
autofill_test::CreateTestFormField(
"Phone Extension", "ext", "", "text", &field);
- field.set_size(3);
+ field.set_max_length(3);
form.fields.push_back(field);
// Set up our FormStructures.
diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc
index 39ec9be..3842fbd 100644
--- a/chrome/common/render_messages.cc
+++ b/chrome/common/render_messages.cc
@@ -94,20 +94,20 @@ void ParamTraits<webkit_glue::FormField>::Write(Message* m,
WriteParam(m, p.name());
WriteParam(m, p.value());
WriteParam(m, p.form_control_type());
- WriteParam(m, p.size());
+ WriteParam(m, p.max_length());
WriteParam(m, p.option_strings());
}
bool ParamTraits<webkit_glue::FormField>::Read(const Message* m, void** iter,
param_type* p) {
string16 label, name, value, form_control_type;
- int size = 0;
+ int max_length = 0;
std::vector<string16> options;
bool result = ReadParam(m, iter, &label);
result = result && ReadParam(m, iter, &name);
result = result && ReadParam(m, iter, &value);
result = result && ReadParam(m, iter, &form_control_type);
- result = result && ReadParam(m, iter, &size);
+ result = result && ReadParam(m, iter, &max_length);
result = result && ReadParam(m, iter, &options);
if (!result)
return false;
@@ -116,7 +116,7 @@ bool ParamTraits<webkit_glue::FormField>::Read(const Message* m, void** iter,
p->set_name(name);
p->set_value(value);
p->set_form_control_type(form_control_type);
- p->set_size(size);
+ p->set_max_length(max_length);
p->set_option_strings(options);
return true;
}
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 9855a09..d8c931b 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -310,7 +310,7 @@ void FormManager::WebFormControlElementToFormField(
if (element.formControlType() == WebString::fromUTF8("text")) {
const WebInputElement& input_element = element.toConst<WebInputElement>();
- field->set_size(input_element.size());
+ field->set_max_length(input_element.maxLength());
}
if (!(extract_mask & EXTRACT_VALUE))
diff --git a/chrome/renderer/form_manager_browsertest.cc b/chrome/renderer/form_manager_browsertest.cc
index 7a948d8..ffcfc53 100644
--- a/chrome/renderer/form_manager_browsertest.cc
+++ b/chrome/renderer/form_manager_browsertest.cc
@@ -37,6 +37,9 @@ namespace {
typedef RenderViewTest FormManagerTest;
+// TODO(isherman): Pull this as a named constant from WebKit
+const int kDefaultMaxLength = 0x80000;
+
TEST_F(FormManagerTest, WebFormElementToFormData) {
LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
" <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
@@ -68,13 +71,13 @@ TEST_F(FormManagerTest, WebFormElementToFormData) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("notvisible"),
@@ -117,13 +120,13 @@ TEST_F(FormManagerTest, ExtractForms) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -167,13 +170,13 @@ TEST_F(FormManagerTest, ExtractMultipleForms) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -194,13 +197,13 @@ TEST_F(FormManagerTest, ExtractMultipleForms) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -267,13 +270,13 @@ TEST_F(FormManagerTest, GetFormsAutocomplete) {
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Jack"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply"),
@@ -313,13 +316,13 @@ TEST_F(FormManagerTest, GetFormsElementsEnabled) {
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Jack"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("submit"),
@@ -365,13 +368,13 @@ TEST_F(FormManagerTest, FindForm) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -421,13 +424,13 @@ TEST_F(FormManagerTest, FillForm) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("imhidden"),
@@ -439,19 +442,19 @@ TEST_F(FormManagerTest, FillForm) {
ASCIIToUTF16("notempty"),
ASCIIToUTF16("Hi"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[3]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("noautocomplete"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[4]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("notenabled"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[5]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -548,13 +551,13 @@ TEST_F(FormManagerTest, PreviewForm) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("imhidden"),
@@ -566,19 +569,19 @@ TEST_F(FormManagerTest, PreviewForm) {
ASCIIToUTF16("notempty"),
ASCIIToUTF16("Hi"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[3]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("noautocomplete"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[4]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("notenabled"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[5]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -691,13 +694,13 @@ TEST_F(FormManagerTest, Labels) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(
FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -737,13 +740,13 @@ TEST_F(FormManagerTest, LabelsWithSpans) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(
FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -789,13 +792,13 @@ TEST_F(FormManagerTest, InvalidLabels) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(
FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -840,13 +843,13 @@ TEST_F(FormManagerTest, OneLabelElementFirstControlElementDisabled) {
ASCIIToUTF16("middlename"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -886,13 +889,13 @@ TEST_F(FormManagerTest, LabelsInferredFromText) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -975,13 +978,13 @@ TEST_F(FormManagerTest, LabelsInferredFromParagraph) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1032,13 +1035,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCell) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1108,13 +1111,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableCellNested) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1177,13 +1180,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableEmptyTDs) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("*Last Name"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Milton"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1233,13 +1236,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableLabels) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1291,13 +1294,13 @@ TEST_F(FormManagerTest, LabelsInferredFromTableTDInterveningElements) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1364,13 +1367,13 @@ TEST_F(FormManagerTest, LabelsInferredFromDefinitionList) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1410,13 +1413,13 @@ TEST_F(FormManagerTest, LabelsInferredWithSameName) {
ASCIIToUTF16("Address"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Address Line 2:"),
ASCIIToUTF16("Address"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1466,31 +1469,31 @@ TEST_F(FormManagerTest, LabelsInferredWithImageTags) {
ASCIIToUTF16("dayphone1"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone2"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone3"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[2]);
EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"),
ASCIIToUTF16("dayphone4"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[3]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("dummy"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[4]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1536,13 +1539,13 @@ TEST_F(FormManagerTest, LabelsInferredFromDivTable) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("Last Name:"),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1588,13 +1591,13 @@ TEST_F(FormManagerTest, FillFormMaxLength) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ 5),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ 5),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1622,13 +1625,13 @@ TEST_F(FormManagerTest, FillFormMaxLength) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Broth"),
ASCIIToUTF16("text"),
- 20)));
+ 5)));
EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonat"),
ASCIIToUTF16("text"),
- 20)));
+ 5)));
EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1676,13 +1679,13 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1711,13 +1714,13 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -1762,28 +1765,28 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) {
ASCIIToUTF16("prefix"),
string16(),
ASCIIToUTF16("text"),
- 20);
+ kDefaultMaxLength);
form->fields.insert(form->fields.begin(), field1);
FormField field2(string16(),
ASCIIToUTF16("hidden"),
string16(),
ASCIIToUTF16("text"),
- 20);
+ kDefaultMaxLength);
form->fields.insert(form->fields.begin() + 2, field2);
FormField field3(string16(),
ASCIIToUTF16("second"),
string16(),
ASCIIToUTF16("text"),
- 20);
+ kDefaultMaxLength);
form->fields.insert(form->fields.begin() + 4, field3);
FormField field4(string16(),
ASCIIToUTF16("postfix"),
string16(),
ASCIIToUTF16("text"),
- 20);
+ kDefaultMaxLength);
form->fields.insert(form->fields.begin() + 6, field4);
// Fill the form.
@@ -1814,17 +1817,17 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Joseph"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("reply-send"),
string16(),
@@ -1892,37 +1895,37 @@ TEST_F(FormManagerTest, FillFormFewerFormDataFields) {
ASCIIToUTF16("prefix"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("hidden"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Joseph"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("second"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[5].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[6].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("postfix"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[7].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("reply-send"),
string16(),
@@ -1987,17 +1990,17 @@ TEST_F(FormManagerTest, FillFormChangedFormDataFields) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("middlename"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("reply-send"),
string16(),
@@ -2059,22 +2062,22 @@ TEST_F(FormManagerTest, FillFormExtraFieldInCache) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Brother"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("middlename"),
ASCIIToUTF16("Joseph"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Jonathan"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("postfix"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(),
ASCIIToUTF16("reply-send"),
string16(),
@@ -2118,13 +2121,13 @@ TEST_F(FormManagerTest, FillFormEmptyName) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -2152,13 +2155,13 @@ TEST_F(FormManagerTest, FillFormEmptyName) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Wyatt"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Earp"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -2210,13 +2213,13 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) {
ASCIIToUTF16("apple"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("banana"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -2244,13 +2247,13 @@ TEST_F(FormManagerTest, FillFormEmptyFormNames) {
ASCIIToUTF16("apple"),
ASCIIToUTF16("Red"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("banana"),
ASCIIToUTF16("Yellow"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -2296,25 +2299,25 @@ TEST_F(FormManagerTest, ThreePartPhone) {
ASCIIToUTF16("dayphone1"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone2"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(ASCIIToUTF16("-"),
ASCIIToUTF16("dayphone3"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[2]);
EXPECT_EQ(FormField(ASCIIToUTF16("ext.:"),
ASCIIToUTF16("dayphone4"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[3]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -2325,22 +2328,22 @@ TEST_F(FormManagerTest, ThreePartPhone) {
}
-TEST_F(FormManagerTest, SizeFields) {
+TEST_F(FormManagerTest, MaxLengthFields) {
LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
" Phone:"
- " <input type=\"text\" size=\"3\" name=\"dayphone1\">"
+ " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">"
" -"
- " <input type=\"text\" size=\"3\" name=\"dayphone2\">"
+ " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">"
" -"
- " <input type=\"text\" size=\"4\" name=\"dayphone3\">"
+ " <input type=\"text\" maxlength=\"4\" size=\"5\""
+ " name=\"dayphone3\">"
" ext.:"
- " <input type=\"text\" size=\"5\" name=\"dayphone4\">"
+ " <input type=\"text\" maxlength=\"5\" name=\"dayphone4\">"
" <input type=\"text\" name=\"default1\">"
- " <input type=\"text\" size=\"-1\" name=\"invalid1\">"
+ " <input type=\"text\" maxlength=\"-1\" name=\"invalid1\">"
" <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
"</FORM>");
-
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
@@ -2383,19 +2386,19 @@ TEST_F(FormManagerTest, SizeFields) {
ASCIIToUTF16("text"),
5),
fields[3]);
- // When unspecified |size|, default is 20.
+ // When unspecified |size|, default is returned.
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("default1"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[4]);
- // When invalid |size| same value is returned.
+ // When invalid |size|, default is returned.
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("invalid1"),
string16(),
ASCIIToUTF16("text"),
- -1),
+ kDefaultMaxLength),
fields[5]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
@@ -2447,13 +2450,13 @@ TEST_F(FormManagerTest, FillFormNonEmptyField) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -2481,13 +2484,13 @@ TEST_F(FormManagerTest, FillFormNonEmptyField) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("Wyatt"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[0]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Earp"),
ASCIIToUTF16("text"),
- 20),
+ kDefaultMaxLength),
fields2[1]);
EXPECT_EQ(FormField(string16(),
string16(),
@@ -2554,25 +2557,25 @@ TEST_F(FormManagerTest, ClearFormWithNode) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("noAC"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[3].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("notenabled"),
ASCIIToUTF16("no clear"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[4].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("notvisible"),
@@ -2647,13 +2650,13 @@ TEST_F(FormManagerTest, ClearFormWithNodeContainingSelectOne) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
string16(),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("state"),
@@ -2921,13 +2924,13 @@ TEST_F(FormManagerTest, SelectOneAsText) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("country"),
@@ -2957,13 +2960,13 @@ TEST_F(FormManagerTest, SelectOneAsText) {
ASCIIToUTF16("firstname"),
ASCIIToUTF16("John"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
ASCIIToUTF16("Smith"),
ASCIIToUTF16("text"),
- 20)));
+ kDefaultMaxLength)));
EXPECT_TRUE(fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("country"),
diff --git a/chrome/renderer/render_view_browsertest.cc b/chrome/renderer/render_view_browsertest.cc
index 1db074a..dafab6c 100644
--- a/chrome/renderer/render_view_browsertest.cc
+++ b/chrome/renderer/render_view_browsertest.cc
@@ -38,6 +38,13 @@ using WebKit::WebURLError;
using webkit_glue::FormData;
using webkit_glue::FormField;
+namespace {
+
+// TODO(isherman): Pull this as a named constant from WebKit
+const int kDefaultMaxLength = 0x80000;
+
+} // namespace
+
// Test that we get form state change notifications when input fields change.
TEST_F(RenderViewTest, OnNavStateChanged) {
// Don't want any delay for form state sync changes. This will still post a
@@ -942,13 +949,13 @@ TEST_F(RenderViewTest, SendForms) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20))) << forms[0].fields[0];
+ kDefaultMaxLength))) << forms[0].fields[0];
EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("middlename"),
string16(),
ASCIIToUTF16("text"),
- 20))) << forms[0].fields[1];
+ kDefaultMaxLength))) << forms[0].fields[1];
EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
@@ -985,13 +992,13 @@ TEST_F(RenderViewTest, SendForms) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20))) << form2.fields[0];
+ kDefaultMaxLength))) << form2.fields[0];
EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("middlename"),
string16(),
ASCIIToUTF16("text"),
- 20))) << form2.fields[1];
+ kDefaultMaxLength))) << form2.fields[1];
EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("lastname"),
@@ -1026,13 +1033,13 @@ TEST_F(RenderViewTest, FillFormElement) {
ASCIIToUTF16("firstname"),
string16(),
ASCIIToUTF16("text"),
- 20))) << forms[0].fields[0];
+ kDefaultMaxLength))) << forms[0].fields[0];
EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack(
FormField(string16(),
ASCIIToUTF16("middlename"),
string16(),
ASCIIToUTF16("text"),
- 20))) << forms[0].fields[1];
+ kDefaultMaxLength))) << forms[0].fields[1];
// Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected
// field.
diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc
index 30d22ad..ee28766 100644
--- a/webkit/glue/form_field.cc
+++ b/webkit/glue/form_field.cc
@@ -20,13 +20,13 @@ using WebKit::WebVector;
namespace webkit_glue {
FormField::FormField()
- : size_(0) {
+ : max_length_(0) {
}
// TODO(jhawkins): This constructor should probably be deprecated and the
// functionality moved to FormManager.
FormField::FormField(WebFormControlElement element)
- : size_(0) {
+ : max_length_(0) {
name_ = element.nameForAutofill();
// TODO(jhawkins): Extract the field label. For now we just use the field
@@ -37,7 +37,7 @@ FormField::FormField(WebFormControlElement element)
if (form_control_type_ == ASCIIToUTF16("text")) {
const WebInputElement& input_element = element.toConst<WebInputElement>();
value_ = input_element.value();
- size_ = input_element.size();
+ max_length_ = input_element.size();
} else if (form_control_type_ == ASCIIToUTF16("select-one")) {
WebSelectElement select_element = element.to<WebSelectElement>();
value_ = select_element.value();
@@ -58,12 +58,12 @@ FormField::FormField(const string16& label,
const string16& name,
const string16& value,
const string16& form_control_type,
- int size)
+ int max_length)
: label_(label),
name_(name),
value_(value),
form_control_type_(form_control_type),
- size_(size) {
+ max_length_(max_length) {
}
FormField::~FormField() {
@@ -75,7 +75,7 @@ bool FormField::operator==(const FormField& field) const {
return (label_ == field.label_ &&
name_ == field.name_ &&
form_control_type_ == field.form_control_type_ &&
- size_ == field.size_);
+ max_length_ == field.max_length_);
}
bool FormField::operator!=(const FormField& field) const {
@@ -87,7 +87,7 @@ bool FormField::StrictlyEqualsHack(const FormField& field) const {
name_ == field.name_ &&
value_ == field.value_ &&
form_control_type_ == field.form_control_type_ &&
- size_ == field.size_);
+ max_length_ == field.max_length_);
}
std::ostream& operator<<(std::ostream& os, const FormField& field) {
@@ -100,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, const FormField& field) {
<< " "
<< UTF16ToUTF8(field.form_control_type())
<< " "
- << field.size();
+ << field.max_length();
}
} // namespace webkit_glue
diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h
index 1ed8d68..0a22ea6 100644
--- a/webkit/glue/form_field.h
+++ b/webkit/glue/form_field.h
@@ -21,14 +21,14 @@ class FormField {
const string16& name,
const string16& value,
const string16& form_control_type,
- int size);
+ int max_length);
virtual ~FormField();
const string16& label() const { return label_; }
const string16& name() const { return name_; }
const string16& value() const { return value_; }
const string16& form_control_type() const { return form_control_type_; }
- int size() const { return size_; }
+ int max_length() const { return max_length_; }
// Returns option string for elements for which they make sense (select-one,
// for example) for the rest of elements return an empty array.
const std::vector<string16>& option_strings() const {
@@ -41,7 +41,7 @@ class FormField {
void set_form_control_type(const string16& form_control_type) {
form_control_type_ = form_control_type;
}
- void set_size(int size) { size_ = size; }
+ void set_max_length(int max_length) { max_length_ = max_length; }
void set_option_strings(const std::vector<string16>& strings) {
option_strings_ = strings;
}
@@ -62,7 +62,7 @@ class FormField {
string16 name_;
string16 value_;
string16 form_control_type_;
- int size_;
+ int max_length_;
std::vector<string16> option_strings_;
};