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 TEST_F( | |
2089 PasswordAutofillAgentTest, | |
2090 SuggestionsOnSubmittingPasswordFormHavingFieldsWithAmbiguousOrNoNameOrIdAttr ibutes) { | |
vabr (Chromium)
2015/09/18 14:41:38
nit: This name is a bit too long. :) You might wan
Pritam Nikam
2015/09/21 10:51:17
Done.
| |
2091 const char kDummyUsernameField[] = "anonymous_username"; | |
2092 const char kDummyPasswordField[] = "anonymous_password"; | |
2093 const char kPasswordFormWithNoNameOrIdHTML[] = | |
2094 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2095 " <INPUT type='text' placeholder='username'/>" | |
2096 " <INPUT type='password' placeholder='Password'/>" | |
2097 " <INPUT type='submit' />" | |
2098 "</FORM>"; | |
2099 | |
2100 const char kChangePasswordFormWithNoNameOrIdHTML[] = | |
2101 "<FORM name='WithoutNameIdForm' action='http://www.bidule.com'>" | |
2102 " <INPUT type='text' placeholder='username'/>" | |
vabr (Chromium)
2015/09/18 14:41:38
Again, this looks like a sign-up form.
I would exp
dvadym
2015/09/18 15:59:00
A password change form may or may not contain old
Pritam Nikam
2015/09/21 10:51:17
Done.
Added attributes |autocomplete='current-pas
| |
2103 " <INPUT type='password' placeholder='Password'/>" | |
2104 " <INPUT type='password' placeholder='Confirm Password'/>" | |
2105 " <INPUT type='submit' />" | |
2106 "</FORM>"; | |
2107 | |
2108 const char kPasswordFormWithAmbiguousNameOrIdHTML[] = | |
2109 "<FORM name='AmbiguousNameIdForm' action='http://www.bidule.com'>" | |
2110 " <INPUT type='text' id='credentials' placeholder='username'/>" | |
2111 " <INPUT type='password' id='credentials' placeholder='Password'/>" | |
2112 " <INPUT type='submit' />" | |
2113 "</FORM>"; | |
2114 | |
2115 const struct { | |
2116 const char* html_form; | |
2117 const char* fill_data_username_field_name; | |
2118 const char* fill_data_password_field_name; | |
2119 const char* expected_username_suggestions; | |
2120 const char* expected_password_suggestions; | |
2121 bool expected_is_username_autofillable; | |
2122 bool expected_is_password_autofillable; | |
2123 } test_cases[] = { | |
2124 // Password form without name or id attributes specified for the input | |
2125 // fields. | |
2126 {kPasswordFormWithNoNameOrIdHTML, kDummyUsernameField, | |
2127 kDummyPasswordField, kAliceUsername, kAlicePassword, true, true}, | |
2128 | |
2129 // Change password form without name or id attributes specified for the | |
2130 // input fields. | |
2131 {kChangePasswordFormWithNoNameOrIdHTML, kDummyUsernameField, | |
2132 kDummyPasswordField, kAliceUsername, kAlicePassword, true, true}, | |
2133 | |
2134 // Password form with ambiguous name or id attributes specified for the | |
2135 // input fields. | |
2136 {kPasswordFormWithAmbiguousNameOrIdHTML, "credentials", "credentials", | |
2137 kAliceUsername, kAlicePassword, true, true}, | |
2138 }; | |
2139 | |
2140 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
vabr (Chromium)
2015/09/18 14:41:38
You can spare yourself the arraysize if you write:
Pritam Nikam
2015/09/21 10:51:17
Done.
| |
2141 SCOPED_TRACE(testing::Message() | |
2142 << "Iteration: " << i | |
2143 << ", html_form: " << test_cases[i].html_form | |
2144 << ", fill_data_username_field_name: " | |
2145 << test_cases[i].fill_data_username_field_name | |
2146 << ", fill_data_password_field_name: " | |
2147 << test_cases[i].fill_data_password_field_name); | |
2148 | |
2149 // Load a password form. | |
2150 LoadHTML(test_cases[i].html_form); | |
2151 | |
2152 blink::WebDocument document = GetMainFrame()->document(); | |
2153 blink::WebVector<blink::WebFormElement> forms; | |
2154 document.forms(forms); | |
2155 blink::WebFormElement form_element = forms[0]; | |
2156 std::vector<blink::WebFormControlElement> control_elements = | |
2157 ExtractAutofillableElementsInForm(form_element); | |
2158 username_element_ = control_elements[0].to<blink::WebInputElement>(); | |
2159 password_element_ = control_elements[1].to<blink::WebInputElement>(); | |
2160 | |
2161 UpdateOriginForHTML(test_cases[i].html_form); | |
2162 fill_data_.username_field.name = | |
2163 ASCIIToUTF16(test_cases[i].fill_data_username_field_name); | |
2164 fill_data_.password_field.name = | |
2165 ASCIIToUTF16(test_cases[i].fill_data_password_field_name); | |
2166 fill_data_.additional_logins.clear(); | |
2167 fill_data_.other_possible_usernames.clear(); | |
2168 | |
2169 ClearUsernameAndPasswordFields(); | |
2170 | |
2171 // Simulate the browser sending back the login info, it triggers the | |
2172 // autocomplete. | |
2173 SimulateOnFillPasswordForm(fill_data_); | |
2174 SimulateSuggestionChoice(username_element_); | |
2175 | |
2176 // The username and password should now have been autocompleted. | |
2177 CheckTextFieldsDOMState(test_cases[i].expected_username_suggestions, | |
2178 test_cases[i].expected_is_username_autofillable, | |
2179 test_cases[i].expected_password_suggestions, | |
2180 test_cases[i].expected_is_password_autofillable); | |
2181 } | |
2182 } | |
2183 | |
2088 } // namespace autofill | 2184 } // namespace autofill |
OLD | NEW |