summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-28 04:47:38 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-28 04:47:38 +0000
commit94d98bfd8ceaafe67d6cd05c6d71d298927516a0 (patch)
treed1d9f01f8c89d02ce5936843ecc1b5ea5f28dc04
parent9beb16d15b82ef461f6a8cdf86597ca30fb7bbad (diff)
downloadchromium_src-94d98bfd8ceaafe67d6cd05c6d71d298927516a0.zip
chromium_src-94d98bfd8ceaafe67d6cd05c6d71d298927516a0.tar.gz
chromium_src-94d98bfd8ceaafe67d6cd05c6d71d298927516a0.tar.bz2
AutoFill: Refactor the code used to fill a form. Don't fill autocomplete=off
or non-empty fields. BUG=45143 TEST=FormManagerTest.FillForm Review URL: http://codereview.chromium.org/2348001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48467 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/form_manager.cc174
-rw-r--r--chrome/renderer/form_manager.h23
-rw-r--r--chrome/renderer/form_manager_unittest.cc518
3 files changed, 358 insertions, 357 deletions
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 83f6ed9..708a62e 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -72,7 +72,7 @@ string16 FindChildTextInner(const WebNode& node) {
return element_text;
}
-// Returns the node value of the first decendant of |element| that is a
+// Returns the node value of the first descendant of |element| that is a
// non-empty text node. "Non-empty" in this case means non-empty after the
// whitespace has been stripped.
string16 FindChildText(const WebElement& element) {
@@ -516,87 +516,11 @@ bool FormManager::FindFormWithFormControlElement(
bool FormManager::FillForm(const FormData& form) {
FormElement* form_element = NULL;
-
- for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin();
- iter != form_elements_map_.end(); ++iter) {
- const WebFrame* frame = iter->first;
-
- for (std::vector<FormElement*>::iterator form_iter = iter->second.begin();
- form_iter != iter->second.end(); ++form_iter) {
- // TODO(dhollowa): matching on form name here which is not guaranteed to
- // be unique for the page, nor is it guaranteed to be non-empty. Need to
- // find a way to uniquely identify the form cross-process. For now we'll
- // check form name and form action for identity.
- // http://crbug.com/37990 test file sample8.html.
- // Also note that WebString() == WebString(string16()) does not seem to
- // evaluate to |true| for some reason TBD, so forcing to string16.
- string16 element_name((*form_iter)->form_element.name());
- GURL action(
- frame->document().completeURL((*form_iter)->form_element.action()));
- if (element_name == form.name && action == form.action) {
- form_element = *form_iter;
- break;
- }
- }
- }
-
- if (!form_element)
+ if (!FindCachedFormElement(form, &form_element))
return false;
- // It's possible that the site has injected fields into the form after the
- // page has loaded, so we can't assert that the size of the cached control
- // elements is equal to the size of the fields in |form|. Fortunately, the
- // one case in the wild where this happens, paypal.com signup form, the fields
- // are appended to the end of the form and are not visible.
-
- for (size_t i = 0, j = 0;
- i < form_element->control_elements.size() && j < form.fields.size();
- ++i) {
- // Once again, empty WebString != empty string16, so we have to explicitly
- // check for this case.
- if (form_element->control_elements[i].nameForAutofill().length() == 0 &&
- form.fields[j].name().empty())
- continue;
-
- size_t k = j;
- while (k < form.fields.size() &&
- form_element->control_elements[i].nameForAutofill() !=
- form.fields[k].name()) {
- k++;
- }
- if (k >= form.fields.size())
- continue;
-
- WebFormControlElement* element = &form_element->control_elements[i];
-
- // It's possible that nameForAutofill() is empty if the form control
- // element has no name or ID. In that case, iter->nameForAutofill() must
- // also be empty.
- if (form.fields[k].name().empty())
- DCHECK(element->nameForAutofill().isEmpty());
- else
- DCHECK_EQ(form.fields[k].name(), element->nameForAutofill());
-
- if (!form.fields[k].value().empty() &&
- element->formControlType() != WebString::fromUTF8("submit")) {
- if (element->formControlType() == WebString::fromUTF8("text")) {
- WebInputElement input_element = element->to<WebInputElement>();
- // If the maxlength attribute contains a negative value, maxLength()
- // returns the default maxlength value.
- input_element.setValue(
- form.fields[k].value().substr(0, input_element.maxLength()));
- input_element.setAutofilled(true);
- } else if (element->formControlType() ==
- WebString::fromUTF8("select-one")) {
- WebSelectElement select_element =
- element->to<WebSelectElement>();
- select_element.setValue(form.fields[k].value());
- }
- }
-
- // We found a matching form field so move on to the next.
- ++j;
- }
+ ForEachMatchingFormField(
+ form_element, form, NewCallback(this, &FormManager::FillFormField));
return true;
}
@@ -687,3 +611,93 @@ string16 FormManager::InferLabelForElement(
return inferred_label;
}
+bool FormManager::FindCachedFormElement(const FormData& form,
+ FormElement** form_element) {
+ for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin();
+ iter != form_elements_map_.end(); ++iter) {
+ const WebFrame* frame = iter->first;
+
+ for (std::vector<FormElement*>::iterator form_iter = iter->second.begin();
+ form_iter != iter->second.end(); ++form_iter) {
+ // TODO(dhollowa): matching on form name here which is not guaranteed to
+ // be unique for the page, nor is it guaranteed to be non-empty. Need to
+ // find a way to uniquely identify the form cross-process. For now we'll
+ // check form name and form action for identity.
+ // http://crbug.com/37990 test file sample8.html.
+ // Also note that WebString() == WebString(string16()) does not seem to
+ // evaluate to |true| for some reason TBD, so forcing to string16.
+ string16 element_name((*form_iter)->form_element.name());
+ GURL action(
+ frame->document().completeURL((*form_iter)->form_element.action()));
+ if (element_name == form.name && action == form.action) {
+ *form_element = *form_iter;
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+void FormManager::ForEachMatchingFormField(
+ FormElement* form, const FormData& data, Callback* callback) {
+ // It's possible that the site has injected fields into the form after the
+ // page has loaded, so we can't assert that the size of the cached control
+ // elements is equal to the size of the fields in |form|. Fortunately, the
+ // one case in the wild where this happens, paypal.com signup form, the fields
+ // are appended to the end of the form and are not visible.
+ for (size_t i = 0, j = 0;
+ i < form->control_elements.size() && j < data.fields.size();
+ ++i) {
+ WebFormControlElement* element = &form->control_elements[i];
+ WebString element_name = element->nameForAutofill();
+
+ // Empty WebString != empty string16, so we have to explicitly
+ // check for this case.
+ if (element_name.isEmpty() && data.fields[j].name().empty())
+ continue;
+
+ // Search forward in the |form| for a corresponding field.
+ size_t k = j;
+ while (k < data.fields.size() && element_name != data.fields[k].name())
+ k++;
+
+ if (k >= data.fields.size())
+ continue;
+
+ DCHECK_EQ(data.fields[k].name(), element_name);
+ callback->Run(element, &data.fields[k]);
+
+ // We found a matching form field so move on to the next.
+ ++j;
+ }
+
+ delete callback;
+}
+
+void FormManager::FillFormField(WebKit::WebFormControlElement* field,
+ const FormField* data) {
+ // Nothing to fill.
+ if (data->value().empty())
+ return;
+
+ if (field->formControlType() == WebString::fromUTF8("text")) {
+ WebInputElement input_element = field->to<WebInputElement>();
+
+ // Don't auto-fill a field with autocomplete=off.
+ if (!input_element.autoComplete())
+ return;
+
+ // Don't overwrite a pre-existing value in the field.
+ if (!input_element.value().isEmpty())
+ return;
+
+ // If the maxlength attribute contains a negative value, maxLength()
+ // returns the default maxlength value.
+ input_element.setValue(data->value().substr(0, input_element.maxLength()));
+ input_element.setAutofilled(true);
+ } else if (field->formControlType() == WebString::fromUTF8("select-one")) {
+ WebSelectElement select_element = field->to<WebSelectElement>();
+ select_element.setValue(data->value());
+ }
+}
diff --git a/chrome/renderer/form_manager.h b/chrome/renderer/form_manager.h
index 67d50a9..57ed5af 100644
--- a/chrome/renderer/form_manager.h
+++ b/chrome/renderer/form_manager.h
@@ -8,6 +8,7 @@
#include <map>
#include <vector>
+#include "base/callback.h"
#include "base/string16.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
@@ -111,6 +112,10 @@ class FormManager {
typedef std::map<const WebKit::WebFrame*, std::vector<FormElement*> >
WebFrameFormElementMap;
+ // The callback type used by ForEachMatchingFormField().
+ typedef Callback2<WebKit::WebFormControlElement*,
+ const webkit_glue::FormField*>::Type Callback;
+
// Converts a FormElement to FormData storage. Returns false if the form does
// not meet all the requirements in the requirements mask.
// TODO(jhawkins): Modify FormElement so we don't need |frame|.
@@ -120,11 +125,27 @@ class FormManager {
webkit_glue::FormData* form);
// Infers corresponding label for |element| from surrounding context in the
- // DOM. Contents of preceeding <p> tag or preceeding text element found in
+ // DOM. Contents of preceding <p> tag or preceding text element found in
// the form.
static string16 InferLabelForElement(
const WebKit::WebFormControlElement& element);
+ // Uses the data in |form| to find the cached FormElement.
+ bool FindCachedFormElement(const webkit_glue::FormData& form,
+ FormElement** form_element);
+
+ // For each field in |form| that matches the corresponding field in the cached
+ // FormElement, |callback| is called with the actual WebFormControlElement and
+ // the FormField data from |form|. This method owns |callback|.
+ void ForEachMatchingFormField(FormElement* form,
+ const webkit_glue::FormData& data,
+ Callback* callback);
+
+ // A ForEachMatchingFormField() callback that sets |field|'s value using the
+ // value in |data|.
+ void FillFormField(WebKit::WebFormControlElement* field,
+ const webkit_glue::FormField* data);
+
// The map of form elements.
WebFrameFormElementMap form_elements_map_;
diff --git a/chrome/renderer/form_manager_unittest.cc b/chrome/renderer/form_manager_unittest.cc
index d5a8c39..684c410 100644
--- a/chrome/renderer/form_manager_unittest.cc
+++ b/chrome/renderer/form_manager_unittest.cc
@@ -13,6 +13,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
#include "webkit/glue/form_data.h"
+using WebKit::WebDocument;
using WebKit::WebElement;
using WebKit::WebFormElement;
using WebKit::WebFrame;
@@ -337,6 +338,9 @@ TEST_F(FormManagerTest, FillForm) {
LoadHTML("<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=\"submit\" name=\"reply-send\" value=\"Send\"/>"
"</FORM>");
@@ -364,7 +368,7 @@ TEST_F(FormManagerTest, FillForm) {
EXPECT_EQ(GURL("http://buh.com"), form.action);
const std::vector<FormField>& fields = form.fields;
- ASSERT_EQ(3U, fields.size());
+ ASSERT_EQ(6U, fields.size());
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("firstname"),
string16(),
@@ -378,45 +382,64 @@ TEST_F(FormManagerTest, FillForm) {
20),
fields[1]);
EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
+ ASCIIToUTF16("imhidden"),
+ string16(),
+ ASCIIToUTF16("hidden"),
0),
fields[2]);
-
- // Fill the form.
- form.fields[0].set_value(ASCIIToUTF16("Wyatt"));
- form.fields[1].set_value(ASCIIToUTF16("Earp"));
- EXPECT_TRUE(form_manager.FillForm(form));
-
- // Find the newly-filled form that contains the input element.
- FormData form2;
- EXPECT_TRUE(form_manager.FindFormWithFormControlElement(
- input_element, FormManager::REQUIRE_NONE, &form2));
- EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name);
- EXPECT_EQ(GURL(web_frame->url()), form2.origin);
- EXPECT_EQ(GURL("http://buh.com"), form2.action);
-
- const std::vector<FormField>& fields2 = form2.fields;
- ASSERT_EQ(3U, fields2.size());
EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Wyatt"),
+ ASCIIToUTF16("notempty"),
+ ASCIIToUTF16("Hi"),
ASCIIToUTF16("text"),
20),
- fields2[0]);
+ fields[3]);
EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Earp"),
+ ASCIIToUTF16("noautocomplete"),
+ string16(),
ASCIIToUTF16("text"),
20),
- fields2[1]);
+ fields[4]);
EXPECT_EQ(FormField(string16(),
ASCIIToUTF16("reply-send"),
ASCIIToUTF16("Send"),
ASCIIToUTF16("submit"),
0),
- fields2[2]);
+ fields[5]);
+
+ // Fill the form.
+ form.fields[0].set_value(ASCIIToUTF16("Wyatt"));
+ form.fields[1].set_value(ASCIIToUTF16("Earp"));
+ form.fields[2].set_value(ASCIIToUTF16("Alpha"));
+ form.fields[3].set_value(ASCIIToUTF16("Beta"));
+ form.fields[4].set_value(ASCIIToUTF16("Gamma"));
+ EXPECT_TRUE(form_manager.FillForm(form));
+
+ // Verify the previewed elements.
+ WebDocument document = web_frame->document();
+ WebInputElement firstname =
+ document.getElementById("firstname").to<WebInputElement>();
+ // TODO(jhawkins): Check firstname.isAutofilled() once support has been added
+ // in WebKit.
+ EXPECT_EQ(ASCIIToUTF16("Wyatt"), firstname.value());
+
+ WebInputElement lastname =
+ document.getElementById("lastname").to<WebInputElement>();
+ EXPECT_EQ(ASCIIToUTF16("Earp"), lastname.value());
+
+ // Hidden fields are not previewed.
+ WebInputElement imhidden =
+ document.getElementById("imhidden").to<WebInputElement>();
+ EXPECT_TRUE(imhidden.value().isEmpty());
+
+ // Non-empty fields are not previewed.
+ WebInputElement notempty =
+ document.getElementById("notempty").to<WebInputElement>();
+ EXPECT_EQ(ASCIIToUTF16("Hi"), notempty.value());
+
+ // autocomplete=off fields are not previewed.
+ WebInputElement noautocomplete =
+ document.getElementById("noautocomplete").to<WebInputElement>();
+ EXPECT_TRUE(noautocomplete.value().isEmpty());
}
TEST_F(FormManagerTest, Reset) {
@@ -470,24 +493,24 @@ TEST_F(FormManagerTest, Labels) {
const std::vector<FormField>& fields = form.fields;
ASSERT_EQ(3U, fields.size());
- EXPECT_EQ(FormField(ASCIIToUTF16("First name:"),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("John"),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Smith"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[2]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(
+ FormField(ASCIIToUTF16("First name:"),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(
+ FormField(ASCIIToUTF16("Last name:"),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
TEST_F(FormManagerTest, LabelsWithSpans) {
@@ -516,24 +539,24 @@ TEST_F(FormManagerTest, LabelsWithSpans) {
const std::vector<FormField>& fields = form.fields;
ASSERT_EQ(3U, fields.size());
- EXPECT_EQ(FormField(ASCIIToUTF16("First name:"),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("John"),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Smith"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[2]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(
+ FormField(ASCIIToUTF16("First name:"),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(
+ FormField(ASCIIToUTF16("Last name:"),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test is different from FormManagerTest.Labels in that the label elements
@@ -566,24 +589,21 @@ TEST_F(FormManagerTest, InvalidLabels) {
const std::vector<FormField>& fields = form.fields;
ASSERT_EQ(3U, fields.size());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("John"),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Smith"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[2]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test has three form control elements, only one of which has a label
@@ -1119,29 +1139,25 @@ TEST_F(FormManagerTest, FillFormMaxLength) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- // TODO(jhawkins): We don't actually compare the value of the field in
- // FormField::operator==()!
const std::vector<FormField>& fields2 = form2.fields;
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Broth"),
- ASCIIToUTF16("text"),
- 20),
- fields2[0]);
- EXPECT_EQ(ASCIIToUTF16("Broth"), fields2[0].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Jonat"),
- ASCIIToUTF16("text"),
- 20),
- fields2[1]);
- EXPECT_EQ(ASCIIToUTF16("Jonat"), fields2[1].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields2[2]);
+ EXPECT_TRUE(fields2[0].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Broth"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Jonat"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test uses negative values of the maxlength attribute for input elements.
@@ -1211,30 +1227,26 @@ TEST_F(FormManagerTest, FillFormNegativeMaxLength) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- // TODO(jhawkins): We don't actually compare the value of the field in
- // FormField::operator==()!
const std::vector<FormField>& fields2 = form2.fields;
ASSERT_EQ(3U, fields2.size());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Brother"),
- ASCIIToUTF16("text"),
- 20),
- fields2[0]);
- EXPECT_EQ(ASCIIToUTF16("Brother"), fields2[0].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Jonathan"),
- ASCIIToUTF16("text"),
- 20),
- fields2[1]);
- EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields2[1].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields2[2]);
+ EXPECT_TRUE(fields2[0].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Brother"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields2[1].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Jonathan"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields2[2].StrictlyEqualsHack(
+ FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test sends a FormData object to FillForm with more fields than are in
@@ -1319,37 +1331,28 @@ TEST_F(FormManagerTest, FillFormMoreFormDataFields) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- // TODO(jhawkins): We don't actually compare the value of the field in
- // FormField::operator==()!
const std::vector<FormField>& fields = form2.fields;
ASSERT_EQ(4U, fields.size());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Brother"),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("middlename"),
- ASCIIToUTF16("Joseph"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Jonathan"),
- ASCIIToUTF16("text"),
- 20),
- fields[2]);
- EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[3]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Brother"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("middlename"),
+ ASCIIToUTF16("Joseph"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Jonathan"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test sends a FormData object to FillForm with fewer fields than are in
@@ -1406,65 +1409,48 @@ TEST_F(FormManagerTest, FillFormFewerFormDataFields) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- // TODO(jhawkins): We don't actually compare the value of the field in
- // FormField::operator==()!
const std::vector<FormField>& fields = form2.fields;
ASSERT_EQ(8U, fields.size());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("prefix"),
- string16(),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(string16(), fields[0].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Brother"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(ASCIIToUTF16("Brother"), fields[1].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("hidden"),
- string16(),
- ASCIIToUTF16("text"),
- 20),
- fields[2]);
- EXPECT_EQ(string16(), fields[2].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("middlename"),
- ASCIIToUTF16("Joseph"),
- ASCIIToUTF16("text"),
- 20),
- fields[3]);
- EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[3].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("second"),
- string16(),
- ASCIIToUTF16("text"),
- 20),
- fields[4]);
- EXPECT_EQ(string16(), fields[4].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Jonathan"),
- ASCIIToUTF16("text"),
- 20),
- fields[5]);
- EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[5].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("postfix"),
- string16(),
- ASCIIToUTF16("text"),
- 20),
- fields[6]);
- EXPECT_EQ(string16(), fields[6].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[7]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("prefix"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Brother"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("hidden"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("middlename"),
+ ASCIIToUTF16("Joseph"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("second"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[5].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Jonathan"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[6].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("postfix"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[7].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test sends a FormData object to FillForm with a field changed from
@@ -1518,37 +1504,28 @@ TEST_F(FormManagerTest, FillFormChangedFormDataFields) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- // TODO(jhawkins): We don't actually compare the value of the field in
- // FormField::operator==()!
const std::vector<FormField>& fields = form2.fields;
ASSERT_EQ(4U, fields.size());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Brother"),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("middlename"),
- ASCIIToUTF16("Joseph"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(string16(), fields[1].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Jonathan"),
- ASCIIToUTF16("text"),
- 20),
- fields[2]);
- EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[3]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Brother"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("middlename"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Jonathan"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
// This test sends a FormData object to FillForm with fewer fields than are in
@@ -1599,44 +1576,33 @@ TEST_F(FormManagerTest, FillFormExtraFieldInCache) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- // TODO(jhawkins): We don't actually compare the value of the field in
- // FormField::operator==()!
const std::vector<FormField>& fields = form2.fields;
ASSERT_EQ(5U, fields.size());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("firstname"),
- ASCIIToUTF16("Brother"),
- ASCIIToUTF16("text"),
- 20),
- fields[0]);
- EXPECT_EQ(ASCIIToUTF16("Brother"), fields[0].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("middlename"),
- ASCIIToUTF16("Joseph"),
- ASCIIToUTF16("text"),
- 20),
- fields[1]);
- EXPECT_EQ(ASCIIToUTF16("Joseph"), fields[1].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("lastname"),
- ASCIIToUTF16("Jonathan"),
- ASCIIToUTF16("text"),
- 20),
- fields[2]);
- EXPECT_EQ(ASCIIToUTF16("Jonathan"), fields[2].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("postfix"),
- string16(),
- ASCIIToUTF16("text"),
- 20),
- fields[3]);
- EXPECT_EQ(string16(), fields[3].value());
- EXPECT_EQ(FormField(string16(),
- ASCIIToUTF16("reply-send"),
- ASCIIToUTF16("Send"),
- ASCIIToUTF16("submit"),
- 0),
- fields[4]);
+ EXPECT_TRUE(fields[0].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Brother"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[1].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("middlename"),
+ ASCIIToUTF16("Joseph"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[2].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Jonathan"),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[3].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("postfix"),
+ string16(),
+ ASCIIToUTF16("text"),
+ 20)));
+ EXPECT_TRUE(fields[4].StrictlyEqualsHack(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ string16(),
+ ASCIIToUTF16("submit"),
+ 0)));
}
TEST_F(FormManagerTest, FillFormEmptyName) {