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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 MOCK_METHOD1(NotifyUserAutoSigninPtr, | 58 MOCK_METHOD1(NotifyUserAutoSigninPtr, |
59 bool(const std::vector<autofill::PasswordForm*>& local_forms)); | 59 bool(const std::vector<autofill::PasswordForm*>& local_forms)); |
60 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, | 60 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, |
61 bool(autofill::PasswordForm* form)); | 61 bool(autofill::PasswordForm* form)); |
62 MOCK_METHOD2(PromptUserToSavePasswordPtr, | 62 MOCK_METHOD2(PromptUserToSavePasswordPtr, |
63 void(PasswordFormManager*, CredentialSourceType type)); | 63 void(PasswordFormManager*, CredentialSourceType type)); |
64 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, | 64 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, |
65 bool(const std::vector<autofill::PasswordForm*>& local_forms, | 65 bool(const std::vector<autofill::PasswordForm*>& local_forms, |
66 const std::vector<autofill::PasswordForm*>& federated_forms, | 66 const std::vector<autofill::PasswordForm*>& federated_forms, |
67 const GURL& origin, | 67 const GURL& origin, |
68 base::Callback<void(const CredentialInfo&)> callback)); | 68 const CredentialsCallback& callback)); |
69 | 69 |
70 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { | 70 explicit MockPasswordManagerClient(PasswordStore* store) : store_(store) { |
71 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, | 71 prefs_.registry()->RegisterBooleanPref(prefs::kCredentialsEnableAutosignin, |
72 true); | 72 true); |
73 prefs_.registry()->RegisterBooleanPref( | 73 prefs_.registry()->RegisterBooleanPref( |
74 prefs::kWasAutoSignInFirstRunExperienceShown, true); | 74 prefs::kWasAutoSignInFirstRunExperienceShown, true); |
75 } | 75 } |
76 ~MockPasswordManagerClient() override {} | 76 ~MockPasswordManagerClient() override {} |
77 | 77 |
78 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager, | 78 bool PromptUserToSaveOrUpdatePassword(scoped_ptr<PasswordFormManager> manager, |
(...skipping 10 matching lines...) Expand all Loading... | |
89 } | 89 } |
90 | 90 |
91 PasswordStore* GetPasswordStore() const override { return store_; } | 91 PasswordStore* GetPasswordStore() const override { return store_; } |
92 | 92 |
93 PrefService* GetPrefs() override { return &prefs_; } | 93 PrefService* GetPrefs() override { return &prefs_; } |
94 | 94 |
95 bool PromptUserToChooseCredentials( | 95 bool PromptUserToChooseCredentials( |
96 ScopedVector<autofill::PasswordForm> local_forms, | 96 ScopedVector<autofill::PasswordForm> local_forms, |
97 ScopedVector<autofill::PasswordForm> federated_forms, | 97 ScopedVector<autofill::PasswordForm> federated_forms, |
98 const GURL& origin, | 98 const GURL& origin, |
99 base::Callback<void(const CredentialInfo&)> callback) { | 99 const CredentialsCallback& callback) { |
100 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); | 100 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); |
101 CredentialInfo info( | 101 const autofill::PasswordForm* form = |
102 local_forms.empty() ? *federated_forms[0] : *local_forms[0], | 102 local_forms.empty() ? federated_forms[0] : local_forms[0]; |
103 local_forms.empty() ? CredentialType::CREDENTIAL_TYPE_FEDERATED | 103 base::ThreadTaskRunnerHandle::Get()->PostTask( |
104 : CredentialType::CREDENTIAL_TYPE_PASSWORD); | 104 FROM_HERE, |
105 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 105 base::Bind(callback, base::Owned(new autofill::PasswordForm(*form)))); |
106 base::Bind(callback, info)); | |
107 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), | 106 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), |
108 origin, callback); | 107 origin, callback); |
109 return true; | 108 return true; |
110 } | 109 } |
111 | 110 |
112 void NotifyUserAutoSignin(ScopedVector<autofill::PasswordForm> local_forms, | 111 void NotifyUserAutoSignin(ScopedVector<autofill::PasswordForm> local_forms, |
113 const GURL& origin) override { | 112 const GURL& origin) override { |
114 EXPECT_FALSE(local_forms.empty()); | 113 EXPECT_FALSE(local_forms.empty()); |
115 NotifyUserAutoSigninPtr(local_forms.get()); | 114 NotifyUserAutoSigninPtr(local_forms.get()); |
116 } | 115 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 // Allow the PasswordFormManager to talk to the password store, determine | 404 // Allow the PasswordFormManager to talk to the password store, determine |
406 // the form is a match for an existing form, and update the PasswordStore. | 405 // the form is a match for an existing form, and update the PasswordStore. |
407 RunAllPendingTasks(); | 406 RunAllPendingTasks(); |
408 | 407 |
409 // Verify that the update didn't toggle the skip_zero_click flag off. | 408 // Verify that the update didn't toggle the skip_zero_click flag off. |
410 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 409 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
411 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 410 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
412 } | 411 } |
413 | 412 |
414 TEST_F(CredentialManagerDispatcherTest, | 413 TEST_F(CredentialManagerDispatcherTest, |
414 CredentialManagerGetOverwriteZeroClick) { | |
415 // Set the global zero click flag on, and populate the PasswordStore with a | |
416 // form that's set to skip zero click and has a primary key that won't match | |
417 // credentials initially created via `store()`. | |
418 client_->set_zero_click_enabled(true); | |
419 form_.skip_zero_click = true; | |
420 form_.username_element = base::ASCIIToUTF16("username-element"); | |
421 form_.password_element = base::ASCIIToUTF16("password-element"); | |
422 form_.signon_realm = "this is a realm"; | |
423 form_.origin = GURL("https://example.com/old_form.html"); | |
424 store_->AddLogin(form_); | |
425 RunAllPendingTasks(); | |
426 | |
427 std::vector<GURL> federations; | |
428 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
429 .Times(testing::Exactly(1)); | |
430 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
431 | |
432 dispatcher()->OnRequestCredential(kRequestId, false, true, federations); | |
433 | |
434 RunAllPendingTasks(); | |
435 | |
436 const uint32_t kMsgID = CredentialManagerMsg_SendCredential::ID; | |
vabr (Chromium)
2016/03/29 08:45:55
heads-up: If you get rebasing conflicts or post-re
vasilii
2016/03/29 09:57:44
No conflicts.
| |
437 const IPC::Message* message = | |
438 process()->sink().GetFirstMessageMatching(kMsgID); | |
439 EXPECT_TRUE(message); | |
440 | |
441 // Verify that the update toggled the skip_zero_click flag. | |
442 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | |
443 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | |
444 } | |
445 | |
446 TEST_F(CredentialManagerDispatcherTest, | |
415 CredentialManagerSignInWithSavingDisabledForCurrentPage) { | 447 CredentialManagerSignInWithSavingDisabledForCurrentPage) { |
416 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); | 448 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_PASSWORD); |
417 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 449 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
418 .WillRepeatedly(testing::Return(false)); | 450 .WillRepeatedly(testing::Return(false)); |
419 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( | 451 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( |
420 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) | 452 _, CredentialSourceType::CREDENTIAL_SOURCE_API)) |
421 .Times(testing::Exactly(0)); | 453 .Times(testing::Exactly(0)); |
422 | 454 |
423 dispatcher()->OnStore(kRequestId, info); | 455 dispatcher()->OnStore(kRequestId, info); |
424 | 456 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1121 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { | 1153 TEST_F(CredentialManagerDispatcherTest, GetSynthesizedFormForOrigin) { |
1122 autofill::PasswordForm synthesized = | 1154 autofill::PasswordForm synthesized = |
1123 dispatcher_->GetSynthesizedFormForOrigin(); | 1155 dispatcher_->GetSynthesizedFormForOrigin(); |
1124 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); | 1156 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); |
1125 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); | 1157 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); |
1126 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); | 1158 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); |
1127 EXPECT_TRUE(synthesized.ssl_valid); | 1159 EXPECT_TRUE(synthesized.ssl_valid); |
1128 } | 1160 } |
1129 | 1161 |
1130 } // namespace password_manager | 1162 } // namespace password_manager |
OLD | NEW |