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

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

Powered by Google App Engine
This is Rietveld 408576698