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 "chrome/browser/ui/passwords/manage_passwords_state.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "components/password_manager/core/browser/password_form_manager.h" | 11 #include "components/password_manager/core/browser/password_form_manager.h" |
12 #include "components/password_manager/core/browser/password_manager.h" | 12 #include "components/password_manager/core/browser/password_manager.h" |
13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
14 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 14 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
15 #include "components/password_manager/core/common/credential_manager_types.h" | |
16 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
19 #include "url/origin.h" | 18 #include "url/origin.h" |
20 | 19 |
21 using ::testing::_; | 20 using ::testing::_; |
22 using ::testing::Contains; | 21 using ::testing::Contains; |
23 using ::testing::ElementsAre; | 22 using ::testing::ElementsAre; |
24 using ::testing::IsEmpty; | 23 using ::testing::IsEmpty; |
25 using ::testing::Not; | 24 using ::testing::Not; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // Pushes irrelevant updates to |passwords_data_| and checks that they don't | 76 // Pushes irrelevant updates to |passwords_data_| and checks that they don't |
78 // affect the state. | 77 // affect the state. |
79 void TestNoisyUpdates(); | 78 void TestNoisyUpdates(); |
80 | 79 |
81 // Pushes both relevant and irrelevant updates to |passwords_data_|. | 80 // Pushes both relevant and irrelevant updates to |passwords_data_|. |
82 void TestAllUpdates(); | 81 void TestAllUpdates(); |
83 | 82 |
84 // Pushes a blacklisted form and checks that it doesn't affect the state. | 83 // Pushes a blacklisted form and checks that it doesn't affect the state. |
85 void TestBlacklistedUpdates(); | 84 void TestBlacklistedUpdates(); |
86 | 85 |
87 MOCK_METHOD1(CredentialCallback, | 86 MOCK_METHOD1(CredentialCallback, void(const autofill::PasswordForm*)); |
88 void(const password_manager::CredentialInfo&)); | |
89 | 87 |
90 private: | 88 private: |
91 // Implements both CreateFormManager and CreateFormManagerWithFederation. | 89 // Implements both CreateFormManager and CreateFormManagerWithFederation. |
92 scoped_ptr<password_manager::PasswordFormManager> CreateFormManagerInternal( | 90 scoped_ptr<password_manager::PasswordFormManager> CreateFormManagerInternal( |
93 bool include_federated); | 91 bool include_federated); |
94 | 92 |
95 password_manager::StubPasswordManagerClient stub_client_; | 93 password_manager::StubPasswordManagerClient stub_client_; |
96 password_manager::StubPasswordManagerDriver driver_; | 94 password_manager::StubPasswordManagerDriver driver_; |
97 password_manager::PasswordManager password_manager_; | 95 password_manager::PasswordManager password_manager_; |
98 | 96 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); | 330 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); |
333 EXPECT_THAT(passwords_data().GetCurrentForms(), | 331 EXPECT_THAT(passwords_data().GetCurrentForms(), |
334 ElementsAre(Pointee(test_local_form()))); | 332 ElementsAre(Pointee(test_local_form()))); |
335 EXPECT_THAT(passwords_data().federated_credentials_forms(), | 333 EXPECT_THAT(passwords_data().federated_credentials_forms(), |
336 ElementsAre(Pointee(test_federated_form()))); | 334 ElementsAre(Pointee(test_federated_form()))); |
337 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, | 335 EXPECT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, |
338 passwords_data().state()); | 336 passwords_data().state()); |
339 EXPECT_EQ(origin, passwords_data().origin()); | 337 EXPECT_EQ(origin, passwords_data().origin()); |
340 TestAllUpdates(); | 338 TestAllUpdates(); |
341 | 339 |
342 password_manager::CredentialInfo credential_info( | 340 EXPECT_CALL(*this, CredentialCallback(nullptr)); |
343 test_local_form(), | |
344 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
345 EXPECT_CALL(*this, CredentialCallback(_)) | |
346 .WillOnce(testing::SaveArg<0>(&credential_info)); | |
347 passwords_data().TransitionToState(password_manager::ui::MANAGE_STATE); | 341 passwords_data().TransitionToState(password_manager::ui::MANAGE_STATE); |
348 EXPECT_EQ(password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY, | |
349 credential_info.type); | |
350 EXPECT_TRUE(passwords_data().credentials_callback().is_null()); | 342 EXPECT_TRUE(passwords_data().credentials_callback().is_null()); |
351 EXPECT_THAT(passwords_data().GetCurrentForms(), | 343 EXPECT_THAT(passwords_data().GetCurrentForms(), |
352 ElementsAre(Pointee(test_local_form()))); | 344 ElementsAre(Pointee(test_local_form()))); |
353 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); | 345 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); |
354 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); | 346 EXPECT_EQ(password_manager::ui::MANAGE_STATE, passwords_data().state()); |
355 EXPECT_EQ(origin, passwords_data().origin()); | 347 EXPECT_EQ(origin, passwords_data().origin()); |
356 TestAllUpdates(); | 348 TestAllUpdates(); |
357 } | 349 } |
358 | 350 |
359 TEST_F(ManagePasswordsStateTest, AutoSignin) { | 351 TEST_F(ManagePasswordsStateTest, AutoSignin) { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 Pointee(test_local_federated_form()))); | 647 Pointee(test_local_federated_form()))); |
656 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); | 648 EXPECT_THAT(passwords_data().federated_credentials_forms(), IsEmpty()); |
657 } | 649 } |
658 | 650 |
659 TEST_F(ManagePasswordsStateTest, ChooseCredentialLocal) { | 651 TEST_F(ManagePasswordsStateTest, ChooseCredentialLocal) { |
660 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), | 652 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), |
661 ScopedVector<autofill::PasswordForm>(), | 653 ScopedVector<autofill::PasswordForm>(), |
662 test_local_form().origin); | 654 test_local_form().origin); |
663 passwords_data().set_credentials_callback(base::Bind( | 655 passwords_data().set_credentials_callback(base::Bind( |
664 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); | 656 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); |
665 password_manager::CredentialInfo credential_info( | 657 EXPECT_CALL(*this, CredentialCallback(&test_local_form())); |
666 test_local_form(), | 658 passwords_data().ChooseCredential(&test_local_form()); |
667 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
668 EXPECT_CALL(*this, CredentialCallback(credential_info)); | |
669 passwords_data().ChooseCredential( | |
670 test_local_form(), | |
671 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
672 } | 659 } |
673 | 660 |
674 TEST_F(ManagePasswordsStateTest, ChooseCredentialFederated) { | 661 TEST_F(ManagePasswordsStateTest, ChooseCredentialEmpty) { |
675 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), | 662 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), |
676 ScopedVector<autofill::PasswordForm>(), | 663 ScopedVector<autofill::PasswordForm>(), |
677 test_local_form().origin); | 664 test_local_form().origin); |
678 passwords_data().set_credentials_callback(base::Bind( | 665 passwords_data().set_credentials_callback(base::Bind( |
679 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); | 666 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); |
680 password_manager::CredentialInfo credential_info( | 667 password_manager::CredentialInfo credential_info( |
681 test_federated_form(), | 668 test_federated_form(), |
682 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); | |
683 EXPECT_CALL(*this, CredentialCallback(credential_info)); | |
684 passwords_data().ChooseCredential( | |
685 test_federated_form(), | |
686 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); | |
687 } | |
688 | |
689 TEST_F(ManagePasswordsStateTest, ChooseCredentialEmpty) { | |
690 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), | |
691 ScopedVector<autofill::PasswordForm>(), | |
692 test_local_form().origin); | |
693 autofill::PasswordForm password_form(test_local_form()); | |
694 passwords_data().set_credentials_callback(base::Bind( | |
695 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); | |
696 password_manager::CredentialInfo credential_info( | |
697 test_federated_form(), | |
698 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); | 669 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); |
699 EXPECT_CALL(*this, CredentialCallback(credential_info)); | 670 EXPECT_CALL(*this, CredentialCallback(nullptr)); |
700 passwords_data().ChooseCredential( | 671 passwords_data().ChooseCredential(nullptr); |
701 test_federated_form(), | |
702 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); | |
703 } | 672 } |
704 | 673 |
705 TEST_F(ManagePasswordsStateTest, ChooseCredentialLocalWithNonEmptyFederation) { | 674 TEST_F(ManagePasswordsStateTest, ChooseCredentialLocalWithNonEmptyFederation) { |
706 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), | 675 passwords_data().OnRequestCredentials(ScopedVector<autofill::PasswordForm>(), |
707 ScopedVector<autofill::PasswordForm>(), | 676 ScopedVector<autofill::PasswordForm>(), |
708 test_local_form().origin); | 677 test_local_form().origin); |
709 autofill::PasswordForm form(test_federated_form()); | |
710 form.federation_origin = url::Origin(GURL("https://federation.test/")); | |
711 passwords_data().set_credentials_callback(base::Bind( | 678 passwords_data().set_credentials_callback(base::Bind( |
712 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); | 679 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); |
713 password_manager::CredentialInfo credential_info( | 680 EXPECT_CALL(*this, CredentialCallback(&test_local_federated_form())); |
714 form, password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); | 681 passwords_data().ChooseCredential(&test_local_federated_form()); |
715 EXPECT_CALL(*this, CredentialCallback(credential_info)); | |
716 passwords_data().ChooseCredential( | |
717 form, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | |
718 } | 682 } |
719 | 683 |
720 } // namespace | 684 } // namespace |
OLD | NEW |