Chromium Code Reviews| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 EXPECT_EQ(form_.display_name, new_form.display_name); | 444 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 444 EXPECT_EQ(form_.password_value, new_form.password_value); | 445 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 445 EXPECT_EQ(form_.origin, new_form.origin); | 446 EXPECT_EQ(form_.origin, new_form.origin); |
| 446 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); | 447 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 447 EXPECT_EQ(form_.federation_origin, new_form.federation_origin); | 448 EXPECT_EQ(form_.federation_origin, new_form.federation_origin); |
| 448 EXPECT_EQ(form_.icon_url, new_form.icon_url); | 449 EXPECT_EQ(form_.icon_url, new_form.icon_url); |
| 449 EXPECT_FALSE(form_.skip_zero_click); | 450 EXPECT_FALSE(form_.skip_zero_click); |
| 450 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); | 451 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 451 } | 452 } |
| 452 | 453 |
| 454 TEST_F(CredentialManagerImplTest, StoreFederatedAfterPassword) { | |
| 455 // Populate the PasswordStore with a form. | |
| 456 store_->AddLogin(form_); | |
| 457 | |
| 458 autofill::PasswordForm federated = form_; | |
| 459 federated.password_value.clear(); | |
| 460 federated.type = autofill::PasswordForm::TYPE_API; | |
| 461 federated.preferred = true; | |
| 462 federated.federation_origin = url::Origin(GURL("https://google.com/")); | |
| 463 federated.signon_realm = "federation://example.com/google.com"; | |
| 464 CredentialInfo info(federated, CredentialType::CREDENTIAL_TYPE_FEDERATED); | |
| 465 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | |
| 466 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | |
| 467 EXPECT_CALL(*client_, NotifyStorePasswordCalled()); | |
| 468 | |
| 469 bool called = false; | |
| 470 CallStore(info, base::Bind(&RespondCallback, &called)); | |
| 471 | |
| 472 // Allow the PasswordFormManager to talk to the password store, determine | |
|
vabr (Chromium)
2016/10/13 07:59:43
Just wanted to say that this is a very well writte
vasilii
2016/10/13 13:59:37
written by Mike, I just copy pasted. Kudos to me t
vabr (Chromium)
2016/10/13 14:04:25
:D
| |
| 473 // that the form is new, and set it as pending. | |
| 474 RunAllPendingTasks(); | |
| 475 | |
| 476 EXPECT_TRUE(called); | |
| 477 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); | |
| 478 client_->pending_manager()->Save(); | |
| 479 | |
| 480 RunAllPendingTasks(); | |
| 481 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | |
| 482 EXPECT_THAT(passwords["https://example.com/"], ElementsAre(form_)); | |
| 483 federated.date_created = | |
| 484 passwords["federation://example.com/google.com"][0].date_created; | |
| 485 EXPECT_THAT(passwords["federation://example.com/google.com"], | |
| 486 ElementsAre(federated)); | |
| 487 } | |
| 488 | |
| 453 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { | 489 TEST_F(CredentialManagerImplTest, CredentialManagerStoreOverwrite) { |
| 454 // Populate the PasswordStore with a form. | 490 // Populate the PasswordStore with a form. |
| 455 store_->AddLogin(form_); | 491 store_->AddLogin(form_); |
| 456 RunAllPendingTasks(); | 492 RunAllPendingTasks(); |
| 457 | 493 |
| 458 // Calling 'Store' with a credential that matches |form_| should update | 494 // Calling 'Store' with a credential that matches |form_| should update |
| 459 // the password without prompting the user. | 495 // the password without prompting the user. |
| 460 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 496 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 461 info.password = base::ASCIIToUTF16("Totally new password."); | 497 info.password = base::ASCIIToUTF16("Totally new password."); |
| 462 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); | 498 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_, _)).Times(0); |
| (...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1372 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1408 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1373 CallStore(info, base::Bind(&RespondCallback, &called)); | 1409 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1374 // Allow the PasswordFormManager to talk to the password store | 1410 // Allow the PasswordFormManager to talk to the password store |
| 1375 RunAllPendingTasks(); | 1411 RunAllPendingTasks(); |
| 1376 | 1412 |
| 1377 ASSERT_TRUE(client_->pending_manager()); | 1413 ASSERT_TRUE(client_->pending_manager()); |
| 1378 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1414 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1379 } | 1415 } |
| 1380 | 1416 |
| 1381 } // namespace password_manager | 1417 } // namespace password_manager |
| OLD | NEW |