Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(939)

Side by Side Diff: net/ssl/channel_id_service_unittest.cc

Issue 1149083013: Combine ChannelIDService::RequestHandle and ChannelIDServiceRequest classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix order of variables Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/ssl/channel_id_service.cc ('K') | « net/ssl/channel_id_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/ssl/channel_id_service.h" 5 #include "net/ssl/channel_id_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 ChannelIDService::GetDomainForHost("goto")); 130 ChannelIDService::GetDomainForHost("goto"));
131 EXPECT_EQ("127.0.0.1", 131 EXPECT_EQ("127.0.0.1",
132 ChannelIDService::GetDomainForHost("127.0.0.1")); 132 ChannelIDService::GetDomainForHost("127.0.0.1"));
133 } 133 }
134 134
135 TEST_F(ChannelIDServiceTest, GetCacheMiss) { 135 TEST_F(ChannelIDServiceTest, GetCacheMiss) {
136 std::string host("encrypted.google.com"); 136 std::string host("encrypted.google.com");
137 137
138 int error; 138 int error;
139 TestCompletionCallback callback; 139 TestCompletionCallback callback;
140 ChannelIDService::RequestHandle request_handle; 140 ChannelIDService::Request request;
141 141
142 // Synchronous completion, because the store is initialized. 142 // Synchronous completion, because the store is initialized.
143 scoped_ptr<crypto::ECPrivateKey> key; 143 scoped_ptr<crypto::ECPrivateKey> key;
144 EXPECT_EQ(0, service_->channel_id_count()); 144 EXPECT_EQ(0, service_->channel_id_count());
145 error = 145 error = service_->GetChannelID(host, &key, callback.callback(), &request);
146 service_->GetChannelID(host, &key, callback.callback(), &request_handle);
147 EXPECT_EQ(ERR_FILE_NOT_FOUND, error); 146 EXPECT_EQ(ERR_FILE_NOT_FOUND, error);
148 EXPECT_FALSE(request_handle.is_active()); 147 EXPECT_FALSE(request.is_active());
149 EXPECT_EQ(0, service_->channel_id_count()); 148 EXPECT_EQ(0, service_->channel_id_count());
150 EXPECT_FALSE(key); 149 EXPECT_FALSE(key);
151 } 150 }
152 151
153 TEST_F(ChannelIDServiceTest, CacheHit) { 152 TEST_F(ChannelIDServiceTest, CacheHit) {
154 std::string host("encrypted.google.com"); 153 std::string host("encrypted.google.com");
155 154
156 int error; 155 int error;
157 TestCompletionCallback callback; 156 TestCompletionCallback callback;
158 ChannelIDService::RequestHandle request_handle; 157 ChannelIDService::Request request;
159 158
160 // Asynchronous completion. 159 // Asynchronous completion.
161 scoped_ptr<crypto::ECPrivateKey> key1; 160 scoped_ptr<crypto::ECPrivateKey> key1;
162 EXPECT_EQ(0, service_->channel_id_count()); 161 EXPECT_EQ(0, service_->channel_id_count());
163 error = service_->GetOrCreateChannelID(host, &key1, callback.callback(), 162 error = service_->GetOrCreateChannelID(host, &key1, callback.callback(),
164 &request_handle); 163 &request);
165 EXPECT_EQ(ERR_IO_PENDING, error); 164 EXPECT_EQ(ERR_IO_PENDING, error);
166 EXPECT_TRUE(request_handle.is_active()); 165 EXPECT_TRUE(request.is_active());
167 error = callback.WaitForResult(); 166 error = callback.WaitForResult();
168 EXPECT_EQ(OK, error); 167 EXPECT_EQ(OK, error);
169 EXPECT_EQ(1, service_->channel_id_count()); 168 EXPECT_EQ(1, service_->channel_id_count());
170 EXPECT_TRUE(key1); 169 EXPECT_TRUE(key1);
171 EXPECT_FALSE(request_handle.is_active()); 170 EXPECT_FALSE(request.is_active());
172 171
173 // Synchronous completion. 172 // Synchronous completion.
174 scoped_ptr<crypto::ECPrivateKey> key2; 173 scoped_ptr<crypto::ECPrivateKey> key2;
175 error = service_->GetOrCreateChannelID(host, &key2, callback.callback(), 174 error = service_->GetOrCreateChannelID(host, &key2, callback.callback(),
176 &request_handle); 175 &request);
177 EXPECT_FALSE(request_handle.is_active()); 176 EXPECT_FALSE(request.is_active());
178 EXPECT_EQ(OK, error); 177 EXPECT_EQ(OK, error);
179 EXPECT_EQ(1, service_->channel_id_count()); 178 EXPECT_EQ(1, service_->channel_id_count());
180 EXPECT_TRUE(KeysEqual(key1.get(), key2.get())); 179 EXPECT_TRUE(KeysEqual(key1.get(), key2.get()));
181 180
182 // Synchronous get. 181 // Synchronous get.
183 scoped_ptr<crypto::ECPrivateKey> key3; 182 scoped_ptr<crypto::ECPrivateKey> key3;
184 error = 183 error = service_->GetChannelID(host, &key3, callback.callback(), &request);
185 service_->GetChannelID(host, &key3, callback.callback(), &request_handle); 184 EXPECT_FALSE(request.is_active());
186 EXPECT_FALSE(request_handle.is_active());
187 EXPECT_EQ(OK, error); 185 EXPECT_EQ(OK, error);
188 EXPECT_EQ(1, service_->channel_id_count()); 186 EXPECT_EQ(1, service_->channel_id_count());
189 EXPECT_TRUE(KeysEqual(key1.get(), key3.get())); 187 EXPECT_TRUE(KeysEqual(key1.get(), key3.get()));
190 188
191 EXPECT_EQ(3u, service_->requests()); 189 EXPECT_EQ(3u, service_->requests());
192 EXPECT_EQ(2u, service_->key_store_hits()); 190 EXPECT_EQ(2u, service_->key_store_hits());
193 EXPECT_EQ(0u, service_->inflight_joins()); 191 EXPECT_EQ(0u, service_->inflight_joins());
194 } 192 }
195 193
196 TEST_F(ChannelIDServiceTest, StoreChannelIDs) { 194 TEST_F(ChannelIDServiceTest, StoreChannelIDs) {
197 int error; 195 int error;
198 TestCompletionCallback callback; 196 TestCompletionCallback callback;
199 ChannelIDService::RequestHandle request_handle; 197 ChannelIDService::Request request;
200 198
201 std::string host1("encrypted.google.com"); 199 std::string host1("encrypted.google.com");
202 scoped_ptr<crypto::ECPrivateKey> key1; 200 scoped_ptr<crypto::ECPrivateKey> key1;
203 EXPECT_EQ(0, service_->channel_id_count()); 201 EXPECT_EQ(0, service_->channel_id_count());
204 error = service_->GetOrCreateChannelID(host1, &key1, callback.callback(), 202 error = service_->GetOrCreateChannelID(host1, &key1, callback.callback(),
205 &request_handle); 203 &request);
206 EXPECT_EQ(ERR_IO_PENDING, error); 204 EXPECT_EQ(ERR_IO_PENDING, error);
207 EXPECT_TRUE(request_handle.is_active()); 205 EXPECT_TRUE(request.is_active());
208 error = callback.WaitForResult(); 206 error = callback.WaitForResult();
209 EXPECT_EQ(OK, error); 207 EXPECT_EQ(OK, error);
210 EXPECT_EQ(1, service_->channel_id_count()); 208 EXPECT_EQ(1, service_->channel_id_count());
211 209
212 std::string host2("www.verisign.com"); 210 std::string host2("www.verisign.com");
213 scoped_ptr<crypto::ECPrivateKey> key2; 211 scoped_ptr<crypto::ECPrivateKey> key2;
214 error = service_->GetOrCreateChannelID(host2, &key2, callback.callback(), 212 error = service_->GetOrCreateChannelID(host2, &key2, callback.callback(),
215 &request_handle); 213 &request);
216 EXPECT_EQ(ERR_IO_PENDING, error); 214 EXPECT_EQ(ERR_IO_PENDING, error);
217 EXPECT_TRUE(request_handle.is_active()); 215 EXPECT_TRUE(request.is_active());
218 error = callback.WaitForResult(); 216 error = callback.WaitForResult();
219 EXPECT_EQ(OK, error); 217 EXPECT_EQ(OK, error);
220 EXPECT_EQ(2, service_->channel_id_count()); 218 EXPECT_EQ(2, service_->channel_id_count());
221 219
222 std::string host3("www.twitter.com"); 220 std::string host3("www.twitter.com");
223 scoped_ptr<crypto::ECPrivateKey> key3; 221 scoped_ptr<crypto::ECPrivateKey> key3;
224 error = service_->GetOrCreateChannelID(host3, &key3, callback.callback(), 222 error = service_->GetOrCreateChannelID(host3, &key3, callback.callback(),
225 &request_handle); 223 &request);
226 EXPECT_EQ(ERR_IO_PENDING, error); 224 EXPECT_EQ(ERR_IO_PENDING, error);
227 EXPECT_TRUE(request_handle.is_active()); 225 EXPECT_TRUE(request.is_active());
228 error = callback.WaitForResult(); 226 error = callback.WaitForResult();
229 EXPECT_EQ(OK, error); 227 EXPECT_EQ(OK, error);
230 EXPECT_EQ(3, service_->channel_id_count()); 228 EXPECT_EQ(3, service_->channel_id_count());
231 229
232 EXPECT_FALSE(KeysEqual(key1.get(), key2.get())); 230 EXPECT_FALSE(KeysEqual(key1.get(), key2.get()));
233 EXPECT_FALSE(KeysEqual(key1.get(), key3.get())); 231 EXPECT_FALSE(KeysEqual(key1.get(), key3.get()));
234 EXPECT_FALSE(KeysEqual(key2.get(), key3.get())); 232 EXPECT_FALSE(KeysEqual(key2.get(), key3.get()));
235 } 233 }
236 234
237 // Tests an inflight join. 235 // Tests an inflight join.
238 TEST_F(ChannelIDServiceTest, InflightJoin) { 236 TEST_F(ChannelIDServiceTest, InflightJoin) {
239 std::string host("encrypted.google.com"); 237 std::string host("encrypted.google.com");
240 int error; 238 int error;
241 239
242 scoped_ptr<crypto::ECPrivateKey> key1; 240 scoped_ptr<crypto::ECPrivateKey> key1;
243 TestCompletionCallback callback1; 241 TestCompletionCallback callback1;
244 ChannelIDService::RequestHandle request_handle1; 242 ChannelIDService::Request request1;
245 243
246 scoped_ptr<crypto::ECPrivateKey> key2; 244 scoped_ptr<crypto::ECPrivateKey> key2;
247 TestCompletionCallback callback2; 245 TestCompletionCallback callback2;
248 ChannelIDService::RequestHandle request_handle2; 246 ChannelIDService::Request request2;
249 247
250 error = service_->GetOrCreateChannelID(host, &key1, callback1.callback(), 248 error = service_->GetOrCreateChannelID(host, &key1, callback1.callback(),
251 &request_handle1); 249 &request1);
252 EXPECT_EQ(ERR_IO_PENDING, error); 250 EXPECT_EQ(ERR_IO_PENDING, error);
253 EXPECT_TRUE(request_handle1.is_active()); 251 EXPECT_TRUE(request1.is_active());
254 // Should join with the original request. 252 // Should join with the original request.
255 error = service_->GetOrCreateChannelID(host, &key2, callback2.callback(), 253 error = service_->GetOrCreateChannelID(host, &key2, callback2.callback(),
256 &request_handle2); 254 &request2);
257 EXPECT_EQ(ERR_IO_PENDING, error); 255 EXPECT_EQ(ERR_IO_PENDING, error);
258 EXPECT_TRUE(request_handle2.is_active()); 256 EXPECT_TRUE(request2.is_active());
259 257
260 error = callback1.WaitForResult(); 258 error = callback1.WaitForResult();
261 EXPECT_EQ(OK, error); 259 EXPECT_EQ(OK, error);
262 error = callback2.WaitForResult(); 260 error = callback2.WaitForResult();
263 EXPECT_EQ(OK, error); 261 EXPECT_EQ(OK, error);
264 262
265 EXPECT_EQ(2u, service_->requests()); 263 EXPECT_EQ(2u, service_->requests());
266 EXPECT_EQ(0u, service_->key_store_hits()); 264 EXPECT_EQ(0u, service_->key_store_hits());
267 EXPECT_EQ(1u, service_->inflight_joins()); 265 EXPECT_EQ(1u, service_->inflight_joins());
268 EXPECT_EQ(1u, service_->workers_created()); 266 EXPECT_EQ(1u, service_->workers_created());
269 } 267 }
270 268
271 // Tests an inflight join of a Get request to a GetOrCreate request. 269 // Tests an inflight join of a Get request to a GetOrCreate request.
272 TEST_F(ChannelIDServiceTest, InflightJoinGetOrCreateAndGet) { 270 TEST_F(ChannelIDServiceTest, InflightJoinGetOrCreateAndGet) {
273 std::string host("encrypted.google.com"); 271 std::string host("encrypted.google.com");
274 int error; 272 int error;
275 273
276 scoped_ptr<crypto::ECPrivateKey> key1; 274 scoped_ptr<crypto::ECPrivateKey> key1;
277 TestCompletionCallback callback1; 275 TestCompletionCallback callback1;
278 ChannelIDService::RequestHandle request_handle1; 276 ChannelIDService::Request request1;
279 277
280 scoped_ptr<crypto::ECPrivateKey> key2; 278 scoped_ptr<crypto::ECPrivateKey> key2;
281 TestCompletionCallback callback2; 279 TestCompletionCallback callback2;
282 ChannelIDService::RequestHandle request_handle2; 280 ChannelIDService::Request request2;
283 281
284 error = service_->GetOrCreateChannelID(host, &key1, callback1.callback(), 282 error = service_->GetOrCreateChannelID(host, &key1, callback1.callback(),
285 &request_handle1); 283 &request1);
286 EXPECT_EQ(ERR_IO_PENDING, error); 284 EXPECT_EQ(ERR_IO_PENDING, error);
287 EXPECT_TRUE(request_handle1.is_active()); 285 EXPECT_TRUE(request1.is_active());
288 // Should join with the original request. 286 // Should join with the original request.
289 error = service_->GetChannelID(host, &key2, callback2.callback(), 287 error = service_->GetChannelID(host, &key2, callback2.callback(), &request2);
290 &request_handle2);
291 EXPECT_EQ(ERR_IO_PENDING, error); 288 EXPECT_EQ(ERR_IO_PENDING, error);
292 EXPECT_TRUE(request_handle2.is_active()); 289 EXPECT_TRUE(request2.is_active());
293 290
294 error = callback1.WaitForResult(); 291 error = callback1.WaitForResult();
295 EXPECT_EQ(OK, error); 292 EXPECT_EQ(OK, error);
296 error = callback2.WaitForResult(); 293 error = callback2.WaitForResult();
297 EXPECT_EQ(OK, error); 294 EXPECT_EQ(OK, error);
298 EXPECT_TRUE(KeysEqual(key1.get(), key2.get())); 295 EXPECT_TRUE(KeysEqual(key1.get(), key2.get()));
299 296
300 EXPECT_EQ(2u, service_->requests()); 297 EXPECT_EQ(2u, service_->requests());
301 EXPECT_EQ(0u, service_->key_store_hits()); 298 EXPECT_EQ(0u, service_->key_store_hits());
302 EXPECT_EQ(1u, service_->inflight_joins()); 299 EXPECT_EQ(1u, service_->inflight_joins());
303 EXPECT_EQ(1u, service_->workers_created()); 300 EXPECT_EQ(1u, service_->workers_created());
304 } 301 }
305 302
306 // Tests that the callback of a canceled request is never made. 303 // Tests that the callback of a canceled request is never made.
307 TEST_F(ChannelIDServiceTest, CancelRequest) { 304 TEST_F(ChannelIDServiceTest, CancelRequest) {
308 std::string host("encrypted.google.com"); 305 std::string host("encrypted.google.com");
309 scoped_ptr<crypto::ECPrivateKey> key; 306 scoped_ptr<crypto::ECPrivateKey> key;
310 int error; 307 int error;
311 ChannelIDService::RequestHandle request_handle; 308 ChannelIDService::Request request;
312 309
313 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest), 310 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest),
314 &request_handle); 311 &request);
315 EXPECT_EQ(ERR_IO_PENDING, error); 312 EXPECT_EQ(ERR_IO_PENDING, error);
316 EXPECT_TRUE(request_handle.is_active()); 313 EXPECT_TRUE(request.is_active());
317 request_handle.Cancel(); 314 request.Cancel();
318 EXPECT_FALSE(request_handle.is_active()); 315 EXPECT_FALSE(request.is_active());
319 316
320 // Wait for reply from ChannelIDServiceWorker to be posted back to the 317 // Wait for reply from ChannelIDServiceWorker to be posted back to the
321 // ChannelIDService. 318 // ChannelIDService.
322 base::MessageLoop::current()->RunUntilIdle(); 319 base::MessageLoop::current()->RunUntilIdle();
323 320
324 // Even though the original request was cancelled, the service will still 321 // Even though the original request was cancelled, the service will still
325 // store the result, it just doesn't call the callback. 322 // store the result, it just doesn't call the callback.
326 EXPECT_EQ(1, service_->channel_id_count()); 323 EXPECT_EQ(1, service_->channel_id_count());
327 } 324 }
328 325
329 // Tests that destructing the RequestHandle cancels the request. 326 // Tests that destructing the Request cancels the request.
330 TEST_F(ChannelIDServiceTest, CancelRequestByHandleDestruction) { 327 TEST_F(ChannelIDServiceTest, CancelRequestByHandleDestruction) {
331 std::string host("encrypted.google.com"); 328 std::string host("encrypted.google.com");
332 scoped_ptr<crypto::ECPrivateKey> key; 329 scoped_ptr<crypto::ECPrivateKey> key;
333 int error; 330 int error;
334 { 331 {
335 ChannelIDService::RequestHandle request_handle; 332 ChannelIDService::Request request;
336 333
337 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest), 334 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest),
338 &request_handle); 335 &request);
339 EXPECT_EQ(ERR_IO_PENDING, error); 336 EXPECT_EQ(ERR_IO_PENDING, error);
340 EXPECT_TRUE(request_handle.is_active()); 337 EXPECT_TRUE(request.is_active());
341 } 338 }
342 339
343 // Wait for reply from ChannelIDServiceWorker to be posted back to the 340 // Wait for reply from ChannelIDServiceWorker to be posted back to the
344 // ChannelIDService. 341 // ChannelIDService.
345 base::MessageLoop::current()->RunUntilIdle(); 342 base::MessageLoop::current()->RunUntilIdle();
346 343
347 // Even though the original request was cancelled, the service will still 344 // Even though the original request was cancelled, the service will still
348 // store the result, it just doesn't call the callback. 345 // store the result, it just doesn't call the callback.
349 EXPECT_EQ(1, service_->channel_id_count()); 346 EXPECT_EQ(1, service_->channel_id_count());
350 } 347 }
351 348
352 TEST_F(ChannelIDServiceTest, DestructionWithPendingRequest) { 349 TEST_F(ChannelIDServiceTest, DestructionWithPendingRequest) {
353 std::string host("encrypted.google.com"); 350 std::string host("encrypted.google.com");
354 scoped_ptr<crypto::ECPrivateKey> key; 351 scoped_ptr<crypto::ECPrivateKey> key;
355 int error; 352 int error;
356 ChannelIDService::RequestHandle request_handle; 353 ChannelIDService::Request request;
357 354
358 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest), 355 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest),
359 &request_handle); 356 &request);
360 EXPECT_EQ(ERR_IO_PENDING, error); 357 EXPECT_EQ(ERR_IO_PENDING, error);
361 EXPECT_TRUE(request_handle.is_active()); 358 EXPECT_TRUE(request.is_active());
362 359
363 // Cancel request and destroy the ChannelIDService. 360 // Cancel request and destroy the ChannelIDService.
364 request_handle.Cancel(); 361 request.Cancel();
365 service_.reset(); 362 service_.reset();
366 363
367 // ChannelIDServiceWorker should not post anything back to the 364 // ChannelIDServiceWorker should not post anything back to the
368 // non-existent ChannelIDService, but run the loop just to be sure it 365 // non-existent ChannelIDService, but run the loop just to be sure it
369 // doesn't. 366 // doesn't.
370 base::MessageLoop::current()->RunUntilIdle(); 367 base::MessageLoop::current()->RunUntilIdle();
371 368
372 // If we got here without crashing or a valgrind error, it worked. 369 // If we got here without crashing or a valgrind error, it worked.
373 } 370 }
374 371
375 // Tests that shutting down the sequenced worker pool and then making new 372 // Tests that shutting down the sequenced worker pool and then making new
376 // requests gracefully fails. 373 // requests gracefully fails.
377 // This is a regression test for http://crbug.com/236387 374 // This is a regression test for http://crbug.com/236387
378 TEST_F(ChannelIDServiceTest, RequestAfterPoolShutdown) { 375 TEST_F(ChannelIDServiceTest, RequestAfterPoolShutdown) {
379 scoped_refptr<FailingTaskRunner> task_runner(new FailingTaskRunner); 376 scoped_refptr<FailingTaskRunner> task_runner(new FailingTaskRunner);
380 service_.reset(new ChannelIDService( 377 service_.reset(new ChannelIDService(
381 new DefaultChannelIDStore(NULL), task_runner)); 378 new DefaultChannelIDStore(NULL), task_runner));
382 379
383 // Make a request that will force synchronous completion. 380 // Make a request that will force synchronous completion.
384 std::string host("encrypted.google.com"); 381 std::string host("encrypted.google.com");
385 scoped_ptr<crypto::ECPrivateKey> key; 382 scoped_ptr<crypto::ECPrivateKey> key;
386 int error; 383 int error;
387 ChannelIDService::RequestHandle request_handle; 384 ChannelIDService::Request request;
388 385
389 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest), 386 error = service_->GetOrCreateChannelID(host, &key, base::Bind(&FailTest),
390 &request_handle); 387 &request);
391 // If we got here without crashing or a valgrind error, it worked. 388 // If we got here without crashing or a valgrind error, it worked.
392 ASSERT_EQ(ERR_INSUFFICIENT_RESOURCES, error); 389 ASSERT_EQ(ERR_INSUFFICIENT_RESOURCES, error);
393 EXPECT_FALSE(request_handle.is_active()); 390 EXPECT_FALSE(request.is_active());
394 } 391 }
395 392
396 // Tests that simultaneous creation of different certs works. 393 // Tests that simultaneous creation of different certs works.
397 TEST_F(ChannelIDServiceTest, SimultaneousCreation) { 394 TEST_F(ChannelIDServiceTest, SimultaneousCreation) {
398 int error; 395 int error;
399 396
400 std::string host1("encrypted.google.com"); 397 std::string host1("encrypted.google.com");
401 scoped_ptr<crypto::ECPrivateKey> key1; 398 scoped_ptr<crypto::ECPrivateKey> key1;
402 TestCompletionCallback callback1; 399 TestCompletionCallback callback1;
403 ChannelIDService::RequestHandle request_handle1; 400 ChannelIDService::Request request1;
404 401
405 std::string host2("foo.com"); 402 std::string host2("foo.com");
406 scoped_ptr<crypto::ECPrivateKey> key2; 403 scoped_ptr<crypto::ECPrivateKey> key2;
407 TestCompletionCallback callback2; 404 TestCompletionCallback callback2;
408 ChannelIDService::RequestHandle request_handle2; 405 ChannelIDService::Request request2;
409 406
410 std::string host3("bar.com"); 407 std::string host3("bar.com");
411 scoped_ptr<crypto::ECPrivateKey> key3; 408 scoped_ptr<crypto::ECPrivateKey> key3;
412 TestCompletionCallback callback3; 409 TestCompletionCallback callback3;
413 ChannelIDService::RequestHandle request_handle3; 410 ChannelIDService::Request request3;
414 411
415 error = service_->GetOrCreateChannelID(host1, &key1, callback1.callback(), 412 error = service_->GetOrCreateChannelID(host1, &key1, callback1.callback(),
416 &request_handle1); 413 &request1);
417 EXPECT_EQ(ERR_IO_PENDING, error); 414 EXPECT_EQ(ERR_IO_PENDING, error);
418 EXPECT_TRUE(request_handle1.is_active()); 415 EXPECT_TRUE(request1.is_active());
419 416
420 error = service_->GetOrCreateChannelID(host2, &key2, callback2.callback(), 417 error = service_->GetOrCreateChannelID(host2, &key2, callback2.callback(),
421 &request_handle2); 418 &request2);
422 EXPECT_EQ(ERR_IO_PENDING, error); 419 EXPECT_EQ(ERR_IO_PENDING, error);
423 EXPECT_TRUE(request_handle2.is_active()); 420 EXPECT_TRUE(request2.is_active());
424 421
425 error = service_->GetOrCreateChannelID(host3, &key3, callback3.callback(), 422 error = service_->GetOrCreateChannelID(host3, &key3, callback3.callback(),
426 &request_handle3); 423 &request3);
427 EXPECT_EQ(ERR_IO_PENDING, error); 424 EXPECT_EQ(ERR_IO_PENDING, error);
428 EXPECT_TRUE(request_handle3.is_active()); 425 EXPECT_TRUE(request3.is_active());
429 426
430 error = callback1.WaitForResult(); 427 error = callback1.WaitForResult();
431 EXPECT_EQ(OK, error); 428 EXPECT_EQ(OK, error);
432 EXPECT_TRUE(key1); 429 EXPECT_TRUE(key1);
433 430
434 error = callback2.WaitForResult(); 431 error = callback2.WaitForResult();
435 EXPECT_EQ(OK, error); 432 EXPECT_EQ(OK, error);
436 EXPECT_TRUE(key2); 433 EXPECT_TRUE(key2);
437 434
438 error = callback3.WaitForResult(); 435 error = callback3.WaitForResult();
(...skipping 10 matching lines...) Expand all
449 TEST_F(ChannelIDServiceTest, AsyncStoreGetOrCreateNoChannelIDsInStore) { 446 TEST_F(ChannelIDServiceTest, AsyncStoreGetOrCreateNoChannelIDsInStore) {
450 MockChannelIDStoreWithAsyncGet* mock_store = 447 MockChannelIDStoreWithAsyncGet* mock_store =
451 new MockChannelIDStoreWithAsyncGet(); 448 new MockChannelIDStoreWithAsyncGet();
452 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService( 449 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService(
453 mock_store, base::MessageLoopProxy::current())); 450 mock_store, base::MessageLoopProxy::current()));
454 451
455 std::string host("encrypted.google.com"); 452 std::string host("encrypted.google.com");
456 453
457 int error; 454 int error;
458 TestCompletionCallback callback; 455 TestCompletionCallback callback;
459 ChannelIDService::RequestHandle request_handle; 456 ChannelIDService::Request request;
460 457
461 // Asynchronous completion with no certs in the store. 458 // Asynchronous completion with no certs in the store.
462 scoped_ptr<crypto::ECPrivateKey> key; 459 scoped_ptr<crypto::ECPrivateKey> key;
463 EXPECT_EQ(0, service_->channel_id_count()); 460 EXPECT_EQ(0, service_->channel_id_count());
464 error = service_->GetOrCreateChannelID(host, &key, callback.callback(), 461 error =
465 &request_handle); 462 service_->GetOrCreateChannelID(host, &key, callback.callback(), &request);
466 EXPECT_EQ(ERR_IO_PENDING, error); 463 EXPECT_EQ(ERR_IO_PENDING, error);
467 EXPECT_TRUE(request_handle.is_active()); 464 EXPECT_TRUE(request.is_active());
468 465
469 mock_store->CallGetChannelIDCallbackWithResult(ERR_FILE_NOT_FOUND, nullptr); 466 mock_store->CallGetChannelIDCallbackWithResult(ERR_FILE_NOT_FOUND, nullptr);
470 467
471 error = callback.WaitForResult(); 468 error = callback.WaitForResult();
472 EXPECT_EQ(OK, error); 469 EXPECT_EQ(OK, error);
473 EXPECT_EQ(1, service_->channel_id_count()); 470 EXPECT_EQ(1, service_->channel_id_count());
474 EXPECT_TRUE(key); 471 EXPECT_TRUE(key);
475 EXPECT_FALSE(request_handle.is_active()); 472 EXPECT_FALSE(request.is_active());
476 } 473 }
477 474
478 TEST_F(ChannelIDServiceTest, AsyncStoreGetNoChannelIDsInStore) { 475 TEST_F(ChannelIDServiceTest, AsyncStoreGetNoChannelIDsInStore) {
479 MockChannelIDStoreWithAsyncGet* mock_store = 476 MockChannelIDStoreWithAsyncGet* mock_store =
480 new MockChannelIDStoreWithAsyncGet(); 477 new MockChannelIDStoreWithAsyncGet();
481 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService( 478 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService(
482 mock_store, base::MessageLoopProxy::current())); 479 mock_store, base::MessageLoopProxy::current()));
483 480
484 std::string host("encrypted.google.com"); 481 std::string host("encrypted.google.com");
485 482
486 int error; 483 int error;
487 TestCompletionCallback callback; 484 TestCompletionCallback callback;
488 ChannelIDService::RequestHandle request_handle; 485 ChannelIDService::Request request;
489 486
490 // Asynchronous completion with no certs in the store. 487 // Asynchronous completion with no certs in the store.
491 scoped_ptr<crypto::ECPrivateKey> key; 488 scoped_ptr<crypto::ECPrivateKey> key;
492 EXPECT_EQ(0, service_->channel_id_count()); 489 EXPECT_EQ(0, service_->channel_id_count());
493 error = 490 error = service_->GetChannelID(host, &key, callback.callback(), &request);
494 service_->GetChannelID(host, &key, callback.callback(), &request_handle);
495 EXPECT_EQ(ERR_IO_PENDING, error); 491 EXPECT_EQ(ERR_IO_PENDING, error);
496 EXPECT_TRUE(request_handle.is_active()); 492 EXPECT_TRUE(request.is_active());
497 493
498 mock_store->CallGetChannelIDCallbackWithResult(ERR_FILE_NOT_FOUND, nullptr); 494 mock_store->CallGetChannelIDCallbackWithResult(ERR_FILE_NOT_FOUND, nullptr);
499 495
500 error = callback.WaitForResult(); 496 error = callback.WaitForResult();
501 EXPECT_EQ(ERR_FILE_NOT_FOUND, error); 497 EXPECT_EQ(ERR_FILE_NOT_FOUND, error);
502 EXPECT_EQ(0, service_->channel_id_count()); 498 EXPECT_EQ(0, service_->channel_id_count());
503 EXPECT_EQ(0u, service_->workers_created()); 499 EXPECT_EQ(0u, service_->workers_created());
504 EXPECT_FALSE(key); 500 EXPECT_FALSE(key);
505 EXPECT_FALSE(request_handle.is_active()); 501 EXPECT_FALSE(request.is_active());
506 } 502 }
507 503
508 TEST_F(ChannelIDServiceTest, AsyncStoreGetOrCreateOneCertInStore) { 504 TEST_F(ChannelIDServiceTest, AsyncStoreGetOrCreateOneCertInStore) {
509 MockChannelIDStoreWithAsyncGet* mock_store = 505 MockChannelIDStoreWithAsyncGet* mock_store =
510 new MockChannelIDStoreWithAsyncGet(); 506 new MockChannelIDStoreWithAsyncGet();
511 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService( 507 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService(
512 mock_store, base::MessageLoopProxy::current())); 508 mock_store, base::MessageLoopProxy::current()));
513 509
514 std::string host("encrypted.google.com"); 510 std::string host("encrypted.google.com");
515 511
516 int error; 512 int error;
517 TestCompletionCallback callback; 513 TestCompletionCallback callback;
518 ChannelIDService::RequestHandle request_handle; 514 ChannelIDService::Request request;
519 515
520 // Asynchronous completion with a cert in the store. 516 // Asynchronous completion with a cert in the store.
521 scoped_ptr<crypto::ECPrivateKey> key; 517 scoped_ptr<crypto::ECPrivateKey> key;
522 EXPECT_EQ(0, service_->channel_id_count()); 518 EXPECT_EQ(0, service_->channel_id_count());
523 error = service_->GetOrCreateChannelID(host, &key, callback.callback(), 519 error =
524 &request_handle); 520 service_->GetOrCreateChannelID(host, &key, callback.callback(), &request);
525 EXPECT_EQ(ERR_IO_PENDING, error); 521 EXPECT_EQ(ERR_IO_PENDING, error);
526 EXPECT_TRUE(request_handle.is_active()); 522 EXPECT_TRUE(request.is_active());
527 523
528 scoped_ptr<crypto::ECPrivateKey> expected_key(crypto::ECPrivateKey::Create()); 524 scoped_ptr<crypto::ECPrivateKey> expected_key(crypto::ECPrivateKey::Create());
529 mock_store->CallGetChannelIDCallbackWithResult(OK, expected_key.get()); 525 mock_store->CallGetChannelIDCallbackWithResult(OK, expected_key.get());
530 526
531 error = callback.WaitForResult(); 527 error = callback.WaitForResult();
532 EXPECT_EQ(OK, error); 528 EXPECT_EQ(OK, error);
533 EXPECT_EQ(1, service_->channel_id_count()); 529 EXPECT_EQ(1, service_->channel_id_count());
534 EXPECT_EQ(1u, service_->requests()); 530 EXPECT_EQ(1u, service_->requests());
535 EXPECT_EQ(1u, service_->key_store_hits()); 531 EXPECT_EQ(1u, service_->key_store_hits());
536 // Because the cert was found in the store, no new workers should have been 532 // Because the cert was found in the store, no new workers should have been
537 // created. 533 // created.
538 EXPECT_EQ(0u, service_->workers_created()); 534 EXPECT_EQ(0u, service_->workers_created());
539 EXPECT_TRUE(key); 535 EXPECT_TRUE(key);
540 EXPECT_TRUE(KeysEqual(expected_key.get(), key.get())); 536 EXPECT_TRUE(KeysEqual(expected_key.get(), key.get()));
541 EXPECT_FALSE(request_handle.is_active()); 537 EXPECT_FALSE(request.is_active());
542 } 538 }
543 539
544 TEST_F(ChannelIDServiceTest, AsyncStoreGetOneCertInStore) { 540 TEST_F(ChannelIDServiceTest, AsyncStoreGetOneCertInStore) {
545 MockChannelIDStoreWithAsyncGet* mock_store = 541 MockChannelIDStoreWithAsyncGet* mock_store =
546 new MockChannelIDStoreWithAsyncGet(); 542 new MockChannelIDStoreWithAsyncGet();
547 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService( 543 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService(
548 mock_store, base::MessageLoopProxy::current())); 544 mock_store, base::MessageLoopProxy::current()));
549 545
550 std::string host("encrypted.google.com"); 546 std::string host("encrypted.google.com");
551 547
552 int error; 548 int error;
553 TestCompletionCallback callback; 549 TestCompletionCallback callback;
554 ChannelIDService::RequestHandle request_handle; 550 ChannelIDService::Request request;
555 551
556 // Asynchronous completion with a cert in the store. 552 // Asynchronous completion with a cert in the store.
557 scoped_ptr<crypto::ECPrivateKey> key; 553 scoped_ptr<crypto::ECPrivateKey> key;
558 std::string private_key, spki; 554 std::string private_key, spki;
559 EXPECT_EQ(0, service_->channel_id_count()); 555 EXPECT_EQ(0, service_->channel_id_count());
560 error = 556 error = service_->GetChannelID(host, &key, callback.callback(), &request);
561 service_->GetChannelID(host, &key, callback.callback(), &request_handle);
562 EXPECT_EQ(ERR_IO_PENDING, error); 557 EXPECT_EQ(ERR_IO_PENDING, error);
563 EXPECT_TRUE(request_handle.is_active()); 558 EXPECT_TRUE(request.is_active());
564 559
565 scoped_ptr<crypto::ECPrivateKey> expected_key(crypto::ECPrivateKey::Create()); 560 scoped_ptr<crypto::ECPrivateKey> expected_key(crypto::ECPrivateKey::Create());
566 mock_store->CallGetChannelIDCallbackWithResult(OK, expected_key.get()); 561 mock_store->CallGetChannelIDCallbackWithResult(OK, expected_key.get());
567 562
568 error = callback.WaitForResult(); 563 error = callback.WaitForResult();
569 EXPECT_EQ(OK, error); 564 EXPECT_EQ(OK, error);
570 EXPECT_EQ(1, service_->channel_id_count()); 565 EXPECT_EQ(1, service_->channel_id_count());
571 EXPECT_EQ(1u, service_->requests()); 566 EXPECT_EQ(1u, service_->requests());
572 EXPECT_EQ(1u, service_->key_store_hits()); 567 EXPECT_EQ(1u, service_->key_store_hits());
573 // Because the cert was found in the store, no new workers should have been 568 // Because the cert was found in the store, no new workers should have been
574 // created. 569 // created.
575 EXPECT_EQ(0u, service_->workers_created()); 570 EXPECT_EQ(0u, service_->workers_created());
576 EXPECT_TRUE(KeysEqual(expected_key.get(), key.get())); 571 EXPECT_TRUE(KeysEqual(expected_key.get(), key.get()));
577 EXPECT_FALSE(request_handle.is_active()); 572 EXPECT_FALSE(request.is_active());
578 } 573 }
579 574
580 TEST_F(ChannelIDServiceTest, AsyncStoreGetThenCreateNoCertsInStore) { 575 TEST_F(ChannelIDServiceTest, AsyncStoreGetThenCreateNoCertsInStore) {
581 MockChannelIDStoreWithAsyncGet* mock_store = 576 MockChannelIDStoreWithAsyncGet* mock_store =
582 new MockChannelIDStoreWithAsyncGet(); 577 new MockChannelIDStoreWithAsyncGet();
583 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService( 578 service_ = scoped_ptr<ChannelIDService>(new ChannelIDService(
584 mock_store, base::MessageLoopProxy::current())); 579 mock_store, base::MessageLoopProxy::current()));
585 580
586 std::string host("encrypted.google.com"); 581 std::string host("encrypted.google.com");
587 582
588 int error; 583 int error;
589 584
590 // Asynchronous get with no certs in the store. 585 // Asynchronous get with no certs in the store.
591 TestCompletionCallback callback1; 586 TestCompletionCallback callback1;
592 ChannelIDService::RequestHandle request_handle1; 587 ChannelIDService::Request request1;
593 scoped_ptr<crypto::ECPrivateKey> key1; 588 scoped_ptr<crypto::ECPrivateKey> key1;
594 EXPECT_EQ(0, service_->channel_id_count()); 589 EXPECT_EQ(0, service_->channel_id_count());
595 error = service_->GetChannelID(host, &key1, callback1.callback(), 590 error = service_->GetChannelID(host, &key1, callback1.callback(), &request1);
596 &request_handle1);
597 EXPECT_EQ(ERR_IO_PENDING, error); 591 EXPECT_EQ(ERR_IO_PENDING, error);
598 EXPECT_TRUE(request_handle1.is_active()); 592 EXPECT_TRUE(request1.is_active());
599 593
600 // Asynchronous get/create with no certs in the store. 594 // Asynchronous get/create with no certs in the store.
601 TestCompletionCallback callback2; 595 TestCompletionCallback callback2;
602 ChannelIDService::RequestHandle request_handle2; 596 ChannelIDService::Request request2;
603 scoped_ptr<crypto::ECPrivateKey> key2; 597 scoped_ptr<crypto::ECPrivateKey> key2;
604 EXPECT_EQ(0, service_->channel_id_count()); 598 EXPECT_EQ(0, service_->channel_id_count());
605 error = service_->GetOrCreateChannelID(host, &key2, callback2.callback(), 599 error = service_->GetOrCreateChannelID(host, &key2, callback2.callback(),
606 &request_handle2); 600 &request2);
607 EXPECT_EQ(ERR_IO_PENDING, error); 601 EXPECT_EQ(ERR_IO_PENDING, error);
608 EXPECT_TRUE(request_handle2.is_active()); 602 EXPECT_TRUE(request2.is_active());
609 603
610 mock_store->CallGetChannelIDCallbackWithResult(ERR_FILE_NOT_FOUND, nullptr); 604 mock_store->CallGetChannelIDCallbackWithResult(ERR_FILE_NOT_FOUND, nullptr);
611 605
612 // Even though the first request didn't ask to create a cert, it gets joined 606 // Even though the first request didn't ask to create a cert, it gets joined
613 // by the second, which does, so both succeed. 607 // by the second, which does, so both succeed.
614 error = callback1.WaitForResult(); 608 error = callback1.WaitForResult();
615 EXPECT_EQ(OK, error); 609 EXPECT_EQ(OK, error);
616 error = callback2.WaitForResult(); 610 error = callback2.WaitForResult();
617 EXPECT_EQ(OK, error); 611 EXPECT_EQ(OK, error);
618 612
619 // One cert is created, one request is joined. 613 // One cert is created, one request is joined.
620 EXPECT_EQ(2U, service_->requests()); 614 EXPECT_EQ(2U, service_->requests());
621 EXPECT_EQ(1, service_->channel_id_count()); 615 EXPECT_EQ(1, service_->channel_id_count());
622 EXPECT_EQ(1u, service_->workers_created()); 616 EXPECT_EQ(1u, service_->workers_created());
623 EXPECT_EQ(1u, service_->inflight_joins()); 617 EXPECT_EQ(1u, service_->inflight_joins());
624 EXPECT_TRUE(key1); 618 EXPECT_TRUE(key1);
625 EXPECT_TRUE(KeysEqual(key1.get(), key2.get())); 619 EXPECT_TRUE(KeysEqual(key1.get(), key2.get()));
626 EXPECT_FALSE(request_handle1.is_active()); 620 EXPECT_FALSE(request1.is_active());
627 EXPECT_FALSE(request_handle2.is_active()); 621 EXPECT_FALSE(request2.is_active());
628 } 622 }
629 623
630 } // namespace 624 } // namespace
631 625
632 } // namespace net 626 } // namespace net
OLDNEW
« net/ssl/channel_id_service.cc ('K') | « net/ssl/channel_id_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698