Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/server_bound_cert_service.h" | 5 #include "net/ssl/server_bound_cert_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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 | 529 |
| 530 mock_store->CallGetServerBoundCertCallbackWithResult( | 530 mock_store->CallGetServerBoundCertCallbackWithResult( |
| 531 ERR_FILE_NOT_FOUND, base::Time(), std::string(), std::string()); | 531 ERR_FILE_NOT_FOUND, base::Time(), std::string(), std::string()); |
| 532 | 532 |
| 533 error = callback.WaitForResult(); | 533 error = callback.WaitForResult(); |
| 534 EXPECT_EQ(OK, error); | 534 EXPECT_EQ(OK, error); |
| 535 EXPECT_EQ(1, service_->cert_count()); | 535 EXPECT_EQ(1, service_->cert_count()); |
| 536 EXPECT_FALSE(private_key_info.empty()); | 536 EXPECT_FALSE(private_key_info.empty()); |
| 537 EXPECT_FALSE(der_cert.empty()); | 537 EXPECT_FALSE(der_cert.empty()); |
| 538 EXPECT_FALSE(request_handle.is_active()); | 538 EXPECT_FALSE(request_handle.is_active()); |
| 539 } | 539 |
| 540 // Wait for any posted ServerBoundCertServiceWorkers to finish, in order to | |
| 541 // ensure that the workers are cleared by the time service_'s destructor is | |
| 542 // called. This prevents a leak of the SequencedWorkerPool, which by default | |
| 543 // continues on shutdown. (By calling | |
| 544 // CallGetServerBoundCertCallbackWithResult, callbacks are called directly, | |
| 545 // short-circuiting ServerBoundCertService's usual bookkeeping, so existing | |
| 546 // tasks must be both cleared and waited for to ensure proper memory freeing.) | |
| 547 sequenced_worker_pool_->FlushForTesting(); | |
|
Ryan Sleevi
2013/08/09 00:45:10
I can't help but keep reading this comment and cod
juanlang
2013/08/09 04:48:52
Yeah, that big comment should have been a clue to
juanlang
2013/08/09 16:25:28
Yep, PostTask is the right thing here. Thanks. I d
| |
| 548 base::MessageLoop::current()->RunUntilIdle(); } | |
| 540 | 549 |
| 541 TEST_F(ServerBoundCertServiceTest, AsyncStoreGetOneCertInStore) { | 550 TEST_F(ServerBoundCertServiceTest, AsyncStoreGetOneCertInStore) { |
| 542 MockServerBoundCertStoreWithAsyncGet* mock_store = | 551 MockServerBoundCertStoreWithAsyncGet* mock_store = |
| 543 new MockServerBoundCertStoreWithAsyncGet(); | 552 new MockServerBoundCertStoreWithAsyncGet(); |
| 544 service_ = scoped_ptr<ServerBoundCertService>( | 553 service_ = scoped_ptr<ServerBoundCertService>( |
| 545 new ServerBoundCertService(mock_store, sequenced_worker_pool_)); | 554 new ServerBoundCertService(mock_store, sequenced_worker_pool_)); |
| 546 | 555 |
| 547 std::string host("encrypted.google.com"); | 556 std::string host("encrypted.google.com"); |
| 548 | 557 |
| 549 int error; | 558 int error; |
| 550 TestCompletionCallback callback; | 559 TestCompletionCallback callback; |
| 551 ServerBoundCertService::RequestHandle request_handle; | 560 ServerBoundCertService::RequestHandle request_handle; |
| 552 | 561 |
| 553 // Asynchronous completion with a cert in the store. | 562 // Asynchronous completion with a cert in the store. |
| 554 std::string private_key_info, der_cert; | 563 std::string private_key_info, der_cert; |
| 555 EXPECT_EQ(0, service_->cert_count()); | 564 EXPECT_EQ(0, service_->cert_count()); |
| 556 error = service_->GetDomainBoundCert( | 565 error = service_->GetDomainBoundCert( |
| 557 host, &private_key_info, &der_cert, callback.callback(), &request_handle); | 566 host, &private_key_info, &der_cert, callback.callback(), &request_handle); |
| 558 EXPECT_EQ(ERR_IO_PENDING, error); | 567 EXPECT_EQ(ERR_IO_PENDING, error); |
| 559 EXPECT_TRUE(request_handle.is_active()); | 568 EXPECT_TRUE(request_handle.is_active()); |
| 560 | 569 |
| 561 mock_store->CallGetServerBoundCertCallbackWithResult( | 570 mock_store->CallGetServerBoundCertCallbackWithResult( |
| 562 OK, base::Time(), "ab", "cd"); | 571 OK, base::Time(), "ab", "cd"); |
| 563 | |
| 564 error = callback.WaitForResult(); | 572 error = callback.WaitForResult(); |
| 565 EXPECT_EQ(OK, error); | 573 EXPECT_EQ(OK, error); |
| 566 EXPECT_EQ(1, service_->cert_count()); | 574 EXPECT_EQ(1, service_->cert_count()); |
| 567 EXPECT_EQ(1u, service_->requests()); | 575 EXPECT_EQ(1u, service_->requests()); |
| 568 EXPECT_EQ(1u, service_->cert_store_hits()); | 576 EXPECT_EQ(1u, service_->cert_store_hits()); |
| 569 // Because the cert was found in the store, no new workers should have been | 577 // Because the cert was found in the store, no new workers should have been |
| 570 // created. | 578 // created. |
| 571 EXPECT_EQ(0u, service_->workers_created()); | 579 EXPECT_EQ(0u, service_->workers_created()); |
| 572 EXPECT_STREQ("ab", private_key_info.c_str()); | 580 EXPECT_STREQ("ab", private_key_info.c_str()); |
| 573 EXPECT_STREQ("cd", der_cert.c_str()); | 581 EXPECT_STREQ("cd", der_cert.c_str()); |
| 574 EXPECT_FALSE(request_handle.is_active()); | 582 EXPECT_FALSE(request_handle.is_active()); |
| 583 | |
| 584 // Wait for any posted ServerBoundCertServiceWorkers to finish, in order to | |
| 585 // ensure that the workers are cleared by the time service_'s destructor is | |
| 586 // called. This prevents a leak of the SequencedWorkerPool, which by default | |
| 587 // continues on shutdown. (By calling | |
| 588 // CallGetServerBoundCertCallbackWithResult, callbacks are called directly, | |
| 589 // short-circuiting ServerBoundCertService's usual bookkeeping, so existing | |
| 590 // tasks must be both cleared and waited for to ensure proper memory freeing.) | |
| 591 sequenced_worker_pool_->FlushForTesting(); | |
| 592 base::MessageLoop::current()->RunUntilIdle(); } | |
| 575 } | 593 } |
| 576 | 594 |
| 577 #endif // !defined(USE_OPENSSL) | 595 #endif // !defined(USE_OPENSSL) |
| 578 | 596 |
| 579 } // namespace | 597 } // namespace |
| 580 | 598 |
| 581 } // namespace net | 599 } // namespace net |
| OLD | NEW |