OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" |
| 7 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "content/browser/media/dtls_identity_store.h" |
| 9 #include "content/public/test/test_browser_thread.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace content { |
| 14 namespace { |
| 15 |
| 16 class DTLSIdentityStoreForTest : public DTLSIdentityStore { |
| 17 public: |
| 18 DTLSIdentityStoreForTest(const scoped_refptr<base::TaskRunner>& task_runner) : |
| 19 DTLSIdentityStore(task_runner) {} |
| 20 }; |
| 21 |
| 22 class DTLSIdentityStoreTest : public testing::Test { |
| 23 public: |
| 24 DTLSIdentityStoreTest() |
| 25 : io_thread_(BrowserThread::IO, &message_loop_), |
| 26 sequenced_worker_pool_( |
| 27 new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")), |
| 28 completed_(false) {} |
| 29 |
| 30 virtual ~DTLSIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); } |
| 31 |
| 32 void OnGetOrGenerateCompleted(const std::string& certificate, |
| 33 const std::string& private_key) { |
| 34 ASSERT_NE("", certificate); |
| 35 ASSERT_NE("", private_key); |
| 36 completed_ = true; |
| 37 } |
| 38 |
| 39 protected: |
| 40 base::MessageLoopForUI message_loop_; |
| 41 TestBrowserThread io_thread_; |
| 42 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; |
| 43 bool completed_; |
| 44 }; |
| 45 |
| 46 TEST_F(DTLSIdentityStoreTest, GetOrGenerateIdentity) { |
| 47 DTLSIdentityStore* store = |
| 48 new DTLSIdentityStoreForTest(sequenced_worker_pool_); |
| 49 store->GetOrGenerateIdentity( |
| 50 GURL("http://google.com"), |
| 51 "a", |
| 52 "b", |
| 53 base::Bind(&DTLSIdentityStoreTest::OnGetOrGenerateCompleted, |
| 54 base::Unretained(this))); |
| 55 sequenced_worker_pool_->FlushForTesting(); |
| 56 message_loop_.RunUntilIdle(); |
| 57 |
| 58 EXPECT_EQ(true, completed_); |
| 59 } |
| 60 |
| 61 } // namespace |
| 62 } // namespace content |
OLD | NEW |