Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / media / cma / test / cma_end_to_end_test.cc
blob70483e6d9a0b74d35068e1a712786caec94da5ad
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/macros.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/time/time.h"
11 #include "chromecast/base/task_runner_impl.h"
12 #include "chromecast/media/cma/backend/media_pipeline_backend_default.h"
13 #include "chromecast/media/cma/base/buffering_defs.h"
14 #include "chromecast/media/cma/filters/cma_renderer.h"
15 #include "chromecast/media/cma/pipeline/media_pipeline_impl.h"
16 #include "gpu/command_buffer/client/gles2_interface_stub.h"
17 #include "media/base/demuxer_stream_provider.h"
18 #include "media/base/fake_demuxer_stream.h"
19 #include "media/base/null_video_sink.h"
20 #include "media/renderers/mock_gpu_video_accelerator_factories.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
24 namespace chromecast {
25 namespace media {
27 namespace {
29 class CmaEndToEndTest : public testing::Test {
30 public:
31 CmaEndToEndTest() {}
33 void SetUp() override {
34 demuxer_stream_provider_.reset(
35 new ::media::FakeDemuxerStreamProvider(1, 1, false));
36 null_sink_.reset(new ::media::NullVideoSink(
37 false, base::TimeDelta::FromSecondsD(1.0 / 60),
38 base::Bind(&MockCB::OnFrameReceived, base::Unretained(&mock_)),
39 message_loop_.task_runner()));
41 scoped_ptr<MediaPipelineImpl> media_pipeline(new MediaPipelineImpl());
42 task_runner_.reset(new TaskRunnerImpl());
43 MediaPipelineDeviceParams params(task_runner_.get());
44 scoped_ptr<MediaPipelineBackend> backend =
45 make_scoped_ptr(new MediaPipelineBackendDefault(params));
47 gles2_.reset(new gpu::gles2::GLES2InterfaceStub());
48 mock_gpu_factories_ = new ::media::MockGpuVideoAcceleratorFactories();
50 EXPECT_CALL(*mock_gpu_factories_.get(), GetGLES2Interface())
51 .WillRepeatedly(testing::Return(gles2_.get()));
53 media_pipeline->Initialize(kLoadTypeMediaSource, backend.Pass());
55 renderer_.reset(new CmaRenderer(media_pipeline.Pass(), null_sink_.get(),
56 mock_gpu_factories_));
58 void TearDown() override { message_loop_.RunUntilIdle(); }
60 ~CmaEndToEndTest() override {}
62 protected:
63 base::MessageLoop message_loop_;
64 scoped_ptr<TaskRunnerImpl> task_runner_;
65 scoped_ptr<::media::FakeDemuxerStreamProvider> demuxer_stream_provider_;
66 scoped_ptr<CmaRenderer> renderer_;
67 scoped_refptr<::media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_;
68 scoped_ptr<gpu::gles2::GLES2Interface> gles2_;
70 class MockCB {
71 public:
72 MOCK_METHOD1(OnInitialized, void(::media::PipelineStatus));
73 MOCK_METHOD1(OnFrameReceived,
74 void(const scoped_refptr<::media::VideoFrame>&));
75 MOCK_METHOD1(OnStatistics, void(const ::media::PipelineStatistics&));
76 MOCK_METHOD1(OnBufferingState, void(::media::BufferingState));
77 MOCK_METHOD0(OnEnded, void());
78 MOCK_METHOD1(OnError, void(::media::PipelineStatus));
79 MOCK_METHOD0(OnWaitingForDecryptionKey, void());
81 MockCB mock_;
83 private:
84 scoped_ptr<::media::NullVideoSink> null_sink_;
86 DISALLOW_COPY_AND_ASSIGN(CmaEndToEndTest);
89 } // namespace
91 TEST_F(CmaEndToEndTest, TestInitialization) {
92 renderer_->Initialize(
93 demuxer_stream_provider_.get(),
94 base::Bind(&MockCB::OnInitialized, base::Unretained(&mock_)),
95 base::Bind(&MockCB::OnStatistics, base::Unretained(&mock_)),
96 base::Bind(&MockCB::OnBufferingState, base::Unretained(&mock_)),
97 base::Bind(&MockCB::OnEnded, base::Unretained(&mock_)),
98 base::Bind(&MockCB::OnError, base::Unretained(&mock_)),
99 base::Bind(&MockCB::OnWaitingForDecryptionKey, base::Unretained(&mock_)));
101 EXPECT_CALL(mock_, OnInitialized(::media::PIPELINE_OK));
105 } // namespace media
106 } // namespace chromecast