| 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" |
| 11 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" | 11 #include "chrome/browser/ui/passwords/passwords_model_delegate_proxy.h" |
| 12 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 12 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 13 #include "components/password_manager/core/browser/password_store_consumer.h" | 13 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 14 #include "components/password_manager/core/browser/test_password_store.h" | 14 #include "components/password_manager/core/browser/test_password_store.h" |
| 15 #include "content/public/test/browser_test.h" | 15 #include "content/public/test/browser_test.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // A helper class that synchronously waits until the password store handles a | 20 // A helper class that synchronously waits until the password store handles a |
| 21 // GetLogins() request. | 21 // GetLogins() request. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 base::RunLoop run_loop_; | 37 base::RunLoop run_loop_; |
| 38 | 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); | 39 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { | 42 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { |
| 43 public: | 43 public: |
| 44 CredentialManagerBrowserTest() = default; | 44 CredentialManagerBrowserTest() = default; |
| 45 | 45 |
| 46 bool IsShowingAccountChooser() { | 46 bool IsShowingAccountChooser() { |
| 47 return PasswordsModelDelegateFromWebContents(WebContents())->GetState() == | 47 return PasswordsModelDelegateProxyFromWebContents(WebContents())-> |
| 48 password_manager::ui::CREDENTIAL_REQUEST_STATE; | 48 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Make sure that the password store processed all the previous calls which | 51 // Make sure that the password store processed all the previous calls which |
| 52 // are executed on another thread. | 52 // are executed on another thread. |
| 53 void WaitForPasswordStore() { | 53 void WaitForPasswordStore() { |
| 54 scoped_refptr<password_manager::PasswordStore> password_store = | 54 scoped_refptr<password_manager::PasswordStore> password_store = |
| 55 PasswordStoreFactory::GetForProfile( | 55 PasswordStoreFactory::GetForProfile( |
| 56 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); | 56 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); |
| 57 PasswordStoreResultsObserver syncer; | 57 PasswordStoreResultsObserver syncer; |
| 58 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); | 58 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 "document.getElementById('username_field').value = 'user';" | 86 "document.getElementById('username_field').value = 'user';" |
| 87 "document.getElementById('password_field').value = 'password';"; | 87 "document.getElementById('password_field').value = 'password';"; |
| 88 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password)); | 88 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password)); |
| 89 | 89 |
| 90 // Call the API to trigger the notification to the client. | 90 // Call the API to trigger the notification to the client. |
| 91 ASSERT_TRUE(content::ExecuteScript( | 91 ASSERT_TRUE(content::ExecuteScript( |
| 92 RenderViewHost(), | 92 RenderViewHost(), |
| 93 "navigator.credentials.get({password: true})" | 93 "navigator.credentials.get({password: true})" |
| 94 ".then(cred => window.location = '/password/done.html')")); | 94 ".then(cred => window.location = '/password/done.html')")); |
| 95 WaitForPasswordStore(); | 95 WaitForPasswordStore(); |
| 96 ASSERT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, | 96 ASSERT_EQ( |
| 97 PasswordsModelDelegateFromWebContents(WebContents())->GetState()); | 97 password_manager::ui::CREDENTIAL_REQUEST_STATE, |
| 98 PasswordsModelDelegateFromWebContents(WebContents())->ChooseCredential( | 98 PasswordsModelDelegateProxyFromWebContents(WebContents())->GetState()); |
| 99 PasswordsModelDelegateProxyFromWebContents(WebContents())->ChooseCredential( |
| 99 signin_form, | 100 signin_form, |
| 100 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | 101 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 101 | 102 |
| 102 NavigationObserver observer(WebContents()); | 103 NavigationObserver observer(WebContents()); |
| 103 observer.SetPathToWaitFor("/password/done.html"); | 104 observer.SetPathToWaitFor("/password/done.html"); |
| 104 observer.Wait(); | 105 observer.Wait(); |
| 105 | 106 |
| 106 // Verify that the form's 'skip_zero_click' is updated and not overwritten | 107 // Verify that the form's 'skip_zero_click' is updated and not overwritten |
| 107 // by the autofill password manager on successful login. | 108 // by the autofill password manager on successful login. |
| 108 WaitForPasswordStore(); | 109 WaitForPasswordStore(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 signin_form.skip_zero_click = false; | 270 signin_form.skip_zero_click = false; |
| 270 signin_form.times_used = 1; | 271 signin_form.times_used = 1; |
| 271 signin_form.password_value = base::ASCIIToUTF16("API"); | 272 signin_form.password_value = base::ASCIIToUTF16("API"); |
| 272 password_manager::TestPasswordStore::PasswordMap stored = | 273 password_manager::TestPasswordStore::PasswordMap stored = |
| 273 password_store->stored_passwords(); | 274 password_store->stored_passwords(); |
| 274 ASSERT_EQ(1u, stored.size()); | 275 ASSERT_EQ(1u, stored.size()); |
| 275 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 276 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
| 276 } | 277 } |
| 277 | 278 |
| 278 } // namespace | 279 } // namespace |
| OLD | NEW |