| 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/test_password_store.h" | 16 #include "components/password_manager/core/browser/test_password_store.h" |
| 17 #include "content/public/test/browser_test.h" | 17 #include "content/public/test/browser_test.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
| 19 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { | 23 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { |
| 24 public: | 24 public: |
| 25 CredentialManagerBrowserTest() = default; | 25 CredentialManagerBrowserTest() = default; |
| 26 | 26 |
| 27 void SetUpOnMainThread() override { |
| 28 PasswordManagerBrowserTestBase::SetUpOnMainThread(); |
| 29 // Redirect all requests to localhost. |
| 30 host_resolver()->AddRule("*", "127.0.0.1"); |
| 31 } |
| 32 |
| 27 bool IsShowingAccountChooser() { | 33 bool IsShowingAccountChooser() { |
| 28 return PasswordsModelDelegateFromWebContents(WebContents())-> | 34 return PasswordsModelDelegateFromWebContents(WebContents())-> |
| 29 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; | 35 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; |
| 30 } | 36 } |
| 31 | 37 |
| 32 // Similarly to PasswordManagerBrowserTestBase::NavigateToFile this is a | 38 // Similarly to PasswordManagerBrowserTestBase::NavigateToFile this is a |
| 33 // wrapper around ui_test_utils::NavigateURL that waits until DidFinishLoad() | 39 // wrapper around ui_test_utils::NavigateURL that waits until DidFinishLoad() |
| 34 // fires. Different to NavigateToFile this method allows passing a test_server | 40 // fires. Different to NavigateToFile this method allows passing a test_server |
| 35 // and modifications to the hostname. | 41 // and modifications to the hostname. |
| 36 void NavigateToURL(const net::EmbeddedTestServer& test_server, | 42 void NavigateToURL(const net::EmbeddedTestServer& test_server, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 passwords_map.begin()->second; | 100 passwords_map.begin()->second; |
| 95 ASSERT_EQ(1u, passwords_vector.size()); | 101 ASSERT_EQ(1u, passwords_vector.size()); |
| 96 const autofill::PasswordForm& form = passwords_vector[0]; | 102 const autofill::PasswordForm& form = passwords_vector[0]; |
| 97 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); | 103 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); |
| 98 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); | 104 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); |
| 99 EXPECT_FALSE(form.skip_zero_click); | 105 EXPECT_FALSE(form.skip_zero_click); |
| 100 } | 106 } |
| 101 | 107 |
| 102 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, | 108 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, |
| 103 StoreSavesPSLMatchedCredential) { | 109 StoreSavesPSLMatchedCredential) { |
| 104 // Redirect all requests to localhost. | |
| 105 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 106 | |
| 107 scoped_refptr<password_manager::TestPasswordStore> password_store = | 110 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 108 static_cast<password_manager::TestPasswordStore*>( | 111 static_cast<password_manager::TestPasswordStore*>( |
| 109 PasswordStoreFactory::GetForProfile( | 112 PasswordStoreFactory::GetForProfile( |
| 110 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | 113 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) |
| 111 .get()); | 114 .get()); |
| 112 | 115 |
| 113 // The call to |GetURL| is needed to get the correct port. | 116 // The call to |GetURL| is needed to get the correct port. |
| 114 GURL psl_url = https_test_server().GetURL("psl.example.com", "/"); | 117 GURL psl_url = https_test_server().GetURL("psl.example.com", "/"); |
| 115 | 118 |
| 116 autofill::PasswordForm signin_form; | 119 autofill::PasswordForm signin_form; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 signin_form.skip_zero_click = false; | 330 signin_form.skip_zero_click = false; |
| 328 signin_form.times_used = 1; | 331 signin_form.times_used = 1; |
| 329 signin_form.password_value = base::ASCIIToUTF16("API"); | 332 signin_form.password_value = base::ASCIIToUTF16("API"); |
| 330 password_manager::TestPasswordStore::PasswordMap stored = | 333 password_manager::TestPasswordStore::PasswordMap stored = |
| 331 password_store->stored_passwords(); | 334 password_store->stored_passwords(); |
| 332 ASSERT_EQ(1u, stored.size()); | 335 ASSERT_EQ(1u, stored.size()); |
| 333 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 336 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
| 334 } | 337 } |
| 335 | 338 |
| 336 } // namespace | 339 } // namespace |
| OLD | NEW |