| 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" |
| 11 #include "components/password_manager/content/common/credential_manager_messages
.h" | 11 #include "components/password_manager/content/common/credential_manager_messages
.h" |
| 12 #include "components/password_manager/content/common/credential_manager_types.h" | 12 #include "components/password_manager/content/common/credential_manager_types.h" |
| 13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 13 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
| 14 #include "components/password_manager/core/browser/test_password_store.h" | 14 #include "components/password_manager/core/browser/test_password_store.h" |
| 15 #include "content/public/browser/web_contents.h" | |
| 16 #include "content/public/test/mock_render_process_host.h" | 15 #include "content/public/test/mock_render_process_host.h" |
| 17 #include "content/public/test/test_renderer_host.h" | 16 #include "content/public/test/test_renderer_host.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 19 |
| 21 using content::BrowserContext; | 20 using content::BrowserContext; |
| 22 using content::WebContents; | 21 using content::WebContents; |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 | 24 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 56 : public content::RenderViewHostTestHarness { | 55 : public content::RenderViewHostTestHarness { |
| 57 public: | 56 public: |
| 58 ContentCredentialManagerDispatcherTest() {} | 57 ContentCredentialManagerDispatcherTest() {} |
| 59 | 58 |
| 60 virtual void SetUp() OVERRIDE { | 59 virtual void SetUp() OVERRIDE { |
| 61 content::RenderViewHostTestHarness::SetUp(); | 60 content::RenderViewHostTestHarness::SetUp(); |
| 62 store_ = new TestPasswordStore; | 61 store_ = new TestPasswordStore; |
| 63 client_.reset(new TestPasswordManagerClient(store_.get())); | 62 client_.reset(new TestPasswordManagerClient(store_.get())); |
| 64 dispatcher_.reset( | 63 dispatcher_.reset( |
| 65 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); | 64 new ContentCredentialManagerDispatcher(web_contents(), client_.get())); |
| 66 | |
| 67 NavigateAndCommit(GURL("https://example.com/test.html")); | |
| 68 | |
| 69 form_.username_value = base::ASCIIToUTF16("Username"); | |
| 70 form_.display_name = base::ASCIIToUTF16("Display Name"); | |
| 71 form_.password_value = base::ASCIIToUTF16("Password"); | |
| 72 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | |
| 73 form_.signon_realm = form_.origin.spec(); | |
| 74 form_.scheme = autofill::PasswordForm::SCHEME_HTML; | |
| 75 } | 65 } |
| 76 | 66 |
| 77 virtual void TearDown() OVERRIDE { | 67 virtual void TearDown() OVERRIDE { |
| 78 store_->Shutdown(); | 68 store_->Shutdown(); |
| 79 content::RenderViewHostTestHarness::TearDown(); | 69 content::RenderViewHostTestHarness::TearDown(); |
| 80 } | 70 } |
| 81 | 71 |
| 82 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 72 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
| 83 | 73 |
| 84 protected: | 74 private: |
| 85 autofill::PasswordForm form_; | |
| 86 scoped_refptr<TestPasswordStore> store_; | 75 scoped_refptr<TestPasswordStore> store_; |
| 87 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; | 76 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; |
| 88 scoped_ptr<TestPasswordManagerClient> client_; | 77 scoped_ptr<TestPasswordManagerClient> client_; |
| 89 }; | 78 }; |
| 90 | 79 |
| 91 TEST_F(ContentCredentialManagerDispatcherTest, | 80 TEST_F(ContentCredentialManagerDispatcherTest, |
| 92 CredentialManagerOnNotifyFailedSignIn) { | 81 CredentialManagerOnNotifyFailedSignIn) { |
| 93 CredentialInfo info(base::ASCIIToUTF16("id"), | 82 CredentialInfo info(base::ASCIIToUTF16("id"), |
| 94 base::ASCIIToUTF16("name"), | 83 base::ASCIIToUTF16("name"), |
| 95 GURL("https://example.com/image.png")); | 84 GURL("https://example.com/image.png")); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 dispatcher()->OnNotifySignedOut(kRequestId); | 110 dispatcher()->OnNotifySignedOut(kRequestId); |
| 122 | 111 |
| 123 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; | 112 const uint32 kMsgID = CredentialManagerMsg_AcknowledgeSignedOut::ID; |
| 124 const IPC::Message* message = | 113 const IPC::Message* message = |
| 125 process()->sink().GetFirstMessageMatching(kMsgID); | 114 process()->sink().GetFirstMessageMatching(kMsgID); |
| 126 EXPECT_TRUE(message); | 115 EXPECT_TRUE(message); |
| 127 process()->sink().ClearMessages(); | 116 process()->sink().ClearMessages(); |
| 128 } | 117 } |
| 129 | 118 |
| 130 TEST_F(ContentCredentialManagerDispatcherTest, | 119 TEST_F(ContentCredentialManagerDispatcherTest, |
| 131 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { | 120 CredentialManagerOnRequestCredential) { |
| 132 std::vector<GURL> federations; | 121 std::vector<GURL> federations; |
| 133 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 122 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 134 | 123 |
| 135 RunAllPendingTasks(); | |
| 136 | |
| 137 const uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | |
| 138 const IPC::Message* message = | |
| 139 process()->sink().GetFirstMessageMatching(kMsgID); | |
| 140 EXPECT_TRUE(message); | |
| 141 process()->sink().ClearMessages(); | |
| 142 } | |
| 143 | |
| 144 TEST_F(ContentCredentialManagerDispatcherTest, | |
| 145 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | |
| 146 store_->AddLogin(form_); | |
| 147 | |
| 148 std::vector<GURL> federations; | |
| 149 dispatcher()->OnRequestCredential(kRequestId, false, federations); | |
| 150 | |
| 151 RunAllPendingTasks(); | 124 RunAllPendingTasks(); |
| 152 | 125 |
| 153 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 126 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 154 const IPC::Message* message = | 127 const IPC::Message* message = |
| 155 process()->sink().GetFirstMessageMatching(kMsgID); | 128 process()->sink().GetFirstMessageMatching(kMsgID); |
| 156 EXPECT_TRUE(message); | 129 EXPECT_TRUE(message); |
| 157 process()->sink().ClearMessages(); | 130 process()->sink().ClearMessages(); |
| 158 } | 131 } |
| 159 | 132 |
| 160 TEST_F(ContentCredentialManagerDispatcherTest, | 133 TEST_F(ContentCredentialManagerDispatcherTest, |
| 161 CredentialManagerOnRequestCredentialWhileRequestPending) { | 134 CredentialManagerOnRequestCredentialWhileRequestPending) { |
| 162 store_->AddLogin(form_); | |
| 163 | |
| 164 std::vector<GURL> federations; | 135 std::vector<GURL> federations; |
| 165 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 136 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 166 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 137 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 167 | 138 |
| 168 // Check that the second request triggered a rejection. | 139 // Check that the second request triggered a rejection. |
| 169 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; | 140 uint32 kMsgID = CredentialManagerMsg_RejectCredentialRequest::ID; |
| 170 const IPC::Message* message = | 141 const IPC::Message* message = |
| 171 process()->sink().GetFirstMessageMatching(kMsgID); | 142 process()->sink().GetFirstMessageMatching(kMsgID); |
| 172 EXPECT_TRUE(message); | 143 EXPECT_TRUE(message); |
| 173 process()->sink().ClearMessages(); | 144 process()->sink().ClearMessages(); |
| 174 | 145 |
| 175 // Execute the PasswordStore asynchronousness. | 146 // Execute the PasswordStore asynchronousness. |
| 176 RunAllPendingTasks(); | 147 RunAllPendingTasks(); |
| 177 | 148 |
| 178 // Check that the first request resolves. | 149 // Check that the first request resolves. |
| 179 kMsgID = CredentialManagerMsg_SendCredential::ID; | 150 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 180 message = process()->sink().GetFirstMessageMatching(kMsgID); | 151 message = process()->sink().GetFirstMessageMatching(kMsgID); |
| 181 EXPECT_TRUE(message); | 152 EXPECT_TRUE(message); |
| 182 process()->sink().ClearMessages(); | 153 process()->sink().ClearMessages(); |
| 183 } | 154 } |
| 184 | 155 |
| 185 } // namespace password_manager | 156 } // namespace password_manager |
| OLD | NEW |