OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/remoting/proto_utils.h" | 5 #include "media/remoting/proto_utils.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "media/base/audio_decoder_config.h" | 14 #include "media/base/audio_decoder_config.h" |
15 #include "media/base/cdm_config.h" | 15 #include "media/base/cdm_config.h" |
16 #include "media/base/cdm_key_information.h" | 16 #include "media/base/cdm_key_information.h" |
17 #include "media/base/content_decryption_module.h" | 17 #include "media/base/content_decryption_module.h" |
18 #include "media/base/decoder_buffer.h" | 18 #include "media/base/decoder_buffer.h" |
19 #include "media/base/demuxer_stream.h" | 19 #include "media/base/demuxer_stream.h" |
20 #include "media/base/eme_constants.h" | 20 #include "media/base/eme_constants.h" |
21 #include "media/base/test_helpers.h" | |
21 #include "media/base/video_decoder_config.h" | 22 #include "media/base/video_decoder_config.h" |
22 #include "media/remoting/rpc.pb.h" | 23 #include "media/remoting/rpc.pb.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using testing::_; | 27 using testing::_; |
27 using testing::Invoke; | 28 using testing::Invoke; |
28 using testing::Return; | 29 using testing::Return; |
29 | 30 |
30 namespace media { | 31 namespace media { |
31 namespace remoting { | 32 namespace remoting { |
33 namespace { | |
34 | |
35 void VerifyCdmPromiseResultsEqual(const CdmPromiseResult& cdm1, | |
36 const CdmPromiseResult& cdm2) { | |
37 ASSERT_EQ(cdm1.success(), cdm2.success()); | |
38 ASSERT_EQ(cdm1.exception(), cdm2.exception()); | |
39 ASSERT_EQ(cdm1.system_code(), cdm2.system_code()); | |
40 ASSERT_EQ(cdm1.error_message(), cdm2.error_message()); | |
41 } | |
42 | |
43 } // namespace | |
32 | 44 |
33 class ProtoUtilsTest : public testing::Test { | 45 class ProtoUtilsTest : public testing::Test { |
34 protected: | 46 protected: |
35 void SetUp() override {} | 47 void SetUp() override {} |
36 }; | 48 }; |
37 | 49 |
38 TEST_F(ProtoUtilsTest, PassEOSDecoderBuffer) { | 50 TEST_F(ProtoUtilsTest, PassEOSDecoderBuffer) { |
39 // 1. To DecoderBuffer | 51 // 1. To DecoderBuffer |
40 scoped_refptr<DecoderBuffer> input_buffer = DecoderBuffer::CreateEOSBuffer(); | 52 scoped_refptr<DecoderBuffer> input_buffer = DecoderBuffer::CreateEOSBuffer(); |
41 | 53 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 154 |
143 PipelineStatistics converted; | 155 PipelineStatistics converted; |
144 memset(&converted, ~0xcd, sizeof(converted)); // See note above. | 156 memset(&converted, ~0xcd, sizeof(converted)); // See note above. |
145 ConvertProtoToPipelineStatistics(pb_stats, &converted); | 157 ConvertProtoToPipelineStatistics(pb_stats, &converted); |
146 | 158 |
147 // If this fails, did media::PipelineStatistics add/change fields that are not | 159 // If this fails, did media::PipelineStatistics add/change fields that are not |
148 // being set by media::remoting::ConvertProtoToPipelineStatistics()? | 160 // being set by media::remoting::ConvertProtoToPipelineStatistics()? |
149 EXPECT_EQ(0, memcmp(&original, &converted, sizeof(converted))); | 161 EXPECT_EQ(0, memcmp(&original, &converted, sizeof(converted))); |
150 } | 162 } |
151 | 163 |
152 // TODO(miu): Tests for all other conversion functions. | 164 TEST_F(ProtoUtilsTest, VideoDecoderConfigConversionTest) { |
165 const VideoDecoderConfig video_config = TestVideoConfig::Normal(); | |
166 ASSERT_TRUE(video_config.IsValidConfig()); | |
167 pb::VideoDecoderConfig message; | |
168 ConvertVideoDecoderConfigToProto(video_config, &message); | |
169 VideoDecoderConfig converted; | |
170 ASSERT_TRUE(ConvertProtoToVideoDecoderConfig(message, &converted)); | |
171 ASSERT_TRUE(converted.Matches(video_config)); | |
172 } | |
153 | 173 |
154 TEST_F(ProtoUtilsTest, CdmPromiseResultConversion) { | 174 TEST_F(ProtoUtilsTest, CdmPromiseResultConversion) { |
155 CdmPromiseResult success_result = CdmPromiseResult::SuccessResult(); | 175 CdmPromiseResult success_result = CdmPromiseResult::SuccessResult(); |
156 | 176 |
157 pb::CdmPromise promise_message; | 177 pb::CdmPromise promise_message; |
158 ConvertCdmPromiseToProto(success_result, &promise_message); | 178 ConvertCdmPromiseToProto(success_result, &promise_message); |
159 | 179 |
160 CdmPromiseResult output_result; | 180 CdmPromiseResult output_result; |
161 ASSERT_TRUE(ConvertProtoToCdmPromise(promise_message, &output_result)); | 181 ASSERT_TRUE(ConvertProtoToCdmPromise(promise_message, &output_result)); |
162 | 182 |
163 ASSERT_EQ(success_result.success(), output_result.success()); | 183 VerifyCdmPromiseResultsEqual(success_result, output_result); |
164 ASSERT_EQ(success_result.exception(), output_result.exception()); | 184 } |
165 ASSERT_EQ(success_result.system_code(), output_result.system_code()); | 185 |
166 ASSERT_EQ(success_result.error_message(), output_result.error_message()); | 186 TEST_F(ProtoUtilsTest, CdmPromiseResultWithCdmIdSessionIdConversion) { |
187 const int kCdmId = 5; | |
188 const std::string kSessionId = "session3"; | |
189 CdmPromiseResult success_result = CdmPromiseResult::SuccessResult(); | |
190 | |
191 pb::RpcMessage rpc; | |
192 rpc.set_handle(1); | |
193 pb::CdmPromise* promise_message = rpc.mutable_cdm_promise_rpc(); | |
194 | |
195 ConvertCdmPromiseWithSessionIdToProto(success_result, kSessionId, | |
196 promise_message); | |
197 CdmPromiseResult output_result; | |
198 std::string converted_session_id; | |
199 ASSERT_TRUE(ConvertProtoToCdmPromiseWithCdmIdSessionId( | |
200 rpc, &output_result, nullptr, &converted_session_id)); | |
201 VerifyCdmPromiseResultsEqual(success_result, output_result); | |
202 ASSERT_EQ(converted_session_id, kSessionId); | |
203 | |
204 ConvertCdmPromiseWithCdmIdToProto(success_result, kCdmId, promise_message); | |
miu
2017/01/25 23:53:34
Before calling the second converter, reset the |ou
xjz
2017/01/26 00:03:31
Done.
| |
205 int converted_cdm_id; | |
206 ASSERT_TRUE(ConvertProtoToCdmPromiseWithCdmIdSessionId( | |
207 rpc, &output_result, &converted_cdm_id, nullptr)); | |
208 VerifyCdmPromiseResultsEqual(success_result, output_result); | |
209 ASSERT_EQ(converted_cdm_id, kCdmId); | |
167 } | 210 } |
168 | 211 |
169 TEST_F(ProtoUtilsTest, CdmKeyInformationConversion) { | 212 TEST_F(ProtoUtilsTest, CdmKeyInformationConversion) { |
170 std::unique_ptr<CdmKeyInformation> cdm_key_info_1(new CdmKeyInformation( | 213 std::unique_ptr<CdmKeyInformation> cdm_key_info_1(new CdmKeyInformation( |
171 "key_1", CdmKeyInformation::OUTPUT_RESTRICTED, 100)); | 214 "key_1", CdmKeyInformation::OUTPUT_RESTRICTED, 100)); |
172 std::unique_ptr<CdmKeyInformation> cdm_key_info_2( | 215 std::unique_ptr<CdmKeyInformation> cdm_key_info_2( |
173 new CdmKeyInformation("key_2", CdmKeyInformation::EXPIRED, 11)); | 216 new CdmKeyInformation("key_2", CdmKeyInformation::EXPIRED, 11)); |
174 std::unique_ptr<CdmKeyInformation> cdm_key_info_3( | 217 std::unique_ptr<CdmKeyInformation> cdm_key_info_3( |
175 new CdmKeyInformation("key_3", CdmKeyInformation::RELEASED, 22)); | 218 new CdmKeyInformation("key_3", CdmKeyInformation::RELEASED, 22)); |
176 CdmKeysInfo keys_information; | 219 CdmKeysInfo keys_information; |
(...skipping 11 matching lines...) Expand all Loading... | |
188 for (uint32_t i = 0; i < 3; i++) { | 231 for (uint32_t i = 0; i < 3; i++) { |
189 ASSERT_EQ(keys_information[i]->key_id, key_output_information[i]->key_id); | 232 ASSERT_EQ(keys_information[i]->key_id, key_output_information[i]->key_id); |
190 ASSERT_EQ(keys_information[i]->status, key_output_information[i]->status); | 233 ASSERT_EQ(keys_information[i]->status, key_output_information[i]->status); |
191 ASSERT_EQ(keys_information[i]->system_code, | 234 ASSERT_EQ(keys_information[i]->system_code, |
192 key_output_information[i]->system_code); | 235 key_output_information[i]->system_code); |
193 } | 236 } |
194 } | 237 } |
195 | 238 |
196 } // namespace remoting | 239 } // namespace remoting |
197 } // namespace media | 240 } // namespace media |
OLD | NEW |