Chromium Code Reviews| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" | 14 #include "components/password_manager/content/browser/credential_manager_passwor d_form_manager.h" |
| 15 #include "components/password_manager/content/common/credential_manager_messages .h" | 15 #include "components/password_manager/content/common/credential_manager_messages .h" |
| 16 #include "components/password_manager/core/browser/stub_password_manager_client. h" | 16 #include "components/password_manager/core/browser/stub_password_manager_client. h" |
| 17 #include "components/password_manager/core/browser/stub_password_manager_driver. h" | 17 #include "components/password_manager/core/browser/stub_password_manager_driver. h" |
| 18 #include "components/password_manager/core/browser/test_password_store.h" | 18 #include "components/password_manager/core/browser/test_password_store.h" |
| 19 #include "components/password_manager/core/common/credential_manager_types.h" | 19 #include "components/password_manager/core/common/credential_manager_types.h" |
| 20 #include "components/password_manager/core/common/password_manager_pref_names.h" | 20 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
| 23 #include "content/public/test/test_renderer_host.h" | 23 #include "content/public/test/test_renderer_host.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 using content::BrowserContext; | 27 using content::BrowserContext; |
| 28 using content::WebContents; | 28 using content::WebContents; |
| 29 | 29 |
| 30 using testing::_; | |
| 31 | |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Chosen by fair dice roll. Guaranteed to be random. | 34 // Chosen by fair dice roll. Guaranteed to be random. |
| 33 const int kRequestId = 4; | 35 const int kRequestId = 4; |
| 34 | 36 |
| 35 class TestPasswordManagerClient | 37 class MockPasswordManagerClient |
| 36 : public password_manager::StubPasswordManagerClient { | 38 : public password_manager::StubPasswordManagerClient { |
| 37 public: | 39 public: |
| 38 TestPasswordManagerClient(password_manager::PasswordStore* store) | 40 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 39 : did_prompt_user_to_save_(false), | 41 MOCK_METHOD1(NotifyUserAutoSigninPtr, |
| 40 did_prompt_user_to_choose_(false), | 42 bool(const std::vector<autofill::PasswordForm*>& local_forms)); |
| 41 did_prompt_auto_signin_(false), | 43 MOCK_METHOD2(PromptUserToSavePasswordPtr, |
| 42 is_off_the_record_(false), | 44 void(password_manager::PasswordFormManager*, |
| 43 store_(store) { | 45 password_manager::CredentialSourceType type)); |
| 46 MOCK_METHOD4(PromptUserToChooseCredentialsPtr, | |
| 47 bool(const std::vector<autofill::PasswordForm*>& local_forms, | |
| 48 const std::vector<autofill::PasswordForm*>& federated_forms, | |
| 49 const GURL& origin, | |
| 50 base::Callback<void( | |
| 51 const password_manager::CredentialInfo&)> callback)); | |
| 52 MockPasswordManagerClient(password_manager::PasswordStore* store) | |
|
vabr (Chromium)
2015/03/30 07:56:43
optional nit: Separate the constructor from the MO
melandory
2015/03/30 08:40:23
Done.
| |
| 53 : did_prompt_auto_signin_(false), store_(store) { | |
| 44 prefs_.registry()->RegisterBooleanPref( | 54 prefs_.registry()->RegisterBooleanPref( |
| 45 password_manager::prefs::kPasswordManagerAutoSignin, true); | 55 password_manager::prefs::kPasswordManagerAutoSignin, true); |
| 46 } | 56 } |
| 47 ~TestPasswordManagerClient() override {} | 57 ~MockPasswordManagerClient() override {} |
| 58 | |
| 59 bool PromptUserToSavePassword( | |
| 60 scoped_ptr<password_manager::PasswordFormManager> manager, | |
| 61 password_manager::CredentialSourceType type) override { | |
| 62 manager_.swap(manager); | |
| 63 PromptUserToSavePasswordPtr(manager.release(), type); | |
|
vabr (Chromium)
2015/03/30 07:56:43
This looks fishy, why do you pass on the previousl
melandory
2015/03/30 08:40:23
Done.
| |
| 64 return true; | |
| 65 } | |
| 48 | 66 |
| 49 password_manager::PasswordStore* GetPasswordStore() const override { | 67 password_manager::PasswordStore* GetPasswordStore() const override { |
| 50 return store_; | 68 return store_; |
| 51 } | 69 } |
| 52 | 70 |
| 53 PrefService* GetPrefs() override { return &prefs_; } | 71 PrefService* GetPrefs() override { return &prefs_; } |
| 54 | 72 |
| 55 bool PromptUserToSavePassword( | |
| 56 scoped_ptr<password_manager::PasswordFormManager> manager, | |
| 57 password_manager::CredentialSourceType type) override { | |
| 58 did_prompt_user_to_save_ = true; | |
| 59 EXPECT_EQ(password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API, | |
| 60 type); | |
| 61 manager_.swap(manager); | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 bool PromptUserToChooseCredentials( | 73 bool PromptUserToChooseCredentials( |
| 66 ScopedVector<autofill::PasswordForm> local_forms, | 74 ScopedVector<autofill::PasswordForm> local_forms, |
| 67 ScopedVector<autofill::PasswordForm> federated_forms, | 75 ScopedVector<autofill::PasswordForm> federated_forms, |
| 68 const GURL& origin, | 76 const GURL& origin, |
| 69 base::Callback<void(const password_manager::CredentialInfo&)> callback) | 77 base::Callback<void(const password_manager::CredentialInfo&)> callback) { |
| 70 override { | |
| 71 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); | 78 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); |
| 72 did_prompt_user_to_choose_ = true; | |
| 73 password_manager::CredentialInfo info( | 79 password_manager::CredentialInfo info( |
| 74 local_forms.empty() ? *federated_forms[0] : *local_forms[0], | 80 local_forms.empty() ? *federated_forms[0] : *local_forms[0], |
| 75 local_forms.empty() | 81 local_forms.empty() |
| 76 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED | 82 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED |
| 77 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 83 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
| 78 base::MessageLoop::current()->PostTask(FROM_HERE, | 84 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 79 base::Bind(callback, info)); | 85 base::Bind(callback, info)); |
| 86 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), | |
| 87 origin, callback); | |
| 80 return true; | 88 return true; |
| 81 } | 89 } |
| 82 | 90 |
| 83 void NotifyUserAutoSignin( | 91 void NotifyUserAutoSignin( |
| 84 ScopedVector<autofill::PasswordForm> local_forms) override { | 92 ScopedVector<autofill::PasswordForm> local_forms) override { |
| 85 EXPECT_FALSE(local_forms.empty()); | 93 EXPECT_FALSE(local_forms.empty()); |
| 86 did_prompt_auto_signin_ = true; | 94 NotifyUserAutoSigninPtr(local_forms.get()); |
| 87 } | 95 } |
| 88 | 96 |
| 89 bool IsOffTheRecord() const override { return is_off_the_record_; } | |
| 90 | |
| 91 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } | |
| 92 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } | |
| 93 bool did_prompt_auto_signin() const { return did_prompt_auto_signin_; } | |
| 94 | |
| 95 password_manager::PasswordFormManager* pending_manager() const { | 97 password_manager::PasswordFormManager* pending_manager() const { |
| 96 return manager_.get(); | 98 return manager_.get(); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void set_off_the_record(bool off_the_record) { | |
| 100 is_off_the_record_ = off_the_record; | |
| 101 } | |
| 102 | |
| 103 void set_zero_click_enabled(bool zero_click_enabled) { | 101 void set_zero_click_enabled(bool zero_click_enabled) { |
| 104 prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin, | 102 prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin, |
| 105 zero_click_enabled); | 103 zero_click_enabled); |
| 106 } | 104 } |
| 107 | 105 |
| 108 private: | 106 private: |
| 109 TestingPrefServiceSimple prefs_; | 107 TestingPrefServiceSimple prefs_; |
| 110 bool did_prompt_user_to_save_; | |
| 111 bool did_prompt_user_to_choose_; | |
| 112 bool did_prompt_auto_signin_; | 108 bool did_prompt_auto_signin_; |
| 113 bool is_off_the_record_; | |
| 114 password_manager::PasswordStore* store_; | 109 password_manager::PasswordStore* store_; |
| 115 scoped_ptr<password_manager::PasswordFormManager> manager_; | 110 scoped_ptr<password_manager::PasswordFormManager> manager_; |
| 116 | 111 |
| 117 DISALLOW_COPY_AND_ASSIGN(TestPasswordManagerClient); | 112 DISALLOW_COPY_AND_ASSIGN(MockPasswordManagerClient); |
| 118 }; | 113 }; |
| 119 | 114 |
| 120 class TestCredentialManagerDispatcher | 115 class TestCredentialManagerDispatcher |
| 121 : public password_manager::CredentialManagerDispatcher { | 116 : public password_manager::CredentialManagerDispatcher { |
| 122 public: | 117 public: |
| 123 TestCredentialManagerDispatcher( | 118 TestCredentialManagerDispatcher( |
| 124 content::WebContents* web_contents, | 119 content::WebContents* web_contents, |
| 125 password_manager::PasswordManagerClient* client, | 120 password_manager::PasswordManagerClient* client, |
| 126 password_manager::PasswordManagerDriver* driver); | 121 password_manager::PasswordManagerDriver* driver); |
| 127 | 122 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 156 namespace password_manager { | 151 namespace password_manager { |
| 157 | 152 |
| 158 class CredentialManagerDispatcherTest | 153 class CredentialManagerDispatcherTest |
| 159 : public content::RenderViewHostTestHarness { | 154 : public content::RenderViewHostTestHarness { |
| 160 public: | 155 public: |
| 161 CredentialManagerDispatcherTest() {} | 156 CredentialManagerDispatcherTest() {} |
| 162 | 157 |
| 163 void SetUp() override { | 158 void SetUp() override { |
| 164 content::RenderViewHostTestHarness::SetUp(); | 159 content::RenderViewHostTestHarness::SetUp(); |
| 165 store_ = new TestPasswordStore; | 160 store_ = new TestPasswordStore; |
| 166 client_.reset(new TestPasswordManagerClient(store_.get())); | 161 client_.reset(new MockPasswordManagerClient(store_.get())); |
| 167 dispatcher_.reset(new TestCredentialManagerDispatcher( | 162 dispatcher_.reset(new TestCredentialManagerDispatcher( |
| 168 web_contents(), client_.get(), &stub_driver_)); | 163 web_contents(), client_.get(), &stub_driver_)); |
| 164 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); | |
| 169 | 165 |
| 170 NavigateAndCommit(GURL("https://example.com/test.html")); | 166 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 171 | 167 |
| 172 form_.username_value = base::ASCIIToUTF16("Username"); | 168 form_.username_value = base::ASCIIToUTF16("Username"); |
| 173 form_.display_name = base::ASCIIToUTF16("Display Name"); | 169 form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 174 form_.password_value = base::ASCIIToUTF16("Password"); | 170 form_.password_value = base::ASCIIToUTF16("Password"); |
| 175 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 171 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 176 form_.signon_realm = form_.origin.spec(); | 172 form_.signon_realm = form_.origin.spec(); |
| 177 form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 173 form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 178 form_.skip_zero_click = false; | 174 form_.skip_zero_click = false; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 202 content::RenderViewHostTestHarness::TearDown(); | 198 content::RenderViewHostTestHarness::TearDown(); |
| 203 } | 199 } |
| 204 | 200 |
| 205 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 201 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 206 | 202 |
| 207 protected: | 203 protected: |
| 208 autofill::PasswordForm form_; | 204 autofill::PasswordForm form_; |
| 209 autofill::PasswordForm form2_; | 205 autofill::PasswordForm form2_; |
| 210 autofill::PasswordForm cross_origin_form_; | 206 autofill::PasswordForm cross_origin_form_; |
| 211 scoped_refptr<TestPasswordStore> store_; | 207 scoped_refptr<TestPasswordStore> store_; |
| 212 scoped_ptr<TestPasswordManagerClient> client_; | 208 scoped_ptr<MockPasswordManagerClient> client_; |
| 213 StubPasswordManagerDriver stub_driver_; | 209 StubPasswordManagerDriver stub_driver_; |
| 214 scoped_ptr<CredentialManagerDispatcher> dispatcher_; | 210 scoped_ptr<CredentialManagerDispatcher> dispatcher_; |
| 215 }; | 211 }; |
| 216 | 212 |
| 217 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { | 213 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { |
| 218 CredentialInfo info; | 214 CredentialInfo info; |
| 219 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; | 215 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; |
| 220 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); | 216 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); |
| 221 | 217 |
| 222 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | 218 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
| 223 const IPC::Message* message = | 219 const IPC::Message* message = |
| 224 process()->sink().GetFirstMessageMatching(kMsgID); | 220 process()->sink().GetFirstMessageMatching(kMsgID); |
| 225 EXPECT_TRUE(message); | 221 EXPECT_TRUE(message); |
| 226 process()->sink().ClearMessages(); | 222 process()->sink().ClearMessages(); |
| 227 } | 223 } |
| 228 | 224 |
| 229 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { | 225 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedIn) { |
| 230 CredentialInfo info(form_, | 226 CredentialInfo info(form_, |
| 231 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 227 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
| 228 EXPECT_CALL( | |
| 229 *client_, | |
| 230 PromptUserToSavePasswordPtr( | |
| 231 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) | |
|
vabr (Chromium)
2015/03/30 07:56:43
Isn't this leaking the manager? (Also on other pla
| |
| 232 .Times(testing::Exactly(1)); | |
| 233 | |
| 232 dispatcher()->OnNotifySignedIn(kRequestId, info); | 234 dispatcher()->OnNotifySignedIn(kRequestId, info); |
| 233 | 235 |
| 234 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | 236 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; |
| 235 const IPC::Message* message = | 237 const IPC::Message* message = |
| 236 process()->sink().GetFirstMessageMatching(kMsgID); | 238 process()->sink().GetFirstMessageMatching(kMsgID); |
| 237 EXPECT_TRUE(message); | 239 EXPECT_TRUE(message); |
| 238 process()->sink().ClearMessages(); | 240 process()->sink().ClearMessages(); |
| 239 | 241 |
| 240 // Allow the PasswordFormManager to talk to the password store, determine | 242 // Allow the PasswordFormManager to talk to the password store, determine |
| 241 // that the form is new, and set it as pending. | 243 // that the form is new, and set it as pending. |
| 242 RunAllPendingTasks(); | 244 RunAllPendingTasks(); |
| 243 | 245 |
| 244 EXPECT_TRUE(client_->did_prompt_user_to_save()); | |
| 245 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); | 246 EXPECT_TRUE(client_->pending_manager()->HasCompletedMatching()); |
| 246 | 247 |
| 247 autofill::PasswordForm new_form = | 248 autofill::PasswordForm new_form = |
| 248 client_->pending_manager()->pending_credentials(); | 249 client_->pending_manager()->pending_credentials(); |
| 249 EXPECT_EQ(form_.username_value, new_form.username_value); | 250 EXPECT_EQ(form_.username_value, new_form.username_value); |
| 250 EXPECT_EQ(form_.display_name, new_form.display_name); | 251 EXPECT_EQ(form_.display_name, new_form.display_name); |
| 251 EXPECT_EQ(form_.password_value, new_form.password_value); | 252 EXPECT_EQ(form_.password_value, new_form.password_value); |
| 252 EXPECT_EQ(form_.origin, new_form.origin); | 253 EXPECT_EQ(form_.origin, new_form.origin); |
| 253 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); | 254 EXPECT_EQ(form_.signon_realm, new_form.signon_realm); |
| 254 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); | 255 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, new_form.scheme); |
| 255 } | 256 } |
| 256 | 257 |
| 257 TEST_F(CredentialManagerDispatcherTest, CredentialManagerIncognitoSignedIn) { | 258 TEST_F(CredentialManagerDispatcherTest, CredentialManagerIncognitoSignedIn) { |
| 258 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL); | 259 CredentialInfo info(form_, CredentialType::CREDENTIAL_TYPE_LOCAL); |
| 259 client_->set_off_the_record(true); | 260 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 261 EXPECT_CALL( | |
| 262 *client_, | |
| 263 PromptUserToSavePasswordPtr( | |
| 264 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) | |
| 265 .Times(testing::Exactly(0)); | |
| 266 | |
| 260 dispatcher()->OnNotifySignedIn(kRequestId, info); | 267 dispatcher()->OnNotifySignedIn(kRequestId, info); |
| 261 | 268 |
| 262 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; | 269 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedIn::ID; |
| 263 const IPC::Message* message = | 270 const IPC::Message* message = |
| 264 process()->sink().GetFirstMessageMatching(kMsgID); | 271 process()->sink().GetFirstMessageMatching(kMsgID); |
| 265 EXPECT_TRUE(message); | 272 EXPECT_TRUE(message); |
| 266 process()->sink().ClearMessages(); | 273 process()->sink().ClearMessages(); |
| 267 | 274 |
| 268 RunAllPendingTasks(); | 275 RunAllPendingTasks(); |
| 269 | 276 |
| 270 EXPECT_FALSE(client_->did_prompt_user_to_save()); | |
| 271 EXPECT_FALSE(client_->pending_manager()); | 277 EXPECT_FALSE(client_->pending_manager()); |
| 272 } | 278 } |
| 273 | 279 |
| 274 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedOut) { | 280 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifySignedOut) { |
| 275 store_->AddLogin(form_); | 281 store_->AddLogin(form_); |
| 276 store_->AddLogin(cross_origin_form_); | 282 store_->AddLogin(cross_origin_form_); |
| 277 RunAllPendingTasks(); | 283 RunAllPendingTasks(); |
| 278 | 284 |
| 279 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 285 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 280 EXPECT_EQ(2U, passwords.size()); | 286 EXPECT_EQ(2U, passwords.size()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 296 EXPECT_EQ(2U, passwords.size()); | 302 EXPECT_EQ(2U, passwords.size()); |
| 297 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 303 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 298 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 304 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 299 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 305 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 300 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 306 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 301 } | 307 } |
| 302 | 308 |
| 303 TEST_F(CredentialManagerDispatcherTest, | 309 TEST_F(CredentialManagerDispatcherTest, |
| 304 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { | 310 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { |
| 305 std::vector<GURL> federations; | 311 std::vector<GURL> federations; |
| 312 EXPECT_CALL( | |
| 313 *client_, | |
| 314 PromptUserToSavePasswordPtr( | |
| 315 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) | |
| 316 .Times(testing::Exactly(0)); | |
| 317 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 318 .Times(testing::Exactly(0)); | |
| 319 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 320 | |
| 306 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 321 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 307 | 322 |
| 308 RunAllPendingTasks(); | 323 RunAllPendingTasks(); |
| 309 | 324 |
| 310 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 325 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 311 const IPC::Message* message = | 326 const IPC::Message* message = |
| 312 process()->sink().GetFirstMessageMatching(kMsgID); | 327 process()->sink().GetFirstMessageMatching(kMsgID); |
| 313 EXPECT_TRUE(message); | 328 EXPECT_TRUE(message); |
| 314 CredentialManagerMsg_SendCredential::Param param; | 329 CredentialManagerMsg_SendCredential::Param param; |
| 315 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 330 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 316 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 331 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); |
| 317 process()->sink().ClearMessages(); | 332 process()->sink().ClearMessages(); |
| 318 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 319 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 320 } | 333 } |
| 321 | 334 |
| 322 TEST_F(CredentialManagerDispatcherTest, | 335 TEST_F(CredentialManagerDispatcherTest, |
| 323 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { | 336 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { |
| 324 store_->AddLogin(cross_origin_form_); | 337 store_->AddLogin(cross_origin_form_); |
| 325 | 338 |
| 326 std::vector<GURL> federations; | 339 std::vector<GURL> federations; |
| 340 EXPECT_CALL( | |
| 341 *client_, | |
| 342 PromptUserToSavePasswordPtr( | |
| 343 testing::_, | |
| 344 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) | |
| 345 .Times(testing::Exactly(0)); | |
| 346 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 347 .Times(testing::Exactly(0)); | |
| 348 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 349 | |
| 327 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 350 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 328 | 351 |
| 329 RunAllPendingTasks(); | 352 RunAllPendingTasks(); |
| 330 | 353 |
| 331 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 354 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 332 const IPC::Message* message = | 355 const IPC::Message* message = |
| 333 process()->sink().GetFirstMessageMatching(kMsgID); | 356 process()->sink().GetFirstMessageMatching(kMsgID); |
| 334 EXPECT_TRUE(message); | 357 EXPECT_TRUE(message); |
| 335 CredentialManagerMsg_SendCredential::Param param; | 358 CredentialManagerMsg_SendCredential::Param param; |
| 336 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 359 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 337 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 360 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); |
| 338 process()->sink().ClearMessages(); | 361 process()->sink().ClearMessages(); |
| 339 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 340 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 341 } | 362 } |
| 342 | 363 |
| 343 TEST_F(CredentialManagerDispatcherTest, | 364 TEST_F(CredentialManagerDispatcherTest, |
| 344 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | 365 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
| 345 client_->set_zero_click_enabled(false); | 366 client_->set_zero_click_enabled(false); |
| 346 store_->AddLogin(form_); | 367 store_->AddLogin(form_); |
| 347 | 368 |
| 348 std::vector<GURL> federations; | 369 std::vector<GURL> federations; |
| 370 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 371 .Times(testing::Exactly(1)); | |
| 372 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 373 | |
| 349 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 374 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 350 | 375 |
| 351 RunAllPendingTasks(); | 376 RunAllPendingTasks(); |
| 352 | 377 |
| 353 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 378 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 354 const IPC::Message* message = | 379 const IPC::Message* message = |
| 355 process()->sink().GetFirstMessageMatching(kMsgID); | 380 process()->sink().GetFirstMessageMatching(kMsgID); |
| 356 EXPECT_TRUE(message); | 381 EXPECT_TRUE(message); |
| 357 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | |
| 358 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 359 } | 382 } |
| 360 | 383 |
| 361 TEST_F( | 384 TEST_F( |
| 362 CredentialManagerDispatcherTest, | 385 CredentialManagerDispatcherTest, |
| 363 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { | 386 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { |
| 364 std::vector<GURL> federations; | 387 std::vector<GURL> federations; |
| 388 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 389 .Times(testing::Exactly(0)); | |
| 390 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 391 | |
| 365 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 392 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 366 | 393 |
| 367 RunAllPendingTasks(); | 394 RunAllPendingTasks(); |
| 368 | 395 |
| 369 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 396 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 370 const IPC::Message* message = | 397 const IPC::Message* message = |
| 371 process()->sink().GetFirstMessageMatching(kMsgID); | 398 process()->sink().GetFirstMessageMatching(kMsgID); |
| 372 EXPECT_TRUE(message); | 399 EXPECT_TRUE(message); |
| 373 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 374 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 375 CredentialManagerMsg_SendCredential::Param send_param; | 400 CredentialManagerMsg_SendCredential::Param send_param; |
| 376 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 401 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 377 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 402 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 378 } | 403 } |
| 379 | 404 |
| 380 TEST_F(CredentialManagerDispatcherTest, | 405 TEST_F(CredentialManagerDispatcherTest, |
| 381 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { | 406 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { |
| 382 store_->AddLogin(form_); | 407 store_->AddLogin(form_); |
| 383 | 408 |
| 384 std::vector<GURL> federations; | 409 std::vector<GURL> federations; |
| 410 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 411 .Times(testing::Exactly(0)); | |
| 412 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1)); | |
| 413 | |
| 385 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 414 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 386 | 415 |
| 387 RunAllPendingTasks(); | 416 RunAllPendingTasks(); |
| 388 | 417 |
| 389 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 418 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 390 const IPC::Message* message = | 419 const IPC::Message* message = |
| 391 process()->sink().GetFirstMessageMatching(kMsgID); | 420 process()->sink().GetFirstMessageMatching(kMsgID); |
| 392 EXPECT_TRUE(message); | 421 EXPECT_TRUE(message); |
| 393 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 394 EXPECT_TRUE(client_->did_prompt_auto_signin()); | |
| 395 CredentialManagerMsg_SendCredential::Param send_param; | 422 CredentialManagerMsg_SendCredential::Param send_param; |
| 396 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 423 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 397 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); | 424 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); |
| 398 } | 425 } |
| 399 | 426 |
| 400 TEST_F(CredentialManagerDispatcherTest, | 427 TEST_F(CredentialManagerDispatcherTest, |
| 401 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | 428 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { |
| 402 store_->AddLogin(form_); | 429 store_->AddLogin(form_); |
| 403 store_->AddLogin(form2_); | 430 store_->AddLogin(form2_); |
| 404 | 431 |
| 405 std::vector<GURL> federations; | 432 std::vector<GURL> federations; |
| 433 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 434 .Times(testing::Exactly(0)); | |
| 435 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 436 | |
| 406 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 437 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 407 | 438 |
| 408 RunAllPendingTasks(); | 439 RunAllPendingTasks(); |
| 409 | 440 |
| 410 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 441 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 411 const IPC::Message* message = | 442 const IPC::Message* message = |
| 412 process()->sink().GetFirstMessageMatching(kMsgID); | 443 process()->sink().GetFirstMessageMatching(kMsgID); |
| 413 EXPECT_TRUE(message); | 444 EXPECT_TRUE(message); |
| 414 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 415 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 416 CredentialManagerMsg_SendCredential::Param send_param; | 445 CredentialManagerMsg_SendCredential::Param send_param; |
| 417 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 446 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 418 | 447 |
| 419 // With two items in the password store, we shouldn't get credentials back. | 448 // With two items in the password store, we shouldn't get credentials back. |
| 420 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 449 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 421 } | 450 } |
| 422 | 451 |
| 423 TEST_F(CredentialManagerDispatcherTest, | 452 TEST_F(CredentialManagerDispatcherTest, |
| 424 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) { | 453 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) { |
| 425 form_.skip_zero_click = true; | 454 form_.skip_zero_click = true; |
| 426 store_->AddLogin(form_); | 455 store_->AddLogin(form_); |
| 427 store_->AddLogin(form2_); | 456 store_->AddLogin(form2_); |
| 428 | 457 |
| 429 std::vector<GURL> federations; | 458 std::vector<GURL> federations; |
| 459 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 460 .Times(testing::Exactly(0)); | |
| 461 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1)); | |
| 462 | |
| 430 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 463 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 431 | 464 |
| 432 RunAllPendingTasks(); | 465 RunAllPendingTasks(); |
| 433 | 466 |
| 434 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 467 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 435 const IPC::Message* message = | 468 const IPC::Message* message = |
| 436 process()->sink().GetFirstMessageMatching(kMsgID); | 469 process()->sink().GetFirstMessageMatching(kMsgID); |
| 437 EXPECT_TRUE(message); | 470 EXPECT_TRUE(message); |
| 438 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 439 EXPECT_TRUE(client_->did_prompt_auto_signin()); | |
| 440 CredentialManagerMsg_SendCredential::Param send_param; | 471 CredentialManagerMsg_SendCredential::Param send_param; |
| 441 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 472 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 442 | 473 |
| 443 // We should get |form2_| back, as |form_| is marked as skipping zero-click. | 474 // We should get |form2_| back, as |form_| is marked as skipping zero-click. |
| 444 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); | 475 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); |
| 445 EXPECT_EQ(form2_.username_value, get<1>(send_param).id); | 476 EXPECT_EQ(form2_.username_value, get<1>(send_param).id); |
| 446 EXPECT_EQ(form2_.display_name, get<1>(send_param).name); | 477 EXPECT_EQ(form2_.display_name, get<1>(send_param).name); |
| 447 EXPECT_EQ(form2_.password_value, get<1>(send_param).password); | 478 EXPECT_EQ(form2_.password_value, get<1>(send_param).password); |
| 448 } | 479 } |
| 449 | 480 |
| 450 TEST_F(CredentialManagerDispatcherTest, | 481 TEST_F(CredentialManagerDispatcherTest, |
| 451 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { | 482 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { |
| 452 store_->AddLogin(cross_origin_form_); | 483 store_->AddLogin(cross_origin_form_); |
| 453 | 484 |
| 454 form_.skip_zero_click = true; | 485 form_.skip_zero_click = true; |
| 455 store_->AddLogin(form_); | 486 store_->AddLogin(form_); |
| 456 | 487 |
| 457 std::vector<GURL> federations; | 488 std::vector<GURL> federations; |
| 489 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 490 .Times(testing::Exactly(0)); | |
| 491 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 492 | |
| 458 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 493 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 459 | 494 |
| 460 RunAllPendingTasks(); | 495 RunAllPendingTasks(); |
| 461 | 496 |
| 462 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 497 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 463 const IPC::Message* message = | 498 const IPC::Message* message = |
| 464 process()->sink().GetFirstMessageMatching(kMsgID); | 499 process()->sink().GetFirstMessageMatching(kMsgID); |
| 465 EXPECT_TRUE(message); | 500 EXPECT_TRUE(message); |
| 466 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 467 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 468 CredentialManagerMsg_SendCredential::Param send_param; | 501 CredentialManagerMsg_SendCredential::Param send_param; |
| 469 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 502 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 470 | 503 |
| 471 // We only have cross-origin zero-click credentials; they should not be | 504 // We only have cross-origin zero-click credentials; they should not be |
| 472 // returned. | 505 // returned. |
| 473 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 506 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 474 } | 507 } |
| 475 | 508 |
| 476 TEST_F(CredentialManagerDispatcherTest, | 509 TEST_F(CredentialManagerDispatcherTest, |
| 477 CredentialManagerOnRequestCredentialWhileRequestPending) { | 510 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 478 client_->set_zero_click_enabled(false); | 511 client_->set_zero_click_enabled(false); |
| 479 store_->AddLogin(form_); | 512 store_->AddLogin(form_); |
| 480 | 513 |
| 481 std::vector<GURL> federations; | 514 std::vector<GURL> federations; |
| 515 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 516 .Times(testing::Exactly(0)); | |
| 517 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 518 | |
| 482 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 519 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 483 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 520 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 484 | 521 |
| 485 // Check that the second request triggered a rejection. | 522 // Check that the second request triggered a rejection. |
| 486 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | 523 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; |
| 487 const IPC::Message* message = | 524 const IPC::Message* message = |
| 488 process()->sink().GetFirstMessageMatching(kMsgID); | 525 process()->sink().GetFirstMessageMatching(kMsgID); |
| 489 EXPECT_TRUE(message); | 526 EXPECT_TRUE(message); |
| 527 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 528 .Times(testing::Exactly(0)); | |
| 529 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 530 | |
| 490 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; | 531 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; |
| 491 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); | 532 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); |
| 492 EXPECT_EQ(blink::WebCredentialManagerError::ErrorTypePendingRequest, | 533 EXPECT_EQ(blink::WebCredentialManagerError::ErrorTypePendingRequest, |
| 493 get<1>(reject_param)); | 534 get<1>(reject_param)); |
| 494 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | 535 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 495 EXPECT_FALSE(client_->did_prompt_auto_signin()); | 536 .Times(testing::Exactly(1)); |
| 537 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 496 | 538 |
| 497 process()->sink().ClearMessages(); | 539 process()->sink().ClearMessages(); |
| 498 | 540 |
| 499 // Execute the PasswordStore asynchronousness. | 541 // Execute the PasswordStore asynchronousness. |
| 500 RunAllPendingTasks(); | 542 RunAllPendingTasks(); |
| 501 | 543 |
| 502 // Check that the first request resolves. | 544 // Check that the first request resolves. |
| 503 kMsgID = CredentialManagerMsg_SendCredential::ID; | 545 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 504 message = process()->sink().GetFirstMessageMatching(kMsgID); | 546 message = process()->sink().GetFirstMessageMatching(kMsgID); |
| 505 EXPECT_TRUE(message); | 547 EXPECT_TRUE(message); |
| 506 CredentialManagerMsg_SendCredential::Param send_param; | 548 CredentialManagerMsg_SendCredential::Param send_param; |
| 507 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 549 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 508 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 550 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 509 process()->sink().ClearMessages(); | 551 process()->sink().ClearMessages(); |
| 510 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | |
| 511 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 512 } | 552 } |
| 513 | 553 |
| 514 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { | 554 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { |
| 515 // Turn on the global zero-click flag, and add two credentials in separate | 555 // Turn on the global zero-click flag, and add two credentials in separate |
| 516 // origins, both set to skip zero-click. | 556 // origins, both set to skip zero-click. |
| 517 client_->set_zero_click_enabled(true); | 557 client_->set_zero_click_enabled(true); |
| 518 form_.skip_zero_click = true; | 558 form_.skip_zero_click = true; |
| 519 store_->AddLogin(form_); | 559 store_->AddLogin(form_); |
| 520 cross_origin_form_.skip_zero_click = true; | 560 cross_origin_form_.skip_zero_click = true; |
| 521 store_->AddLogin(cross_origin_form_); | 561 store_->AddLogin(cross_origin_form_); |
| 522 | 562 |
| 523 // Execute the PasswordStore asynchronousness to ensure everything is | 563 // Execute the PasswordStore asynchronousness to ensure everything is |
| 524 // written before proceeding. | 564 // written before proceeding. |
| 525 RunAllPendingTasks(); | 565 RunAllPendingTasks(); |
| 526 | 566 |
| 527 // Sanity check. | 567 // Sanity check. |
| 528 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 568 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 529 EXPECT_EQ(2U, passwords.size()); | 569 EXPECT_EQ(2U, passwords.size()); |
| 530 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 570 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 531 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 571 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 532 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 572 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 533 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 573 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 534 | 574 |
| 535 // Trigger a request which should return the credential found in |form_|, and | 575 // Trigger a request which should return the credential found in |form_|, and |
| 536 // wait for it to process. | 576 // wait for it to process. |
| 537 std::vector<GURL> federations; | 577 std::vector<GURL> federations; |
| 578 // Check that the form in the database has been updated. `OnRequestCredential` | |
| 579 // generates a call to prompt the user to choose a credential. | |
| 580 // MockPasswordManagerClient mocks a user choice, and when users choose a | |
| 581 // credential (and have the global zero-click flag enabled), we make sure that | |
| 582 // they'll be logged in again next time. | |
| 583 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 584 .Times(testing::Exactly(1)); | |
| 585 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 586 | |
| 538 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 587 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 539 RunAllPendingTasks(); | 588 RunAllPendingTasks(); |
| 540 | 589 |
| 541 // Check that the form in the database has been updated. `OnRequestCredential` | |
| 542 // generates a call to prompt the user to choose a credential. | |
| 543 // TestPasswordManagerClient mocks a user choice, and when users choose a | |
| 544 // credential (and have the global zero-click flag enabled), we make sure that | |
| 545 // they'll be logged in again next time. | |
| 546 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | |
| 547 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 548 passwords = store_->stored_passwords(); | 590 passwords = store_->stored_passwords(); |
| 549 EXPECT_EQ(2U, passwords.size()); | 591 EXPECT_EQ(2U, passwords.size()); |
| 550 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 592 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 551 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 593 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 552 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 594 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 553 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 595 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 554 } | 596 } |
| 555 | 597 |
| 556 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { | 598 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { |
| 557 client_->set_off_the_record(true); | 599 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 558 store_->AddLogin(form_); | 600 store_->AddLogin(form_); |
| 559 | 601 |
| 560 std::vector<GURL> federations; | 602 std::vector<GURL> federations; |
| 603 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) | |
| 604 .Times(testing::Exactly(0)); | |
| 605 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); | |
| 606 | |
| 561 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 607 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 562 | 608 |
| 563 RunAllPendingTasks(); | 609 RunAllPendingTasks(); |
| 564 | 610 |
| 565 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 611 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 566 const IPC::Message* message = | 612 const IPC::Message* message = |
| 567 process()->sink().GetFirstMessageMatching(kMsgID); | 613 process()->sink().GetFirstMessageMatching(kMsgID); |
| 568 ASSERT_TRUE(message); | 614 ASSERT_TRUE(message); |
| 569 CredentialManagerMsg_SendCredential::Param param; | 615 CredentialManagerMsg_SendCredential::Param param; |
| 570 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 616 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 571 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 617 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); |
| 572 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 573 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 574 } | 618 } |
| 575 | 619 |
| 576 } // namespace password_manager | 620 } // namespace password_manager |
| OLD | NEW |