Chromium Code Reviews| Index: ppapi/proxy/video_decoder_resource_unittest.cc |
| diff --git a/ppapi/proxy/video_decoder_resource_unittest.cc b/ppapi/proxy/video_decoder_resource_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..334c6f41fb79cc6d1a45aaf3d6b3c02abc1a9408 |
| --- /dev/null |
| +++ b/ppapi/proxy/video_decoder_resource_unittest.cc |
| @@ -0,0 +1,597 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <GLES2/gl2.h> |
| + |
| +#include "base/memory/shared_memory.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "ppapi/c/pp_errors.h" |
| +#include "ppapi/c/ppb_video_decoder.h" |
| +#include "ppapi/proxy/locking_resource_releaser.h" |
| +#include "ppapi/proxy/plugin_message_filter.h" |
| +#include "ppapi/proxy/ppapi_message_utils.h" |
| +#include "ppapi/proxy/ppapi_messages.h" |
| +#include "ppapi/proxy/ppapi_proxy_test.h" |
| +#include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| +#include "ppapi/proxy/video_decoder_resource.h" |
| +#include "ppapi/shared_impl/proxy_lock.h" |
| +#include "ppapi/thunk/thunk.h" |
| + |
| +using ppapi::proxy::ResourceMessageTestSink; |
| + |
| +namespace ppapi { |
| +namespace proxy { |
| + |
| +namespace { |
| + |
| +const PP_Bool kAllowSoftwareFallback = PP_TRUE; |
| +const PP_Resource kGraphics3D = 7; |
| +const uint32_t kDecodeBufferSize = 16; |
| +const uint32_t kDecodeId = 5; |
| +const uint32_t kTextureId1 = 1; |
| +const uint32_t kTextureId2 = 2; |
| +const uint32_t kNumRequestedTextures = 2; |
| + |
| +class MockCompletionCallback { |
| + public: |
| + MockCompletionCallback() : called_(false) {} |
| + |
| + bool called() { return called_; } |
| + int32_t result() { return result_; } |
| + |
| + void Reset() { called_ = false; } |
| + |
| + static void Callback(void* user_data, int32_t result) { |
| + MockCompletionCallback* that = |
| + reinterpret_cast<MockCompletionCallback*>(user_data); |
| + that->called_ = true; |
| + that->result_ = result; |
| + } |
| + |
| + private: |
| + bool called_; |
| + int32_t result_; |
| +}; |
| + |
| +class VideoDecoderResourceTest : public PluginProxyTest { |
| + public: |
| + const PPB_VideoDecoder_0_1* decoder_iface; |
| + const PPB_Graphics3D_1_0* graphics3d_iface; |
| + |
| + VideoDecoderResourceTest() |
| + : decoder_iface(thunk::GetPPB_VideoDecoder_0_1_Thunk()), |
| + graphics3d_iface(thunk::GetPPB_Graphics3D_1_0_Thunk()) {} |
| + |
| + void SendReply(const ResourceMessageCallParams& params, |
| + int32_t result, |
| + const IPC::Message& nested_message) { |
| + ResourceMessageReplyParams reply_params(params.pp_resource(), |
| + params.sequence()); |
| + reply_params.set_result(result); |
| + PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
| + nested_message); |
| + } |
| + |
| + void SendReplyWithHandle(const ResourceMessageCallParams& params, |
| + int32_t result, |
| + const IPC::Message& nested_message, |
| + const SerializedHandle& handle) { |
| + ResourceMessageReplyParams reply_params(params.pp_resource(), |
| + params.sequence()); |
| + reply_params.set_result(result); |
| + reply_params.AppendHandle(handle); |
| + PluginMessageFilter::DispatchResourceReplyForTest(reply_params, |
| + nested_message); |
| + } |
| + |
| + PP_Resource CreateDecoder() { |
| + PP_Resource result = decoder_iface->Create(pp_instance()); |
| + if (result) { |
| + ProxyAutoLock lock; |
| + ppapi::Resource* resource = |
| + GetGlobals()->GetResourceTracker()->GetResource(result); |
| + proxy::VideoDecoderResource* decoder = |
| + static_cast<proxy::VideoDecoderResource*>(resource); |
| + decoder->SetForTest(); |
| + } |
| + |
| + return result; |
| + } |
| + |
| + PP_Resource CreateGraphics3d() { |
| + ProxyAutoLock lock; |
| + |
| + HostResource host_resource; |
| + host_resource.SetHostResource(pp_instance(), kGraphics3D); |
| + scoped_refptr<ppapi::proxy::Graphics3D> graphics_3d( |
| + new ppapi::proxy::Graphics3D(host_resource)); |
| + return graphics_3d->GetReference(); |
| + } |
| + |
| + PP_Resource CreateAndInitializeDecoder() { |
| + PP_Resource decoder = CreateDecoder(); |
| + LockingResourceReleaser graphics3d(CreateGraphics3d()); |
| + MockCompletionCallback cb; |
| + int32_t result = |
| + decoder_iface->Initialize(decoder, |
| + graphics3d.get(), |
| + PP_VIDEOPROFILE_H264MAIN, |
| + PP_TRUE /* allow_software_fallback */, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, &cb)); |
| + if (result != PP_OK_COMPLETIONPENDING) |
| + return 0; |
| + ResourceMessageCallParams params; |
| + IPC::Message msg; |
| + if (!sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)) |
| + return 0; |
| + sink().ClearMessages(); |
| + SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply()); |
| + return decoder; |
| + } |
| + |
| + SerializedHandle CreateSharedMemory(uint32_t size) { |
| + base::SharedMemory shm; |
| + shm.CreateAnonymous(size); |
| + base::SharedMemoryHandle shm_handle; |
| + shm.ShareToProcess(base::GetCurrentProcessHandle(), &shm_handle); |
| + return SerializedHandle(shm_handle, size); |
| + } |
| + |
| + int32_t CallDecode(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| + char decode_buffer[kDecodeBufferSize]; |
| + memset(decode_buffer, 0x55, kDecodeBufferSize); |
| + int32_t result = |
| + decoder_iface->Decode(pp_decoder, |
| + kDecodeId, |
| + kDecodeBufferSize, |
| + decode_buffer, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, cb)); |
|
piman
2014/05/15 04:02:53
This is an illegal call.
decode_buffer is on the s
bbudge
2014/05/15 16:31:57
Agreed, this is illegal and only works because we
dmichael (off chromium)
2014/05/15 21:18:22
It is a bit confusing, though... it's not an out-
bbudge
2014/05/15 22:27:44
I'd like to keep the API simple. I think FileIO Re
|
| + return result; |
| + } |
| + |
| + int32_t CallGetPicture(PP_Resource pp_decoder, |
| + PP_VideoPicture* picture, |
| + MockCompletionCallback* cb) { |
| + int32_t result = |
| + decoder_iface->GetPicture(pp_decoder, |
| + picture, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, cb)); |
| + return result; |
| + } |
| + |
| + void CallRecyclePicture(PP_Resource pp_decoder, |
| + const PP_VideoPicture& picture) { |
| + decoder_iface->RecyclePicture(pp_decoder, &picture); |
| + } |
| + |
| + int32_t CallFlush(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| + int32_t result = |
| + decoder_iface->Flush(pp_decoder, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, cb)); |
| + return result; |
| + } |
| + |
| + int32_t CallReset(PP_Resource pp_decoder, MockCompletionCallback* cb) { |
| + int32_t result = |
| + decoder_iface->Reset(pp_decoder, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, cb)); |
| + return result; |
| + } |
| + |
| + void SendGetShmReply(const ResourceMessageCallParams& params, uint32_t size) { |
| + SendReplyWithHandle(params, |
| + PP_OK, |
| + PpapiPluginMsg_VideoDecoder_GetShmReply(size), |
| + CreateSharedMemory(size)); |
| + } |
| + |
| + void SendDecodeReply(const ResourceMessageCallParams& params, |
| + uint32_t shm_id) { |
| + SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_DecodeReply(shm_id)); |
| + } |
| + |
| + void SendPictureReady(const ResourceMessageCallParams& params, |
| + uint32_t shm_id, |
| + uint32_t texture_id) { |
| + SendReply(params, |
| + PP_OK, |
| + PpapiPluginMsg_VideoDecoder_PictureReady(shm_id, texture_id)); |
| + } |
| + |
| + void SendFlushReply(const ResourceMessageCallParams& params) { |
| + SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_FlushReply()); |
| + } |
| + |
| + void SendResetReply(const ResourceMessageCallParams& params) { |
| + SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_ResetReply()); |
| + } |
| + |
| + void SendRequestTextures(const ResourceMessageCallParams& params) { |
| + SendReply(params, |
| + PP_OK, |
| + PpapiPluginMsg_VideoDecoder_RequestTextures( |
| + kNumRequestedTextures, PP_MakeSize(320, 240), GL_TEXTURE_2D)); |
| + } |
| + |
| + void SendNotifyError(const ResourceMessageCallParams& params, int32_t error) { |
| + SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_NotifyError(error)); |
| + } |
| + |
| + bool CheckGetShmMsg(ResourceMessageCallParams* params, uint32_t* size) { |
| + IPC::Message msg; |
| + if (!sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_VideoDecoder_GetShm::ID, params, &msg)) |
| + return false; |
| + sink().ClearMessages(); |
| + return UnpackMessage<PpapiHostMsg_VideoDecoder_GetShm>(msg, size); |
| + } |
| + |
| + bool CheckDecodeMsg(ResourceMessageCallParams* params, |
| + uint32_t* shm_id, |
| + uint32_t* decode_id, |
| + uint32_t* size) { |
| + IPC::Message msg; |
| + if (!sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_VideoDecoder_Decode::ID, params, &msg)) |
| + return false; |
| + sink().ClearMessages(); |
| + return UnpackMessage<PpapiHostMsg_VideoDecoder_Decode>( |
| + msg, shm_id, decode_id, size); |
| + } |
| + |
| + bool CheckRecyclePictureMsg(ResourceMessageCallParams* params, |
| + uint32_t* texture_id) { |
| + IPC::Message msg; |
| + if (!sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_VideoDecoder_RecyclePicture::ID, params, &msg)) |
| + return false; |
| + sink().ClearMessages(); |
| + return UnpackMessage<PpapiHostMsg_VideoDecoder_RecyclePicture>(msg, |
| + texture_id); |
| + } |
| + |
| + bool CheckFlushMsg(ResourceMessageCallParams* params) { |
| + return CheckMsg(params, PpapiHostMsg_VideoDecoder_Flush::ID); |
| + } |
| + |
| + bool CheckResetMsg(ResourceMessageCallParams* params) { |
| + return CheckMsg(params, PpapiHostMsg_VideoDecoder_Reset::ID); |
| + } |
| + |
| + void ClearCallbacks(PP_Resource pp_decoder) { |
| + ResourceMessageCallParams params; |
| + MockCompletionCallback cb; |
| + |
| + // Reset to abort Decode and GetPicture callbacks. |
| + CallReset(pp_decoder, &cb); |
| + // Initialize params so we can reply to the Reset. |
| + CheckResetMsg(¶ms); |
| + // Run the Reset callback. |
| + SendResetReply(params); |
| + } |
| + |
| + private: |
| + bool CheckMsg(ResourceMessageCallParams* params, int id) { |
| + IPC::Message msg; |
| + if (!sink().GetFirstResourceCallMatching(id, params, &msg)) |
| + return false; |
| + sink().ClearMessages(); |
| + return true; |
| + } |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST_F(VideoDecoderResourceTest, Initialize) { |
| + // Initialize with 0 graphics3d_context should fail. |
| + { |
| + LockingResourceReleaser decoder(CreateDecoder()); |
| + MockCompletionCallback cb; |
| + int32_t result = |
| + decoder_iface->Initialize(decoder.get(), |
| + 0 /* invalid 3d graphics */, |
| + PP_VIDEOPROFILE_H264MAIN, |
| + kAllowSoftwareFallback, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, &cb)); |
| + ASSERT_EQ(PP_ERROR_BADRESOURCE, result); |
| + } |
| + // Initialize with bad profile value should fail. |
| + { |
| + LockingResourceReleaser decoder(CreateDecoder()); |
| + MockCompletionCallback cb; |
| + int32_t result = |
| + decoder_iface->Initialize(decoder.get(), |
| + 1 /* non-zero resource */, |
| + static_cast<PP_VideoProfile>(-1), |
| + kAllowSoftwareFallback, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, &cb)); |
| + ASSERT_EQ(PP_ERROR_BADARGUMENT, result); |
| + } |
| + // Initialize with valid graphics3d_context and profile should succeed. |
| + { |
| + LockingResourceReleaser decoder(CreateDecoder()); |
| + LockingResourceReleaser graphics3d(CreateGraphics3d()); |
| + MockCompletionCallback cb; |
| + int32_t result = |
| + decoder_iface->Initialize(decoder.get(), |
| + graphics3d.get(), |
| + PP_VIDEOPROFILE_H264MAIN, |
| + kAllowSoftwareFallback, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, &cb)); |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| + ASSERT_TRUE(decoder_iface->IsVideoDecoder(decoder.get())); |
| + |
| + // Another attempt while pending should fail. |
| + result = |
| + decoder_iface->Initialize(decoder.get(), |
| + graphics3d.get(), |
| + PP_VIDEOPROFILE_H264MAIN, |
| + kAllowSoftwareFallback, |
| + PP_MakeOptionalCompletionCallback( |
| + &MockCompletionCallback::Callback, &cb)); |
| + ASSERT_EQ(PP_ERROR_INPROGRESS, result); |
| + |
| + // Check for host message and send a reply to complete initialization. |
| + ResourceMessageCallParams params; |
| + IPC::Message msg; |
| + ASSERT_TRUE(sink().GetFirstResourceCallMatching( |
| + PpapiHostMsg_VideoDecoder_Initialize::ID, ¶ms, &msg)); |
| + sink().ClearMessages(); |
| + SendReply(params, PP_OK, PpapiPluginMsg_VideoDecoder_InitializeReply()); |
| + ASSERT_TRUE(cb.called()); |
| + ASSERT_EQ(PP_OK, cb.result()); |
| + } |
| +} |
| + |
| +TEST_F(VideoDecoderResourceTest, Uninitialized) { |
| + // Operations on uninitialized decoders should fail. |
| + LockingResourceReleaser decoder(CreateDecoder()); |
| + MockCompletionCallback uncalled_cb; |
| + |
| + ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| +} |
| + |
| +TEST_F(VideoDecoderResourceTest, DecodeAndGetPicture) { |
| + LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| + ResourceMessageCallParams params, params2; // TODO rename? |
| + MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| + ASSERT_FALSE(decode_cb.called()); |
| + |
| + // Calling Decode when another Decode is pending should fail. |
| + ASSERT_EQ(PP_ERROR_INPROGRESS, CallDecode(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + // Check for host message to create shm and send a reply with handle. |
| + uint32_t shm_buffer_size; |
| + ASSERT_TRUE(CheckGetShmMsg(¶ms, &shm_buffer_size)); |
| + ASSERT_GE(shm_buffer_size, kDecodeBufferSize); |
| + SendGetShmReply(params, shm_buffer_size); |
| + // The decoder should copy the user data and send a Decode message. |
| + uint32_t shm_id; |
| + uint32_t decode_id; |
| + uint32_t decode_size; |
| + ASSERT_TRUE(CheckDecodeMsg(¶ms, &shm_id, &decode_id, &decode_size)); |
| + // Buffer id is 0. |
| + ASSERT_EQ(0U, shm_id); |
| + ASSERT_EQ(kDecodeId, decode_id); |
| + ASSERT_EQ(kDecodeBufferSize, decode_size); |
| + // The decoder should run the callback. |
| + ASSERT_TRUE(decode_cb.called()); |
| + ASSERT_EQ(PP_OK, decode_cb.result()); |
| + decode_cb.Reset(); |
| + |
| + // The decoder only has 1 shm buffer and it is still in use. The next Decode |
| + // call should also cause a shm buffer to be created. |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| + ASSERT_FALSE(decode_cb.called()); |
| + // Check for another host message to create shm and send a reply with handle. |
| + ASSERT_TRUE(CheckGetShmMsg(¶ms2, &shm_buffer_size)); |
| + SendGetShmReply(params2, shm_buffer_size); |
| + |
| + // The decoder should copy the user data and send the host message to Decode. |
| + ASSERT_TRUE(CheckDecodeMsg(¶ms2, &shm_id, &decode_id, &decode_size)); |
| + // Buffer id should be 1. |
| + ASSERT_EQ(1U, shm_id); |
| + ASSERT_EQ(kDecodeBufferSize, decode_size); |
| + // The decoder should run the plugin's callback. |
| + ASSERT_TRUE(decode_cb.called()); |
| + ASSERT_EQ(PP_OK, decode_cb.result()); |
| + decode_cb.Reset(); |
| + |
| + // Now send a reply for both in-flight decodes. This should free up shm |
| + // buffers 0 and 1, and set the picture ids for them. |
| + SendDecodeReply(params, 0U); |
| + SendDecodeReply(params2, 1U); |
| + |
| + // Calling Decode when a shm buffer is available should complete |
| + // synchronously. |
| + ASSERT_EQ(PP_OK, CallDecode(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + // Now try to get a picture. No picture ready message has been received yet. |
| + PP_VideoPicture picture; |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| + CallGetPicture(decoder.get(), &picture, &get_picture_cb)); |
| + ASSERT_FALSE(get_picture_cb.called()); |
| + // Calling GetPicture when another GetPicture is pending should fail. |
| + ASSERT_EQ(PP_ERROR_INPROGRESS, |
| + CallGetPicture(decoder.get(), &picture, &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + // Send 'request textures' message to initialize textures. |
| + SendRequestTextures(params); |
| + // Send a picture ready message for shm 0. The callback should complete. |
| + SendPictureReady(params, kDecodeId, kTextureId1); |
| + ASSERT_TRUE(get_picture_cb.called()); |
| + ASSERT_EQ(PP_OK, get_picture_cb.result()); |
| + ASSERT_EQ(kDecodeId, picture.decode_id); |
| + get_picture_cb.Reset(); |
| + |
| + // Send another picture ready message. Since there is no pending GetPicture |
| + // call, the picture should be queued. |
| + SendPictureReady(params, kDecodeId + 1, kTextureId2); |
| + // The next GetPicture should return synchronously. |
| + ASSERT_EQ(PP_OK, CallGetPicture(decoder.get(), &picture, &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(kDecodeId + 1, picture.decode_id); |
| +} |
| + |
| +TEST_F(VideoDecoderResourceTest, RecyclePicture) { |
| + LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| + ResourceMessageCallParams params; |
| + MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| + |
| + // Call Decode, which sends a message that we can check, which will initialize |
| + // 'params' so we can send a 'picture ready' message. |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| + ASSERT_FALSE(decode_cb.called()); |
| + uint32_t shm_buffer_size; |
| + CheckGetShmMsg(¶ms, &shm_buffer_size); |
| + // Send 'request textures' message to initialize textures. |
| + SendRequestTextures(params); |
| + // Call GetPicture and send 'picture ready' message to get a picture to |
| + // recycle. |
| + PP_VideoPicture picture; |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| + CallGetPicture(decoder.get(), &picture, &get_picture_cb)); |
| + SendPictureReady(params, 0U, kTextureId1); |
| + ASSERT_EQ(kTextureId1, picture.texture_id); |
| + |
| + CallRecyclePicture(decoder.get(), picture); |
| + uint32_t texture_id; |
| + ASSERT_TRUE(CheckRecyclePictureMsg(¶ms, &texture_id)); |
| + ASSERT_EQ(kTextureId1, texture_id); |
| + |
| + ClearCallbacks(decoder.get()); |
| +} |
| + |
| +TEST_F(VideoDecoderResourceTest, Flush) { |
| + LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| + ResourceMessageCallParams params, params2; |
| + MockCompletionCallback flush_cb, get_picture_cb, uncalled_cb; |
| + |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallFlush(decoder.get(), &flush_cb)); |
| + ASSERT_FALSE(flush_cb.called()); |
| + ASSERT_TRUE(CheckFlushMsg(¶ms)); |
| + |
| + ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + // Plugin can call GetPicture while Flush is pending. |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| + CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| + ASSERT_FALSE(get_picture_cb.called()); |
| + |
| + ASSERT_EQ(PP_ERROR_INPROGRESS, CallFlush(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + ASSERT_EQ(PP_ERROR_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + // Plugin can call RecyclePicture while Flush is pending. |
| + PP_VideoPicture picture; |
| + picture.texture_id = kTextureId1; |
| + CallRecyclePicture(decoder.get(), picture); |
| + uint32_t texture_id; |
| + ASSERT_TRUE(CheckRecyclePictureMsg(¶ms2, &texture_id)); |
| + |
| + SendFlushReply(params); |
| + // Any pending GetPicture call is aborted. |
| + ASSERT_TRUE(get_picture_cb.called()); |
| + ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result()); |
| + ASSERT_TRUE(flush_cb.called()); |
| + ASSERT_EQ(PP_OK, flush_cb.result()); |
| +} |
| + |
| +TEST_F(VideoDecoderResourceTest, Reset) { |
| + LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| + ResourceMessageCallParams params; |
| + MockCompletionCallback reset_cb, decode_cb, get_picture_cb, uncalled_cb; |
| + |
| + // Call Decode and GetPicture to have some pending requests. |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| + CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| + |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallReset(decoder.get(), &reset_cb)); |
| + ASSERT_FALSE(reset_cb.called()); |
| + ASSERT_TRUE(CheckResetMsg(¶ms)); |
| + // Pending calls should be aborted. |
| + ASSERT_TRUE(decode_cb.called()); |
| + ASSERT_EQ(PP_ERROR_ABORTED, decode_cb.result()); |
| + ASSERT_TRUE(get_picture_cb.called()); |
| + ASSERT_EQ(PP_ERROR_ABORTED, get_picture_cb.result()); |
| + |
| + // No calls can be made while Reset is pending. |
| + ASSERT_EQ(PP_ERROR_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(PP_ERROR_FAILED, CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(PP_ERROR_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(PP_ERROR_INPROGRESS, CallReset(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + |
| + SendResetReply(params); |
| + ASSERT_TRUE(reset_cb.called()); |
| + ASSERT_EQ(PP_OK, reset_cb.result()); |
| +} |
| + |
| +TEST_F(VideoDecoderResourceTest, NotifyError) { |
| + LockingResourceReleaser decoder(CreateAndInitializeDecoder()); |
| + ResourceMessageCallParams params; |
| + MockCompletionCallback decode_cb, get_picture_cb, uncalled_cb; |
| + |
| + // Call Decode and GetPicture to have some pending requests. |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, CallDecode(decoder.get(), &decode_cb)); |
| + ASSERT_FALSE(decode_cb.called()); |
| + ASSERT_EQ(PP_OK_COMPLETIONPENDING, |
| + CallGetPicture(decoder.get(), NULL, &get_picture_cb)); |
| + ASSERT_FALSE(get_picture_cb.called()); |
| + |
| + // Send the decoder resource an unsolicited notify error message. We first |
| + // need to initialize 'params' so the message is routed to the decoder. |
| + uint32_t shm_buffer_size; |
| + CheckGetShmMsg(¶ms, &shm_buffer_size); |
| + SendNotifyError(params, PP_ERROR_PLATFORM_FAILED); |
| + |
| + // Both pending messages should be run with the reported error. |
| + ASSERT_TRUE(decode_cb.called()); |
| + ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, decode_cb.result()); |
| + ASSERT_TRUE(get_picture_cb.called()); |
| + ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, get_picture_cb.result()); |
| + |
| + // All further calls return the reported error. |
| + ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, CallDecode(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, |
| + CallGetPicture(decoder.get(), NULL, &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, CallFlush(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| + ASSERT_EQ(PP_ERROR_PLATFORM_FAILED, CallReset(decoder.get(), &uncalled_cb)); |
| + ASSERT_FALSE(uncalled_cb.called()); |
| +} |
| + |
| +} // namespace proxy |
| +} // namespace ppapi |