void WithSingleChunkDecode(const ImageTestCase& aTestCase, const Maybe<IntSize>& aOutputSize, Func aResultChecker) { nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath); ASSERT_TRUE(inputStream != nullptr); // Figure out how much data we have. uint64_t length; nsresult rv = inputStream->Available(&length); ASSERT_TRUE(NS_SUCCEEDED(rv)); // Write the data into a SourceBuffer. NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer()); sourceBuffer->ExpectLength(length); rv = sourceBuffer->AppendFromInputStream(inputStream, length); ASSERT_TRUE(NS_SUCCEEDED(rv)); sourceBuffer->Complete(NS_OK); // Create a decoder. DecoderType decoderType = DecoderFactory::GetDecoderType(aTestCase.mMimeType); RefPtr<Decoder> decoder = DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer, aOutputSize, DefaultSurfaceFlags()); ASSERT_TRUE(decoder != nullptr); RefPtr<IDecodingTask> task = new AnonymousDecodingTask(WrapNotNull(decoder)); // Run the full decoder synchronously. task->Run(); // Call the lambda to verify the expected results. aResultChecker(decoder); }
static void CheckDecoderMultiChunk(const ImageTestCase& aTestCase) { nsCOMPtr<nsIInputStream> inputStream = LoadFile(aTestCase.mPath); ASSERT_TRUE(inputStream != nullptr); // Figure out how much data we have. uint64_t length; nsresult rv = inputStream->Available(&length); ASSERT_TRUE(NS_SUCCEEDED(rv)); // Create a SourceBuffer and a decoder. NotNull<RefPtr<SourceBuffer>> sourceBuffer = WrapNotNull(new SourceBuffer()); sourceBuffer->ExpectLength(length); DecoderType decoderType = DecoderFactory::GetDecoderType(aTestCase.mMimeType); RefPtr<Decoder> decoder = DecoderFactory::CreateAnonymousDecoder(decoderType, sourceBuffer, Nothing(), DefaultSurfaceFlags()); ASSERT_TRUE(decoder != nullptr); RefPtr<IDecodingTask> task = new AnonymousDecodingTask(WrapNotNull(decoder)); for (uint64_t read = 0; read < length ; ++read) { uint64_t available = 0; rv = inputStream->Available(&available); ASSERT_TRUE(available > 0); ASSERT_TRUE(NS_SUCCEEDED(rv)); rv = sourceBuffer->AppendFromInputStream(inputStream, 1); ASSERT_TRUE(NS_SUCCEEDED(rv)); task->Run(); } sourceBuffer->Complete(NS_OK); task->Run(); CheckDecoderResults(aTestCase, decoder); }