OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/remoting/rpc/rpc.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <string> |
| 9 #include <utility> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "media/base/audio_decoder_config.h" |
| 15 #include "media/base/cdm_config.h" |
| 16 #include "media/base/cdm_key_information.h" |
| 17 #include "media/base/demuxer_stream.h" |
| 18 #include "media/base/eme_constants.h" |
| 19 #include "media/base/media_keys.h" |
| 20 #include "media/base/video_decoder_config.h" |
| 21 #include "media/remoting/remoting_rpc_message.pb.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 |
| 25 using testing::_; |
| 26 using testing::Invoke; |
| 27 using testing::Return; |
| 28 |
| 29 namespace media { |
| 30 namespace remoting { |
| 31 |
| 32 class RemotingRpcTest : public testing::Test { |
| 33 protected: |
| 34 void SetUp() override {} |
| 35 }; |
| 36 |
| 37 TEST_F(RemotingRpcTest, GarbageInput) { |
| 38 std::string proto_buffer_string("$%@#$@$%$&%^&^%*^&^&...."); |
| 39 |
| 40 // Convert proto buffer string back to RPC data structure. |
| 41 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 42 DCHECK(!to_rpc); |
| 43 } |
| 44 |
| 45 // Test RPC message which has single integer message. |
| 46 TEST_F(RemotingRpcTest, AcquireRendererRpc) { |
| 47 int rpc_handle = 3; |
| 48 |
| 49 // Convert RPC data structure into proto buffer string |
| 50 int value = 0; |
| 51 scoped_refptr<Rpc> from_rpc(new AcquireRendererRpc(rpc_handle, value)); |
| 52 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 53 int proc = from_rpc->GetProc(); |
| 54 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 55 |
| 56 // Convert proto buffer string back to RPC data structure. |
| 57 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 58 DCHECK(to_rpc); |
| 59 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 60 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 61 |
| 62 AcquireRendererRpc* actual_to_rpc = |
| 63 static_cast<AcquireRendererRpc*>(to_rpc.get()); |
| 64 ASSERT_EQ(value, actual_to_rpc->value()); |
| 65 } |
| 66 |
| 67 // Test RPC message which has single double message. |
| 68 TEST_F(RemotingRpcTest, RendererSetPlaybackRateRpc) { |
| 69 int rpc_handle = 3; |
| 70 |
| 71 // Convert RPC data structure into proto buffer string |
| 72 double value = 1.1; |
| 73 scoped_refptr<Rpc> from_rpc( |
| 74 new RendererSetPlaybackRateRpc(rpc_handle, value)); |
| 75 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 76 int proc = from_rpc->GetProc(); |
| 77 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 78 |
| 79 // Convert proto buffer string back to RPC data structure. |
| 80 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 81 DCHECK(to_rpc); |
| 82 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 83 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 84 |
| 85 RendererSetPlaybackRateRpc* actual_to_rpc = |
| 86 static_cast<RendererSetPlaybackRateRpc*>(to_rpc.get()); |
| 87 ASSERT_EQ(value, actual_to_rpc->value()); |
| 88 } |
| 89 |
| 90 // Test RPC message which has single boolean message. |
| 91 TEST_F(RemotingRpcTest, RendererInitializeCallbackRpc) { |
| 92 int rpc_handle = 3; |
| 93 |
| 94 // Convert RPC data structure into proto buffer string |
| 95 bool value = true; |
| 96 scoped_refptr<Rpc> from_rpc( |
| 97 new RendererInitializeCallbackRpc(rpc_handle, value)); |
| 98 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 99 int proc = from_rpc->GetProc(); |
| 100 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 101 |
| 102 // Convert proto buffer string back to RPC data structure. |
| 103 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 104 DCHECK(to_rpc); |
| 105 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 106 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 107 |
| 108 RendererInitializeCallbackRpc* actual_to_rpc = |
| 109 static_cast<RendererInitializeCallbackRpc*>(to_rpc.get()); |
| 110 ASSERT_EQ(value, actual_to_rpc->value()); |
| 111 } |
| 112 |
| 113 // Test RPC message which has no additional message. |
| 114 TEST_F(RemotingRpcTest, RendererFlushUntilCallbackRpc) { |
| 115 int rpc_handle = 3; |
| 116 |
| 117 // Convert RPC data structure into proto buffer string |
| 118 scoped_refptr<Rpc> from_rpc(new RendererFlushUntilCallbackRpc(rpc_handle)); |
| 119 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 120 int proc = from_rpc->GetProc(); |
| 121 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 122 |
| 123 // Convert proto buffer string back to RPC data structure. |
| 124 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 125 DCHECK(to_rpc); |
| 126 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 127 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 128 } |
| 129 |
| 130 // Following are the RPC message which have various data structure. |
| 131 TEST_F(RemotingRpcTest, RendererInitializeRpc) { |
| 132 // Convert RPC data structure into proto buffer string |
| 133 int rpc_handle = 3; |
| 134 int client_handle = 4; |
| 135 int audio_demuxer_handle = 5; |
| 136 int video_demuxer_handle = 6; |
| 137 int callback_handle = 7; |
| 138 scoped_refptr<Rpc> from_rpc( |
| 139 new RendererInitializeRpc(rpc_handle, client_handle, audio_demuxer_handle, |
| 140 video_demuxer_handle, callback_handle)); |
| 141 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 142 int proc = from_rpc->GetProc(); |
| 143 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 144 |
| 145 // Convert proto buffer string back to RPC data structure. |
| 146 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 147 DCHECK(to_rpc); |
| 148 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 149 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 150 |
| 151 RendererInitializeRpc* actual_to_rpc = |
| 152 static_cast<RendererInitializeRpc*>(to_rpc.get()); |
| 153 ASSERT_EQ(client_handle, actual_to_rpc->client_handle()); |
| 154 ASSERT_EQ(audio_demuxer_handle, actual_to_rpc->audio_demuxer_handle()); |
| 155 ASSERT_EQ(video_demuxer_handle, actual_to_rpc->video_demuxer_handle()); |
| 156 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 157 } |
| 158 |
| 159 TEST_F(RemotingRpcTest, RendererFlushUntilRpc) { |
| 160 // Convert RPC data structure into proto buffer string |
| 161 int rpc_handle = 3; |
| 162 uint32_t audio_frame_id = 4; |
| 163 uint32_t video_frame_id = 5; |
| 164 int callback_handle = 6; |
| 165 scoped_refptr<Rpc> from_rpc(new RendererFlushUntilRpc( |
| 166 rpc_handle, audio_frame_id, video_frame_id, callback_handle)); |
| 167 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 168 int proc = from_rpc->GetProc(); |
| 169 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 170 |
| 171 // Convert proto buffer string back to RPC data structure. |
| 172 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 173 DCHECK(to_rpc); |
| 174 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 175 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 176 |
| 177 RendererFlushUntilRpc* actual_to_rpc = |
| 178 static_cast<RendererFlushUntilRpc*>(to_rpc.get()); |
| 179 ASSERT_EQ(audio_frame_id, actual_to_rpc->audio_frame_id()); |
| 180 ASSERT_EQ(video_frame_id, actual_to_rpc->video_frame_id()); |
| 181 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 182 } |
| 183 |
| 184 TEST_F(RemotingRpcTest, RendererSetCdmRpc) { |
| 185 // Convert RPC data structure into proto buffer string |
| 186 int rpc_handle = 3; |
| 187 int cdm_id = 2; |
| 188 int callback_handle = 1; |
| 189 scoped_refptr<Rpc> from_rpc( |
| 190 new RendererSetCdmRpc(rpc_handle, cdm_id, callback_handle)); |
| 191 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 192 int proc = from_rpc->GetProc(); |
| 193 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 194 |
| 195 // Convert proto buffer string back to RPC data structure. |
| 196 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 197 DCHECK(to_rpc); |
| 198 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 199 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 200 |
| 201 RendererSetCdmRpc* actual_to_rpc = |
| 202 static_cast<RendererSetCdmRpc*>(to_rpc.get()); |
| 203 ASSERT_EQ(cdm_id, actual_to_rpc->cdm_id()); |
| 204 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 205 } |
| 206 |
| 207 TEST_F(RemotingRpcTest, RendererClientOnTimeUpdateRpc) { |
| 208 // Convert RPC data structure into proto buffer string |
| 209 int rpc_handle = 3; |
| 210 int time_usec = 2; |
| 211 int max_time_usec = 1; |
| 212 scoped_refptr<Rpc> from_rpc( |
| 213 new RendererClientOnTimeUpdateRpc(rpc_handle, time_usec, max_time_usec)); |
| 214 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 215 int proc = from_rpc->GetProc(); |
| 216 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 217 |
| 218 // Convert proto buffer string back to RPC data structure. |
| 219 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 220 DCHECK(to_rpc); |
| 221 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 222 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 223 |
| 224 RendererClientOnTimeUpdateRpc* actual_to_rpc = |
| 225 static_cast<RendererClientOnTimeUpdateRpc*>(to_rpc.get()); |
| 226 ASSERT_EQ(time_usec, actual_to_rpc->time_usec()); |
| 227 ASSERT_EQ(max_time_usec, actual_to_rpc->max_time_usec()); |
| 228 } |
| 229 |
| 230 TEST_F(RemotingRpcTest, RendererClientOnVideoNaturalSizeChangeRpc) { |
| 231 // Convert RPC data structure into proto buffer string |
| 232 int rpc_handle = 3; |
| 233 gfx::Size size(640, 480); |
| 234 scoped_refptr<Rpc> from_rpc( |
| 235 new RendererClientOnVideoNaturalSizeChangeRpc(rpc_handle, size)); |
| 236 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 237 int proc = from_rpc->GetProc(); |
| 238 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 239 |
| 240 // Convert proto buffer string back to RPC data structure. |
| 241 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 242 DCHECK(to_rpc); |
| 243 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 244 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 245 |
| 246 RendererClientOnVideoNaturalSizeChangeRpc* actual_to_rpc = |
| 247 static_cast<RendererClientOnVideoNaturalSizeChangeRpc*>(to_rpc.get()); |
| 248 ASSERT_EQ(size, actual_to_rpc->size()); |
| 249 } |
| 250 |
| 251 TEST_F(RemotingRpcTest, DemuxerStreamReadUntilRpc) { |
| 252 // Convert RPC data structure into proto buffer string |
| 253 int rpc_handle = 3; |
| 254 uint32_t frame_id = 2; |
| 255 int callback_handle = 1; |
| 256 scoped_refptr<Rpc> from_rpc( |
| 257 new DemuxerStreamReadUntilRpc(rpc_handle, frame_id, callback_handle)); |
| 258 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 259 int proc = from_rpc->GetProc(); |
| 260 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 261 |
| 262 // Convert proto buffer string back to RPC data structure. |
| 263 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 264 DCHECK(to_rpc); |
| 265 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 266 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 267 |
| 268 DemuxerStreamReadUntilRpc* actual_to_rpc = |
| 269 static_cast<DemuxerStreamReadUntilRpc*>(to_rpc.get()); |
| 270 ASSERT_EQ(frame_id, actual_to_rpc->frame_id()); |
| 271 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 272 } |
| 273 |
| 274 TEST_F(RemotingRpcTest, DemuxerStreamInitializeCallbackRpc) { |
| 275 // Convert RPC data structure into proto buffer string |
| 276 int rpc_handle = 3; |
| 277 ::media::DemuxerStream::Type type = ::media::DemuxerStream::VIDEO; |
| 278 ::media::AudioDecoderConfig audio_config; |
| 279 ::media::VideoDecoderConfig video_config; |
| 280 scoped_refptr<Rpc> from_rpc(new DemuxerStreamInitializeCallbackRpc( |
| 281 rpc_handle, type, audio_config, video_config)); |
| 282 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 283 int proc = from_rpc->GetProc(); |
| 284 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 285 |
| 286 // Convert proto buffer string back to RPC data structure. |
| 287 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 288 DCHECK(to_rpc); |
| 289 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 290 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 291 |
| 292 DemuxerStreamInitializeCallbackRpc* actual_to_rpc = |
| 293 static_cast<DemuxerStreamInitializeCallbackRpc*>(to_rpc.get()); |
| 294 ASSERT_EQ(type, actual_to_rpc->type()); |
| 295 // TODO(erickung) compare |audio_config| and |video_config|; |
| 296 } |
| 297 |
| 298 TEST_F(RemotingRpcTest, DemuxerStreamReadUntilCallbackRpc) { |
| 299 // Convert RPC data structure into proto buffer string |
| 300 int rpc_handle = 3; |
| 301 uint32_t frame_id = 100; |
| 302 ::media::DemuxerStream::Status status = ::media::DemuxerStream::kOk; |
| 303 ::media::AudioDecoderConfig audio_config; |
| 304 ::media::VideoDecoderConfig video_config; |
| 305 scoped_refptr<Rpc> from_rpc(new DemuxerStreamReadUntilCallbackRpc( |
| 306 rpc_handle, frame_id, status, audio_config, video_config)); |
| 307 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 308 int proc = from_rpc->GetProc(); |
| 309 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 310 |
| 311 // Convert proto buffer string back to RPC data structure. |
| 312 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 313 DCHECK(to_rpc); |
| 314 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 315 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 316 |
| 317 DemuxerStreamReadUntilCallbackRpc* actual_to_rpc = |
| 318 static_cast<DemuxerStreamReadUntilCallbackRpc*>(to_rpc.get()); |
| 319 ASSERT_EQ(frame_id, actual_to_rpc->frame_id()); |
| 320 ASSERT_EQ(status, actual_to_rpc->status()); |
| 321 // TODO(erickung) compare |audio_config| and |video_config|; |
| 322 } |
| 323 |
| 324 TEST_F(RemotingRpcTest, CdmInitializeRpc) { |
| 325 // Convert RPC data structure into proto buffer string |
| 326 int rpc_handle = 3; |
| 327 std::string key_system; |
| 328 std::string security_origin; |
| 329 ::media::CdmConfig cdm_config; |
| 330 cdm_config.allow_distinctive_identifier = true; |
| 331 cdm_config.allow_persistent_state = false; |
| 332 cdm_config.use_hw_secure_codecs = true; |
| 333 int callback_handle = 4; |
| 334 scoped_refptr<Rpc> from_rpc(new CdmInitializeRpc( |
| 335 rpc_handle, key_system, security_origin, cdm_config, callback_handle)); |
| 336 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 337 int proc = from_rpc->GetProc(); |
| 338 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 339 |
| 340 // Convert proto buffer string back to RPC data structure. |
| 341 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 342 DCHECK(to_rpc); |
| 343 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 344 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 345 |
| 346 CdmInitializeRpc* actual_to_rpc = |
| 347 static_cast<CdmInitializeRpc*>(to_rpc.get()); |
| 348 ASSERT_EQ(key_system, actual_to_rpc->key_system()); |
| 349 ASSERT_EQ(security_origin, actual_to_rpc->security_origin()); |
| 350 ::media::CdmConfig cdm_config_out = actual_to_rpc->cdm_config(); |
| 351 ASSERT_EQ(cdm_config.allow_distinctive_identifier, |
| 352 cdm_config_out.allow_distinctive_identifier); |
| 353 ASSERT_EQ(cdm_config.allow_persistent_state, |
| 354 cdm_config_out.allow_persistent_state); |
| 355 ASSERT_EQ(cdm_config.use_hw_secure_codecs, |
| 356 cdm_config_out.use_hw_secure_codecs); |
| 357 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 358 } |
| 359 |
| 360 TEST_F(RemotingRpcTest, CdmSetServerCertificateRpc) { |
| 361 // Convert RPC data structure into proto buffer string |
| 362 int rpc_handle = 3; |
| 363 std::string data_blob("HereIsTestBlob"); |
| 364 std::vector<uint8_t> certificate_data(data_blob.begin(), data_blob.end()); |
| 365 int callback_handle = 4; |
| 366 scoped_refptr<Rpc> from_rpc( |
| 367 new CdmSetServerCertificateRpc(rpc_handle, &certificate_data[0], |
| 368 certificate_data.size(), callback_handle)); |
| 369 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 370 int proc = from_rpc->GetProc(); |
| 371 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 372 |
| 373 // Convert proto buffer string back to RPC data structure. |
| 374 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 375 DCHECK(to_rpc); |
| 376 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 377 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 378 |
| 379 CdmSetServerCertificateRpc* actual_to_rpc = |
| 380 static_cast<CdmSetServerCertificateRpc*>(to_rpc.get()); |
| 381 ASSERT_EQ(certificate_data.size(), actual_to_rpc->certificate_data_size()); |
| 382 std::string data_out_blob(actual_to_rpc->certificate_data(), |
| 383 actual_to_rpc->certificate_data() + |
| 384 actual_to_rpc->certificate_data_size()); |
| 385 ASSERT_EQ(data_blob, data_out_blob); |
| 386 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 387 } |
| 388 |
| 389 TEST_F(RemotingRpcTest, CdmCreateSessionAndGenerateRequestRpc) { |
| 390 // Convert RPC data structure into proto buffer string |
| 391 int rpc_handle = 3; |
| 392 ::media::MediaKeys::SessionType session_type = |
| 393 ::media::MediaKeys::TEMPORARY_SESSION; |
| 394 ::media::EmeInitDataType init_data_type = ::media::EmeInitDataType::CENC; |
| 395 std::string data_blob("Arbitrary##Data@@@"); |
| 396 std::vector<uint8_t> init_data(data_blob.begin(), data_blob.end()); |
| 397 int callback_handle = 4; |
| 398 scoped_refptr<Rpc> from_rpc(new CdmCreateSessionAndGenerateRequestRpc( |
| 399 rpc_handle, session_type, init_data_type, &init_data[0], init_data.size(), |
| 400 callback_handle)); |
| 401 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 402 int proc = from_rpc->GetProc(); |
| 403 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 404 |
| 405 // Convert proto buffer string back to RPC data structure. |
| 406 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 407 DCHECK(to_rpc); |
| 408 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 409 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 410 |
| 411 CdmCreateSessionAndGenerateRequestRpc* actual_to_rpc = |
| 412 static_cast<CdmCreateSessionAndGenerateRequestRpc*>(to_rpc.get()); |
| 413 ASSERT_EQ(session_type, actual_to_rpc->session_type()); |
| 414 ASSERT_EQ(init_data_type, actual_to_rpc->init_data_type()); |
| 415 ASSERT_EQ(init_data.size(), actual_to_rpc->init_data_size()); |
| 416 std::string data_out_blob( |
| 417 actual_to_rpc->init_data(), |
| 418 actual_to_rpc->init_data() + actual_to_rpc->init_data_size()); |
| 419 ASSERT_EQ(data_blob, data_out_blob); |
| 420 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 421 } |
| 422 |
| 423 TEST_F(RemotingRpcTest, CdmUpdateSessionRpc) { |
| 424 // Convert RPC data structure into proto buffer string |
| 425 int rpc_handle = 3; |
| 426 std::string session_id; |
| 427 std::string data_blob("___!!AS#HGSTU"); |
| 428 std::vector<uint8_t> response(data_blob.begin(), data_blob.end()); |
| 429 int callback_handle = 4; |
| 430 scoped_refptr<Rpc> from_rpc(new CdmUpdateSessionRpc( |
| 431 rpc_handle, session_id, &response[0], response.size(), callback_handle)); |
| 432 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 433 int proc = from_rpc->GetProc(); |
| 434 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 435 |
| 436 // Convert proto buffer string back to RPC data structure. |
| 437 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 438 DCHECK(to_rpc); |
| 439 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 440 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 441 |
| 442 CdmUpdateSessionRpc* actual_to_rpc = |
| 443 static_cast<CdmUpdateSessionRpc*>(to_rpc.get()); |
| 444 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 445 ASSERT_EQ(response.size(), actual_to_rpc->response_size()); |
| 446 std::string data_out_blob( |
| 447 actual_to_rpc->response(), |
| 448 actual_to_rpc->response() + actual_to_rpc->response_size()); |
| 449 ASSERT_EQ(data_blob, data_out_blob); |
| 450 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 451 } |
| 452 |
| 453 TEST_F(RemotingRpcTest, CdmSetServerCertificateCallbackRpc) { |
| 454 // Convert RPC data structure into proto buffer string |
| 455 int rpc_handle = 3; |
| 456 bool success = false; |
| 457 CdmPromiseResult result(::media::MediaKeys::UNKNOWN_ERROR, 3, ""); |
| 458 scoped_refptr<Rpc> from_rpc( |
| 459 new CdmSetServerCertificateCallbackRpc(rpc_handle, result)); |
| 460 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 461 int proc = from_rpc->GetProc(); |
| 462 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 463 |
| 464 // Convert proto buffer string back to RPC data structure. |
| 465 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 466 DCHECK(to_rpc); |
| 467 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 468 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 469 |
| 470 CdmSetServerCertificateCallbackRpc* actual_to_rpc = |
| 471 static_cast<CdmSetServerCertificateCallbackRpc*>(to_rpc.get()); |
| 472 const CdmPromiseResult result_out = actual_to_rpc->result(); |
| 473 ASSERT_EQ(success, result_out.success()); |
| 474 ASSERT_EQ(result.exception(), result_out.exception()); |
| 475 ASSERT_EQ(result.system_code(), result_out.system_code()); |
| 476 ASSERT_EQ(result.error_message(), result_out.error_message()); |
| 477 } |
| 478 |
| 479 TEST_F(RemotingRpcTest, CdmCreateSessionAndGenerateRequestCallbackRpc) { |
| 480 // Convert RPC data structure into proto buffer string |
| 481 int rpc_handle = 3; |
| 482 bool success = true; |
| 483 std::string session_id; |
| 484 CdmPromiseResult result(CdmPromiseResult::SuccessResult()); |
| 485 scoped_refptr<Rpc> from_rpc(new CdmCreateSessionAndGenerateRequestCallbackRpc( |
| 486 rpc_handle, result, session_id)); |
| 487 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 488 int proc = from_rpc->GetProc(); |
| 489 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 490 |
| 491 // Convert proto buffer string back to RPC data structure. |
| 492 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 493 DCHECK(to_rpc); |
| 494 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 495 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 496 |
| 497 CdmCreateSessionAndGenerateRequestCallbackRpc* actual_to_rpc = |
| 498 static_cast<CdmCreateSessionAndGenerateRequestCallbackRpc*>(to_rpc.get()); |
| 499 const CdmPromiseResult result_out = actual_to_rpc->result(); |
| 500 ASSERT_EQ(success, result_out.success()); |
| 501 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 502 } |
| 503 |
| 504 TEST_F(RemotingRpcTest, CdmInitializeCallbackRpc) { |
| 505 // Convert RPC data structure into proto buffer string |
| 506 int rpc_handle = 3; |
| 507 bool success = true; |
| 508 CdmPromiseResult result(CdmPromiseResult::SuccessResult()); |
| 509 int cdm_id = 4; |
| 510 int decryptor_handle = 5; |
| 511 scoped_refptr<Rpc> from_rpc(new CdmInitializeCallbackRpc( |
| 512 rpc_handle, result, cdm_id, decryptor_handle)); |
| 513 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 514 int proc = from_rpc->GetProc(); |
| 515 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 516 |
| 517 // Convert proto buffer string back to RPC data structure. |
| 518 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 519 DCHECK(to_rpc); |
| 520 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 521 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 522 |
| 523 CdmInitializeCallbackRpc* actual_to_rpc = |
| 524 static_cast<CdmInitializeCallbackRpc*>(to_rpc.get()); |
| 525 const CdmPromiseResult result_out = actual_to_rpc->result(); |
| 526 ASSERT_EQ(success, result_out.success()); |
| 527 ASSERT_EQ(cdm_id, actual_to_rpc->cdm_id()); |
| 528 ASSERT_EQ(decryptor_handle, actual_to_rpc->decryptor_handle()); |
| 529 } |
| 530 |
| 531 TEST_F(RemotingRpcTest, CdmClientOnSessionMessageRpc) { |
| 532 // Convert RPC data structure into proto buffer string |
| 533 int rpc_handle = 3; |
| 534 std::string session_id; |
| 535 ::media::MediaKeys::MessageType message_type = |
| 536 ::media::MediaKeys::LICENSE_RELEASE; |
| 537 uint8_t message[1] = {0xAB}; |
| 538 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionMessageRpc( |
| 539 rpc_handle, session_id, message_type, message, sizeof(message))); |
| 540 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 541 int proc = from_rpc->GetProc(); |
| 542 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 543 |
| 544 // Convert proto buffer string back to RPC data structure. |
| 545 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 546 DCHECK(to_rpc); |
| 547 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 548 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 549 |
| 550 CdmClientOnSessionMessageRpc* actual_to_rpc = |
| 551 static_cast<CdmClientOnSessionMessageRpc*>(to_rpc.get()); |
| 552 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 553 ASSERT_EQ(message_type, actual_to_rpc->message_type()); |
| 554 ASSERT_EQ(message[0], actual_to_rpc->message()[0]); |
| 555 ASSERT_EQ(size_t(1), actual_to_rpc->message_size()); |
| 556 } |
| 557 |
| 558 TEST_F(RemotingRpcTest, CdmClientOnSessionKeysChangeRpc) { |
| 559 // Convert RPC data structure into proto buffer string |
| 560 int rpc_handle = 3; |
| 561 std::string session_id; |
| 562 bool has_additional_usable_key = false; |
| 563 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionKeysChangeRpc( |
| 564 rpc_handle, session_id, has_additional_usable_key, nullptr, 0)); |
| 565 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 566 int proc = from_rpc->GetProc(); |
| 567 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 568 |
| 569 // Convert proto buffer string back to RPC data structure. |
| 570 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 571 DCHECK(to_rpc); |
| 572 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 573 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 574 |
| 575 CdmClientOnSessionKeysChangeRpc* actual_to_rpc = |
| 576 static_cast<CdmClientOnSessionKeysChangeRpc*>(to_rpc.get()); |
| 577 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 578 ASSERT_EQ(has_additional_usable_key, |
| 579 actual_to_rpc->has_additional_usable_key()); |
| 580 ASSERT_EQ(nullptr, actual_to_rpc->key_information()); |
| 581 ASSERT_EQ(static_cast<size_t>(0), actual_to_rpc->key_information_size()); |
| 582 } |
| 583 |
| 584 TEST_F(RemotingRpcTest, CdmClientOnSessionExpirationUpdateRpc) { |
| 585 // Convert RPC data structure into proto buffer string |
| 586 int rpc_handle = 3; |
| 587 std::string session_id; |
| 588 double new_expiry_time_sec = 3600.2; |
| 589 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionExpirationUpdateRpc( |
| 590 rpc_handle, session_id, new_expiry_time_sec)); |
| 591 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 592 int proc = from_rpc->GetProc(); |
| 593 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 594 |
| 595 // Convert proto buffer string back to RPC data structure. |
| 596 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 597 DCHECK(to_rpc); |
| 598 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 599 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 600 |
| 601 CdmClientOnSessionExpirationUpdateRpc* actual_to_rpc = |
| 602 static_cast<CdmClientOnSessionExpirationUpdateRpc*>(to_rpc.get()); |
| 603 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 604 ASSERT_EQ(new_expiry_time_sec, actual_to_rpc->new_expiry_time_sec()); |
| 605 } |
| 606 |
| 607 } // namespace remoting |
| 608 } // namespace media |
OLD | NEW |