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/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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 131 |
132 NavigateAndCommit(GURL("https://example.com/test.html")); | 132 NavigateAndCommit(GURL("https://example.com/test.html")); |
133 | 133 |
134 form_.username_value = base::ASCIIToUTF16("Username"); | 134 form_.username_value = base::ASCIIToUTF16("Username"); |
135 form_.display_name = base::ASCIIToUTF16("Display Name"); | 135 form_.display_name = base::ASCIIToUTF16("Display Name"); |
136 form_.password_value = base::ASCIIToUTF16("Password"); | 136 form_.password_value = base::ASCIIToUTF16("Password"); |
137 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 137 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
138 form_.signon_realm = form_.origin.spec(); | 138 form_.signon_realm = form_.origin.spec(); |
139 form_.scheme = autofill::PasswordForm::SCHEME_HTML; | 139 form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
140 | 140 |
| 141 cross_origin_form_.username_value = base::ASCIIToUTF16("Username"); |
| 142 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 143 cross_origin_form_.password_value = base::ASCIIToUTF16("Password"); |
| 144 cross_origin_form_.origin = GURL("https://example.net/"); |
| 145 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); |
| 146 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; |
| 147 |
141 store_->Clear(); | 148 store_->Clear(); |
142 EXPECT_TRUE(store_->IsEmpty()); | 149 EXPECT_TRUE(store_->IsEmpty()); |
143 } | 150 } |
144 | 151 |
145 void TearDown() override { | 152 void TearDown() override { |
146 store_->Shutdown(); | 153 store_->Shutdown(); |
147 content::RenderViewHostTestHarness::TearDown(); | 154 content::RenderViewHostTestHarness::TearDown(); |
148 } | 155 } |
149 | 156 |
150 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } | 157 ContentCredentialManagerDispatcher* dispatcher() { return dispatcher_.get(); } |
151 | 158 |
152 protected: | 159 protected: |
153 autofill::PasswordForm form_; | 160 autofill::PasswordForm form_; |
| 161 autofill::PasswordForm cross_origin_form_; |
154 scoped_refptr<TestPasswordStore> store_; | 162 scoped_refptr<TestPasswordStore> store_; |
155 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; | 163 scoped_ptr<ContentCredentialManagerDispatcher> dispatcher_; |
156 scoped_ptr<TestPasswordManagerClient> client_; | 164 scoped_ptr<TestPasswordManagerClient> client_; |
157 StubPasswordManagerDriver stub_driver_; | 165 StubPasswordManagerDriver stub_driver_; |
158 }; | 166 }; |
159 | 167 |
160 TEST_F(ContentCredentialManagerDispatcherTest, | 168 TEST_F(ContentCredentialManagerDispatcherTest, |
161 CredentialManagerOnNotifyFailedSignIn) { | 169 CredentialManagerOnNotifyFailedSignIn) { |
162 CredentialInfo info; | 170 CredentialInfo info; |
163 info.type = CREDENTIAL_TYPE_LOCAL; | 171 info.type = CREDENTIAL_TYPE_LOCAL; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 process()->sink().GetFirstMessageMatching(kMsgID); | 229 process()->sink().GetFirstMessageMatching(kMsgID); |
222 EXPECT_TRUE(message); | 230 EXPECT_TRUE(message); |
223 CredentialManagerMsg_SendCredential::Param param; | 231 CredentialManagerMsg_SendCredential::Param param; |
224 CredentialManagerMsg_SendCredential::Read(message, ¶m); | 232 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
225 EXPECT_EQ(CREDENTIAL_TYPE_EMPTY, param.b.type); | 233 EXPECT_EQ(CREDENTIAL_TYPE_EMPTY, param.b.type); |
226 process()->sink().ClearMessages(); | 234 process()->sink().ClearMessages(); |
227 EXPECT_FALSE(client_->did_prompt_user_to_choose()); | 235 EXPECT_FALSE(client_->did_prompt_user_to_choose()); |
228 } | 236 } |
229 | 237 |
230 TEST_F(ContentCredentialManagerDispatcherTest, | 238 TEST_F(ContentCredentialManagerDispatcherTest, |
| 239 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { |
| 240 store_->AddLogin(cross_origin_form_); |
| 241 |
| 242 std::vector<GURL> federations; |
| 243 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
| 244 |
| 245 RunAllPendingTasks(); |
| 246 |
| 247 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
| 248 const IPC::Message* message = |
| 249 process()->sink().GetFirstMessageMatching(kMsgID); |
| 250 EXPECT_TRUE(message); |
| 251 CredentialManagerMsg_SendCredential::Param param; |
| 252 CredentialManagerMsg_SendCredential::Read(message, ¶m); |
| 253 EXPECT_EQ(CREDENTIAL_TYPE_EMPTY, param.b.type); |
| 254 process()->sink().ClearMessages(); |
| 255 EXPECT_FALSE(client_->did_prompt_user_to_choose()); |
| 256 } |
| 257 |
| 258 TEST_F(ContentCredentialManagerDispatcherTest, |
231 CredentialManagerOnRequestCredentialWithFullPasswordStore) { | 259 CredentialManagerOnRequestCredentialWithFullPasswordStore) { |
232 store_->AddLogin(form_); | 260 store_->AddLogin(form_); |
233 | 261 |
234 std::vector<GURL> federations; | 262 std::vector<GURL> federations; |
235 dispatcher()->OnRequestCredential(kRequestId, false, federations); | 263 dispatcher()->OnRequestCredential(kRequestId, false, federations); |
236 | 264 |
237 RunAllPendingTasks(); | 265 RunAllPendingTasks(); |
238 | 266 |
239 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; | 267 const uint32 kMsgID = CredentialManagerMsg_SendCredential::ID; |
240 const IPC::Message* message = | 268 const IPC::Message* message = |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 EXPECT_TRUE(message); | 301 EXPECT_TRUE(message); |
274 CredentialManagerMsg_SendCredential::Param send_param; | 302 CredentialManagerMsg_SendCredential::Param send_param; |
275 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 303 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
276 CredentialManagerMsg_SendCredential::Read(message, &send_param); | 304 CredentialManagerMsg_SendCredential::Read(message, &send_param); |
277 EXPECT_NE(CREDENTIAL_TYPE_EMPTY, send_param.b.type); | 305 EXPECT_NE(CREDENTIAL_TYPE_EMPTY, send_param.b.type); |
278 process()->sink().ClearMessages(); | 306 process()->sink().ClearMessages(); |
279 EXPECT_TRUE(client_->did_prompt_user_to_choose()); | 307 EXPECT_TRUE(client_->did_prompt_user_to_choose()); |
280 } | 308 } |
281 | 309 |
282 } // namespace password_manager | 310 } // namespace password_manager |
OLD | NEW |