| 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 "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&)> callback) | 55 base::Callback<void(const password_manager::CredentialInfo&)> callback) |
| 56 override { | 56 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, | 71 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 66 base::Bind(callback, info)); | 72 base::Bind(callback, 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); | 179 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); |
| 174 | 180 |
| 175 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | 181 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
| 176 const IPC::Message* message = | 182 const IPC::Message* message = |
| 177 process()->sink().GetFirstMessageMatching(kMsgID); | 183 process()->sink().GetFirstMessageMatching(kMsgID); |
| 178 EXPECT_TRUE(message); | 184 EXPECT_TRUE(message); |
| 179 process()->sink().ClearMessages(); | 185 process()->sink().ClearMessages(); |
| 180 } | 186 } |
| 181 | 187 |
| 182 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { | 188 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { |
| 183 CredentialInfo info(form_); | 189 CredentialInfo info(form_, |
| 190 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
| 184 dispatcher()->OnNotifySignedIn(kRequestId, info); | 191 dispatcher()->OnNotifySignedIn(kRequestId, info); |
| 185 | 192 |
| 186 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | 193 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; |
| 187 const IPC::Message* message = | 194 const IPC::Message* message = |
| 188 process()->sink().GetFirstMessageMatching(kMsgID); | 195 process()->sink().GetFirstMessageMatching(kMsgID); |
| 189 EXPECT_TRUE(message); | 196 EXPECT_TRUE(message); |
| 190 process()->sink().ClearMessages(); | 197 process()->sink().ClearMessages(); |
| 191 | 198 |
| 192 // Allow the PasswordFormManager to talk to the password store, determine | 199 // Allow the PasswordFormManager to talk to the password store, determine |
| 193 // that the form is new, and set it as pending. | 200 // that the form is new, and set it as pending. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 message = process()->sink().GetFirstMessageMatching(kMsgID); | 306 message = process()->sink().GetFirstMessageMatching(kMsgID); |
| 300 EXPECT_TRUE(message); | 307 EXPECT_TRUE(message); |
| 301 CredentialManagerMsg_SendCredential::Param send_param; | 308 CredentialManagerMsg_SendCredential::Param send_param; |
| 302 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 309 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 303 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 310 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 304 process()->sink().ClearMessages(); | 311 process()->sink().ClearMessages(); |
| 305 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | 312 EXPECT_TRUE(client_->did_prompt_user_to_choose()); |
| 306 } | 313 } |
| 307 | 314 |
| 308 } // namespace password_manager | 315 } // namespace password_manager |
| OLD | NEW |