Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: media/filters/pipeline_controller_unittest.cc

Issue 1641423002: Re-land extract state management from WebMediaPlayerImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix scoped_ptr usage. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 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.
4
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "media/base/pipeline.h"
13 #include "media/filters/pipeline_controller.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using ::testing::_;
18 using ::testing::Mock;
19 using ::testing::NiceMock;
20 using ::testing::SaveArg;
21
22 namespace media {
23
24 ACTION_TEMPLATE(RunCallback,
25 HAS_1_TEMPLATE_PARAMS(int, k),
26 AND_1_VALUE_PARAMS(p0)) {
27 return ::std::tr1::get<k>(args).Run(p0);
28 }
29
30 class MockPipeline : public Pipeline {
31 public:
32 MockPipeline() {}
33
34 virtual ~MockPipeline() {}
35
36 // Start() cannot be mocked due to scoped_ptr. Instead it forwards to a
37 // version that can.
38 MOCK_METHOD10(Start,
39 void(Demuxer*,
40 scoped_ptr<Renderer>*,
41 const base::Closure&,
42 const PipelineStatusCB&,
43 const PipelineStatusCB&,
44 const PipelineMetadataCB&,
45 const BufferingStateCB&,
46 const base::Closure&,
47 const AddTextTrackCB&,
48 const base::Closure&));
49
50 void Start(Demuxer* demuxer,
51 scoped_ptr<Renderer> renderer,
52 const base::Closure& ended_cb,
53 const PipelineStatusCB& error_cb,
54 const PipelineStatusCB& seek_cb,
55 const PipelineMetadataCB& metadata_cb,
56 const BufferingStateCB& buffering_state_cb,
57 const base::Closure& duration_change_cb,
58 const AddTextTrackCB& add_text_track_cb,
59 const base::Closure& waiting_for_decryption_key_cb) override {
60 Start(demuxer, &renderer, ended_cb, error_cb, seek_cb, metadata_cb,
61 buffering_state_cb, duration_change_cb, add_text_track_cb,
62 waiting_for_decryption_key_cb);
63 }
64
65 MOCK_METHOD1(Stop, void(const base::Closure&));
66 MOCK_METHOD2(Seek, void(base::TimeDelta, const PipelineStatusCB&));
67 MOCK_METHOD1(Suspend, void(const PipelineStatusCB&));
68
69 // Resume() cannot be mocked due to scoped_ptr. Instead it forwards to a
70 // version that can.
71 MOCK_METHOD3(Resume,
72 void(scoped_ptr<Renderer>*,
73 base::TimeDelta,
74 const PipelineStatusCB&));
75
76 void Resume(scoped_ptr<Renderer> renderer,
77 base::TimeDelta timestamp,
78 const PipelineStatusCB& seek_cb) override {
79 Resume(&renderer, timestamp, seek_cb);
80 }
81
82 // TODO(sandersd): It would be helpful if this always returned true once the
83 // start callback was called (until Stop()).
84 MOCK_CONST_METHOD0(IsRunning, bool());
85
86 // TODO(sandersd): These should be regular get/set implementations.
87 MOCK_CONST_METHOD0(GetPlaybackRate, double());
88 MOCK_METHOD1(SetPlaybackRate, void(double));
89 MOCK_CONST_METHOD0(GetVolume, float());
90 MOCK_METHOD1(SetVolume, void(float));
91
92 // TODO(sandersd): Some sort of help would be useful for configuring these.
93 MOCK_CONST_METHOD0(GetMediaTime, base::TimeDelta());
94 MOCK_CONST_METHOD0(GetBufferedTimeRanges, Ranges<base::TimeDelta>());
95 MOCK_CONST_METHOD0(GetMediaDuration, base::TimeDelta());
96 MOCK_METHOD0(DidLoadingProgress, bool());
97 MOCK_CONST_METHOD0(GetStatistics, PipelineStatistics());
98
99 MOCK_METHOD2(SetCdm, void(CdmContext*, const CdmAttachedCB&));
100 };
101
102 class PipelineControllerTest : public ::testing::Test {
103 public:
104 PipelineControllerTest()
105 : pipeline_controller_(&pipeline_,
106 base::Bind(&PipelineControllerTest::CreateRenderer,
107 base::Unretained(this)),
108 base::Bind(&PipelineControllerTest::OnSeeked,
109 base::Unretained(this)),
110 base::Bind(&PipelineControllerTest::OnSuspended,
111 base::Unretained(this)),
112 base::Bind(&PipelineControllerTest::OnError,
113 base::Unretained(this))) {}
114
115 ~PipelineControllerTest() override {}
116
117 void StartPipeline(ChunkDemuxer* chunk_demuxer) {
118 // Everything other than |chunk_demuxer| is null since there is no reason
119 // for MockPipeline to call them.
120 pipeline_controller_.Start(
121 chunk_demuxer, nullptr, base::Closure(), PipelineMetadataCB(),
122 BufferingStateCB(), base::Closure(), AddTextTrackCB(), base::Closure());
123 }
124
125 void StopPipeline() {}
126
127 protected:
128 scoped_ptr<Renderer> CreateRenderer() { return scoped_ptr<Renderer>(); }
129
130 void OnSeeked(bool time_updated) {}
131
132 void OnSuspended() {}
133
134 void OnError(PipelineStatus status) { NOTREACHED(); }
135
136 MockPipeline pipeline_;
137 PipelineController pipeline_controller_;
138
139 DISALLOW_COPY_AND_ASSIGN(PipelineControllerTest);
140 };
141
142 TEST_F(PipelineControllerTest, PendingSuspend) {
143 // Immediately complete Pipline startup.
144 EXPECT_CALL(pipeline_, Start(_, _, _, _, _, _, _, _, _, _))
145 .WillOnce(RunCallback<4>(PIPELINE_OK));
146 StartPipeline(nullptr);
147
148 Mock::VerifyAndClear(&pipeline_);
149 EXPECT_TRUE(pipeline_controller_.IsStable());
150
151 // Start a seek, but do not complete it immediately.
152 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
153 PipelineStatusCB seek_cb;
154 EXPECT_CALL(pipeline_, Seek(seek_time, _)).WillOnce(SaveArg<1>(&seek_cb));
155 pipeline_controller_.Seek(seek_time, true);
156
157 Mock::VerifyAndClear(&pipeline_);
158 EXPECT_FALSE(pipeline_controller_.IsStable());
159
160 // Schedule a suspend. (It shouldn't happen yet.)
161 pipeline_controller_.Suspend();
162
163 // Complete the seek; the suspend should trigger.
164 EXPECT_CALL(pipeline_, Suspend(_));
165 seek_cb.Run(PIPELINE_OK);
166 }
167
168 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698