Chromium Code Reviews| Index: content/browser/media/dtls_identity_store_unittest.cc |
| diff --git a/content/browser/media/dtls_identity_store_unittest.cc b/content/browser/media/dtls_identity_store_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bb8ec5e04a67db392207b2aa066f1a9986a4b5b6 |
| --- /dev/null |
| +++ b/content/browser/media/dtls_identity_store_unittest.cc |
| @@ -0,0 +1,117 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/message_loop.h" |
| +#include "base/threading/sequenced_worker_pool.h" |
| +#include "content/browser/media/dtls_identity_store.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "net/base/net_errors.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace content { |
| +namespace { |
| + |
| +class DTLSIdentityStoreForTest : public DTLSIdentityStore { |
| + public: |
| + DTLSIdentityStoreForTest(const scoped_refptr<base::TaskRunner>& task_runner) |
| + : DTLSIdentityStore(task_runner) {} |
| + |
| + private: |
| + virtual ~DTLSIdentityStoreForTest() {} |
| +}; |
| + |
| +class DTLSIdentityStoreTest : public testing::Test { |
| + public: |
| + DTLSIdentityStoreTest() |
| + : io_thread_(BrowserThread::IO, &message_loop_), |
| + sequenced_worker_pool_( |
| + new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")), |
| + dtls_identity_store_( |
| + new DTLSIdentityStoreForTest(sequenced_worker_pool_)) {} |
| + |
| + virtual ~DTLSIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); } |
| + |
| + protected: |
| + base::MessageLoopForUI message_loop_; |
| + TestBrowserThread io_thread_; |
|
Ryan Sleevi
2013/06/13 22:36:47
Please see the PSA https://groups.google.com/a/chr
jiayl
2013/06/14 00:37:01
Done.
|
| + scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
| + scoped_refptr<DTLSIdentityStoreForTest> dtls_identity_store_; |
| +}; |
| + |
| +void OnRequestCompleted(bool* completed, |
| + int error, |
| + const std::string& certificate, |
| + const std::string& private_key) { |
| + ASSERT_EQ(net::OK, error); |
| + ASSERT_NE("", certificate); |
| + ASSERT_NE("", private_key); |
| + *completed = true; |
| +} |
| + |
| +TEST_F(DTLSIdentityStoreTest, RequestIdentity) { |
| + DTLSIdentityStore::RequestHandle request_handle; |
| + scoped_ptr<bool> completed; |
| + completed.reset(new bool(false)); |
| + dtls_identity_store_->RequestIdentity( |
| + GURL("http://google.com"), |
| + "a", |
| + "b", |
| + base::Bind(&OnRequestCompleted, base::Unretained(completed.get())), |
| + &request_handle); |
| + sequenced_worker_pool_->FlushForTesting(); |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ(true, *completed); |
| +} |
| + |
| +TEST_F(DTLSIdentityStoreTest, CancelRequest) { |
| + DTLSIdentityStore::RequestHandle request_handle; |
| + scoped_ptr<bool> completed; |
| + completed.reset(new bool(false)); |
| + dtls_identity_store_->RequestIdentity( |
| + GURL("http://google.com"), |
| + "a", |
| + "b", |
| + base::Bind(&OnRequestCompleted, base::Unretained(completed.get())), |
| + &request_handle); |
| + request_handle.Cancel(); |
| + sequenced_worker_pool_->FlushForTesting(); |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ(false, *completed); |
| +} |
| + |
| +TEST_F(DTLSIdentityStoreTest, MultipleRequests) { |
| + scoped_ptr<bool> completed_1; |
| + completed_1.reset(new bool(false)); |
| + scoped_ptr<bool> completed_2; |
| + completed_2.reset(new bool(false)); |
| + |
| + DTLSIdentityStore::RequestHandle request_handle_1; |
| + DTLSIdentityStore::RequestHandle request_handle_2; |
| + dtls_identity_store_->RequestIdentity( |
| + GURL("http://foo.com"), |
| + "a", |
| + "b", |
| + base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())), |
| + &request_handle_1); |
| + |
| + dtls_identity_store_->RequestIdentity( |
| + GURL("http://bar.com"), |
| + "a", |
| + "b", |
| + base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())), |
| + &request_handle_2); |
| + |
| + sequenced_worker_pool_->FlushForTesting(); |
| + message_loop_.RunUntilIdle(); |
| + |
| + EXPECT_EQ(true, *completed_1); |
| + EXPECT_EQ(true, *completed_2); |
| +} |
| + |
| +} // namespace |
| +} // namespace content |