| 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/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/password_manager/password_manager_test_base.h" | 8 #include "chrome/browser/password_manager/password_manager_test_base.h" |
| 9 #include "chrome/browser/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_io_data.h" | 11 #include "chrome/browser/profiles/profile_io_data.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" | 13 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 15 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 16 #include "components/password_manager/core/browser/password_store_consumer.h" | |
| 17 #include "components/password_manager/core/browser/test_password_store.h" | 16 #include "components/password_manager/core/browser/test_password_store.h" |
| 18 #include "content/public/test/browser_test.h" | 17 #include "content/public/test/browser_test.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
| 20 #include "net/cert/cert_verify_result.h" | 19 #include "net/cert/cert_verify_result.h" |
| 21 #include "net/cert/mock_cert_verifier.h" | 20 #include "net/cert/mock_cert_verifier.h" |
| 22 #include "net/dns/mock_host_resolver.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| 26 // A helper class that synchronously waits until the password store handles a | |
| 27 // GetLogins() request. | |
| 28 class PasswordStoreResultsObserver | |
| 29 : public password_manager::PasswordStoreConsumer { | |
| 30 public: | |
| 31 PasswordStoreResultsObserver() = default; | |
| 32 | |
| 33 void OnGetPasswordStoreResults( | |
| 34 std::vector<std::unique_ptr<autofill::PasswordForm>> results) override { | |
| 35 run_loop_.Quit(); | |
| 36 } | |
| 37 | |
| 38 void Wait() { | |
| 39 run_loop_.Run(); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 base::RunLoop run_loop_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); | |
| 46 }; | |
| 47 | |
| 48 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { | 25 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { |
| 49 public: | 26 public: |
| 50 CredentialManagerBrowserTest() = default; | 27 CredentialManagerBrowserTest() = default; |
| 51 | 28 |
| 52 bool IsShowingAccountChooser() { | 29 bool IsShowingAccountChooser() { |
| 53 return PasswordsModelDelegateFromWebContents(WebContents())-> | 30 return PasswordsModelDelegateFromWebContents(WebContents())-> |
| 54 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; | 31 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; |
| 55 } | 32 } |
| 56 | 33 |
| 57 // Make sure that the password store processed all the previous calls which | |
| 58 // are executed on another thread. | |
| 59 void WaitForPasswordStore() { | |
| 60 scoped_refptr<password_manager::PasswordStore> password_store = | |
| 61 PasswordStoreFactory::GetForProfile( | |
| 62 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); | |
| 63 PasswordStoreResultsObserver syncer; | |
| 64 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); | |
| 65 syncer.Wait(); | |
| 66 } | |
| 67 | |
| 68 // Similarly to PasswordManagerBrowserTestBase::NavigateToFile this is a | 34 // Similarly to PasswordManagerBrowserTestBase::NavigateToFile this is a |
| 69 // wrapper around ui_test_utils::NavigateURL that waits until DidFinishLoad() | 35 // wrapper around ui_test_utils::NavigateURL that waits until DidFinishLoad() |
| 70 // fires. Different to NavigateToFile this method allows passing a test_server | 36 // fires. Different to NavigateToFile this method allows passing a test_server |
| 71 // and modifications to the hostname. | 37 // and modifications to the hostname. |
| 72 void NavigateToURL(const net::EmbeddedTestServer& test_server, | 38 void NavigateToURL(const net::EmbeddedTestServer& test_server, |
| 73 const std::string& hostname, | 39 const std::string& hostname, |
| 74 const std::string& relative_url) { | 40 const std::string& relative_url) { |
| 75 NavigationObserver observer(WebContents()); | 41 NavigationObserver observer(WebContents()); |
| 76 GURL url = test_server.GetURL(hostname, relative_url); | 42 GURL url = test_server.GetURL(hostname, relative_url); |
| 77 ui_test_utils::NavigateToURL(browser(), url); | 43 ui_test_utils::NavigateToURL(browser(), url); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 signin_form.skip_zero_click = false; | 319 signin_form.skip_zero_click = false; |
| 354 signin_form.times_used = 1; | 320 signin_form.times_used = 1; |
| 355 signin_form.password_value = base::ASCIIToUTF16("API"); | 321 signin_form.password_value = base::ASCIIToUTF16("API"); |
| 356 password_manager::TestPasswordStore::PasswordMap stored = | 322 password_manager::TestPasswordStore::PasswordMap stored = |
| 357 password_store->stored_passwords(); | 323 password_store->stored_passwords(); |
| 358 ASSERT_EQ(1u, stored.size()); | 324 ASSERT_EQ(1u, stored.size()); |
| 359 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 325 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
| 360 } | 326 } |
| 361 | 327 |
| 362 } // namespace | 328 } // namespace |
| OLD | NEW |