Index: chrome/renderer/autofill/form_autofill_browsertest.cc |
diff --git a/chrome/renderer/autofill/form_autofill_browsertest.cc b/chrome/renderer/autofill/form_autofill_browsertest.cc |
index f541b35ad1e7fff4d11f0e580898379b5e4010b5..f8ff9c54705ac49835dfa6316375d76235f16a88 100644 |
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc |
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc |
@@ -117,7 +117,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
const FormData& form = forms[0]; |
@@ -177,7 +177,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the input element we want to find. |
@@ -805,7 +805,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(2U, forms.size()); |
// First form. |
@@ -852,109 +852,6 @@ |
expected.name = ASCIIToUTF16("email"); |
expected.value = ASCIIToUTF16("jack@example.com"); |
- 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]); |
} |
@@ -971,7 +868,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
EXPECT_EQ(0U, forms.size()); |
} |
@@ -987,8 +884,12 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, |
+ 3, |
+ &forms, |
+ NULL); |
EXPECT_EQ(0U, forms.size()); |
+ EXPECT_TRUE(has_skipped_forms); |
} |
// We should not report additional forms for empty forms. |
@@ -1001,8 +902,12 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ bool has_skipped_forms = form_cache.ExtractFormsAndFormElements(*web_frame, |
+ 3, |
+ &forms, |
+ NULL); |
EXPECT_EQ(0U, forms.size()); |
+ EXPECT_FALSE(has_skipped_forms); |
} |
// We should not extract a form if it has too few fillable fields. |
@@ -1021,7 +926,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
EXPECT_EQ(0U, forms.size()); |
} |
@@ -1118,7 +1023,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the input element we want to find. |
@@ -1212,7 +1117,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the textarea element we want to find. |
@@ -2309,7 +2214,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the input element we want to find. |
@@ -2406,7 +2311,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the input element we want to find. |
@@ -2487,7 +2392,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the input element we want to find. |
@@ -2577,7 +2482,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(2U, forms.size()); |
// Get the input element we want to find. |
@@ -2797,7 +2702,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Get the input element we want to find. |
@@ -2909,7 +2814,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Set the auto-filled attribute on the firstname element. |
@@ -3013,7 +2918,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Set the auto-filled attribute on the firstname element. |
@@ -3086,7 +2991,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Set the auto-filled attribute. |
@@ -3154,7 +3059,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Set the auto-filled attribute. |
@@ -3222,7 +3127,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
// Set the auto-filled attribute. |
@@ -3289,7 +3194,7 @@ |
FormCache form_cache; |
std::vector<FormData> forms; |
- form_cache.ExtractNewForms(*web_frame, &forms); |
+ form_cache.ExtractForms(*web_frame, &forms); |
ASSERT_EQ(1U, forms.size()); |
WebInputElement firstname = |