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/renderer/credential_manager_client
.h" | 5 #include "components/password_manager/content/renderer/credential_manager_client
.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <tuple> | 10 #include <tuple> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "content/public/renderer/render_frame.h" | 18 #include "content/public/renderer/render_frame.h" |
19 #include "content/public/renderer/render_view.h" | 19 #include "content/public/renderer/render_view.h" |
20 #include "content/public/test/render_view_test.h" | 20 #include "content/public/test/render_view_test.h" |
21 #include "mojo/public/cpp/bindings/binding_set.h" | 21 #include "mojo/public/cpp/bindings/binding_set.h" |
22 #include "services/service_manager/public/cpp/interface_provider.h" | 22 #include "services/service_manager/public/cpp/interface_provider.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/WebKit/public/platform/WebCredential.h" | 24 #include "third_party/WebKit/public/platform/WebCredential.h" |
25 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" | 25 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" |
26 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" | 26 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" |
| 27 #include "third_party/WebKit/public/platform/WebCredentialMediationRequirement.h
" |
27 #include "third_party/WebKit/public/platform/WebPasswordCredential.h" | 28 #include "third_party/WebKit/public/platform/WebPasswordCredential.h" |
28 | 29 |
29 namespace password_manager { | 30 namespace password_manager { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const char kTestCredentialPassword[] = "https://password.com/"; | 34 const char kTestCredentialPassword[] = "https://password.com/"; |
34 const char kTestCredentialEmpty[] = "https://empty.com/"; | 35 const char kTestCredentialEmpty[] = "https://empty.com/"; |
35 const char kTestCredentialReject[] = "https://reject.com/"; | 36 const char kTestCredentialReject[] = "https://reject.com/"; |
36 | 37 |
(...skipping 10 matching lines...) Expand all Loading... |
47 // mojom::CredentialManager methods: | 48 // mojom::CredentialManager methods: |
48 void Store(const CredentialInfo& credential, | 49 void Store(const CredentialInfo& credential, |
49 StoreCallback callback) override { | 50 StoreCallback callback) override { |
50 std::move(callback).Run(); | 51 std::move(callback).Run(); |
51 } | 52 } |
52 | 53 |
53 void RequireUserMediation(RequireUserMediationCallback callback) override { | 54 void RequireUserMediation(RequireUserMediationCallback callback) override { |
54 std::move(callback).Run(); | 55 std::move(callback).Run(); |
55 } | 56 } |
56 | 57 |
57 void Get(bool zero_click_only, | 58 void Get(CredentialMediationRequirement mediation, |
58 bool include_passwords, | 59 bool include_passwords, |
59 const std::vector<GURL>& federations, | 60 const std::vector<GURL>& federations, |
60 GetCallback callback) override { | 61 GetCallback callback) override { |
61 const std::string& url = federations[0].spec(); | 62 const std::string& url = federations[0].spec(); |
62 | 63 |
63 if (url == kTestCredentialPassword) { | 64 if (url == kTestCredentialPassword) { |
64 CredentialInfo info; | 65 CredentialInfo info; |
65 info.type = CredentialType::CREDENTIAL_TYPE_PASSWORD; | 66 info.type = CredentialType::CREDENTIAL_TYPE_PASSWORD; |
66 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info); | 67 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info); |
67 } else if (url == kTestCredentialEmpty) { | 68 } else if (url == kTestCredentialEmpty) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 202 |
202 EXPECT_TRUE(callback_succeeded()); | 203 EXPECT_TRUE(callback_succeeded()); |
203 EXPECT_FALSE(callback_errored()); | 204 EXPECT_FALSE(callback_errored()); |
204 } | 205 } |
205 | 206 |
206 TEST_F(CredentialManagerClientTest, SendRequestCredential) { | 207 TEST_F(CredentialManagerClientTest, SendRequestCredential) { |
207 std::unique_ptr<TestRequestCallbacks> callbacks( | 208 std::unique_ptr<TestRequestCallbacks> callbacks( |
208 new TestRequestCallbacks(this)); | 209 new TestRequestCallbacks(this)); |
209 std::vector<GURL> federations; | 210 std::vector<GURL> federations; |
210 federations.push_back(GURL(kTestCredentialPassword)); | 211 federations.push_back(GURL(kTestCredentialPassword)); |
211 client_->DispatchGet(false, true, federations, callbacks.release()); | 212 client_->DispatchGet(blink::WebCredentialMediationRequirement::kOptional, |
| 213 true, federations, callbacks.release()); |
212 | 214 |
213 RunAllPendingTasks(); | 215 RunAllPendingTasks(); |
214 | 216 |
215 EXPECT_TRUE(callback_succeeded()); | 217 EXPECT_TRUE(callback_succeeded()); |
216 EXPECT_FALSE(callback_errored()); | 218 EXPECT_FALSE(callback_errored()); |
217 EXPECT_TRUE(credential_); | 219 EXPECT_TRUE(credential_); |
218 EXPECT_EQ("password", credential_->GetType()); | 220 EXPECT_EQ("password", credential_->GetType()); |
219 } | 221 } |
220 | 222 |
221 TEST_F(CredentialManagerClientTest, SendRequestCredentialEmpty) { | 223 TEST_F(CredentialManagerClientTest, SendRequestCredentialEmpty) { |
222 std::unique_ptr<TestRequestCallbacks> callbacks( | 224 std::unique_ptr<TestRequestCallbacks> callbacks( |
223 new TestRequestCallbacks(this)); | 225 new TestRequestCallbacks(this)); |
224 std::vector<GURL> federations; | 226 std::vector<GURL> federations; |
225 federations.push_back(GURL(kTestCredentialEmpty)); | 227 federations.push_back(GURL(kTestCredentialEmpty)); |
226 client_->DispatchGet(false, true, federations, callbacks.release()); | 228 client_->DispatchGet(blink::WebCredentialMediationRequirement::kOptional, |
| 229 true, federations, callbacks.release()); |
227 | 230 |
228 RunAllPendingTasks(); | 231 RunAllPendingTasks(); |
229 | 232 |
230 EXPECT_TRUE(callback_succeeded()); | 233 EXPECT_TRUE(callback_succeeded()); |
231 EXPECT_FALSE(callback_errored()); | 234 EXPECT_FALSE(callback_errored()); |
232 EXPECT_FALSE(credential_); | 235 EXPECT_FALSE(credential_); |
233 } | 236 } |
234 | 237 |
235 TEST_F(CredentialManagerClientTest, SendRequestCredentialReject) { | 238 TEST_F(CredentialManagerClientTest, SendRequestCredentialReject) { |
236 std::unique_ptr<TestRequestCallbacks> callbacks( | 239 std::unique_ptr<TestRequestCallbacks> callbacks( |
237 new TestRequestCallbacks(this)); | 240 new TestRequestCallbacks(this)); |
238 std::vector<GURL> federations; | 241 std::vector<GURL> federations; |
239 federations.push_back(GURL(kTestCredentialReject)); | 242 federations.push_back(GURL(kTestCredentialReject)); |
240 client_->DispatchGet(false, true, federations, callbacks.release()); | 243 client_->DispatchGet(blink::WebCredentialMediationRequirement::kOptional, |
| 244 true, federations, callbacks.release()); |
241 | 245 |
242 RunAllPendingTasks(); | 246 RunAllPendingTasks(); |
243 | 247 |
244 EXPECT_FALSE(callback_succeeded()); | 248 EXPECT_FALSE(callback_succeeded()); |
245 EXPECT_TRUE(callback_errored()); | 249 EXPECT_TRUE(callback_errored()); |
246 EXPECT_FALSE(credential_); | 250 EXPECT_FALSE(credential_); |
247 EXPECT_EQ(blink::WebCredentialManagerError:: | 251 EXPECT_EQ(blink::WebCredentialManagerError:: |
248 kWebCredentialManagerPasswordStoreUnavailableError, | 252 kWebCredentialManagerPasswordStoreUnavailableError, |
249 error_); | 253 error_); |
250 } | 254 } |
251 | 255 |
252 } // namespace password_manager | 256 } // namespace password_manager |
OLD | NEW |