| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/passwords/credential_manager.h" | 5 #include "ios/chrome/browser/passwords/credential_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/mac/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // Tests that a zero-click credential request is resolved properly with an empty | 313 // Tests that a zero-click credential request is resolved properly with an empty |
| 314 // credential when zero-click sign-in is disabled. | 314 // credential when zero-click sign-in is disabled. |
| 315 TEST_F(CredentialManagerTest, | 315 TEST_F(CredentialManagerTest, |
| 316 ZeroClickRequestResolvedWithEmptyCredentialWhenZeroClickSignInDisabled) { | 316 ZeroClickRequestResolvedWithEmptyCredentialWhenZeroClickSignInDisabled) { |
| 317 // Set a password store, but request a zero-click credential with zero-click | 317 // Set a password store, but request a zero-click credential with zero-click |
| 318 // disabled. | 318 // disabled. |
| 319 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); | 319 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); |
| 320 const bool zero_click = true; | 320 const bool zero_click = true; |
| 321 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) | 321 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) |
| 322 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, | 322 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, |
| 323 new base::FundamentalValue(!zero_click)); | 323 new base::Value(!zero_click)); |
| 324 | 324 |
| 325 // Requesting a zero-click credential should immediately resolve the request | 325 // Requesting a zero-click credential should immediately resolve the request |
| 326 // with an empty credential. | 326 // with an empty credential. |
| 327 const int request_id = 0; | 327 const int request_id = 0; |
| 328 bool verified = false; | 328 bool verified = false; |
| 329 ExpectPromiseResolved(&verified, request_id, web::Credential()); | 329 ExpectPromiseResolved(&verified, request_id, web::Credential()); |
| 330 credential_manager_->CredentialsRequested( | 330 credential_manager_->CredentialsRequested( |
| 331 request_id, GURL("http://foo.com/login"), zero_click, | 331 request_id, GURL("http://foo.com/login"), zero_click, |
| 332 std::vector<std::string>(), true); | 332 std::vector<std::string>(), true); |
| 333 | 333 |
| 334 // Pump the message loop and verify. | 334 // Pump the message loop and verify. |
| 335 WaitForBackgroundTasks(); | 335 WaitForBackgroundTasks(); |
| 336 EXPECT_TRUE(verified); | 336 EXPECT_TRUE(verified); |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Tests that a credential request is properly resolved with an empty credential | 339 // Tests that a credential request is properly resolved with an empty credential |
| 340 // when no credentials are available. | 340 // when no credentials are available. |
| 341 TEST_F(CredentialManagerTest, | 341 TEST_F(CredentialManagerTest, |
| 342 RequestResolvedWithEmptyCredentialWhenNoneAvailable) { | 342 RequestResolvedWithEmptyCredentialWhenNoneAvailable) { |
| 343 // Set a password store with no credentials, enable zero-click, and request a | 343 // Set a password store with no credentials, enable zero-click, and request a |
| 344 // zero-click credential. | 344 // zero-click credential. |
| 345 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); | 345 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); |
| 346 const bool zero_click = true; | 346 const bool zero_click = true; |
| 347 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) | 347 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) |
| 348 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, | 348 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, |
| 349 new base::FundamentalValue(zero_click)); | 349 new base::Value(zero_click)); |
| 350 | 350 |
| 351 // Requesting a zero-click credential should try to retrieve PasswordForms | 351 // Requesting a zero-click credential should try to retrieve PasswordForms |
| 352 // from the PasswordStore and resolve the request with an empty Credential | 352 // from the PasswordStore and resolve the request with an empty Credential |
| 353 // when none are found. | 353 // when none are found. |
| 354 const int request_id = 0; | 354 const int request_id = 0; |
| 355 bool verified = false; | 355 bool verified = false; |
| 356 ExpectPromiseResolved(&verified, request_id, web::Credential()); | 356 ExpectPromiseResolved(&verified, request_id, web::Credential()); |
| 357 credential_manager_->CredentialsRequested( | 357 credential_manager_->CredentialsRequested( |
| 358 request_id, GURL("http://foo.com/login"), zero_click, | 358 request_id, GURL("http://foo.com/login"), zero_click, |
| 359 std::vector<std::string>(), true); | 359 std::vector<std::string>(), true); |
| 360 | 360 |
| 361 // Pump the message loop and verify. | 361 // Pump the message loop and verify. |
| 362 WaitForBackgroundTasks(); | 362 WaitForBackgroundTasks(); |
| 363 EXPECT_TRUE(verified); | 363 EXPECT_TRUE(verified); |
| 364 } | 364 } |
| 365 | 365 |
| 366 // Tests that a zero-click credential request properly resolves. | 366 // Tests that a zero-click credential request properly resolves. |
| 367 TEST_F(CredentialManagerTest, ZeroClickRequestResolved) { | 367 TEST_F(CredentialManagerTest, ZeroClickRequestResolved) { |
| 368 // Set a password store with a credential, enable zero-click, and request a | 368 // Set a password store with a credential, enable zero-click, and request a |
| 369 // zero-click credential. | 369 // zero-click credential. |
| 370 scoped_refptr<password_manager::TestPasswordStore> store( | 370 scoped_refptr<password_manager::TestPasswordStore> store( |
| 371 new password_manager::TestPasswordStore); | 371 new password_manager::TestPasswordStore); |
| 372 const bool zero_click = true; | 372 const bool zero_click = true; |
| 373 store->AddLogin(GetTestPasswordForm1(zero_click)); | 373 store->AddLogin(GetTestPasswordForm1(zero_click)); |
| 374 stub_client_.SetPasswordStore(store); | 374 stub_client_.SetPasswordStore(store); |
| 375 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) | 375 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) |
| 376 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, | 376 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, |
| 377 new base::FundamentalValue(zero_click)); | 377 new base::Value(zero_click)); |
| 378 // Without the first run experience, the zero-click credentials won't be | 378 // Without the first run experience, the zero-click credentials won't be |
| 379 // passed to the site. | 379 // passed to the site. |
| 380 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) | 380 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) |
| 381 ->SetUserPref( | 381 ->SetUserPref( |
| 382 password_manager::prefs::kWasAutoSignInFirstRunExperienceShown, | 382 password_manager::prefs::kWasAutoSignInFirstRunExperienceShown, |
| 383 new base::FundamentalValue(true)); | 383 new base::Value(true)); |
| 384 WaitForBackgroundTasks(); | 384 WaitForBackgroundTasks(); |
| 385 | 385 |
| 386 // Requesting a zero-click credential should retrieve a PasswordForm from the | 386 // Requesting a zero-click credential should retrieve a PasswordForm from the |
| 387 // PasswordStore and resolve the request with a corresponding Credential. | 387 // PasswordStore and resolve the request with a corresponding Credential. |
| 388 const int request_id = 0; | 388 const int request_id = 0; |
| 389 bool verified = false; | 389 bool verified = false; |
| 390 ExpectPromiseResolved(&verified, request_id, | 390 ExpectPromiseResolved(&verified, request_id, |
| 391 GetTestWebCredential1(zero_click)); | 391 GetTestWebCredential1(zero_click)); |
| 392 credential_manager_->CredentialsRequested( | 392 credential_manager_->CredentialsRequested( |
| 393 request_id, GURL("http://foo.com/login"), zero_click, | 393 request_id, GURL("http://foo.com/login"), zero_click, |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 WaitForBackgroundTasks(); | 598 WaitForBackgroundTasks(); |
| 599 EXPECT_EQ(1U, store->stored_passwords().size()); | 599 EXPECT_EQ(1U, store->stored_passwords().size()); |
| 600 const std::vector<autofill::PasswordForm>& passwords_after_signout = | 600 const std::vector<autofill::PasswordForm>& passwords_after_signout = |
| 601 store->stored_passwords().find(current_origin)->second; | 601 store->stored_passwords().find(current_origin)->second; |
| 602 EXPECT_EQ(2U, passwords_after_signout.size()); | 602 EXPECT_EQ(2U, passwords_after_signout.size()); |
| 603 for (const autofill::PasswordForm& form : passwords_after_signout) | 603 for (const autofill::PasswordForm& form : passwords_after_signout) |
| 604 EXPECT_TRUE(form.skip_zero_click); | 604 EXPECT_TRUE(form.skip_zero_click); |
| 605 } | 605 } |
| 606 | 606 |
| 607 } // namespace | 607 } // namespace |
| OLD | NEW |