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/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 // Chosen by fair dice roll. Guaranteed to be random. | 29 // Chosen by fair dice roll. Guaranteed to be random. |
| 30 const int kRequestId = 4; | 30 const int kRequestId = 4; |
| 31 | 31 |
| 32 class TestPasswordManagerClient | 32 class TestPasswordManagerClient |
| 33 : public password_manager::StubPasswordManagerClient { | 33 : public password_manager::StubPasswordManagerClient { |
| 34 public: | 34 public: |
| 35 TestPasswordManagerClient(password_manager::PasswordStore* store) | 35 TestPasswordManagerClient(password_manager::PasswordStore* store) |
| 36 : did_prompt_user_to_save_(false), | 36 : did_prompt_user_to_save_(false), |
| 37 did_prompt_user_to_choose_(false), | 37 did_prompt_user_to_choose_(false), |
| 38 is_off_the_record_(false), | 38 is_off_the_record_(false), |
| 39 is_zero_click_disabled_(false), | |
| 39 store_(store) {} | 40 store_(store) {} |
| 40 ~TestPasswordManagerClient() override {} | 41 ~TestPasswordManagerClient() override {} |
| 41 | 42 |
| 42 password_manager::PasswordStore* GetPasswordStore() override { | 43 password_manager::PasswordStore* GetPasswordStore() override { |
| 43 return store_; | 44 return store_; |
| 44 } | 45 } |
| 45 | 46 |
| 46 bool PromptUserToSavePassword( | 47 bool PromptUserToSavePassword( |
| 47 scoped_ptr<password_manager::PasswordFormManager> manager) override { | 48 scoped_ptr<password_manager::PasswordFormManager> manager) override { |
| 48 did_prompt_user_to_save_ = true; | 49 did_prompt_user_to_save_ = true; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 68 local_forms.empty() ? *federated_forms[0] : *local_entries[0], | 69 local_forms.empty() ? *federated_forms[0] : *local_entries[0], |
| 69 local_forms.empty() | 70 local_forms.empty() |
| 70 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED | 71 ? password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED |
| 71 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 72 : password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
| 72 base::MessageLoop::current()->PostTask(FROM_HERE, | 73 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 73 base::Bind(callback, info)); | 74 base::Bind(callback, info)); |
| 74 return true; | 75 return true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 bool IsOffTheRecord() override { return is_off_the_record_; } | 78 bool IsOffTheRecord() override { return is_off_the_record_; } |
| 79 bool IsZeroClickDisabled() override { return is_zero_click_disabled_; } | |
| 78 | 80 |
| 79 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } | 81 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } |
| 80 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } | 82 bool did_prompt_user_to_choose() const { return did_prompt_user_to_choose_; } |
| 81 | 83 |
| 82 password_manager::PasswordFormManager* pending_manager() const { | 84 password_manager::PasswordFormManager* pending_manager() const { |
| 83 return manager_.get(); | 85 return manager_.get(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void set_off_the_record(bool off_the_record) { | 88 void set_off_the_record(bool off_the_record) { |
| 87 is_off_the_record_ = off_the_record; | 89 is_off_the_record_ = off_the_record; |
| 88 } | 90 } |
| 89 | 91 |
| 92 void set_zero_click_disabled(bool zero_click_disabled) { | |
| 93 is_zero_click_disabled_ = zero_click_disabled; | |
| 94 } | |
| 95 | |
| 90 private: | 96 private: |
| 91 bool did_prompt_user_to_save_; | 97 bool did_prompt_user_to_save_; |
| 92 bool did_prompt_user_to_choose_; | 98 bool did_prompt_user_to_choose_; |
| 93 bool is_off_the_record_; | 99 bool is_off_the_record_; |
| 100 bool is_zero_click_disabled_; | |
| 94 password_manager::PasswordStore* store_; | 101 password_manager::PasswordStore* store_; |
| 95 scoped_ptr<password_manager::PasswordFormManager> manager_; | 102 scoped_ptr<password_manager::PasswordFormManager> manager_; |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 class TestCredentialManagerDispatcher | 105 class TestCredentialManagerDispatcher |
| 99 : public password_manager::CredentialManagerDispatcher { | 106 : public password_manager::CredentialManagerDispatcher { |
| 100 public: | 107 public: |
| 101 TestCredentialManagerDispatcher( | 108 TestCredentialManagerDispatcher( |
| 102 content::WebContents* web_contents, | 109 content::WebContents* web_contents, |
| 103 password_manager::PasswordManagerClient* client, | 110 password_manager::PasswordManagerClient* client, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 | 154 |
| 148 NavigateAndCommit(GURL("https://example.com/test.html")); | 155 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 149 | 156 |
| 150 form_.username_value = base::ASCIIToUTF16("Username"); | 157 form_.username_value = base::ASCIIToUTF16("Username"); |
| 151 form_.display_name = base::ASCIIToUTF16("Display Name"); | 158 form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 152 form_.password_value = base::ASCIIToUTF16("Password"); | 159 form_.password_value = base::ASCIIToUTF16("Password"); |
| 153 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 160 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 154 form_.signon_realm = form_.origin.spec(); | 161 form_.signon_realm = form_.origin.spec(); |
| 155 form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 162 form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 156 | 163 |
| 164 form2_.username_value = base::ASCIIToUTF16("Username 2"); | |
| 165 form2_.display_name = base::ASCIIToUTF16("Display Name 2"); | |
| 166 form2_.password_value = base::ASCIIToUTF16("Password 2"); | |
| 167 form2_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | |
| 168 form2_.signon_realm = form_.origin.spec(); | |
| 169 form2_.scheme = autofill::PasswordForm::SCHEME_HTML; | |
| 170 | |
| 157 cross_origin_form_.username_value = base::ASCIIToUTF16("Username"); | 171 cross_origin_form_.username_value = base::ASCIIToUTF16("Username"); |
| 158 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name"); | 172 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 159 cross_origin_form_.password_value = base::ASCIIToUTF16("Password"); | 173 cross_origin_form_.password_value = base::ASCIIToUTF16("Password"); |
| 160 cross_origin_form_.origin = GURL("https://example.net/"); | 174 cross_origin_form_.origin = GURL("https://example.net/"); |
| 161 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); | 175 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); |
| 162 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 176 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 163 | 177 |
| 164 store_->Clear(); | 178 store_->Clear(); |
| 165 EXPECT_TRUE(store_->IsEmpty()); | 179 EXPECT_TRUE(store_->IsEmpty()); |
| 166 } | 180 } |
| 167 | 181 |
| 168 void TearDown() override { | 182 void TearDown() override { |
| 169 store_->Shutdown(); | 183 store_->Shutdown(); |
| 170 content::RenderViewHostTestHarness::TearDown(); | 184 content::RenderViewHostTestHarness::TearDown(); |
| 171 } | 185 } |
| 172 | 186 |
| 173 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 187 CredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 174 | 188 |
| 175 protected: | 189 protected: |
| 176 autofill::PasswordForm form_; | 190 autofill::PasswordForm form_; |
| 191 autofill::PasswordForm form2_; | |
| 177 autofill::PasswordForm cross_origin_form_; | 192 autofill::PasswordForm cross_origin_form_; |
| 178 scoped_refptr<TestPasswordStore> store_; | 193 scoped_refptr<TestPasswordStore> store_; |
| 179 scoped_ptr<CredentialManagerDispatcher> dispatcher_; | 194 scoped_ptr<CredentialManagerDispatcher> dispatcher_; |
| 180 scoped_ptr<TestPasswordManagerClient> client_; | 195 scoped_ptr<TestPasswordManagerClient> client_; |
| 181 StubPasswordManagerDriver stub_driver_; | 196 StubPasswordManagerDriver stub_driver_; |
| 182 }; | 197 }; |
| 183 | 198 |
| 184 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { | 199 TEST_F(CredentialManagerDispatcherTest, CredentialManagerOnNotifyFailedSignIn) { |
| 185 CredentialInfo info; | 200 CredentialInfo info; |
| 186 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; | 201 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 EXPECT_TRUE(message); | 296 EXPECT_TRUE(message); |
| 282 CredentialManagerMsg_SendCredential::Param param; | 297 CredentialManagerMsg_SendCredential::Param param; |
| 283 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 298 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 284 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 299 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); |
| 285 process()->sink().ClearMessages(); | 300 process()->sink().ClearMessages(); |
| 286 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | 301 EXPECT_FALSE(client_->did_prompt_user_to_choose()); |
| 287 } | 302 } |
| 288 | 303 |
| 289 TEST_F(CredentialManagerDispatcherTest, | 304 TEST_F(CredentialManagerDispatcherTest, |
| 290 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | 305 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
| 306 client_->set_zero_click_disabled(true); | |
| 291 store_->AddLogin(form_); | 307 store_->AddLogin(form_); |
| 292 | 308 |
| 293 std::vector<GURL> federations; | 309 std::vector<GURL> federations; |
| 294 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 310 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 295 | 311 |
| 296 RunAllPendingTasks(); | 312 RunAllPendingTasks(); |
| 297 | 313 |
| 298 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 314 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 299 const IPC::Message* message = | 315 const IPC::Message* message = |
| 300 process()->sink().GetFirstMessageMatching(kMsgID); | 316 process()->sink().GetFirstMessageMatching(kMsgID); |
| 301 EXPECT_TRUE(message); | 317 EXPECT_TRUE(message); |
| 302 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | 318 EXPECT_TRUE(client_->did_prompt_user_to_choose()); |
| 303 } | 319 } |
| 304 | 320 |
| 321 TEST_F( | |
| 322 CredentialManagerDispatcherTest, | |
| 323 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { | |
|
vasilii
2015/01/28 16:14:59
optional: the test names became too long. I'd omit
| |
| 324 std::vector<GURL> federations; | |
| 325 dispatcher()->OnRequestCredential(kRequestId, true, federations); | |
| 326 | |
| 327 RunAllPendingTasks(); | |
| 328 | |
| 329 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 330 const IPC::Message* message = | |
| 331 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 332 EXPECT_TRUE(message); | |
| 333 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 334 CredentialManagerMsg_SendCredential::Param send_param; | |
| 335 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 336 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | |
| 337 } | |
| 338 | |
| 339 TEST_F(CredentialManagerDispatcherTest, | |
| 340 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { | |
| 341 store_->AddLogin(form_); | |
| 342 | |
| 343 std::vector<GURL> federations; | |
| 344 dispatcher()->OnRequestCredential(kRequestId, true, federations); | |
| 345 | |
| 346 RunAllPendingTasks(); | |
| 347 | |
| 348 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 349 const IPC::Message* message = | |
| 350 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 351 EXPECT_TRUE(message); | |
| 352 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 353 CredentialManagerMsg_SendCredential::Param send_param; | |
| 354 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 355 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_LOCAL, get<1>(send_param).type); | |
| 356 } | |
| 357 | |
| 358 TEST_F(CredentialManagerDispatcherTest, | |
| 359 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | |
| 360 store_->AddLogin(form_); | |
| 361 store_->AddLogin(form2_); | |
| 362 | |
| 363 std::vector<GURL> federations; | |
| 364 dispatcher()->OnRequestCredential(kRequestId, true, federations); | |
| 365 | |
| 366 RunAllPendingTasks(); | |
| 367 | |
| 368 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | |
| 369 const IPC::Message* message = | |
| 370 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 371 EXPECT_TRUE(message); | |
| 372 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | |
| 373 CredentialManagerMsg_SendCredential::Param send_param; | |
| 374 CredentialManagerMsg_SendCredential::Read(message, &send_param); | |
| 375 | |
| 376 // With two items in the password store, we shouldn't get credentials back. | |
| 377 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(send_param).type); | |
| 378 } | |
| 379 | |
| 305 TEST_F(CredentialManagerDispatcherTest, | 380 TEST_F(CredentialManagerDispatcherTest, |
| 306 CredentialManagerOnRequestCredentialWhileRequestPending) { | 381 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 382 client_->set_zero_click_disabled(true); | |
| 307 store_->AddLogin(form_); | 383 store_->AddLogin(form_); |
| 308 | 384 |
| 309 std::vector<GURL> federations; | 385 std::vector<GURL> federations; |
| 310 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 386 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 311 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 387 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 312 | 388 |
| 313 // Check that the second request triggered a rejection. | 389 // Check that the second request triggered a rejection. |
| 314 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | 390 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; |
| 315 const IPC::Message* message = | 391 const IPC::Message* message = |
| 316 process()->sink().GetFirstMessageMatching(kMsgID); | 392 process()->sink().GetFirstMessageMatching(kMsgID); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 const IPC::Message* message = | 426 const IPC::Message* message = |
| 351 process()->sink().GetFirstMessageMatching(kMsgID); | 427 process()->sink().GetFirstMessageMatching(kMsgID); |
| 352 ASSERT_TRUE(message); | 428 ASSERT_TRUE(message); |
| 353 CredentialManagerMsg_SendCredential::Param param; | 429 CredentialManagerMsg_SendCredential::Param param; |
| 354 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 430 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 355 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); | 431 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, get<1>(param).type); |
| 356 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | 432 EXPECT_FALSE(client_->did_prompt_user_to_choose()); |
| 357 } | 433 } |
| 358 | 434 |
| 359 } // namespace password_manager | 435 } // namespace password_manager |
| OLD | NEW |