| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 credential:(const web::Credential&)credential | 48 credential:(const web::Credential&)credential |
| 49 completionHandler:(void (^)(BOOL))completionHandler { | 49 completionHandler:(void (^)(BOOL))completionHandler { |
| 50 static_cast<ResolvePromiseBlock>([self blockForSelector:_cmd])(requestID, | 50 static_cast<ResolvePromiseBlock>([self blockForSelector:_cmd])(requestID, |
| 51 credential); | 51 credential); |
| 52 completionHandler(YES); | 52 completionHandler(YES); |
| 53 } | 53 } |
| 54 @end | 54 @end |
| 55 | 55 |
| 56 namespace { | 56 namespace { |
| 57 | 57 |
| 58 const char kTestURL[] = "https://foo.com/login"; |
| 59 |
| 58 // Returns a test credential. | 60 // Returns a test credential. |
| 59 autofill::PasswordForm GetTestPasswordForm1(bool zero_click_allowed) { | 61 autofill::PasswordForm GetTestPasswordForm1(bool zero_click_allowed) { |
| 60 autofill::PasswordForm form; | 62 autofill::PasswordForm form; |
| 63 form.origin = GURL(kTestURL); |
| 64 form.signon_realm = form.origin.spec(); |
| 61 form.username_value = base::ASCIIToUTF16("foo"); | 65 form.username_value = base::ASCIIToUTF16("foo"); |
| 62 form.password_value = base::ASCIIToUTF16("bar"); | 66 form.password_value = base::ASCIIToUTF16("bar"); |
| 63 form.skip_zero_click = !zero_click_allowed; | 67 form.skip_zero_click = !zero_click_allowed; |
| 64 form.type = autofill::PasswordForm::Type::TYPE_API; | 68 form.type = autofill::PasswordForm::Type::TYPE_API; |
| 65 return form; | 69 return form; |
| 66 } | 70 } |
| 67 | 71 |
| 68 // Returns a test credential matching |GetTestPasswordForm1()|. | 72 // Returns a test credential matching |GetTestPasswordForm1()|. |
| 69 web::Credential GetTestWebCredential1(bool zero_click_allowed) { | 73 web::Credential GetTestWebCredential1(bool zero_click_allowed) { |
| 70 web::Credential credential; | 74 web::Credential credential; |
| 71 autofill::PasswordForm form(GetTestPasswordForm1(zero_click_allowed)); | 75 autofill::PasswordForm form(GetTestPasswordForm1(zero_click_allowed)); |
| 72 credential.type = web::CredentialType::CREDENTIAL_TYPE_PASSWORD; | 76 credential.type = web::CredentialType::CREDENTIAL_TYPE_PASSWORD; |
| 73 credential.id = form.username_value; | 77 credential.id = form.username_value; |
| 74 credential.password = form.password_value; | 78 credential.password = form.password_value; |
| 75 return credential; | 79 return credential; |
| 76 } | 80 } |
| 77 | 81 |
| 78 // Returns a different test credential. | 82 // Returns a different test credential. |
| 79 autofill::PasswordForm GetTestPasswordForm2(bool zero_click_allowed) { | 83 autofill::PasswordForm GetTestPasswordForm2(bool zero_click_allowed) { |
| 80 autofill::PasswordForm form; | 84 autofill::PasswordForm form; |
| 85 form.origin = GURL(kTestURL); |
| 86 form.signon_realm = form.origin.spec(); |
| 81 form.username_value = base::ASCIIToUTF16("baz"); | 87 form.username_value = base::ASCIIToUTF16("baz"); |
| 82 form.password_value = base::ASCIIToUTF16("bah"); | 88 form.password_value = base::ASCIIToUTF16("bah"); |
| 83 form.skip_zero_click = !zero_click_allowed; | 89 form.skip_zero_click = !zero_click_allowed; |
| 84 return form; | 90 return form; |
| 85 } | 91 } |
| 86 | 92 |
| 87 // Returns a test credential matching |GetTestPasswordForm2()|. | 93 // Returns a test credential matching |GetTestPasswordForm2()|. |
| 88 web::Credential GetTestWebCredential2(bool zero_click_allowed) { | 94 web::Credential GetTestWebCredential2(bool zero_click_allowed) { |
| 89 web::Credential credential; | 95 web::Credential credential; |
| 90 autofill::PasswordForm form(GetTestPasswordForm2(zero_click_allowed)); | 96 autofill::PasswordForm form(GetTestPasswordForm2(zero_click_allowed)); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 189 |
| 184 void SetUp() override { | 190 void SetUp() override { |
| 185 web::WebTestWithWebState::SetUp(); | 191 web::WebTestWithWebState::SetUp(); |
| 186 id originalMock = | 192 id originalMock = |
| 187 [OCMockObject niceMockForClass:[JSCredentialManager class]]; | 193 [OCMockObject niceMockForClass:[JSCredentialManager class]]; |
| 188 mock_js_credential_manager_.reset([[MockJSCredentialManager alloc] | 194 mock_js_credential_manager_.reset([[MockJSCredentialManager alloc] |
| 189 initWithRepresentedObject:originalMock]); | 195 initWithRepresentedObject:originalMock]); |
| 190 credential_manager_.reset(new CredentialManager( | 196 credential_manager_.reset(new CredentialManager( |
| 191 web_state(), &stub_client_, &stub_driver_, | 197 web_state(), &stub_client_, &stub_driver_, |
| 192 static_cast<id>(mock_js_credential_manager_.get()))); | 198 static_cast<id>(mock_js_credential_manager_.get()))); |
| 199 LoadHtml(@"", GURL(kTestURL)); |
| 193 } | 200 } |
| 194 | 201 |
| 195 // Sets up an expectation that the promise identified by |request_id| will be | 202 // Sets up an expectation that the promise identified by |request_id| will be |
| 196 // resolved with |credential|. |verified| must point to a variable that will | 203 // resolved with |credential|. |verified| must point to a variable that will |
| 197 // be checked by the caller to ensure that the expectations were run. (This | 204 // be checked by the caller to ensure that the expectations were run. (This |
| 198 // is necessary because OCMock doesn't handle methods with C++ object | 205 // is necessary because OCMock doesn't handle methods with C++ object |
| 199 // parameters.) | 206 // parameters.) |
| 200 void ExpectPromiseResolved(bool* verified, | 207 void ExpectPromiseResolved(bool* verified, |
| 201 int request_id, | 208 int request_id, |
| 202 const web::Credential& credential) { | 209 const web::Credential& credential) { |
| 203 SEL selector = | 210 SEL selector = |
| 204 @selector(resolvePromiseWithRequestID:credential:completionHandler:); | 211 @selector(resolvePromiseWithRequestID:credential:completionHandler:); |
| 205 web::Credential strong_credential(credential); | 212 web::Credential strong_credential(credential); |
| 206 [mock_js_credential_manager_ | 213 [mock_js_credential_manager_ |
| 207 onSelector:selector | 214 onSelector:selector |
| 208 callBlockExpectation:^(NSInteger block_request_id, | 215 callBlockExpectation:^(NSInteger block_request_id, |
| 209 const web::Credential& block_credential) { | 216 const web::Credential& block_credential) { |
| 210 EXPECT_EQ(request_id, block_request_id); | 217 EXPECT_EQ(request_id, block_request_id); |
| 211 EXPECT_TRUE(CredentialsEqual(strong_credential, block_credential)); | 218 EXPECT_EQ(strong_credential.type, block_credential.type); |
| 219 EXPECT_EQ(strong_credential.id, block_credential.id); |
| 220 EXPECT_EQ(strong_credential.name, block_credential.name); |
| 221 EXPECT_EQ(strong_credential.avatar_url, block_credential.avatar_url); |
| 222 EXPECT_EQ(strong_credential.password, block_credential.password); |
| 223 EXPECT_EQ(strong_credential.federation_origin.Serialize(), |
| 224 block_credential.federation_origin.Serialize()); |
| 212 *verified = true; | 225 *verified = true; |
| 213 }]; | 226 }]; |
| 214 } | 227 } |
| 215 | 228 |
| 216 // Same as |ExpectPromiseResolved(bool*, int, const web::Credential&)| but | 229 // Same as |ExpectPromiseResolved(bool*, int, const web::Credential&)| but |
| 217 // does not expect a credential to be passed. | 230 // does not expect a credential to be passed. |
| 218 void ExpectPromiseResolved(int request_id) { | 231 void ExpectPromiseResolved(int request_id) { |
| 219 [[[mock_js_credential_manager_ representedObject] expect] | 232 [[[mock_js_credential_manager_ representedObject] expect] |
| 220 resolvePromiseWithRequestID:request_id | 233 resolvePromiseWithRequestID:request_id |
| 221 completionHandler:nil]; | 234 completionHandler:nil]; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // is unavailable. | 277 // is unavailable. |
| 265 TEST_F(CredentialManagerTest, RequestRejectedWhenPasswordStoreUnavailable) { | 278 TEST_F(CredentialManagerTest, RequestRejectedWhenPasswordStoreUnavailable) { |
| 266 // Clear the password store. | 279 // Clear the password store. |
| 267 stub_client_.SetPasswordStore(nullptr); | 280 stub_client_.SetPasswordStore(nullptr); |
| 268 | 281 |
| 269 // Requesting a credential should reject the request with an error. | 282 // Requesting a credential should reject the request with an error. |
| 270 const int request_id = 0; | 283 const int request_id = 0; |
| 271 ExpectPromiseRejected(request_id, | 284 ExpectPromiseRejected(request_id, |
| 272 kCredentialsPasswordStoreUnavailableErrorType, | 285 kCredentialsPasswordStoreUnavailableErrorType, |
| 273 kCredentialsPasswordStoreUnavailableErrorMessage); | 286 kCredentialsPasswordStoreUnavailableErrorMessage); |
| 274 credential_manager_->CredentialsRequested(request_id, | 287 credential_manager_->CredentialsRequested(request_id, GURL(kTestURL), false, |
| 275 GURL("http://foo.com/login"), false, | |
| 276 std::vector<std::string>(), true); | 288 std::vector<std::string>(), true); |
| 277 | 289 |
| 278 // Pump the message loop and verify. | 290 // Pump the message loop and verify. |
| 279 WaitForBackgroundTasks(); | 291 WaitForBackgroundTasks(); |
| 280 EXPECT_OCMOCK_VERIFY([mock_js_credential_manager_ representedObject]); | 292 EXPECT_OCMOCK_VERIFY([mock_js_credential_manager_ representedObject]); |
| 281 } | 293 } |
| 282 | 294 |
| 283 // Tests that a credential request is rejected when another request is pending. | 295 // Tests that a credential request is rejected when another request is pending. |
| 284 TEST_F(CredentialManagerTest, RequestRejectedWhenExistingRequestIsPending) { | 296 TEST_F(CredentialManagerTest, RequestRejectedWhenExistingRequestIsPending) { |
| 285 // Set a password store, but prevent requests from completing. | 297 // Set a password store, but prevent requests from completing. |
| 286 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); | 298 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); |
| 287 | 299 |
| 288 // Make an initial request. Don't pump the message loop, so that the task | 300 // Make an initial request. Don't pump the message loop, so that the task |
| 289 // doesn't complete. Expect the request to resolve with an empty credential | 301 // doesn't complete. Expect the request to resolve with an empty credential |
| 290 // after the message loop is pumped. | 302 // after the message loop is pumped. |
| 291 const int first_request_id = 0; | 303 const int first_request_id = 0; |
| 292 bool first_verified = false; | 304 bool first_verified = false; |
| 293 ExpectPromiseResolved(&first_verified, first_request_id, web::Credential()); | 305 ExpectPromiseResolved(&first_verified, first_request_id, web::Credential()); |
| 294 credential_manager_->CredentialsRequested(first_request_id, | 306 credential_manager_->CredentialsRequested(first_request_id, GURL(kTestURL), |
| 295 GURL("http://foo.com/login"), false, | 307 false, std::vector<std::string>(), |
| 296 std::vector<std::string>(), true); | 308 true); |
| 297 | 309 |
| 298 // Making a second request and then pumping the message loop should reject the | 310 // Making a second request and then pumping the message loop should reject the |
| 299 // request with an error. | 311 // request with an error. |
| 300 const int second_request_id = 0; | 312 const int second_request_id = 0; |
| 301 ExpectPromiseRejected(second_request_id, kCredentialsPendingRequestErrorType, | 313 ExpectPromiseRejected(second_request_id, kCredentialsPendingRequestErrorType, |
| 302 kCredentialsPendingRequestErrorMessage); | 314 kCredentialsPendingRequestErrorMessage); |
| 303 credential_manager_->CredentialsRequested(second_request_id, | 315 credential_manager_->CredentialsRequested(second_request_id, GURL(kTestURL), |
| 304 GURL("http://foo.com/login"), false, | 316 false, std::vector<std::string>(), |
| 305 std::vector<std::string>(), true); | 317 true); |
| 306 | 318 |
| 307 // Pump the message loop and verify. | 319 // Pump the message loop and verify. |
| 308 WaitForBackgroundTasks(); | 320 WaitForBackgroundTasks(); |
| 309 EXPECT_TRUE(first_verified); | 321 EXPECT_TRUE(first_verified); |
| 310 EXPECT_OCMOCK_VERIFY([mock_js_credential_manager_ representedObject]); | 322 EXPECT_OCMOCK_VERIFY([mock_js_credential_manager_ representedObject]); |
| 311 } | 323 } |
| 312 | 324 |
| 313 // Tests that a zero-click credential request is resolved properly with an empty | 325 // Tests that a zero-click credential request is resolved properly with an empty |
| 314 // credential when zero-click sign-in is disabled. | 326 // credential when zero-click sign-in is disabled. |
| 315 TEST_F(CredentialManagerTest, | 327 TEST_F(CredentialManagerTest, |
| 316 ZeroClickRequestResolvedWithEmptyCredentialWhenZeroClickSignInDisabled) { | 328 ZeroClickRequestResolvedWithEmptyCredentialWhenZeroClickSignInDisabled) { |
| 317 // Set a password store, but request a zero-click credential with zero-click | 329 // Set a password store, but request a zero-click credential with zero-click |
| 318 // disabled. | 330 // disabled. |
| 319 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); | 331 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); |
| 320 const bool zero_click = true; | 332 const bool zero_click = true; |
| 321 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) | 333 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) |
| 322 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, | 334 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, |
| 323 new base::FundamentalValue(!zero_click)); | 335 new base::FundamentalValue(!zero_click)); |
| 324 | 336 |
| 325 // Requesting a zero-click credential should immediately resolve the request | 337 // Requesting a zero-click credential should immediately resolve the request |
| 326 // with an empty credential. | 338 // with an empty credential. |
| 327 const int request_id = 0; | 339 const int request_id = 0; |
| 328 bool verified = false; | 340 bool verified = false; |
| 329 ExpectPromiseResolved(&verified, request_id, web::Credential()); | 341 ExpectPromiseResolved(&verified, request_id, web::Credential()); |
| 330 credential_manager_->CredentialsRequested( | 342 credential_manager_->CredentialsRequested( |
| 331 request_id, GURL("http://foo.com/login"), zero_click, | 343 request_id, GURL(kTestURL), zero_click, std::vector<std::string>(), true); |
| 332 std::vector<std::string>(), true); | |
| 333 | 344 |
| 334 // Pump the message loop and verify. | 345 // Pump the message loop and verify. |
| 335 WaitForBackgroundTasks(); | 346 WaitForBackgroundTasks(); |
| 336 EXPECT_TRUE(verified); | 347 EXPECT_TRUE(verified); |
| 337 } | 348 } |
| 338 | 349 |
| 339 // Tests that a credential request is properly resolved with an empty credential | 350 // Tests that a credential request is properly resolved with an empty credential |
| 340 // when no credentials are available. | 351 // when no credentials are available. |
| 341 TEST_F(CredentialManagerTest, | 352 TEST_F(CredentialManagerTest, |
| 342 RequestResolvedWithEmptyCredentialWhenNoneAvailable) { | 353 RequestResolvedWithEmptyCredentialWhenNoneAvailable) { |
| 343 // Set a password store with no credentials, enable zero-click, and request a | 354 // Set a password store with no credentials, enable zero-click, and request a |
| 344 // zero-click credential. | 355 // zero-click credential. |
| 345 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); | 356 stub_client_.SetPasswordStore(new password_manager::TestPasswordStore); |
| 346 const bool zero_click = true; | 357 const bool zero_click = true; |
| 347 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) | 358 static_cast<TestingPrefServiceSimple*>(stub_client_.GetPrefs()) |
| 348 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, | 359 ->SetUserPref(password_manager::prefs::kCredentialsEnableAutosignin, |
| 349 new base::FundamentalValue(zero_click)); | 360 new base::FundamentalValue(zero_click)); |
| 350 | 361 |
| 351 // Requesting a zero-click credential should try to retrieve PasswordForms | 362 // Requesting a zero-click credential should try to retrieve PasswordForms |
| 352 // from the PasswordStore and resolve the request with an empty Credential | 363 // from the PasswordStore and resolve the request with an empty Credential |
| 353 // when none are found. | 364 // when none are found. |
| 354 const int request_id = 0; | 365 const int request_id = 0; |
| 355 bool verified = false; | 366 bool verified = false; |
| 356 ExpectPromiseResolved(&verified, request_id, web::Credential()); | 367 ExpectPromiseResolved(&verified, request_id, web::Credential()); |
| 357 credential_manager_->CredentialsRequested( | 368 credential_manager_->CredentialsRequested( |
| 358 request_id, GURL("http://foo.com/login"), zero_click, | 369 request_id, GURL(kTestURL), zero_click, std::vector<std::string>(), true); |
| 359 std::vector<std::string>(), true); | |
| 360 | 370 |
| 361 // Pump the message loop and verify. | 371 // Pump the message loop and verify. |
| 362 WaitForBackgroundTasks(); | 372 WaitForBackgroundTasks(); |
| 363 EXPECT_TRUE(verified); | 373 EXPECT_TRUE(verified); |
| 364 } | 374 } |
| 365 | 375 |
| 366 // Tests that a zero-click credential request properly resolves. | 376 // Tests that a zero-click credential request properly resolves. |
| 367 TEST_F(CredentialManagerTest, ZeroClickRequestResolved) { | 377 TEST_F(CredentialManagerTest, ZeroClickRequestResolved) { |
| 368 // Set a password store with a credential, enable zero-click, and request a | 378 // Set a password store with a credential, enable zero-click, and request a |
| 369 // zero-click credential. | 379 // zero-click credential. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 383 new base::FundamentalValue(true)); | 393 new base::FundamentalValue(true)); |
| 384 WaitForBackgroundTasks(); | 394 WaitForBackgroundTasks(); |
| 385 | 395 |
| 386 // Requesting a zero-click credential should retrieve a PasswordForm from the | 396 // Requesting a zero-click credential should retrieve a PasswordForm from the |
| 387 // PasswordStore and resolve the request with a corresponding Credential. | 397 // PasswordStore and resolve the request with a corresponding Credential. |
| 388 const int request_id = 0; | 398 const int request_id = 0; |
| 389 bool verified = false; | 399 bool verified = false; |
| 390 ExpectPromiseResolved(&verified, request_id, | 400 ExpectPromiseResolved(&verified, request_id, |
| 391 GetTestWebCredential1(zero_click)); | 401 GetTestWebCredential1(zero_click)); |
| 392 credential_manager_->CredentialsRequested( | 402 credential_manager_->CredentialsRequested( |
| 393 request_id, GURL("http://foo.com/login"), zero_click, | 403 request_id, GURL(kTestURL), zero_click, std::vector<std::string>(), true); |
| 394 std::vector<std::string>(), true); | |
| 395 | 404 |
| 396 // Pump the message loop and verify. | 405 // Pump the message loop and verify. |
| 397 WaitForBackgroundTasks(); | 406 WaitForBackgroundTasks(); |
| 398 EXPECT_TRUE(verified); | 407 EXPECT_TRUE(verified); |
| 399 } | 408 } |
| 400 | 409 |
| 401 // Tests that a credential request properly resolves. | 410 // Tests that a credential request properly resolves. |
| 402 // TODO(crbug.com/598851): Reenabled this test. | 411 // TODO(crbug.com/598851): Reenabled this test. |
| 403 TEST_F(CredentialManagerTest, DISABLED_RequestResolved) { | 412 TEST_F(CredentialManagerTest, DISABLED_RequestResolved) { |
| 404 // Set a password store with two credentials and set a credential to be | 413 // Set a password store with two credentials and set a credential to be |
| 405 // returned by the PasswordManagerClient as if chosen by the user. | 414 // returned by the PasswordManagerClient as if chosen by the user. |
| 406 scoped_refptr<password_manager::TestPasswordStore> store( | 415 scoped_refptr<password_manager::TestPasswordStore> store( |
| 407 new password_manager::TestPasswordStore); | 416 new password_manager::TestPasswordStore); |
| 408 const bool zero_click = false; | 417 const bool zero_click = false; |
| 409 store->AddLogin(GetTestPasswordForm1(zero_click)); | 418 store->AddLogin(GetTestPasswordForm1(zero_click)); |
| 410 store->AddLogin(GetTestPasswordForm2(zero_click)); | 419 store->AddLogin(GetTestPasswordForm2(zero_click)); |
| 411 stub_client_.SetPasswordStore(store); | 420 stub_client_.SetPasswordStore(store); |
| 412 stub_client_.SetUserChosenCredential(password_manager::CredentialInfo( | 421 stub_client_.SetUserChosenCredential(password_manager::CredentialInfo( |
| 413 GetTestPasswordForm2(zero_click), | 422 GetTestPasswordForm2(zero_click), |
| 414 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); | 423 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); |
| 415 WaitForBackgroundTasks(); | 424 WaitForBackgroundTasks(); |
| 416 | 425 |
| 417 // Request a credential. The request should be resolved with the credential | 426 // Request a credential. The request should be resolved with the credential |
| 418 // set on the stub client. | 427 // set on the stub client. |
| 419 const int request_id = 0; | 428 const int request_id = 0; |
| 420 bool verified = false; | 429 bool verified = false; |
| 421 ExpectPromiseResolved(&verified, request_id, | 430 ExpectPromiseResolved(&verified, request_id, |
| 422 GetTestWebCredential2(zero_click)); | 431 GetTestWebCredential2(zero_click)); |
| 423 credential_manager_->CredentialsRequested( | 432 credential_manager_->CredentialsRequested( |
| 424 request_id, GURL("http://foo.com/login"), zero_click, | 433 request_id, GURL(kTestURL), zero_click, std::vector<std::string>(), true); |
| 425 std::vector<std::string>(), true); | |
| 426 | 434 |
| 427 // Pump the message loop and verify. | 435 // Pump the message loop and verify. |
| 428 WaitForBackgroundTasks(); | 436 WaitForBackgroundTasks(); |
| 429 EXPECT_TRUE(verified); | 437 EXPECT_TRUE(verified); |
| 430 } | 438 } |
| 431 | 439 |
| 432 // Tests that two requests back-to-back succeed when they wait to be resolved. | 440 // Tests that two requests back-to-back succeed when they wait to be resolved. |
| 433 // TODO(crbug.com/598851): Reenable this test. | 441 // TODO(crbug.com/598851): Reenable this test. |
| 434 TEST_F(CredentialManagerTest, DISABLED_ConsecutiveRequestsResolve) { | 442 TEST_F(CredentialManagerTest, DISABLED_ConsecutiveRequestsResolve) { |
| 435 // Set a password store with two credentials and set a credential to be | 443 // Set a password store with two credentials and set a credential to be |
| 436 // returned by the PasswordManagerClient as if chosen by the user. | 444 // returned by the PasswordManagerClient as if chosen by the user. |
| 437 scoped_refptr<password_manager::TestPasswordStore> store( | 445 scoped_refptr<password_manager::TestPasswordStore> store( |
| 438 new password_manager::TestPasswordStore); | 446 new password_manager::TestPasswordStore); |
| 439 const bool zero_click = false; | 447 const bool zero_click = false; |
| 440 store->AddLogin(GetTestPasswordForm1(zero_click)); | 448 store->AddLogin(GetTestPasswordForm1(zero_click)); |
| 441 stub_client_.SetPasswordStore(store); | 449 stub_client_.SetPasswordStore(store); |
| 442 stub_client_.SetUserChosenCredential(password_manager::CredentialInfo( | 450 stub_client_.SetUserChosenCredential(password_manager::CredentialInfo( |
| 443 GetTestPasswordForm1(zero_click), | 451 GetTestPasswordForm1(zero_click), |
| 444 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); | 452 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD)); |
| 445 WaitForBackgroundTasks(); | 453 WaitForBackgroundTasks(); |
| 446 | 454 |
| 447 // Request a credential. The request should be resolved with the credential | 455 // Request a credential. The request should be resolved with the credential |
| 448 // set on the stub client. | 456 // set on the stub client. |
| 449 const int first_request_id = 0; | 457 const int first_request_id = 0; |
| 450 bool first_verified = false; | 458 bool first_verified = false; |
| 451 ExpectPromiseResolved(&first_verified, first_request_id, | 459 ExpectPromiseResolved(&first_verified, first_request_id, |
| 452 GetTestWebCredential1(zero_click)); | 460 GetTestWebCredential1(zero_click)); |
| 453 credential_manager_->CredentialsRequested( | 461 credential_manager_->CredentialsRequested(first_request_id, GURL(kTestURL), |
| 454 first_request_id, GURL("http://foo.com/login"), zero_click, | 462 zero_click, |
| 455 std::vector<std::string>(), true); | 463 std::vector<std::string>(), true); |
| 456 | 464 |
| 457 // Pump the message loop and verify. | 465 // Pump the message loop and verify. |
| 458 WaitForBackgroundTasks(); | 466 WaitForBackgroundTasks(); |
| 459 EXPECT_TRUE(first_verified); | 467 EXPECT_TRUE(first_verified); |
| 460 | 468 |
| 461 ClearPromiseResolutionExpectations(); | 469 ClearPromiseResolutionExpectations(); |
| 462 | 470 |
| 463 // Make a second request. It should be resolved again. | 471 // Make a second request. It should be resolved again. |
| 464 const int second_request_id = 1; | 472 const int second_request_id = 1; |
| 465 bool second_verified = false; | 473 bool second_verified = false; |
| 466 ExpectPromiseResolved(&second_verified, second_request_id, | 474 ExpectPromiseResolved(&second_verified, second_request_id, |
| 467 GetTestWebCredential1(zero_click)); | 475 GetTestWebCredential1(zero_click)); |
| 468 credential_manager_->CredentialsRequested( | 476 credential_manager_->CredentialsRequested(second_request_id, GURL(kTestURL), |
| 469 second_request_id, GURL("http://foo.com/login"), zero_click, | 477 zero_click, |
| 470 std::vector<std::string>(), true); | 478 std::vector<std::string>(), true); |
| 471 | 479 |
| 472 // Pump the message loop and verify. | 480 // Pump the message loop and verify. |
| 473 WaitForBackgroundTasks(); | 481 WaitForBackgroundTasks(); |
| 474 EXPECT_TRUE(second_verified); | 482 EXPECT_TRUE(second_verified); |
| 475 } | 483 } |
| 476 | 484 |
| 477 // Tests that notifySignedIn prompts the user to save a password. | 485 // Tests that notifySignedIn prompts the user to save a password. |
| 478 TEST_F(CredentialManagerTest, | 486 TEST_F(CredentialManagerTest, |
| 479 SignInResolvesAndPromptsUserWhenSavingEnabledAndNotBlacklisted) { | 487 SignInResolvesAndPromptsUserWhenSavingEnabledAndNotBlacklisted) { |
| 480 // Set a password store so the PasswordFormManager can retrieve credentials. | 488 // Set a password store so the PasswordFormManager can retrieve credentials. |
| 481 scoped_refptr<password_manager::TestPasswordStore> store( | 489 scoped_refptr<password_manager::TestPasswordStore> store( |
| 482 new password_manager::TestPasswordStore); | 490 new password_manager::TestPasswordStore); |
| 483 stub_client_.SetPasswordStore(store); | 491 stub_client_.SetPasswordStore(store); |
| 484 const bool saving_enabled = true; | 492 const bool saving_enabled = true; |
| 485 EXPECT_CALL(stub_client_, IsSavingAndFillingEnabledForCurrentPage()) | 493 EXPECT_CALL(stub_client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 486 .WillOnce(Return(saving_enabled)) | 494 .WillOnce(Return(saving_enabled)) |
| 487 .WillOnce(Return(saving_enabled)); | 495 .WillOnce(Return(saving_enabled)); |
| 488 | 496 |
| 489 // Notify the browser that the user signed in. | 497 // Notify the browser that the user signed in. |
| 490 const int request_id = 0; | 498 const int request_id = 0; |
| 491 ExpectPromiseResolved(request_id); | 499 ExpectPromiseResolved(request_id); |
| 492 const bool zero_click = true; | 500 const bool zero_click = true; |
| 493 credential_manager_->SignedIn(request_id, GURL("http://foo.com/login"), | 501 credential_manager_->SignedIn(request_id, GURL(kTestURL), |
| 494 GetTestWebCredential1(zero_click)); | 502 GetTestWebCredential1(zero_click)); |
| 495 | 503 |
| 496 // Pump the message loop and verify. | 504 // Pump the message loop and verify. |
| 497 WaitForBackgroundTasks(); | 505 WaitForBackgroundTasks(); |
| 498 autofill::PasswordForm expected_observed_form( | 506 autofill::PasswordForm expected_observed_form( |
| 499 GetTestPasswordForm1(zero_click)); | 507 GetTestPasswordForm1(zero_click)); |
| 500 expected_observed_form.username_value.clear(); | 508 expected_observed_form.username_value.clear(); |
| 501 expected_observed_form.password_value.clear(); | 509 expected_observed_form.password_value.clear(); |
| 502 EXPECT_EQ(expected_observed_form, stub_client_.saved_form()->observed_form()); | 510 EXPECT_EQ(expected_observed_form, stub_client_.saved_form()->observed_form()); |
| 503 } | 511 } |
| 504 | 512 |
| 505 // Tests that notifySignedIn doesn't prompt the user to save a password when the | 513 // Tests that notifySignedIn doesn't prompt the user to save a password when the |
| 506 // password manager is disabled for the current page. | 514 // password manager is disabled for the current page. |
| 507 TEST_F(CredentialManagerTest, | 515 TEST_F(CredentialManagerTest, |
| 508 SignInResolvesAndDoesNotPromptsUserWhenSavingDisabledAndNotBlacklisted) { | 516 SignInResolvesAndDoesNotPromptsUserWhenSavingDisabledAndNotBlacklisted) { |
| 509 // Disable saving. | 517 // Disable saving. |
| 510 scoped_refptr<password_manager::TestPasswordStore> store( | 518 scoped_refptr<password_manager::TestPasswordStore> store( |
| 511 new password_manager::TestPasswordStore); | 519 new password_manager::TestPasswordStore); |
| 512 stub_client_.SetPasswordStore(store); | 520 stub_client_.SetPasswordStore(store); |
| 513 const bool saving_enabled = false; | 521 const bool saving_enabled = false; |
| 514 EXPECT_CALL(stub_client_, IsSavingAndFillingEnabledForCurrentPage()) | 522 EXPECT_CALL(stub_client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 515 .WillOnce(Return(saving_enabled)); | 523 .WillOnce(Return(saving_enabled)); |
| 516 | 524 |
| 517 // Notify the browser that the user signed in. | 525 // Notify the browser that the user signed in. |
| 518 const int request_id = 0; | 526 const int request_id = 0; |
| 519 ExpectPromiseResolved(request_id); | 527 ExpectPromiseResolved(request_id); |
| 520 const bool zero_click = false; | 528 const bool zero_click = false; |
| 521 credential_manager_->SignedIn(request_id, GURL("http://foo.com/login"), | 529 credential_manager_->SignedIn(request_id, GURL(kTestURL), |
| 522 GetTestWebCredential1(zero_click)); | 530 GetTestWebCredential1(zero_click)); |
| 523 | 531 |
| 524 // Pump the message loop and verify that no form was saved. | 532 // Pump the message loop and verify that no form was saved. |
| 525 WaitForBackgroundTasks(); | 533 WaitForBackgroundTasks(); |
| 526 EXPECT_FALSE(stub_client_.saved_form()); | 534 EXPECT_FALSE(stub_client_.saved_form()); |
| 527 } | 535 } |
| 528 | 536 |
| 529 // Tests that notifySignedIn doesn't prompt the user to save a password when the | 537 // Tests that notifySignedIn doesn't prompt the user to save a password when the |
| 530 // submitted form is blacklisted by the password manager. | 538 // submitted form is blacklisted by the password manager. |
| 531 TEST_F(CredentialManagerTest, | 539 TEST_F(CredentialManagerTest, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 542 // Save the credential that will be signed in and mark it blacklisted. | 550 // Save the credential that will be signed in and mark it blacklisted. |
| 543 const bool zero_click = false; | 551 const bool zero_click = false; |
| 544 autofill::PasswordForm blacklisted_form(GetTestPasswordForm1(zero_click)); | 552 autofill::PasswordForm blacklisted_form(GetTestPasswordForm1(zero_click)); |
| 545 blacklisted_form.blacklisted_by_user = true; | 553 blacklisted_form.blacklisted_by_user = true; |
| 546 store->AddLogin(blacklisted_form); | 554 store->AddLogin(blacklisted_form); |
| 547 WaitForBackgroundTasks(); | 555 WaitForBackgroundTasks(); |
| 548 | 556 |
| 549 // Notify the browser that the user signed in. | 557 // Notify the browser that the user signed in. |
| 550 const int request_id = 0; | 558 const int request_id = 0; |
| 551 ExpectPromiseResolved(request_id); | 559 ExpectPromiseResolved(request_id); |
| 552 credential_manager_->SignedIn(request_id, GURL("http://foo.com/login"), | 560 credential_manager_->SignedIn(request_id, GURL(kTestURL), |
| 553 GetTestWebCredential1(zero_click)); | 561 GetTestWebCredential1(zero_click)); |
| 554 | 562 |
| 555 // Pump the message loop and verify that no form was saved. | 563 // Pump the message loop and verify that no form was saved. |
| 556 WaitForBackgroundTasks(); | 564 WaitForBackgroundTasks(); |
| 557 EXPECT_FALSE(stub_client_.saved_form()); | 565 EXPECT_FALSE(stub_client_.saved_form()); |
| 558 } | 566 } |
| 559 | 567 |
| 560 // Tests that notifySignedOut marks credentials as non-zero-click. | 568 // Tests that notifySignedOut marks credentials as non-zero-click. |
| 561 TEST_F(CredentialManagerTest, SignOutResolvesAndMarksFormsNonZeroClick) { | 569 TEST_F(CredentialManagerTest, SignOutResolvesAndMarksFormsNonZeroClick) { |
| 562 // Create two zero-click credentials for the current page. | 570 // Create two zero-click credentials for the current page. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 WaitForBackgroundTasks(); | 606 WaitForBackgroundTasks(); |
| 599 EXPECT_EQ(1U, store->stored_passwords().size()); | 607 EXPECT_EQ(1U, store->stored_passwords().size()); |
| 600 const std::vector<autofill::PasswordForm>& passwords_after_signout = | 608 const std::vector<autofill::PasswordForm>& passwords_after_signout = |
| 601 store->stored_passwords().find(current_origin)->second; | 609 store->stored_passwords().find(current_origin)->second; |
| 602 EXPECT_EQ(2U, passwords_after_signout.size()); | 610 EXPECT_EQ(2U, passwords_after_signout.size()); |
| 603 for (const autofill::PasswordForm& form : passwords_after_signout) | 611 for (const autofill::PasswordForm& form : passwords_after_signout) |
| 604 EXPECT_TRUE(form.skip_zero_click); | 612 EXPECT_TRUE(form.skip_zero_click); |
| 605 } | 613 } |
| 606 | 614 |
| 607 } // namespace | 615 } // namespace |
| OLD | NEW |