#include "chrome/test/base/chrome_render_view_test.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
#include "components/autofill/content/renderer/form_cache.h"
+#include "components/autofill/core/common/autofill_data_validation.h"
#include "components/autofill/core/common/form_data.h"
#include "components/autofill/core/common/web_element_descriptor.h"
#include "components/variations/entropy_provider.h"
#include "third_party/WebKit/public/web/WebFormControlElement.h"
#include "third_party/WebKit/public/web/WebFormElement.h"
#include "third_party/WebKit/public/web/WebInputElement.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebNode.h"
#include "third_party/WebKit/public/web/WebSelectElement.h"
#include "third_party/WebKit/public/web/WebTextAreaElement.h"
};
static const char kFormHtml[] =
- "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"hidden\" id=\"imhidden\"/>"
- " <INPUT type=\"text\" id=\"notempty\" value=\"Hi\"/>"
- " <INPUT type=\"text\" autocomplete=\"off\" id=\"noautocomplete\"/>"
- " <INPUT type=\"text\" disabled=\"disabled\" id=\"notenabled\"/>"
- " <INPUT type=\"text\" readonly id=\"readonly\"/>"
- " <INPUT type=\"text\" style=\"visibility: hidden\""
- " id=\"invisible\"/>"
- " <INPUT type=\"text\" style=\"display: none\" id=\"displaynone\"/>"
- " <INPUT type=\"month\" id=\"month\"/>"
- " <INPUT type=\"month\" id=\"month-nonempty\" value=\"2011-12\"/>"
- " <SELECT id=\"select\">"
+ "<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='hidden' id='imhidden'/>"
+ " <INPUT type='text' id='notempty' value='Hi'/>"
+ " <INPUT type='text' autocomplete='off' id='noautocomplete'/>"
+ " <INPUT type='text' disabled='disabled' id='notenabled'/>"
+ " <INPUT type='text' readonly id='readonly'/>"
+ " <INPUT type='text' style='visibility: hidden'"
+ " id='invisible'/>"
+ " <INPUT type='text' style='display: none' id='displaynone'/>"
+ " <INPUT type='month' id='month'/>"
+ " <INPUT type='month' id='month-nonempty' value='2011-12'/>"
+ " <SELECT id='select'>"
" <OPTION></OPTION>"
- " <OPTION value=\"CA\">California</OPTION>"
- " <OPTION value=\"TX\">Texas</OPTION>"
+ " <OPTION value='CA'>California</OPTION>"
+ " <OPTION value='TX'>Texas</OPTION>"
" </SELECT>"
- " <SELECT id=\"select-nonempty\">"
- " <OPTION value=\"CA\" selected>California</OPTION>"
- " <OPTION value=\"TX\">Texas</OPTION>"
+ " <SELECT id='select-nonempty'>"
+ " <OPTION value='CA' selected>California</OPTION>"
+ " <OPTION value='TX'>Texas</OPTION>"
" </SELECT>"
- " <TEXTAREA id=\"textarea\"></TEXTAREA>"
- " <TEXTAREA id=\"textarea-nonempty\">Go away!</TEXTAREA>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <SELECT id='select-unchanged'>"
+ " <OPTION value='CA' selected>California</OPTION>"
+ " <OPTION value='TX'>Texas</OPTION>"
+ " </SELECT>"
+ " <TEXTAREA id='textarea'></TEXTAREA>"
+ " <TEXTAREA id='textarea-nonempty'>Go away!</TEXTAREA>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>";
} // namespace
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
const FormData& form = forms[0];
}
typedef void (*FillFormFunction)(const FormData& form,
- const WebInputElement& element);
+ const WebFormControlElement& element);
typedef WebString (*GetValueFunction)(WebFormControlElement element);
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
FormData form_data;
FormFieldData field;
EXPECT_TRUE(
- FindFormAndFieldForInputElement(input_element,
- &form_data,
- &field,
- autofill::REQUIRE_AUTOCOMPLETE));
+ FindFormAndFieldForFormControlElement(input_element,
+ &form_data,
+ &field,
+ autofill::REQUIRE_AUTOCOMPLETE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form_data.name);
EXPECT_EQ(GURL(web_frame->document().url()), form_data.origin);
EXPECT_EQ(GURL("http://buh.com"), form_data.action);
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[i]);
// Fill the form_data for the field.
form_data.fields[i].value = ASCIIToUTF16(field_cases[i].autofill_value);
+ // Set the is_autofilled property for the field.
+ form_data.fields[i].is_autofilled = field_cases[i].should_be_autofilled;
}
// Autofill the form using the given fill form function.
WebString value;
WebFormControlElement element = GetMainFrame()->document().getElementById(
ASCIIToUTF16(field_case.name)).to<WebFormControlElement>();
- if (element.formControlType() == "select-one") {
- value = element.to<WebSelectElement>().value();
- } else if (element.formControlType() == "textarea") {
+ if ((element.formControlType() == "select-one") ||
+ (element.formControlType() == "textarea")) {
value = get_value_function(element);
} else {
ASSERT_TRUE(element.formControlType() == "text" ||
EXPECT_EQ(field_case.should_be_autofilled, element.isAutofilled());
}
- static void FillFormForAllFieldsWrapper(const FormData& form,
- const WebInputElement& element) {
- FillFormForAllElements(form, element.form());
- }
-
static void FillFormIncludingNonFocusableElementsWrapper(
const FormData& form,
- const WebInputElement& element) {
+ const WebFormControlElement& element) {
FillFormIncludingNonFocusableElements(form, element.form());
}
if (element.formControlType() == "textarea")
return element.to<WebTextAreaElement>().value();
+ if (element.formControlType() == "select-one")
+ return element.to<WebSelectElement>().value();
+
return element.to<WebInputElement>().value();
}
if (element.formControlType() == "textarea")
return element.to<WebTextAreaElement>().suggestedValue();
+ if (element.formControlType() == "select-one")
+ return element.to<WebSelectElement>().suggestedValue();
+
return element.to<WebInputElement>().suggestedValue();
}
// We should be able to extract a normal text field.
TEST_F(FormAutofillTest, WebFormControlElementToFormField) {
- LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
+ LoadHTML("<INPUT type='text' id='element' value='value'/>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// We should be able to extract a text field with autocomplete="off".
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompleteOff) {
- LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\""
- " autocomplete=\"off\"/>");
+ LoadHTML("<INPUT type='text' id='element' value='value'"
+ " autocomplete='off'/>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// We should be able to extract a text field with maxlength specified.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMaxLength) {
- LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\""
- " maxlength=\"5\"/>");
+ LoadHTML("<INPUT type='text' id='element' value='value'"
+ " maxlength='5'/>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// We should be able to extract a text field that has been autofilled.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutofilled) {
- LoadHTML("<INPUT type=\"text\" id=\"element\" value=\"value\"/>");
+ LoadHTML("<INPUT type='text' id='element' value='value'/>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// We should be able to extract a radio or a checkbox field that has been
// autofilled.
TEST_F(FormAutofillTest, WebFormControlElementToClickableFormField) {
- LoadHTML("<INPUT type=\"checkbox\" id=\"checkbox\" value=\"mail\" checked/>"
- "<INPUT type=\"radio\" id=\"radio\" value=\"male\"/>");
+ LoadHTML("<INPUT type='checkbox' id='checkbox' value='mail' checked/>"
+ "<INPUT type='radio' id='radio' value='male'/>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// We should be able to extract a <select> field.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldSelect) {
- LoadHTML("<SELECT id=\"element\"/>"
- " <OPTION value=\"CA\">California</OPTION>"
- " <OPTION value=\"TX\">Texas</OPTION>"
+ LoadHTML("<SELECT id='element'/>"
+ " <OPTION value='CA'>California</OPTION>"
+ " <OPTION value='TX'>Texas</OPTION>"
"</SELECT>");
WebFrame* frame = GetMainFrame();
EXPECT_EQ(ASCIIToUTF16("Texas"), result3.option_contents[1]);
}
+// When faced with <select> field with *many* options, we should trim them to a
+// reasonable number.
+TEST_F(FormAutofillTest, WebFormControlElementToFormFieldLongSelect) {
+ std::string html = "<SELECT id='element'/>";
+ for (size_t i = 0; i < 2 * kMaxListSize; ++i) {
+ html += base::StringPrintf("<OPTION value='%" PRIuS "'>"
+ "%" PRIuS "</OPTION>", i, i);
+ }
+ html += "</SELECT>";
+ LoadHTML(html.c_str());
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_TRUE(frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_OPTIONS, &result);
+
+ EXPECT_EQ(0U, result.option_values.size());
+ EXPECT_EQ(0U, result.option_contents.size());
+}
+
// We should be able to extract a <textarea> field.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldTextArea) {
- LoadHTML("<TEXTAREA id=\"element\">"
+ LoadHTML("<TEXTAREA id='element'>"
"This element's value "
"spans multiple lines."
"</TEXTAREA>");
// We should be able to extract an <input type="month"> field.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldMonthInput) {
- LoadHTML("<INPUT type=\"month\" id=\"element\" value=\"2011-12\">");
+ LoadHTML("<INPUT type='month' id='element' value='2011-12'>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// We should not extract the value for non-text and non-select fields.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldInvalidType) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"hidden\" id=\"hidden\" value=\"apple\"/>"
- " <INPUT type=\"submit\" id=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='hidden' id='hidden' value='apple'/>"
+ " <INPUT type='submit' id='submit' value='Send'/>"
"</FORM>");
WebFrame* frame = GetMainFrame();
// We should be able to extract password fields.
TEST_F(FormAutofillTest, WebFormControlElementToPasswordFormField) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='password' id='password' value='secret'/>"
"</FORM>");
WebFrame* frame = GetMainFrame();
// We should be able to extract the autocompletetype attribute.
TEST_F(FormAutofillTest, WebFormControlElementToFormFieldAutocompletetype) {
std::string html =
- "<INPUT type=\"text\" id=\"absent\"/>"
- "<INPUT type=\"text\" id=\"empty\" autocomplete=\"\"/>"
- "<INPUT type=\"text\" id=\"off\" autocomplete=\"off\"/>"
- "<INPUT type=\"text\" id=\"regular\" autocomplete=\"email\"/>"
- "<INPUT type=\"text\" id=\"multi-valued\" "
- " autocomplete=\"billing email\"/>"
- "<INPUT type=\"text\" id=\"experimental\" x-autocompletetype=\"email\"/>"
- "<INPUT type=\"month\" id=\"month\" autocomplete=\"cc-exp\"/>"
- "<SELECT id=\"select\" autocomplete=\"state\"/>"
- " <OPTION value=\"CA\">California</OPTION>"
- " <OPTION value=\"TX\">Texas</OPTION>"
+ "<INPUT type='text' id='absent'/>"
+ "<INPUT type='text' id='empty' autocomplete=''/>"
+ "<INPUT type='text' id='off' autocomplete='off'/>"
+ "<INPUT type='text' id='regular' autocomplete='email'/>"
+ "<INPUT type='text' id='multi-valued' "
+ " autocomplete='billing email'/>"
+ "<INPUT type='text' id='experimental' x-autocompletetype='email'/>"
+ "<INPUT type='month' id='month' autocomplete='cc-exp'/>"
+ "<SELECT id='select' autocomplete='state'/>"
+ " <OPTION value='CA'>California</OPTION>"
+ " <OPTION value='TX'>Texas</OPTION>"
"</SELECT>"
- "<TEXTAREA id=\"textarea\" autocomplete=\"street-address\">"
+ "<TEXTAREA id='textarea' autocomplete='street-address'>"
" Some multi-"
" lined value"
"</TEXTAREA>";
html +=
- "<INPUT type=\"text\" id=\"malicious\" autocomplete=\"" +
- std::string(10000, 'x') + "\"/>";
+ "<INPUT type='text' id='malicious' autocomplete='" +
+ std::string(10000, 'x') + "'/>";
LoadHTML(html.c_str());
WebFrame* frame = GetMainFrame();
}
}
+TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) {
+ LoadHTML("<STYLE>input{direction:rtl}</STYLE>"
+ "<FORM>"
+ " <INPUT type='text' id='element'>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
+}
+
+TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) {
+ LoadHTML("<FORM>"
+ " <INPUT dir='rtl' type='text' id='element'/>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
+}
+
+TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) {
+ LoadHTML("<STYLE>form{direction:rtl}</STYLE>"
+ "<FORM>"
+ " <INPUT type='text' id='element'/>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
+}
+
+TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) {
+ LoadHTML("<FORM dir='rtl'>"
+ " <INPUT type='text' id='element'/>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
+}
+
+TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) {
+ LoadHTML("<STYLE>input{direction:ltr}</STYLE>"
+ "<FORM dir='rtl'>"
+ " <INPUT type='text' id='element'/>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction);
+}
+
+TEST_F(FormAutofillTest,
+ DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) {
+ LoadHTML("<STYLE>form{direction:ltr}</STYLE>"
+ "<FORM dir='rtl'>"
+ " <INPUT type='text' id='element'/>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction);
+}
+
+TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) {
+ LoadHTML("<FORM style='direction:ltr'>"
+ " <SPAN dir='rtl'>"
+ " <INPUT type='text' id='element'/>"
+ " </SPAN>"
+ "</FORM>");
+
+ WebFrame* frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
+
+ WebElement web_element = frame->document().getElementById("element");
+ WebFormControlElement element = web_element.to<WebFormControlElement>();
+
+ FormFieldData result;
+ WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result);
+ EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction);
+}
+
TEST_F(FormAutofillTest, WebFormElementToFormData) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <LABEL for=\"firstname\">First name:</LABEL>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <LABEL for=\"lastname\">Last name:</LABEL>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <LABEL for=\"street-address\">Address:</LABEL>"
- " <TEXTAREA id=\"street-address\">"
- "123 Fantasy Ln. "
- "Apt. 42"
- "</TEXTAREA>"
- " <LABEL for=\"state\">State:</LABEL>"
- " <SELECT id=\"state\"/>"
- " <OPTION value=\"CA\">California</OPTION>"
- " <OPTION value=\"TX\">Texas</OPTION>"
- " </SELECT>"
- " <LABEL for=\"password\">Password:</LABEL>"
- " <INPUT type=\"password\" id=\"password\" value=\"secret\"/>"
- " <LABEL for=\"month\">Card expiration:</LABEL>"
- " <INPUT type=\"month\" id=\"month\" value=\"2011-12\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <LABEL for='firstname'>First name:</LABEL>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <LABEL for='lastname'>Last name:</LABEL>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <LABEL for='street-address'>Address:</LABEL>"
+ " <TEXTAREA id='street-address'>"
+ "123 Fantasy Ln. "
+ "Apt. 42"
+ "</TEXTAREA>"
+ " <LABEL for='state'>State:</LABEL>"
+ " <SELECT id='state'/>"
+ " <OPTION value='CA'>California</OPTION>"
+ " <OPTION value='TX'>Texas</OPTION>"
+ " </SELECT>"
+ " <LABEL for='password'>Password:</LABEL>"
+ " <INPUT type='password' id='password' value='secret'/>"
+ " <LABEL for='month'>Card expiration:</LABEL>"
+ " <INPUT type='month' id='month' value='2011-12'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
// The below inputs should be ignored
- " <LABEL for=\"notvisible\">Hidden:</LABEL>"
- " <INPUT type=\"hidden\" id=\"notvisible\" value=\"apple\"/>"
+ " <LABEL for='notvisible'>Hidden:</LABEL>"
+ " <INPUT type='hidden' id='notvisible' value='apple'/>"
"</FORM>");
WebFrame* frame = GetMainFrame();
// We should not be able to serialize a form with too many fillable fields.
TEST_F(FormAutofillTest, WebFormElementToFormDataTooManyFields) {
std::string html =
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">";
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>";
for (size_t i = 0; i < (autofill::kMaxParseableFields + 1); ++i) {
- html += "<INPUT type=\"text\"/>";
+ html += "<INPUT type='text'/>";
}
html += "</FORM>";
LoadHTML(html.c_str());
TEST_F(FormAutofillTest, ExtractForms) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " First name: <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " Last name: <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " Email: <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " First name: <INPUT type='text' id='firstname' value='John'/>"
+ " Last name: <INPUT type='text' id='lastname' value='Smith'/>"
+ " Email: <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, ExtractMultipleForms) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>"
- "<FORM name=\"TestForm2\" action=\"http://zoo.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"Jack\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Adams\"/>"
- " <INPUT type=\"text\" id=\"email\" value=\"jack@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<FORM name='TestForm2' action='http://zoo.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='Jack'/>"
+ " <INPUT type='text' id='lastname' value='Adams'/>"
+ " <INPUT type='text' id='email' value='jack@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(2U, forms.size());
// First form.
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
}
+TEST_F(FormAutofillTest, OnlyExtractNewForms) {
+ LoadHTML(
+ "<FORM id='testform' action='http://cnn.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
+ "</FORM>");
+
+ WebFrame* web_frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
+
+ FormCache form_cache;
+ std::vector<FormData> forms;
+ form_cache.ExtractNewForms(*web_frame, &forms);
+ ASSERT_EQ(1U, forms.size());
+ forms.clear();
+
+ // Second call should give nothing as there are no new forms.
+ form_cache.ExtractNewForms(*web_frame, &forms);
+ ASSERT_EQ(0U, forms.size());
+
+ // Append to the current form will re-extract.
+ ExecuteJavaScript(
+ "var newInput = document.createElement('input');"
+ "newInput.setAttribute('type', 'text');"
+ "newInput.setAttribute('id', 'telephone');"
+ "newInput.value = '12345';"
+ "document.getElementById('testform').appendChild(newInput);");
+ msg_loop_.RunUntilIdle();
+
+ form_cache.ExtractNewForms(*web_frame, &forms);
+ ASSERT_EQ(1U, forms.size());
+
+ const std::vector<FormFieldData>& fields = forms[0].fields;
+ ASSERT_EQ(4U, fields.size());
+
+ FormFieldData expected;
+ expected.form_control_type = "text";
+ expected.max_length = WebInputElement::defaultMaxLength();
+
+ expected.name = ASCIIToUTF16("firstname");
+ expected.value = ASCIIToUTF16("John");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
+
+ expected.name = ASCIIToUTF16("lastname");
+ expected.value = ASCIIToUTF16("Smith");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
+
+ expected.name = ASCIIToUTF16("email");
+ expected.value = ASCIIToUTF16("john@example.com");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
+
+ expected.name = ASCIIToUTF16("telephone");
+ expected.value = ASCIIToUTF16("12345");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
+
+ forms.clear();
+
+ // Completely new form will also be extracted.
+ ExecuteJavaScript(
+ "var newForm=document.createElement('form');"
+ "newForm.id='new_testform';"
+ "newForm.action='http://google.com';"
+ "newForm.method='post';"
+ "var newFirstname=document.createElement('input');"
+ "newFirstname.setAttribute('type', 'text');"
+ "newFirstname.setAttribute('id', 'second_firstname');"
+ "newFirstname.value = 'Bob';"
+ "var newLastname=document.createElement('input');"
+ "newLastname.setAttribute('type', 'text');"
+ "newLastname.setAttribute('id', 'second_lastname');"
+ "newLastname.value = 'Hope';"
+ "var newEmail=document.createElement('input');"
+ "newEmail.setAttribute('type', 'text');"
+ "newEmail.setAttribute('id', 'second_email');"
+ "newEmail.value = 'bobhope@example.com';"
+ "newForm.appendChild(newFirstname);"
+ "newForm.appendChild(newLastname);"
+ "newForm.appendChild(newEmail);"
+ "document.body.appendChild(newForm);");
+ msg_loop_.RunUntilIdle();
+
+ web_frame = GetMainFrame();
+ form_cache.ExtractNewForms(*web_frame, &forms);
+ ASSERT_EQ(1U, forms.size());
+
+ const std::vector<FormFieldData>& fields2 = forms[0].fields;
+ ASSERT_EQ(3U, fields2.size());
+
+ expected.name = ASCIIToUTF16("second_firstname");
+ expected.value = ASCIIToUTF16("Bob");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
+
+ expected.name = ASCIIToUTF16("second_lastname");
+ expected.value = ASCIIToUTF16("Hope");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
+
+ expected.name = ASCIIToUTF16("second_email");
+ expected.value = ASCIIToUTF16("bobhope@example.com");
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
+}
+
// We should not extract a form if it has too few fillable fields.
TEST_F(FormAutofillTest, ExtractFormsTooFewFields) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
EXPECT_EQ(0U, forms.size());
}
// We should not report additional forms for empty forms.
TEST_F(FormAutofillTest, ExtractFormsSkippedForms) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame,
- 3,
- &forms,
- NULL);
+ form_cache.ExtractNewForms(*web_frame, &forms);
EXPECT_EQ(0U, forms.size());
- EXPECT_TRUE(has_skipped_forms);
}
// We should not report additional forms for empty forms.
TEST_F(FormAutofillTest, ExtractFormsNoFields) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame,
- 3,
- &forms,
- NULL);
+ form_cache.ExtractNewForms(*web_frame, &forms);
EXPECT_EQ(0U, forms.size());
- EXPECT_FALSE(has_skipped_forms);
}
// We should not extract a form if it has too few fillable fields.
// Make sure radio and checkbox fields don't count.
TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <INPUT type=\"radio\" id=\"a_radio\" value=\"0\"/>"
- " <INPUT type=\"checkbox\" id=\"a_check\" value=\"1\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='radio' id='a_radio' value='0'/>"
+ " <INPUT type='checkbox' id='a_check' value='1'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
EXPECT_EQ(0U, forms.size());
}
TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) {
{
// Form is not auto-completable due to autocomplete=off.
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\""
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'"
" autocomplete=off>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
{
// The firstname element is not auto-completable due to autocomplete=off.
- LoadHTML("<FORM name=\"TestForm\" action=\"http://abc.com\" "
- " method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\""
+ LoadHTML("<FORM name='TestForm' action='http://abc.com' "
+ " method='post'>"
+ " <INPUT type='text' id='firstname' value='John'"
" autocomplete=off>"
- " <INPUT type=\"text\" id=\"middlename\" value=\"Jack\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply\" value=\"Send\"/>"
+ " <INPUT type='text' id='middlename' value='Jack'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
}
}
-TEST_F(FormAutofillTest, FindForm) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\""
- "autocomplete=\"off\" />"
- " <INPUT type=\"text\" id=\"phone\" value=\"1.800.555.1234\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+TEST_F(FormAutofillTest, FindFormForInputElement) {
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='text' id='email' value='john@example.com'"
+ "autocomplete='off' />"
+ " <INPUT type='text' id='phone' value='1.800.555.1234'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
// Find the form and verify it's the correct form.
FormData form;
FormFieldData field;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
// Try again, but require autocomplete.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
- autofill::REQUIRE_AUTOCOMPLETE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(
+ input_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_AUTOCOMPLETE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
}
+TEST_F(FormAutofillTest, FindFormForTextAreaElement) {
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <INPUT type='text' id='email' value='john@example.com'"
+ "autocomplete='off' />"
+ " <TEXTAREA id='street-address'>"
+ "123 Fantasy Ln. "
+ "Apt. 42"
+ "</TEXTAREA>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
+ "</FORM>");
+
+ WebFrame* web_frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
+
+ FormCache form_cache;
+ std::vector<FormData> forms;
+ form_cache.ExtractNewForms(*web_frame, &forms);
+ ASSERT_EQ(1U, forms.size());
+
+ // Get the textarea element we want to find.
+ WebElement element = web_frame->document().getElementById("street-address");
+ WebTextAreaElement textarea_element = element.to<WebTextAreaElement>();
+
+ // Find the form and verify it's the correct form.
+ FormData form;
+ FormFieldData field;
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(textarea_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
+ EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
+ EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
+ EXPECT_EQ(GURL("http://buh.com"), form.action);
+
+ const std::vector<FormFieldData>& fields = form.fields;
+ ASSERT_EQ(4U, fields.size());
+
+ FormFieldData expected;
+
+ expected.name = ASCIIToUTF16("firstname");
+ expected.value = ASCIIToUTF16("John");
+ expected.form_control_type = "text";
+ expected.max_length = WebInputElement::defaultMaxLength();
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[0]);
+
+ expected.name = ASCIIToUTF16("lastname");
+ expected.value = ASCIIToUTF16("Smith");
+ expected.form_control_type = "text";
+ expected.max_length = WebInputElement::defaultMaxLength();
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]);
+
+ expected.name = ASCIIToUTF16("email");
+ expected.value = ASCIIToUTF16("john@example.com");
+ expected.autocomplete_attribute = "off";
+ expected.form_control_type = "text";
+ expected.max_length = WebInputElement::defaultMaxLength();
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
+ expected.autocomplete_attribute = std::string(); // reset
+
+ expected.name = ASCIIToUTF16("street-address");
+ expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42");
+ expected.form_control_type = "textarea";
+ expected.max_length = 0;
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[3]);
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, field);
+
+ // Try again, but require autocomplete.
+ FormData form2;
+ FormFieldData field2;
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(
+ textarea_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_AUTOCOMPLETE));
+ EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
+ EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
+ EXPECT_EQ(GURL("http://buh.com"), form2.action);
+
+ const std::vector<FormFieldData>& fields2 = form2.fields;
+ ASSERT_EQ(3U, fields2.size());
+
+ expected.name = ASCIIToUTF16("firstname");
+ expected.value = ASCIIToUTF16("John");
+ expected.form_control_type = "text";
+ expected.max_length = WebInputElement::defaultMaxLength();
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[0]);
+
+ expected.name = ASCIIToUTF16("lastname");
+ expected.value = ASCIIToUTF16("Smith");
+ expected.form_control_type = "text";
+ expected.max_length = WebInputElement::defaultMaxLength();
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
+
+ expected.name = ASCIIToUTF16("street-address");
+ expected.value = ASCIIToUTF16("123 Fantasy Ln.\nApt. 42");
+ expected.form_control_type = "textarea";
+ expected.max_length = 0;
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
+ EXPECT_FORM_FIELD_DATA_EQUALS(expected, field);
+}
+
// Test regular FillForm function.
TEST_F(FormAutofillTest, FillForm) {
static const AutofillFieldCase field_cases[] = {
// Select fields should be autofilled even if they already have a
// non-empty value.
{"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
+ // Select fields should not be autofilled if no new value is passed from
+ // autofill profile. The existing value should not be overriden.
+ {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
// Regular textarea elements should be autofilled.
{"textarea", "textarea", "", "", true, "some multi-\nline value",
"some multi-\nline value"},
// Select fields should be autofilled even if they already have a
// non-empty value.
{"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
+ // Select fields should not be autofilled if no new value is passed from
+ // autofill profile. The existing value should not be overriden.
+ {"select-one", "select-unchanged", "CA", "", false, "CA", "CA"},
// Regular textarea elements should be autofilled.
{"textarea", "textarea", "", "", true, "some multi-\nline value",
"some multi-\nline value"},
// Fields with "display:none" should not previewed.
{"text", "displaynone", "", "", false, "suggested displaynone",
""},
- // Regular <input type="month"> should not be previewed.
- {"month", "month", "", "", false, "2017-11", ""},
+ // Regular <input type="month"> should be previewed.
+ {"month", "month", "", "", true, "2017-11", "2017-11"},
// Non-empty <input type="month"> should not be previewed.
{"month", "month-nonempty", "2011-12", "", false, "2017-11", ""},
- // Regular select fields preview is not yet supported
- {"select-one", "select", "", "", false, "TX", ""},
- // Select fields preview is not yet supported
- {"select-one", "select-nonempty", "CA", "", false, "TX", "CA"},
+ // Regular select fields should be previewed.
+ {"select-one", "select", "", "", true, "TX", "TX"},
+ // Select fields should be previewed even if they already have a
+ // non-empty value.
+ {"select-one", "select-nonempty", "CA", "", true, "TX", "TX"},
+ // Select fields should not be previewed if no suggestion is passed from
+ // autofill profile.
+ {"select-one", "select-unchanged", "CA", "", false, "", ""},
// Normal textarea elements should be previewed.
{"textarea", "textarea", "", "", true, "suggested multi-\nline value",
"suggested multi-\nline value"},
TEST_F(FormAutofillTest, Labels) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <LABEL for=\"firstname\"> First name: </LABEL>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <LABEL for=\"lastname\"> Last name: </LABEL>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <LABEL for=\"email\"> Email: </LABEL>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <LABEL for='firstname'> First name: </LABEL>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <LABEL for='lastname'> Last name: </LABEL>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <LABEL for='email'> Email: </LABEL>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsWithSpans) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <LABEL for=\"firstname\"><span>First name: </span></LABEL>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <LABEL for=\"lastname\"><span>Last name: </span></LABEL>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <LABEL for=\"email\"><span>Email: </span></LABEL>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <LABEL for='firstname'><span>First name: </span></LABEL>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <LABEL for='lastname'><span>Last name: </span></LABEL>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <LABEL for='email'><span>Email: </span></LABEL>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
// label element and apply it to the following input field.
TEST_F(FormAutofillTest, InvalidLabels) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <LABEL for=\"firstname\"> First name: </LABEL>"
- " <INPUT type=\"text\" name=\"firstname\" value=\"John\"/>"
- " <LABEL for=\"lastname\"> Last name: </LABEL>"
- " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\"/>"
- " <LABEL for=\"email\"> Email: </LABEL>"
- " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <LABEL for='firstname'> First name: </LABEL>"
+ " <INPUT type='text' name='firstname' value='John'/>"
+ " <LABEL for='lastname'> Last name: </LABEL>"
+ " <INPUT type='text' name='lastname' value='Smith'/>"
+ " <LABEL for='email'> Email: </LABEL>"
+ " <INPUT type='text' name='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
// element associated with it.
TEST_F(FormAutofillTest, OneLabelElement) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
" First name:"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <LABEL for=\"lastname\">Last name: </LABEL>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <LABEL for='lastname'>Last name: </LABEL>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" Email:"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromText) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
" First name:"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" Last name:"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" Email:"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromParagraph) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <P>First name:</P><INPUT type=\"text\" "
- " id=\"firstname\" value=\"John\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <P>First name:</P><INPUT type='text' "
+ " id='firstname' value='John'/>"
" <P>Last name:</P>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" <P>Email:</P>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromBold) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <B>First name:</B><INPUT type=\"text\" "
- " id=\"firstname\" value=\"John\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <B>First name:</B><INPUT type='text' "
+ " id='firstname' value='John'/>"
" <B>Last name:</B>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" <B>Email:</B>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredPriorToImgOrBr) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " First name:<IMG/><INPUT type=\"text\" "
- " id=\"firstname\" value=\"John\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " First name:<IMG/><INPUT type='text' "
+ " id='firstname' value='John'/>"
" Last name:<IMG/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" Email:<BR/>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromTableCell) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>First name:</TD>"
- " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>"
+ " <TD><INPUT type='text' id='firstname' value='John'/></TD>"
" </TR>"
" <TR>"
" <TD>Last name:</TD>"
- " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>"
+ " <TD><INPUT type='text' id='lastname' value='Smith'/></TD>"
" </TR>"
" <TR>"
" <TD>Email:</TD>"
- " <TD><INPUT type=\"text\" id=\"email\""
- " value=\"john@example.com\"/></TD>"
+ " <TD><INPUT type='text' id='email'"
+ " value='john@example.com'/></TD>"
" </TR>"
" <TR>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
TEST_F(FormAutofillTest, LabelsInferredFromTableCellTH) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TH>First name:</TH>"
- " <TD><INPUT type=\"text\" id=\"firstname\" value=\"John\"/></TD>"
+ " <TD><INPUT type='text' id='firstname' value='John'/></TD>"
" </TR>"
" <TR>"
" <TH>Last name:</TH>"
- " <TD><INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/></TD>"
+ " <TD><INPUT type='text' id='lastname' value='Smith'/></TD>"
" </TR>"
" <TR>"
" <TH>Email:</TH>"
- " <TD><INPUT type=\"text\" id=\"email\""
- " value=\"john@example.com\"/></TD>"
+ " <TD><INPUT type='text' id='email'"
+ " value='john@example.com'/></TD>"
" </TR>"
" <TR>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>"
" </TD>"
" <TD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </FONT>"
" </TD>"
" </TR>"
" </TD>"
" <TD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </FONT>"
" </TD>"
" </TR>"
" </TD>"
" <TD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </FONT>"
" </TD>"
" </TR>"
" <TR>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>"
" </TD>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" </TR>"
" <TR>"
" </TD>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" </TR>"
" <TR>"
" </TD>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>* First Name</TD>"
" <TD>"
" Bogus"
- " <INPUT type=\"hidden\"/>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='hidden'/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>* Last Name</TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>* Email</TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
control_types.push_back("text");
ExpectLabelsAndTypes(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>"
" <TD>"
" <SCRIPT> <!-- function test() { alert('ignored as label'); } -->"
" </SCRIPT>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" </TR>"
" <TR>"
" <NOSCRIPT>"
" <P>Bad</P>"
" </NOSCRIPT>"
- " <INPUT type=\"text\" id=\"middlename\" value=\"Joe\"/>"
+ " <INPUT type='text' id='middlename' value='Joe'/>"
" </TD>"
" </TR>"
" <TR>"
" <B>Last Name</B>"
" </TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" </TR>"
" <TR>"
" <B>Country</B>"
" </TD>"
" <TD>"
- " <SELECT id=\"country\">"
- " <OPTION VALUE=\"US\">The value should be ignored as label."
+ " <SELECT id='country'>"
+ " <OPTION VALUE='US'>The value should be ignored as label."
" </OPTION>"
- " <OPTION VALUE=\"JP\">JAPAN</OPTION>"
+ " <OPTION VALUE='JP'>JAPAN</OPTION>"
" </SELECT>"
" </TD>"
" </TR>"
" </TD>"
" <TD>"
" <!-- This comment should be ignored as inferred label.-->"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD></TD>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
TEST_F(FormAutofillTest, LabelsInferredFromTableLabels) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>"
" <LABEL>First name:</LABEL>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>"
" <LABEL>Last name:</LABEL>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>"
" <LABEL>Email:</LABEL>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
"</TABLE>"
- "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromTableTDInterveningElements) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>"
" First name:"
" <BR>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>"
" Last name:"
" <BR>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>"
" Email:"
" <BR>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
"</TABLE>"
- "<INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
}
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>"
" <SPAN>*</SPAN><B>First Name</B>"
" </TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" </TR>"
" <TR>"
" <SPAN>*</SPAN><B>Last Name</B>"
" </TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" </TR>"
" <TR>"
" <SPAN>*</SPAN><B>Email</B>"
" </TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>"
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<TABLE>"
" <TR>"
" <TD>*First Name</TD>"
" </TR>"
" <TR>"
" <TD>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </TD>"
" <TD>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </TD>"
" </TR>"
" <TR>"
" <TD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </TD>"
" </TR>"
"</TABLE>",
values.push_back(ASCIIToUTF16("1212"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<DIV>"
" <LI>"
" <SPAN>Bogus</SPAN>"
" </LI>"
" <LI>"
" <LABEL><EM>*</EM> Home Phone</LABEL>"
- " <INPUT type=\"text\" id=\"areacode\" value=\"415\"/>"
- " <INPUT type=\"text\" id=\"prefix\" value=\"555\"/>"
- " <INPUT type=\"text\" id=\"suffix\" value=\"1212\"/>"
+ " <INPUT type='text' id='areacode' value='415'/>"
+ " <INPUT type='text' id='prefix' value='555'/>"
+ " <INPUT type='text' id='suffix' value='1212'/>"
" </LI>"
" <LI>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </LI>"
"</DIV>"
"</FORM>",
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<DL>"
" <DT>"
" <SPAN>"
" </DT>"
" <DD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </FONT>"
" </DD>"
" <DT>"
" </DT>"
" <DD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </FONT>"
" </DD>"
" <DT>"
" </DT>"
" <DD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </FONT>"
" </DD>"
" <DT></DT>"
" <DD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </DD>"
"</DL>"
"</FORM>",
values.push_back(base::string16());
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
" Address Line 1:"
- " <INPUT type=\"text\" name=\"Address\"/>"
+ " <INPUT type='text' name='Address'/>"
" Address Line 2:"
- " <INPUT type=\"text\" name=\"Address\"/>"
+ " <INPUT type='text' name='Address'/>"
" Address Line 3:"
- " <INPUT type=\"text\" name=\"Address\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='text' name='Address'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>",
labels, names, values);
}
values.push_back(base::string16());
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
" Phone:"
- " <input type=\"text\" name=\"dayphone1\">"
+ " <input type='text' name='dayphone1'>"
" <img/>"
" -"
" <img/>"
- " <input type=\"text\" name=\"dayphone2\">"
+ " <input type='text' name='dayphone2'>"
" <img/>"
" -"
" <img/>"
- " <input type=\"text\" name=\"dayphone3\">"
+ " <input type='text' name='dayphone3'>"
" ext.:"
- " <input type=\"text\" name=\"dayphone4\">"
- " <input type=\"text\" name=\"dummy\">"
- " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
+ " <input type='text' name='dayphone4'>"
+ " <input type='text' name='dummy'>"
+ " <input type='submit' name='reply-send' value='Send'>"
"</FORM>",
labels, names, values);
}
TEST_F(FormAutofillTest, LabelsInferredFromDivTable) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<DIV>First name:<BR>"
" <SPAN>"
- " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
+ " <INPUT type='text' name='firstname' value='John'>"
" </SPAN>"
"</DIV>"
"<DIV>Last name:<BR>"
" <SPAN>"
- " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">"
+ " <INPUT type='text' name='lastname' value='Smith'>"
" </SPAN>"
"</DIV>"
"<DIV>Email:<BR>"
" <SPAN>"
- " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">"
+ " <INPUT type='text' name='email' value='john@example.com'>"
" </SPAN>"
"</DIV>"
- "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
+ "<input type='submit' name='reply-send' value='Send'>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromDivSiblingTable) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<DIV>First name:</DIV>"
"<DIV>"
" <SPAN>"
- " <INPUT type=\"text\" name=\"firstname\" value=\"John\">"
+ " <INPUT type='text' name='firstname' value='John'>"
" </SPAN>"
"</DIV>"
"<DIV>Last name:</DIV>"
"<DIV>"
" <SPAN>"
- " <INPUT type=\"text\" name=\"lastname\" value=\"Smith\">"
+ " <INPUT type='text' name='lastname' value='Smith'>"
" </SPAN>"
"</DIV>"
"<DIV>Email:</DIV>"
"<DIV>"
" <SPAN>"
- " <INPUT type=\"text\" name=\"email\" value=\"john@example.com\">"
+ " <INPUT type='text' name='email' value='john@example.com'>"
" </SPAN>"
"</DIV>"
- "<input type=\"submit\" name=\"reply-send\" value=\"Send\">"
+ "<input type='submit' name='reply-send' value='Send'>"
"</FORM>");
}
TEST_F(FormAutofillTest, LabelsInferredFromDefinitionListRatherThanDivTable) {
ExpectJohnSmithLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
"<DIV>This is not a label.<BR>"
"<DL>"
" <DT>"
" </DT>"
" <DD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
+ " <INPUT type='text' id='firstname' value='John'/>"
" </FONT>"
" </DD>"
" <DT>"
" </DT>"
" <DD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
" </FONT>"
" </DD>"
" <DT>"
" </DT>"
" <DD>"
" <FONT>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
" </FONT>"
" </DD>"
" <DT></DT>"
" <DD>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
" </DD>"
"</DL>"
"</DIV>"
}
TEST_F(FormAutofillTest, FillFormMaxLength) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" maxlength=\"5\"/>"
- " <INPUT type=\"text\" id=\"lastname\" maxlength=\"7\"/>"
- " <INPUT type=\"text\" id=\"email\" maxlength=\"9\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' maxlength='5'/>"
+ " <INPUT type='text' id='lastname' maxlength='7'/>"
+ " <INPUT type='text' id='email' maxlength='9'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
// Find the form that contains the input element.
FormData form;
FormFieldData field;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
form.fields[0].value = ASCIIToUTF16("Brother");
form.fields[1].value = ASCIIToUTF16("Jonathan");
form.fields[2].value = ASCIIToUTF16("brotherj@example.com");
+ form.fields[0].is_autofilled = true;
+ form.fields[1].is_autofilled = true;
+ form.fields[2].is_autofilled = true;
FillForm(form, input_element);
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
// In this case, the maxlength of the input elements is set to the default
// maxlength (defined in WebKit.)
TEST_F(FormAutofillTest, FillFormNegativeMaxLength) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" maxlength=\"-1\"/>"
- " <INPUT type=\"text\" id=\"lastname\" maxlength=\"-10\"/>"
- " <INPUT type=\"text\" id=\"email\" maxlength=\"-13\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' maxlength='-1'/>"
+ " <INPUT type='text' id='lastname' maxlength='-10'/>"
+ " <INPUT type='text' id='email' maxlength='-13'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
// Find the form that contains the input element.
FormData form;
FormFieldData field;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
}
TEST_F(FormAutofillTest, FillFormEmptyName) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"text\" id=\"email\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='text' id='email'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
// Find the form that contains the input element.
FormData form;
FormFieldData field;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
}
TEST_F(FormAutofillTest, FillFormEmptyFormNames) {
- LoadHTML("<FORM action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\"/>"
- " <INPUT type=\"text\" id=\"middlename\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname'/>"
+ " <INPUT type='text' id='middlename'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>"
- "<FORM action=\"http://abc.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"apple\"/>"
- " <INPUT type=\"text\" id=\"banana\"/>"
- " <INPUT type=\"text\" id=\"cantelope\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ "<FORM action='http://abc.com' method='post'>"
+ " <INPUT type='text' id='apple'/>"
+ " <INPUT type='text' id='banana'/>"
+ " <INPUT type='text' id='cantelope'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(2U, forms.size());
// Get the input element we want to find.
// Find the form that contains the input element.
FormData form;
FormFieldData field;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(base::string16(), form.name);
EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
EXPECT_EQ(GURL("http://abc.com"), form.action);
form.fields[0].value = ASCIIToUTF16("Red");
form.fields[1].value = ASCIIToUTF16("Yellow");
form.fields[2].value = ASCIIToUTF16("Also Yellow");
+ form.fields[0].is_autofilled = true;
+ form.fields[1].is_autofilled = true;
+ form.fields[2].is_autofilled = true;
FillForm(form, input_element);
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(base::string16(), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
}
TEST_F(FormAutofillTest, ThreePartPhone) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
" Phone:"
- " <input type=\"text\" name=\"dayphone1\">"
+ " <input type='text' name='dayphone1'>"
" -"
- " <input type=\"text\" name=\"dayphone2\">"
+ " <input type='text' name='dayphone2'>"
" -"
- " <input type=\"text\" name=\"dayphone3\">"
+ " <input type='text' name='dayphone3'>"
" ext.:"
- " <input type=\"text\" name=\"dayphone4\">"
- " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
+ " <input type='text' name='dayphone4'>"
+ " <input type='submit' name='reply-send' value='Send'>"
"</FORM>");
TEST_F(FormAutofillTest, MaxLengthFields) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
" Phone:"
- " <input type=\"text\" maxlength=\"3\" name=\"dayphone1\">"
+ " <input type='text' maxlength='3' name='dayphone1'>"
" -"
- " <input type=\"text\" maxlength=\"3\" name=\"dayphone2\">"
+ " <input type='text' maxlength='3' name='dayphone2'>"
" -"
- " <input type=\"text\" maxlength=\"4\" size=\"5\""
- " name=\"dayphone3\">"
+ " <input type='text' maxlength='4' size='5'"
+ " name='dayphone3'>"
" ext.:"
- " <input type=\"text\" maxlength=\"5\" name=\"dayphone4\">"
- " <input type=\"text\" name=\"default1\">"
- " <input type=\"text\" maxlength=\"-1\" name=\"invalid1\">"
- " <input type=\"submit\" name=\"reply-send\" value=\"Send\">"
+ " <input type='text' maxlength='5' name='dayphone4'>"
+ " <input type='text' name='default1'>"
+ " <input type='text' maxlength='-1' name='invalid1'>"
+ " <input type='submit' name='reply-send' value='Send'>"
"</FORM>");
WebFrame* frame = GetMainFrame();
// profile from the Autofill suggestions popup. The field that is being typed
// into should be filled even though it's not technically empty.
TEST_F(FormAutofillTest, FillFormNonEmptyField) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"text\" id=\"email\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='text' id='email'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Get the input element we want to find.
// Find the form that contains the input element.
FormData form;
FormFieldData field;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form, &field,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form,
+ &field,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name);
EXPECT_EQ(GURL(web_frame->document().url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
form.fields[0].value = ASCIIToUTF16("Wyatt");
form.fields[1].value = ASCIIToUTF16("Earp");
form.fields[2].value = ASCIIToUTF16("wyatt@example.com");
+ form.fields[0].is_autofilled = true;
+ form.fields[1].is_autofilled = true;
+ form.fields[2].is_autofilled = true;
PreviewForm(form, input_element);
EXPECT_EQ(2, input_element.selectionStart());
EXPECT_EQ(5, input_element.selectionEnd());
// Find the newly-filled form that contains the input element.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(input_element, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(input_element,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
TEST_F(FormAutofillTest, ClearFormWithNode) {
LoadHTML(
- "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
- " <INPUT type=\"text\" autocomplete=\"off\" id=\"noAC\" value=\"one\"/>"
- " <INPUT type=\"text\" id=\"notenabled\" disabled=\"disabled\">"
- " <INPUT type=\"month\" id=\"month\" value=\"2012-11\">"
- " <INPUT type=\"month\" id=\"month-disabled\" value=\"2012-11\""
- " disabled=\"disabled\">"
- " <TEXTAREA id=\"textarea\">Apple.</TEXTAREA>"
- " <TEXTAREA id=\"textarea-disabled\" disabled=\"disabled\">"
+ "<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='Wyatt'/>"
+ " <INPUT type='text' id='lastname' value='Earp'/>"
+ " <INPUT type='text' autocomplete='off' id='noAC' value='one'/>"
+ " <INPUT type='text' id='notenabled' disabled='disabled'>"
+ " <INPUT type='month' id='month' value='2012-11'>"
+ " <INPUT type='month' id='month-disabled' value='2012-11'"
+ " disabled='disabled'>"
+ " <TEXTAREA id='textarea'>Apple.</TEXTAREA>"
+ " <TEXTAREA id='textarea-disabled' disabled='disabled'>"
" Banana!"
" </TEXTAREA>"
- " <TEXTAREA id=\"textarea-noAC\" autocomplete=\"off\">Carrot?</TEXTAREA>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ " <TEXTAREA id='textarea-noAC' autocomplete='off'>Carrot?</TEXTAREA>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
- // Set the auto-filled attribute on the firstname element.
+ // Set the auto-filled attribute.
WebInputElement firstname =
web_frame->document().getElementById("firstname").to<WebInputElement>();
firstname.setAutofilled(true);
+ WebInputElement lastname =
+ web_frame->document().getElementById("lastname").to<WebInputElement>();
+ lastname.setAutofilled(true);
+ WebInputElement month =
+ web_frame->document().getElementById("month").to<WebInputElement>();
+ month.setAutofilled(true);
+ WebInputElement textarea =
+ web_frame->document().getElementById("textarea").to<WebInputElement>();
+ textarea.setAutofilled(true);
// Set the value of the disabled text input element.
WebInputElement notenabled =
// Verify the form is cleared.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[1]);
expected.name = ASCIIToUTF16("noAC");
- expected.value = base::string16();
+ expected.value = ASCIIToUTF16("one");
expected.autocomplete_attribute = "off";
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[2]);
expected.autocomplete_attribute = std::string(); // reset
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[7]);
expected.name = ASCIIToUTF16("textarea-noAC");
- expected.value = base::string16();
+ expected.value = ASCIIToUTF16("Carrot?");
expected.autocomplete_attribute = "off";
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields2[8]);
expected.autocomplete_attribute = std::string(); // reset
TEST_F(FormAutofillTest, ClearFormWithNodeContainingSelectOne) {
LoadHTML(
- "<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Earp\"/>"
- " <SELECT id=\"state\" name=\"state\">"
+ "<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='Wyatt'/>"
+ " <INPUT type='text' id='lastname' value='Earp'/>"
+ " <SELECT id='state' name='state'>"
" <OPTION selected>?</OPTION>"
" <OPTION>AA</OPTION>"
" <OPTION>AE</OPTION>"
" <OPTION>AK</OPTION>"
" </SELECT>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
- // Set the auto-filled attribute on the firstname element.
+ // Set the auto-filled attribute.
WebInputElement firstname =
web_frame->document().getElementById("firstname").to<WebInputElement>();
firstname.setAutofilled(true);
+ WebInputElement lastname =
+ web_frame->document().getElementById("lastname").to<WebInputElement>();
+ lastname.setAutofilled(true);
- // Set the value of the select-one.
- WebSelectElement select_element =
+ // Set the value and auto-filled attribute of the state element.
+ WebSelectElement state =
web_frame->document().getElementById("state").to<WebSelectElement>();
- select_element.setValue(WebString::fromUTF8("AK"));
+ state.setValue(WebString::fromUTF8("AK"));
+ state.setAutofilled(true);
// Clear the form.
EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
// Verify the form is cleared.
FormData form2;
FormFieldData field2;
- EXPECT_TRUE(FindFormAndFieldForInputElement(firstname, &form2, &field2,
- autofill::REQUIRE_NONE));
+ EXPECT_TRUE(FindFormAndFieldForFormControlElement(firstname,
+ &form2,
+ &field2,
+ autofill::REQUIRE_NONE));
EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
EXPECT_EQ(GURL(web_frame->document().url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
}
TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"text\" id=\"email\"/>"
- " <INPUT type=\"email\" id=\"email2\"/>"
- " <INPUT type=\"tel\" id=\"phone\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='Wyatt'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='text' id='email'/>"
+ " <INPUT type='email' id='email2'/>"
+ " <INPUT type='tel' id='phone'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
}
TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"text\" id=\"email\"/>"
- " <INPUT type=\"email\" id=\"email2\"/>"
- " <INPUT type=\"tel\" id=\"phone\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='W'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='text' id='email'/>"
+ " <INPUT type='email' id='email2'/>"
+ " <INPUT type='tel' id='phone'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
}
TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"W\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"text\" id=\"email\"/>"
- " <INPUT type=\"email\" id=\"email2\"/>"
- " <INPUT type=\"tel\" id=\"phone\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='W'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='text' id='email'/>"
+ " <INPUT type='email' id='email2'/>"
+ " <INPUT type='tel' id='phone'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
// Set the auto-filled attribute.
EXPECT_FALSE(phone.isAutofilled());
}
+// Autofill's "Clear Form" should clear only autofilled fields
+TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) {
+ // Load the form.
+ LoadHTML(
+ "<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='Wyatt'/>"
+ " <INPUT type='text' id='lastname' value='Earp'/>"
+ " <INPUT type='email' id='email' value='wyatt@earp.com'/>"
+ " <INPUT type='tel' id='phone' value='650-777-9999'/>"
+ " <INPUT type='submit' value='Send'/>"
+ "</FORM>");
+
+ WebFrame* web_frame = GetMainFrame();
+ ASSERT_NE(static_cast<WebFrame*>(NULL), web_frame);
+
+ FormCache form_cache;
+ std::vector<FormData> forms;
+ form_cache.ExtractNewForms(*web_frame, &forms);
+ ASSERT_EQ(1U, forms.size());
+
+ // Set the autofilled attribute.
+ WebInputElement firstname =
+ web_frame->document().getElementById("firstname").to<WebInputElement>();
+ firstname.setAutofilled(false);
+ WebInputElement lastname =
+ web_frame->document().getElementById("lastname").to<WebInputElement>();
+ lastname.setAutofilled(true);
+ WebInputElement email =
+ web_frame->document().getElementById("email").to<WebInputElement>();
+ email.setAutofilled(true);
+ WebInputElement phone =
+ web_frame->document().getElementById("phone").to<WebInputElement>();
+ phone.setAutofilled(true);
+
+ // Clear the fields.
+ EXPECT_TRUE(form_cache.ClearFormWithElement(firstname));
+
+ // Verify only autofilled fields are cleared.
+ EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value());
+ EXPECT_TRUE(firstname.suggestedValue().isEmpty());
+ EXPECT_FALSE(firstname.isAutofilled());
+ EXPECT_TRUE(lastname.value().isEmpty());
+ EXPECT_TRUE(lastname.suggestedValue().isEmpty());
+ EXPECT_FALSE(lastname.isAutofilled());
+ EXPECT_TRUE(email.value().isEmpty());
+ EXPECT_TRUE(email.suggestedValue().isEmpty());
+ EXPECT_FALSE(email.isAutofilled());
+ EXPECT_TRUE(phone.value().isEmpty());
+ EXPECT_TRUE(phone.suggestedValue().isEmpty());
+ EXPECT_FALSE(phone.isAutofilled());
+}
+
TEST_F(FormAutofillTest, FormWithNodeIsAutofilled) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://buh.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"Wyatt\"/>"
- " <INPUT type=\"text\" id=\"lastname\"/>"
- " <INPUT type=\"text\" id=\"email\"/>"
- " <INPUT type=\"email\" id=\"email2\"/>"
- " <INPUT type=\"tel\" id=\"phone\"/>"
- " <INPUT type=\"submit\" value=\"Send\"/>"
+ LoadHTML("<FORM name='TestForm' action='http://buh.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='Wyatt'/>"
+ " <INPUT type='text' id='lastname'/>"
+ " <INPUT type='text' id='email'/>"
+ " <INPUT type='email' id='email2'/>"
+ " <INPUT type='tel' id='phone'/>"
+ " <INPUT type='submit' value='Send'/>"
"</FORM>");
WebFrame* web_frame = GetMainFrame();
FormCache form_cache;
std::vector<FormData> forms;
- form_cache.ExtractForms(*web_frame, &forms);
+ form_cache.ExtractNewForms(*web_frame, &forms);
ASSERT_EQ(1U, forms.size());
WebInputElement firstname =
values.push_back(ASCIIToUTF16("john@example.com"));
ExpectLabels(
- "<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <LABEL for=\"firstname\"> First Name: </LABEL>"
- " <LABEL for=\"firstname\"></LABEL>"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <LABEL for=\"lastname\"></LABEL>"
- " <LABEL for=\"lastname\"> Last Name: </LABEL>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <LABEL for=\"email\"> Email: </LABEL>"
- " <LABEL for=\"email\"> xxx@yyy.com </LABEL>"
- " <INPUT type=\"text\" id=\"email\" value=\"john@example.com\"/>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ "<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <LABEL for='firstname'> First Name: </LABEL>"
+ " <LABEL for='firstname'></LABEL>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <LABEL for='lastname'></LABEL>"
+ " <LABEL for='lastname'> Last Name: </LABEL>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <LABEL for='email'> Email: </LABEL>"
+ " <LABEL for='email'> xxx@yyy.com </LABEL>"
+ " <INPUT type='text' id='email' value='john@example.com'/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>",
labels, names, values);
}
TEST_F(FormAutofillTest, ClickElement) {
- LoadHTML("<BUTTON id=\"link\">Button</BUTTON>"
- "<BUTTON name=\"button\">Button</BUTTON>");
+ LoadHTML("<BUTTON id='link'>Button</BUTTON>"
+ "<BUTTON name='button'>Button</BUTTON>");
WebFrame* frame = GetMainFrame();
ASSERT_NE(static_cast<WebFrame*>(NULL), frame);
// Successful retrieval by css selector.
clicker.retrieval_method = autofill::WebElementDescriptor::CSS_SELECTOR;
- clicker.descriptor = "button[name=\"button\"]";
+ clicker.descriptor = "button[name='button']";
EXPECT_TRUE(ClickElement(frame->document(), clicker));
// Unsuccessful retrieval due to invalid CSS selector.
}
TEST_F(FormAutofillTest, SelectOneAsText) {
- LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">"
- " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>"
- " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>"
- " <SELECT id=\"country\">"
- " <OPTION value=\"AF\">Afghanistan</OPTION>"
- " <OPTION value=\"AL\">Albania</OPTION>"
- " <OPTION value=\"DZ\">Algeria</OPTION>"
+ LoadHTML("<FORM name='TestForm' action='http://cnn.com' method='post'>"
+ " <INPUT type='text' id='firstname' value='John'/>"
+ " <INPUT type='text' id='lastname' value='Smith'/>"
+ " <SELECT id='country'>"
+ " <OPTION value='AF'>Afghanistan</OPTION>"
+ " <OPTION value='AL'>Albania</OPTION>"
+ " <OPTION value='DZ'>Algeria</OPTION>"
" </SELECT>"
- " <INPUT type=\"submit\" name=\"reply-send\" value=\"Send\"/>"
+ " <INPUT type='submit' name='reply-send' value='Send'/>"
"</FORM>");
WebFrame* frame = GetMainFrame();
expected.max_length = 0;
EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]);
}
-
} // namespace autofill