| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/content/browser/credential_manager_impl.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/test/mock_render_process_host.h" | 34 #include "content/public/test/mock_render_process_host.h" |
| 35 #include "content/public/test/test_renderer_host.h" | 35 #include "content/public/test/test_renderer_host.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 36 #include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 38 |
| 39 using content::BrowserContext; | 39 using content::BrowserContext; |
| 40 using content::WebContents; | 40 using content::WebContents; |
| 41 | 41 |
| 42 using testing::_; | 42 using testing::_; |
| 43 using testing::ElementsAre; |
| 43 using testing::Pointee; | 44 using testing::Pointee; |
| 44 using testing::UnorderedElementsAre; | 45 using testing::UnorderedElementsAre; |
| 45 | 46 |
| 46 namespace password_manager { | 47 namespace password_manager { |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 const char kTestWebOrigin[] = "https://example.com/"; | 51 const char kTestWebOrigin[] = "https://example.com/"; |
| 51 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; | 52 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; |
| 52 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; | 53 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 EXPECT_EQ(form_.display_name, new_form.display_name); | 445 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 445 EXPECT_EQ(form_.password_value, new_form.password_value); | 446 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 446 EXPECT_EQ(form_.origin, new_form.origin); | 447 EXPECT_EQ(form_.origin, new_form.origin); |
| 447 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); | 448 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 448 EXPECT_EQ(form_.federation_origin, new_form.federation_origin); | 449 EXPECT_EQ(form_.federation_origin, new_form.federation_origin); |
| 449 EXPECT_EQ(form_.icon_url, new_form.icon_url); | 450 EXPECT_EQ(form_.icon_url, new_form.icon_url); |
| 450 EXPECT_FALSE(form_.skip_zero_click); | 451 EXPECT_FALSE(form_.skip_zero_click); |
| 451 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); | 452 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 452 } | 453 } |
| 453 | 454 |
| 455 TEST_F(CredentialManagerImplTest, StoreFederatedAfterPassword) { |
| 456 // Populate the PasswordStore with a form. |
| 457 store_->AddLogin(form_); |
| 458 |
| 459 autofill::PasswordForm federated = form_; |
| 460 federated.password_value.clear(); |
| 461 federated.type = autofill::PasswordForm::TYPE_API; |
| 462 federated.preferred = true; |
| 463 federated.federation_origin = url::Origin(GURL("https://google.com/")); |
| 464 federated.signon_realm = "federation://example.com/google.com"; |
| 465 CredentialInfo info(federated, CredentialType::CREDENTIAL_TYPE_FEDERATED); |
| 466 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
| 467 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 468 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); |
| 469 |
| 470 bool called = false; |
| 471 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 472 |
| 473 // Allow the PasswordFormManager to talk to the password store, determine |
| 474 // that the form is new, and set it as pending. |
| 475 RunAllPendingTasks(); |
| 476 |
| 477 EXPECT_TRUE(called); |
| 478 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); |
| 479 client_->pending_manager()->Save(); |
| 480 |
| 481 RunAllPendingTasks(); |
| 482 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 483 EXPECT_THAT(passwords["https://example.com/"], ElementsAre(form_)); |
| 484 federated.date_created = |
| 485 passwords["federation://example.com/google.com"][0].date_created; |
| 486 EXPECT_THAT(passwords["federation://example.com/google.com"], |
| 487 ElementsAre(federated)); |
| 488 } |
| 489 |
| 454 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { | 490 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { |
| 455 // Populate the PasswordStore with a form. | 491 // Populate the PasswordStore with a form. |
| 456 store_->AddLogin(form_); | 492 store_->AddLogin(form_); |
| 457 RunAllPendingTasks(); | 493 RunAllPendingTasks(); |
| 458 | 494 |
| 459 // Calling 'Store' with a credential that matches |form_| should update | 495 // Calling 'Store' with a credential that matches |form_| should update |
| 460 // the password without prompting the user. | 496 // the password without prompting the user. |
| 461 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 497 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 462 info.password = base::ASCIIToUTF16("Totally new password."); | 498 info.password = base::ASCIIToUTF16("Totally new password."); |
| 463 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); | 499 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1373 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1409 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1374 CallStore(info, base::Bind(&RespondCallback, &called)); | 1410 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1375 // Allow the PasswordFormManager to talk to the password store | 1411 // Allow the PasswordFormManager to talk to the password store |
| 1376 RunAllPendingTasks(); | 1412 RunAllPendingTasks(); |
| 1377 | 1413 |
| 1378 ASSERT_TRUE(client_->pending_manager()); | 1414 ASSERT_TRUE(client_->pending_manager()); |
| 1379 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1415 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1380 } | 1416 } |
| 1381 | 1417 |
| 1382 } // namespace password_manager | 1418 } // namespace password_manager |
| OLD | NEW |