Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils_browsertest.cc

Issue 372683003: Clean up PasswordFormConversionUtilsTest and add some missing tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/strings/string16.h" 5 #include "base/strings/string16.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/content/renderer/password_form_conversion_utils.h" 9 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
10 #include "components/autofill/core/common/password_form.h" 10 #include "components/autofill/core/common/password_form.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 *password_form = CreatePasswordForm(forms[0]); 106 *password_form = CreatePasswordForm(forms[0]);
107 } 107 }
108 108
109 private: 109 private:
110 DISALLOW_COPY_AND_ASSIGN(PasswordFormConversionUtilsTest); 110 DISALLOW_COPY_AND_ASSIGN(PasswordFormConversionUtilsTest);
111 }; 111 };
112 112
113 } // namespace 113 } // namespace
114 114
115 TEST_F(PasswordFormConversionUtilsTest, ValidWebFormElementToPasswordForm) { 115 TEST_F(PasswordFormConversionUtilsTest, BasicFormAttributes) {
116 PasswordFormBuilder builder(kTestFormActionURL); 116 PasswordFormBuilder builder(kTestFormActionURL);
117 builder.AddUsernameField("username", "johnsmith", NULL); 117 builder.AddUsernameField("username", "johnsmith", NULL);
118 builder.AddSubmitButton(); 118 builder.AddSubmitButton();
119 builder.AddPasswordField("password", "secret", NULL); 119 builder.AddPasswordField("password", "secret", NULL);
120 std::string html = builder.ProduceHTML(); 120 std::string html = builder.ProduceHTML();
121 121
122 scoped_ptr<PasswordForm> password_form; 122 scoped_ptr<PasswordForm> password_form;
123 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); 123 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
124 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get()); 124 ASSERT_TRUE(password_form);
125 125
126 EXPECT_EQ("data:", password_form->signon_realm); 126 EXPECT_EQ("data:", password_form->signon_realm);
127 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action); 127 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action);
128 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); 128 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element);
129 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); 129 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value);
130 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); 130 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element);
131 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); 131 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value);
132 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme); 132 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme);
133 EXPECT_FALSE(password_form->ssl_valid); 133 EXPECT_FALSE(password_form->ssl_valid);
134 EXPECT_FALSE(password_form->preferred); 134 EXPECT_FALSE(password_form->preferred);
135 EXPECT_FALSE(password_form->blacklisted_by_user); 135 EXPECT_FALSE(password_form->blacklisted_by_user);
136 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type); 136 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type);
137 } 137 EXPECT_FALSE(password_form->use_additional_authentication);
138
139 TEST_F(PasswordFormConversionUtilsTest, InvalidWebFormElementToPasswordForm) {
140 PasswordFormBuilder builder("invalid_target");
141 builder.AddUsernameField("username", "johnsmith", NULL);
142 builder.AddSubmitButton();
143 builder.AddPasswordField("password", "secret", NULL);
144 std::string html = builder.ProduceHTML();
145
146 scoped_ptr<PasswordForm> password_form;
147 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
148 ASSERT_EQ(static_cast<PasswordForm*>(NULL), password_form.get());
149 } 138 }
150 139
151 TEST_F(PasswordFormConversionUtilsTest, 140 TEST_F(PasswordFormConversionUtilsTest,
152 WebFormWithMultipleUseNameAndPassWordFieldsToPasswordForm) { 141 IdentifyingUsernameFields) {
vabr (Chromium) 2014/07/07 12:12:19 nit: Seems like this would fit on one line?
engedy 2014/07/09 16:58:35 Done.
153 PasswordFormBuilder builder(kTestFormActionURL);
154 builder.AddUsernameField("username1", "John", NULL);
155 builder.AddPasswordField("password1", "oldsecret", NULL);
156 builder.AddUsernameField("username2", "William", NULL);
157 builder.AddPasswordField("password2", "secret", NULL);
158 builder.AddUsernameField("username3", "Smith", NULL);
159 builder.AddPasswordField("password3", "secret", NULL);
160 builder.AddSubmitButton();
161 std::string html = builder.ProduceHTML();
162
163 scoped_ptr<PasswordForm> password_form;
164 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
165 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get());
166
167 EXPECT_EQ("data:", password_form->signon_realm);
168 EXPECT_EQ(GURL(kTestFormActionURL), password_form->action);
169 EXPECT_EQ(base::UTF8ToUTF16("username1"), password_form->username_element);
170 EXPECT_EQ(base::UTF8ToUTF16("John"), password_form->username_value);
171 EXPECT_EQ(base::UTF8ToUTF16("password1"),
172 password_form->password_element);
173 EXPECT_EQ(base::UTF8ToUTF16("oldsecret"), password_form->password_value);
174 EXPECT_EQ(base::UTF8ToUTF16("password2"),
175 password_form->new_password_element);
176 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value);
177 ASSERT_EQ(2u, password_form->other_possible_usernames.size());
178 EXPECT_EQ(base::UTF8ToUTF16("William"),
179 password_form->other_possible_usernames[0]);
180 EXPECT_EQ(base::UTF8ToUTF16("Smith"),
181 password_form->other_possible_usernames[1]);
182 EXPECT_EQ(PasswordForm::SCHEME_HTML, password_form->scheme);
183 EXPECT_FALSE(password_form->ssl_valid);
184 EXPECT_FALSE(password_form->preferred);
185 EXPECT_FALSE(password_form->blacklisted_by_user);
186 EXPECT_EQ(PasswordForm::TYPE_MANUAL, password_form->type);
187 }
188
189 TEST_F(PasswordFormConversionUtilsTest,
190 WebFormwithThreeDifferentPasswordsToPasswordForm) {
191 PasswordFormBuilder builder(kTestFormActionURL);
192 builder.AddUsernameField("username1", "John", NULL);
193 builder.AddPasswordField("password1", "alpha", NULL);
194 builder.AddPasswordField("password2", "beta", NULL);
195 builder.AddPasswordField("password3", "gamma", NULL);
196 builder.AddSubmitButton();
197 std::string html = builder.ProduceHTML();
198
199 scoped_ptr<PasswordForm> password_form;
200 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
201 ASSERT_EQ(static_cast<PasswordForm*>(NULL), password_form.get());
202 }
203
204 TEST_F(PasswordFormConversionUtilsTest,
205 UsernameFieldsWithAutocompleteAttributes) {
206 // Each test case consists of a set of parameters to be plugged into the 142 // Each test case consists of a set of parameters to be plugged into the
207 // PasswordFormBuilder below, plus the corresponding expectations. 143 // PasswordFormBuilder below, plus the corresponding expectations.
208 struct TestCase { 144 struct TestCase {
209 const char* autocomplete[3]; 145 const char* autocomplete[3];
210 const char* expected_username_element; 146 const char* expected_username_element;
211 const char* expected_username_value; 147 const char* expected_username_value;
212 const char* expected_other_possible_usernames; 148 const char* expected_other_possible_usernames;
213 } cases[] = { 149 } cases[] = {
150 // When no elements are marked with autocomplete='username', the text-type
151 // input field before the first password element should get selected as
152 // the username, and the rest should be marked as alternatives.
153 {{NULL, NULL, NULL}, "username2", "William", "John+Smith"},
214 // When a sole element is marked with autocomplete='username', it should 154 // When a sole element is marked with autocomplete='username', it should
215 // be treated as the username for sure, with no other_possible_usernames. 155 // be treated as the username for sure, with no other_possible_usernames.
216 {{"username", NULL, NULL}, "username1", "John", ""}, 156 {{"username", NULL, NULL}, "username1", "John", ""},
217 {{NULL, "username", NULL}, "username2", "William", ""}, 157 {{NULL, "username", NULL}, "username2", "William", ""},
218 {{NULL, NULL, "username"}, "username3", "Smith", ""}, 158 {{NULL, NULL, "username"}, "username3", "Smith", ""},
219 // When >=2 elements have the attribute, the first should be selected as 159 // When >=2 elements have the attribute, the first should be selected as
220 // the username, and the rest should go to other_possible_usernames. 160 // the username, and the rest should go to other_possible_usernames.
221 {{"username", "username", NULL}, "username1", "John", "William"}, 161 {{"username", "username", NULL}, "username1", "John", "William"},
222 {{NULL, "username", "username"}, "username2", "William", "Smith"}, 162 {{NULL, "username", "username"}, "username2", "William", "Smith"},
223 {{"username", NULL, "username"}, "username1", "John", "Smith"}, 163 {{"username", NULL, "username"}, "username1", "John", "Smith"},
(...skipping 14 matching lines...) Expand all
238 PasswordFormBuilder builder(kTestFormActionURL); 178 PasswordFormBuilder builder(kTestFormActionURL);
239 builder.AddUsernameField("username1", "John", cases[i].autocomplete[0]); 179 builder.AddUsernameField("username1", "John", cases[i].autocomplete[0]);
240 builder.AddUsernameField("username2", "William", cases[i].autocomplete[1]); 180 builder.AddUsernameField("username2", "William", cases[i].autocomplete[1]);
241 builder.AddPasswordField("password", "secret", NULL); 181 builder.AddPasswordField("password", "secret", NULL);
242 builder.AddUsernameField("username3", "Smith", cases[i].autocomplete[2]); 182 builder.AddUsernameField("username3", "Smith", cases[i].autocomplete[2]);
243 builder.AddSubmitButton(); 183 builder.AddSubmitButton();
244 std::string html = builder.ProduceHTML(); 184 std::string html = builder.ProduceHTML();
245 185
246 scoped_ptr<PasswordForm> password_form; 186 scoped_ptr<PasswordForm> password_form;
247 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); 187 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
248 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get()); 188 ASSERT_TRUE(password_form);
249 189
250 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element), 190 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_element),
251 password_form->username_element); 191 password_form->username_element);
252 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value), 192 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_username_value),
253 password_form->username_value); 193 password_form->username_value);
194 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_other_possible_usernames),
195 JoinString(password_form->other_possible_usernames, '+'));
196
197 // Do a basic sanity check that we are still having a password field.
254 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); 198 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element);
255 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); 199 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value);
256 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_other_possible_usernames), 200 }
257 JoinString(password_form->other_possible_usernames, '+')); 201 }
202
203 TEST_F(PasswordFormConversionUtilsTest, IdentifyingTwoPasswordFields) {
204 // Each test case consists of a set of parameters to be plugged into the
205 // PasswordFormBuilder below, plus the corresponding expectations.
206 struct TestCase {
207 const char* password_values[2];
208 const char* expected_password_element;
209 const char* expected_password_value;
210 const char* expected_new_password_element;
211 const char* expected_new_password_value;
212 } cases[] = {
213 // Twp non-empty fields with the same value should be treated as a new
214 // password field plus a confirmation field for the new password.
215 {{"alpha", "alpha"}, "", "", "password1", "alpha"},
216 // The same goes if the fields are yet empty: we speculate that we will
217 // identify them as new password fields once they are filled out, and we
218 // want to keep our abstract interpretation of the form less flaky.
219 {{"", ""}, "", "", "password1", ""},
220 // Two different values should be treated as a password change form, one
221 // that also asks for the current password, but only once for the new.
222 {{"alpha", ""}, "password1", "alpha", "password2", ""},
223 {{"", "beta"}, "password1", "", "password2", "beta"},
224 {{"alpha", "beta"}, "password1", "alpha", "password2", "beta"}};
225
226 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
227 SCOPED_TRACE(testing::Message() << "Iteration " << i);
228
229 PasswordFormBuilder builder(kTestFormActionURL);
230 builder.AddPasswordField("password1", cases[i].password_values[0], NULL);
231 builder.AddUsernameField("username1", "William", NULL);
232 builder.AddPasswordField("password2", cases[i].password_values[1], NULL);
233 builder.AddUsernameField("username2", "Smith", NULL);
234 builder.AddSubmitButton();
235 std::string html = builder.ProduceHTML();
236
237 scoped_ptr<PasswordForm> password_form;
238 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
239 ASSERT_TRUE(password_form);
240
241 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element),
242 password_form->password_element);
243 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value),
244 password_form->password_value);
245 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element),
246 password_form->new_password_element);
247 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value),
248 password_form->new_password_value);
249
250 // Do a basic sanity check that we are still selecting the right username.
251 EXPECT_EQ(base::UTF8ToUTF16("username1"), password_form->username_element);
252 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value);
253 ASSERT_EQ(1u, password_form->other_possible_usernames.size());
254 EXPECT_EQ(base::UTF8ToUTF16("Smith"),
255 password_form->other_possible_usernames[0]);
256 }
257 }
258
259 TEST_F(PasswordFormConversionUtilsTest, IdentifyingThreePasswordFields) {
260 // Each test case consists of a set of parameters to be plugged into the
261 // PasswordFormBuilder below, plus the corresponding expectations.
262 struct TestCase {
263 const char* password_values[3];
264 const char* expected_password_element;
265 const char* expected_password_value;
266 const char* expected_new_password_element;
267 const char* expected_new_password_value;
268 } cases[] = {
269 // Two fields with the same value, and one different: we should treat this
270 // as a password change form with confirmation for the new password. Note
271 // that we only recognize (current + new + new) and (new + new + current)
272 // without autocomplete attributes.
273 {{"alpha", "", ""}, "password1", "alpha", "password2", ""},
274 {{"", "beta", "beta"}, "password1", "", "password2", "beta"},
275 {{"alpha", "beta", "beta"}, "password1", "alpha", "password2", "beta"},
276 {{"beta", "beta", "alpha"}, "password3", "alpha", "password1", "beta"},
277 // If the fields are yet empty, we speculate that we will identify them as
278 // (current + new + new) once they are filled out, so we should classify
279 // them the same for now to keep our abstract interpretation less flaky.
280 {{"", "", ""}, "password1", "", "password2", ""}};
281 // Note: In all other cases, we give up and consider the form invalid.
282 // This is tested in InvalidFormDueToConfusingPasswordFields.
283
284 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
285 SCOPED_TRACE(testing::Message() << "Iteration " << i);
286
287 PasswordFormBuilder builder(kTestFormActionURL);
288 builder.AddPasswordField("password1", cases[i].password_values[0], NULL);
289 builder.AddUsernameField("username1", "William", NULL);
290 builder.AddPasswordField("password2", cases[i].password_values[1], NULL);
291 builder.AddUsernameField("username2", "Smith", NULL);
292 builder.AddPasswordField("password3", cases[i].password_values[2], NULL);
293 builder.AddSubmitButton();
294 std::string html = builder.ProduceHTML();
295
296 scoped_ptr<PasswordForm> password_form;
297 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
298 ASSERT_TRUE(password_form);
299
300 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element),
301 password_form->password_element);
302 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value),
303 password_form->password_value);
304 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element),
305 password_form->new_password_element);
306 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value),
307 password_form->new_password_value);
308
309 // Do a basic sanity check that we are still selecting the right username.
310 EXPECT_EQ(base::UTF8ToUTF16("username1"), password_form->username_element);
311 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value);
312 ASSERT_EQ(1u, password_form->other_possible_usernames.size());
313 EXPECT_EQ(base::UTF8ToUTF16("Smith"),
314 password_form->other_possible_usernames[0]);
258 } 315 }
259 } 316 }
260 317
261 TEST_F(PasswordFormConversionUtilsTest, 318 TEST_F(PasswordFormConversionUtilsTest,
262 PasswordFieldsWithAutocompleteAttributes) { 319 IdentifyingPasswordFieldsWithAutocompleteAttributes) {
263 // Each test case consists of a set of parameters to be plugged into the 320 // Each test case consists of a set of parameters to be plugged into the
264 // PasswordFormBuilder below, plus the corresponding expectations. 321 // PasswordFormBuilder below, plus the corresponding expectations.
265 struct TestCase { 322 struct TestCase {
266 const char* autocomplete[3]; 323 const char* autocomplete[3];
267 const char* expected_password_element; 324 const char* expected_password_element;
268 const char* expected_password_value; 325 const char* expected_password_value;
269 const char* expected_new_password_element; 326 const char* expected_new_password_element;
270 const char* expected_new_password_value; 327 const char* expected_new_password_value;
271 } cases[] = { 328 } cases[] = {
272 // When there are elements marked with autocomplete='current-password', 329 // When there are elements marked with autocomplete='current-password',
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); 411 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]);
355 builder.AddUsernameField("username1", "William", NULL); 412 builder.AddUsernameField("username1", "William", NULL);
356 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); 413 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]);
357 builder.AddUsernameField("username2", "Smith", NULL); 414 builder.AddUsernameField("username2", "Smith", NULL);
358 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); 415 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]);
359 builder.AddSubmitButton(); 416 builder.AddSubmitButton();
360 std::string html = builder.ProduceHTML(); 417 std::string html = builder.ProduceHTML();
361 418
362 scoped_ptr<PasswordForm> password_form; 419 scoped_ptr<PasswordForm> password_form;
363 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); 420 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
364 ASSERT_NE(static_cast<PasswordForm*>(NULL), password_form.get()); 421 ASSERT_TRUE(password_form);
365 422
366 // Any constellation of password autocomplete attributes should have no
367 // effect on that the first text-type input field before a password field
368 // should be selected as the username.
369 // TODO(engedy): Double-check whether this is the intended behavior.
370 EXPECT_EQ(base::UTF8ToUTF16("username1"), password_form->username_element);
371 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value);
372 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element), 423 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_element),
373 password_form->password_element); 424 password_form->password_element);
374 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value), 425 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_password_value),
375 password_form->password_value); 426 password_form->password_value);
376 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), 427 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element),
377 password_form->new_password_element); 428 password_form->new_password_element);
378 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), 429 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value),
379 password_form->new_password_value); 430 password_form->new_password_value);
431
432 // Any constellation of password autocomplete attributes should have no
vabr (Chromium) 2014/07/07 12:12:19 nit: Any constellation ... should have no ... -> N
engedy 2014/07/09 16:58:35 Done.
433 // effect on that the text-type input field before the first password field
434 // should be selected as the username.
435 // TODO(engedy): Double-check whether this is the intended behavior.
436 EXPECT_EQ(base::UTF8ToUTF16("username1"), password_form->username_element);
437 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value);
380 ASSERT_EQ(1u, password_form->other_possible_usernames.size()); 438 ASSERT_EQ(1u, password_form->other_possible_usernames.size());
381 EXPECT_EQ(base::UTF8ToUTF16("Smith"), 439 EXPECT_EQ(base::UTF8ToUTF16("Smith"),
382 password_form->other_possible_usernames[0]); 440 password_form->other_possible_usernames[0]);
383 } 441 }
384 } 442 }
385 443
444 TEST_F(PasswordFormConversionUtilsTest, InvalidFormDueToBadActionURL) {
445 PasswordFormBuilder builder("invalid_target");
446 builder.AddUsernameField("username", "JohnSmith", NULL);
447 builder.AddSubmitButton();
448 builder.AddPasswordField("password", "secret", NULL);
449 std::string html = builder.ProduceHTML();
450
451 scoped_ptr<PasswordForm> password_form;
452 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
453 EXPECT_FALSE(password_form);
454 }
455
456 TEST_F(PasswordFormConversionUtilsTest, InvalidFormDueToNoPasswordFields) {
457 PasswordFormBuilder builder(kTestFormActionURL);
458 builder.AddUsernameField("username1", "John", NULL);
459 builder.AddUsernameField("username2", "Smith", NULL);
460 builder.AddSubmitButton();
461 std::string html = builder.ProduceHTML();
462
463 scoped_ptr<PasswordForm> password_form;
464 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
465 EXPECT_FALSE(password_form);
466 }
467
468 TEST_F(PasswordFormConversionUtilsTest,
469 InvalidFormDueToConfusingPasswordFields) {
470 // Each test case consists of a set of parameters to be plugged into the
471 // PasswordFormBuilder below.
472 const char* cases[][3] = {
473 // No autocomplete attributes to guide us, and we see:
474 // * three password values that are all different,
475 // * three password values that are all the same;
476 // * three password values with the first and last matching.
477 // In any case, we are lost, and we should just give up on this form.
478 {"alpha", "beta", "gamma"},
479 {"alpha", "alpha", "alpha"},
480 {"alpha", "beta", "alpha"}};
481
482 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
483 SCOPED_TRACE(testing::Message() << "Iteration " << i);
484
485 PasswordFormBuilder builder(kTestFormActionURL);
486 builder.AddUsernameField("username1", "John", NULL);
487 builder.AddPasswordField("password1", cases[i][0], NULL);
488 builder.AddPasswordField("password2", cases[i][1], NULL);
489 builder.AddPasswordField("password3", cases[i][2], NULL);
490 builder.AddSubmitButton();
491 std::string html = builder.ProduceHTML();
492
493 scoped_ptr<PasswordForm> password_form;
494 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form));
495 EXPECT_FALSE(password_form);
496 }
497 }
498
386 } // namespace autofill 499 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698