MockDecoderModule.h (2263B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOCK_DECODER_MODULE_H_ 8 #define MOCK_DECODER_MODULE_H_ 9 10 #include "BlankDecoderModule.h" 11 #include "DummyMediaDataDecoder.h" 12 #include "PlatformDecoderModule.h" 13 #include "gmock/gmock.h" 14 15 namespace mozilla { 16 17 class MockVideoDataDecoder : public DummyMediaDataDecoder { 18 public: 19 explicit MockVideoDataDecoder(const CreateDecoderParams& aParams) 20 : DummyMediaDataDecoder( 21 MakeUnique<BlankVideoDataCreator>( 22 aParams.VideoConfig().mDisplay.width, 23 aParams.VideoConfig().mDisplay.height, aParams.mImageContainer), 24 "MockVideoDataDecoder"_ns, aParams) { 25 // A non-owning reference is captured to allow deletion of the node. 26 // The method is called only when the caller holds a reference. 27 ON_CALL(*this, Drain).WillByDefault([self = MOZ_KnownLive(this)]() { 28 return self->DummyMediaDataDecoder::Drain(); 29 }); 30 } 31 32 MOCK_METHOD(RefPtr<DecodePromise>, Drain, (), (override)); 33 34 void SetLatencyFrameCount(uint32_t aLatency) { mMaxRefFrames = aLatency; } 35 36 protected: 37 ~MockVideoDataDecoder() override = default; 38 }; 39 40 class MockDecoderModule : public PlatformDecoderModule { 41 public: 42 MockDecoderModule() { 43 ON_CALL(*this, SupportsMimeType) 44 .WillByDefault(testing::Return(media::DecodeSupport::SoftwareDecode)); 45 } 46 47 MOCK_METHOD(already_AddRefed<MediaDataDecoder>, CreateVideoDecoder, 48 (const CreateDecoderParams& aParams), (override)); 49 50 MOCK_METHOD(already_AddRefed<MediaDataDecoder>, CreateAudioDecoder, 51 (const CreateDecoderParams& aParams), (override)); 52 53 MOCK_METHOD(media::DecodeSupportSet, SupportsMimeType, 54 (const nsACString& aMimeType, 55 DecoderDoctorDiagnostics* aDiagnostics), 56 (const override)); 57 58 const char* Name() const override { return "Mock"; } 59 60 protected: 61 ~MockDecoderModule() override = default; 62 }; 63 64 } // namespace mozilla 65 66 #endif /* MOCK_DECODER_MODULE_H_ */