| 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/content_credential_manager
_dispatcher.h" | 5 #include "components/password_manager/content/browser/content_credential_manager
_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 : public password_manager::StubPasswordManagerClient { | 32 : public password_manager::StubPasswordManagerClient { |
| 33 public: | 33 public: |
| 34 TestPasswordManagerClient(password_manager::PasswordStore* store) | 34 TestPasswordManagerClient(password_manager::PasswordStore* store) |
| 35 : did_prompt_user_to_save_(false), store_(store) {} | 35 : did_prompt_user_to_save_(false), store_(store) {} |
| 36 ~TestPasswordManagerClient() override {} | 36 ~TestPasswordManagerClient() override {} |
| 37 | 37 |
| 38 password_manager::PasswordStore* GetPasswordStore() override { | 38 password_manager::PasswordStore* GetPasswordStore() override { |
| 39 return store_; | 39 return store_; |
| 40 } | 40 } |
| 41 | 41 |
| 42 password_manager::PasswordManagerDriver* GetDriver() override { | |
| 43 return &driver_; | |
| 44 } | |
| 45 | |
| 46 bool PromptUserToSavePassword( | 42 bool PromptUserToSavePassword( |
| 47 scoped_ptr<password_manager::PasswordFormManager> manager) override { | 43 scoped_ptr<password_manager::PasswordFormManager> manager) override { |
| 48 did_prompt_user_to_save_ = true; | 44 did_prompt_user_to_save_ = true; |
| 49 manager_.reset(manager.release()); | 45 manager_.reset(manager.release()); |
| 50 return true; | 46 return true; |
| 51 } | 47 } |
| 52 | 48 |
| 53 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } | 49 bool did_prompt_user_to_save() const { return did_prompt_user_to_save_; } |
| 54 | 50 |
| 55 password_manager::PasswordFormManager* pending_manager() const { | 51 password_manager::PasswordFormManager* pending_manager() const { |
| 56 return manager_.get(); | 52 return manager_.get(); |
| 57 } | 53 } |
| 58 | 54 |
| 59 private: | 55 private: |
| 60 bool did_prompt_user_to_save_; | 56 bool did_prompt_user_to_save_; |
| 61 password_manager::PasswordStore* store_; | 57 password_manager::PasswordStore* store_; |
| 62 password_manager::StubPasswordManagerDriver driver_; | |
| 63 scoped_ptr<password_manager::PasswordFormManager> manager_; | 58 scoped_ptr<password_manager::PasswordFormManager> manager_; |
| 64 }; | 59 }; |
| 65 | 60 |
| 66 void RunAllPendingTasks() { | 61 void RunAllPendingTasks() { |
| 67 base::RunLoop run_loop; | 62 base::RunLoop run_loop; |
| 68 base::MessageLoop::current()->PostTask( | 63 base::MessageLoop::current()->PostTask( |
| 69 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | 64 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 70 run_loop.Run(); | 65 run_loop.Run(); |
| 71 } | 66 } |
| 72 | 67 |
| 73 } // namespace | 68 } // namespace |
| 74 | 69 |
| 75 namespace password_manager { | 70 namespace password_manager { |
| 76 | 71 |
| 77 class ContentCredentialManagerDispatcherTest | 72 class ContentCredentialManagerDispatcherTest |
| 78 : public content::RenderViewHostTestHarness { | 73 : public content::RenderViewHostTestHarness { |
| 79 public: | 74 public: |
| 80 ContentCredentialManagerDispatcherTest() {} | 75 ContentCredentialManagerDispatcherTest() {} |
| 81 | 76 |
| 82 void SetUp() override { | 77 void SetUp() override { |
| 83 content::RenderViewHostTestHarness::SetUp(); | 78 content::RenderViewHostTestHarness::SetUp(); |
| 84 store_ = new TestPasswordStore; | 79 store_ = new TestPasswordStore; |
| 85 client_.reset(new TestPasswordManagerClient(store_.get())); | 80 client_.reset(new TestPasswordManagerClient(store_.get())); |
| 86 dispatcher_.reset( | 81 dispatcher_.reset( |
| 87 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); | 82 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); |
| 83 dispatcher_->set_password_manager_driver(&stub_driver_); |
| 88 | 84 |
| 89 NavigateAndCommit(GURL("https://example.com/test.html")); | 85 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 90 | 86 |
| 91 form_.username_value = base::ASCIIToUTF16("Username"); | 87 form_.username_value = base::ASCIIToUTF16("Username"); |
| 92 form_.display_name = base::ASCIIToUTF16("Display Name"); | 88 form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 93 form_.password_value = base::ASCIIToUTF16("Password"); | 89 form_.password_value = base::ASCIIToUTF16("Password"); |
| 94 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 90 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 95 form_.signon_realm = form_.origin.spec(); | 91 form_.signon_realm = form_.origin.spec(); |
| 96 form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 92 form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 97 | 93 |
| 98 store_->Clear(); | 94 store_->Clear(); |
| 99 EXPECT_TRUE(store_->IsEmpty()); | 95 EXPECT_TRUE(store_->IsEmpty()); |
| 100 } | 96 } |
| 101 | 97 |
| 102 void TearDown() override { | 98 void TearDown() override { |
| 103 store_->Shutdown(); | 99 store_->Shutdown(); |
| 104 content::RenderViewHostTestHarness::TearDown(); | 100 content::RenderViewHostTestHarness::TearDown(); |
| 105 } | 101 } |
| 106 | 102 |
| 107 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 103 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 108 | 104 |
| 109 protected: | 105 protected: |
| 110 autofill::PasswordForm form_; | 106 autofill::PasswordForm form_; |
| 111 scoped_refptr<TestPasswordStore> store_; | 107 scoped_refptr<TestPasswordStore> store_; |
| 112 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; | 108 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; |
| 113 scoped_ptr<TestPasswordManagerClient> client_; | 109 scoped_ptr<TestPasswordManagerClient> client_; |
| 110 StubPasswordManagerDriver stub_driver_; |
| 114 }; | 111 }; |
| 115 | 112 |
| 116 TEST_F(ContentCredentialManagerDispatcherTest, | 113 TEST_F(ContentCredentialManagerDispatcherTest, |
| 117 CredentialManagerOnNotifyFailedSignIn) { | 114 CredentialManagerOnNotifyFailedSignIn) { |
| 118 CredentialInfo info; | 115 CredentialInfo info; |
| 119 info.type = CREDENTIAL_TYPE_LOCAL; | 116 info.type = CREDENTIAL_TYPE_LOCAL; |
| 120 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); | 117 dispatcher()->OnNotifyFailedSignIn(kRequestId, info); |
| 121 | 118 |
| 122 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; | 119 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeFailedSignIn::ID; |
| 123 const IPC::Message* message = | 120 const IPC::Message* message = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 message = process()->sink().GetFirstMessageMatching(kMsgID); | 223 message = process()->sink().GetFirstMessageMatching(kMsgID); |
| 227 EXPECT_TRUE(message); | 224 EXPECT_TRUE(message); |
| 228 CredentialManagerMsg_SendCredential::Param send_param; | 225 CredentialManagerMsg_SendCredential::Param send_param; |
| 229 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 226 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 230 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 227 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
| 231 EXPECT_NE(CREDENTIAL_TYPE_EMPTY, send_param.b.type); | 228 EXPECT_NE(CREDENTIAL_TYPE_EMPTY, send_param.b.type); |
| 232 process()->sink().ClearMessages(); | 229 process()->sink().ClearMessages(); |
| 233 } | 230 } |
| 234 | 231 |
| 235 } // namespace password_manager | 232 } // namespace password_manager |
| OLD | NEW |