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 227e24493d734192b91ea09ece58aba7532a0dc9..27f58e2e242ef90c927d2160e4972d1ca8ca6ca6 100644 |
--- a/chrome/renderer/autofill/form_autofill_browsertest.cc |
+++ b/chrome/renderer/autofill/form_autofill_browsertest.cc |
@@ -4129,5 +4129,48 @@ TEST_F(FormAutofillTest, UnownedFormElementsAndFieldSetsToFormDataWithForm) { |
&form, nullptr)); |
} |
+TEST_F(FormAutofillTest, FormCache_ExtractNewForms) { |
+ struct { |
+ const char* html; |
+ const size_t expected_forms; |
+ } test_cases[] = { |
+ // An empty form should not be extracted |
+ {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
+ "</FORM>", |
+ 0}, |
+ // A form with less than three fields with no autocomplete type(s) should |
+ // not be extracted. |
+ {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
+ " <INPUT type='name' id='firstname'/>" |
+ "</FORM>", |
+ 0}, |
+ // A form with less than three fields with at least one autocomplete type |
+ // should be extracted. |
+ {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
+ " <INPUT type='name' id='firstname' autocomplete='given-name'/>" |
+ "</FORM>", |
+ 1}, |
+ // A form with three or more fields should be extracted. |
+ {"<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>", |
+ 1}, |
+ }; |
+ |
+ for (auto test_case : test_cases) { |
+ LoadHTML(test_case.html); |
+ |
+ WebFrame* web_frame = GetMainFrame(); |
+ ASSERT_NE(nullptr, web_frame); |
+ |
+ FormCache form_cache(*web_frame); |
+ std::vector<FormData> forms = form_cache.ExtractNewForms(); |
+ EXPECT_EQ(test_case.expected_forms, forms.size()); |
+ } |
+} |
+ |
} // namespace form_util |
} // namespace autofill |