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 "content/public/test/render_view_test.h" | 7 #include "content/public/test/render_view_test.h" |
8 #include "ipc/ipc_test_sink.h" | 8 #include "ipc/ipc_test_sink.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/public/platform/WebCredential.h" | 10 #include "third_party/WebKit/public/platform/WebCredential.h" |
11 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" | 11 #include "third_party/WebKit/public/platform/WebCredentialManagerClient.h" |
12 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" | 12 #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" |
13 #include "third_party/WebKit/public/platform/WebLocalCredential.h" | 13 #include "third_party/WebKit/public/platform/WebLocalCredential.h" |
14 | 14 |
15 namespace password_manager { | 15 namespace password_manager { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class CredentialManagerClientTest : public content::RenderViewTest { | 19 // This test has crashed on Android since commit |
| 20 // d94a4430bc4448406b7564790d06110c7c5bcaaf was merged. |
| 21 // http://crbug.com/481415 |
| 22 #if defined(OS_ANDROID) |
| 23 #define MAYBE_CredentialManagerClientTest DISABLED_CredentialManagerClientTest |
| 24 #else |
| 25 #define MAYBE_CredentialManagerClientTest CredentialManagerClientTest |
| 26 #endif // defined(OS_ANDROID) |
| 27 |
| 28 class MAYBE_CredentialManagerClientTest : public content::RenderViewTest { |
20 public: | 29 public: |
21 CredentialManagerClientTest() | 30 MAYBE_CredentialManagerClientTest() |
22 : callback_errored_(false), callback_succeeded_(false) {} | 31 : callback_errored_(false), callback_succeeded_(false) {} |
23 ~CredentialManagerClientTest() override {} | 32 ~MAYBE_CredentialManagerClientTest() override {} |
24 | 33 |
25 void SetUp() override { | 34 void SetUp() override { |
26 content::RenderViewTest::SetUp(); | 35 content::RenderViewTest::SetUp(); |
27 credential_.reset(new blink::WebLocalCredential("", "", GURL(), "")); | 36 credential_.reset(new blink::WebLocalCredential("", "", GURL(), "")); |
28 client_.reset(new CredentialManagerClient(view_)); | 37 client_.reset(new CredentialManagerClient(view_)); |
29 } | 38 } |
30 | 39 |
31 void TearDown() override { | 40 void TearDown() override { |
32 credential_.reset(); | 41 credential_.reset(); |
33 content::RenderViewTest::TearDown(); | 42 content::RenderViewTest::TearDown(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // pending Blink-side Promise. | 110 // pending Blink-side Promise. |
102 bool callback_errored_; | 111 bool callback_errored_; |
103 bool callback_succeeded_; | 112 bool callback_succeeded_; |
104 | 113 |
105 scoped_ptr<blink::WebLocalCredential> credential_; | 114 scoped_ptr<blink::WebLocalCredential> credential_; |
106 }; | 115 }; |
107 | 116 |
108 class TestNotificationCallbacks | 117 class TestNotificationCallbacks |
109 : public blink::WebCredentialManagerClient::NotificationCallbacks { | 118 : public blink::WebCredentialManagerClient::NotificationCallbacks { |
110 public: | 119 public: |
111 explicit TestNotificationCallbacks(CredentialManagerClientTest* test) | 120 explicit TestNotificationCallbacks(MAYBE_CredentialManagerClientTest* test) |
112 : test_(test) {} | 121 : test_(test) {} |
113 | 122 |
114 virtual ~TestNotificationCallbacks() {} | 123 virtual ~TestNotificationCallbacks() {} |
115 | 124 |
116 virtual void onSuccess() { test_->set_callback_succeeded(true); } | 125 virtual void onSuccess() { test_->set_callback_succeeded(true); } |
117 | 126 |
118 virtual void onError(blink::WebCredentialManagerError* reason) { | 127 virtual void onError(blink::WebCredentialManagerError* reason) { |
119 test_->set_callback_errored(true); | 128 test_->set_callback_errored(true); |
120 } | 129 } |
121 | 130 |
122 private: | 131 private: |
123 CredentialManagerClientTest* test_; | 132 MAYBE_CredentialManagerClientTest* test_; |
124 }; | 133 }; |
125 | 134 |
126 class TestRequestCallbacks | 135 class TestRequestCallbacks |
127 : public blink::WebCredentialManagerClient::RequestCallbacks { | 136 : public blink::WebCredentialManagerClient::RequestCallbacks { |
128 public: | 137 public: |
129 explicit TestRequestCallbacks(CredentialManagerClientTest* test) | 138 explicit TestRequestCallbacks(MAYBE_CredentialManagerClientTest* test) |
130 : test_(test) {} | 139 : test_(test) {} |
131 | 140 |
132 virtual ~TestRequestCallbacks() {} | 141 virtual ~TestRequestCallbacks() {} |
133 | 142 |
134 virtual void onSuccess(blink::WebCredential*) { | 143 virtual void onSuccess(blink::WebCredential*) { |
135 test_->set_callback_succeeded(true); | 144 test_->set_callback_succeeded(true); |
136 } | 145 } |
137 | 146 |
138 virtual void onError(blink::WebCredentialManagerError* reason) { | 147 virtual void onError(blink::WebCredentialManagerError* reason) { |
139 test_->set_callback_errored(true); | 148 test_->set_callback_errored(true); |
140 } | 149 } |
141 | 150 |
142 private: | 151 private: |
143 CredentialManagerClientTest* test_; | 152 MAYBE_CredentialManagerClientTest* test_; |
144 }; | 153 }; |
145 | 154 |
146 } // namespace | 155 } // namespace |
147 | 156 |
148 TEST_F(CredentialManagerClientTest, SendNotifyFailedSignIn) { | 157 TEST_F(MAYBE_CredentialManagerClientTest, SendNotifyFailedSignIn) { |
149 int request_id; | 158 int request_id; |
150 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, | 159 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, |
151 request_id)); | 160 request_id)); |
152 | 161 |
153 scoped_ptr<TestNotificationCallbacks> callbacks( | 162 scoped_ptr<TestNotificationCallbacks> callbacks( |
154 new TestNotificationCallbacks(this)); | 163 new TestNotificationCallbacks(this)); |
155 client_->dispatchFailedSignIn(*credential(), callbacks.release()); | 164 client_->dispatchFailedSignIn(*credential(), callbacks.release()); |
156 | 165 |
157 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, | 166 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifyFailedSignIn::ID, |
158 request_id)); | 167 request_id)); |
159 | 168 |
160 client_->OnAcknowledgeFailedSignIn(request_id); | 169 client_->OnAcknowledgeFailedSignIn(request_id); |
161 EXPECT_TRUE(callback_succeeded()); | 170 EXPECT_TRUE(callback_succeeded()); |
162 EXPECT_FALSE(callback_errored()); | 171 EXPECT_FALSE(callback_errored()); |
163 } | 172 } |
164 | 173 |
165 TEST_F(CredentialManagerClientTest, SendNotifySignedIn) { | 174 TEST_F(MAYBE_CredentialManagerClientTest, SendNotifySignedIn) { |
166 int request_id; | 175 int request_id; |
167 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, | 176 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, |
168 request_id)); | 177 request_id)); |
169 | 178 |
170 scoped_ptr<TestNotificationCallbacks> callbacks( | 179 scoped_ptr<TestNotificationCallbacks> callbacks( |
171 new TestNotificationCallbacks(this)); | 180 new TestNotificationCallbacks(this)); |
172 client_->dispatchSignedIn(*credential(), callbacks.release()); | 181 client_->dispatchSignedIn(*credential(), callbacks.release()); |
173 | 182 |
174 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, | 183 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedIn::ID, |
175 request_id)); | 184 request_id)); |
176 | 185 |
177 client_->OnAcknowledgeSignedIn(request_id); | 186 client_->OnAcknowledgeSignedIn(request_id); |
178 EXPECT_TRUE(callback_succeeded()); | 187 EXPECT_TRUE(callback_succeeded()); |
179 EXPECT_FALSE(callback_errored()); | 188 EXPECT_FALSE(callback_errored()); |
180 } | 189 } |
181 | 190 |
182 TEST_F(CredentialManagerClientTest, SendNotifySignedOut) { | 191 TEST_F(MAYBE_CredentialManagerClientTest, SendNotifySignedOut) { |
183 int request_id; | 192 int request_id; |
184 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedOut::ID, | 193 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedOut::ID, |
185 request_id)); | 194 request_id)); |
186 | 195 |
187 scoped_ptr<TestNotificationCallbacks> callbacks( | 196 scoped_ptr<TestNotificationCallbacks> callbacks( |
188 new TestNotificationCallbacks(this)); | 197 new TestNotificationCallbacks(this)); |
189 client_->dispatchSignedOut(callbacks.release()); | 198 client_->dispatchSignedOut(callbacks.release()); |
190 | 199 |
191 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedOut::ID, | 200 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_NotifySignedOut::ID, |
192 request_id)); | 201 request_id)); |
193 | 202 |
194 client_->OnAcknowledgeSignedOut(request_id); | 203 client_->OnAcknowledgeSignedOut(request_id); |
195 EXPECT_TRUE(callback_succeeded()); | 204 EXPECT_TRUE(callback_succeeded()); |
196 EXPECT_FALSE(callback_errored()); | 205 EXPECT_FALSE(callback_errored()); |
197 } | 206 } |
198 | 207 |
199 TEST_F(CredentialManagerClientTest, SendRequestCredential) { | 208 TEST_F(MAYBE_CredentialManagerClientTest, SendRequestCredential) { |
200 int request_id; | 209 int request_id; |
201 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 210 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
202 request_id)); | 211 request_id)); |
203 | 212 |
204 scoped_ptr<TestRequestCallbacks> callbacks(new TestRequestCallbacks(this)); | 213 scoped_ptr<TestRequestCallbacks> callbacks(new TestRequestCallbacks(this)); |
205 std::vector<GURL> federations; | 214 std::vector<GURL> federations; |
206 client_->dispatchRequest(false, federations, callbacks.release()); | 215 client_->dispatchRequest(false, federations, callbacks.release()); |
207 | 216 |
208 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 217 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
209 request_id)); | 218 request_id)); |
210 | 219 |
211 CredentialInfo info; | 220 CredentialInfo info; |
212 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; | 221 info.type = CredentialType::CREDENTIAL_TYPE_LOCAL; |
213 client_->OnSendCredential(request_id, info); | 222 client_->OnSendCredential(request_id, info); |
214 EXPECT_TRUE(callback_succeeded()); | 223 EXPECT_TRUE(callback_succeeded()); |
215 EXPECT_FALSE(callback_errored()); | 224 EXPECT_FALSE(callback_errored()); |
216 } | 225 } |
217 | 226 |
218 TEST_F(CredentialManagerClientTest, SendRequestCredentialEmpty) { | 227 TEST_F(MAYBE_CredentialManagerClientTest, SendRequestCredentialEmpty) { |
219 int request_id; | 228 int request_id; |
220 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 229 EXPECT_FALSE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
221 request_id)); | 230 request_id)); |
222 | 231 |
223 scoped_ptr<TestRequestCallbacks> callbacks(new TestRequestCallbacks(this)); | 232 scoped_ptr<TestRequestCallbacks> callbacks(new TestRequestCallbacks(this)); |
224 std::vector<GURL> federations; | 233 std::vector<GURL> federations; |
225 client_->dispatchRequest(false, federations, callbacks.release()); | 234 client_->dispatchRequest(false, federations, callbacks.release()); |
226 | 235 |
227 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, | 236 EXPECT_TRUE(ExtractRequestId(CredentialManagerHostMsg_RequestCredential::ID, |
228 request_id)); | 237 request_id)); |
229 | 238 |
230 CredentialInfo info; // Send an empty credential in response. | 239 CredentialInfo info; // Send an empty credential in response. |
231 client_->OnSendCredential(request_id, info); | 240 client_->OnSendCredential(request_id, info); |
232 EXPECT_TRUE(callback_succeeded()); | 241 EXPECT_TRUE(callback_succeeded()); |
233 EXPECT_FALSE(callback_errored()); | 242 EXPECT_FALSE(callback_errored()); |
234 } | 243 } |
235 | 244 |
236 } // namespace password_manager | 245 } // namespace password_manager |
OLD | NEW |