OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/password_manager/password_manager_test_base.h" | 7 #include "chrome/browser/password_manager/password_manager_test_base.h" |
8 #include "chrome/browser/password_manager/password_store_factory.h" | 8 #include "chrome/browser/password_manager/password_store_factory.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 NavigationObserver observer(WebContents()); | 159 NavigationObserver observer(WebContents()); |
160 observer.SetPathToWaitFor("/password/done.html"); | 160 observer.SetPathToWaitFor("/password/done.html"); |
161 observer.Wait(); | 161 observer.Wait(); |
162 | 162 |
163 std::unique_ptr<BubbleObserver> prompt_observer( | 163 std::unique_ptr<BubbleObserver> prompt_observer( |
164 new BubbleObserver(WebContents())); | 164 new BubbleObserver(WebContents())); |
165 // The autofill password manager shouldn't react to the successful login. | 165 // The autofill password manager shouldn't react to the successful login. |
166 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 166 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); |
167 } | 167 } |
168 | 168 |
169 // Disabled due to flakes; see https://crbug.com/629459. | 169 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, SaveViaAPIAndAutofill) { |
170 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, | |
171 DISABLED_SaveViaAPIAndAutofill) { | |
172 NavigateToFile("/password/password_form.html"); | 170 NavigateToFile("/password/password_form.html"); |
173 std::string fill_password = | |
174 "document.getElementById('username_field').value = 'user';" | |
175 "document.getElementById('password_field').value = '12345';"; | |
176 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password)); | |
177 | 171 |
178 // Call the API to save the form. | 172 // Postpone a submit event for 1 second. Even for the static html page Chrome |
| 173 // continues to parse and recreate the PasswordFormManager instances after the |
| 174 // page load. Calling the API before this would make the test flaky. Clicking |
| 175 // on the button emulates server analysing the credential and then saving and |
| 176 // navigating to the landing page. |
179 ASSERT_TRUE(content::ExecuteScript( | 177 ASSERT_TRUE(content::ExecuteScript( |
180 RenderViewHost(), | 178 RenderViewHost(), |
181 "var c = new PasswordCredential({ id: 'user', password: '12345' });" | 179 "document.getElementById('input_submit_button').addEventListener('click'," |
182 "navigator.credentials.store(c);")); | 180 "function(event) {" |
183 // Wait for the password store before checking the prompt because it pops up | 181 "setTimeout( function() {" |
184 // after the store replies. | 182 "var c = new PasswordCredential({ id: 'user', password: 'API' });" |
| 183 "navigator.credentials.store(c);" |
| 184 "document.getElementById('testform').submit();" |
| 185 "}, 1000 );" |
| 186 "event.preventDefault();" |
| 187 "});")); |
| 188 // Fill the password and click the button to submit the page later. The API |
| 189 // should suppress the autofill password manager. |
| 190 NavigationObserver form_submit_observer(WebContents()); |
| 191 ASSERT_TRUE(content::ExecuteScript( |
| 192 RenderViewHost(), |
| 193 "document.getElementById('username_field').value = 'user';" |
| 194 "document.getElementById('password_field').value = 'autofill';" |
| 195 "document.getElementById('input_submit_button').click();")); |
| 196 form_submit_observer.Wait(); |
| 197 |
185 WaitForPasswordStore(); | 198 WaitForPasswordStore(); |
186 std::unique_ptr<BubbleObserver> prompt_observer( | 199 std::unique_ptr<BubbleObserver> prompt_observer( |
187 new BubbleObserver(WebContents())); | 200 new BubbleObserver(WebContents())); |
188 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); | 201 ASSERT_TRUE(prompt_observer->IsShowingSavePrompt()); |
189 prompt_observer->Dismiss(); | 202 prompt_observer->AcceptSavePrompt(); |
190 | 203 |
191 NavigationObserver form_submit_observer(WebContents()); | 204 WaitForPasswordStore(); |
192 ASSERT_TRUE(content::ExecuteScript( | 205 password_manager::TestPasswordStore::PasswordMap stored = |
193 RenderViewHost(), | 206 static_cast<password_manager::TestPasswordStore*>( |
194 "document.getElementById('input_submit_button').click();")); | 207 PasswordStoreFactory::GetForProfile( |
195 form_submit_observer.Wait(); | 208 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) |
196 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | 209 .get())->stored_passwords(); |
| 210 ASSERT_EQ(1u, stored.size()); |
| 211 autofill::PasswordForm signin_form = stored.begin()->second[0]; |
| 212 EXPECT_EQ(base::ASCIIToUTF16("user"), signin_form.username_value); |
| 213 EXPECT_EQ(base::ASCIIToUTF16("API"), signin_form.password_value); |
| 214 EXPECT_EQ(embedded_test_server()->base_url().spec(), |
| 215 signin_form.signon_realm); |
| 216 EXPECT_EQ(embedded_test_server()->base_url(), signin_form.origin); |
197 } | 217 } |
198 | 218 |
199 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, UpdateViaAPIAndAutofill) { | 219 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, UpdateViaAPIAndAutofill) { |
200 // Save credentials with 'skip_zero_click' false. | 220 // Save credentials with 'skip_zero_click' false. |
201 scoped_refptr<password_manager::TestPasswordStore> password_store = | 221 scoped_refptr<password_manager::TestPasswordStore> password_store = |
202 static_cast<password_manager::TestPasswordStore*>( | 222 static_cast<password_manager::TestPasswordStore*>( |
203 PasswordStoreFactory::GetForProfile( | 223 PasswordStoreFactory::GetForProfile( |
204 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | 224 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) |
205 .get()); | 225 .get()); |
206 autofill::PasswordForm signin_form; | 226 autofill::PasswordForm signin_form; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 signin_form.skip_zero_click = false; | 271 signin_form.skip_zero_click = false; |
252 signin_form.times_used = 1; | 272 signin_form.times_used = 1; |
253 signin_form.password_value = base::ASCIIToUTF16("API"); | 273 signin_form.password_value = base::ASCIIToUTF16("API"); |
254 password_manager::TestPasswordStore::PasswordMap stored = | 274 password_manager::TestPasswordStore::PasswordMap stored = |
255 password_store->stored_passwords(); | 275 password_store->stored_passwords(); |
256 ASSERT_EQ(1u, stored.size()); | 276 ASSERT_EQ(1u, stored.size()); |
257 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 277 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
258 } | 278 } |
259 | 279 |
260 } // namespace | 280 } // namespace |
OLD | NEW |