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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override { | 120 base::WeakPtr<autofill::AutofillPopupDelegate> delegate) override { |
121 message_loop_runner_->Quit(); | 121 message_loop_runner_->Quit(); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 125 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
126 | 126 |
127 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); | 127 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); |
128 }; | 128 }; |
129 | 129 |
130 // TODO(dvadym): This is for avoiding unused function compilation error. Remove | |
131 // it when http://crbug.com/359315 is implemented for Mac. | |
132 #if !defined(OS_MACOSX) | |
133 // For simplicity we assume that password store contains only 1 credentials. | |
134 void CheckThatCredentialsStored( | 130 void CheckThatCredentialsStored( |
135 password_manager::TestPasswordStore* password_store, | 131 password_manager::TestPasswordStore* password_store, |
136 const base::string16& username, | 132 const base::string16& username, |
137 const base::string16& password) { | 133 const base::string16& password) { |
138 auto& passwords_map = password_store->stored_passwords(); | 134 auto& passwords_map = password_store->stored_passwords(); |
139 ASSERT_EQ(1u, passwords_map.size()); | 135 ASSERT_EQ(1u, passwords_map.size()); |
140 auto& passwords_vector = passwords_map.begin()->second; | 136 auto& passwords_vector = passwords_map.begin()->second; |
141 ASSERT_EQ(1u, passwords_vector.size()); | 137 ASSERT_EQ(1u, passwords_vector.size()); |
142 const autofill::PasswordForm& form = passwords_vector[0]; | 138 const autofill::PasswordForm& form = passwords_vector[0]; |
143 EXPECT_EQ(username, form.username_value); | 139 EXPECT_EQ(username, form.username_value); |
144 EXPECT_EQ(password, form.password_value); | 140 EXPECT_EQ(password, form.password_value); |
145 } | 141 } |
146 #endif | |
147 | 142 |
148 void TestPromptNotShown(const char* failure_message, | 143 void TestPromptNotShown(const char* failure_message, |
149 content::WebContents* web_contents, | 144 content::WebContents* web_contents, |
150 content::RenderViewHost* rvh) { | 145 content::RenderViewHost* rvh) { |
151 SCOPED_TRACE(testing::Message(failure_message)); | 146 SCOPED_TRACE(testing::Message(failure_message)); |
152 | 147 |
153 NavigationObserver observer(web_contents); | 148 NavigationObserver observer(web_contents); |
154 scoped_ptr<PromptObserver> prompt_observer( | 149 scoped_ptr<PromptObserver> prompt_observer( |
155 PromptObserver::Create(web_contents)); | 150 PromptObserver::Create(web_contents)); |
156 std::string fill_and_submit = | 151 std::string fill_and_submit = |
(...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2756 "var text = document.getElementById('log-entries').innerText;" | 2751 "var text = document.getElementById('log-entries').innerText;" |
2757 "var logs_found = /PasswordManager::/.test(text);" | 2752 "var logs_found = /PasswordManager::/.test(text);" |
2758 "window.domAutomationController.send(logs_found);"; | 2753 "window.domAutomationController.send(logs_found);"; |
2759 bool browser_logs_found; | 2754 bool browser_logs_found; |
2760 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 2755 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
2761 internals_web_contents->GetRenderViewHost(), find_browser_logs, | 2756 internals_web_contents->GetRenderViewHost(), find_browser_logs, |
2762 &browser_logs_found)); | 2757 &browser_logs_found)); |
2763 EXPECT_TRUE(browser_logs_found); | 2758 EXPECT_TRUE(browser_logs_found); |
2764 } | 2759 } |
2765 | 2760 |
2761 // Tests that submitted credentials are saved on a password form without | |
2762 // username element when there are no stored credentials. | |
2763 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
2764 PasswordRetryFormSaveNoUsernameCredentials) { | |
2765 scoped_refptr<password_manager::TestPasswordStore> password_store = | |
2766 static_cast<password_manager::TestPasswordStore*>( | |
2767 PasswordStoreFactory::GetForProfile( | |
2768 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
2769 .get()); | |
2770 // Check that password save bubble is shown. | |
2771 NavigateToFile("/password/password_form.html"); | |
2772 NavigationObserver observer(WebContents()); | |
2773 scoped_ptr<PromptObserver> prompt_observer( | |
2774 PromptObserver::Create(WebContents())); | |
2775 std::string fill_and_submit = | |
2776 "document.getElementById('retry_password_field').value = 'pw';" | |
2777 "document.getElementById('retry_submit_button').click()"; | |
2778 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
2779 observer.Wait(); | |
2780 EXPECT_TRUE(prompt_observer->IsShowingPrompt()); | |
2781 prompt_observer->Accept(); | |
2782 // Spin the message loop to make sure the password store had a chance to | |
2783 // update the password. | |
2784 base::RunLoop run_loop; | |
2785 run_loop.RunUntilIdle(); | |
2786 CheckThatCredentialsStored(password_store.get(), base::string16(), | |
2787 base::ASCIIToUTF16("pw")); | |
2788 } | |
2789 | |
2790 // Tests that no bubble shown when a password form without username submitted | |
2791 // and there is stored credentials with the same password. | |
2792 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
2793 PasswordRetryFormNoBubbleWhenPasswordTheSame) { | |
2794 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()); | |
2795 // At first let us save credentials to the PasswordManager. | |
2796 scoped_refptr<password_manager::TestPasswordStore> password_store = | |
2797 static_cast<password_manager::TestPasswordStore*>( | |
2798 PasswordStoreFactory::GetForProfile( | |
2799 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
2800 .get()); | |
2801 autofill::PasswordForm signin_form; | |
2802 signin_form.signon_realm = embedded_test_server()->base_url().spec(); | |
2803 signin_form.username_value = base::ASCIIToUTF16("temp"); | |
2804 signin_form.password_value = base::ASCIIToUTF16("pw"); | |
2805 password_store->AddLogin(signin_form); | |
2806 signin_form.username_value = base::ASCIIToUTF16("temp1"); | |
2807 signin_form.password_value = base::ASCIIToUTF16("pw1"); | |
2808 password_store->AddLogin(signin_form); | |
2809 | |
2810 // Check that no password bubble is shown when the submitted password is the | |
2811 // same in one of the stored credentials. | |
2812 NavigateToFile("/password/password_form.html"); | |
2813 NavigationObserver observer(WebContents()); | |
2814 scoped_ptr<PromptObserver> prompt_observer( | |
2815 PromptObserver::Create(WebContents())); | |
2816 std::string fill_and_submit = | |
2817 "document.getElementById('retry_password_field').value = 'pw';" | |
2818 "document.getElementById('retry_submit_button').click()"; | |
2819 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
2820 observer.Wait(); | |
2821 EXPECT_FALSE(prompt_observer->IsShowingPrompt()); | |
2822 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); | |
2823 } | |
2824 | |
2825 // TODO(dvadym): Turn on this test when Change password UI will be implemented | |
2826 // for Mac. http://crbug.com/359315 | |
2827 #if !defined(OS_MACOSX) | |
2828 // Tests that the update bubble shown when a password form without username | |
2829 // submitted and there are stored credentials but with different password. | |
vabr (Chromium)
2015/11/26 14:35:54
typo: submitted -> is submitted
dvadym
2015/11/26 15:19:55
Done.
| |
2830 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, | |
2831 PasswordRetryFormUpdateBubbleShown) { | |
2832 ASSERT_TRUE(ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()); | |
2833 // At first let us save credentials to the PasswordManager. | |
2834 scoped_refptr<password_manager::TestPasswordStore> password_store = | |
2835 static_cast<password_manager::TestPasswordStore*>( | |
2836 PasswordStoreFactory::GetForProfile( | |
2837 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
2838 .get()); | |
2839 autofill::PasswordForm signin_form; | |
2840 signin_form.signon_realm = embedded_test_server()->base_url().spec(); | |
2841 signin_form.username_value = base::ASCIIToUTF16("temp"); | |
2842 signin_form.password_value = base::ASCIIToUTF16("pw"); | |
2843 password_store->AddLogin(signin_form); | |
2844 | |
2845 // Check that password update bubble is shown. | |
2846 NavigateToFile("/password/password_form.html"); | |
2847 NavigationObserver observer(WebContents()); | |
2848 scoped_ptr<PromptObserver> prompt_observer( | |
2849 PromptObserver::Create(WebContents())); | |
2850 std::string fill_and_submit = | |
2851 "document.getElementById('retry_password_field').value = 'new_pw';" | |
2852 "document.getElementById('retry_submit_button').click()"; | |
2853 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); | |
2854 observer.Wait(); | |
2855 // The new password "new_pw" is used, so update prompt is expected. | |
2856 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); | |
2857 | |
2858 const autofill::PasswordForm stored_form = | |
2859 password_store->stored_passwords().begin()->second[0]; | |
2860 prompt_observer->AcceptUpdatePrompt(stored_form); | |
2861 // Spin the message loop to make sure the password store had a chance to | |
2862 // update the password. | |
2863 base::RunLoop run_loop; | |
2864 run_loop.RunUntilIdle(); | |
2865 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), | |
2866 base::ASCIIToUTF16("new_pw")); | |
2867 } | |
2868 #endif | |
2869 | |
2766 } // namespace password_manager | 2870 } // namespace password_manager |
OLD | NEW |