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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/password_manager/core/browser/password_form_manager.h" | 10 #include "components/password_manager/core/browser/password_form_manager.h" |
11 #include "components/password_manager/core/browser/password_manager.h" | 11 #include "components/password_manager/core/browser/password_manager.h" |
| 12 #include "components/password_manager/core/browser/stub_log_manager.h" |
12 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
13 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 14 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
14 #include "components/password_manager/core/common/credential_manager_types.h" | 15 #include "components/password_manager/core/common/credential_manager_types.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 using ::testing::_; | 19 using ::testing::_; |
19 using ::testing::Contains; | 20 using ::testing::Contains; |
20 using ::testing::ElementsAre; | 21 using ::testing::ElementsAre; |
21 using ::testing::IsEmpty; | 22 using ::testing::IsEmpty; |
22 using ::testing::Not; | 23 using ::testing::Not; |
23 using ::testing::Pointee; | 24 using ::testing::Pointee; |
24 using ::testing::UnorderedElementsAre; | 25 using ::testing::UnorderedElementsAre; |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 class MockPasswordManagerClient | 29 class MockPasswordManagerClient |
29 : public password_manager::StubPasswordManagerClient { | 30 : public password_manager::StubPasswordManagerClient { |
30 public: | 31 public: |
31 MOCK_CONST_METHOD0(GetPasswordManager, | 32 MockPasswordManagerClient() = default; |
32 const password_manager::PasswordManager*()); | 33 ~MockPasswordManagerClient() override = default; |
| 34 |
| 35 MOCK_CONST_METHOD0(GetLogManager, const password_manager::LogManager*()); |
| 36 |
| 37 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); |
33 }; | 39 }; |
34 | 40 |
35 class ManagePasswordsStateTest : public testing::Test { | 41 class ManagePasswordsStateTest : public testing::Test { |
36 public: | 42 public: |
37 ManagePasswordsStateTest() : password_manager_(&mock_client_) {} | 43 ManagePasswordsStateTest() : password_manager_(&mock_client_) {} |
38 | 44 |
39 void SetUp() override { | 45 void SetUp() override { |
40 ON_CALL(mock_client_, GetPasswordManager()) | 46 ON_CALL(mock_client_, GetLogManager()) |
41 .WillByDefault(testing::Return(&password_manager_)); | 47 .WillByDefault(testing::Return(&log_manager_)); |
42 | 48 |
43 test_local_form_.origin = GURL("http://example.com"); | 49 test_local_form_.origin = GURL("http://example.com"); |
44 test_local_form_.username_value = base::ASCIIToUTF16("username"); | 50 test_local_form_.username_value = base::ASCIIToUTF16("username"); |
45 test_local_form_.password_value = base::ASCIIToUTF16("12345"); | 51 test_local_form_.password_value = base::ASCIIToUTF16("12345"); |
46 | 52 |
47 test_submitted_form_ = test_local_form_; | 53 test_submitted_form_ = test_local_form_; |
48 test_submitted_form_.username_value = base::ASCIIToUTF16("new one"); | 54 test_submitted_form_.username_value = base::ASCIIToUTF16("new one"); |
49 test_submitted_form_.password_value = base::ASCIIToUTF16("asdfjkl;"); | 55 test_submitted_form_.password_value = base::ASCIIToUTF16("asdfjkl;"); |
50 | 56 |
51 test_federated_form_.origin = GURL("https://idp.com"); | 57 test_federated_form_.origin = GURL("https://idp.com"); |
(...skipping 17 matching lines...) Expand all Loading... |
69 // Pushes both relevant and irrelevant updates to |passwords_data_|. | 75 // Pushes both relevant and irrelevant updates to |passwords_data_|. |
70 void TestAllUpdates(); | 76 void TestAllUpdates(); |
71 | 77 |
72 // Pushes a blacklisted form and checks that it doesn't affect the state. | 78 // Pushes a blacklisted form and checks that it doesn't affect the state. |
73 void TestBlacklistedUpdates(); | 79 void TestBlacklistedUpdates(); |
74 | 80 |
75 MOCK_METHOD1(CredentialCallback, | 81 MOCK_METHOD1(CredentialCallback, |
76 void(const password_manager::CredentialInfo&)); | 82 void(const password_manager::CredentialInfo&)); |
77 | 83 |
78 private: | 84 private: |
| 85 password_manager::StubLogManager log_manager_; |
79 MockPasswordManagerClient mock_client_; | 86 MockPasswordManagerClient mock_client_; |
80 password_manager::StubPasswordManagerDriver driver_; | 87 password_manager::StubPasswordManagerDriver driver_; |
81 password_manager::PasswordManager password_manager_; | 88 password_manager::PasswordManager password_manager_; |
82 | 89 |
83 ManagePasswordsState passwords_data_; | 90 ManagePasswordsState passwords_data_; |
84 autofill::PasswordForm test_local_form_; | 91 autofill::PasswordForm test_local_form_; |
85 autofill::PasswordForm test_submitted_form_; | 92 autofill::PasswordForm test_submitted_form_; |
86 autofill::PasswordForm test_federated_form_; | 93 autofill::PasswordForm test_federated_form_; |
87 }; | 94 }; |
88 | 95 |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 passwords_data().set_credentials_callback(base::Bind( | 566 passwords_data().set_credentials_callback(base::Bind( |
560 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); | 567 &ManagePasswordsStateTest::CredentialCallback, base::Unretained(this))); |
561 password_manager::CredentialInfo credential_info( | 568 password_manager::CredentialInfo credential_info( |
562 form, password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); | 569 form, password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); |
563 EXPECT_CALL(*this, CredentialCallback(credential_info)); | 570 EXPECT_CALL(*this, CredentialCallback(credential_info)); |
564 passwords_data().ChooseCredential( | 571 passwords_data().ChooseCredential( |
565 form, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | 572 form, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
566 } | 573 } |
567 | 574 |
568 } // namespace | 575 } // namespace |
OLD | NEW |