| 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/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 bool PromptUserToChooseCredentials( | 75 bool PromptUserToChooseCredentials( |
| 76 ScopedVector<autofill::PasswordForm> local_forms, | 76 ScopedVector<autofill::PasswordForm> local_forms, |
| 77 ScopedVector<autofill::PasswordForm> federated_forms, | 77 ScopedVector<autofill::PasswordForm> federated_forms, |
| 78 const GURL& origin, | 78 const GURL& origin, |
| 79 base::Callback<void(const password_manager::CredentialInfo&)> callback) { | 79 base::Callback<void(const password_manager::CredentialInfo&)> callback) { |
| 80 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); | 80 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); |
| 81 password_manager::CredentialInfo info( | 81 password_manager::CredentialInfo info( |
| 82 local_forms.empty() ? *federated_forms[0] : *local_forms[0], | 82 local_forms.empty() ? *federated_forms[0] : *local_forms[0], |
| 83 local_forms.empty() | 83 local_forms.empty() |
| 84 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED | 84 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED |
| 85 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 85 : password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 86 base::MessageLoop::current()->PostTask(FROM_HERE, | 86 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 87 base::Bind(callback, info)); | 87 base::Bind(callback, info)); |
| 88 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), | 88 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), |
| 89 origin, callback); | 89 origin, callback); |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void NotifyUserAutoSignin( | 93 void NotifyUserAutoSignin( |
| 94 ScopedVector<autofill::PasswordForm> local_forms) override { | 94 ScopedVector<autofill::PasswordForm> local_forms) override { |
| 95 EXPECT_FALSE(local_forms.empty()); | 95 EXPECT_FALSE(local_forms.empty()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 autofill::PasswordForm origin_path_form_; | 208 autofill::PasswordForm origin_path_form_; |
| 209 autofill::PasswordForm cross_origin_form_; | 209 autofill::PasswordForm cross_origin_form_; |
| 210 scoped_refptr<TestPasswordStore> store_; | 210 scoped_refptr<TestPasswordStore> store_; |
| 211 scoped_ptr<MockPasswordManagerClient> client_; | 211 scoped_ptr<MockPasswordManagerClient> client_; |
| 212 StubPasswordManagerDriver stub_driver_; | 212 StubPasswordManagerDriver stub_driver_; |
| 213 scoped_ptr<CredentialManagerDispatcher> dispatcher_; | 213 scoped_ptr<CredentialManagerDispatcher> dispatcher_; |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { | 216 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { |
| 217 CredentialInfo info; | 217 CredentialInfo info; |
| 218 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; | 218 info.type = CredentialType::CREDENTIAL_TYPE_PASSWORD; |
| 219 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); | 219 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); |
| 220 | 220 |
| 221 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | 221 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
| 222 const IPC::Message* message = | 222 const IPC::Message* message = |
| 223 process()->sink().GetFirstMessageMatching(kMsgID); | 223 process()->sink().GetFirstMessageMatching(kMsgID); |
| 224 EXPECT_TRUE(message); | 224 EXPECT_TRUE(message); |
| 225 process()->sink().ClearMessages(); | 225 process()->sink().ClearMessages(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { | 228 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { |
| 229 CredentialInfo info(form_, | 229 CredentialInfo info( |
| 230 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 230 form_, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 231 EXPECT_CALL( | 231 EXPECT_CALL( |
| 232 *client_, | 232 *client_, |
| 233 PromptUserToSavePasswordPtr( | 233 PromptUserToSavePasswordPtr( |
| 234 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) | 234 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 235 .Times(testing::Exactly(1)); | 235 .Times(testing::Exactly(1)); |
| 236 | 236 |
| 237 dispatcher()->OnNotifySignedIn(kRequestId, info); | 237 dispatcher()->OnNotifySignedIn(kRequestId, info); |
| 238 | 238 |
| 239 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | 239 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; |
| 240 const IPC::Message* message = | 240 const IPC::Message* message = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 253 EXPECT_EQ(form_.username_value, new_form.username_value); | 253 EXPECT_EQ(form_.username_value, new_form.username_value); |
| 254 EXPECT_EQ(form_.display_name, new_form.display_name); | 254 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 255 EXPECT_EQ(form_.password_value, new_form.password_value); | 255 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 256 EXPECT_EQ(form_.origin, new_form.origin); | 256 EXPECT_EQ(form_.origin, new_form.origin); |
| 257 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); | 257 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 258 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); | 258 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 259 } | 259 } |
| 260 | 260 |
| 261 TEST_F(CredentialManagerDispatcherTest, | 261 TEST_F(CredentialManagerDispatcherTest, |
| 262 CredentialManagerSignInWithSavingDisabledForCurrentPage) { | 262 CredentialManagerSignInWithSavingDisabledForCurrentPage) { |
| 263 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL); | 263 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 264 EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage()) | 264 EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage()) |
| 265 .WillRepeatedly(testing::Return(false)); | 265 .WillRepeatedly(testing::Return(false)); |
| 266 EXPECT_CALL( | 266 EXPECT_CALL( |
| 267 *client_, | 267 *client_, |
| 268 PromptUserToSavePasswordPtr( | 268 PromptUserToSavePasswordPtr( |
| 269 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) | 269 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 270 .Times(testing::Exactly(0)); | 270 .Times(testing::Exactly(0)); |
| 271 | 271 |
| 272 dispatcher()->OnNotifySignedIn(kRequestId, info); | 272 dispatcher()->OnNotifySignedIn(kRequestId, info); |
| 273 | 273 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 419 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 420 | 420 |
| 421 RunAllPendingTasks(); | 421 RunAllPendingTasks(); |
| 422 | 422 |
| 423 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 423 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 424 const IPC::Message* message = | 424 const IPC::Message* message = |
| 425 process()->sink().GetFirstMessageMatching(kMsgID); | 425 process()->sink().GetFirstMessageMatching(kMsgID); |
| 426 EXPECT_TRUE(message); | 426 EXPECT_TRUE(message); |
| 427 CredentialManagerMsg_SendCredential::Param send_param; | 427 CredentialManagerMsg_SendCredential::Param send_param; |
| 428 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 428 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 429 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, | 429 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD, |
| 430 base::get<1>(send_param).type); | 430 base::get<1>(send_param).type); |
| 431 } | 431 } |
| 432 | 432 |
| 433 TEST_F(CredentialManagerDispatcherTest, | 433 TEST_F(CredentialManagerDispatcherTest, |
| 434 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | 434 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { |
| 435 store_->AddLogin(form_); | 435 store_->AddLogin(form_); |
| 436 store_->AddLogin(origin_path_form_); | 436 store_->AddLogin(origin_path_form_); |
| 437 | 437 |
| 438 std::vector<GURL> federations; | 438 std::vector<GURL> federations; |
| 439 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | 439 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 473 |
| 474 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 474 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 475 const IPC::Message* message = | 475 const IPC::Message* message = |
| 476 process()->sink().GetFirstMessageMatching(kMsgID); | 476 process()->sink().GetFirstMessageMatching(kMsgID); |
| 477 EXPECT_TRUE(message); | 477 EXPECT_TRUE(message); |
| 478 CredentialManagerMsg_SendCredential::Param send_param; | 478 CredentialManagerMsg_SendCredential::Param send_param; |
| 479 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 479 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 480 | 480 |
| 481 // We should get |origin_path_form_| back, as |form_| is marked as skipping | 481 // We should get |origin_path_form_| back, as |form_| is marked as skipping |
| 482 // zero-click. | 482 // zero-click. |
| 483 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, | 483 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD, |
| 484 base::get<1>(send_param).type); | 484 base::get<1>(send_param).type); |
| 485 EXPECT_EQ(origin_path_form_.username_value, base::get<1>(send_param).id); | 485 EXPECT_EQ(origin_path_form_.username_value, base::get<1>(send_param).id); |
| 486 EXPECT_EQ(origin_path_form_.display_name, base::get<1>(send_param).name); | 486 EXPECT_EQ(origin_path_form_.display_name, base::get<1>(send_param).name); |
| 487 EXPECT_EQ(origin_path_form_.password_value, | 487 EXPECT_EQ(origin_path_form_.password_value, |
| 488 base::get<1>(send_param).password); | 488 base::get<1>(send_param).password); |
| 489 } | 489 } |
| 490 | 490 |
| 491 TEST_F(CredentialManagerDispatcherTest, | 491 TEST_F(CredentialManagerDispatcherTest, |
| 492 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { | 492 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { |
| 493 store_->AddLogin(cross_origin_form_); | 493 store_->AddLogin(cross_origin_form_); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 620 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 621 const IPC::Message* message = | 621 const IPC::Message* message = |
| 622 process()->sink().GetFirstMessageMatching(kMsgID); | 622 process()->sink().GetFirstMessageMatching(kMsgID); |
| 623 ASSERT_TRUE(message); | 623 ASSERT_TRUE(message); |
| 624 CredentialManagerMsg_SendCredential::Param param; | 624 CredentialManagerMsg_SendCredential::Param param; |
| 625 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 625 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 626 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type); | 626 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type); |
| 627 } | 627 } |
| 628 | 628 |
| 629 } // namespace password_manager | 629 } // namespace password_manager |
| OLD | NEW |