OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 4111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4122 frame->document().all(), &fieldsets); | 4122 frame->document().all(), &fieldsets); |
4123 ASSERT_TRUE(control_elements.empty()); | 4123 ASSERT_TRUE(control_elements.empty()); |
4124 ASSERT_TRUE(fieldsets.empty()); | 4124 ASSERT_TRUE(fieldsets.empty()); |
4125 | 4125 |
4126 FormData form; | 4126 FormData form; |
4127 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( | 4127 EXPECT_FALSE(UnownedCheckoutFormElementsAndFieldSetsToFormData( |
4128 fieldsets, control_elements, nullptr, frame->document(), extract_mask, | 4128 fieldsets, control_elements, nullptr, frame->document(), extract_mask, |
4129 &form, nullptr)); | 4129 &form, nullptr)); |
4130 } | 4130 } |
4131 | 4131 |
| 4132 TEST_F(FormAutofillTest, FormCache_ExtractNewForms) { |
| 4133 struct { |
| 4134 const char* html; |
| 4135 const size_t expected_forms; |
| 4136 } test_cases[] = { |
| 4137 // An empty form should not be extracted |
| 4138 {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 4139 "</FORM>", |
| 4140 0}, |
| 4141 // A form with less than three fields with no autocomplete type(s) should |
| 4142 // not be extracted. |
| 4143 {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 4144 " <INPUT type='name' id='firstname'/>" |
| 4145 "</FORM>", |
| 4146 0}, |
| 4147 // A form with less than three fields with at least one autocomplete type |
| 4148 // should be extracted. |
| 4149 {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 4150 " <INPUT type='name' id='firstname' autocomplete='given-name'/>" |
| 4151 "</FORM>", |
| 4152 1}, |
| 4153 // A form with three or more fields should be extracted. |
| 4154 {"<FORM name='TestForm' action='http://buh.com' method='post'>" |
| 4155 " <INPUT type='text' id='firstname'/>" |
| 4156 " <INPUT type='text' id='lastname'/>" |
| 4157 " <INPUT type='text' id='email'/>" |
| 4158 " <INPUT type='submit' value='Send'/>" |
| 4159 "</FORM>", |
| 4160 1}, |
| 4161 }; |
| 4162 |
| 4163 for (auto test_case : test_cases) { |
| 4164 LoadHTML(test_case.html); |
| 4165 |
| 4166 WebFrame* web_frame = GetMainFrame(); |
| 4167 ASSERT_NE(nullptr, web_frame); |
| 4168 |
| 4169 FormCache form_cache(*web_frame); |
| 4170 std::vector<FormData> forms = form_cache.ExtractNewForms(); |
| 4171 EXPECT_EQ(test_case.expected_forms, forms.size()); |
| 4172 } |
| 4173 } |
| 4174 |
4132 } // namespace form_util | 4175 } // namespace form_util |
4133 } // namespace autofill | 4176 } // namespace autofill |
OLD | NEW |