Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / chromecast / media / cma / test / cma_end_to_end_test.cc
blob9a8e4cd1fb0473069153a08dec929ddcfc06ab96
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/media/cma/backend/media_pipeline_device.h"
12 #include "chromecast/media/cma/backend/media_pipeline_device_factory_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 scoped_ptr<MediaPipelineDeviceFactory> factory =
43 make_scoped_ptr(new MediaPipelineDeviceFactoryDefault());
45 gles2_.reset(new gpu::gles2::GLES2InterfaceStub());
46 mock_gpu_factories_ = new ::media::MockGpuVideoAcceleratorFactories();
48 EXPECT_CALL(*mock_gpu_factories_.get(), GetGLES2Interface())
49 .WillRepeatedly(testing::Return(gles2_.get()));
51 media_pipeline->Initialize(
52 kLoadTypeMediaSource,
53 make_scoped_ptr(new MediaPipelineDevice(factory.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<::media::FakeDemuxerStreamProvider> demuxer_stream_provider_;
65 scoped_ptr<CmaRenderer> renderer_;
66 scoped_refptr<::media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_;
67 scoped_ptr<gpu::gles2::GLES2Interface> gles2_;
69 class MockCB {
70 public:
71 MOCK_METHOD1(OnInitialized, void(::media::PipelineStatus));
72 MOCK_METHOD1(OnFrameReceived,
73 void(const scoped_refptr<::media::VideoFrame>&));
74 MOCK_METHOD1(OnStatistics, void(const ::media::PipelineStatistics&));
75 MOCK_METHOD1(OnBufferingState, void(::media::BufferingState));
76 MOCK_METHOD0(OnEnded, void());
77 MOCK_METHOD1(OnError, void(::media::PipelineStatus));
78 MOCK_METHOD0(OnWaitingForDecryptionKey, void());
80 MockCB mock_;
82 private:
83 scoped_ptr<::media::NullVideoSink> null_sink_;
85 DISALLOW_COPY_AND_ASSIGN(CmaEndToEndTest);
88 } // namespace
90 TEST_F(CmaEndToEndTest, TestInitialization) {
91 renderer_->Initialize(
92 demuxer_stream_provider_.get(),
93 base::Bind(&MockCB::OnInitialized, base::Unretained(&mock_)),
94 base::Bind(&MockCB::OnStatistics, base::Unretained(&mock_)),
95 base::Bind(&MockCB::OnBufferingState, base::Unretained(&mock_)),
96 base::Bind(&MockCB::OnEnded, base::Unretained(&mock_)),
97 base::Bind(&MockCB::OnError, base::Unretained(&mock_)),
98 base::Bind(&MockCB::OnWaitingForDecryptionKey, base::Unretained(&mock_)));
100 EXPECT_CALL(mock_, OnInitialized(::media::PIPELINE_OK));
104 } // namespace media
105 } // namespace chromecast