Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: chrome/browser/password_manager/credential_manager_browsertest.cc

Issue 2721663002: Move Credentials when migrating to HSTS page (Closed)
Patch Set: Code Deduplication Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // There should be an entry for both psl.example.com and www.example.com. 179 // There should be an entry for both psl.example.com and www.example.com.
180 password_manager::TestPasswordStore::PasswordMap passwords = 180 password_manager::TestPasswordStore::PasswordMap passwords =
181 password_store->stored_passwords(); 181 password_store->stored_passwords();
182 GURL www_url = https_test_server().GetURL("www.example.com", "/"); 182 GURL www_url = https_test_server().GetURL("www.example.com", "/");
183 EXPECT_EQ(2U, passwords.size()); 183 EXPECT_EQ(2U, passwords.size());
184 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec())); 184 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec()));
185 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec())); 185 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec()));
186 } 186 }
187 187
188 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, 188 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
189 ObsoleteHttpCredentialMovedOnMigrationToHstsSite) {
190 auto cert = https_test_server().GetCertificate();
191 net::CertVerifyResult verify_result;
192 verify_result.cert_status = 0;
193 verify_result.is_issued_by_known_root = true;
194 verify_result.verified_cert = cert;
195 mock_cert_verifier().AddResultForCert(cert.get(), verify_result, net::OK);
vasilii 2017/03/08 13:31:16 Why do we need this setup?
jdoerrie 2017/03/09 18:35:49 Because otherwise |CredentialManagerImpl::Get| nev
vasilii 2017/03/10 10:21:00 Strange because other CredentialManagerBrowserTest
jdoerrie 2017/03/10 13:53:10 The other tests pass because they are not making u
196 // Add an http credential to the password store.
197 GURL https_origin = https_test_server().base_url();
198 ASSERT_TRUE(https_origin.SchemeIs(url::kHttpsScheme));
199 GURL::Replacements rep;
200 rep.SetSchemeStr(url::kHttpScheme);
201 GURL http_origin = https_origin.ReplaceComponents(rep);
202 autofill::PasswordForm http_form;
203 http_form.signon_realm = http_origin.spec();
204 http_form.origin = http_origin;
205 // Assume that the previous action was already HTTPS one matching the current
206 // page.
207 http_form.action = https_origin;
208 http_form.username_value = base::ASCIIToUTF16("user");
209 http_form.password_value = base::ASCIIToUTF16("12345");
210 scoped_refptr<password_manager::TestPasswordStore> password_store =
211 static_cast<password_manager::TestPasswordStore*>(
212 PasswordStoreFactory::GetForProfile(
213 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
214 .get());
215 password_store->AddLogin(http_form);
216 WaitForPasswordStore();
217
218 // Treat the host of the HTTPS test server as HSTS.
219 AddHSTSHost(https_test_server().host_port_pair().host());
220
221 // Navigate to HTTPS page and trigger the migration.
222 ui_test_utils::NavigateToURL(
223 browser(), https_test_server().GetURL("/password/password_form.html"));
vasilii 2017/03/08 13:31:16 I'm afraid that you are testing the autofill web p
jdoerrie 2017/03/09 18:35:49 Done.
224
225 // Call the API to trigger |get| and |store| and redirect.
226 ASSERT_TRUE(
227 content::ExecuteScript(RenderViewHost(),
228 "navigator.credentials.get({password: true})"
vasilii 2017/03/08 13:31:16 I think get() should be enough to trigger the migr
jdoerrie 2017/03/09 18:35:49 Done.
229 ".then(cred => "
230 "navigator.credentials.store(cred)"
231 ".then(cred => "
232 "window.location = '/password/done.html'))"));
233
234 WaitForPasswordStore();
235 ASSERT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
236 PasswordsModelDelegateFromWebContents(WebContents())->GetState());
237 PasswordsModelDelegateFromWebContents(WebContents())
238 ->ChooseCredential(
239 http_form,
240 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
241
242 NavigationObserver observer(WebContents());
243 observer.SetPathToWaitFor("/password/done.html");
244 observer.Wait();
vasilii 2017/03/08 13:31:16 I think it's all excessive.
jdoerrie 2017/03/09 18:35:49 Done.
245
246 // Wait for the password store before checking the prompt because it pops up
247 // after the store replies.
248 WaitForPasswordStore();
249
250 // Only HTTPS passwords should be present.
251 EXPECT_TRUE(
252 password_store->stored_passwords().at(http_origin.spec()).empty());
253 EXPECT_FALSE(
254 password_store->stored_passwords().at(https_origin.spec()).empty());
255 }
256
257 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
189 AutoSigninOldCredentialAndNavigation) { 258 AutoSigninOldCredentialAndNavigation) {
190 // Save credentials with 'skip_zero_click' false. 259 // Save credentials with 'skip_zero_click' false.
191 scoped_refptr<password_manager::TestPasswordStore> password_store = 260 scoped_refptr<password_manager::TestPasswordStore> password_store =
192 static_cast<password_manager::TestPasswordStore*>( 261 static_cast<password_manager::TestPasswordStore*>(
193 PasswordStoreFactory::GetForProfile( 262 PasswordStoreFactory::GetForProfile(
194 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); 263 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
195 autofill::PasswordForm signin_form; 264 autofill::PasswordForm signin_form;
196 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 265 signin_form.signon_realm = embedded_test_server()->base_url().spec();
197 signin_form.password_value = base::ASCIIToUTF16("password"); 266 signin_form.password_value = base::ASCIIToUTF16("password");
198 signin_form.username_value = base::ASCIIToUTF16("user"); 267 signin_form.username_value = base::ASCIIToUTF16("user");
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 signin_form.skip_zero_click = false; 380 signin_form.skip_zero_click = false;
312 signin_form.times_used = 1; 381 signin_form.times_used = 1;
313 signin_form.password_value = base::ASCIIToUTF16("API"); 382 signin_form.password_value = base::ASCIIToUTF16("API");
314 password_manager::TestPasswordStore::PasswordMap stored = 383 password_manager::TestPasswordStore::PasswordMap stored =
315 password_store->stored_passwords(); 384 password_store->stored_passwords();
316 ASSERT_EQ(1u, stored.size()); 385 ASSERT_EQ(1u, stored.size());
317 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); 386 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]);
318 } 387 }
319 388
320 } // namespace 389 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698