Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1441)

Side by Side Diff: components/password_manager/content/browser/credential_manager_dispatcher_unittest.cc

Issue 1162583003: Credential Management: Rename 'LocalCredential' to 'PasswordCredential' (2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@drop
Patch Set: Fix. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 bool PromptUserToChooseCredentials( 76 bool PromptUserToChooseCredentials(
77 ScopedVector<autofill::PasswordForm> local_forms, 77 ScopedVector<autofill::PasswordForm> local_forms,
78 ScopedVector<autofill::PasswordForm> federated_forms, 78 ScopedVector<autofill::PasswordForm> federated_forms,
79 const GURL& origin, 79 const GURL& origin,
80 base::Callback<void(const password_manager::CredentialInfo&)> callback) { 80 base::Callback<void(const password_manager::CredentialInfo&)> callback) {
81 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); 81 EXPECT_FALSE(local_forms.empty() && federated_forms.empty());
82 password_manager::CredentialInfo info( 82 password_manager::CredentialInfo info(
83 local_forms.empty() ? *federated_forms[0] : *local_forms[0], 83 local_forms.empty() ? *federated_forms[0] : *local_forms[0],
84 local_forms.empty() 84 local_forms.empty()
85 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED 85 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED
86 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); 86 : password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
88 base::Bind(callback, info)); 88 base::Bind(callback, info));
89 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), 89 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(),
90 origin, callback); 90 origin, callback);
91 return true; 91 return true;
92 } 92 }
93 93
94 void NotifyUserAutoSignin( 94 void NotifyUserAutoSignin(
95 ScopedVector<autofill::PasswordForm> local_forms) override { 95 ScopedVector<autofill::PasswordForm> local_forms) override {
96 EXPECT_FALSE(local_forms.empty()); 96 EXPECT_FALSE(local_forms.empty());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 autofill::PasswordForm origin_path_form_; 209 autofill::PasswordForm origin_path_form_;
210 autofill::PasswordForm cross_origin_form_; 210 autofill::PasswordForm cross_origin_form_;
211 scoped_refptr<TestPasswordStore> store_; 211 scoped_refptr<TestPasswordStore> store_;
212 scoped_ptr<MockPasswordManagerClient> client_; 212 scoped_ptr<MockPasswordManagerClient> client_;
213 StubPasswordManagerDriver stub_driver_; 213 StubPasswordManagerDriver stub_driver_;
214 scoped_ptr<CredentialManagerDispatcher> dispatcher_; 214 scoped_ptr<CredentialManagerDispatcher> dispatcher_;
215 }; 215 };
216 216
217 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { 217 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) {
218 CredentialInfo info; 218 CredentialInfo info;
219 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; 219 info.type = CredentialType::CREDENTIAL_TYPE_PASSWORD;
220 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); 220 dispatcher()->OnNotifyFailedSignIn(kRequestId, info);
221 221
222 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; 222 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID;
223 const IPC::Message* message = 223 const IPC::Message* message =
224 process()->sink().GetFirstMessageMatching(kMsgID); 224 process()->sink().GetFirstMessageMatching(kMsgID);
225 EXPECT_TRUE(message); 225 EXPECT_TRUE(message);
226 process()->sink().ClearMessages(); 226 process()->sink().ClearMessages();
227 } 227 }
228 228
229 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { 229 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) {
230 CredentialInfo info(form_, 230 CredentialInfo info(
231 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); 231 form_, password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
232 EXPECT_CALL( 232 EXPECT_CALL(
233 *client_, 233 *client_,
234 PromptUserToSavePasswordPtr( 234 PromptUserToSavePasswordPtr(
235 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) 235 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
236 .Times(testing::Exactly(1)); 236 .Times(testing::Exactly(1));
237 237
238 dispatcher()->OnNotifySignedIn(kRequestId, info); 238 dispatcher()->OnNotifySignedIn(kRequestId, info);
239 239
240 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; 240 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID;
241 const IPC::Message* message = 241 const IPC::Message* message =
(...skipping 12 matching lines...) Expand all
254 EXPECT_EQ(form_.username_value, new_form.username_value); 254 EXPECT_EQ(form_.username_value, new_form.username_value);
255 EXPECT_EQ(form_.display_name, new_form.display_name); 255 EXPECT_EQ(form_.display_name, new_form.display_name);
256 EXPECT_EQ(form_.password_value, new_form.password_value); 256 EXPECT_EQ(form_.password_value, new_form.password_value);
257 EXPECT_EQ(form_.origin, new_form.origin); 257 EXPECT_EQ(form_.origin, new_form.origin);
258 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); 258 EXPECT_EQ(form_.signon_realm, new_form.signon_realm);
259 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); 259 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme);
260 } 260 }
261 261
262 TEST_F(CredentialManagerDispatcherTest, 262 TEST_F(CredentialManagerDispatcherTest,
263 CredentialManagerSignInWithSavingDisabledForCurrentPage) { 263 CredentialManagerSignInWithSavingDisabledForCurrentPage) {
264 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL); 264 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD);
265 EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage()) 265 EXPECT_CALL(*client_, IsSavingEnabledForCurrentPage())
266 .WillRepeatedly(testing::Return(false)); 266 .WillRepeatedly(testing::Return(false));
267 EXPECT_CALL( 267 EXPECT_CALL(
268 *client_, 268 *client_,
269 PromptUserToSavePasswordPtr( 269 PromptUserToSavePasswordPtr(
270 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) 270 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API))
271 .Times(testing::Exactly(0)); 271 .Times(testing::Exactly(0));
272 272
273 dispatcher()->OnNotifySignedIn(kRequestId, info); 273 dispatcher()->OnNotifySignedIn(kRequestId, info);
274 274
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 dispatcher()->OnRequestCredential(kRequestId, true, federations); 420 dispatcher()->OnRequestCredential(kRequestId, true, federations);
421 421
422 RunAllPendingTasks(); 422 RunAllPendingTasks();
423 423
424 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 424 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
425 const IPC::Message* message = 425 const IPC::Message* message =
426 process()->sink().GetFirstMessageMatching(kMsgID); 426 process()->sink().GetFirstMessageMatching(kMsgID);
427 EXPECT_TRUE(message); 427 EXPECT_TRUE(message);
428 CredentialManagerMsg_SendCredential::Param send_param; 428 CredentialManagerMsg_SendCredential::Param send_param;
429 CredentialManagerMsg_SendCredential::Read(message, &send_param); 429 CredentialManagerMsg_SendCredential::Read(message, &send_param);
430 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, 430 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD,
431 base::get<1>(send_param).type); 431 base::get<1>(send_param).type);
432 } 432 }
433 433
434 TEST_F(CredentialManagerDispatcherTest, 434 TEST_F(CredentialManagerDispatcherTest,
435 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { 435 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
436 store_->AddLogin(form_); 436 store_->AddLogin(form_);
437 store_->AddLogin(origin_path_form_); 437 store_->AddLogin(origin_path_form_);
438 438
439 std::vector<GURL> federations; 439 std::vector<GURL> federations;
440 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) 440 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _))
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 475 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
476 const IPC::Message* message = 476 const IPC::Message* message =
477 process()->sink().GetFirstMessageMatching(kMsgID); 477 process()->sink().GetFirstMessageMatching(kMsgID);
478 EXPECT_TRUE(message); 478 EXPECT_TRUE(message);
479 CredentialManagerMsg_SendCredential::Param send_param; 479 CredentialManagerMsg_SendCredential::Param send_param;
480 CredentialManagerMsg_SendCredential::Read(message, &send_param); 480 CredentialManagerMsg_SendCredential::Read(message, &send_param);
481 481
482 // We should get |origin_path_form_| back, as |form_| is marked as skipping 482 // We should get |origin_path_form_| back, as |form_| is marked as skipping
483 // zero-click. 483 // zero-click.
484 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, 484 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD,
485 base::get<1>(send_param).type); 485 base::get<1>(send_param).type);
486 EXPECT_EQ(origin_path_form_.username_value, base::get<1>(send_param).id); 486 EXPECT_EQ(origin_path_form_.username_value, base::get<1>(send_param).id);
487 EXPECT_EQ(origin_path_form_.display_name, base::get<1>(send_param).name); 487 EXPECT_EQ(origin_path_form_.display_name, base::get<1>(send_param).name);
488 EXPECT_EQ(origin_path_form_.password_value, 488 EXPECT_EQ(origin_path_form_.password_value,
489 base::get<1>(send_param).password); 489 base::get<1>(send_param).password);
490 } 490 }
491 491
492 TEST_F(CredentialManagerDispatcherTest, 492 TEST_F(CredentialManagerDispatcherTest,
493 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { 493 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) {
494 store_->AddLogin(cross_origin_form_); 494 store_->AddLogin(cross_origin_form_);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; 621 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID;
622 const IPC::Message* message = 622 const IPC::Message* message =
623 process()->sink().GetFirstMessageMatching(kMsgID); 623 process()->sink().GetFirstMessageMatching(kMsgID);
624 ASSERT_TRUE(message); 624 ASSERT_TRUE(message);
625 CredentialManagerMsg_SendCredential::Param param; 625 CredentialManagerMsg_SendCredential::Param param;
626 CredentialManagerMsg_SendCredential::Read(message, &param); 626 CredentialManagerMsg_SendCredential::Read(message, &param);
627 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type); 627 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, base::get<1>(param).type);
628 } 628 }
629 629
630 } // namespace password_manager 630 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698