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

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

Issue 10753021: Move AudioRenderer out of Filter heirarchy. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: woot for RunInSeries/Parallel Created 8 years, 5 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 | Annotate | Revision Log
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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/simple_thread.h" 10 #include "base/threading/simple_thread.h"
(...skipping 21 matching lines...) Expand all
32 using ::testing::StrictMock; 32 using ::testing::StrictMock;
33 using ::testing::WithArg; 33 using ::testing::WithArg;
34 34
35 namespace media { 35 namespace media {
36 36
37 // Demuxer properties. 37 // Demuxer properties.
38 static const int kTotalBytes = 1024; 38 static const int kTotalBytes = 1024;
39 static const int kBufferedBytes = 1024; 39 static const int kBufferedBytes = 1024;
40 static const int kBitrate = 1234; 40 static const int kBitrate = 1234;
41 41
42 ACTION_P(InitializeDemuxerWithError, error) {
43 arg1.Run(error);
44 }
45
46 ACTION_P(SetDemuxerProperties, duration) { 42 ACTION_P(SetDemuxerProperties, duration) {
47 arg0->SetTotalBytes(kTotalBytes); 43 arg0->SetTotalBytes(kTotalBytes);
48 arg0->SetDuration(duration); 44 arg0->SetDuration(duration);
49 } 45 }
50 46
51 ACTION_P(DisableAudioRenderer, pipeline) { 47 ACTION(RunPipelineStatusCB1) {
52 FilterHost* host = pipeline; 48 arg1.Run(PIPELINE_OK);
53 host->DisableAudioRenderer(); 49 }
50
51 ACTION_P(RunPipelineStatusCB1WithStatus, status) {
52 arg1.Run(status);
54 } 53 }
55 54
56 // Used for setting expectations on pipeline callbacks. Using a StrictMock 55 // Used for setting expectations on pipeline callbacks. Using a StrictMock
57 // also lets us test for missing callbacks. 56 // also lets us test for missing callbacks.
58 class CallbackHelper { 57 class CallbackHelper {
59 public: 58 public:
60 CallbackHelper() {} 59 CallbackHelper() {}
61 virtual ~CallbackHelper() {} 60 virtual ~CallbackHelper() {}
62 61
63 MOCK_METHOD1(OnStart, void(PipelineStatus)); 62 MOCK_METHOD1(OnStart, void(PipelineStatus));
(...skipping 29 matching lines...) Expand all
93 } 92 }
94 93
95 virtual ~PipelineTest() { 94 virtual ~PipelineTest() {
96 if (!pipeline_->IsRunning()) { 95 if (!pipeline_->IsRunning()) {
97 return; 96 return;
98 } 97 }
99 98
100 // Shutdown sequence. 99 // Shutdown sequence.
101 if (pipeline_->IsInitialized()) { 100 if (pipeline_->IsInitialized()) {
102 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 101 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
103 .WillOnce(Invoke(&RunClosure)); 102 .WillOnce(RunClosure());
104 103
105 if (audio_stream_) { 104 if (audio_stream_) {
106 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 105 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
107 .WillOnce(Invoke(&RunClosure)); 106 .WillOnce(RunClosure());
108 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 107 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
109 .WillOnce(Invoke(&RunClosure)); 108 .WillOnce(RunClosure());
110 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) 109 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
111 .WillOnce(Invoke(&RunClosure)); 110 .WillOnce(RunClosure());
112 } 111 }
113 112
114 if (video_stream_) { 113 if (video_stream_) {
115 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) 114 EXPECT_CALL(*mocks_->video_renderer(), Pause(_))
116 .WillOnce(Invoke(&RunClosure)); 115 .WillOnce(RunClosure());
117 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) 116 EXPECT_CALL(*mocks_->video_renderer(), Flush(_))
118 .WillOnce(Invoke(&RunClosure)); 117 .WillOnce(RunClosure());
119 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) 118 EXPECT_CALL(*mocks_->video_renderer(), Stop(_))
120 .WillOnce(Invoke(&RunClosure)); 119 .WillOnce(RunClosure());
121 } 120 }
122 } 121 }
123 122
124 // Expect a stop callback if we were started. 123 // Expect a stop callback if we were started.
125 EXPECT_CALL(callbacks_, OnStop()); 124 EXPECT_CALL(callbacks_, OnStop());
126 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, 125 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop,
127 base::Unretained(&callbacks_))); 126 base::Unretained(&callbacks_)));
128 message_loop_.RunAllPending(); 127 message_loop_.RunAllPending();
129 128
130 pipeline_ = NULL; 129 pipeline_ = NULL;
131 mocks_.reset(); 130 mocks_.reset();
132 } 131 }
133 132
134 protected: 133 protected:
135 // Sets up expectations to allow the demuxer to initialize. 134 // Sets up expectations to allow the demuxer to initialize.
136 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; 135 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector;
137 void InitializeDemuxer(MockDemuxerStreamVector* streams, 136 void InitializeDemuxer(MockDemuxerStreamVector* streams,
138 const base::TimeDelta& duration) { 137 const base::TimeDelta& duration) {
139 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) 138 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
140 .WillOnce(DoAll(SetDemuxerProperties(duration), 139 .WillOnce(DoAll(SetDemuxerProperties(duration),
141 Invoke(&RunPipelineStatusCB2))); 140 RunPipelineStatusCB1()));
142 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); 141 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f));
143 142
144 // Demuxer properties. 143 // Demuxer properties.
145 EXPECT_CALL(*mocks_->demuxer(), GetBitrate()) 144 EXPECT_CALL(*mocks_->demuxer(), GetBitrate())
146 .WillRepeatedly(Return(kBitrate)); 145 .WillRepeatedly(Return(kBitrate));
147 146
148 // Configure the demuxer to return the streams. 147 // Configure the demuxer to return the streams.
149 for (size_t i = 0; i < streams->size(); ++i) { 148 for (size_t i = 0; i < streams->size(); ++i) {
150 scoped_refptr<DemuxerStream> stream((*streams)[i]); 149 scoped_refptr<DemuxerStream> stream((*streams)[i]);
151 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) 150 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type()))
(...skipping 11 matching lines...) Expand all
163 new StrictMock<MockDemuxerStream>(); 162 new StrictMock<MockDemuxerStream>();
164 EXPECT_CALL(*stream, type()) 163 EXPECT_CALL(*stream, type())
165 .WillRepeatedly(Return(type)); 164 .WillRepeatedly(Return(type));
166 return stream; 165 return stream;
167 } 166 }
168 167
169 // Sets up expectations to allow the video decoder to initialize. 168 // Sets up expectations to allow the video decoder to initialize.
170 void InitializeVideoDecoder(const scoped_refptr<DemuxerStream>& stream) { 169 void InitializeVideoDecoder(const scoped_refptr<DemuxerStream>& stream) {
171 EXPECT_CALL(*mocks_->video_decoder(), 170 EXPECT_CALL(*mocks_->video_decoder(),
172 Initialize(stream, _, _)) 171 Initialize(stream, _, _))
173 .WillOnce(Invoke(&RunPipelineStatusCB3)); 172 .WillOnce(RunPipelineStatusCB1());
174 } 173 }
175 174
176 // Sets up expectations to allow the audio decoder to initialize. 175 // Sets up expectations to allow the audio decoder to initialize.
177 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { 176 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) {
178 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) 177 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _))
179 .WillOnce(Invoke(&RunPipelineStatusCB3)); 178 .WillOnce(RunPipelineStatusCB1());
180 } 179 }
181 180
182 // Sets up expectations to allow the video renderer to initialize. 181 // Sets up expectations to allow the video renderer to initialize.
183 void InitializeVideoRenderer() { 182 void InitializeVideoRenderer() {
184 EXPECT_CALL(*mocks_->video_renderer(), SetHost(NotNull())); 183 EXPECT_CALL(*mocks_->video_renderer(), SetHost(NotNull()));
185 EXPECT_CALL(*mocks_->video_renderer(), Initialize( 184 EXPECT_CALL(*mocks_->video_renderer(), Initialize(
186 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), _, _, _)) 185 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), _, _, _))
187 .WillOnce(Invoke(&RunPipelineStatusCB4)); 186 .WillOnce(RunPipelineStatusCB1());
188 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); 187 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f));
189 188
190 // Startup sequence. 189 // Startup sequence.
191 EXPECT_CALL(*mocks_->video_renderer(), 190 EXPECT_CALL(*mocks_->video_renderer(),
192 Seek(mocks_->demuxer()->GetStartTime(), _)) 191 Seek(mocks_->demuxer()->GetStartTime(), _))
193 .WillOnce(Invoke(&RunPipelineStatusCB2)); 192 .WillOnce(RunPipelineStatusCB1());
194 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) 193 EXPECT_CALL(*mocks_->video_renderer(), Play(_))
195 .WillOnce(Invoke(&RunClosure)); 194 .WillOnce(RunClosure());
196 } 195 }
197 196
198 // Sets up expectations to allow the audio renderer to initialize. 197 // Sets up expectations to allow the audio renderer to initialize.
199 void InitializeAudioRenderer(bool disable_after_init_cb = false) { 198 void InitializeAudioRenderer(bool disable_after_init_cb = false) {
200 EXPECT_CALL(*mocks_->audio_renderer(), SetHost(NotNull()));
201 if (disable_after_init_cb) { 199 if (disable_after_init_cb) {
202 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( 200 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(
203 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) 201 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _, _, _))
204 .WillOnce(DoAll(Invoke(&RunPipelineStatusCB4), 202 .WillOnce(DoAll(RunPipelineStatusCB1(),
205 DisableAudioRenderer(pipeline_))); 203 WithArg<5>(RunClosure()))); // |disabled_cb|.
acolwell GONE FROM CHROMIUM 2012/07/19 00:58:18 nit: 2 spaces before comment
scherkus (not reviewing) 2012/07/19 21:29:02 Done.
206 } else { 204 } else {
207 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( 205 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(
208 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) 206 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _, _, _))
209 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), 207 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_),
210 Invoke(&RunPipelineStatusCB4))); 208 RunPipelineStatusCB1()));
211 } 209 }
212 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); 210 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f));
213 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); 211 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f));
214 212
215 // Startup sequence. 213 // Startup sequence.
216 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) 214 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _))
217 .WillOnce(Invoke(&RunPipelineStatusCB2)); 215 .WillOnce(RunPipelineStatusCB1());
218 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) 216 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
219 .WillOnce(Invoke(&RunClosure)); 217 .WillOnce(RunClosure());
220 } 218 }
221 219
222 // Sets up expectations on the callback and initializes the pipeline. Called 220 // Sets up expectations on the callback and initializes the pipeline. Called
223 // after tests have set expectations any filters they wish to use. 221 // after tests have set expectations any filters they wish to use.
224 void InitializePipeline(PipelineStatus start_status) { 222 void InitializePipeline(PipelineStatus start_status) {
225 EXPECT_CALL(callbacks_, OnStart(start_status)); 223 EXPECT_CALL(callbacks_, OnStart(start_status));
226 224
227 pipeline_->Start( 225 pipeline_->Start(
228 mocks_->Create().Pass(), 226 mocks_->Create().Pass(),
229 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 227 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
(...skipping 14 matching lines...) Expand all
244 return audio_stream_; 242 return audio_stream_;
245 } 243 }
246 244
247 MockDemuxerStream* video_stream() { 245 MockDemuxerStream* video_stream() {
248 return video_stream_; 246 return video_stream_;
249 } 247 }
250 248
251 void ExpectSeek(const base::TimeDelta& seek_time) { 249 void ExpectSeek(const base::TimeDelta& seek_time) {
252 // Every filter should receive a call to Seek(). 250 // Every filter should receive a call to Seek().
253 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) 251 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _))
254 .WillOnce(Invoke(&RunPipelineStatusCB2)); 252 .WillOnce(RunPipelineStatusCB1());
255 253
256 if (audio_stream_) { 254 if (audio_stream_) {
257 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 255 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
258 .WillOnce(Invoke(&RunClosure)); 256 .WillOnce(RunClosure());
259 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 257 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
260 .WillOnce(Invoke(&RunClosure)); 258 .WillOnce(RunClosure());
261 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) 259 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _))
262 .WillOnce(Invoke(&RunPipelineStatusCB2)); 260 .WillOnce(RunPipelineStatusCB1());
263 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) 261 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
264 .WillOnce(Invoke(&RunClosure)); 262 .WillOnce(RunClosure());
265 } 263 }
266 264
267 if (video_stream_) { 265 if (video_stream_) {
268 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) 266 EXPECT_CALL(*mocks_->video_renderer(), Pause(_))
269 .WillOnce(Invoke(&RunClosure)); 267 .WillOnce(RunClosure());
270 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) 268 EXPECT_CALL(*mocks_->video_renderer(), Flush(_))
271 .WillOnce(Invoke(&RunClosure)); 269 .WillOnce(RunClosure());
272 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _)) 270 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _))
273 .WillOnce(Invoke(&RunPipelineStatusCB2)); 271 .WillOnce(RunPipelineStatusCB1());
274 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) 272 EXPECT_CALL(*mocks_->video_renderer(), Play(_))
275 .WillOnce(Invoke(&RunClosure)); 273 .WillOnce(RunClosure());
276 } 274 }
277 275
278 // We expect a successful seek callback. 276 // We expect a successful seek callback.
279 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); 277 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK));
280 } 278 }
281 279
282 void DoSeek(const base::TimeDelta& seek_time) { 280 void DoSeek(const base::TimeDelta& seek_time) {
283 pipeline_->Seek(seek_time, 281 pipeline_->Seek(seek_time,
284 base::Bind(&CallbackHelper::OnSeek, 282 base::Bind(&CallbackHelper::OnSeek,
285 base::Unretained(&callbacks_))); 283 base::Unretained(&callbacks_)));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 gfx::Size size(1, 1); 335 gfx::Size size(1, 1);
338 pipeline_->GetNaturalVideoSize(&size); 336 pipeline_->GetNaturalVideoSize(&size);
339 EXPECT_EQ(0, size.width()); 337 EXPECT_EQ(0, size.width());
340 EXPECT_EQ(0, size.height()); 338 EXPECT_EQ(0, size.height());
341 } 339 }
342 340
343 TEST_F(PipelineTest, NeverInitializes) { 341 TEST_F(PipelineTest, NeverInitializes) {
344 // Don't execute the callback passed into Initialize(). 342 // Don't execute the callback passed into Initialize().
345 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)); 343 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _));
346 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 344 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
347 .WillOnce(Invoke(&RunClosure)); 345 .WillOnce(RunClosure());
348 346
349 // This test hangs during initialization by never calling 347 // This test hangs during initialization by never calling
350 // InitializationComplete(). StrictMock<> will ensure that the callback is 348 // InitializationComplete(). StrictMock<> will ensure that the callback is
351 // never executed. 349 // never executed.
352 pipeline_->Start( 350 pipeline_->Start(
353 mocks_->Create().Pass(), 351 mocks_->Create().Pass(),
354 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 352 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
355 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 353 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
356 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 354 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)));
357 message_loop_.RunAllPending(); 355 message_loop_.RunAllPending();
(...skipping 17 matching lines...) Expand all
375 collection.Pass(), 373 collection.Pass(),
376 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 374 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
377 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 375 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
378 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 376 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)));
379 message_loop_.RunAllPending(); 377 message_loop_.RunAllPending();
380 EXPECT_FALSE(pipeline_->IsInitialized()); 378 EXPECT_FALSE(pipeline_->IsInitialized());
381 } 379 }
382 380
383 TEST_F(PipelineTest, URLNotFound) { 381 TEST_F(PipelineTest, URLNotFound) {
384 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) 382 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
385 .WillOnce(InitializeDemuxerWithError(PIPELINE_ERROR_URL_NOT_FOUND)); 383 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND));
386 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 384 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
387 .WillOnce(Invoke(&RunClosure)); 385 .WillOnce(RunClosure());
388 386
389 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); 387 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND);
390 EXPECT_FALSE(pipeline_->IsInitialized()); 388 EXPECT_FALSE(pipeline_->IsInitialized());
391 } 389 }
392 390
393 TEST_F(PipelineTest, NoStreams) { 391 TEST_F(PipelineTest, NoStreams) {
394 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) 392 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
395 .WillOnce(Invoke(&RunPipelineStatusCB2)); 393 .WillOnce(RunPipelineStatusCB1());
396 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 394 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
397 .WillOnce(Invoke(&RunClosure)); 395 .WillOnce(RunClosure());
398 396
399 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); 397 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER);
400 EXPECT_FALSE(pipeline_->IsInitialized()); 398 EXPECT_FALSE(pipeline_->IsInitialized());
401 } 399 }
402 400
403 TEST_F(PipelineTest, AudioStream) { 401 TEST_F(PipelineTest, AudioStream) {
404 CreateAudioStream(); 402 CreateAudioStream();
405 MockDemuxerStreamVector streams; 403 MockDemuxerStreamVector streams;
406 streams.push_back(audio_stream()); 404 streams.push_back(audio_stream());
407 405
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 InitializeAudioDecoder(audio_stream()); 569 InitializeAudioDecoder(audio_stream());
572 InitializeAudioRenderer(); 570 InitializeAudioRenderer();
573 InitializeVideoDecoder(video_stream()); 571 InitializeVideoDecoder(video_stream());
574 InitializeVideoRenderer(); 572 InitializeVideoRenderer();
575 573
576 InitializePipeline(PIPELINE_OK); 574 InitializePipeline(PIPELINE_OK);
577 EXPECT_TRUE(pipeline_->IsInitialized()); 575 EXPECT_TRUE(pipeline_->IsInitialized());
578 EXPECT_TRUE(pipeline_->HasAudio()); 576 EXPECT_TRUE(pipeline_->HasAudio());
579 EXPECT_TRUE(pipeline_->HasVideo()); 577 EXPECT_TRUE(pipeline_->HasVideo());
580 578
581 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(1.0f)) 579 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled());
582 .WillOnce(DisableAudioRenderer(pipeline_)); 580 pipeline_->OnAudioDisabled();
583 EXPECT_CALL(*mocks_->demuxer(), 581 message_loop_.RunAllPending();
acolwell GONE FROM CHROMIUM 2012/07/19 00:58:18 Why do you need to run the message_loop_ now?
scherkus (not reviewing) 2012/07/19 21:29:02 Turns out I don't need to! I thought we might hav
584 OnAudioRendererDisabled());
585
586 mocks_->audio_renderer()->SetPlaybackRate(1.0f);
587 582
588 // Verify that ended event is fired when video ends. 583 // Verify that ended event is fired when video ends.
589 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) 584 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
590 .WillOnce(Return(true)); 585 .WillOnce(Return(true));
591 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); 586 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK));
592 FilterHost* host = pipeline_; 587 FilterHost* host = pipeline_;
593 host->NotifyEnded(); 588 host->NotifyEnded();
594 } 589 }
595 590
596 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { 591 TEST_F(PipelineTest, DisableAudioRendererDuringInit) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 717
723 // Signal end of video stream and make sure OnEnded() callback occurs. 718 // Signal end of video stream and make sure OnEnded() callback occurs.
724 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) 719 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded())
725 .WillOnce(Return(true)); 720 .WillOnce(Return(true));
726 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) 721 EXPECT_CALL(*mocks_->video_renderer(), HasEnded())
727 .WillOnce(Return(true)); 722 .WillOnce(Return(true));
728 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); 723 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK));
729 host->NotifyEnded(); 724 host->NotifyEnded();
730 } 725 }
731 726
732 void SendReadErrorToCB(::testing::Unused, const PipelineStatusCB& cb) {
733 cb.Run(PIPELINE_ERROR_READ);
734 }
735
736 TEST_F(PipelineTest, ErrorDuringSeek) { 727 TEST_F(PipelineTest, ErrorDuringSeek) {
737 CreateAudioStream(); 728 CreateAudioStream();
738 MockDemuxerStreamVector streams; 729 MockDemuxerStreamVector streams;
739 streams.push_back(audio_stream()); 730 streams.push_back(audio_stream());
740 731
741 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); 732 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10));
742 InitializeAudioDecoder(audio_stream()); 733 InitializeAudioDecoder(audio_stream());
743 InitializeAudioRenderer(); 734 InitializeAudioRenderer();
744 InitializePipeline(PIPELINE_OK); 735 InitializePipeline(PIPELINE_OK);
745 736
746 float playback_rate = 1.0f; 737 float playback_rate = 1.0f;
747 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); 738 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate));
748 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); 739 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate));
749 pipeline_->SetPlaybackRate(playback_rate); 740 pipeline_->SetPlaybackRate(playback_rate);
750 message_loop_.RunAllPending(); 741 message_loop_.RunAllPending();
751 742
752 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 743 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
753 744
754 // Seek() isn't called as the demuxer errors out first. 745 // Seek() isn't called as the demuxer errors out first.
755 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 746 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
756 .WillOnce(Invoke(&RunClosure)); 747 .WillOnce(RunClosure());
757 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 748 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
758 .WillOnce(Invoke(&RunClosure)); 749 .WillOnce(RunClosure());
759 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) 750 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
760 .WillOnce(Invoke(&RunClosure)); 751 .WillOnce(RunClosure());
761 752
762 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) 753 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _))
763 .WillOnce(Invoke(&SendReadErrorToCB)); 754 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ));
764 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 755 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
765 .WillOnce(Invoke(&RunClosure)); 756 .WillOnce(RunClosure());
766 757
767 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, 758 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek,
768 base::Unretained(&callbacks_))); 759 base::Unretained(&callbacks_)));
769 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); 760 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ));
770 message_loop_.RunAllPending(); 761 message_loop_.RunAllPending();
771 } 762 }
772 763
773 // Invoked function OnError. This asserts that the pipeline does not enqueue 764 // Invoked function OnError. This asserts that the pipeline does not enqueue
774 // non-teardown related tasks while tearing down. 765 // non-teardown related tasks while tearing down.
775 static void TestNoCallsAfterError( 766 static void TestNoCallsAfterError(
(...skipping 26 matching lines...) Expand all
802 // Trigger additional requests on the pipeline during tear down from error. 793 // Trigger additional requests on the pipeline during tear down from error.
803 base::Callback<void(PipelineStatus)> cb = base::Bind( 794 base::Callback<void(PipelineStatus)> cb = base::Bind(
804 &TestNoCallsAfterError, pipeline_, &message_loop_); 795 &TestNoCallsAfterError, pipeline_, &message_loop_);
805 ON_CALL(callbacks_, OnError(_)) 796 ON_CALL(callbacks_, OnError(_))
806 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); 797 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run));
807 798
808 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 799 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
809 800
810 // Seek() isn't called as the demuxer errors out first. 801 // Seek() isn't called as the demuxer errors out first.
811 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 802 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
812 .WillOnce(Invoke(&RunClosure)); 803 .WillOnce(RunClosure());
813 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 804 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
814 .WillOnce(Invoke(&RunClosure)); 805 .WillOnce(RunClosure());
815 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) 806 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
816 .WillOnce(Invoke(&RunClosure)); 807 .WillOnce(RunClosure());
817 808
818 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) 809 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _))
819 .WillOnce(Invoke(&SendReadErrorToCB)); 810 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ));
820 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 811 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
821 .WillOnce(Invoke(&RunClosure)); 812 .WillOnce(RunClosure());
822 813
823 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, 814 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek,
824 base::Unretained(&callbacks_))); 815 base::Unretained(&callbacks_)));
825 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); 816 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ));
826 message_loop_.RunAllPending(); 817 message_loop_.RunAllPending();
827 } 818 }
828 819
829 TEST_F(PipelineTest, StartTimeIsZero) { 820 TEST_F(PipelineTest, StartTimeIsZero) {
830 CreateVideoStream(); 821 CreateVideoStream();
831 MockDemuxerStreamVector streams; 822 MockDemuxerStreamVector streams;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 base::TimeDelta::FromMilliseconds(500)); 887 base::TimeDelta::FromMilliseconds(500));
897 888
898 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 889 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
899 890
900 // Arrange to trigger a time update while the demuxer is in the middle of 891 // Arrange to trigger a time update while the demuxer is in the middle of
901 // seeking. This update should be ignored by the pipeline and the clock should 892 // seeking. This update should be ignored by the pipeline and the clock should
902 // not get updated. 893 // not get updated.
903 base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700); 894 base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700);
904 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) 895 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _))
905 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), 896 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run),
906 Invoke(&RunPipelineStatusCB2))); 897 RunPipelineStatusCB1()));
907 898
908 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 899 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
909 .WillOnce(Invoke(&RunClosure)); 900 .WillOnce(RunClosure());
910 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 901 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
911 .WillOnce(Invoke(&RunClosure)); 902 .WillOnce(RunClosure());
912 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) 903 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _))
913 .WillOnce(Invoke(&RunPipelineStatusCB2)); 904 .WillOnce(RunPipelineStatusCB1());
914 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) 905 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
915 .WillOnce(Invoke(&RunClosure)); 906 .WillOnce(RunClosure());
916 907
917 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); 908 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK));
918 DoSeek(seek_time); 909 DoSeek(seek_time);
919 910
920 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time); 911 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time);
921 912
922 // Now that the seek is complete, verify that time updates advance the current 913 // Now that the seek is complete, verify that time updates advance the current
923 // time. 914 // time.
924 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); 915 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100);
925 audio_time_cb_.Run(new_time, new_time); 916 audio_time_cb_.Run(new_time, new_time);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); 965 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0));
975 } 966 }
976 967
977 // Test that different-thread, some-delay callback (the expected common case) 968 // Test that different-thread, some-delay callback (the expected common case)
978 // works correctly. 969 // works correctly.
979 TEST(PipelineStatusNotificationTest, DelayedCallback) { 970 TEST(PipelineStatusNotificationTest, DelayedCallback) {
980 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); 971 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20));
981 } 972 }
982 973
983 } // namespace media 974 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698