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 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2545 auth_needed_observer.Wait(); | 2545 auth_needed_observer.Wait(); |
2546 | 2546 |
2547 // The auth dialog caused a query to PasswordStore, make sure it was | 2547 // The auth dialog caused a query to PasswordStore, make sure it was |
2548 // processed. | 2548 // processed. |
2549 base::RunLoop run_loop2; | 2549 base::RunLoop run_loop2; |
2550 run_loop2.RunUntilIdle(); | 2550 run_loop2.RunUntilIdle(); |
2551 | 2551 |
2552 password_manager->RemoveObserver(&mock_login_model_observer); | 2552 password_manager->RemoveObserver(&mock_login_model_observer); |
2553 } | 2553 } |
2554 | 2554 |
| 2555 // Test whether the password form which is loaded as hidden is autofilled |
| 2556 // correctly. This happens very often in situations when in order to sign-in the |
| 2557 // user clicks a sign-in button and a hidden passsword form becomes visible. |
| 2558 // This test differs from AutofillSuggetionsForProblematicPasswordForm in that |
| 2559 // the form is hidden and in that test only some fields are hidden. |
| 2560 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
| 2561 AutofillSuggetionsHiddenPasswordForm) { |
| 2562 // At first let us save credentials to the PasswordManager. |
| 2563 scoped_refptr<password_manager::PasswordStore> password_store = |
| 2564 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 2565 ServiceAccessType::IMPLICIT_ACCESS); |
| 2566 autofill::PasswordForm login_form; |
| 2567 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
| 2568 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
| 2569 login_form.username_value = base::ASCIIToUTF16("myusername"); |
| 2570 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
| 2571 password_store->AddLogin(login_form); |
| 2572 |
| 2573 // Logins are added asynchronously to the password store. Spin the message |
| 2574 // loop to make sure the |password_store| had a chance to store the |
| 2575 // |login_form|. |
| 2576 base::RunLoop run_loop; |
| 2577 run_loop.RunUntilIdle(); |
| 2578 |
| 2579 // Now, navigate to the hidden password form and verify whether username and |
| 2580 // password is autofilled. |
| 2581 NavigateToFile("/password/password_form.html"); |
| 2582 |
| 2583 // Let the user interact with the page, so that DOM gets modification events, |
| 2584 // needed for autofilling fields. |
| 2585 content::SimulateMouseClickAt( |
| 2586 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
| 2587 |
| 2588 std::string get_username = |
| 2589 "window.domAutomationController.send(" |
| 2590 " document.getElementById('hidden_password_form_username').value);"; |
| 2591 std::string actual_username; |
| 2592 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2593 RenderViewHost(), get_username, &actual_username)); |
| 2594 EXPECT_EQ("myusername", actual_username); |
| 2595 |
| 2596 std::string get_password = |
| 2597 "window.domAutomationController.send(" |
| 2598 " document.getElementById('hidden_password_form_password').value);"; |
| 2599 std::string actual_password; |
| 2600 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 2601 RenderViewHost(), get_password, &actual_password)); |
| 2602 EXPECT_EQ("mypassword", actual_password); |
| 2603 } |
| 2604 |
2555 // Test whether the password form with the problematic invisible password field | 2605 // Test whether the password form with the problematic invisible password field |
2556 // gets autofilled correctly. | 2606 // gets autofilled correctly. |
2557 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 2607 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
2558 AutofillSuggetionsForProblematicPasswordForm) { | 2608 AutofillSuggetionsForProblematicPasswordForm) { |
2559 // At first let us save credentials to the PasswordManager. | 2609 // At first let us save credentials to the PasswordManager. |
2560 scoped_refptr<password_manager::PasswordStore> password_store = | 2610 scoped_refptr<password_manager::PasswordStore> password_store = |
2561 PasswordStoreFactory::GetForProfile(browser()->profile(), | 2611 PasswordStoreFactory::GetForProfile(browser()->profile(), |
2562 ServiceAccessType::IMPLICIT_ACCESS); | 2612 ServiceAccessType::IMPLICIT_ACCESS); |
2563 autofill::PasswordForm login_form; | 2613 autofill::PasswordForm login_form; |
2564 login_form.signon_realm = embedded_test_server()->base_url().spec(); | 2614 login_form.signon_realm = embedded_test_server()->base_url().spec(); |
2565 login_form.action = embedded_test_server()->GetURL("/password/done.html"); | 2615 login_form.action = embedded_test_server()->GetURL("/password/done.html"); |
2566 login_form.username_value = base::ASCIIToUTF16("myusername"); | 2616 login_form.username_value = base::ASCIIToUTF16("myusername"); |
2567 login_form.password_value = base::ASCIIToUTF16("mypassword"); | 2617 login_form.password_value = base::ASCIIToUTF16("mypassword"); |
2568 password_store->AddLogin(login_form); | 2618 password_store->AddLogin(login_form); |
2569 | 2619 |
2570 // Logins are added asynchronously to the password store. Spin the message | 2620 // Logins are added asynchronously to the password store. Spin the message |
2571 // loop to make sure the |password_store| had a chance to store the | 2621 // loop to make sure the |password_store| had a chance to store the |
2572 // |login_form|. | 2622 // |login_form|. |
2573 base::RunLoop run_loop; | 2623 base::RunLoop run_loop; |
2574 run_loop.RunUntilIdle(); | 2624 run_loop.RunUntilIdle(); |
2575 | 2625 |
2576 // Now, navigate to the password form having ambiguous Ids for username and | 2626 // Now, navigate to the password form with a hidden password field and verify |
2577 // password fields and verify whether username and password is autofilled. | 2627 // whether username and password is autofilled. |
2578 NavigateToFile("/password/password_form.html"); | 2628 NavigateToFile("/password/password_form.html"); |
2579 | 2629 |
2580 // Let the user interact with the page, so that DOM gets modification events, | 2630 // Let the user interact with the page, so that DOM gets modification events, |
2581 // needed for autofilling fields. | 2631 // needed for autofilling fields. |
2582 content::SimulateMouseClickAt( | 2632 content::SimulateMouseClickAt( |
2583 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); | 2633 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); |
2584 | 2634 |
2585 std::string get_username = | 2635 std::string get_username = |
2586 "window.domAutomationController.send(" | 2636 "window.domAutomationController.send(" |
2587 " document.getElementById('username').value);"; | 2637 " document.getElementById('form_with_hidden_password_username').value);"; |
2588 std::string actual_username; | 2638 std::string actual_username; |
2589 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 2639 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
2590 RenderViewHost(), get_username, &actual_username)); | 2640 RenderViewHost(), get_username, &actual_username)); |
2591 EXPECT_EQ("myusername", actual_username); | 2641 EXPECT_EQ("myusername", actual_username); |
2592 | 2642 |
2593 std::string get_password = | 2643 std::string get_password = |
2594 "window.domAutomationController.send(" | 2644 "window.domAutomationController.send(" |
2595 " document.getElementById('password').value);"; | 2645 " document.getElementById('form_with_hidden_password_password').value);"; |
2596 std::string actual_password; | 2646 std::string actual_password; |
2597 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 2647 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
2598 RenderViewHost(), get_password, &actual_password)); | 2648 RenderViewHost(), get_password, &actual_password)); |
2599 EXPECT_EQ("mypassword", actual_password); | 2649 EXPECT_EQ("mypassword", actual_password); |
2600 } | 2650 } |
2601 | 2651 |
2602 // Test whether the password form with the problematic invisible password field | 2652 // Test whether the password form with the problematic invisible password field |
2603 // in ambiguous password form gets autofilled correctly. | 2653 // in ambiguous password form gets autofilled correctly. |
2604 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | 2654 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, |
2605 AutofillSuggetionsForProblematicAmbiguousPasswordForm) { | 2655 AutofillSuggetionsForProblematicAmbiguousPasswordForm) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2640 std::string get_password = | 2690 std::string get_password = |
2641 "window.domAutomationController.send(" | 2691 "window.domAutomationController.send(" |
2642 " document.getElementById('hidden_password_form').elements[2].value);"; | 2692 " document.getElementById('hidden_password_form').elements[2].value);"; |
2643 std::string actual_password; | 2693 std::string actual_password; |
2644 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 2694 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
2645 RenderViewHost(), get_password, &actual_password)); | 2695 RenderViewHost(), get_password, &actual_password)); |
2646 EXPECT_EQ("mypassword", actual_password); | 2696 EXPECT_EQ("mypassword", actual_password); |
2647 } | 2697 } |
2648 | 2698 |
2649 } // namespace password_manager | 2699 } // namespace password_manager |
OLD | NEW |