| Index: media/gpu/mojo/service/gpu_jpeg_decode_accelerator_unittest.cc
|
| diff --git a/media/gpu/mojo/service/gpu_jpeg_decode_accelerator_unittest.cc b/media/gpu/mojo/service/gpu_jpeg_decode_accelerator_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a1521a957cafa318f5bcf64f9b1e11fcce942e7b
|
| --- /dev/null
|
| +++ b/media/gpu/mojo/service/gpu_jpeg_decode_accelerator_unittest.cc
|
| @@ -0,0 +1,92 @@
|
| +// Copyright 2017 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 "media/gpu/mojo/service/gpu_jpeg_decode_accelerator.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| +#include "base/run_loop.h"
|
| +#include "base/test/scoped_task_environment.h"
|
| +#include "base/threading/thread.h"
|
| +#include "media/base/media_switches.h"
|
| +#include "mojo/public/cpp/system/platform_handle.h"
|
| +#include "services/service_manager/public/cpp/bind_source_info.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace media {
|
| +
|
| +static const int32_t kArbitraryBitstreamBufferId = 123;
|
| +
|
| +// Test fixture for the unit that is created via the mojom interface for
|
| +// class GpuJpegDecodeAccelerator. Uses a FakeJpegDecodeAccelerator to
|
| +// simulate the actual decoding without the need for special hardware.
|
| +class GpuJpegDecodeAcceleratorTest : public ::testing::Test {
|
| + public:
|
| + GpuJpegDecodeAcceleratorTest() : io_thread_("io") {}
|
| + ~GpuJpegDecodeAcceleratorTest() override{};
|
| +
|
| + void SetUp() override {
|
| + base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kUseFakeJpegDecodeAccelerator);
|
| + io_thread_.Start();
|
| + }
|
| +
|
| + void OnDecodeAck(const base::Closure& continuation,
|
| + int32_t bitstream_buffer_id,
|
| + mojom::Error error) {
|
| + EXPECT_EQ(kArbitraryBitstreamBufferId, bitstream_buffer_id);
|
| + continuation.Run();
|
| + }
|
| +
|
| + protected:
|
| + base::Thread io_thread_;
|
| +
|
| + private:
|
| + // This is required to allow base::ThreadTaskRunnerHandle::Get() from the
|
| + // test execution thread.
|
| + base::test::ScopedTaskEnvironment scoped_task_environment_;
|
| +};
|
| +
|
| +TEST_F(GpuJpegDecodeAcceleratorTest, InitializeAndDecode) {
|
| + mojom::GpuJpegDecodeAcceleratorPtr jpeg_decoder_;
|
| + GpuJpegDecodeAccelerator::Create(io_thread_.task_runner(),
|
| + service_manager::BindSourceInfo(),
|
| + mojo::MakeRequest(&jpeg_decoder_));
|
| +
|
| + bool succeeded = false;
|
| + jpeg_decoder_->Initialize(&succeeded);
|
| + EXPECT_TRUE(succeeded);
|
| +
|
| + const size_t kInputBufferSizeInBytes = 512;
|
| + const size_t kOutputFrameSizeInBytes = 1024;
|
| + const gfx::Size kDummyFrameCodedSize(10, 10);
|
| + const char kKeyId[] = "key id";
|
| + const char kIv[] = "0123456789abcdef";
|
| + std::vector<SubsampleEntry> subsamples;
|
| + subsamples.push_back(SubsampleEntry(10, 5));
|
| + subsamples.push_back(SubsampleEntry(15, 7));
|
| +
|
| + base::RunLoop run_loop;
|
| + mojo::ScopedSharedBufferHandle input_buffer_handle =
|
| + mojo::SharedBufferHandle::Create(kInputBufferSizeInBytes);
|
| + mojom::BitstreamBufferPtr buffer = mojom::BitstreamBuffer::New();
|
| + buffer->id = kArbitraryBitstreamBufferId;
|
| + buffer->memory_handle = std::move(input_buffer_handle);
|
| + buffer->size = kInputBufferSizeInBytes;
|
| + buffer->key_id = kKeyId;
|
| + buffer->iv = kIv;
|
| + buffer->subsamples = subsamples;
|
| +
|
| + mojo::ScopedSharedBufferHandle output_frame_handle =
|
| + mojo::SharedBufferHandle::Create(kOutputFrameSizeInBytes);
|
| +
|
| + jpeg_decoder_->Decode(
|
| + std::move(buffer), kDummyFrameCodedSize, std::move(output_frame_handle),
|
| + base::checked_cast<uint32_t>(kOutputFrameSizeInBytes),
|
| + base::Bind(&GpuJpegDecodeAcceleratorTest::OnDecodeAck,
|
| + base::Unretained(this), run_loop.QuitClosure()));
|
| + run_loop.Run();
|
| +}
|
| +
|
| +} // namespace media
|
|
|