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/common/credential_manager_messages
.h" | 5 #include "components/password_manager/content/common/credential_manager_messages
.h" |
6 #include "components/password_manager/content/renderer/credential_manager_client
.h" | 6 #include "components/password_manager/content/renderer/credential_manager_client
.h" |
7 #include "components/password_manager/content/renderer/test_credential_manager_c
lient.h" | 7 #include "components/password_manager/content/renderer/test_credential_manager_c
lient.h" |
8 #include "content/public/test/mock_render_thread.h" | 8 #include "content/public/test/mock_render_thread.h" |
9 #include "content/test/blink_test_environment.h" | 9 #include "content/test/blink_test_environment.h" |
10 #include "ipc/ipc_test_sink.h" | 10 #include "ipc/ipc_test_sink.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/public/platform/WebCredential.h" | 12 #include "third_party/WebKit/public/platform/WebCredential.h" |
13 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" | 13 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" |
14 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" | 14 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" |
15 | 15 |
16 namespace password_manager { | 16 namespace password_manager { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class CredentialManagerClientTest : public testing::Test { | 20 class CredentialManagerClientTest : public testing::Test { |
21 public: | 21 public: |
22 CredentialManagerClientTest() | 22 CredentialManagerClientTest() |
23 : callback_errored_(false), | 23 : callback_errored_(false), |
24 callback_succeeded_(false) {} | 24 callback_succeeded_(false) { |
| 25 blink::WebString string = blink::WebString::fromUTF8(""); |
| 26 GURL url("https://example.com/image"); |
| 27 credential_.reset(new blink::WebCredential(string, string, url)); |
| 28 } |
25 virtual ~CredentialManagerClientTest() {} | 29 virtual ~CredentialManagerClientTest() {} |
26 | 30 |
27 static void SetUpTestCase() { content::SetUpBlinkTestEnvironment(); } | 31 static void SetUpTestCase() { content::SetUpBlinkTestEnvironment(); } |
28 | 32 |
29 static void TearDownTestCase() { content::TearDownBlinkTestEnvironment(); } | 33 static void TearDownTestCase() { content::TearDownBlinkTestEnvironment(); } |
30 | 34 |
31 IPC::TestSink& sink() { return render_thread_.sink(); } | 35 IPC::TestSink& sink() { return render_thread_.sink(); } |
32 | 36 |
| 37 blink::WebCredential* credential() { return credential_.get(); } |
| 38 |
33 // The browser's response to any of the messages the client sends must contain | 39 // The browser's response to any of the messages the client sends must contain |
34 // a request ID so that the client knows which request is being serviced. This | 40 // a request ID so that the client knows which request is being serviced. This |
35 // method grabs the ID from an outgoing |message_id| message, and sets the | 41 // method grabs the ID from an outgoing |message_id| message, and sets the |
36 // |request_id| param to its value. If no request ID can be found, the method | 42 // |request_id| param to its value. If no request ID can be found, the method |
37 // returns false, and the |request_id| is set to -1. | 43 // returns false, and the |request_id| is set to -1. |
38 // | 44 // |
39 // Clears any pending messages upon return. | 45 // Clears any pending messages upon return. |
40 bool ExtractRequestId(uint32 message_id, int& request_id) { | 46 bool ExtractRequestId(uint32 message_id, int& request_id) { |
41 request_id = -1; | 47 request_id = -1; |
42 const IPC::Message* message = sink().GetFirstMessageMatching(message_id); | 48 const IPC::Message* message = sink().GetFirstMessageMatching(message_id); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 content::MockRenderThread render_thread_; | 94 content::MockRenderThread render_thread_; |
89 TestCredentialManagerClient client_; | 95 TestCredentialManagerClient client_; |
90 | 96 |
91 // True if a message's callback's 'onSuccess'/'onError' methods were called, | 97 // True if a message's callback's 'onSuccess'/'onError' methods were called, |
92 // false otherwise. We put these on the test object rather than on the | 98 // false otherwise. We put these on the test object rather than on the |
93 // Test*Callbacks objects because ownership of those objects passes into the | 99 // Test*Callbacks objects because ownership of those objects passes into the |
94 // client, which destroys the callbacks after calling them to resolve the | 100 // client, which destroys the callbacks after calling them to resolve the |
95 // pending Blink-side Promise. | 101 // pending Blink-side Promise. |
96 bool callback_errored_; | 102 bool callback_errored_; |
97 bool callback_succeeded_; | 103 bool callback_succeeded_; |
| 104 |
| 105 scoped_ptr<blink::WebCredential> credential_; |
98 }; | 106 }; |
99 | 107 |
100 class TestNotificationCallbacks | 108 class TestNotificationCallbacks |
101 : public blink::WebCredentialManagerClient::NotificationCallbacks { | 109 : public blink::WebCredentialManagerClient::NotificationCallbacks { |
102 public: | 110 public: |
103 explicit TestNotificationCallbacks(CredentialManagerClientTest* test) | 111 explicit TestNotificationCallbacks(CredentialManagerClientTest* test) |
104 : test_(test) { | 112 : test_(test) { |
105 } | 113 } |
106 | 114 |
107 virtual ~TestNotificationCallbacks() {} | 115 virtual ~TestNotificationCallbacks() {} |
(...skipping 29 matching lines...) Expand all Loading... |
137 CredentialManagerClientTest* test_; | 145 CredentialManagerClientTest* test_; |
138 }; | 146 }; |
139 | 147 |
140 } // namespace | 148 } // namespace |
141 | 149 |
142 TEST_F(CredentialManagerClientTest, SendNotifyFailedSignIn) { | 150 TEST_F(CredentialManagerClientTest, SendNotifyFailedSignIn) { |
143 int request_id; | 151 int request_id; |
144 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, | 152 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, |
145 request_id)); | 153 request_id)); |
146 | 154 |
147 blink::WebCredential credential( | |
148 "id", "user", GURL("https://example.com/img.png")); | |
149 scoped_ptr<TestNotificationCallbacks> callbacks( | 155 scoped_ptr<TestNotificationCallbacks> callbacks( |
150 new TestNotificationCallbacks(this)); | 156 new TestNotificationCallbacks(this)); |
151 client_.dispatchFailedSignIn(credential, callbacks.release()); | 157 client_.dispatchFailedSignIn(*credential(), callbacks.release()); |
152 | 158 |
153 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, | 159 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, |
154 request_id)); | 160 request_id)); |
155 | 161 |
156 client_.OnAcknowledgeFailedSignIn(request_id); | 162 client_.OnAcknowledgeFailedSignIn(request_id); |
157 EXPECT_TRUE(callback_succeeded()); | 163 EXPECT_TRUE(callback_succeeded()); |
158 EXPECT_FALSE(callback_errored()); | 164 EXPECT_FALSE(callback_errored()); |
159 } | 165 } |
160 | 166 |
161 TEST_F(CredentialManagerClientTest, SendNotifySignedIn) { | 167 TEST_F(CredentialManagerClientTest, SendNotifySignedIn) { |
162 int request_id; | 168 int request_id; |
163 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, | 169 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, |
164 request_id)); | 170 request_id)); |
165 | 171 |
166 blink::WebCredential credential( | |
167 "id", "user", GURL("https://example.com/img.png")); | |
168 scoped_ptr<TestNotificationCallbacks> callbacks( | 172 scoped_ptr<TestNotificationCallbacks> callbacks( |
169 new TestNotificationCallbacks(this)); | 173 new TestNotificationCallbacks(this)); |
170 client_.dispatchSignedIn(credential, callbacks.release()); | 174 client_.dispatchSignedIn(*credential(), callbacks.release()); |
171 | 175 |
172 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, | 176 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, |
173 request_id)); | 177 request_id)); |
174 | 178 |
175 client_.OnAcknowledgeSignedIn(request_id); | 179 client_.OnAcknowledgeSignedIn(request_id); |
176 EXPECT_TRUE(callback_succeeded()); | 180 EXPECT_TRUE(callback_succeeded()); |
177 EXPECT_FALSE(callback_errored()); | 181 EXPECT_FALSE(callback_errored()); |
178 } | 182 } |
179 | 183 |
180 TEST_F(CredentialManagerClientTest, SendNotifySignedOut) { | 184 TEST_F(CredentialManagerClientTest, SendNotifySignedOut) { |
(...skipping 25 matching lines...) Expand all Loading... |
206 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 210 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
207 request_id)); | 211 request_id)); |
208 | 212 |
209 CredentialInfo info; | 213 CredentialInfo info; |
210 client_.OnSendCredential(request_id, info); | 214 client_.OnSendCredential(request_id, info); |
211 EXPECT_TRUE(callback_succeeded()); | 215 EXPECT_TRUE(callback_succeeded()); |
212 EXPECT_FALSE(callback_errored()); | 216 EXPECT_FALSE(callback_errored()); |
213 } | 217 } |
214 | 218 |
215 } // namespace password_manager | 219 } // namespace password_manager |
OLD | NEW |