Chromium Code Reviews| 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 "net/base/net_errors.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace content { | |
| 15 namespace { | |
| 16 | |
| 17 class DTLSIdentityStoreForTest : public DTLSIdentityStore { | |
| 18 public: | |
| 19 DTLSIdentityStoreForTest(const scoped_refptr<base::TaskRunner>& task_runner) | |
| 20 : DTLSIdentityStore(task_runner) {} | |
| 21 | |
| 22 private: | |
| 23 virtual ~DTLSIdentityStoreForTest() {} | |
| 24 }; | |
| 25 | |
| 26 class DTLSIdentityStoreTest : public testing::Test { | |
| 27 public: | |
| 28 DTLSIdentityStoreTest() | |
| 29 : io_thread_(BrowserThread::IO, &message_loop_), | |
| 30 sequenced_worker_pool_( | |
| 31 new base::SequencedWorkerPool(3, "ServerBoundCertServiceTest")), | |
| 32 dtls_identity_store_( | |
| 33 new DTLSIdentityStoreForTest(sequenced_worker_pool_)) {} | |
| 34 | |
| 35 virtual ~DTLSIdentityStoreTest() { sequenced_worker_pool_->Shutdown(); } | |
| 36 | |
| 37 protected: | |
| 38 base::MessageLoopForUI message_loop_; | |
| 39 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.
| |
| 40 scoped_refptr<base::SequencedWorkerPool> sequenced_worker_pool_; | |
| 41 scoped_refptr<DTLSIdentityStoreForTest> dtls_identity_store_; | |
| 42 }; | |
| 43 | |
| 44 void OnRequestCompleted(bool* completed, | |
| 45 int error, | |
| 46 const std::string& certificate, | |
| 47 const std::string& private_key) { | |
| 48 ASSERT_EQ(net::OK, error); | |
| 49 ASSERT_NE("", certificate); | |
| 50 ASSERT_NE("", private_key); | |
| 51 *completed = true; | |
| 52 } | |
| 53 | |
| 54 TEST_F(DTLSIdentityStoreTest, RequestIdentity) { | |
| 55 DTLSIdentityStore::RequestHandle request_handle; | |
| 56 scoped_ptr<bool> completed; | |
| 57 completed.reset(new bool(false)); | |
| 58 dtls_identity_store_->RequestIdentity( | |
| 59 GURL("http://google.com"), | |
| 60 "a", | |
| 61 "b", | |
| 62 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())), | |
| 63 &request_handle); | |
| 64 sequenced_worker_pool_->FlushForTesting(); | |
| 65 message_loop_.RunUntilIdle(); | |
| 66 | |
| 67 EXPECT_EQ(true, *completed); | |
| 68 } | |
| 69 | |
| 70 TEST_F(DTLSIdentityStoreTest, CancelRequest) { | |
| 71 DTLSIdentityStore::RequestHandle request_handle; | |
| 72 scoped_ptr<bool> completed; | |
| 73 completed.reset(new bool(false)); | |
| 74 dtls_identity_store_->RequestIdentity( | |
| 75 GURL("http://google.com"), | |
| 76 "a", | |
| 77 "b", | |
| 78 base::Bind(&OnRequestCompleted, base::Unretained(completed.get())), | |
| 79 &request_handle); | |
| 80 request_handle.Cancel(); | |
| 81 sequenced_worker_pool_->FlushForTesting(); | |
| 82 message_loop_.RunUntilIdle(); | |
| 83 | |
| 84 EXPECT_EQ(false, *completed); | |
| 85 } | |
| 86 | |
| 87 TEST_F(DTLSIdentityStoreTest, MultipleRequests) { | |
| 88 scoped_ptr<bool> completed_1; | |
| 89 completed_1.reset(new bool(false)); | |
| 90 scoped_ptr<bool> completed_2; | |
| 91 completed_2.reset(new bool(false)); | |
| 92 | |
| 93 DTLSIdentityStore::RequestHandle request_handle_1; | |
| 94 DTLSIdentityStore::RequestHandle request_handle_2; | |
| 95 dtls_identity_store_->RequestIdentity( | |
| 96 GURL("http://foo.com"), | |
| 97 "a", | |
| 98 "b", | |
| 99 base::Bind(&OnRequestCompleted, base::Unretained(completed_1.get())), | |
| 100 &request_handle_1); | |
| 101 | |
| 102 dtls_identity_store_->RequestIdentity( | |
| 103 GURL("http://bar.com"), | |
| 104 "a", | |
| 105 "b", | |
| 106 base::Bind(&OnRequestCompleted, base::Unretained(completed_2.get())), | |
| 107 &request_handle_2); | |
| 108 | |
| 109 sequenced_worker_pool_->FlushForTesting(); | |
| 110 message_loop_.RunUntilIdle(); | |
| 111 | |
| 112 EXPECT_EQ(true, *completed_1); | |
| 113 EXPECT_EQ(true, *completed_2); | |
| 114 } | |
| 115 | |
| 116 } // namespace | |
| 117 } // namespace content | |
| OLD | NEW |