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_dispatc
her.h" | 5 #include "components/password_manager/content/browser/credential_manager_dispatc
her.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
13 #include "base/prefs/testing_pref_service.h" | 13 #include "base/prefs/testing_pref_service.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "components/password_manager/content/common/credential_manager_messages
.h" | 18 #include "components/password_manager/content/common/credential_manager_messages
.h" |
19 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" | 19 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" |
| 20 #include "components/password_manager/core/browser/dummy_log_manager.h" |
20 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" | 21 #include "components/password_manager/core/browser/mock_affiliated_match_helper.
h" |
21 #include "components/password_manager/core/browser/password_manager.h" | |
22 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 22 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
23 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" | 23 #include "components/password_manager/core/browser/stub_password_manager_driver.
h" |
24 #include "components/password_manager/core/browser/test_password_store.h" | 24 #include "components/password_manager/core/browser/test_password_store.h" |
25 #include "components/password_manager/core/common/credential_manager_types.h" | 25 #include "components/password_manager/core/common/credential_manager_types.h" |
26 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/mock_render_process_host.h" | 28 #include "content/public/test/mock_render_process_host.h" |
29 #include "content/public/test/test_renderer_host.h" | 29 #include "content/public/test/test_renderer_host.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 21 matching lines...) Expand all Loading... |
53 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 53 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
54 MOCK_METHOD1(NotifyUserAutoSigninPtr, | 54 MOCK_METHOD1(NotifyUserAutoSigninPtr, |
55 bool(const std::vector<autofill::PasswordForm*>& local_forms)); | 55 bool(const std::vector<autofill::PasswordForm*>& local_forms)); |
56 MOCK_METHOD2(PromptUserToSavePasswordPtr, | 56 MOCK_METHOD2(PromptUserToSavePasswordPtr, |
57 void(PasswordFormManager*, CredentialSourceType type)); | 57 void(PasswordFormManager*, CredentialSourceType type)); |
58 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, | 58 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, |
59 bool(const std::vector<autofill::PasswordForm*>& local_forms, | 59 bool(const std::vector<autofill::PasswordForm*>& local_forms, |
60 const std::vector<autofill::PasswordForm*>& federated_forms, | 60 const std::vector<autofill::PasswordForm*>& federated_forms, |
61 const GURL& origin, | 61 const GURL& origin, |
62 base::Callback<void(const CredentialInfo&)> callback)); | 62 base::Callback<void(const CredentialInfo&)> callback)); |
| 63 MOCK_CONST_METHOD0(GetLogManager, const LogManager*()); |
63 | 64 |
64 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { | 65 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { |
65 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerAutoSignin, | 66 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerAutoSignin, |
66 true); | 67 true); |
67 } | 68 } |
68 ~MockPasswordManagerClient() override {} | 69 ~MockPasswordManagerClient() override {} |
69 | 70 |
70 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager, | 71 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager, |
71 CredentialSourceType type, | 72 CredentialSourceType type, |
72 bool update_password) override { | 73 bool update_password) override { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 PasswordManagerClient* client, | 134 PasswordManagerClient* client, |
134 PasswordManagerDriver* driver) | 135 PasswordManagerDriver* driver) |
135 : CredentialManagerDispatcher(web_contents, client), | 136 : CredentialManagerDispatcher(web_contents, client), |
136 driver_(driver->AsWeakPtr()) {} | 137 driver_(driver->AsWeakPtr()) {} |
137 | 138 |
138 base::WeakPtr<PasswordManagerDriver> | 139 base::WeakPtr<PasswordManagerDriver> |
139 TestCredentialManagerDispatcher::GetDriver() { | 140 TestCredentialManagerDispatcher::GetDriver() { |
140 return driver_; | 141 return driver_; |
141 } | 142 } |
142 | 143 |
143 class MockPasswordManagerDriver : public StubPasswordManagerDriver { | |
144 public: | |
145 MOCK_METHOD0(GetPasswordManager, PasswordManager*()); | |
146 }; | |
147 | |
148 void RunAllPendingTasks() { | 144 void RunAllPendingTasks() { |
149 base::RunLoop run_loop; | 145 base::RunLoop run_loop; |
150 base::MessageLoop::current()->PostTask( | 146 base::MessageLoop::current()->PostTask( |
151 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 147 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
152 run_loop.Run(); | 148 run_loop.Run(); |
153 } | 149 } |
154 | 150 |
155 } // namespace | 151 } // namespace |
156 | 152 |
157 class CredentialManagerDispatcherTest | 153 class CredentialManagerDispatcherTest |
158 : public content::RenderViewHostTestHarness { | 154 : public content::RenderViewHostTestHarness { |
159 public: | 155 public: |
160 CredentialManagerDispatcherTest() {} | 156 CredentialManagerDispatcherTest() {} |
161 | 157 |
162 void SetUp() override { | 158 void SetUp() override { |
163 content::RenderViewHostTestHarness::SetUp(); | 159 content::RenderViewHostTestHarness::SetUp(); |
164 store_ = new TestPasswordStore; | 160 store_ = new TestPasswordStore; |
165 client_.reset(new MockPasswordManagerClient(store_.get())); | 161 client_.reset(new MockPasswordManagerClient(store_.get())); |
166 password_manager_.reset(new PasswordManager(client_.get())); | 162 ON_CALL(*client_, GetLogManager()) |
167 ON_CALL(mock_driver_, GetPasswordManager()) | 163 .WillByDefault(testing::Return(&log_manager_)); |
168 .WillByDefault(testing::Return(password_manager_.get())); | |
169 dispatcher_.reset(new TestCredentialManagerDispatcher( | 164 dispatcher_.reset(new TestCredentialManagerDispatcher( |
170 web_contents(), client_.get(), &mock_driver_)); | 165 web_contents(), client_.get(), &stub_driver_)); |
171 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 166 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
172 .WillByDefault(testing::Return(true)); | 167 .WillByDefault(testing::Return(true)); |
173 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); | 168 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); |
174 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) | 169 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) |
175 .WillByDefault(testing::Return(false)); | 170 .WillByDefault(testing::Return(false)); |
176 | 171 |
177 NavigateAndCommit(GURL("https://example.com/test.html")); | 172 NavigateAndCommit(GURL("https://example.com/test.html")); |
178 | 173 |
179 form_.username_value = base::ASCIIToUTF16("Username"); | 174 form_.username_value = base::ASCIIToUTF16("Username"); |
180 form_.display_name = base::ASCIIToUTF16("Display Name"); | 175 form_.display_name = base::ASCIIToUTF16("Display Name"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 264 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
270 | 265 |
271 protected: | 266 protected: |
272 autofill::PasswordForm form_; | 267 autofill::PasswordForm form_; |
273 autofill::PasswordForm affiliated_form1_; | 268 autofill::PasswordForm affiliated_form1_; |
274 autofill::PasswordForm affiliated_form2_; | 269 autofill::PasswordForm affiliated_form2_; |
275 autofill::PasswordForm origin_path_form_; | 270 autofill::PasswordForm origin_path_form_; |
276 autofill::PasswordForm cross_origin_form_; | 271 autofill::PasswordForm cross_origin_form_; |
277 scoped_refptr<TestPasswordStore> store_; | 272 scoped_refptr<TestPasswordStore> store_; |
278 scoped_ptr<MockPasswordManagerClient> client_; | 273 scoped_ptr<MockPasswordManagerClient> client_; |
279 MockPasswordManagerDriver mock_driver_; | 274 StubPasswordManagerDriver stub_driver_; |
280 scoped_ptr<CredentialManagerDispatcher> dispatcher_; | 275 scoped_ptr<CredentialManagerDispatcher> dispatcher_; |
281 scoped_ptr<PasswordManager> password_manager_; | 276 DummyLogManager log_manager_; |
282 }; | 277 }; |
283 | 278 |
284 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStore) { | 279 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnStore) { |
285 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 280 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
286 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 281 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
287 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 282 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
288 .Times(testing::Exactly(1)); | 283 .Times(testing::Exactly(1)); |
289 | 284 |
290 dispatcher()->OnStore(kRequestId, info); | 285 dispatcher()->OnStore(kRequestId, info); |
291 | 286 |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { | 789 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { |
795 autofill::PasswordForm synthesized = | 790 autofill::PasswordForm synthesized = |
796 dispatcher_->GetSynthesizedFormForOrigin(); | 791 dispatcher_->GetSynthesizedFormForOrigin(); |
797 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); | 792 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); |
798 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); | 793 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); |
799 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); | 794 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); |
800 EXPECT_TRUE(synthesized.ssl_valid); | 795 EXPECT_TRUE(synthesized.ssl_valid); |
801 } | 796 } |
802 | 797 |
803 } // namespace password_manager | 798 } // namespace password_manager |
OLD | NEW |