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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
9 #include "base/metrics/statistics_recorder.h" | 9 #include "base/metrics/statistics_recorder.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 2149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2160 prompt_observer->AcceptUpdatePrompt(stored_form); | 2160 prompt_observer->AcceptUpdatePrompt(stored_form); |
2161 // Spin the message loop to make sure the password store had a chance to | 2161 // Spin the message loop to make sure the password store had a chance to |
2162 // update the password. | 2162 // update the password. |
2163 base::RunLoop run_loop; | 2163 base::RunLoop run_loop; |
2164 run_loop.RunUntilIdle(); | 2164 run_loop.RunUntilIdle(); |
2165 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), | 2165 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), |
2166 base::ASCIIToUTF16("new_pw")); | 2166 base::ASCIIToUTF16("new_pw")); |
2167 } | 2167 } |
2168 #endif | 2168 #endif |
2169 | 2169 |
| 2170 // Test whether the password form with the username and password fields having |
| 2171 // ambiguity in id attribute gets autofilled correctly. |
| 2172 IN_PROC_BROWSER_TEST_F( |
| 2173 PasswordManagerBrowserTestBase, |
| 2174 AutofillSuggetionsForPasswordFormWithAmbiguousIdAttribute) { |
| 2175 // At first let us save credentials to the PasswordManager. |
| 2176 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2177 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2178 ServiceAccessType::IMPLICIT_ACCESS); |
| 2179 autofill::PasswordForm login_form; |
| 2180 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2181 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2182 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2183 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2184 password_store->AddLogin(login_form); |
| 2185 |
| 2186 // Logins are added asynchronously to the password store. Spin the message |
| 2187 // loop to make sure the |password_store| had a chance to store the |
| 2188 // |login_form|. |
| 2189 base::RunLoop run_loop; |
| 2190 run_loop.RunUntilIdle(); |
| 2191 |
| 2192 // Now, navigate to the password form having ambiguous Ids for username and |
| 2193 // password fields and verify whether username and password is autofilled. |
| 2194 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2195 |
| 2196 // Let the user interact with the page, so that DOM gets modification events, |
| 2197 // needed for autofilling fields. |
| 2198 content::SimulateMouseClickAt( |
| 2199 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2200 |
| 2201 std::string get_username = |
| 2202 "window.domAutomationController.send(" |
| 2203 " document.getElementById('ambiguous_form').elements[0].value);"; |
| 2204 std::string actual_username; |
| 2205 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2206 RenderViewHost(), get_username, &actual_username)); |
| 2207 EXPECT_EQ("myusername", actual_username); |
| 2208 |
| 2209 std::string get_password = |
| 2210 "window.domAutomationController.send(" |
| 2211 " document.getElementById('ambiguous_form').elements[1].value);"; |
| 2212 std::string actual_password; |
| 2213 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2214 RenderViewHost(), get_password, &actual_password)); |
| 2215 EXPECT_EQ("mypassword", actual_password); |
| 2216 } |
| 2217 |
| 2218 // Test whether the password form having username and password fields without |
| 2219 // name and id attribute gets autofilled correctly. |
| 2220 IN_PROC_BROWSER_TEST_F( |
| 2221 PasswordManagerBrowserTestBase, |
| 2222 AutofillSuggetionsForPasswordFormWithoutNameOrIdAttribute) { |
| 2223 // At first let us save credentials to the PasswordManager. |
| 2224 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2225 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2226 ServiceAccessType::IMPLICIT_ACCESS); |
| 2227 autofill::PasswordForm login_form; |
| 2228 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2229 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2230 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2231 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2232 password_store->AddLogin(login_form); |
| 2233 |
| 2234 // Logins are added asynchronously to the password store. Spin the message |
| 2235 // loop to make sure the |password_store| had a chance to store the |
| 2236 // |login_form|. |
| 2237 base::RunLoop run_loop; |
| 2238 run_loop.RunUntilIdle(); |
| 2239 |
| 2240 // Now, navigate to the password form having no Ids for username and password |
| 2241 // fields and verify whether username and password is autofilled. |
| 2242 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2243 |
| 2244 // Let the user interact with the page, so that DOM gets modification events, |
| 2245 // needed for autofilling fields. |
| 2246 content::SimulateMouseClickAt( |
| 2247 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2248 |
| 2249 std::string get_username = |
| 2250 "window.domAutomationController.send(" |
| 2251 " document.getElementById('no_name_id_form').elements[0].value);"; |
| 2252 std::string actual_username; |
| 2253 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2254 RenderViewHost(), get_username, &actual_username)); |
| 2255 EXPECT_EQ("myusername", actual_username); |
| 2256 |
| 2257 std::string get_password = |
| 2258 "window.domAutomationController.send(" |
| 2259 " document.getElementById('no_name_id_form').elements[1].value);"; |
| 2260 std::string actual_password; |
| 2261 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2262 RenderViewHost(), get_password, &actual_password)); |
| 2263 EXPECT_EQ("mypassword", actual_password); |
| 2264 } |
| 2265 |
| 2266 // Test whether the change password form having username and password fields |
| 2267 // without name and id attribute gets autofilled correctly. |
| 2268 IN_PROC_BROWSER_TEST_F( |
| 2269 PasswordManagerBrowserTestBase, |
| 2270 AutofillSuggetionsForChangePasswordFormWithoutNameOrIdAttribute) { |
| 2271 // At first let us save credentials to the PasswordManager. |
| 2272 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2273 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2274 ServiceAccessType::IMPLICIT_ACCESS); |
| 2275 autofill::PasswordForm login_form; |
| 2276 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2277 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2278 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2279 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2280 password_store->AddLogin(login_form); |
| 2281 |
| 2282 // Logins are added asynchronously to the password store. Spin the message |
| 2283 // loop to make sure the |password_store| had a chance to store the |
| 2284 // |login_form|. |
| 2285 base::RunLoop run_loop; |
| 2286 run_loop.RunUntilIdle(); |
| 2287 |
| 2288 // Now, navigate to the password form having no Ids for username and password |
| 2289 // fields and verify whether username and password is autofilled. |
| 2290 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2291 |
| 2292 // Let the user interact with the page, so that DOM gets modification events, |
| 2293 // needed for autofilling fields. |
| 2294 content::SimulateMouseClickAt( |
| 2295 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2296 |
| 2297 std::string get_username = |
| 2298 "window.domAutomationController.send(" |
| 2299 " document.getElementById('change_pwd_no_name_id').elements[0].value);"; |
| 2300 std::string actual_username; |
| 2301 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2302 RenderViewHost(), get_username, &actual_username)); |
| 2303 EXPECT_EQ("myusername", actual_username); |
| 2304 |
| 2305 std::string get_password = |
| 2306 "window.domAutomationController.send(" |
| 2307 " document.getElementById('change_pwd_no_name_id').elements[1].value);"; |
| 2308 std::string actual_password; |
| 2309 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2310 RenderViewHost(), get_password, &actual_password)); |
| 2311 EXPECT_EQ("mypassword", actual_password); |
| 2312 } |
| 2313 |
2170 } // namespace password_manager | 2314 } // namespace password_manager |
OLD | NEW |