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 24b5f05cab1403664b768f7bb2980e89b9657201..98f161c5cd405a5a08179c03bd01359c59c8720a 100644 |
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc |
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc |
@@ -196,8 +196,11 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ EXPECT_EQ(1U, unowned_form_index); |
const FormData& form = forms[0]; |
EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); |
@@ -256,8 +259,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("firstname"); |
@@ -487,8 +494,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("firstname"); |
@@ -567,8 +578,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the textarea element we want to find. |
WebElement element = web_frame->document().getElementById("street-address"); |
@@ -657,8 +672,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("firstname"); |
@@ -745,8 +764,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("firstname"); |
@@ -817,8 +840,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("firstname"); |
@@ -892,9 +919,13 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
const size_t expected_size = unowned ? 1 : 2; |
ASSERT_EQ(expected_size, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 2; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("apple"); |
@@ -975,8 +1006,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Get the input element we want to find. |
WebInputElement input_element = GetInputElementById("firstname"); |
@@ -1071,8 +1106,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Set the auto-filled attribute. |
WebInputElement firstname = GetInputElementById("firstname"); |
@@ -1167,8 +1206,12 @@ class FormAutofillTest : public ChromeRenderViewTest { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Set the auto-filled attribute. |
WebInputElement firstname = GetInputElementById("firstname"); |
@@ -1227,14 +1270,18 @@ class FormAutofillTest : public ChromeRenderViewTest { |
EXPECT_EQ(0, firstname.selectionEnd()); |
} |
- void TestClearPreviewedFormWithElement(const char* html) { |
+ void TestClearPreviewedFormWithElement(const char* html, bool unowned) { |
LoadHTML(html); |
WebFrame* web_frame = GetMainFrame(); |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Set the auto-filled attribute. |
WebInputElement firstname = GetInputElementById("firstname"); |
@@ -1281,14 +1328,19 @@ class FormAutofillTest : public ChromeRenderViewTest { |
EXPECT_EQ(0, lastname.selectionEnd()); |
} |
- void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html) { |
+ void TestClearPreviewedFormWithNonEmptyInitiatingNode(const char* html, |
+ bool unowned) { |
LoadHTML(html); |
WebFrame* web_frame = GetMainFrame(); |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Set the auto-filled attribute. |
WebInputElement firstname = GetInputElementById("firstname"); |
@@ -1335,14 +1387,19 @@ class FormAutofillTest : public ChromeRenderViewTest { |
EXPECT_FALSE(phone.isAutofilled()); |
} |
- void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html) { |
+ void TestClearPreviewedFormWithAutofilledInitiatingNode(const char* html, |
+ bool unowned) { |
LoadHTML(html); |
WebFrame* web_frame = GetMainFrame(); |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Set the auto-filled attribute. |
WebInputElement firstname = GetInputElementById("firstname"); |
@@ -1388,15 +1445,19 @@ class FormAutofillTest : public ChromeRenderViewTest { |
EXPECT_FALSE(phone.isAutofilled()); |
} |
- void TestClearOnlyAutofilledFields(const char* html) { |
+ void TestClearOnlyAutofilledFields(const char* html, bool unowned) { |
LoadHTML(html); |
WebFrame* web_frame = GetMainFrame(); |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = |
+ form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ const size_t expected_index = unowned ? 0 : 1; |
+ EXPECT_EQ(expected_index, unowned_form_index); |
// Set the autofilled attribute. |
WebInputElement firstname = GetInputElementById("firstname"); |
@@ -2088,8 +2149,10 @@ TEST_F(FormAutofillTest, ExtractMultipleForms) { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(2U, forms.size()); |
+ EXPECT_EQ(2U, unowned_form_index); |
// First form. |
const FormData& form = forms[0]; |
@@ -2151,12 +2214,15 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ EXPECT_EQ(1U, unowned_form_index); |
// Second call should give nothing as there are no new forms. |
- forms = form_cache.ExtractNewForms(); |
+ forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_TRUE(forms.empty()); |
+ EXPECT_EQ(0U, unowned_form_index); |
// Append to the current form will re-extract. |
ExecuteJavaScript( |
@@ -2167,8 +2233,9 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) { |
"document.getElementById('testform').appendChild(newInput);"); |
msg_loop_.RunUntilIdle(); |
- forms = form_cache.ExtractNewForms(); |
+ forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ EXPECT_EQ(1U, unowned_form_index); |
const std::vector<FormFieldData>& fields = forms[0].fields; |
ASSERT_EQ(4U, fields.size()); |
@@ -2220,8 +2287,9 @@ TEST_F(FormAutofillTest, OnlyExtractNewForms) { |
msg_loop_.RunUntilIdle(); |
web_frame = GetMainFrame(); |
- forms = form_cache.ExtractNewForms(); |
+ forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_EQ(1U, forms.size()); |
+ EXPECT_EQ(1U, unowned_form_index); |
const std::vector<FormFieldData>& fields2 = forms[0].fields; |
ASSERT_EQ(3U, fields2.size()); |
@@ -2251,8 +2319,10 @@ TEST_F(FormAutofillTest, ExtractFormsTooFewFields) { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_TRUE(forms.empty()); |
+ EXPECT_EQ(0U, unowned_form_index); |
} |
// We should not report additional forms for empty forms. |
@@ -2266,8 +2336,10 @@ TEST_F(FormAutofillTest, ExtractFormsSkippedForms) { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_TRUE(forms.empty()); |
+ EXPECT_EQ(0U, unowned_form_index); |
} |
// We should not report additional forms for empty forms. |
@@ -2279,8 +2351,10 @@ TEST_F(FormAutofillTest, ExtractFormsNoFields) { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_TRUE(forms.empty()); |
+ EXPECT_EQ(0U, unowned_form_index); |
} |
// We should not extract a form if it has too few fillable fields. |
@@ -2298,8 +2372,10 @@ TEST_F(FormAutofillTest, ExtractFormsTooFewFieldsSkipsCheckable) { |
ASSERT_NE(nullptr, web_frame); |
FormCache form_cache(*web_frame); |
- std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ size_t unowned_form_index; |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(&unowned_form_index); |
ASSERT_TRUE(forms.empty()); |
+ EXPECT_EQ(0U, unowned_form_index); |
} |
TEST_F(FormAutofillTest, WebFormElementToFormDataAutocomplete) { |
@@ -3717,7 +3793,8 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithElement) { |
" <INPUT type='email' id='email2'/>" |
" <INPUT type='tel' id='phone'/>" |
" <INPUT type='submit' value='Send'/>" |
- "</FORM>"); |
+ "</FORM>", |
+ false); |
} |
TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) { |
@@ -3727,7 +3804,8 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithElementForUnownedForm) { |
"<INPUT type='text' id='email'/>" |
"<INPUT type='email' id='email2'/>" |
"<INPUT type='tel' id='phone'/>" |
- "<INPUT type='submit' value='Send'/>"); |
+ "<INPUT type='submit' value='Send'/>", |
+ true); |
} |
TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { |
@@ -3739,7 +3817,8 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithNonEmptyInitiatingNode) { |
" <INPUT type='email' id='email2'/>" |
" <INPUT type='tel' id='phone'/>" |
" <INPUT type='submit' value='Send'/>" |
- "</FORM>"); |
+ "</FORM>", |
+ false); |
} |
TEST_F(FormAutofillTest, |
@@ -3750,7 +3829,8 @@ TEST_F(FormAutofillTest, |
"<INPUT type='text' id='email'/>" |
"<INPUT type='email' id='email2'/>" |
"<INPUT type='tel' id='phone'/>" |
- "<INPUT type='submit' value='Send'/>"); |
+ "<INPUT type='submit' value='Send'/>", |
+ true); |
} |
TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { |
@@ -3762,7 +3842,8 @@ TEST_F(FormAutofillTest, ClearPreviewedFormWithAutofilledInitiatingNode) { |
" <INPUT type='email' id='email2'/>" |
" <INPUT type='tel' id='phone'/>" |
" <INPUT type='submit' value='Send'/>" |
- "</FORM>"); |
+ "</FORM>", |
+ false); |
} |
TEST_F(FormAutofillTest, |
@@ -3773,7 +3854,8 @@ TEST_F(FormAutofillTest, |
"<INPUT type='text' id='email'/>" |
"<INPUT type='email' id='email2'/>" |
"<INPUT type='tel' id='phone'/>" |
- "<INPUT type='submit' value='Send'/>"); |
+ "<INPUT type='submit' value='Send'/>", |
+ true); |
} |
// Autofill's "Clear Form" should clear only autofilled fields |
@@ -3785,7 +3867,8 @@ TEST_F(FormAutofillTest, ClearOnlyAutofilledFields) { |
" <INPUT type='email' id='email' value='wyatt@earp.com'/>" |
" <INPUT type='tel' id='phone' value='650-777-9999'/>" |
" <INPUT type='submit' value='Send'/>" |
- "</FORM>"); |
+ "</FORM>", |
+ false); |
} |
TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) { |
@@ -3794,7 +3877,8 @@ TEST_F(FormAutofillTest, ClearOnlyAutofilledFieldsForUnownedForm) { |
"<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'/>"); |
+ "<INPUT type='submit' value='Send'/>", |
+ true); |
} |
// If we have multiple labels per id, the labels concatenated into label string. |