Chromium Code Reviews| 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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/password_manager/password_manager_test_base.h" | 8 #include "chrome/browser/password_manager/password_manager_test_base.h" |
| 8 #include "chrome/browser/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/profiles/profile_io_data.h" | |
| 10 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 11 #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" | |
| 12 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 15 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 13 #include "components/password_manager/core/browser/password_store_consumer.h" | 16 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 14 #include "components/password_manager/core/browser/test_password_store.h" | 17 #include "components/password_manager/core/browser/test_password_store.h" |
| 15 #include "content/public/test/browser_test.h" | 18 #include "content/public/test/browser_test.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 20 #include "net/cert/cert_verify_result.h" | |
| 21 #include "net/cert/mock_cert_verifier.h" | |
| 22 #include "net/dns/mock_host_resolver.h" | |
| 17 | 23 |
| 18 namespace { | 24 namespace { |
| 19 | 25 |
| 20 // A helper class that synchronously waits until the password store handles a | 26 // A helper class that synchronously waits until the password store handles a |
| 21 // GetLogins() request. | 27 // GetLogins() request. |
| 22 class PasswordStoreResultsObserver | 28 class PasswordStoreResultsObserver |
| 23 : public password_manager::PasswordStoreConsumer { | 29 : public password_manager::PasswordStoreConsumer { |
| 24 public: | 30 public: |
| 25 PasswordStoreResultsObserver() = default; | 31 PasswordStoreResultsObserver() = default; |
| 26 | 32 |
| 27 void OnGetPasswordStoreResults( | 33 void OnGetPasswordStoreResults( |
| 28 std::vector<std::unique_ptr<autofill::PasswordForm>> results) override { | 34 std::vector<std::unique_ptr<autofill::PasswordForm>> results) override { |
| 29 run_loop_.Quit(); | 35 run_loop_.Quit(); |
| 30 } | 36 } |
| 31 | 37 |
| 32 void Wait() { | 38 void Wait() { |
| 33 run_loop_.Run(); | 39 run_loop_.Run(); |
| 34 } | 40 } |
| 35 | 41 |
| 36 private: | 42 private: |
| 37 base::RunLoop run_loop_; | 43 base::RunLoop run_loop_; |
| 38 | 44 |
| 39 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); | 45 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver); |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { | 48 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase { |
| 43 public: | 49 public: |
| 44 CredentialManagerBrowserTest() = default; | 50 CredentialManagerBrowserTest() |
| 51 : mock_cert_verifier_(base::MakeUnique<net::MockCertVerifier>()) {} | |
| 45 | 52 |
| 46 bool IsShowingAccountChooser() { | 53 bool IsShowingAccountChooser() { |
| 47 return PasswordsModelDelegateFromWebContents(WebContents())-> | 54 return PasswordsModelDelegateFromWebContents(WebContents())-> |
| 48 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; | 55 GetState() == password_manager::ui::CREDENTIAL_REQUEST_STATE; |
| 49 } | 56 } |
| 50 | 57 |
| 51 // Make sure that the password store processed all the previous calls which | 58 // Make sure that the password store processed all the previous calls which |
| 52 // are executed on another thread. | 59 // are executed on another thread. |
| 53 void WaitForPasswordStore() { | 60 void WaitForPasswordStore() { |
| 54 scoped_refptr<password_manager::PasswordStore> password_store = | 61 scoped_refptr<password_manager::PasswordStore> password_store = |
| 55 PasswordStoreFactory::GetForProfile( | 62 PasswordStoreFactory::GetForProfile( |
| 56 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); | 63 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); |
| 57 PasswordStoreResultsObserver syncer; | 64 PasswordStoreResultsObserver syncer; |
| 58 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); | 65 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); |
| 59 syncer.Wait(); | 66 syncer.Wait(); |
| 60 } | 67 } |
| 61 | 68 |
| 69 // Similarly to PasswordManagerBrowserTestBase::NavigateToFile this is a | |
| 70 // wrapper around ui_test_utils::NavigateURL that waits until DidFinishLoad() | |
| 71 // fires. Different to NavigateToFile this method allows passing a test_server | |
| 72 // and modifications to the hostname. | |
| 73 void NavigateToURL(const net::EmbeddedTestServer& test_server, | |
| 74 const std::string& hostname, | |
| 75 const std::string& relative_url = "/") { | |
|
vabr (Chromium)
2016/12/22 13:08:24
I don't see where this is only called with 2 argum
jdoerrie
2016/12/22 16:20:00
Done.
| |
| 76 NavigationObserver observer(WebContents()); | |
| 77 GURL url = test_server.GetURL(hostname, relative_url); | |
| 78 ui_test_utils::NavigateToURL(browser(), url); | |
| 79 observer.Wait(); | |
| 80 } | |
| 81 | |
| 82 void SetUpInProcessBrowserTestFixture() override { | |
| 83 ProfileIOData::SetCertVerifierForTesting(mock_cert_verifier_.get()); | |
| 84 } | |
| 85 | |
| 86 void TearDownInProcessBrowserTestFixture() override { | |
| 87 ProfileIOData::SetCertVerifierForTesting(nullptr); | |
| 88 } | |
| 89 | |
| 90 net::MockCertVerifier* mock_cert_verifier() { | |
| 91 return mock_cert_verifier_.get(); | |
| 92 } | |
| 93 | |
| 62 private: | 94 private: |
| 63 | 95 std::unique_ptr<net::MockCertVerifier> mock_cert_verifier_; |
|
vabr (Chromium)
2016/12/22 13:08:24
This is created in the constructor and never delet
vasilii
2016/12/22 13:24:58
Why not just net::MockCertVerifier> mock_cert_veri
jdoerrie
2016/12/22 16:20:01
Done.
| |
| 64 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest); | 96 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest); |
| 65 }; | 97 }; |
| 66 | 98 |
| 67 // Tests. | 99 // Tests. |
| 68 | 100 |
| 69 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, | 101 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, |
| 70 AccountChooserWithOldCredentialAndNavigation) { | 102 AccountChooserWithOldCredentialAndNavigation) { |
| 71 // Save credentials with 'skip_zero_click'. | 103 // Save credentials with 'skip_zero_click'. |
| 72 scoped_refptr<password_manager::TestPasswordStore> password_store = | 104 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 73 static_cast<password_manager::TestPasswordStore*>( | 105 static_cast<password_manager::TestPasswordStore*>( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 ASSERT_EQ(1u, passwords_map.size()); | 144 ASSERT_EQ(1u, passwords_map.size()); |
| 113 const std::vector<autofill::PasswordForm>& passwords_vector = | 145 const std::vector<autofill::PasswordForm>& passwords_vector = |
| 114 passwords_map.begin()->second; | 146 passwords_map.begin()->second; |
| 115 ASSERT_EQ(1u, passwords_vector.size()); | 147 ASSERT_EQ(1u, passwords_vector.size()); |
| 116 const autofill::PasswordForm& form = passwords_vector[0]; | 148 const autofill::PasswordForm& form = passwords_vector[0]; |
| 117 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); | 149 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); |
| 118 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); | 150 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); |
| 119 EXPECT_FALSE(form.skip_zero_click); | 151 EXPECT_FALSE(form.skip_zero_click); |
| 120 } | 152 } |
| 121 | 153 |
| 154 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, | |
| 155 StoreSavesPSLMatchedCredential) { | |
| 156 // Setup HTTPS server serving files from standard test directory. | |
| 157 const base::FilePath::CharType kDocRoot[] = | |
|
vabr (Chromium)
2016/12/22 13:08:24
Please make this both static and constexpr, see ht
jdoerrie
2016/12/22 16:20:01
Done.
| |
| 158 FILE_PATH_LITERAL("chrome/test/data"); | |
| 159 net::EmbeddedTestServer https_test_server( | |
| 160 net::EmbeddedTestServer::TYPE_HTTPS); | |
| 161 https_test_server.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); | |
| 162 ASSERT_TRUE(https_test_server.Start()); | |
| 163 | |
| 164 // Setup mock certificate for all origins. | |
| 165 auto cert = https_test_server.GetCertificate(); | |
| 166 net::CertVerifyResult verify_result; | |
| 167 verify_result.cert_status = 0; | |
| 168 verify_result.is_issued_by_known_root = true; | |
| 169 verify_result.verified_cert = cert; | |
| 170 mock_cert_verifier()->AddResultForCert(cert.get(), verify_result, net::OK); | |
|
jdoerrie
2016/12/22 12:33:53
Even though there is a "--ignore-certificate-error
vabr (Chromium)
2016/12/22 13:08:24
It depends on the purpose of the --ignore-certific
vasilii
2016/12/22 13:24:58
Leave it as it is.
I wonder how NoPromptForLogin
jdoerrie
2016/12/22 16:20:00
Acknowledged.
| |
| 171 | |
| 172 // Redirect all requests to localhost. | |
| 173 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 174 | |
| 175 scoped_refptr<password_manager::TestPasswordStore> password_store = | |
| 176 static_cast<password_manager::TestPasswordStore*>( | |
| 177 PasswordStoreFactory::GetForProfile( | |
| 178 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | |
| 179 .get()); | |
| 180 | |
| 181 // The call to |GetURL| is needed to get the correct port. | |
| 182 GURL psl_url = https_test_server.GetURL("psl.example.com", "/"); | |
| 183 | |
| 184 autofill::PasswordForm signin_form; | |
| 185 signin_form.signon_realm = psl_url.spec(); | |
| 186 signin_form.password_value = base::ASCIIToUTF16("password"); | |
| 187 signin_form.username_value = base::ASCIIToUTF16("user"); | |
| 188 signin_form.origin = psl_url; | |
| 189 password_store->AddLogin(signin_form); | |
| 190 | |
| 191 NavigateToURL(https_test_server, "www.example.com", | |
| 192 "/password/password_form.html"); | |
| 193 | |
| 194 // Call the API to trigger |get| and |store| and redirect. | |
| 195 ASSERT_TRUE( | |
| 196 content::ExecuteScript(RenderViewHost(), | |
| 197 "navigator.credentials.get({password: true})" | |
| 198 ".then(cred => " | |
| 199 "navigator.credentials.store(cred)" | |
| 200 ".then(cred => " | |
| 201 "window.location = '/password/done.html'))")); | |
| 202 | |
| 203 WaitForPasswordStore(); | |
| 204 ASSERT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, | |
| 205 PasswordsModelDelegateFromWebContents(WebContents())->GetState()); | |
| 206 PasswordsModelDelegateFromWebContents(WebContents()) | |
| 207 ->ChooseCredential( | |
| 208 signin_form, | |
| 209 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
| 210 | |
| 211 NavigationObserver observer(WebContents()); | |
| 212 observer.SetPathToWaitFor("/password/done.html"); | |
| 213 observer.Wait(); | |
| 214 | |
| 215 // Wait for the password store before checking the prompt because it pops up | |
| 216 // after the store replies. | |
| 217 WaitForPasswordStore(); | |
| 218 std::unique_ptr<BubbleObserver> prompt_observer( | |
|
vabr (Chromium)
2016/12/22 13:08:24
auto prompt_observer = base::MakeUnique<BubbleObse
jdoerrie
2016/12/22 16:20:01
Acknowledged. As discussed offline I prefer MakeUn
| |
| 219 new BubbleObserver(WebContents())); | |
| 220 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); | |
| 221 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); | |
| 222 | |
| 223 // There should be an entry for both psl.example.com and www.example.com. | |
| 224 password_manager::TestPasswordStore::PasswordMap passwords = | |
| 225 password_store->stored_passwords(); | |
| 226 GURL www_url = https_test_server.GetURL("www.example.com", "/"); | |
| 227 EXPECT_EQ(2U, passwords.size()); | |
| 228 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec())); | |
| 229 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec())); | |
| 230 } | |
| 122 | 231 |
| 123 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, | 232 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, |
| 124 AutoSigninOldCredentialAndNavigation) { | 233 AutoSigninOldCredentialAndNavigation) { |
| 125 // Save credentials with 'skip_zero_click' false. | 234 // Save credentials with 'skip_zero_click' false. |
| 126 scoped_refptr<password_manager::TestPasswordStore> password_store = | 235 scoped_refptr<password_manager::TestPasswordStore> password_store = |
| 127 static_cast<password_manager::TestPasswordStore*>( | 236 static_cast<password_manager::TestPasswordStore*>( |
| 128 PasswordStoreFactory::GetForProfile( | 237 PasswordStoreFactory::GetForProfile( |
| 129 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); | 238 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); |
| 130 autofill::PasswordForm signin_form; | 239 autofill::PasswordForm signin_form; |
| 131 signin_form.signon_realm = embedded_test_server()->base_url().spec(); | 240 signin_form.signon_realm = embedded_test_server()->base_url().spec(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 signin_form.skip_zero_click = false; | 358 signin_form.skip_zero_click = false; |
| 250 signin_form.times_used = 1; | 359 signin_form.times_used = 1; |
| 251 signin_form.password_value = base::ASCIIToUTF16("API"); | 360 signin_form.password_value = base::ASCIIToUTF16("API"); |
| 252 password_manager::TestPasswordStore::PasswordMap stored = | 361 password_manager::TestPasswordStore::PasswordMap stored = |
| 253 password_store->stored_passwords(); | 362 password_store->stored_passwords(); |
| 254 ASSERT_EQ(1u, stored.size()); | 363 ASSERT_EQ(1u, stored.size()); |
| 255 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 364 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
| 256 } | 365 } |
| 257 | 366 |
| 258 } // namespace | 367 } // namespace |
| OLD | NEW |