| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 const char* value) { | 96 const char* value) { |
| 97 base::StringAppendF( | 97 base::StringAppendF( |
| 98 &html_, | 98 &html_, |
| 99 "<INPUT type=\"hidden\" name=\"%s\" id=\"%s\" value=\"%s\" />", | 99 "<INPUT type=\"hidden\" name=\"%s\" id=\"%s\" value=\"%s\" />", |
| 100 name_and_id, name_and_id, value); | 100 name_and_id, name_and_id, value); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Append a text field with "display: none". | 103 // Append a text field with "display: none". |
| 104 void AddNonDisplayedTextField(const char* name_and_id, | 104 void AddNonDisplayedTextField(const char* name_and_id, |
| 105 const char* value) { | 105 const char* value) { |
| 106 // TODO(crbug.com/570628): Add tests with style="visibility: hidden;" too | |
| 107 // when IsWebNodeVisible in form_autofill_util.cc has changed according to | |
| 108 // esprehn's TODO in the function. Now tests with visibility attribute fail. | |
| 109 base::StringAppendF( | 106 base::StringAppendF( |
| 110 &html_, | 107 &html_, |
| 111 "<INPUT type=\"text\" name=\"%s\" id=\"%s\" value=\"%s\"" | 108 "<INPUT type=\"text\" name=\"%s\" id=\"%s\" value=\"%s\"" |
| 112 "style=\"display: none;\"/>", | 109 "style=\"display: none;\"/>", |
| 113 name_and_id, name_and_id, value); | 110 name_and_id, name_and_id, value); |
| 114 } | 111 } |
| 115 | 112 |
| 116 // Append a password field with "display: none". | 113 // Append a password field with "display: none". |
| 117 void AddNonDisplayedPasswordField(const char* name_and_id, | 114 void AddNonDisplayedPasswordField(const char* name_and_id, |
| 118 const char* value) { | 115 const char* value) { |
| 119 base::StringAppendF( | 116 base::StringAppendF( |
| 120 &html_, | 117 &html_, |
| 121 "<INPUT type=\"password\" name=\"%s\" id=\"%s\" value=\"%s\"" | 118 "<INPUT type=\"password\" name=\"%s\" id=\"%s\" value=\"%s\"" |
| 122 "style=\"display: none;\"/>", | 119 "style=\"display: none;\"/>", |
| 123 name_and_id, name_and_id, value); | 120 name_and_id, name_and_id, value); |
| 124 } | 121 } |
| 125 | 122 |
| 123 // Append a text field with "visibility: hidden". |
| 124 void AddNonVisibleTextField(const char* name_and_id, const char* value) { |
| 125 base::StringAppendF( |
| 126 &html_, |
| 127 "<INPUT type=\"text\" name=\"%s\" id=\"%s\" value=\"%s\"" |
| 128 "style=\"visibility: hidden;\"/>", |
| 129 name_and_id, name_and_id, value); |
| 130 } |
| 131 |
| 132 // Append a password field with "visibility: hidden". |
| 133 void AddNonVisiblePasswordField(const char* name_and_id, const char* value) { |
| 134 base::StringAppendF( |
| 135 &html_, |
| 136 "<INPUT type=\"password\" name=\"%s\" id=\"%s\" value=\"%s\"" |
| 137 "style=\"visibility: hidden;\"/>", |
| 138 name_and_id, name_and_id, value); |
| 139 } |
| 140 |
| 126 // Appends a new submit-type field at the end of the form with the specified | 141 // Appends a new submit-type field at the end of the form with the specified |
| 127 // |name|. | 142 // |name|. |
| 128 void AddSubmitButton(const char* name) { | 143 void AddSubmitButton(const char* name) { |
| 129 base::StringAppendF( | 144 base::StringAppendF( |
| 130 &html_, | 145 &html_, |
| 131 "<INPUT type=\"submit\" name=\"%s\" value=\"Submit\"/>", | 146 "<INPUT type=\"submit\" name=\"%s\" value=\"Submit\"/>", |
| 132 name); | 147 name); |
| 133 } | 148 } |
| 134 | 149 |
| 135 // Returns the HTML code for the form containing the fields that have been | 150 // Returns the HTML code for the form containing the fields that have been |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 password_form->password_value); | 901 password_form->password_value); |
| 887 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), | 902 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_element), |
| 888 password_form->new_password_element); | 903 password_form->new_password_element); |
| 889 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), | 904 EXPECT_EQ(base::UTF8ToUTF16(cases[i].expected_new_password_value), |
| 890 password_form->new_password_value); | 905 password_form->new_password_value); |
| 891 EXPECT_EQ(cases[i].expected_new_password_marked_by_site, | 906 EXPECT_EQ(cases[i].expected_new_password_marked_by_site, |
| 892 password_form->new_password_marked_by_site); | 907 password_form->new_password_marked_by_site); |
| 893 } | 908 } |
| 894 } | 909 } |
| 895 | 910 |
| 896 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedTextFields) { | 911 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreInvisibledTextFields) { |
| 897 PasswordFormBuilder builder(kTestFormActionURL); | 912 PasswordFormBuilder builder(kTestFormActionURL); |
| 898 | 913 |
| 899 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); | 914 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
| 915 builder.AddNonVisibleTextField("nonvisible1", "nonvisible_value1"); |
| 900 builder.AddTextField("username", "johnsmith", nullptr); | 916 builder.AddTextField("username", "johnsmith", nullptr); |
| 901 builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); | 917 builder.AddNonDisplayedTextField("nondisplayed2", "nodispalyed_value2"); |
| 918 builder.AddNonVisiblePasswordField("nonvisible2", "nonvisible_value2"); |
| 902 builder.AddPasswordField("password", "secret", nullptr); | 919 builder.AddPasswordField("password", "secret", nullptr); |
| 903 builder.AddPasswordField("password", "secret", nullptr); | 920 builder.AddPasswordField("password", "secret", nullptr); |
| 904 builder.AddSubmitButton("submit"); | 921 builder.AddSubmitButton("submit"); |
| 905 std::string html = builder.ProduceHTML(); | 922 std::string html = builder.ProduceHTML(); |
| 906 | 923 |
| 907 std::unique_ptr<PasswordForm> password_form = | 924 std::unique_ptr<PasswordForm> password_form = |
| 908 LoadHTMLAndConvertForm(html, nullptr, false); | 925 LoadHTMLAndConvertForm(html, nullptr, false); |
| 909 ASSERT_TRUE(password_form); | 926 ASSERT_TRUE(password_form); |
| 910 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 927 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 911 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 928 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 912 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); | 929 EXPECT_EQ(base::UTF8ToUTF16(""), password_form->password_element); |
| 913 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); | 930 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->new_password_element); |
| 914 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); | 931 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->new_password_value); |
| 915 } | 932 } |
| 916 | 933 |
| 917 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreNonDisplayedLoginPairs) { | 934 TEST_F(MAYBE_PasswordFormConversionUtilsTest, IgnoreInvisiblLoginPairs) { |
| 918 PasswordFormBuilder builder(kTestFormActionURL); | 935 PasswordFormBuilder builder(kTestFormActionURL); |
| 919 | 936 |
| 920 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); | 937 builder.AddNonDisplayedTextField("nondisplayed1", "nodispalyed_value1"); |
| 921 builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); | 938 builder.AddNonDisplayedPasswordField("nondisplayed2", "nodispalyed_value2"); |
| 939 builder.AddNonVisibleTextField("nonvisible1", "nonvisible_value1"); |
| 940 builder.AddNonVisiblePasswordField("nonvisible2", "nonvisible_value2"); |
| 922 builder.AddTextField("username", "johnsmith", nullptr); | 941 builder.AddTextField("username", "johnsmith", nullptr); |
| 942 builder.AddNonVisibleTextField("nonvisible3", "nonvisible_value3"); |
| 943 builder.AddNonVisiblePasswordField("nonvisible4", "nonvisible_value4"); |
| 923 builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); | 944 builder.AddNonDisplayedTextField("nondisplayed3", "nodispalyed_value3"); |
| 924 builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); | 945 builder.AddNonDisplayedPasswordField("nondisplayed4", "nodispalyed_value4"); |
| 925 builder.AddPasswordField("password", "secret", nullptr); | 946 builder.AddPasswordField("password", "secret", nullptr); |
| 926 builder.AddPasswordField("password", "secret", nullptr); | 947 builder.AddPasswordField("password", "secret", nullptr); |
| 927 builder.AddSubmitButton("submit"); | 948 builder.AddSubmitButton("submit"); |
| 928 std::string html = builder.ProduceHTML(); | 949 std::string html = builder.ProduceHTML(); |
| 929 | 950 |
| 930 std::unique_ptr<PasswordForm> password_form = | 951 std::unique_ptr<PasswordForm> password_form = |
| 931 LoadHTMLAndConvertForm(html, nullptr, false); | 952 LoadHTMLAndConvertForm(html, nullptr, false); |
| 932 ASSERT_TRUE(password_form); | 953 ASSERT_TRUE(password_form); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 951 EXPECT_EQ(base::UTF8ToUTF16("username"), | 972 EXPECT_EQ(base::UTF8ToUTF16("username"), |
| 952 password_form->username_element); | 973 password_form->username_element); |
| 953 EXPECT_EQ(base::UTF8ToUTF16("William"), | 974 EXPECT_EQ(base::UTF8ToUTF16("William"), |
| 954 password_form->username_value); | 975 password_form->username_value); |
| 955 EXPECT_EQ(base::UTF8ToUTF16("password"), | 976 EXPECT_EQ(base::UTF8ToUTF16("password"), |
| 956 password_form->password_element); | 977 password_form->password_element); |
| 957 EXPECT_EQ(base::UTF8ToUTF16("secret"), | 978 EXPECT_EQ(base::UTF8ToUTF16("secret"), |
| 958 password_form->password_value); | 979 password_form->password_value); |
| 959 } | 980 } |
| 960 | 981 |
| 982 TEST_F(MAYBE_PasswordFormConversionUtilsTest, OnlyNonVisibleLoginPair) { |
| 983 PasswordFormBuilder builder(kTestFormActionURL); |
| 984 |
| 985 builder.AddNonVisibleTextField("username", "William"); |
| 986 builder.AddNonVisiblePasswordField("password", "secret"); |
| 987 builder.AddSubmitButton("submit"); |
| 988 std::string html = builder.ProduceHTML(); |
| 989 |
| 990 std::unique_ptr<PasswordForm> password_form = |
| 991 LoadHTMLAndConvertForm(html, nullptr, false); |
| 992 ASSERT_TRUE(password_form); |
| 993 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 994 EXPECT_EQ(base::UTF8ToUTF16("William"), password_form->username_value); |
| 995 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 996 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 997 } |
| 998 |
| 961 TEST_F(MAYBE_PasswordFormConversionUtilsTest, | 999 TEST_F(MAYBE_PasswordFormConversionUtilsTest, |
| 962 VisiblePasswordAndInvisibleUsername) { | 1000 VisiblePasswordAndInvisibleUsername) { |
| 963 PasswordFormBuilder builder(kTestFormActionURL); | 1001 PasswordFormBuilder builder(kTestFormActionURL); |
| 964 | 1002 |
| 965 builder.AddNonDisplayedTextField("username", "William"); | 1003 builder.AddNonDisplayedTextField("username", "William"); |
| 966 builder.AddPasswordField("password", "secret", nullptr); | 1004 builder.AddPasswordField("password", "secret", nullptr); |
| 967 builder.AddSubmitButton("submit"); | 1005 builder.AddSubmitButton("submit"); |
| 968 std::string html = builder.ProduceHTML(); | 1006 std::string html = builder.ProduceHTML(); |
| 969 | 1007 |
| 970 std::unique_ptr<PasswordForm> password_form = | 1008 std::unique_ptr<PasswordForm> password_form = |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 | 1570 |
| 1533 ASSERT_TRUE(password_form); | 1571 ASSERT_TRUE(password_form); |
| 1534 | 1572 |
| 1535 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); | 1573 EXPECT_EQ(base::UTF8ToUTF16("username"), password_form->username_element); |
| 1536 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); | 1574 EXPECT_EQ(base::UTF8ToUTF16("johnsmith"), password_form->username_value); |
| 1537 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); | 1575 EXPECT_EQ(base::UTF8ToUTF16("password"), password_form->password_element); |
| 1538 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); | 1576 EXPECT_EQ(base::UTF8ToUTF16("secret"), password_form->password_value); |
| 1539 } | 1577 } |
| 1540 | 1578 |
| 1541 } // namespace autofill | 1579 } // namespace autofill |
| OLD | NEW |