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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // Appends a disabled text-type field at the end of the form. | 73 // Appends a disabled text-type field at the end of the form. |
74 void AddDisabledUsernameField() { | 74 void AddDisabledUsernameField() { |
75 html_ += "<INPUT type=\"text\" disabled/>"; | 75 html_ += "<INPUT type=\"text\" disabled/>"; |
76 } | 76 } |
77 | 77 |
78 // Appends a disabled password-type field at the end of the form. | 78 // Appends a disabled password-type field at the end of the form. |
79 void AddDisabledPasswordField() { | 79 void AddDisabledPasswordField() { |
80 html_ += "<INPUT type=\"password\" disabled/>"; | 80 html_ += "<INPUT type=\"password\" disabled/>"; |
81 } | 81 } |
82 | 82 |
| 83 // Appends a hidden field at the end of the form. |
| 84 void AddHiddenField() { html_ += "<INPUT type=\"hidden\"/>"; } |
| 85 |
83 // Appends a new submit-type field at the end of the form with the specified | 86 // Appends a new submit-type field at the end of the form with the specified |
84 // |name|. If |activated| is true, the test will emulate as if this button | 87 // |name|. If |activated| is true, the test will emulate as if this button |
85 // were used to submit the form. | 88 // were used to submit the form. |
86 void AddSubmitButton(const char* name, bool activated) { | 89 void AddSubmitButton(const char* name, bool activated) { |
87 base::StringAppendF( | 90 base::StringAppendF( |
88 &html_, | 91 &html_, |
89 "<INPUT type=\"submit\" name=\"%s\" value=\"Submit\" %s/>", | 92 "<INPUT type=\"submit\" name=\"%s\" value=\"Submit\" %s/>", |
90 name, activated ? "set-activated-submit" : ""); | 93 name, activated ? "set-activated-submit" : ""); |
91 } | 94 } |
92 | 95 |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 builder.AddPasswordField("password3", "alpha", NULL); | 588 builder.AddPasswordField("password3", "alpha", NULL); |
586 builder.AddPasswordField("password4", "alpha", NULL); | 589 builder.AddPasswordField("password4", "alpha", NULL); |
587 builder.AddSubmitButton("submit", true); | 590 builder.AddSubmitButton("submit", true); |
588 std::string html = builder.ProduceHTML(); | 591 std::string html = builder.ProduceHTML(); |
589 | 592 |
590 scoped_ptr<PasswordForm> password_form; | 593 scoped_ptr<PasswordForm> password_form; |
591 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); | 594 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(html, &password_form)); |
592 EXPECT_FALSE(password_form); | 595 EXPECT_FALSE(password_form); |
593 } | 596 } |
594 | 597 |
| 598 TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLogin) { |
| 599 PasswordFormBuilder builder(kTestFormActionURL); |
| 600 builder.AddHiddenField(); |
| 601 builder.AddUsernameField("username", "", nullptr); |
| 602 builder.AddPasswordField("password", "", nullptr); |
| 603 builder.AddSubmitButton("submit", false); |
| 604 std::string login_html = builder.ProduceHTML(); |
| 605 |
| 606 scoped_ptr<PasswordForm> login_form; |
| 607 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(login_html, &login_form)); |
| 608 ASSERT_TRUE(login_form); |
| 609 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, login_form->layout); |
| 610 } |
| 611 |
| 612 TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationSignup) { |
| 613 PasswordFormBuilder builder(kTestFormActionURL); |
| 614 builder.AddUsernameField("someotherfield", "", nullptr); |
| 615 builder.AddUsernameField("username", "", nullptr); |
| 616 builder.AddPasswordField("new_password", "", nullptr); |
| 617 builder.AddHiddenField(); |
| 618 builder.AddPasswordField("new_password2", "", nullptr); |
| 619 builder.AddSubmitButton("submit", false); |
| 620 std::string signup_html = builder.ProduceHTML(); |
| 621 |
| 622 scoped_ptr<PasswordForm> signup_form; |
| 623 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(signup_html, &signup_form)); |
| 624 ASSERT_TRUE(signup_form); |
| 625 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, signup_form->layout); |
| 626 } |
| 627 |
| 628 TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationChange) { |
| 629 PasswordFormBuilder builder(kTestFormActionURL); |
| 630 builder.AddUsernameField("username", "", nullptr); |
| 631 builder.AddPasswordField("old_password", "", nullptr); |
| 632 builder.AddHiddenField(); |
| 633 builder.AddPasswordField("new_password", "", nullptr); |
| 634 builder.AddPasswordField("new_password2", "", nullptr); |
| 635 builder.AddSubmitButton("submit", false); |
| 636 std::string change_html = builder.ProduceHTML(); |
| 637 |
| 638 scoped_ptr<PasswordForm> change_form; |
| 639 ASSERT_NO_FATAL_FAILURE(LoadHTMLAndConvertForm(change_html, &change_form)); |
| 640 ASSERT_TRUE(change_form); |
| 641 EXPECT_EQ(PasswordForm::Layout::LAYOUT_OTHER, change_form->layout); |
| 642 } |
| 643 |
| 644 TEST_F(PasswordFormConversionUtilsTest, LayoutClassificationLoginPlusSignup) { |
| 645 PasswordFormBuilder builder(kTestFormActionURL); |
| 646 builder.AddUsernameField("username", "", nullptr); |
| 647 builder.AddHiddenField(); |
| 648 builder.AddPasswordField("password", "", nullptr); |
| 649 builder.AddUsernameField("username2", "", nullptr); |
| 650 builder.AddUsernameField("someotherfield", "", nullptr); |
| 651 builder.AddPasswordField("new_password", "", nullptr); |
| 652 builder.AddPasswordField("new_password2", "", nullptr); |
| 653 builder.AddHiddenField(); |
| 654 builder.AddSubmitButton("submit", false); |
| 655 std::string login_plus_signup_html = builder.ProduceHTML(); |
| 656 |
| 657 scoped_ptr<PasswordForm> login_plus_signup_form; |
| 658 ASSERT_NO_FATAL_FAILURE( |
| 659 LoadHTMLAndConvertForm(login_plus_signup_html, &login_plus_signup_form)); |
| 660 ASSERT_TRUE(login_plus_signup_form); |
| 661 EXPECT_EQ(PasswordForm::Layout::LAYOUT_LOGIN_AND_SIGNUP, |
| 662 login_plus_signup_form->layout); |
| 663 } |
| 664 |
595 } // namespace autofill | 665 } // namespace autofill |
OLD | NEW |