| 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 NoPromptForXHXSubmitWithoutNavigationWithUnfilledForm) { |
| 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 NOT been |
| 784 // filled out we don't prompt. |
| 785 scoped_ptr<PromptObserver> prompt_observer( |
| 786 PromptObserver::Create(WebContents())); |
| 787 std::string fill_and_submit = |
| 788 "navigate = false;" |
| 789 "document.getElementById('username_field').value = 'temp';" |
| 790 "document.getElementById('submit_button').click();"; |
| 791 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 792 std::string message; |
| 793 while (message_queue.WaitForMessage(&message)) { |
| 794 if (message == "\"XHR_FINISHED\"") |
| 795 break; |
| 796 } |
| 797 |
| 798 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); |
| 799 } |
| 800 |
| 745 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) { | 801 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) { |
| 746 NavigateToFile("/password/password_form.html"); | 802 NavigateToFile("/password/password_form.html"); |
| 747 | 803 |
| 748 // Verify that if the user takes a direct action to leave the page, we don't | 804 // 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. | 805 // prompt to save the password even if the form is already filled out. |
| 750 NavigationObserver observer(WebContents()); | 806 NavigationObserver observer(WebContents()); |
| 751 scoped_ptr<PromptObserver> prompt_observer( | 807 scoped_ptr<PromptObserver> prompt_observer( |
| 752 PromptObserver::Create(WebContents())); | 808 PromptObserver::Create(WebContents())); |
| 753 std::string fill_and_click_link = | 809 std::string fill_and_click_link = |
| 754 "document.getElementById('username_field').value = 'temp';" | 810 "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';" | 1709 "document.getElementById('username_field').value = 'username';" |
| 1654 "document.getElementById('password_field').value = 'mypass';" | 1710 "document.getElementById('password_field').value = 'mypass';" |
| 1655 "document.getElementById('confirm_field').value = 'mypass';" | 1711 "document.getElementById('confirm_field').value = 'mypass';" |
| 1656 "document.getElementById('security_answer').value = 'hometown';" | 1712 "document.getElementById('security_answer').value = 'hometown';" |
| 1657 "document.getElementById('SSN').value = '1234';" | 1713 "document.getElementById('SSN').value = '1234';" |
| 1658 "document.getElementById('testform').submit();"; | 1714 "document.getElementById('testform').submit();"; |
| 1659 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | 1715 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); |
| 1660 observer.Wait(); | 1716 observer.Wait(); |
| 1661 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); | 1717 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); |
| 1662 } | 1718 } |
| OLD | NEW |