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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/renderer/autofill/password_generation_test_utils.h" | 7 #include "chrome/renderer/autofill/password_generation_test_utils.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 8 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "components/autofill/content/common/autofill_messages.h" | 9 #include "components/autofill/content/common/autofill_messages.h" |
10 #include "components/autofill/content/renderer/autofill_agent.h" | 10 #include "components/autofill/content/renderer/autofill_agent.h" |
(...skipping 2067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2078 SimulatePasswordChange("mypassword"); | 2078 SimulatePasswordChange("mypassword"); |
2079 | 2079 |
2080 password_autofill_agent_->AJAXSucceeded(); | 2080 password_autofill_agent_->AJAXSucceeded(); |
2081 | 2081 |
2082 const IPC::Message* message = | 2082 const IPC::Message* message = |
2083 render_thread_->sink().GetFirstMessageMatching( | 2083 render_thread_->sink().GetFirstMessageMatching( |
2084 AutofillHostMsg_PasswordFormSubmitted::ID); | 2084 AutofillHostMsg_PasswordFormSubmitted::ID); |
2085 ASSERT_FALSE(message); | 2085 ASSERT_FALSE(message); |
2086 } | 2086 } |
2087 | 2087 |
2088 // Tests that credential suggestions are getting autofill on a password (and | |
vabr (Chromium)
2015/09/23 11:23:24
nit: getting autofill -> autofilled
(Or did you me
Pritam Nikam
2015/09/24 12:10:40
Done.
| |
2089 // change password) forms having either ambiguous or empty name. | |
2090 TEST_F(PasswordAutofillAgentTest, | |
2091 SuggestionsOnFormContainingAmbiguousOrEmptyNames) { | |
2092 const char kEmpty[] = ""; | |
2093 const char kDummyUsernameField[] = "anonymous_username"; | |
2094 const char kDummyPasswordField[] = "anonymous_password"; | |
2095 const char kFormContainsEmptyNamesHTML[] = | |
2096 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2097 " <INPUT type='text' placeholder='username'/>" | |
2098 " <INPUT type='password' placeholder='Password'/>" | |
2099 " <INPUT type='submit' />" | |
2100 "</FORM>"; | |
2101 | |
2102 const char kFormContainsAmbiguousNamesHTML[] = | |
2103 "<FORM name='AmbiguousNameIdForm' action='http://www.bidule.com'>" | |
2104 " <INPUT type='text' id='credentials' placeholder='username' />" | |
2105 " <INPUT type='password' id='credentials' placeholder='Password' />" | |
2106 " <INPUT type='submit' />" | |
2107 "</FORM>"; | |
2108 | |
2109 const char kChangePasswordFormContainsEmptyNamesHTML[] = | |
2110 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2111 " <INPUT type='text' placeholder='username' />" | |
2112 " <INPUT type='password' placeholder='Old Password' " | |
2113 "autocomplete='current-password' />" | |
2114 " <INPUT type='password' placeholder='New Password' " | |
2115 "autocomplete='new-password' />" | |
2116 " <INPUT type='submit' />" | |
2117 "</FORM>"; | |
2118 | |
2119 const char kChangePasswordFormButNoUsername[] = | |
2120 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2121 " <INPUT type='password' placeholder='Old Password' " | |
2122 "autocomplete='current-password' />" | |
2123 " <INPUT type='password' placeholder='New Password' " | |
2124 "autocomplete='new-password' />" | |
2125 " <INPUT type='submit' />" | |
2126 "</FORM>"; | |
2127 | |
2128 const char kChangePasswordFormButNoOldPassword[] = | |
2129 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2130 " <INPUT type='text' placeholder='username' />" | |
2131 " <INPUT type='password' placeholder='New Password' " | |
2132 "autocomplete='new-password' />" | |
2133 " <INPUT type='password' placeholder='Retype Password' " | |
2134 "autocomplete='new-password' />" | |
2135 " <INPUT type='submit' />" | |
2136 "</FORM>"; | |
2137 | |
2138 const char kChangePasswordFormButNoAutocompleteAttribute[] = | |
2139 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2140 " <INPUT type='text' placeholder='username' />" | |
2141 " <INPUT type='password' placeholder='Old Password' />" | |
2142 " <INPUT type='password' placeholder='New Password' />" | |
2143 " <INPUT type='submit' />" | |
2144 "</FORM>"; | |
2145 | |
2146 const struct { | |
2147 const char* html_form; | |
2148 const char* fill_data_username_field_name; | |
2149 const char* fill_data_password_field_name; | |
2150 const char* expected_username_suggestions; | |
2151 const char* expected_password_suggestions; | |
2152 bool expected_is_username_autofillable; | |
2153 bool expected_is_password_autofillable; | |
2154 } test_cases[] = { | |
2155 // Password form without name or id attributes specified for the input | |
2156 // fields. | |
2157 {kFormContainsEmptyNamesHTML, kDummyUsernameField, kDummyPasswordField, | |
2158 kAliceUsername, kAlicePassword, true, true}, | |
2159 | |
2160 // Password form with ambiguous name or id attributes specified for the | |
2161 // input fields. | |
2162 {kFormContainsAmbiguousNamesHTML, "credentials", "credentials", | |
2163 kAliceUsername, kAlicePassword, true, true}, | |
2164 | |
2165 // Change password form without name or id attributes specified for the | |
2166 // input fields and |autocomplete='current-password'| attribute for old | |
2167 // password field. | |
2168 {kChangePasswordFormContainsEmptyNamesHTML, kDummyUsernameField, | |
2169 kDummyPasswordField, kAliceUsername, kAlicePassword, true, true}, | |
2170 | |
2171 // Change password form without optional username field. | |
2172 {kChangePasswordFormButNoUsername, kEmpty, kDummyPasswordField, kEmpty, | |
2173 kAlicePassword, false, true}, | |
2174 | |
2175 // Change password form without name or id attributes specified for the | |
2176 // input fields and |autocomplete='new-password'| attribute for new | |
2177 // password fields. | |
2178 {kChangePasswordFormButNoOldPassword, kDummyUsernameField, | |
2179 kDummyPasswordField, kEmpty, kEmpty, false, false}, | |
2180 | |
2181 // Change password form without name or id attributes specified for the | |
2182 // input fields but |autocomplete='current-password'| attribute is missing | |
2183 // for old password field. | |
2184 {kChangePasswordFormButNoAutocompleteAttribute, kDummyUsernameField, | |
2185 kDummyPasswordField, kEmpty, kEmpty, false, false}, | |
2186 }; | |
2187 | |
2188 for (const auto& test_case : test_cases) { | |
2189 SCOPED_TRACE(testing::Message() << "html_form: " << test_case.html_form | |
2190 << ", fill_data_username_field_name: " | |
2191 << test_case.fill_data_username_field_name | |
2192 << ", fill_data_password_field_name: " | |
2193 << test_case.fill_data_password_field_name); | |
2194 | |
2195 // Load a password form. | |
2196 LoadHTML(test_case.html_form); | |
2197 | |
2198 blink::WebDocument document = GetMainFrame()->document(); | |
2199 blink::WebVector<blink::WebFormElement> forms; | |
2200 document.forms(forms); | |
2201 blink::WebFormElement form_element = forms[0]; | |
2202 std::vector<blink::WebFormControlElement> control_elements = | |
2203 ExtractAutofillableElementsInForm(form_element); | |
2204 bool has_fillable_username = | |
2205 (kEmpty != test_case.fill_data_username_field_name); | |
2206 if (has_fillable_username) { | |
2207 username_element_ = control_elements[0].to<blink::WebInputElement>(); | |
2208 password_element_ = control_elements[1].to<blink::WebInputElement>(); | |
2209 } else { | |
2210 password_element_ = control_elements[0].to<blink::WebInputElement>(); | |
2211 } | |
2212 | |
2213 UpdateOriginForHTML(test_case.html_form); | |
2214 fill_data_.username_field.name = | |
2215 ASCIIToUTF16(test_case.fill_data_username_field_name); | |
2216 fill_data_.password_field.name = | |
2217 ASCIIToUTF16(test_case.fill_data_password_field_name); | |
2218 fill_data_.additional_logins.clear(); | |
2219 fill_data_.other_possible_usernames.clear(); | |
2220 | |
2221 ClearUsernameAndPasswordFields(); | |
2222 | |
2223 // Simulate the browser sending back the login info, it triggers the | |
2224 // autocomplete. | |
2225 SimulateOnFillPasswordForm(fill_data_); | |
2226 | |
2227 if (has_fillable_username) { | |
2228 SimulateSuggestionChoice(username_element_); | |
2229 } else { | |
2230 SimulateSuggestionChoice(password_element_); | |
2231 } | |
2232 | |
2233 // The username and password should now have been autocompleted. | |
2234 CheckTextFieldsDOMState(test_case.expected_username_suggestions, | |
2235 test_case.expected_is_username_autofillable, | |
2236 test_case.expected_password_suggestions, | |
2237 test_case.expected_is_password_autofillable); | |
2238 } | |
2239 } | |
2240 | |
2088 } // namespace autofill | 2241 } // namespace autofill |
OLD | NEW |