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

Side by Side Diff: media/base/pipeline_impl_unittest.cc

Issue 1904793002: Move Pipeline permanent callbacks into Pipeline::Client interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/pipeline_impl.h" 5 #include "media/base/pipeline_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // TODO(scherkus): even though some filters are initialized on separate 70 // TODO(scherkus): even though some filters are initialized on separate
71 // threads these test aren't flaky... why? It's because filters' Initialize() 71 // threads these test aren't flaky... why? It's because filters' Initialize()
72 // is executed on |message_loop_| and the mock filters instantly call 72 // is executed on |message_loop_| and the mock filters instantly call
73 // InitializationComplete(), which keeps the pipeline humming along. If 73 // InitializationComplete(), which keeps the pipeline humming along. If
74 // either filters don't call InitializationComplete() immediately or filter 74 // either filters don't call InitializationComplete() immediately or filter
75 // initialization is moved to a separate thread this test will become flaky. 75 // initialization is moved to a separate thread this test will become flaky.
76 class PipelineImplTest : public ::testing::Test { 76 class PipelineImplTest : public ::testing::Test {
77 public: 77 public:
78 // Used for setting expectations on pipeline callbacks. Using a StrictMock 78 // Used for setting expectations on pipeline callbacks. Using a StrictMock
79 // also lets us test for missing callbacks. 79 // also lets us test for missing callbacks.
80 class CallbackHelper { 80 class CallbackHelper : public Pipeline::Client {
81 public: 81 public:
82 CallbackHelper() {} 82 CallbackHelper() {}
83 virtual ~CallbackHelper() {} 83 virtual ~CallbackHelper() {}
84 84
85 MOCK_METHOD1(OnStart, void(PipelineStatus)); 85 MOCK_METHOD1(OnStart, void(PipelineStatus));
86 MOCK_METHOD1(OnSeek, void(PipelineStatus)); 86 MOCK_METHOD1(OnSeek, void(PipelineStatus));
87 MOCK_METHOD1(OnSuspend, void(PipelineStatus)); 87 MOCK_METHOD1(OnSuspend, void(PipelineStatus));
88 MOCK_METHOD1(OnResume, void(PipelineStatus)); 88 MOCK_METHOD1(OnResume, void(PipelineStatus));
89 MOCK_METHOD0(OnStop, void()); 89 MOCK_METHOD0(OnStop, void());
90
91 // Pipeline::Client overrides.
92 MOCK_METHOD1(OnError, void(PipelineStatus));
90 MOCK_METHOD0(OnEnded, void()); 93 MOCK_METHOD0(OnEnded, void());
91 MOCK_METHOD1(OnError, void(PipelineStatus));
92 MOCK_METHOD1(OnMetadata, void(PipelineMetadata)); 94 MOCK_METHOD1(OnMetadata, void(PipelineMetadata));
93 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); 95 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState));
94 MOCK_METHOD0(OnDurationChange, void()); 96 MOCK_METHOD0(OnDurationChange, void());
97 MOCK_METHOD2(OnAddTextTrack,
98 void(const TextTrackConfig&, const AddTextTrackDoneCB&));
99 MOCK_METHOD0(OnWaitingForDecryptionKey, void());
95 100
96 private: 101 private:
97 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); 102 DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
98 }; 103 };
99 104
100 PipelineImplTest() 105 PipelineImplTest()
101 : pipeline_( 106 : pipeline_(
102 new PipelineImpl(message_loop_.task_runner(), new MediaLog())), 107 new PipelineImpl(message_loop_.task_runner(), new MediaLog())),
103 demuxer_(new StrictMock<MockDemuxer>()), 108 demuxer_(new StrictMock<MockDemuxer>()),
104 scoped_renderer_(new StrictMock<MockRenderer>()), 109 scoped_renderer_(new StrictMock<MockRenderer>()),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void SetRendererExpectations() { 182 void SetRendererExpectations() {
178 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) 183 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _))
179 .WillOnce(DoAll(SaveArg<2>(&statistics_cb_), 184 .WillOnce(DoAll(SaveArg<2>(&statistics_cb_),
180 SaveArg<3>(&buffering_state_cb_), 185 SaveArg<3>(&buffering_state_cb_),
181 SaveArg<4>(&ended_cb_), PostCallback<1>(PIPELINE_OK))); 186 SaveArg<4>(&ended_cb_), PostCallback<1>(PIPELINE_OK)));
182 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(audio_stream())); 187 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(audio_stream()));
183 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(video_stream())); 188 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(video_stream()));
184 } 189 }
185 190
186 void AddTextStream() { 191 void AddTextStream() {
187 EXPECT_CALL(*this, OnAddTextTrack(_, _)) 192 EXPECT_CALL(callbacks_, OnAddTextTrack(_, _))
188 .WillOnce(Invoke(this, &PipelineImplTest::DoOnAddTextTrack)); 193 .WillOnce(Invoke(this, &PipelineImplTest::DoOnAddTextTrack));
189 static_cast<DemuxerHost*>(pipeline_.get()) 194 static_cast<DemuxerHost*>(pipeline_.get())
190 ->AddTextStream(text_stream(), 195 ->AddTextStream(text_stream(),
191 TextTrackConfig(kTextSubtitles, "", "", "")); 196 TextTrackConfig(kTextSubtitles, "", "", ""));
192 message_loop_.RunUntilIdle(); 197 message_loop_.RunUntilIdle();
193 } 198 }
194 199
195 void StartPipeline() { 200 void StartPipeline() {
196 EXPECT_CALL(*this, OnWaitingForDecryptionKey()).Times(0); 201 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0);
197 pipeline_->Start( 202 pipeline_->Start(
198 demuxer_.get(), std::move(scoped_renderer_), 203 demuxer_.get(), std::move(scoped_renderer_), &callbacks_,
199 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 204 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)));
200 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
201 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
202 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)),
203 base::Bind(&CallbackHelper::OnBufferingStateChange,
204 base::Unretained(&callbacks_)),
205 base::Bind(&CallbackHelper::OnDurationChange,
206 base::Unretained(&callbacks_)),
207 base::Bind(&PipelineImplTest::OnAddTextTrack, base::Unretained(this)),
208 base::Bind(&PipelineImplTest::OnWaitingForDecryptionKey,
209 base::Unretained(this)));
210 } 205 }
211 206
212 // Sets up expectations on the callback and initializes the pipeline. Called 207 // Sets up expectations on the callback and initializes the pipeline. Called
213 // after tests have set expectations any filters they wish to use. 208 // after tests have set expectations any filters they wish to use.
214 void StartPipelineAndExpect(PipelineStatus start_status) { 209 void StartPipelineAndExpect(PipelineStatus start_status) {
215 EXPECT_CALL(callbacks_, OnStart(start_status)); 210 EXPECT_CALL(callbacks_, OnStart(start_status));
216 211
217 if (start_status == PIPELINE_OK) { 212 if (start_status == PIPELINE_OK) {
218 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_)); 213 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_));
219 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0)); 214 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 EXPECT_CALL(*demuxer_, Stop()); 322 EXPECT_CALL(*demuxer_, Stop());
328 } 323 }
329 324
330 void ExpectPipelineStopAndDestroyPipeline() { 325 void ExpectPipelineStopAndDestroyPipeline() {
331 // After the Pipeline is stopped, it could be destroyed any time. Always 326 // After the Pipeline is stopped, it could be destroyed any time. Always
332 // destroy the pipeline immediately after OnStop() to test this. 327 // destroy the pipeline immediately after OnStop() to test this.
333 EXPECT_CALL(callbacks_, OnStop()) 328 EXPECT_CALL(callbacks_, OnStop())
334 .WillOnce(Invoke(this, &PipelineImplTest::DestroyPipeline)); 329 .WillOnce(Invoke(this, &PipelineImplTest::DestroyPipeline));
335 } 330 }
336 331
337 MOCK_METHOD2(OnAddTextTrack,
338 void(const TextTrackConfig&, const AddTextTrackDoneCB&));
339 MOCK_METHOD0(OnWaitingForDecryptionKey, void(void));
340
341 void DoOnAddTextTrack(const TextTrackConfig& config, 332 void DoOnAddTextTrack(const TextTrackConfig& config,
342 const AddTextTrackDoneCB& done_cb) { 333 const AddTextTrackDoneCB& done_cb) {
343 std::unique_ptr<TextTrack> text_track(new MockTextTrack); 334 std::unique_ptr<TextTrack> text_track(new MockTextTrack);
344 done_cb.Run(std::move(text_track)); 335 done_cb.Run(std::move(text_track));
345 } 336 }
346 337
347 void RunBufferedTimeRangesTest(const base::TimeDelta duration) { 338 void RunBufferedTimeRangesTest(const base::TimeDelta duration) {
348 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); 339 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size());
349 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 340 EXPECT_FALSE(pipeline_->DidLoadingProgress());
350 Ranges<base::TimeDelta> ranges; 341 Ranges<base::TimeDelta> ranges;
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1154 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1164 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1155 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1165 INSTANTIATE_TEARDOWN_TEST(Error, Suspending); 1156 INSTANTIATE_TEARDOWN_TEST(Error, Suspending);
1166 INSTANTIATE_TEARDOWN_TEST(Error, Suspended); 1157 INSTANTIATE_TEARDOWN_TEST(Error, Suspended);
1167 INSTANTIATE_TEARDOWN_TEST(Error, Resuming); 1158 INSTANTIATE_TEARDOWN_TEST(Error, Resuming);
1168 1159
1169 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); 1160 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing);
1170 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Suspended); 1161 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Suspended);
1171 1162
1172 } // namespace media 1163 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698