OLD | NEW |
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 "William+Smith"}, | 212 "William+Smith"}, |
213 // When there is an empty autocomplete attribute (i.e. autocomplete=""), | 213 // When there is an empty autocomplete attribute (i.e. autocomplete=""), |
214 // it should have the same effect as having no attribute whatsoever. | 214 // it should have the same effect as having no attribute whatsoever. |
215 {{"", "", ""}, "username2", "William", "John+Smith"}, | 215 {{"", "", ""}, "username2", "William", "John+Smith"}, |
216 {{"", "", "username"}, "username3", "Smith", ""}, | 216 {{"", "", "username"}, "username3", "Smith", ""}, |
217 {{"username", "", "username"}, "username1", "John", "Smith"}, | 217 {{"username", "", "username"}, "username1", "John", "Smith"}, |
218 // It should not matter if attribute values are upper or mixed case. | 218 // It should not matter if attribute values are upper or mixed case. |
219 {{"USERNAME", NULL, "uSeRNaMe"}, "username1", "John", "Smith"}, | 219 {{"USERNAME", NULL, "uSeRNaMe"}, "username1", "John", "Smith"}, |
220 {{"uSeRNaMe", NULL, "USERNAME"}, "username1", "John", "Smith"}}; | 220 {{"uSeRNaMe", NULL, "USERNAME"}, "username1", "John", "Smith"}}; |
221 | 221 |
222 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 222 for (size_t i = 0; i < arraysize(cases); ++i) { |
223 for (size_t nonempty_username_fields = 0; nonempty_username_fields < 2; | 223 for (size_t nonempty_username_fields = 0; nonempty_username_fields < 2; |
224 ++nonempty_username_fields) { | 224 ++nonempty_username_fields) { |
225 SCOPED_TRACE(testing::Message() | 225 SCOPED_TRACE(testing::Message() |
226 << "Iteration " << i << " " | 226 << "Iteration " << i << " " |
227 << (nonempty_username_fields ? "nonempty" : "empty")); | 227 << (nonempty_username_fields ? "nonempty" : "empty")); |
228 | 228 |
229 // Repeat each test once with empty, and once with non-empty usernames. | 229 // Repeat each test once with empty, and once with non-empty usernames. |
230 // In the former case, no empty other_possible_usernames should be saved. | 230 // In the former case, no empty other_possible_usernames should be saved. |
231 const char* names[3]; | 231 const char* names[3]; |
232 if (nonempty_username_fields) { | 232 if (nonempty_username_fields) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // The same goes if the fields are yet empty: we speculate that we will | 286 // The same goes if the fields are yet empty: we speculate that we will |
287 // identify them as new password fields once they are filled out, and we | 287 // identify them as new password fields once they are filled out, and we |
288 // want to keep our abstract interpretation of the form less flaky. | 288 // want to keep our abstract interpretation of the form less flaky. |
289 {{"", ""}, "", "", "password1", ""}, | 289 {{"", ""}, "", "", "password1", ""}, |
290 // Two different values should be treated as a password change form, one | 290 // Two different values should be treated as a password change form, one |
291 // that also asks for the current password, but only once for the new. | 291 // that also asks for the current password, but only once for the new. |
292 {{"alpha", ""}, "password1", "alpha", "password2", ""}, | 292 {{"alpha", ""}, "password1", "alpha", "password2", ""}, |
293 {{"", "beta"}, "password1", "", "password2", "beta"}, | 293 {{"", "beta"}, "password1", "", "password2", "beta"}, |
294 {{"alpha", "beta"}, "password1", "alpha", "password2", "beta"}}; | 294 {{"alpha", "beta"}, "password1", "alpha", "password2", "beta"}}; |
295 | 295 |
296 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 296 for (size_t i = 0; i < arraysize(cases); ++i) { |
297 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 297 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
298 | 298 |
299 PasswordFormBuilder builder(kTestFormActionURL); | 299 PasswordFormBuilder builder(kTestFormActionURL); |
300 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); | 300 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); |
301 builder.AddUsernameField("username1", "William", NULL); | 301 builder.AddUsernameField("username1", "William", NULL); |
302 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); | 302 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); |
303 builder.AddUsernameField("username2", "Smith", NULL); | 303 builder.AddUsernameField("username2", "Smith", NULL); |
304 builder.AddSubmitButton("submit", true); | 304 builder.AddSubmitButton("submit", true); |
305 std::string html = builder.ProduceHTML(); | 305 std::string html = builder.ProduceHTML(); |
306 | 306 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 {{"", "beta", "beta"}, "password1", "", "password2", "beta"}, | 343 {{"", "beta", "beta"}, "password1", "", "password2", "beta"}, |
344 {{"alpha", "beta", "beta"}, "password1", "alpha", "password2", "beta"}, | 344 {{"alpha", "beta", "beta"}, "password1", "alpha", "password2", "beta"}, |
345 {{"beta", "beta", "alpha"}, "password3", "alpha", "password1", "beta"}, | 345 {{"beta", "beta", "alpha"}, "password3", "alpha", "password1", "beta"}, |
346 // If the fields are yet empty, we speculate that we will identify them as | 346 // If the fields are yet empty, we speculate that we will identify them as |
347 // (current + new + new) once they are filled out, so we should classify | 347 // (current + new + new) once they are filled out, so we should classify |
348 // them the same for now to keep our abstract interpretation less flaky. | 348 // them the same for now to keep our abstract interpretation less flaky. |
349 {{"", "", ""}, "password1", "", "password2", ""}}; | 349 {{"", "", ""}, "password1", "", "password2", ""}}; |
350 // Note: In all other cases, we give up and consider the form invalid. | 350 // Note: In all other cases, we give up and consider the form invalid. |
351 // This is tested in InvalidFormDueToConfusingPasswordFields. | 351 // This is tested in InvalidFormDueToConfusingPasswordFields. |
352 | 352 |
353 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 353 for (size_t i = 0; i < arraysize(cases); ++i) { |
354 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 354 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
355 | 355 |
356 PasswordFormBuilder builder(kTestFormActionURL); | 356 PasswordFormBuilder builder(kTestFormActionURL); |
357 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); | 357 builder.AddPasswordField("password1", cases[i].password_values[0], NULL); |
358 builder.AddUsernameField("username1", "William", NULL); | 358 builder.AddUsernameField("username1", "William", NULL); |
359 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); | 359 builder.AddPasswordField("password2", cases[i].password_values[1], NULL); |
360 builder.AddUsernameField("username2", "Smith", NULL); | 360 builder.AddUsernameField("username2", "Smith", NULL); |
361 builder.AddPasswordField("password3", cases[i].password_values[2], NULL); | 361 builder.AddPasswordField("password3", cases[i].password_values[2], NULL); |
362 builder.AddSubmitButton("submit", true); | 362 builder.AddSubmitButton("submit", true); |
363 std::string html = builder.ProduceHTML(); | 363 std::string html = builder.ProduceHTML(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // It should not matter if attribute values are upper or mixed case. | 475 // It should not matter if attribute values are upper or mixed case. |
476 {{NULL, "current-password", NULL}, | 476 {{NULL, "current-password", NULL}, |
477 "password2", "beta", "", ""}, | 477 "password2", "beta", "", ""}, |
478 {{NULL, "CURRENT-PASSWORD", NULL}, | 478 {{NULL, "CURRENT-PASSWORD", NULL}, |
479 "password2", "beta", "", ""}, | 479 "password2", "beta", "", ""}, |
480 {{NULL, "new-password", NULL}, | 480 {{NULL, "new-password", NULL}, |
481 "", "", "password2", "beta"}, | 481 "", "", "password2", "beta"}, |
482 {{NULL, "nEw-PaSsWoRd", NULL}, | 482 {{NULL, "nEw-PaSsWoRd", NULL}, |
483 "", "", "password2", "beta"}}; | 483 "", "", "password2", "beta"}}; |
484 | 484 |
485 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 485 for (size_t i = 0; i < arraysize(cases); ++i) { |
486 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 486 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
487 | 487 |
488 PasswordFormBuilder builder(kTestFormActionURL); | 488 PasswordFormBuilder builder(kTestFormActionURL); |
489 builder.AddPasswordField("pin1", "123456", NULL); | 489 builder.AddPasswordField("pin1", "123456", NULL); |
490 builder.AddPasswordField("pin2", "789101", NULL); | 490 builder.AddPasswordField("pin2", "789101", NULL); |
491 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); | 491 builder.AddPasswordField("password1", "alpha", cases[i].autocomplete[0]); |
492 builder.AddUsernameField("username1", "William", NULL); | 492 builder.AddUsernameField("username1", "William", NULL); |
493 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); | 493 builder.AddPasswordField("password2", "beta", cases[i].autocomplete[1]); |
494 builder.AddUsernameField("username2", "Smith", NULL); | 494 builder.AddUsernameField("username2", "Smith", NULL); |
495 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); | 495 builder.AddPasswordField("password3", "gamma", cases[i].autocomplete[2]); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 const char* cases[][3] = { | 549 const char* cases[][3] = { |
550 // No autocomplete attributes to guide us, and we see: | 550 // No autocomplete attributes to guide us, and we see: |
551 // * three password values that are all different, | 551 // * three password values that are all different, |
552 // * three password values that are all the same; | 552 // * three password values that are all the same; |
553 // * three password values with the first and last matching. | 553 // * three password values with the first and last matching. |
554 // In any case, we should just give up on this form. | 554 // In any case, we should just give up on this form. |
555 {"alpha", "beta", "gamma"}, | 555 {"alpha", "beta", "gamma"}, |
556 {"alpha", "alpha", "alpha"}, | 556 {"alpha", "alpha", "alpha"}, |
557 {"alpha", "beta", "alpha"}}; | 557 {"alpha", "beta", "alpha"}}; |
558 | 558 |
559 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 559 for (size_t i = 0; i < arraysize(cases); ++i) { |
560 SCOPED_TRACE(testing::Message() << "Iteration " << i); | 560 SCOPED_TRACE(testing::Message() << "Iteration " << i); |
561 | 561 |
562 PasswordFormBuilder builder(kTestFormActionURL); | 562 PasswordFormBuilder builder(kTestFormActionURL); |
563 builder.AddUsernameField("username1", "John", NULL); | 563 builder.AddUsernameField("username1", "John", NULL); |
564 builder.AddPasswordField("password1", cases[i][0], NULL); | 564 builder.AddPasswordField("password1", cases[i][0], NULL); |
565 builder.AddPasswordField("password2", cases[i][1], NULL); | 565 builder.AddPasswordField("password2", cases[i][1], NULL); |
566 builder.AddPasswordField("password3", cases[i][2], NULL); | 566 builder.AddPasswordField("password3", cases[i][2], NULL); |
567 builder.AddSubmitButton("submit", true); | 567 builder.AddSubmitButton("submit", true); |
568 std::string html = builder.ProduceHTML(); | 568 std::string html = builder.ProduceHTML(); |
569 | 569 |
(...skipping 13 matching lines...) Expand all Loading... |
583 builder.AddPasswordField("password4", "alpha", NULL); | 583 builder.AddPasswordField("password4", "alpha", NULL); |
584 builder.AddSubmitButton("submit", true); | 584 builder.AddSubmitButton("submit", true); |
585 std::string html = builder.ProduceHTML(); | 585 std::string html = builder.ProduceHTML(); |
586 | 586 |
587 scoped_ptr<PasswordForm> password_form; | 587 scoped_ptr<PasswordForm> password_form; |
588 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); | 588 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); |
589 EXPECT_FALSE(password_form); | 589 EXPECT_FALSE(password_form); |
590 } | 590 } |
591 | 591 |
592 } // namespace autofill | 592 } // namespace autofill |
OLD | NEW |