| 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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 std::string fill_and_navigate = | 735 std::string fill_and_navigate = |
| 736 "document.getElementById('signup_username_field').value = 'temp';" | 736 "document.getElementById('signup_username_field').value = 'temp';" |
| 737 "document.getElementById('signup_password_field').value = 'random';" | 737 "document.getElementById('signup_password_field').value = 'random';" |
| 738 "document.getElementById('confirmation_password_field').value = 'random';" | 738 "document.getElementById('confirmation_password_field').value = 'random';" |
| 739 "send_xhr()"; | 739 "send_xhr()"; |
| 740 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); | 740 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); |
| 741 observer.Wait(); | 741 observer.Wait(); |
| 742 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); | 742 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 743 } | 743 } |
| 744 | 744 |
| 745 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 746 PromptForXHRSubmitWithoutNavigation) { |
| 747 NavigateToFile("/password/password_xhr_submit.html"); |
| 748 |
| 749 // Need to pay attention for a message that XHR has finished since there |
| 750 // is no navigation to wait for. |
| 751 content::DOMMessageQueue message_queue; |
| 752 |
| 753 // Verify that if XHR without navigation occurs and the form has been filled |
| 754 // out we try and save the password. Note that in general the submission |
| 755 // doesn't need to be via form.submit(), but for testing purposes it's |
| 756 // necessary since we otherwise ignore changes made to the value of these |
| 757 // fields by script. |
| 758 scoped_ptr<PromptObserver> prompt_observer( |
| 759 PromptObserver::Create(WebContents())); |
| 760 std::string fill_and_submit = |
| 761 "navigate = false;" |
| 762 "document.getElementById('username_field').value = 'temp';" |
| 763 "document.getElementById('password_field').value = 'random';" |
| 764 "document.getElementById('submit_button').click();"; |
| 765 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 766 std::string message; |
| 767 while (message_queue.WaitForMessage(&message)) { |
| 768 if (message == "\"XHR_FINISHED\"") |
| 769 break; |
| 770 } |
| 771 |
| 772 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 773 } |
| 774 |
| 775 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 776 PromptForXHRSubmitWithoutNavigation_SignupForm) { |
| 777 NavigateToFile("/password/password_xhr_submit.html"); |
| 778 |
| 779 // Need to pay attention for a message that XHR has finished since there |
| 780 // is no navigation to wait for. |
| 781 content::DOMMessageQueue message_queue; |
| 782 |
| 783 // Verify that if XHR without navigation occurs and the form has been filled |
| 784 // out we try and save the password. Note that in general the submission |
| 785 // doesn't need to be via form.submit(), but for testing purposes it's |
| 786 // necessary since we otherwise ignore changes made to the value of these |
| 787 // fields by script. |
| 788 scoped_ptr<PromptObserver> prompt_observer( |
| 789 PromptObserver::Create(WebContents())); |
| 790 std::string fill_and_submit = |
| 791 "navigate = false;" |
| 792 "document.getElementById('signup_username_field').value = 'temp';" |
| 793 "document.getElementById('signup_password_field').value = 'random';" |
| 794 "document.getElementById('confirmation_password_field').value = 'random';" |
| 795 "document.getElementById('signup_submit_button').click();"; |
| 796 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 797 std::string message; |
| 798 while (message_queue.WaitForMessage(&message)) { |
| 799 if (message == "\"XHR_FINISHED\"") |
| 800 break; |
| 801 } |
| 802 |
| 803 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 804 } |
| 805 |
| 806 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, |
| 807 NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm) { |
| 808 NavigateToFile("/password/password_xhr_submit.html"); |
| 809 |
| 810 // Need to pay attention for a message that XHR has finished since there |
| 811 // is no navigation to wait for. |
| 812 content::DOMMessageQueue message_queue; |
| 813 |
| 814 // Verify that if XHR without navigation occurs and the form has NOT been |
| 815 // filled out we don't prompt. |
| 816 scoped_ptr<PromptObserver> prompt_observer( |
| 817 PromptObserver::Create(WebContents())); |
| 818 std::string fill_and_submit = |
| 819 "navigate = false;" |
| 820 "document.getElementById('username_field').value = 'temp';" |
| 821 "document.getElementById('submit_button').click();"; |
| 822 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 823 std::string message; |
| 824 while (message_queue.WaitForMessage(&message)) { |
| 825 if (message == "\"XHR_FINISHED\"") |
| 826 break; |
| 827 } |
| 828 |
| 829 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); |
| 830 } |
| 831 |
| 832 IN_PROC_BROWSER_TEST_F( |
| 833 PasswordManagerBrowserTest, |
| 834 NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm_SignupForm) { |
| 835 NavigateToFile("/password/password_xhr_submit.html"); |
| 836 |
| 837 // Need to pay attention for a message that XHR has finished since there |
| 838 // is no navigation to wait for. |
| 839 content::DOMMessageQueue message_queue; |
| 840 |
| 841 // Verify that if XHR without navigation occurs and the form has NOT been |
| 842 // filled out we don't prompt. |
| 843 scoped_ptr<PromptObserver> prompt_observer( |
| 844 PromptObserver::Create(WebContents())); |
| 845 std::string fill_and_submit = |
| 846 "navigate = false;" |
| 847 "document.getElementById('signup_username_field').value = 'temp';" |
| 848 "document.getElementById('signup_submit_button').click();"; |
| 849 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 850 std::string message; |
| 851 while (message_queue.WaitForMessage(&message)) { |
| 852 if (message == "\"XHR_FINISHED\"") |
| 853 break; |
| 854 } |
| 855 |
| 856 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); |
| 857 } |
| 858 |
| 745 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) { | 859 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) { |
| 746 NavigateToFile("/password/password_form.html"); | 860 NavigateToFile("/password/password_form.html"); |
| 747 | 861 |
| 748 // Verify that if the user takes a direct action to leave the page, we don't | 862 // Verify that if the user takes a direct action to leave the page, we don't |
| 749 // prompt to save the password even if the form is already filled out. | 863 // prompt to save the password even if the form is already filled out. |
| 750 NavigationObserver observer(WebContents()); | 864 NavigationObserver observer(WebContents()); |
| 751 scoped_ptr<PromptObserver> prompt_observer( | 865 scoped_ptr<PromptObserver> prompt_observer( |
| 752 PromptObserver::Create(WebContents())); | 866 PromptObserver::Create(WebContents())); |
| 753 std::string fill_and_click_link = | 867 std::string fill_and_click_link = |
| 754 "document.getElementById('username_field').value = 'temp';" | 868 "document.getElementById('username_field').value = 'temp';" |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1653 "document.getElementById('username_field').value = 'username';" | 1767 "document.getElementById('username_field').value = 'username';" |
| 1654 "document.getElementById('password_field').value = 'mypass';" | 1768 "document.getElementById('password_field').value = 'mypass';" |
| 1655 "document.getElementById('confirm_field').value = 'mypass';" | 1769 "document.getElementById('confirm_field').value = 'mypass';" |
| 1656 "document.getElementById('security_answer').value = 'hometown';" | 1770 "document.getElementById('security_answer').value = 'hometown';" |
| 1657 "document.getElementById('SSN').value = '1234';" | 1771 "document.getElementById('SSN').value = '1234';" |
| 1658 "document.getElementById('testform').submit();"; | 1772 "document.getElementById('testform').submit();"; |
| 1659 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1773 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1660 observer.Wait(); | 1774 observer.Wait(); |
| 1661 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); | 1775 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 1662 } | 1776 } |
| OLD | NEW |