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/content_credential_manager
_dispatcher.h" | 5 #include "components/password_manager/content/browser/content_credential_manager
_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 did_prompt_user_to_save_ = true; | 47 did_prompt_user_to_save_ = true; |
48 manager_.reset(manager.release()); | 48 manager_.reset(manager.release()); |
49 return true; | 49 return true; |
50 } | 50 } |
51 | 51 |
52 bool PromptUserToChooseCredentials( | 52 bool PromptUserToChooseCredentials( |
53 const std::vector<autofill::PasswordForm*>& local_forms, | 53 const std::vector<autofill::PasswordForm*>& local_forms, |
54 const std::vector<autofill::PasswordForm*>& federated_forms, | 54 const std::vector<autofill::PasswordForm*>& federated_forms, |
55 base::Callback<void(const password_manager::CredentialInfo&)> | 55 base::Callback<void(const password_manager::CredentialInfo&)> |
56 callback) override { | 56 callback) override { |
| 57 // TODO(melandory): Use ScopedVector instead of std::vector in arguments. |
| 58 // ContentCredentialManagerDispatcher::OnGetPasswordStoreResults contains a |
| 59 // memory leak because of this. |
57 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); | 60 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); |
58 did_prompt_user_to_choose_ = true; | 61 did_prompt_user_to_choose_ = true; |
59 ScopedVector<autofill::PasswordForm> local_entries; | 62 ScopedVector<autofill::PasswordForm> local_entries; |
60 local_entries.assign(local_forms.begin(), local_forms.end()); | 63 local_entries.assign(local_forms.begin(), local_forms.end()); |
61 ScopedVector<autofill::PasswordForm> federated_entries; | 64 ScopedVector<autofill::PasswordForm> federated_entries; |
62 federated_entries.assign(federated_forms.begin(), federated_forms.end()); | 65 federated_entries.assign(federated_forms.begin(), federated_forms.end()); |
63 // TODO(vasilii): Do something clever with |federated_forms|. | 66 password_manager::CredentialInfo info( |
64 password_manager::CredentialInfo info(*local_entries[0]); | 67 local_forms.empty() ? *federated_forms[0] : *local_entries[0], |
| 68 local_forms.empty() |
| 69 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED |
| 70 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
65 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, | 71 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, |
66 info)); | 72 info)); |
67 return true; | 73 return true; |
68 } | 74 } |
69 | 75 |
70 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } | 76 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } |
71 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } | 77 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } |
72 | 78 |
73 password_manager::PasswordFormManager* pending_manager() const { | 79 password_manager::PasswordFormManager* pending_manager() const { |
74 return manager_.get(); | 80 return manager_.get(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 183 |
178 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | 184 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
179 const IPC::Message* message = | 185 const IPC::Message* message = |
180 process()->sink().GetFirstMessageMatching(kMsgID); | 186 process()->sink().GetFirstMessageMatching(kMsgID); |
181 EXPECT_TRUE(message); | 187 EXPECT_TRUE(message); |
182 process()->sink().ClearMessages(); | 188 process()->sink().ClearMessages(); |
183 } | 189 } |
184 | 190 |
185 TEST_F(ContentCredentialManagerDispatcherTest, | 191 TEST_F(ContentCredentialManagerDispatcherTest, |
186 CredentialManagerOnNotifySignedIn) { | 192 CredentialManagerOnNotifySignedIn) { |
187 CredentialInfo info(form_); | 193 CredentialInfo info(form_, |
| 194 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
188 dispatcher()->OnNotifySignedIn(kRequestId, info); | 195 dispatcher()->OnNotifySignedIn(kRequestId, info); |
189 | 196 |
190 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | 197 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; |
191 const IPC::Message* message = | 198 const IPC::Message* message = |
192 process()->sink().GetFirstMessageMatching(kMsgID); | 199 process()->sink().GetFirstMessageMatching(kMsgID); |
193 EXPECT_TRUE(message); | 200 EXPECT_TRUE(message); |
194 process()->sink().ClearMessages(); | 201 process()->sink().ClearMessages(); |
195 | 202 |
196 // Allow the PasswordFormManager to talk to the password store, determine | 203 // Allow the PasswordFormManager to talk to the password store, determine |
197 // that the form is new, and set it as pending. | 204 // that the form is new, and set it as pending. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 message = process()->sink().GetFirstMessageMatching(kMsgID); | 311 message = process()->sink().GetFirstMessageMatching(kMsgID); |
305 EXPECT_TRUE(message); | 312 EXPECT_TRUE(message); |
306 CredentialManagerMsg_SendCredential::Param send_param; | 313 CredentialManagerMsg_SendCredential::Param send_param; |
307 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 314 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
308 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 315 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
309 process()->sink().ClearMessages(); | 316 process()->sink().ClearMessages(); |
310 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | 317 EXPECT_TRUE(client_->did_prompt_user_to_choose()); |
311 } | 318 } |
312 | 319 |
313 } // namespace password_manager | 320 } // namespace password_manager |
OLD | NEW |