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 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2206 prompt_observer->AcceptUpdatePrompt(stored_form); | 2206 prompt_observer->AcceptUpdatePrompt(stored_form); |
2207 // Spin the message loop to make sure the password store had a chance to | 2207 // Spin the message loop to make sure the password store had a chance to |
2208 // update the password. | 2208 // update the password. |
2209 base::RunLoop run_loop; | 2209 base::RunLoop run_loop; |
2210 run_loop.RunUntilIdle(); | 2210 run_loop.RunUntilIdle(); |
2211 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), | 2211 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), |
2212 base::ASCIIToUTF16("new_pw")); | 2212 base::ASCIIToUTF16("new_pw")); |
2213 } | 2213 } |
2214 #endif | 2214 #endif |
2215 | 2215 |
| 2216 // Test whether the password form with the username and password fields having |
| 2217 // ambiguity in id attribute gets autofilled correctly. |
| 2218 IN_PROC_BROWSER_TEST_F( |
| 2219 PasswordManagerBrowserTestBase, |
| 2220 AutofillSuggetionsForPasswordFormWithAmbiguousIdAttribute) { |
| 2221 // At first let us save credentials to the PasswordManager. |
| 2222 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2223 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2224 ServiceAccessType::IMPLICIT_ACCESS); |
| 2225 autofill::PasswordForm login_form; |
| 2226 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2227 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2228 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2229 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2230 password_store->AddLogin(login_form); |
| 2231 |
| 2232 // Logins are added asynchronously to the password store. Spin the message |
| 2233 // loop to make sure the |password_store| had a chance to store the |
| 2234 // |login_form|. |
| 2235 base::RunLoop run_loop; |
| 2236 run_loop.RunUntilIdle(); |
| 2237 |
| 2238 // Now, navigate to the password form having ambiguous Ids for username and |
| 2239 // password fields and verify whether username and password is autofilled. |
| 2240 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2241 |
| 2242 // Let the user interact with the page, so that DOM gets modification events, |
| 2243 // needed for autofilling fields. |
| 2244 content::SimulateMouseClickAt( |
| 2245 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2246 |
| 2247 std::string get_username = |
| 2248 "window.domAutomationController.send(" |
| 2249 " document.getElementById('ambiguous_form').elements[0].value);"; |
| 2250 std::string actual_username; |
| 2251 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2252 RenderViewHost(), get_username, &actual_username)); |
| 2253 EXPECT_EQ("myusername", actual_username); |
| 2254 |
| 2255 std::string get_password = |
| 2256 "window.domAutomationController.send(" |
| 2257 " document.getElementById('ambiguous_form').elements[1].value);"; |
| 2258 std::string actual_password; |
| 2259 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2260 RenderViewHost(), get_password, &actual_password)); |
| 2261 EXPECT_EQ("mypassword", actual_password); |
| 2262 } |
| 2263 |
| 2264 // Test whether the password form having username and password fields without |
| 2265 // name and id attribute gets autofilled correctly. |
| 2266 IN_PROC_BROWSER_TEST_F( |
| 2267 PasswordManagerBrowserTestBase, |
| 2268 AutofillSuggetionsForPasswordFormWithoutNameOrIdAttribute) { |
| 2269 // At first let us save credentials to the PasswordManager. |
| 2270 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2271 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2272 ServiceAccessType::IMPLICIT_ACCESS); |
| 2273 autofill::PasswordForm login_form; |
| 2274 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2275 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2276 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2277 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2278 password_store->AddLogin(login_form); |
| 2279 |
| 2280 // Logins are added asynchronously to the password store. Spin the message |
| 2281 // loop to make sure the |password_store| had a chance to store the |
| 2282 // |login_form|. |
| 2283 base::RunLoop run_loop; |
| 2284 run_loop.RunUntilIdle(); |
| 2285 |
| 2286 // Now, navigate to the password form having no Ids for username and password |
| 2287 // fields and verify whether username and password is autofilled. |
| 2288 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2289 |
| 2290 // Let the user interact with the page, so that DOM gets modification events, |
| 2291 // needed for autofilling fields. |
| 2292 content::SimulateMouseClickAt( |
| 2293 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2294 |
| 2295 std::string get_username = |
| 2296 "window.domAutomationController.send(" |
| 2297 " document.getElementById('no_name_id_form').elements[0].value);"; |
| 2298 std::string actual_username; |
| 2299 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2300 RenderViewHost(), get_username, &actual_username)); |
| 2301 EXPECT_EQ("myusername", actual_username); |
| 2302 |
| 2303 std::string get_password = |
| 2304 "window.domAutomationController.send(" |
| 2305 " document.getElementById('no_name_id_form').elements[1].value);"; |
| 2306 std::string actual_password; |
| 2307 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2308 RenderViewHost(), get_password, &actual_password)); |
| 2309 EXPECT_EQ("mypassword", actual_password); |
| 2310 } |
| 2311 |
| 2312 // Test whether the change password form having username and password fields |
| 2313 // without name and id attribute gets autofilled correctly. |
| 2314 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 2315 AutofillSuggetionsForChangePwdWithEmptyNames) { |
| 2316 // At first let us save credentials to the PasswordManager. |
| 2317 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2318 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2319 ServiceAccessType::IMPLICIT_ACCESS); |
| 2320 autofill::PasswordForm login_form; |
| 2321 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2322 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2323 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2324 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2325 password_store->AddLogin(login_form); |
| 2326 |
| 2327 // Logins are added asynchronously to the password store. Spin the message |
| 2328 // loop to make sure the |password_store| had a chance to store the |
| 2329 // |login_form|. |
| 2330 base::RunLoop run_loop; |
| 2331 run_loop.RunUntilIdle(); |
| 2332 |
| 2333 // Now, navigate to the password form having no Ids for username and password |
| 2334 // fields and verify whether username and password is autofilled. |
| 2335 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2336 |
| 2337 // Let the user interact with the page, so that DOM gets modification events, |
| 2338 // needed for autofilling fields. |
| 2339 content::SimulateMouseClickAt( |
| 2340 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2341 |
| 2342 std::string get_username = |
| 2343 "window.domAutomationController.send(" |
| 2344 " document.getElementById(" |
| 2345 " 'change_pwd_but_no_autocomplete').elements[0].value);"; |
| 2346 std::string actual_username; |
| 2347 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2348 RenderViewHost(), get_username, &actual_username)); |
| 2349 EXPECT_EQ("myusername", actual_username); |
| 2350 |
| 2351 std::string get_password = |
| 2352 "window.domAutomationController.send(" |
| 2353 " document.getElementById(" |
| 2354 " 'change_pwd_but_no_autocomplete').elements[1].value);"; |
| 2355 std::string actual_password; |
| 2356 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2357 RenderViewHost(), get_password, &actual_password)); |
| 2358 EXPECT_EQ("mypassword", actual_password); |
| 2359 |
| 2360 std::string get_new_password = |
| 2361 "window.domAutomationController.send(" |
| 2362 " document.getElementById(" |
| 2363 " 'change_pwd_but_no_autocomplete').elements[2].value);"; |
| 2364 std::string new_password; |
| 2365 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2366 RenderViewHost(), get_new_password, &new_password)); |
| 2367 EXPECT_EQ("", new_password); |
| 2368 } |
| 2369 |
| 2370 // Test whether the change password form having username and password fields |
| 2371 // with empty names but having |autocomplete='current-password'| gets autofilled |
| 2372 // correctly. |
| 2373 IN_PROC_BROWSER_TEST_F( |
| 2374 PasswordManagerBrowserTestBase, |
| 2375 AutofillSuggetionsForChangePwdWithEmptyNamesAndAutocomplete) { |
| 2376 // At first let us save credentials to the PasswordManager. |
| 2377 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2378 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2379 ServiceAccessType::IMPLICIT_ACCESS); |
| 2380 autofill::PasswordForm login_form; |
| 2381 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2382 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2383 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2384 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2385 password_store->AddLogin(login_form); |
| 2386 |
| 2387 // Logins are added asynchronously to the password store. Spin the message |
| 2388 // loop to make sure the |password_store| had a chance to store the |
| 2389 // |login_form|. |
| 2390 base::RunLoop run_loop; |
| 2391 run_loop.RunUntilIdle(); |
| 2392 |
| 2393 // Now, navigate to the password form having no Ids for username and password |
| 2394 // fields and verify whether username and password is autofilled. |
| 2395 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2396 |
| 2397 // Let the user interact with the page, so that DOM gets modification events, |
| 2398 // needed for autofilling fields. |
| 2399 content::SimulateMouseClickAt( |
| 2400 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2401 |
| 2402 std::string get_username = |
| 2403 "window.domAutomationController.send(" |
| 2404 " document.getElementById('change_pwd').elements[0].value);"; |
| 2405 std::string actual_username; |
| 2406 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2407 RenderViewHost(), get_username, &actual_username)); |
| 2408 EXPECT_EQ("myusername", actual_username); |
| 2409 |
| 2410 std::string get_password = |
| 2411 "window.domAutomationController.send(" |
| 2412 " document.getElementById('change_pwd').elements[1].value);"; |
| 2413 std::string actual_password; |
| 2414 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2415 RenderViewHost(), get_password, &actual_password)); |
| 2416 EXPECT_EQ("mypassword", actual_password); |
| 2417 |
| 2418 std::string get_new_password = |
| 2419 "window.domAutomationController.send(" |
| 2420 " document.getElementById('change_pwd').elements[2].value);"; |
| 2421 std::string new_password; |
| 2422 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2423 RenderViewHost(), get_new_password, &new_password)); |
| 2424 EXPECT_EQ("", new_password); |
| 2425 } |
| 2426 |
| 2427 // Test whether the change password form having username and password fields |
| 2428 // with empty names but having only new password fields having |
| 2429 // |autocomplete='new-password'| atrribute do not get autofilled. |
| 2430 IN_PROC_BROWSER_TEST_F( |
| 2431 PasswordManagerBrowserTestBase, |
| 2432 AutofillSuggetionsForChangePwdWithEmptyNamesButOnlyNewPwdField) { |
| 2433 // At first let us save credentials to the PasswordManager. |
| 2434 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2435 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2436 ServiceAccessType::IMPLICIT_ACCESS); |
| 2437 autofill::PasswordForm login_form; |
| 2438 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2439 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2440 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2441 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2442 password_store->AddLogin(login_form); |
| 2443 |
| 2444 // Logins are added asynchronously to the password store. Spin the message |
| 2445 // loop to make sure the |password_store| had a chance to store the |
| 2446 // |login_form|. |
| 2447 base::RunLoop run_loop; |
| 2448 run_loop.RunUntilIdle(); |
| 2449 |
| 2450 // Now, navigate to the password form having no Ids for username and password |
| 2451 // fields and verify whether username and password is autofilled. |
| 2452 NavigateToFile("/password/ambiguous_password_form.html"); |
| 2453 |
| 2454 // Let the user interact with the page, so that DOM gets modification events, |
| 2455 // needed for autofilling fields. |
| 2456 content::SimulateMouseClickAt( |
| 2457 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2458 |
| 2459 std::string get_username = |
| 2460 "window.domAutomationController.send(" |
| 2461 " document.getElementById(" |
| 2462 " 'change_pwd_but_no_old_pwd').elements[0].value);"; |
| 2463 std::string actual_username; |
| 2464 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2465 RenderViewHost(), get_username, &actual_username)); |
| 2466 EXPECT_EQ("", actual_username); |
| 2467 |
| 2468 std::string get_new_password = |
| 2469 "window.domAutomationController.send(" |
| 2470 " document.getElementById(" |
| 2471 " 'change_pwd_but_no_old_pwd').elements[1].value);"; |
| 2472 std::string new_password; |
| 2473 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2474 RenderViewHost(), get_new_password, &new_password)); |
| 2475 EXPECT_EQ("", new_password); |
| 2476 |
| 2477 std::string get_retype_password = |
| 2478 "window.domAutomationController.send(" |
| 2479 " document.getElementById(" |
| 2480 " 'change_pwd_but_no_old_pwd').elements[2].value);"; |
| 2481 std::string retyped_password; |
| 2482 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2483 RenderViewHost(), get_retype_password, &retyped_password)); |
| 2484 EXPECT_EQ("", retyped_password); |
| 2485 } |
| 2486 |
2216 } // namespace password_manager | 2487 } // namespace password_manager |
OLD | NEW |