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

Side by Side Diff: ppapi/proxy/video_decoder_resource_unittest.cc

Issue 270213004: Implement Pepper PPB_VideoDecoder interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 <GLES2/gl2.h>
6
7 #include "base/memory/shared_memory.h"
8 #include "base/message_loop/message_loop.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_video_decoder.h"
11 #include "ppapi/proxy/locking_resource_releaser.h"
12 #include "ppapi/proxy/plugin_message_filter.h"
13 #include "ppapi/proxy/ppapi_message_utils.h"
14 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/proxy/ppapi_proxy_test.h"
16 #include "ppapi/proxy/ppb_graphics_3d_proxy.h"
17 #include "ppapi/proxy/video_decoder_resource.h"
18 #include "ppapi/shared_impl/proxy_lock.h"
19 #include "ppapi/thunk/thunk.h"
20
21 using ppapi::proxy::ResourceMessageTestSink;
22
23 namespace ppapi {
24 namespace proxy {
25
26 namespace {
27
28 const PP_Bool kAllowSoftwareFallback = PP_TRUE;
29 const PP_Resource kGraphics3D = 7;
30 const uint32_t kDecodeBufferSize = 16;
31 const uint32_t kDecodeId = 5;
32 const uint32_t kTextureId1 = 1;
33 const uint32_t kTextureId2 = 2;
34 const uint32_t kNumRequestedTextures = 2;
35
36 class MockCompletionCallback {
37 public:
38 MockCompletionCallback() : called_(false) {}
39
40 bool called() { return called_; }
41 int32_t result() { return result_; }
42
43 void Reset() { called_ = false; }
44
45 static void Callback(void* user_data, int32_t result) {
46 MockCompletionCallback* that =
47 reinterpret_cast<MockCompletionCallback*>(user_data);
48 that->called_ = true;
49 that->result_ = result;
50 }
51
52 private:
53 bool called_;
54 int32_t result_;
55 };
56
57 class VideoDecoderResourceTest : public PluginProxyTest {
58 public:
59 const PPB_VideoDecoder_0_1* decoder_iface;
60 const PPB_Graphics3D_1_0* graphics3d_iface;
61
62 VideoDecoderResourceTest()
63 : decoder_iface(thunk::GetPPB_VideoDecoder_0_1_Thunk()),
64 graphics3d_iface(thunk::GetPPB_Graphics3D_1_0_Thunk()) {}
65
66 void SendReply(const ResourceMessageCallParams& params,
67 int32_t result,
68 const IPC::Message& nested_message) {
69 ResourceMessageReplyParams reply_params(params.pp_resource(),
70 params.sequence());
71 reply_params.set_result(result);
72 PluginMessageFilter::DispatchResourceReplyForTest(reply_params,
73 nested_message);
74 }
75
76 void SendReplyWithHandle(const ResourceMessageCallParams& params,
77 int32_t result,
78 const IPC::Message& nested_message,
79 const SerializedHandle& handle) {
80 ResourceMessageReplyParams reply_params(params.pp_resource(),
81 params.sequence());
82 reply_params.set_result(result);
83 reply_params.AppendHandle(handle);
84 PluginMessageFilter::DispatchResourceReplyForTest(reply_params,
85 nested_message);
86 }
87
88 PP_Resource CreateDecoder() {
89 PP_Resource result = decoder_iface->Create(pp_instance());
90 if (result) {
91 ProxyAutoLock lock;
92 ppapi::Resource* resource =
93 GetGlobals()->GetResourceTracker()->GetResource(result);
94 proxy::VideoDecoderResource* decoder =
95 static_cast<proxy::VideoDecoderResource*>(resource);
96 decoder->SetForTest();
97 }
98
99 return result;
100 }
101
102 PP_Resource CreateGraphics3d() {
103 ProxyAutoLock lock;
104
105 HostResource host_resource;
106 host_resource.SetHostResource(pp_instance(), kGraphics3D);
107 scoped_refptr<ppapi::proxy::Graphics3D> graphics_3d(
108 new ppapi::proxy::Graphics3D(host_resource));
109 return graphics_3d->GetReference();
110 }
111
112 PP_Resource CreateAndInitializeDecoder() {
113 PP_Resource decoder = CreateDecoder();
114 LockingResourceReleaser graphics3d(CreateGraphics3d());
115 MockCompletionCallback cb;
116 int32_t result =
117 decoder_iface->Initialize(decoder,
118 graphics3d.get(),
119 PP_VIDEOPROFILE_H264MAIN,
120 PP_TRUE /* allow_software_fallback */,
121 PP_MakeOptionalCompletionCallback(
122 &MockCompletionCallback::Callback, &cb));
123 if (result != PP_OK_COMPLETIONPENDING)
124 return 0;
125 ResourceMessageCallParams params;
126 IPC::Message msg;
127 if (!sink().GetFirstResourceCallMatching(
128 PpapiHostMsg_VideoDecoder_Initialize::ID, &params, &msg))
129 return 0;
130 sink().ClearMessages();
131 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply());
132 return decoder;
133 }
134
135 SerializedHandle CreateSharedMemory(uint32_t size) {
136 base::SharedMemory shm;
137 shm.CreateAnonymous(size);
138 base::SharedMemoryHandle shm_handle;
139 shm.ShareToProcess(base::GetCurrentProcessHandle(), &shm_handle);
140 return SerializedHandle(shm_handle, size);
141 }
142
143 int32_t CallDecode(PP_Resource pp_decoder, MockCompletionCallback* cb) {
144 memset(decode_buffer, 0x55, kDecodeBufferSize);
145 int32_t result =
146 decoder_iface->Decode(pp_decoder,
147 kDecodeId,
148 kDecodeBufferSize,
149 decode_buffer,
150 PP_MakeOptionalCompletionCallback(
151 &MockCompletionCallback::Callback, cb));
152 return result;
153 }
154
155 int32_t CallGetPicture(PP_Resource pp_decoder,
156 PP_VideoPicture* picture,
157 MockCompletionCallback* cb) {
158 int32_t result =
159 decoder_iface->GetPicture(pp_decoder,
160 picture,
161 PP_MakeOptionalCompletionCallback(
162 &MockCompletionCallback::Callback, cb));
163 return result;
164 }
165
166 void CallRecyclePicture(PP_Resource pp_decoder,
167 const PP_VideoPicture& picture) {
168 decoder_iface->RecyclePicture(pp_decoder, &picture);
169 }
170
171 int32_t CallFlush(PP_Resource pp_decoder, MockCompletionCallback* cb) {
172 int32_t result =
173 decoder_iface->Flush(pp_decoder,
174 PP_MakeOptionalCompletionCallback(
175 &MockCompletionCallback::Callback, cb));
176 return result;
177 }
178
179 int32_t CallReset(PP_Resource pp_decoder, MockCompletionCallback* cb) {
180 int32_t result =
181 decoder_iface->Reset(pp_decoder,
182 PP_MakeOptionalCompletionCallback(
183 &MockCompletionCallback::Callback, cb));
184 return result;
185 }
186
187 void SendGetShmReply(const ResourceMessageCallParams& params, uint32_t size) {
188 SendReplyWithHandle(params,
189 PP_OK,
190 PpapiPluginMsg_VideoDecoder_GetShmReply(size),
191 CreateSharedMemory(size));
192 }
193
194 void SendDecodeReply(const ResourceMessageCallParams& params,
195 uint32_t shm_id) {
196 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_DecodeReply(shm_id));
197 }
198
199 void SendPictureReady(const ResourceMessageCallParams& params,
200 uint32_t decode_count,
201 uint32_t texture_id) {
202 SendReply(params,
203 PP_OK,
204 PpapiPluginMsg_VideoDecoder_PictureReady(
205 decode_count, texture_id));
206 }
207
208 void SendFlushReply(const ResourceMessageCallParams& params) {
209 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_FlushReply());
210 }
211
212 void SendResetReply(const ResourceMessageCallParams& params) {
213 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_ResetReply());
214 }
215
216 void SendRequestTextures(const ResourceMessageCallParams& params) {
217 SendReply(params,
218 PP_OK,
219 PpapiPluginMsg_VideoDecoder_RequestTextures(
220 kNumRequestedTextures, PP_MakeSize(320, 240), GL_TEXTURE_2D));
221 }
222
223 void SendNotifyError(const ResourceMessageCallParams& params, int32_t error) {
224 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_NotifyError(error));
225 }
226
227 bool CheckGetShmMsg(ResourceMessageCallParams* params,
228 uint32_t* size,
229 uint32_t* pending_shm_id) {
230 IPC::Message msg;
231 if (!sink().GetFirstResourceCallMatching(
232 PpapiHostMsg_VideoDecoder_GetShm::ID, params, &msg))
233 return false;
234 sink().ClearMessages();
235 return UnpackMessage<PpapiHostMsg_VideoDecoder_GetShm>(
236 msg, size, pending_shm_id);
237 }
238
239 bool CheckDecodeMsg(ResourceMessageCallParams* params,
240 uint32_t* shm_id,
241 uint32_t* size) {
242 IPC::Message msg;
243 if (!sink().GetFirstResourceCallMatching(
244 PpapiHostMsg_VideoDecoder_Decode::ID, params, &msg))
245 return false;
246 sink().ClearMessages();
247 return UnpackMessage<PpapiHostMsg_VideoDecoder_Decode>(msg, shm_id, size);
248 }
249
250 bool CheckRecyclePictureMsg(ResourceMessageCallParams* params,
251 uint32_t* texture_id) {
252 IPC::Message msg;
253 if (!sink().GetFirstResourceCallMatching(
254 PpapiHostMsg_VideoDecoder_RecyclePicture::ID, params, &msg))
255 return false;
256 sink().ClearMessages();
257 return UnpackMessage<PpapiHostMsg_VideoDecoder_RecyclePicture>(msg,
258 texture_id);
259 }
260
261 bool CheckFlushMsg(ResourceMessageCallParams* params) {
262 return CheckMsg(params, PpapiHostMsg_VideoDecoder_Flush::ID);
263 }
264
265 bool CheckResetMsg(ResourceMessageCallParams* params) {
266 return CheckMsg(params, PpapiHostMsg_VideoDecoder_Reset::ID);
267 }
268
269 void ClearCallbacks(PP_Resource pp_decoder) {
270 ResourceMessageCallParams params;
271 MockCompletionCallback cb;
272
273 // Reset to abort Decode and GetPicture callbacks.
274 CallReset(pp_decoder, &cb);
275 // Initialize params so we can reply to the Reset.
276 CheckResetMsg(&params);
277 // Run the Reset callback.
278 SendResetReply(params);
279 }
280
281 char decode_buffer[kDecodeBufferSize];
282
283 private:
284 bool CheckMsg(ResourceMessageCallParams* params, int id) {
285 IPC::Message msg;
286 if (!sink().GetFirstResourceCallMatching(id, params, &msg))
287 return false;
288 sink().ClearMessages();
289 return true;
290 }
291 };
292
293 } // namespace
294
295 TEST_F(VideoDecoderResourceTest, Initialize) {
296 // Initialize with 0 graphics3d_context should fail.
297 {
298 LockingResourceReleaser decoder(CreateDecoder());
299 MockCompletionCallback cb;
300 int32_t result =
301 decoder_iface->Initialize(decoder.get(),
302 0 /* invalid 3d graphics */,
303 PP_VIDEOPROFILE_H264MAIN,
304 kAllowSoftwareFallback,
305 PP_MakeOptionalCompletionCallback(
306 &MockCompletionCallback::Callback, &cb));
307 ASSERT_EQ(PP_ERROR_BADRESOURCE, result);
308 }
309 // Initialize with bad profile value should fail.
310 {
311 LockingResourceReleaser decoder(CreateDecoder());
312 MockCompletionCallback cb;
313 int32_t result =
314 decoder_iface->Initialize(decoder.get(),
315 1 /* non-zero resource */,
316 static_cast<PP_VideoProfile>(-1),
317 kAllowSoftwareFallback,
318 PP_MakeOptionalCompletionCallback(
319 &MockCompletionCallback::Callback, &cb));
320 ASSERT_EQ(PP_ERROR_BADARGUMENT, result);
321 }
322 // Initialize with valid graphics3d_context and profile should succeed.
323 {
324 LockingResourceReleaser decoder(CreateDecoder());
325 LockingResourceReleaser graphics3d(CreateGraphics3d());
326 MockCompletionCallback cb;
327 int32_t result =
328 decoder_iface->Initialize(decoder.get(),
329 graphics3d.get(),
330 PP_VIDEOPROFILE_H264MAIN,
331 kAllowSoftwareFallback,
332 PP_MakeOptionalCompletionCallback(
333 &MockCompletionCallback::Callback, &cb));
334 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
335 ASSERT_TRUE(decoder_iface->IsVideoDecoder(decoder.get()));
336
337 // Another attempt while pending should fail.
338 result =
339 decoder_iface->Initialize(decoder.get(),
340 graphics3d.get(),
341 PP_VIDEOPROFILE_H264MAIN,
342 kAllowSoftwareFallback,
343 PP_MakeOptionalCompletionCallback(
344 &MockCompletionCallback::Callback, &cb));
345 ASSERT_EQ(PP_ERROR_INPROGRESS, result);
346
347 // Check for host message and send a reply to complete initialization.
348 ResourceMessageCallParams params;
349 IPC::Message msg;
350 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
351 PpapiHostMsg_VideoDecoder_Initialize::ID, &params, &msg));
352 sink().ClearMessages();
353 SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply());
354 ASSERT_TRUE(cb.called());
355 ASSERT_EQ(PP_OK, cb.result());
356 }
357 }
358
359 TEST_F(VideoDecoderResourceTest, Uninitialized) {
360 // Operations on uninitialized decoders should fail.
361 LockingResourceReleaser decoder(CreateDecoder());
362 MockCompletionCallback uncalled_cb;
363
364 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb));
365 ASSERT_FALSE(uncalled_cb.called());
366
367 ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb));
368 ASSERT_FALSE(uncalled_cb.called());
369
370 ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb));
371 ASSERT_FALSE(uncalled_cb.called());
372
373 ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb));
374 ASSERT_FALSE(uncalled_cb.called());
375 }
376
377 TEST_F(VideoDecoderResourceTest, DecodeAndGetPicture) {
378 LockingResourceReleaser decoder(CreateAndInitializeDecoder());
379 ResourceMessageCallParams params, params2; // TODO rename?
380 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb;
381 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb));
382 ASSERT_FALSE(decode_cb.called());
383
384 // Calling Decode when another Decode is pending should fail.
385 ASSERT_EQ(PP_ERROR_INPROGRESS, CallDecode(decoder.get(), &uncalled_cb));
386 ASSERT_FALSE(uncalled_cb.called());
387
388 // Check for host message to create shm and send a reply with handle.
389 uint32_t shm_buffer_size;
390 uint32_t pending_shm_id;
391 CheckGetShmMsg(&params, &shm_buffer_size, &pending_shm_id);
392 ASSERT_GE(shm_buffer_size, kDecodeBufferSize);
393 ASSERT_EQ(0U, pending_shm_id);
394 SendGetShmReply(params, shm_buffer_size);
395 // The decoder should copy the user data and send a Decode message.
396 uint32_t shm_id;
397 uint32_t decode_size;
398 ASSERT_TRUE(CheckDecodeMsg(&params, &shm_id, &decode_size));
399 // Buffer id is 0.
400 ASSERT_EQ(0U, shm_id);
401 ASSERT_EQ(kDecodeBufferSize, decode_size);
402 // The decoder should run the callback.
403 ASSERT_TRUE(decode_cb.called());
404 ASSERT_EQ(PP_OK, decode_cb.result());
405 decode_cb.Reset();
406
407 // The decoder only has 1 shm buffer and it is still in use. The next Decode
408 // call should also cause a shm buffer to be created.
409 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb));
410 ASSERT_FALSE(decode_cb.called());
411 // Check for another host message to create shm and send a reply with handle.
412 ASSERT_TRUE(CheckGetShmMsg(&params2, &shm_buffer_size, &pending_shm_id));
413 ASSERT_EQ(1U, pending_shm_id);
414 SendGetShmReply(params2, shm_buffer_size);
415
416 // The decoder should copy the user data and send the host message to Decode.
417 ASSERT_TRUE(CheckDecodeMsg(&params2, &shm_id, &decode_size));
418 // Buffer id should be 1.
419 ASSERT_EQ(1U, shm_id);
420 ASSERT_EQ(kDecodeBufferSize, decode_size);
421 // The decoder should run the plugin's callback.
422 ASSERT_TRUE(decode_cb.called());
423 ASSERT_EQ(PP_OK, decode_cb.result());
424 decode_cb.Reset();
425
426 // Now send a reply for both in-flight decodes. This should free up shm
427 // buffers 0 and 1, and set the picture ids for them.
428 SendDecodeReply(params, 0U);
429 SendDecodeReply(params2, 1U);
430
431 // Calling Decode when a shm buffer is available should complete
432 // synchronously.
433 ASSERT_EQ(PP_OK, CallDecode(decoder.get(), &uncalled_cb));
434 ASSERT_FALSE(uncalled_cb.called());
435
436 // Now try to get a picture. No picture ready message has been received yet.
437 PP_VideoPicture picture;
438 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
439 CallGetPicture(decoder.get(), &picture, &get_picture_cb));
440 ASSERT_FALSE(get_picture_cb.called());
441 // Calling GetPicture when another GetPicture is pending should fail.
442 ASSERT_EQ(PP_ERROR_INPROGRESS,
443 CallGetPicture(decoder.get(), &picture, &uncalled_cb));
444 ASSERT_FALSE(uncalled_cb.called());
445 // Send 'request textures' message to initialize textures.
446 SendRequestTextures(params);
447 // Send a picture ready message for Decode buffer 0. The GetPicture callback
448 // should complete.
449 SendPictureReady(params, 0U, kTextureId1);
450 ASSERT_TRUE(get_picture_cb.called());
451 ASSERT_EQ(PP_OK, get_picture_cb.result());
452 ASSERT_EQ(kDecodeId, picture.decode_id);
453 get_picture_cb.Reset();
454
455 // Send a picture ready message for Decode buffer 1. Since there is no pending
456 // GetPicture call, the picture should be queued.
457 SendPictureReady(params, 1U, kTextureId2);
458 // The next GetPicture should return synchronously.
459 ASSERT_EQ(PP_OK, CallGetPicture(decoder.get(), &picture, &uncalled_cb));
460 ASSERT_FALSE(uncalled_cb.called());
461 ASSERT_EQ(kDecodeId, picture.decode_id);
462 }
463
464 TEST_F(VideoDecoderResourceTest, RecyclePicture) {
465 LockingResourceReleaser decoder(CreateAndInitializeDecoder());
466 ResourceMessageCallParams params;
467 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb;
468
469 // Get to a state where we have a picture to recycle.
470 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb));
471 ASSERT_FALSE(decode_cb.called());
472 uint32_t shm_buffer_size;
473 uint32_t pending_shm_id;
474 CheckGetShmMsg(&params, &shm_buffer_size, &pending_shm_id);
475 // Send 'request textures' message to initialize textures.
476 SendRequestTextures(params);
477 // Call GetPicture and send 'picture ready' message to get a picture to
478 // recycle.
479 PP_VideoPicture picture;
480 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
481 CallGetPicture(decoder.get(), &picture, &get_picture_cb));
482 SendPictureReady(params, 0U, kTextureId1);
483 ASSERT_EQ(kTextureId1, picture.texture_id);
484
485 CallRecyclePicture(decoder.get(), picture);
486 uint32_t texture_id;
487 ASSERT_TRUE(CheckRecyclePictureMsg(&params, &texture_id));
488 ASSERT_EQ(kTextureId1, texture_id);
489
490 ClearCallbacks(decoder.get());
491 }
492
493 TEST_F(VideoDecoderResourceTest, Flush) {
494 LockingResourceReleaser decoder(CreateAndInitializeDecoder());
495 ResourceMessageCallParams params, params2;
496 MockCompletionCallback flush_cb, get_picture_cb, uncalled_cb;
497
498 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallFlush(decoder.get(), &flush_cb));
499 ASSERT_FALSE(flush_cb.called());
500 ASSERT_TRUE(CheckFlushMsg(&params));
501
502 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb));
503 ASSERT_FALSE(uncalled_cb.called());
504
505 // Plugin can call GetPicture while Flush is pending.
506 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
507 CallGetPicture(decoder.get(), NULL, &get_picture_cb));
508 ASSERT_FALSE(get_picture_cb.called());
509
510 ASSERT_EQ(PP_ERROR_INPROGRESS, CallFlush(decoder.get(), &uncalled_cb));
511 ASSERT_FALSE(uncalled_cb.called());
512
513 ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb));
514 ASSERT_FALSE(uncalled_cb.called());
515
516 // Plugin can call RecyclePicture while Flush is pending.
517 PP_VideoPicture picture;
518 picture.texture_id = kTextureId1;
519 CallRecyclePicture(decoder.get(), picture);
520 uint32_t texture_id;
521 ASSERT_TRUE(CheckRecyclePictureMsg(&params2, &texture_id));
522
523 SendFlushReply(params);
524 // Any pending GetPicture call is aborted.
525 ASSERT_TRUE(get_picture_cb.called());
526 ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result());
527 ASSERT_TRUE(flush_cb.called());
528 ASSERT_EQ(PP_OK, flush_cb.result());
529 }
530
531 TEST_F(VideoDecoderResourceTest, Reset) {
532 LockingResourceReleaser decoder(CreateAndInitializeDecoder());
533 ResourceMessageCallParams params;
534 MockCompletionCallback reset_cb, decode_cb, get_picture_cb, uncalled_cb;
535
536 // Call Decode and GetPicture to have some pending requests.
537 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb));
538 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
539 CallGetPicture(decoder.get(), NULL, &get_picture_cb));
540
541 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallReset(decoder.get(), &reset_cb));
542 ASSERT_FALSE(reset_cb.called());
543 ASSERT_TRUE(CheckResetMsg(&params));
544 // Pending calls should be aborted.
545 ASSERT_TRUE(decode_cb.called());
546 ASSERT_EQ(PP_ERROR_ABORTED, decode_cb.result());
547 ASSERT_TRUE(get_picture_cb.called());
548 ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result());
549
550 // No calls can be made while Reset is pending.
551 ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb));
552 ASSERT_FALSE(uncalled_cb.called());
553 ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb));
554 ASSERT_FALSE(uncalled_cb.called());
555 ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb));
556 ASSERT_FALSE(uncalled_cb.called());
557 ASSERT_EQ(PP_ERROR_INPROGRESS, CallReset(decoder.get(), &uncalled_cb));
558 ASSERT_FALSE(uncalled_cb.called());
559
560 SendResetReply(params);
561 ASSERT_TRUE(reset_cb.called());
562 ASSERT_EQ(PP_OK, reset_cb.result());
563 }
564
565 TEST_F(VideoDecoderResourceTest, NotifyError) {
566 LockingResourceReleaser decoder(CreateAndInitializeDecoder());
567 ResourceMessageCallParams params;
568 MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb;
569
570 // Call Decode and GetPicture to have some pending requests.
571 ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb));
572 ASSERT_FALSE(decode_cb.called());
573 ASSERT_EQ(PP_OK_COMPLETIONPENDING,
574 CallGetPicture(decoder.get(), NULL, &get_picture_cb));
575 ASSERT_FALSE(get_picture_cb.called());
576
577 // Send the decoder resource an unsolicited notify error message. We first
578 // need to initialize 'params' so the message is routed to the decoder.
579 uint32_t shm_buffer_size;
580 uint32_t pending_shm_id;
581 CheckGetShmMsg(&params, &shm_buffer_size, &pending_shm_id);
582 SendNotifyError(params, PP_ERROR_RESOURCE_FAILED);
583
584 // Both pending messages should be run with the reported error.
585 ASSERT_TRUE(decode_cb.called());
586 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, decode_cb.result());
587 ASSERT_TRUE(get_picture_cb.called());
588 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, get_picture_cb.result());
589
590 // All further calls return the reported error.
591 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallDecode(decoder.get(), &uncalled_cb));
592 ASSERT_FALSE(uncalled_cb.called());
593 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED,
594 CallGetPicture(decoder.get(), NULL, &uncalled_cb));
595 ASSERT_FALSE(uncalled_cb.called());
596 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallFlush(decoder.get(), &uncalled_cb));
597 ASSERT_FALSE(uncalled_cb.called());
598 ASSERT_EQ(PP_ERROR_RESOURCE_FAILED, CallReset(decoder.get(), &uncalled_cb));
599 ASSERT_FALSE(uncalled_cb.called());
600 }
601
602 } // namespace proxy
603 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698