// Copyright 2022 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <sys/mman.h> #include "base/posix/eintr_wrapper.h" #include "base/test/mock_callback.h" #include "base/test/task_environment.h" #include "gpu/ipc/common/gpu_memory_buffer_support.h" #include "media/mojo/common/mojo_decoder_buffer_converter.h" #include "media/mojo/mojom/media_log.mojom.h" #include "media/mojo/mojom/video_decoder.mojom.h" #include "media/mojo/services/stable_video_decoder_factory_service.h" #include "media/mojo/services/stable_video_decoder_service.h" #include "mojo/public/cpp/bindings/associated_receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/system/data_pipe.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/gpu_memory_buffer.h" _; ByMove; Mock; Return; SaveArg; StrictMock; WithArgs; namespace media { namespace { VideoDecoderConfig CreateValidVideoDecoderConfig() { … } scoped_refptr<VideoFrame> CreateTestNV12GpuMemoryBufferVideoFrame() { … } class MockVideoFrameHandleReleaser : public mojom::VideoFrameHandleReleaser { … }; class MockVideoDecoder : public mojom::VideoDecoder { … }; class MockStableVideoDecoderTracker : public stable::mojom::StableVideoDecoderTracker { … }; class MockStableVideoDecoderClient : public stable::mojom::VideoDecoderClient { … }; class MockStableMediaLog : public stable::mojom::MediaLog { … }; // AuxiliaryEndpoints groups the endpoints that support the operation of a // StableVideoDecoderService and that come from the Construct() call. That way, // tests can easily poke at one endpoint and set expectations on the other. For // example, a test might want to simulate the scenario in which a frame has been // decoded by the underlying mojom::VideoDecoder. In this case, the test can // call |video_decoder_client_remote|->OnVideoFrameDecoded() and then set an // expectation on |mock_stable_video_decoder_client|->OnVideoFrameDecoded(). struct AuxiliaryEndpoints { … }; // Calls Construct() on |stable_video_decoder_remote| and, if // |expect_construct_call| is true, expects a corresponding Construct() call on // |mock_video_decoder| which is assumed to be the backing decoder of // |stable_video_decoder_remote|. Returns nullptr if the expectations on // |mock_video_decoder| are violated. Otherwise, returns an AuxiliaryEndpoints // instance that contains the supporting endpoints that tests can use to // interact with the auxiliary interfaces used by the // |stable_video_decoder_remote|. std::unique_ptr<AuxiliaryEndpoints> ConstructStableVideoDecoder( mojo::Remote<stable::mojom::StableVideoDecoder>& stable_video_decoder_remote, StrictMock<MockVideoDecoder>& mock_video_decoder, bool expect_construct_call) { … } class StableVideoDecoderServiceTest : public testing::Test { … }; // Tests that we can create multiple StableVideoDecoder implementation instances // through the StableVideoDecoderFactory and that they can exist concurrently. TEST_F(StableVideoDecoderServiceTest, FactoryCanCreateStableVideoDecoders) { … } // Tests that a call to stable::mojom::VideoDecoder::Construct() gets routed // correctly to the underlying mojom::VideoDecoder. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCanBeConstructed) { … } // Tests that if two calls to stable::mojom::VideoDecoder::Construct() are made, // only one is routed to the underlying mojom::VideoDecoder. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCannotBeConstructedTwice) { … } // Tests that a call to stable::mojom::VideoDecoder::GetSupportedConfigs() gets // routed correctly to the underlying mojom::VideoDecoder. Also tests that the // underlying mojom::VideoDecoder's reply gets routed correctly back to the // client. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCanGetSupportedConfigs) { … } // Tests that a call to stable::mojom::VideoDecoder::Initialize() gets routed // correctly to the underlying mojom::VideoDecoder. Also tests that when the // underlying mojom::VideoDecoder calls the initialization callback, the call // gets routed to the client. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCanBeInitialized) { … } // Tests that the StableVideoDecoderService rejects a call to // stable::mojom::VideoDecoder::Initialize() before // stable::mojom::VideoDecoder::Construct() gets called. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCannotBeInitializedBeforeConstruction) { … } // Tests that a call to stable::mojom::VideoDecoder::Decode() gets routed // correctly to the underlying mojom::VideoDecoder and that the data pipe is // plumbed correctly. Also tests that when the underlying mojom::VideoDecoder // calls the decode callback, the call gets routed to the client. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCanDecode) { … } // Tests that the StableVideoDecoderService rejects a call to // stable::mojom::VideoDecoder::Decode() before // stable::mojom::VideoDecoder::Construct() gets called. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCannotDecodeBeforeConstruction) { … } // Tests that a call to stable::mojom::VideoDecoder::Reset() gets routed // correctly to the underlying mojom::VideoDecoder. Also tests that when the // underlying mojom::VideoDecoder calls the reset callback, the call gets routed // to the client. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCanBeReset) { … } // Tests that the StableVideoDecoderService doesn't route a // stable::mojom::VideoDecoder::Reset() call to the underlying // mojom::VideoDecoder before stable::mojom::VideoDecoder::Construct() gets // called and that it just calls the reset callback. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderCannotBeResetBeforeConstruction) { … } // Tests that a call to // stable::mojom::VideoFrameHandleReleaser::ReleaseVideoFrame() gets routed // correctly to the underlying mojom::VideoFrameHandleReleaser. TEST_F(StableVideoDecoderServiceTest, VideoFramesCanBeReleased) { … } TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderClientReceivesOnVideoFrameDecodedEvent) { … } // Tests that a mojom::VideoDecoderClient::OnWaiting() call originating from the // underlying mojom::VideoDecoder gets forwarded to the // stable::mojom::VideoDecoderClient correctly. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderClientReceivesOnWaitingEvent) { … } // Tests that a mojom::MediaLog::AddLogRecord() call originating from the // underlying mojom::VideoDecoder gets forwarded to the stable::mojom::MediaLog // correctly. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderClientReceivesAddLogRecordEvent) { … } // Tests that a StableVideoDecoderTracker can be used to know when the remote // StableVideoDecoder implementation dies. TEST_F(StableVideoDecoderServiceTest, StableVideoDecoderTrackerDisconnectsWhenStableVideoDecoderDies) { … } } // namespace } // namespace media