| 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 |
| 53 MockPasswordManagerClient(password_manager::PasswordStore* store) |
| 54 : store_(store) { |
| 44 prefs_.registry()->RegisterBooleanPref( | 55 prefs_.registry()->RegisterBooleanPref( |
| 45 password_manager::prefs::kPasswordManagerAutoSignin, true); | 56 password_manager::prefs::kPasswordManagerAutoSignin, true); |
| 46 } | 57 } |
| 47 ~TestPasswordManagerClient() override {} | 58 ~MockPasswordManagerClient() override {} |
| 59 |
| 60 bool PromptUserToSavePassword( |
| 61 scoped_ptr<password_manager::PasswordFormManager> manager, |
| 62 password_manager::CredentialSourceType type) override { |
| 63 manager_.swap(manager); |
| 64 PromptUserToSavePasswordPtr(manager_.get(), type); |
| 65 return true; |
| 66 } |
| 48 | 67 |
| 49 password_manager::PasswordStore* GetPasswordStore() const override { | 68 password_manager::PasswordStore* GetPasswordStore() const override { |
| 50 return store_; | 69 return store_; |
| 51 } | 70 } |
| 52 | 71 |
| 53 PrefService* GetPrefs() override { return &prefs_; } | 72 PrefService* GetPrefs() override { return &prefs_; } |
| 54 | 73 |
| 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( | 74 bool PromptUserToChooseCredentials( |
| 66 ScopedVector<autofill::PasswordForm> local_forms, | 75 ScopedVector<autofill::PasswordForm> local_forms, |
| 67 ScopedVector<autofill::PasswordForm> federated_forms, | 76 ScopedVector<autofill::PasswordForm> federated_forms, |
| 68 const GURL& origin, | 77 const GURL& origin, |
| 69 base::Callback<void(const password_manager::CredentialInfo&)> callback) | 78 base::Callback<void(const password_manager::CredentialInfo&)> callback) { |
| 70 override { | |
| 71 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); | 79 EXPECT_FALSE(local_forms.empty() && federated_forms.empty()); |
| 72 did_prompt_user_to_choose_ = true; | |
| 73 password_manager::CredentialInfo info( | 80 password_manager::CredentialInfo info( |
| 74 local_forms.empty() ? *federated_forms[0] : *local_forms[0], | 81 local_forms.empty() ? *federated_forms[0] : *local_forms[0], |
| 75 local_forms.empty() | 82 local_forms.empty() |
| 76 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED | 83 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED |
| 77 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 84 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
| 78 base::MessageLoop::current()->PostTask(FROM_HERE, | 85 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 79 base::Bind(callback, info)); | 86 base::Bind(callback, info)); |
| 87 PromptUserToChooseCredentialsPtr(local_forms.get(), federated_forms.get(), |
| 88 origin, callback); |
| 80 return true; | 89 return true; |
| 81 } | 90 } |
| 82 | 91 |
| 83 void NotifyUserAutoSignin( | 92 void NotifyUserAutoSignin( |
| 84 ScopedVector<autofill::PasswordForm> local_forms) override { | 93 ScopedVector<autofill::PasswordForm> local_forms) override { |
| 85 EXPECT_FALSE(local_forms.empty()); | 94 EXPECT_FALSE(local_forms.empty()); |
| 86 did_prompt_auto_signin_ = true; | 95 NotifyUserAutoSigninPtr(local_forms.get()); |
| 87 } | 96 } |
| 88 | 97 |
| 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 { | 98 password_manager::PasswordFormManager* pending_manager() const { |
| 96 return manager_.get(); | 99 return manager_.get(); |
| 97 } | 100 } |
| 98 | 101 |
| 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) { | 102 void set_zero_click_enabled(bool zero_click_enabled) { |
| 104 prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin, | 103 prefs_.SetBoolean(password_manager::prefs::kPasswordManagerAutoSignin, |
| 105 zero_click_enabled); | 104 zero_click_enabled); |
| 106 } | 105 } |
| 107 | 106 |
| 108 private: | 107 private: |
| 109 TestingPrefServiceSimple prefs_; | 108 TestingPrefServiceSimple prefs_; |
| 110 bool did_prompt_user_to_save_; | |
| 111 bool did_prompt_user_to_choose_; | |
| 112 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)) |
| 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 _, password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API)) |
| 344 .Times(testing::Exactly(0)); |
| 345 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 346 .Times(testing::Exactly(0)); |
| 347 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 348 |
| 327 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 349 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 328 | 350 |
| 329 RunAllPendingTasks(); | 351 RunAllPendingTasks(); |
| 330 | 352 |
| 331 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 353 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 332 const IPC::Message* message = | 354 const IPC::Message* message = |
| 333 process()->sink().GetFirstMessageMatching(kMsgID); | 355 process()->sink().GetFirstMessageMatching(kMsgID); |
| 334 EXPECT_TRUE(message); | 356 EXPECT_TRUE(message); |
| 335 CredentialManagerMsg_SendCredential::Param param; | 357 CredentialManagerMsg_SendCredential::Param param; |
| 336 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 358 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 337 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 359 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); |
| 338 process()->sink().ClearMessages(); | 360 process()->sink().ClearMessages(); |
| 339 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 340 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 341 } | 361 } |
| 342 | 362 |
| 343 TEST_F(CredentialManagerDispatcherTest, | 363 TEST_F(CredentialManagerDispatcherTest, |
| 344 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | 364 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
| 345 client_->set_zero_click_enabled(false); | 365 client_->set_zero_click_enabled(false); |
| 346 store_->AddLogin(form_); | 366 store_->AddLogin(form_); |
| 347 | 367 |
| 348 std::vector<GURL> federations; | 368 std::vector<GURL> federations; |
| 369 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 370 .Times(testing::Exactly(1)); |
| 371 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 372 |
| 349 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 373 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 350 | 374 |
| 351 RunAllPendingTasks(); | 375 RunAllPendingTasks(); |
| 352 | 376 |
| 353 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 377 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 354 const IPC::Message* message = | 378 const IPC::Message* message = |
| 355 process()->sink().GetFirstMessageMatching(kMsgID); | 379 process()->sink().GetFirstMessageMatching(kMsgID); |
| 356 EXPECT_TRUE(message); | 380 EXPECT_TRUE(message); |
| 357 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | |
| 358 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 359 } | 381 } |
| 360 | 382 |
| 361 TEST_F( | 383 TEST_F( |
| 362 CredentialManagerDispatcherTest, | 384 CredentialManagerDispatcherTest, |
| 363 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { | 385 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { |
| 364 std::vector<GURL> federations; | 386 std::vector<GURL> federations; |
| 387 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 388 .Times(testing::Exactly(0)); |
| 389 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 390 |
| 365 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 391 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 366 | 392 |
| 367 RunAllPendingTasks(); | 393 RunAllPendingTasks(); |
| 368 | 394 |
| 369 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 395 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 370 const IPC::Message* message = | 396 const IPC::Message* message = |
| 371 process()->sink().GetFirstMessageMatching(kMsgID); | 397 process()->sink().GetFirstMessageMatching(kMsgID); |
| 372 EXPECT_TRUE(message); | 398 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; | 399 CredentialManagerMsg_SendCredential::Param send_param; |
| 376 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 400 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 377 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 401 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 378 } | 402 } |
| 379 | 403 |
| 380 TEST_F(CredentialManagerDispatcherTest, | 404 TEST_F(CredentialManagerDispatcherTest, |
| 381 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { | 405 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { |
| 382 store_->AddLogin(form_); | 406 store_->AddLogin(form_); |
| 383 | 407 |
| 384 std::vector<GURL> federations; | 408 std::vector<GURL> federations; |
| 409 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 410 .Times(testing::Exactly(0)); |
| 411 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1)); |
| 412 |
| 385 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 413 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 386 | 414 |
| 387 RunAllPendingTasks(); | 415 RunAllPendingTasks(); |
| 388 | 416 |
| 389 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 417 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 390 const IPC::Message* message = | 418 const IPC::Message* message = |
| 391 process()->sink().GetFirstMessageMatching(kMsgID); | 419 process()->sink().GetFirstMessageMatching(kMsgID); |
| 392 EXPECT_TRUE(message); | 420 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; | 421 CredentialManagerMsg_SendCredential::Param send_param; |
| 396 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 422 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 397 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); | 423 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); |
| 398 } | 424 } |
| 399 | 425 |
| 400 TEST_F(CredentialManagerDispatcherTest, | 426 TEST_F(CredentialManagerDispatcherTest, |
| 401 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | 427 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { |
| 402 store_->AddLogin(form_); | 428 store_->AddLogin(form_); |
| 403 store_->AddLogin(form2_); | 429 store_->AddLogin(form2_); |
| 404 | 430 |
| 405 std::vector<GURL> federations; | 431 std::vector<GURL> federations; |
| 432 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 433 .Times(testing::Exactly(0)); |
| 434 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 435 |
| 406 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 436 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 407 | 437 |
| 408 RunAllPendingTasks(); | 438 RunAllPendingTasks(); |
| 409 | 439 |
| 410 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 440 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 411 const IPC::Message* message = | 441 const IPC::Message* message = |
| 412 process()->sink().GetFirstMessageMatching(kMsgID); | 442 process()->sink().GetFirstMessageMatching(kMsgID); |
| 413 EXPECT_TRUE(message); | 443 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; | 444 CredentialManagerMsg_SendCredential::Param send_param; |
| 417 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 445 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 418 | 446 |
| 419 // With two items in the password store, we shouldn't get credentials back. | 447 // 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); | 448 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 421 } | 449 } |
| 422 | 450 |
| 423 TEST_F(CredentialManagerDispatcherTest, | 451 TEST_F(CredentialManagerDispatcherTest, |
| 424 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) { | 452 OnRequestCredentialWithZeroClickOnlyOnePasswordStore) { |
| 425 form_.skip_zero_click = true; | 453 form_.skip_zero_click = true; |
| 426 store_->AddLogin(form_); | 454 store_->AddLogin(form_); |
| 427 store_->AddLogin(form2_); | 455 store_->AddLogin(form2_); |
| 428 | 456 |
| 429 std::vector<GURL> federations; | 457 std::vector<GURL> federations; |
| 458 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 459 .Times(testing::Exactly(0)); |
| 460 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(1)); |
| 461 |
| 430 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 462 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 431 | 463 |
| 432 RunAllPendingTasks(); | 464 RunAllPendingTasks(); |
| 433 | 465 |
| 434 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 466 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 435 const IPC::Message* message = | 467 const IPC::Message* message = |
| 436 process()->sink().GetFirstMessageMatching(kMsgID); | 468 process()->sink().GetFirstMessageMatching(kMsgID); |
| 437 EXPECT_TRUE(message); | 469 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; | 470 CredentialManagerMsg_SendCredential::Param send_param; |
| 441 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 471 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 442 | 472 |
| 443 // We should get |form2_| back, as |form_| is marked as skipping zero-click. | 473 // 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); | 474 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); |
| 445 EXPECT_EQ(form2_.username_value, get<1>(send_param).id); | 475 EXPECT_EQ(form2_.username_value, get<1>(send_param).id); |
| 446 EXPECT_EQ(form2_.display_name, get<1>(send_param).name); | 476 EXPECT_EQ(form2_.display_name, get<1>(send_param).name); |
| 447 EXPECT_EQ(form2_.password_value, get<1>(send_param).password); | 477 EXPECT_EQ(form2_.password_value, get<1>(send_param).password); |
| 448 } | 478 } |
| 449 | 479 |
| 450 TEST_F(CredentialManagerDispatcherTest, | 480 TEST_F(CredentialManagerDispatcherTest, |
| 451 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { | 481 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { |
| 452 store_->AddLogin(cross_origin_form_); | 482 store_->AddLogin(cross_origin_form_); |
| 453 | 483 |
| 454 form_.skip_zero_click = true; | 484 form_.skip_zero_click = true; |
| 455 store_->AddLogin(form_); | 485 store_->AddLogin(form_); |
| 456 | 486 |
| 457 std::vector<GURL> federations; | 487 std::vector<GURL> federations; |
| 488 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 489 .Times(testing::Exactly(0)); |
| 490 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 491 |
| 458 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 492 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 459 | 493 |
| 460 RunAllPendingTasks(); | 494 RunAllPendingTasks(); |
| 461 | 495 |
| 462 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 496 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 463 const IPC::Message* message = | 497 const IPC::Message* message = |
| 464 process()->sink().GetFirstMessageMatching(kMsgID); | 498 process()->sink().GetFirstMessageMatching(kMsgID); |
| 465 EXPECT_TRUE(message); | 499 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; | 500 CredentialManagerMsg_SendCredential::Param send_param; |
| 469 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 501 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 470 | 502 |
| 471 // We only have cross-origin zero-click credentials; they should not be | 503 // We only have cross-origin zero-click credentials; they should not be |
| 472 // returned. | 504 // returned. |
| 473 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 505 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 474 } | 506 } |
| 475 | 507 |
| 476 TEST_F(CredentialManagerDispatcherTest, | 508 TEST_F(CredentialManagerDispatcherTest, |
| 477 CredentialManagerOnRequestCredentialWhileRequestPending) { | 509 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 478 client_->set_zero_click_enabled(false); | 510 client_->set_zero_click_enabled(false); |
| 479 store_->AddLogin(form_); | 511 store_->AddLogin(form_); |
| 480 | 512 |
| 481 std::vector<GURL> federations; | 513 std::vector<GURL> federations; |
| 514 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 515 .Times(testing::Exactly(0)); |
| 516 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 517 |
| 482 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 518 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 483 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 519 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 484 | 520 |
| 485 // Check that the second request triggered a rejection. | 521 // Check that the second request triggered a rejection. |
| 486 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | 522 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; |
| 487 const IPC::Message* message = | 523 const IPC::Message* message = |
| 488 process()->sink().GetFirstMessageMatching(kMsgID); | 524 process()->sink().GetFirstMessageMatching(kMsgID); |
| 489 EXPECT_TRUE(message); | 525 EXPECT_TRUE(message); |
| 526 |
| 490 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; | 527 CredentialManagerMsg_RejectCredentialRequest::Param reject_param; |
| 491 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); | 528 CredentialManagerMsg_RejectCredentialRequest::Read(message, &reject_param); |
| 492 EXPECT_EQ(blink::WebCredentialManagerError::ErrorTypePendingRequest, | 529 EXPECT_EQ(blink::WebCredentialManagerError::ErrorTypePendingRequest, |
| 493 get<1>(reject_param)); | 530 get<1>(reject_param)); |
| 494 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | 531 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 495 EXPECT_FALSE(client_->did_prompt_auto_signin()); | 532 .Times(testing::Exactly(1)); |
| 533 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 496 | 534 |
| 497 process()->sink().ClearMessages(); | 535 process()->sink().ClearMessages(); |
| 498 | 536 |
| 499 // Execute the PasswordStore asynchronousness. | 537 // Execute the PasswordStore asynchronousness. |
| 500 RunAllPendingTasks(); | 538 RunAllPendingTasks(); |
| 501 | 539 |
| 502 // Check that the first request resolves. | 540 // Check that the first request resolves. |
| 503 kMsgID = CredentialManagerMsg_SendCredential::ID; | 541 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 504 message = process()->sink().GetFirstMessageMatching(kMsgID); | 542 message = process()->sink().GetFirstMessageMatching(kMsgID); |
| 505 EXPECT_TRUE(message); | 543 EXPECT_TRUE(message); |
| 506 CredentialManagerMsg_SendCredential::Param send_param; | 544 CredentialManagerMsg_SendCredential::Param send_param; |
| 507 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 545 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 508 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | 546 EXPECT_NE(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); |
| 509 process()->sink().ClearMessages(); | 547 process()->sink().ClearMessages(); |
| 510 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | |
| 511 EXPECT_FALSE(client_->did_prompt_auto_signin()); | |
| 512 } | 548 } |
| 513 | 549 |
| 514 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { | 550 TEST_F(CredentialManagerDispatcherTest, ResetSkipZeroClickAfterPrompt) { |
| 515 // Turn on the global zero-click flag, and add two credentials in separate | 551 // Turn on the global zero-click flag, and add two credentials in separate |
| 516 // origins, both set to skip zero-click. | 552 // origins, both set to skip zero-click. |
| 517 client_->set_zero_click_enabled(true); | 553 client_->set_zero_click_enabled(true); |
| 518 form_.skip_zero_click = true; | 554 form_.skip_zero_click = true; |
| 519 store_->AddLogin(form_); | 555 store_->AddLogin(form_); |
| 520 cross_origin_form_.skip_zero_click = true; | 556 cross_origin_form_.skip_zero_click = true; |
| 521 store_->AddLogin(cross_origin_form_); | 557 store_->AddLogin(cross_origin_form_); |
| 522 | 558 |
| 523 // Execute the PasswordStore asynchronousness to ensure everything is | 559 // Execute the PasswordStore asynchronousness to ensure everything is |
| 524 // written before proceeding. | 560 // written before proceeding. |
| 525 RunAllPendingTasks(); | 561 RunAllPendingTasks(); |
| 526 | 562 |
| 527 // Sanity check. | 563 // Sanity check. |
| 528 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); | 564 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); |
| 529 EXPECT_EQ(2U, passwords.size()); | 565 EXPECT_EQ(2U, passwords.size()); |
| 530 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 566 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 531 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 567 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 532 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); | 568 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); |
| 533 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 569 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 534 | 570 |
| 535 // Trigger a request which should return the credential found in |form_|, and | 571 // Trigger a request which should return the credential found in |form_|, and |
| 536 // wait for it to process. | 572 // wait for it to process. |
| 537 std::vector<GURL> federations; | 573 std::vector<GURL> federations; |
| 574 // Check that the form in the database has been updated. `OnRequestCredential` |
| 575 // generates a call to prompt the user to choose a credential. |
| 576 // MockPasswordManagerClient mocks a user choice, and when users choose a |
| 577 // credential (and have the global zero-click flag enabled), we make sure that |
| 578 // they'll be logged in again next time. |
| 579 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 580 .Times(testing::Exactly(1)); |
| 581 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 582 |
| 538 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 583 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 539 RunAllPendingTasks(); | 584 RunAllPendingTasks(); |
| 540 | 585 |
| 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(); | 586 passwords = store_->stored_passwords(); |
| 549 EXPECT_EQ(2U, passwords.size()); | 587 EXPECT_EQ(2U, passwords.size()); |
| 550 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); | 588 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); |
| 551 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); | 589 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); |
| 552 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); | 590 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); |
| 553 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); | 591 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); |
| 554 } | 592 } |
| 555 | 593 |
| 556 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { | 594 TEST_F(CredentialManagerDispatcherTest, IncognitoZeroClickRequestCredential) { |
| 557 client_->set_off_the_record(true); | 595 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); |
| 558 store_->AddLogin(form_); | 596 store_->AddLogin(form_); |
| 559 | 597 |
| 560 std::vector<GURL> federations; | 598 std::vector<GURL> federations; |
| 599 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _, _)) |
| 600 .Times(testing::Exactly(0)); |
| 601 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr(_)).Times(testing::Exactly(0)); |
| 602 |
| 561 dispatcher()->OnRequestCredential(kRequestId, true, federations); | 603 dispatcher()->OnRequestCredential(kRequestId, true, federations); |
| 562 | 604 |
| 563 RunAllPendingTasks(); | 605 RunAllPendingTasks(); |
| 564 | 606 |
| 565 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 607 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 566 const IPC::Message* message = | 608 const IPC::Message* message = |
| 567 process()->sink().GetFirstMessageMatching(kMsgID); | 609 process()->sink().GetFirstMessageMatching(kMsgID); |
| 568 ASSERT_TRUE(message); | 610 ASSERT_TRUE(message); |
| 569 CredentialManagerMsg_SendCredential::Param param; | 611 CredentialManagerMsg_SendCredential::Param param; |
| 570 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 612 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 571 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 613 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 } | 614 } |
| 575 | 615 |
| 576 } // namespace password_manager | 616 } // namespace password_manager |
| OLD | NEW |