Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: media/remoting/rpc/rpc_unittest.cc

Issue 2261503002: Define remote playback proto buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add OWNERS file Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« media/remoting/rpc/rpc.cc ('K') | « media/remoting/rpc/rpc.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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, RendererClientOnStatisticsUpdateRpc) {
252 // Convert RPC data structure into proto buffer string
253 int rpc_handle = 3;
254 ::media::PipelineStatistics stats;
255 stats.audio_bytes_decoded = 1;
256 stats.video_bytes_decoded = 2;
257 stats.video_frames_decoded = 3;
258 stats.video_frames_dropped = 4;
259 stats.audio_memory_usage = 5;
260 stats.video_memory_usage = 6;
261 scoped_refptr<Rpc> from_rpc(
262 new RendererClientOnStatisticsUpdateRpc(rpc_handle, stats));
263 ASSERT_EQ(rpc_handle, from_rpc->handle());
264 int proc = from_rpc->GetProc();
265 std::string proto_buffer_string = from_rpc->ToMessage();
266
267 // Convert proto buffer string back to RPC data structure.
268 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
269 DCHECK(to_rpc);
270 ASSERT_EQ(proc, to_rpc->GetProc());
271 ASSERT_EQ(rpc_handle, to_rpc->handle());
272
273 RendererClientOnStatisticsUpdateRpc* actual_to_rpc =
274 static_cast<RendererClientOnStatisticsUpdateRpc*>(to_rpc.get());
275 ::media::PipelineStatistics to_stats = actual_to_rpc->stats();
276 ASSERT_EQ(stats.audio_bytes_decoded, to_stats.audio_bytes_decoded);
277 ASSERT_EQ(stats.video_bytes_decoded, to_stats.video_bytes_decoded);
278 ASSERT_EQ(stats.video_frames_decoded, to_stats.video_frames_decoded);
279 ASSERT_EQ(stats.video_frames_dropped, to_stats.video_frames_dropped);
280 ASSERT_EQ(stats.audio_memory_usage, to_stats.audio_memory_usage);
281 ASSERT_EQ(stats.video_memory_usage, to_stats.video_memory_usage);
282 }
283
284 TEST_F(RemotingRpcTest, DemuxerStreamReadUntilRpc) {
285 // Convert RPC data structure into proto buffer string
286 int rpc_handle = 3;
287 uint32_t frame_id = 2;
288 int callback_handle = 1;
289 scoped_refptr<Rpc> from_rpc(
290 new DemuxerStreamReadUntilRpc(rpc_handle, frame_id, callback_handle));
291 ASSERT_EQ(rpc_handle, from_rpc->handle());
292 int proc = from_rpc->GetProc();
293 std::string proto_buffer_string = from_rpc->ToMessage();
294
295 // Convert proto buffer string back to RPC data structure.
296 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
297 DCHECK(to_rpc);
298 ASSERT_EQ(proc, to_rpc->GetProc());
299 ASSERT_EQ(rpc_handle, to_rpc->handle());
300
301 DemuxerStreamReadUntilRpc* actual_to_rpc =
302 static_cast<DemuxerStreamReadUntilRpc*>(to_rpc.get());
303 ASSERT_EQ(frame_id, actual_to_rpc->frame_id());
304 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle());
305 }
306
307 TEST_F(RemotingRpcTest, DemuxerStreamInitializeCallbackRpc) {
308 // Convert RPC data structure into proto buffer string
309 int rpc_handle = 3;
310 ::media::DemuxerStream::Type type = ::media::DemuxerStream::VIDEO;
311 ::media::AudioDecoderConfig audio_config;
312 ::media::VideoDecoderConfig video_config;
313 scoped_refptr<Rpc> from_rpc(new DemuxerStreamInitializeCallbackRpc(
314 rpc_handle, type, audio_config, video_config));
315 ASSERT_EQ(rpc_handle, from_rpc->handle());
316 int proc = from_rpc->GetProc();
317 std::string proto_buffer_string = from_rpc->ToMessage();
318
319 // Convert proto buffer string back to RPC data structure.
320 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
321 DCHECK(to_rpc);
322 ASSERT_EQ(proc, to_rpc->GetProc());
323 ASSERT_EQ(rpc_handle, to_rpc->handle());
324
325 DemuxerStreamInitializeCallbackRpc* actual_to_rpc =
326 static_cast<DemuxerStreamInitializeCallbackRpc*>(to_rpc.get());
327 ASSERT_EQ(type, actual_to_rpc->type());
328 // TODO(erickung) compare |audio_config| and |video_config|;
329 }
330
331 TEST_F(RemotingRpcTest, DemuxerStreamReadUntilCallbackRpc) {
332 // Convert RPC data structure into proto buffer string
333 int rpc_handle = 3;
334 uint32_t frame_id = 100;
335 ::media::DemuxerStream::Status status = ::media::DemuxerStream::kOk;
336 ::media::AudioDecoderConfig audio_config;
337 ::media::VideoDecoderConfig video_config;
338 scoped_refptr<Rpc> from_rpc(new DemuxerStreamReadUntilCallbackRpc(
339 rpc_handle, frame_id, status, audio_config, video_config));
340 ASSERT_EQ(rpc_handle, from_rpc->handle());
341 int proc = from_rpc->GetProc();
342 std::string proto_buffer_string = from_rpc->ToMessage();
343
344 // Convert proto buffer string back to RPC data structure.
345 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
346 DCHECK(to_rpc);
347 ASSERT_EQ(proc, to_rpc->GetProc());
348 ASSERT_EQ(rpc_handle, to_rpc->handle());
349
350 DemuxerStreamReadUntilCallbackRpc* actual_to_rpc =
351 static_cast<DemuxerStreamReadUntilCallbackRpc*>(to_rpc.get());
352 ASSERT_EQ(frame_id, actual_to_rpc->frame_id());
353 ASSERT_EQ(status, actual_to_rpc->status());
354 // TODO(erickung) compare |audio_config| and |video_config|;
355 }
356
357 TEST_F(RemotingRpcTest, CdmInitializeRpc) {
358 // Convert RPC data structure into proto buffer string
359 int rpc_handle = 3;
360 std::string key_system;
361 std::string security_origin;
362 ::media::CdmConfig cdm_config;
363 cdm_config.allow_distinctive_identifier = true;
364 cdm_config.allow_persistent_state = false;
365 cdm_config.use_hw_secure_codecs = true;
366 int callback_handle = 4;
367 scoped_refptr<Rpc> from_rpc(new CdmInitializeRpc(
368 rpc_handle, key_system, security_origin, cdm_config, 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 CdmInitializeRpc* actual_to_rpc =
380 static_cast<CdmInitializeRpc*>(to_rpc.get());
381 ASSERT_EQ(key_system, actual_to_rpc->key_system());
382 ASSERT_EQ(security_origin, actual_to_rpc->security_origin());
383 ::media::CdmConfig cdm_config_out = actual_to_rpc->cdm_config();
384 ASSERT_EQ(cdm_config.allow_distinctive_identifier,
385 cdm_config_out.allow_distinctive_identifier);
386 ASSERT_EQ(cdm_config.allow_persistent_state,
387 cdm_config_out.allow_persistent_state);
388 ASSERT_EQ(cdm_config.use_hw_secure_codecs,
389 cdm_config_out.use_hw_secure_codecs);
390 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle());
391 }
392
393 TEST_F(RemotingRpcTest, CdmSetServerCertificateRpc) {
394 // Convert RPC data structure into proto buffer string
395 int rpc_handle = 3;
396 std::string data_blob("HereIsTestBlob");
397 std::vector<uint8_t> certificate_data(data_blob.begin(), data_blob.end());
398 int callback_handle = 4;
399 scoped_refptr<Rpc> from_rpc(
400 new CdmSetServerCertificateRpc(rpc_handle, &certificate_data[0],
401 certificate_data.size(), callback_handle));
402 ASSERT_EQ(rpc_handle, from_rpc->handle());
403 int proc = from_rpc->GetProc();
404 std::string proto_buffer_string = from_rpc->ToMessage();
405
406 // Convert proto buffer string back to RPC data structure.
407 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
408 DCHECK(to_rpc);
409 ASSERT_EQ(proc, to_rpc->GetProc());
410 ASSERT_EQ(rpc_handle, to_rpc->handle());
411
412 CdmSetServerCertificateRpc* actual_to_rpc =
413 static_cast<CdmSetServerCertificateRpc*>(to_rpc.get());
414 ASSERT_EQ(certificate_data.size(), actual_to_rpc->certificate_data_size());
415 std::string data_out_blob(actual_to_rpc->certificate_data(),
416 actual_to_rpc->certificate_data() +
417 actual_to_rpc->certificate_data_size());
418 ASSERT_EQ(data_blob, data_out_blob);
419 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle());
420 }
421
422 TEST_F(RemotingRpcTest, CdmCreateSessionAndGenerateRequestRpc) {
423 // Convert RPC data structure into proto buffer string
424 int rpc_handle = 3;
425 ::media::MediaKeys::SessionType session_type =
426 ::media::MediaKeys::TEMPORARY_SESSION;
427 ::media::EmeInitDataType init_data_type = ::media::EmeInitDataType::CENC;
428 std::string data_blob("Arbitrary##Data@@@");
429 std::vector<uint8_t> init_data(data_blob.begin(), data_blob.end());
430 int callback_handle = 4;
431 scoped_refptr<Rpc> from_rpc(new CdmCreateSessionAndGenerateRequestRpc(
432 rpc_handle, session_type, init_data_type, &init_data[0], init_data.size(),
433 callback_handle));
434 ASSERT_EQ(rpc_handle, from_rpc->handle());
435 int proc = from_rpc->GetProc();
436 std::string proto_buffer_string = from_rpc->ToMessage();
437
438 // Convert proto buffer string back to RPC data structure.
439 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
440 DCHECK(to_rpc);
441 ASSERT_EQ(proc, to_rpc->GetProc());
442 ASSERT_EQ(rpc_handle, to_rpc->handle());
443
444 CdmCreateSessionAndGenerateRequestRpc* actual_to_rpc =
445 static_cast<CdmCreateSessionAndGenerateRequestRpc*>(to_rpc.get());
446 ASSERT_EQ(session_type, actual_to_rpc->session_type());
447 ASSERT_EQ(init_data_type, actual_to_rpc->init_data_type());
448 ASSERT_EQ(init_data.size(), actual_to_rpc->init_data_size());
449 std::string data_out_blob(
450 actual_to_rpc->init_data(),
451 actual_to_rpc->init_data() + actual_to_rpc->init_data_size());
452 ASSERT_EQ(data_blob, data_out_blob);
453 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle());
454 }
455
456 TEST_F(RemotingRpcTest, CdmUpdateSessionRpc) {
457 // Convert RPC data structure into proto buffer string
458 int rpc_handle = 3;
459 std::string session_id;
460 std::string data_blob("___!!AS#HGSTU");
461 std::vector<uint8_t> response(data_blob.begin(), data_blob.end());
462 int callback_handle = 4;
463 scoped_refptr<Rpc> from_rpc(new CdmUpdateSessionRpc(
464 rpc_handle, session_id, &response[0], response.size(), callback_handle));
465 ASSERT_EQ(rpc_handle, from_rpc->handle());
466 int proc = from_rpc->GetProc();
467 std::string proto_buffer_string = from_rpc->ToMessage();
468
469 // Convert proto buffer string back to RPC data structure.
470 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
471 DCHECK(to_rpc);
472 ASSERT_EQ(proc, to_rpc->GetProc());
473 ASSERT_EQ(rpc_handle, to_rpc->handle());
474
475 CdmUpdateSessionRpc* actual_to_rpc =
476 static_cast<CdmUpdateSessionRpc*>(to_rpc.get());
477 ASSERT_EQ(session_id, actual_to_rpc->session_id());
478 ASSERT_EQ(response.size(), actual_to_rpc->response_size());
479 std::string data_out_blob(
480 actual_to_rpc->response(),
481 actual_to_rpc->response() + actual_to_rpc->response_size());
482 ASSERT_EQ(data_blob, data_out_blob);
483 ASSERT_EQ(callback_handle, actual_to_rpc->callback_handle());
484 }
485
486 TEST_F(RemotingRpcTest, CdmSetServerCertificateCallbackRpc) {
487 // Convert RPC data structure into proto buffer string
488 int rpc_handle = 3;
489 bool success = false;
490 CdmPromiseResult result(::media::MediaKeys::UNKNOWN_ERROR, 3, "");
491 scoped_refptr<Rpc> from_rpc(
492 new CdmSetServerCertificateCallbackRpc(rpc_handle, result));
493 ASSERT_EQ(rpc_handle, from_rpc->handle());
494 int proc = from_rpc->GetProc();
495 std::string proto_buffer_string = from_rpc->ToMessage();
496
497 // Convert proto buffer string back to RPC data structure.
498 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
499 DCHECK(to_rpc);
500 ASSERT_EQ(proc, to_rpc->GetProc());
501 ASSERT_EQ(rpc_handle, to_rpc->handle());
502
503 CdmSetServerCertificateCallbackRpc* actual_to_rpc =
504 static_cast<CdmSetServerCertificateCallbackRpc*>(to_rpc.get());
505 const CdmPromiseResult result_out = actual_to_rpc->result();
506 ASSERT_EQ(success, result_out.success());
507 ASSERT_EQ(result.exception(), result_out.exception());
508 ASSERT_EQ(result.system_code(), result_out.system_code());
509 ASSERT_EQ(result.error_message(), result_out.error_message());
510 }
511
512 TEST_F(RemotingRpcTest, CdmCreateSessionAndGenerateRequestCallbackRpc) {
513 // Convert RPC data structure into proto buffer string
514 int rpc_handle = 3;
515 bool success = true;
516 std::string session_id;
517 CdmPromiseResult result(CdmPromiseResult::SuccessResult());
518 scoped_refptr<Rpc> from_rpc(new CdmCreateSessionAndGenerateRequestCallbackRpc(
519 rpc_handle, result, session_id));
520 ASSERT_EQ(rpc_handle, from_rpc->handle());
521 int proc = from_rpc->GetProc();
522 std::string proto_buffer_string = from_rpc->ToMessage();
523
524 // Convert proto buffer string back to RPC data structure.
525 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
526 DCHECK(to_rpc);
527 ASSERT_EQ(proc, to_rpc->GetProc());
528 ASSERT_EQ(rpc_handle, to_rpc->handle());
529
530 CdmCreateSessionAndGenerateRequestCallbackRpc* actual_to_rpc =
531 static_cast<CdmCreateSessionAndGenerateRequestCallbackRpc*>(to_rpc.get());
532 const CdmPromiseResult result_out = actual_to_rpc->result();
533 ASSERT_EQ(success, result_out.success());
534 ASSERT_EQ(session_id, actual_to_rpc->session_id());
535 }
536
537 TEST_F(RemotingRpcTest, CdmInitializeCallbackRpc) {
538 // Convert RPC data structure into proto buffer string
539 int rpc_handle = 3;
540 bool success = true;
541 CdmPromiseResult result(CdmPromiseResult::SuccessResult());
542 int cdm_id = 4;
543 int decryptor_handle = 5;
544 scoped_refptr<Rpc> from_rpc(new CdmInitializeCallbackRpc(
545 rpc_handle, result, cdm_id, decryptor_handle));
546 ASSERT_EQ(rpc_handle, from_rpc->handle());
547 int proc = from_rpc->GetProc();
548 std::string proto_buffer_string = from_rpc->ToMessage();
549
550 // Convert proto buffer string back to RPC data structure.
551 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
552 DCHECK(to_rpc);
553 ASSERT_EQ(proc, to_rpc->GetProc());
554 ASSERT_EQ(rpc_handle, to_rpc->handle());
555
556 CdmInitializeCallbackRpc* actual_to_rpc =
557 static_cast<CdmInitializeCallbackRpc*>(to_rpc.get());
558 const CdmPromiseResult result_out = actual_to_rpc->result();
559 ASSERT_EQ(success, result_out.success());
560 ASSERT_EQ(cdm_id, actual_to_rpc->cdm_id());
561 ASSERT_EQ(decryptor_handle, actual_to_rpc->decryptor_handle());
562 }
563
564 TEST_F(RemotingRpcTest, CdmClientOnSessionMessageRpc) {
565 // Convert RPC data structure into proto buffer string
566 int rpc_handle = 3;
567 std::string session_id;
568 ::media::MediaKeys::MessageType message_type =
569 ::media::MediaKeys::LICENSE_RELEASE;
570 uint8_t message[1] = {0xAB};
571 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionMessageRpc(
572 rpc_handle, session_id, message_type, message, sizeof(message)));
573 ASSERT_EQ(rpc_handle, from_rpc->handle());
574 int proc = from_rpc->GetProc();
575 std::string proto_buffer_string = from_rpc->ToMessage();
576
577 // Convert proto buffer string back to RPC data structure.
578 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
579 DCHECK(to_rpc);
580 ASSERT_EQ(proc, to_rpc->GetProc());
581 ASSERT_EQ(rpc_handle, to_rpc->handle());
582
583 CdmClientOnSessionMessageRpc* actual_to_rpc =
584 static_cast<CdmClientOnSessionMessageRpc*>(to_rpc.get());
585 ASSERT_EQ(session_id, actual_to_rpc->session_id());
586 ASSERT_EQ(message_type, actual_to_rpc->message_type());
587 ASSERT_EQ(message[0], actual_to_rpc->message()[0]);
588 ASSERT_EQ(size_t(1), actual_to_rpc->message_size());
589 }
590
591 TEST_F(RemotingRpcTest, CdmClientOnSessionKeysChangeRpc) {
592 // Convert RPC data structure into proto buffer string
593 int rpc_handle = 3;
594 std::string session_id;
595 bool has_additional_usable_key = false;
596 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionKeysChangeRpc(
597 rpc_handle, session_id, has_additional_usable_key, nullptr, 0));
598 ASSERT_EQ(rpc_handle, from_rpc->handle());
599 int proc = from_rpc->GetProc();
600 std::string proto_buffer_string = from_rpc->ToMessage();
601
602 // Convert proto buffer string back to RPC data structure.
603 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
604 DCHECK(to_rpc);
605 ASSERT_EQ(proc, to_rpc->GetProc());
606 ASSERT_EQ(rpc_handle, to_rpc->handle());
607
608 CdmClientOnSessionKeysChangeRpc* actual_to_rpc =
609 static_cast<CdmClientOnSessionKeysChangeRpc*>(to_rpc.get());
610 ASSERT_EQ(session_id, actual_to_rpc->session_id());
611 ASSERT_EQ(has_additional_usable_key,
612 actual_to_rpc->has_additional_usable_key());
613 ASSERT_EQ(nullptr, actual_to_rpc->key_information());
614 ASSERT_EQ(static_cast<size_t>(0), actual_to_rpc->key_information_size());
615 }
616
617 TEST_F(RemotingRpcTest, CdmClientOnSessionExpirationUpdateRpc) {
618 // Convert RPC data structure into proto buffer string
619 int rpc_handle = 3;
620 std::string session_id;
621 double new_expiry_time_sec = 3600.2;
622 scoped_refptr<Rpc> from_rpc(new CdmClientOnSessionExpirationUpdateRpc(
623 rpc_handle, session_id, new_expiry_time_sec));
624 ASSERT_EQ(rpc_handle, from_rpc->handle());
625 int proc = from_rpc->GetProc();
626 std::string proto_buffer_string = from_rpc->ToMessage();
627
628 // Convert proto buffer string back to RPC data structure.
629 scoped_refptr<remoting::Rpc> to_rpc = Rpc::FromMessage(proto_buffer_string);
630 DCHECK(to_rpc);
631 ASSERT_EQ(proc, to_rpc->GetProc());
632 ASSERT_EQ(rpc_handle, to_rpc->handle());
633
634 CdmClientOnSessionExpirationUpdateRpc* actual_to_rpc =
635 static_cast<CdmClientOnSessionExpirationUpdateRpc*>(to_rpc.get());
636 ASSERT_EQ(session_id, actual_to_rpc->session_id());
637 ASSERT_EQ(new_expiry_time_sec, actual_to_rpc->new_expiry_time_sec());
638 }
639
640 } // namespace remoting
641 } // namespace media
OLDNEW
« media/remoting/rpc/rpc.cc ('K') | « media/remoting/rpc/rpc.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698