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, RendererFlushCallbackRpc) { |
| 115 int rpc_handle = 3; |
| 116 |
| 117 // Convert RPC data structure into proto buffer string |
| 118 scoped_refptr<Rpc> from_rpc(new RendererFlushCallbackRpc(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, RendererSetCdmRpc) { |
| 160 // Convert RPC data structure into proto buffer string |
| 161 int rpc_handle = 3; |
| 162 int cdm_id = 2; |
| 163 int callback_handle = 1; |
| 164 scoped_refptr<Rpc> from_rpc( |
| 165 new RendererSetCdmRpc(rpc_handle, cdm_id, callback_handle)); |
| 166 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 167 int proc = from_rpc->GetProc(); |
| 168 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 169 |
| 170 // Convert proto buffer string back to RPC data structure. |
| 171 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 172 DCHECK(to_rpc); |
| 173 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 174 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 175 |
| 176 RendererSetCdmRpc* actual_to_rpc = |
| 177 static_cast<RendererSetCdmRpc*>(to_rpc.get()); |
| 178 ASSERT_EQ(cdm_id, actual_to_rpc->cdm_id()); |
| 179 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 180 } |
| 181 |
| 182 TEST_F(RemotingRpcTest, RendererClientOnTimeUpdateRpc) { |
| 183 // Convert RPC data structure into proto buffer string |
| 184 int rpc_handle = 3; |
| 185 int time_usec = 2; |
| 186 int max_time_usec = 1; |
| 187 scoped_refptr<Rpc> from_rpc( |
| 188 new RendererClientOnTimeUpdateRpc(rpc_handle, time_usec, max_time_usec)); |
| 189 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 190 int proc = from_rpc->GetProc(); |
| 191 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 192 |
| 193 // Convert proto buffer string back to RPC data structure. |
| 194 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 195 DCHECK(to_rpc); |
| 196 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 197 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 198 |
| 199 RendererClientOnTimeUpdateRpc* actual_to_rpc = |
| 200 static_cast<RendererClientOnTimeUpdateRpc*>(to_rpc.get()); |
| 201 ASSERT_EQ(time_usec, actual_to_rpc->time_usec()); |
| 202 ASSERT_EQ(max_time_usec, actual_to_rpc->max_time_usec()); |
| 203 } |
| 204 |
| 205 TEST_F(RemotingRpcTest, RendererClientOnVideoNaturalSizeChangeRpc) { |
| 206 // Convert RPC data structure into proto buffer string |
| 207 int rpc_handle = 3; |
| 208 gfx::Size size(640, 480); |
| 209 scoped_refptr<Rpc> from_rpc( |
| 210 new RendererClientOnVideoNaturalSizeChangeRpc(rpc_handle, size)); |
| 211 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 212 int proc = from_rpc->GetProc(); |
| 213 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 214 |
| 215 // Convert proto buffer string back to RPC data structure. |
| 216 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 217 DCHECK(to_rpc); |
| 218 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 219 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 220 |
| 221 RendererClientOnVideoNaturalSizeChangeRpc* actual_to_rpc = |
| 222 static_cast<RendererClientOnVideoNaturalSizeChangeRpc*>(to_rpc.get()); |
| 223 ASSERT_EQ(size, actual_to_rpc->size()); |
| 224 } |
| 225 |
| 226 TEST_F(RemotingRpcTest, DemuxerStreamReadUntilRpc) { |
| 227 // Convert RPC data structure into proto buffer string |
| 228 int rpc_handle = 3; |
| 229 uint32_t frame_id = 2; |
| 230 int callback_handle = 1; |
| 231 scoped_refptr<Rpc> from_rpc( |
| 232 new DemuxerStreamReadUntilRpc(rpc_handle, frame_id, callback_handle)); |
| 233 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 234 int proc = from_rpc->GetProc(); |
| 235 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 236 |
| 237 // Convert proto buffer string back to RPC data structure. |
| 238 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 239 DCHECK(to_rpc); |
| 240 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 241 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 242 |
| 243 DemuxerStreamReadUntilRpc* actual_to_rpc = |
| 244 static_cast<DemuxerStreamReadUntilRpc*>(to_rpc.get()); |
| 245 ASSERT_EQ(frame_id, actual_to_rpc->frame_id()); |
| 246 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 247 } |
| 248 |
| 249 TEST_F(RemotingRpcTest, DemuxerStreamInitializeCallbackRpc) { |
| 250 // Convert RPC data structure into proto buffer string |
| 251 int rpc_handle = 3; |
| 252 ::media::DemuxerStream::Type type = ::media::DemuxerStream::VIDEO; |
| 253 ::media::AudioDecoderConfig audio_config; |
| 254 ::media::VideoDecoderConfig video_config; |
| 255 scoped_refptr<Rpc> from_rpc(new DemuxerStreamInitializeCallbackRpc( |
| 256 rpc_handle, type, audio_config, video_config)); |
| 257 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 258 int proc = from_rpc->GetProc(); |
| 259 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 260 |
| 261 // Convert proto buffer string back to RPC data structure. |
| 262 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 263 DCHECK(to_rpc); |
| 264 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 265 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 266 |
| 267 DemuxerStreamInitializeCallbackRpc* actual_to_rpc = |
| 268 static_cast<DemuxerStreamInitializeCallbackRpc*>(to_rpc.get()); |
| 269 ASSERT_EQ(type, actual_to_rpc->type()); |
| 270 // TODO(erickung) compare |audio_config| and |video_config|; |
| 271 } |
| 272 |
| 273 TEST_F(RemotingRpcTest, DemuxerStreamReadUntilCallbackRpc) { |
| 274 // Convert RPC data structure into proto buffer string |
| 275 int rpc_handle = 3; |
| 276 uint32_t frame_id = 100; |
| 277 ::media::DemuxerStream::Status status = ::media::DemuxerStream::kOk; |
| 278 ::media::AudioDecoderConfig audio_config; |
| 279 ::media::VideoDecoderConfig video_config; |
| 280 scoped_refptr<Rpc> from_rpc(new DemuxerStreamReadUntilCallbackRpc( |
| 281 rpc_handle, frame_id, status, 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 DemuxerStreamReadUntilCallbackRpc* actual_to_rpc = |
| 293 static_cast<DemuxerStreamReadUntilCallbackRpc*>(to_rpc.get()); |
| 294 ASSERT_EQ(frame_id, actual_to_rpc->frame_id()); |
| 295 ASSERT_EQ(status, actual_to_rpc->status()); |
| 296 // TODO(erickung) compare |audio_config| and |video_config|; |
| 297 } |
| 298 |
| 299 TEST_F(RemotingRpcTest, CdmInitializeRpc) { |
| 300 // Convert RPC data structure into proto buffer string |
| 301 int rpc_handle = 3; |
| 302 std::string key_system; |
| 303 std::string security_origin; |
| 304 ::media::CdmConfig cdm_config; |
| 305 cdm_config.allow_distinctive_identifier = true; |
| 306 cdm_config.allow_persistent_state = false; |
| 307 cdm_config.use_hw_secure_codecs = true; |
| 308 int callback_handle = 4; |
| 309 scoped_refptr<Rpc> from_rpc(new CdmInitializeRpc( |
| 310 rpc_handle, key_system, security_origin, cdm_config, callback_handle)); |
| 311 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 312 int proc = from_rpc->GetProc(); |
| 313 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 314 |
| 315 // Convert proto buffer string back to RPC data structure. |
| 316 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 317 DCHECK(to_rpc); |
| 318 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 319 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 320 |
| 321 CdmInitializeRpc* actual_to_rpc = |
| 322 static_cast<CdmInitializeRpc*>(to_rpc.get()); |
| 323 ASSERT_EQ(key_system, actual_to_rpc->key_system()); |
| 324 ASSERT_EQ(security_origin, actual_to_rpc->security_origin()); |
| 325 ::media::CdmConfig cdm_config_out = actual_to_rpc->cdm_config(); |
| 326 ASSERT_EQ(cdm_config.allow_distinctive_identifier, |
| 327 cdm_config_out.allow_distinctive_identifier); |
| 328 ASSERT_EQ(cdm_config.allow_persistent_state, |
| 329 cdm_config_out.allow_persistent_state); |
| 330 ASSERT_EQ(cdm_config.use_hw_secure_codecs, |
| 331 cdm_config_out.use_hw_secure_codecs); |
| 332 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 333 } |
| 334 |
| 335 TEST_F(RemotingRpcTest, CdmSetServerCertificateRpc) { |
| 336 // Convert RPC data structure into proto buffer string |
| 337 int rpc_handle = 3; |
| 338 std::string data_blob("HereIsTestBlob"); |
| 339 std::vector<uint8_t> certificate_data(data_blob.begin(), data_blob.end()); |
| 340 int callback_handle = 4; |
| 341 scoped_refptr<Rpc> from_rpc( |
| 342 new CdmSetServerCertificateRpc(rpc_handle, &certificate_data[0], |
| 343 certificate_data.size(), callback_handle)); |
| 344 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 345 int proc = from_rpc->GetProc(); |
| 346 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 347 |
| 348 // Convert proto buffer string back to RPC data structure. |
| 349 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 350 DCHECK(to_rpc); |
| 351 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 352 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 353 |
| 354 CdmSetServerCertificateRpc* actual_to_rpc = |
| 355 static_cast<CdmSetServerCertificateRpc*>(to_rpc.get()); |
| 356 ASSERT_EQ(certificate_data.size(), actual_to_rpc->certificate_data_size()); |
| 357 std::string data_out_blob(actual_to_rpc->certificate_data(), |
| 358 actual_to_rpc->certificate_data() + |
| 359 actual_to_rpc->certificate_data_size()); |
| 360 ASSERT_EQ(data_blob, data_out_blob); |
| 361 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 362 } |
| 363 |
| 364 TEST_F(RemotingRpcTest, CdmCreateSessionAndGenerateRequestRpc) { |
| 365 // Convert RPC data structure into proto buffer string |
| 366 int rpc_handle = 3; |
| 367 ::media::MediaKeys::SessionType session_type = |
| 368 ::media::MediaKeys::TEMPORARY_SESSION; |
| 369 ::media::EmeInitDataType init_data_type = ::media::EmeInitDataType::CENC; |
| 370 std::string data_blob("Arbitrary##Data@@@"); |
| 371 std::vector<uint8_t> init_data(data_blob.begin(), data_blob.end()); |
| 372 int callback_handle = 4; |
| 373 scoped_refptr<Rpc> from_rpc(new CdmCreateSessionAndGenerateRequestRpc( |
| 374 rpc_handle, session_type, init_data_type, &init_data[0], init_data.size(), |
| 375 callback_handle)); |
| 376 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 377 int proc = from_rpc->GetProc(); |
| 378 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 379 |
| 380 // Convert proto buffer string back to RPC data structure. |
| 381 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 382 DCHECK(to_rpc); |
| 383 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 384 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 385 |
| 386 CdmCreateSessionAndGenerateRequestRpc* actual_to_rpc = |
| 387 static_cast<CdmCreateSessionAndGenerateRequestRpc*>(to_rpc.get()); |
| 388 ASSERT_EQ(session_type, actual_to_rpc->session_type()); |
| 389 ASSERT_EQ(init_data_type, actual_to_rpc->init_data_type()); |
| 390 ASSERT_EQ(init_data.size(), actual_to_rpc->init_data_size()); |
| 391 std::string data_out_blob( |
| 392 actual_to_rpc->init_data(), |
| 393 actual_to_rpc->init_data() + actual_to_rpc->init_data_size()); |
| 394 ASSERT_EQ(data_blob, data_out_blob); |
| 395 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 396 } |
| 397 |
| 398 TEST_F(RemotingRpcTest, CdmUpdateSessionRpc) { |
| 399 // Convert RPC data structure into proto buffer string |
| 400 int rpc_handle = 3; |
| 401 std::string session_id; |
| 402 std::string data_blob("___!!AS#HGSTU"); |
| 403 std::vector<uint8_t> response(data_blob.begin(), data_blob.end()); |
| 404 int callback_handle = 4; |
| 405 scoped_refptr<Rpc> from_rpc(new CdmUpdateSessionRpc( |
| 406 rpc_handle, session_id, &response[0], response.size(), callback_handle)); |
| 407 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 408 int proc = from_rpc->GetProc(); |
| 409 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 410 |
| 411 // Convert proto buffer string back to RPC data structure. |
| 412 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 413 DCHECK(to_rpc); |
| 414 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 415 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 416 |
| 417 CdmUpdateSessionRpc* actual_to_rpc = |
| 418 static_cast<CdmUpdateSessionRpc*>(to_rpc.get()); |
| 419 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 420 ASSERT_EQ(response.size(), actual_to_rpc->response_size()); |
| 421 std::string data_out_blob( |
| 422 actual_to_rpc->response(), |
| 423 actual_to_rpc->response() + actual_to_rpc->response_size()); |
| 424 ASSERT_EQ(data_blob, data_out_blob); |
| 425 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle()); |
| 426 } |
| 427 |
| 428 TEST_F(RemotingRpcTest, CdmSetServerCertificateCallbackRpc) { |
| 429 // Convert RPC data structure into proto buffer string |
| 430 int rpc_handle = 3; |
| 431 bool success = false; |
| 432 CdmPromiseResult result(::media::MediaKeys::UNKNOWN_ERROR, 3, ""); |
| 433 scoped_refptr<Rpc> from_rpc( |
| 434 new CdmSetServerCertificateCallbackRpc(rpc_handle, result)); |
| 435 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 436 int proc = from_rpc->GetProc(); |
| 437 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 438 |
| 439 // Convert proto buffer string back to RPC data structure. |
| 440 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 441 DCHECK(to_rpc); |
| 442 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 443 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 444 |
| 445 CdmSetServerCertificateCallbackRpc* actual_to_rpc = |
| 446 static_cast<CdmSetServerCertificateCallbackRpc*>(to_rpc.get()); |
| 447 const CdmPromiseResult result_out = actual_to_rpc->result(); |
| 448 ASSERT_EQ(success, result_out.success()); |
| 449 ASSERT_EQ(result.exception(), result_out.exception()); |
| 450 ASSERT_EQ(result.system_code(), result_out.system_code()); |
| 451 ASSERT_EQ(result.error_message(), result_out.error_message()); |
| 452 } |
| 453 |
| 454 TEST_F(RemotingRpcTest, CdmCreateSessionAndGenerateRequestCallbackRpc) { |
| 455 // Convert RPC data structure into proto buffer string |
| 456 int rpc_handle = 3; |
| 457 bool success = true; |
| 458 std::string session_id; |
| 459 CdmPromiseResult result(CdmPromiseResult::SuccessResult()); |
| 460 scoped_refptr<Rpc> from_rpc(new CdmCreateSessionAndGenerateRequestCallbackRpc( |
| 461 rpc_handle, result, session_id)); |
| 462 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 463 int proc = from_rpc->GetProc(); |
| 464 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 465 |
| 466 // Convert proto buffer string back to RPC data structure. |
| 467 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 468 DCHECK(to_rpc); |
| 469 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 470 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 471 |
| 472 CdmCreateSessionAndGenerateRequestCallbackRpc* actual_to_rpc = |
| 473 static_cast<CdmCreateSessionAndGenerateRequestCallbackRpc*>(to_rpc.get()); |
| 474 const CdmPromiseResult result_out = actual_to_rpc->result(); |
| 475 ASSERT_EQ(success, result_out.success()); |
| 476 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 477 } |
| 478 |
| 479 TEST_F(RemotingRpcTest, CdmInitializeCallbackRpc) { |
| 480 // Convert RPC data structure into proto buffer string |
| 481 int rpc_handle = 3; |
| 482 bool success = true; |
| 483 CdmPromiseResult result(CdmPromiseResult::SuccessResult()); |
| 484 int cdm_id = 4; |
| 485 int decryptor_handle = 5; |
| 486 scoped_refptr<Rpc> from_rpc(new CdmInitializeCallbackRpc( |
| 487 rpc_handle, result, cdm_id, decryptor_handle)); |
| 488 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 489 int proc = from_rpc->GetProc(); |
| 490 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 491 |
| 492 // Convert proto buffer string back to RPC data structure. |
| 493 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 494 DCHECK(to_rpc); |
| 495 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 496 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 497 |
| 498 CdmInitializeCallbackRpc* actual_to_rpc = |
| 499 static_cast<CdmInitializeCallbackRpc*>(to_rpc.get()); |
| 500 const CdmPromiseResult result_out = actual_to_rpc->result(); |
| 501 ASSERT_EQ(success, result_out.success()); |
| 502 ASSERT_EQ(cdm_id, actual_to_rpc->cdm_id()); |
| 503 ASSERT_EQ(decryptor_handle, actual_to_rpc->decryptor_handle()); |
| 504 } |
| 505 |
| 506 TEST_F(RemotingRpcTest, CdmClientOnSessionMessageRpc) { |
| 507 // Convert RPC data structure into proto buffer string |
| 508 int rpc_handle = 3; |
| 509 std::string session_id; |
| 510 ::media::MediaKeys::MessageType message_type = |
| 511 ::media::MediaKeys::LICENSE_RELEASE; |
| 512 std::string legacy_destination_url; |
| 513 uint8_t message[1] = {0xAB}; |
| 514 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionMessageRpc( |
| 515 rpc_handle, session_id, message_type, message, sizeof(message), |
| 516 legacy_destination_url)); |
| 517 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 518 int proc = from_rpc->GetProc(); |
| 519 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 520 |
| 521 // Convert proto buffer string back to RPC data structure. |
| 522 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 523 DCHECK(to_rpc); |
| 524 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 525 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 526 |
| 527 CdmClientOnSessionMessageRpc* actual_to_rpc = |
| 528 static_cast<CdmClientOnSessionMessageRpc*>(to_rpc.get()); |
| 529 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 530 ASSERT_EQ(message_type, actual_to_rpc->message_type()); |
| 531 ASSERT_EQ(message[0], actual_to_rpc->message()[0]); |
| 532 ASSERT_EQ(size_t(1), actual_to_rpc->message_size()); |
| 533 ASSERT_EQ(legacy_destination_url, actual_to_rpc->legacy_destination_url()); |
| 534 } |
| 535 |
| 536 TEST_F(RemotingRpcTest, CdmClientOnLegacySessionErrorRpc) { |
| 537 // Convert RPC data structure into proto buffer string |
| 538 int rpc_handle = 3; |
| 539 std::string session_id; |
| 540 ::media::MediaKeys::Exception exception = ::media::MediaKeys::UNKNOWN_ERROR; |
| 541 uint32_t system_code = 23; |
| 542 std::string error_message; |
| 543 scoped_refptr<Rpc> from_rpc(new CdmClientOnLegacySessionErrorRpc( |
| 544 rpc_handle, session_id, exception, system_code, error_message)); |
| 545 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 546 int proc = from_rpc->GetProc(); |
| 547 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 548 |
| 549 // Convert proto buffer string back to RPC data structure. |
| 550 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 551 DCHECK(to_rpc); |
| 552 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 553 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 554 |
| 555 CdmClientOnLegacySessionErrorRpc* actual_to_rpc = |
| 556 static_cast<CdmClientOnLegacySessionErrorRpc*>(to_rpc.get()); |
| 557 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 558 ASSERT_EQ(exception, actual_to_rpc->exception()); |
| 559 ASSERT_EQ(system_code, actual_to_rpc->system_code()); |
| 560 ASSERT_EQ(error_message, actual_to_rpc->error_message()); |
| 561 } |
| 562 |
| 563 TEST_F(RemotingRpcTest, CdmClientOnSessionKeysChangeRpc) { |
| 564 // Convert RPC data structure into proto buffer string |
| 565 int rpc_handle = 3; |
| 566 std::string session_id; |
| 567 bool has_additional_usable_key = false; |
| 568 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionKeysChangeRpc( |
| 569 rpc_handle, session_id, has_additional_usable_key, nullptr, 0)); |
| 570 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 571 int proc = from_rpc->GetProc(); |
| 572 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 573 |
| 574 // Convert proto buffer string back to RPC data structure. |
| 575 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 576 DCHECK(to_rpc); |
| 577 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 578 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 579 |
| 580 CdmClientOnSessionKeysChangeRpc* actual_to_rpc = |
| 581 static_cast<CdmClientOnSessionKeysChangeRpc*>(to_rpc.get()); |
| 582 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 583 ASSERT_EQ(has_additional_usable_key, |
| 584 actual_to_rpc->has_additional_usable_key()); |
| 585 ASSERT_EQ(nullptr, actual_to_rpc->key_information()); |
| 586 ASSERT_EQ(static_cast<size_t>(0), actual_to_rpc->key_information_size()); |
| 587 } |
| 588 |
| 589 TEST_F(RemotingRpcTest, CdmClientOnSessionExpirationUpdateRpc) { |
| 590 // Convert RPC data structure into proto buffer string |
| 591 int rpc_handle = 3; |
| 592 std::string session_id; |
| 593 double new_expiry_time_sec = 3600.2; |
| 594 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionExpirationUpdateRpc( |
| 595 rpc_handle, session_id, new_expiry_time_sec)); |
| 596 ASSERT_EQ(rpc_handle, from_rpc->handle()); |
| 597 int proc = from_rpc->GetProc(); |
| 598 std::string proto_buffer_string = from_rpc->ToMessage(); |
| 599 |
| 600 // Convert proto buffer string back to RPC data structure. |
| 601 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string); |
| 602 DCHECK(to_rpc); |
| 603 ASSERT_EQ(proc, to_rpc->GetProc()); |
| 604 ASSERT_EQ(rpc_handle, to_rpc->handle()); |
| 605 |
| 606 CdmClientOnSessionExpirationUpdateRpc* actual_to_rpc = |
| 607 static_cast<CdmClientOnSessionExpirationUpdateRpc*>(to_rpc.get()); |
| 608 ASSERT_EQ(session_id, actual_to_rpc->session_id()); |
| 609 ASSERT_EQ(new_expiry_time_sec, actual_to_rpc->new_expiry_time_sec()); |
| 610 } |
| 611 |
| 612 } // namespace remoting |
| 613 } // namespace media |
OLD | NEW |