OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/api/dtlsidentitystore.h" | 11 #include "webrtc/api/dtlsidentitystore.h" |
12 | 12 |
| 13 #include <memory> |
| 14 |
13 #include "webrtc/api/webrtcsessiondescriptionfactory.h" | 15 #include "webrtc/api/webrtcsessiondescriptionfactory.h" |
14 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
16 #include "webrtc/base/ssladapter.h" | 18 #include "webrtc/base/ssladapter.h" |
17 | 19 |
18 using webrtc::DtlsIdentityStoreImpl; | 20 using webrtc::DtlsIdentityStoreImpl; |
19 | 21 |
20 static const int kTimeoutMs = 10000; | 22 static const int kTimeoutMs = 10000; |
21 | 23 |
22 class MockDtlsIdentityRequestObserver : | 24 class MockDtlsIdentityRequestObserver : |
23 public webrtc::DtlsIdentityRequestObserver { | 25 public webrtc::DtlsIdentityRequestObserver { |
24 public: | 26 public: |
25 MockDtlsIdentityRequestObserver() | 27 MockDtlsIdentityRequestObserver() |
26 : call_back_called_(false), last_request_success_(false) {} | 28 : call_back_called_(false), last_request_success_(false) {} |
27 void OnFailure(int error) override { | 29 void OnFailure(int error) override { |
28 EXPECT_FALSE(call_back_called_); | 30 EXPECT_FALSE(call_back_called_); |
29 call_back_called_ = true; | 31 call_back_called_ = true; |
30 last_request_success_ = false; | 32 last_request_success_ = false; |
31 } | 33 } |
32 void OnSuccess(const std::string& der_cert, | 34 void OnSuccess(const std::string& der_cert, |
33 const std::string& der_private_key) override { | 35 const std::string& der_private_key) override { |
34 LOG(LS_WARNING) << "The string version of OnSuccess is called unexpectedly"; | 36 LOG(LS_WARNING) << "The string version of OnSuccess is called unexpectedly"; |
35 EXPECT_TRUE(false); | 37 EXPECT_TRUE(false); |
36 } | 38 } |
37 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override { | 39 void OnSuccess(std::unique_ptr<rtc::SSLIdentity> identity) override { |
38 EXPECT_FALSE(call_back_called_); | 40 EXPECT_FALSE(call_back_called_); |
39 call_back_called_ = true; | 41 call_back_called_ = true; |
40 last_request_success_ = true; | 42 last_request_success_ = true; |
41 } | 43 } |
42 | 44 |
43 void Reset() { | 45 void Reset() { |
44 call_back_called_ = false; | 46 call_back_called_ = false; |
45 last_request_success_ = false; | 47 last_request_success_ = false; |
46 } | 48 } |
47 | 49 |
(...skipping 22 matching lines...) Expand all Loading... |
70 } | 72 } |
71 ~DtlsIdentityStoreTest() {} | 73 ~DtlsIdentityStoreTest() {} |
72 | 74 |
73 static void SetUpTestCase() { | 75 static void SetUpTestCase() { |
74 rtc::InitializeSSL(); | 76 rtc::InitializeSSL(); |
75 } | 77 } |
76 static void TearDownTestCase() { | 78 static void TearDownTestCase() { |
77 rtc::CleanupSSL(); | 79 rtc::CleanupSSL(); |
78 } | 80 } |
79 | 81 |
80 rtc::scoped_ptr<rtc::Thread> worker_thread_; | 82 std::unique_ptr<rtc::Thread> worker_thread_; |
81 rtc::scoped_ptr<DtlsIdentityStoreImpl> store_; | 83 std::unique_ptr<DtlsIdentityStoreImpl> store_; |
82 rtc::scoped_refptr<MockDtlsIdentityRequestObserver> observer_; | 84 rtc::scoped_refptr<MockDtlsIdentityRequestObserver> observer_; |
83 }; | 85 }; |
84 | 86 |
85 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) { | 87 TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) { |
86 store_->RequestIdentity(rtc::KeyParams(rtc::KT_RSA), | 88 store_->RequestIdentity(rtc::KeyParams(rtc::KT_RSA), |
87 rtc::Optional<uint64_t>(), | 89 rtc::Optional<uint64_t>(), |
88 observer_.get()); | 90 observer_.get()); |
89 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); | 91 EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs); |
90 | 92 |
91 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs); | 93 EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 138 |
137 store_->RequestIdentity(rtc::KeyParams(rtc::KT_ECDSA), | 139 store_->RequestIdentity(rtc::KeyParams(rtc::KT_ECDSA), |
138 rtc::Optional<uint64_t>(), | 140 rtc::Optional<uint64_t>(), |
139 observer_.get()); | 141 observer_.get()); |
140 store_.reset(); | 142 store_.reset(); |
141 | 143 |
142 worker_thread_->Stop(); | 144 worker_thread_->Stop(); |
143 EXPECT_FALSE(observer_->call_back_called()); | 145 EXPECT_FALSE(observer_->call_back_called()); |
144 } | 146 } |
145 | 147 |
OLD | NEW |