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

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

Issue 511323003: media: Remove FilterCollection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 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
« no previous file with comments | « media/base/pipeline.cc ('k') | media/base/run_all_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); 79 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState));
80 MOCK_METHOD0(OnDurationChange, void()); 80 MOCK_METHOD0(OnDurationChange, void());
81 81
82 private: 82 private:
83 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); 83 DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
84 }; 84 };
85 85
86 PipelineTest() 86 PipelineTest()
87 : pipeline_(new Pipeline(message_loop_.message_loop_proxy(), 87 : pipeline_(new Pipeline(message_loop_.message_loop_proxy(),
88 new MediaLog())), 88 new MediaLog())),
89 filter_collection_(new FilterCollection()), 89 demuxer_(new StrictMock<MockDemuxer>()),
90 demuxer_(new StrictMock<MockDemuxer>()) { 90 scoped_renderer_(new StrictMock<MockRenderer>()),
91 filter_collection_->SetDemuxer(demuxer_.get()); 91 renderer_(scoped_renderer_.get()) {
92
93 renderer_ = new StrictMock<MockRenderer>();
94 scoped_ptr<Renderer> renderer(renderer_);
95 filter_collection_->SetRenderer(renderer.Pass());
96
97 text_renderer_ = new TextRenderer(
98 message_loop_.message_loop_proxy(),
99 base::Bind(&PipelineTest::OnAddTextTrack,
100 base::Unretained(this)));
101 scoped_ptr<TextRenderer> text_renderer(text_renderer_);
102 filter_collection_->SetTextRenderer(text_renderer.Pass());
103
104 // SetDemuxerExpectations() adds overriding expectations for expected 92 // SetDemuxerExpectations() adds overriding expectations for expected
105 // non-NULL streams. 93 // non-NULL streams.
106 DemuxerStream* null_pointer = NULL; 94 DemuxerStream* null_pointer = NULL;
107 EXPECT_CALL(*demuxer_, GetStream(_)) 95 EXPECT_CALL(*demuxer_, GetStream(_))
108 .WillRepeatedly(Return(null_pointer)); 96 .WillRepeatedly(Return(null_pointer));
109 97
110 EXPECT_CALL(*demuxer_, GetTimelineOffset()) 98 EXPECT_CALL(*demuxer_, GetTimelineOffset())
111 .WillRepeatedly(Return(base::Time())); 99 .WillRepeatedly(Return(base::Time()));
112 100
113 EXPECT_CALL(*demuxer_, GetLiveness()) 101 EXPECT_CALL(*demuxer_, GetLiveness())
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 172 }
185 173
186 void AddTextStream() { 174 void AddTextStream() {
187 EXPECT_CALL(*this, OnAddTextTrack(_,_)) 175 EXPECT_CALL(*this, OnAddTextTrack(_,_))
188 .WillOnce(Invoke(this, &PipelineTest::DoOnAddTextTrack)); 176 .WillOnce(Invoke(this, &PipelineTest::DoOnAddTextTrack));
189 static_cast<DemuxerHost*>(pipeline_.get())->AddTextStream(text_stream(), 177 static_cast<DemuxerHost*>(pipeline_.get())->AddTextStream(text_stream(),
190 TextTrackConfig(kTextSubtitles, "", "", "")); 178 TextTrackConfig(kTextSubtitles, "", "", ""));
191 message_loop_.RunUntilIdle(); 179 message_loop_.RunUntilIdle();
192 } 180 }
193 181
182 void StartPipeline() {
183 pipeline_->Start(
184 demuxer_.get(),
185 scoped_renderer_.PassAs<Renderer>(),
186 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
187 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
188 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
189 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)),
190 base::Bind(&CallbackHelper::OnBufferingStateChange,
191 base::Unretained(&callbacks_)),
192 base::Bind(&CallbackHelper::OnDurationChange,
193 base::Unretained(&callbacks_)),
194 base::Bind(&PipelineTest::OnAddTextTrack, base::Unretained(this)));
195 }
196
194 // Sets up expectations on the callback and initializes the pipeline. Called 197 // Sets up expectations on the callback and initializes the pipeline. Called
195 // after tests have set expectations any filters they wish to use. 198 // after tests have set expectations any filters they wish to use.
196 void StartPipeline(PipelineStatus start_status) { 199 void StartPipelineAndExpect(PipelineStatus start_status) {
197 EXPECT_CALL(callbacks_, OnStart(start_status)); 200 EXPECT_CALL(callbacks_, OnStart(start_status));
198 201
199 if (start_status == PIPELINE_OK) { 202 if (start_status == PIPELINE_OK) {
200 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_)); 203 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_));
201 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0f)); 204 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0f));
202 EXPECT_CALL(*renderer_, SetVolume(1.0f)); 205 EXPECT_CALL(*renderer_, SetVolume(1.0f));
203 EXPECT_CALL(*renderer_, StartPlayingFrom(base::TimeDelta())) 206 EXPECT_CALL(*renderer_, StartPlayingFrom(base::TimeDelta()))
204 .WillOnce(SetBufferingState(&buffering_state_cb_, 207 .WillOnce(SetBufferingState(&buffering_state_cb_,
205 BUFFERING_HAVE_ENOUGH)); 208 BUFFERING_HAVE_ENOUGH));
206 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 209 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
207 } 210 }
208 211
209 pipeline_->Start( 212 StartPipeline();
210 filter_collection_.Pass(),
211 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
212 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
213 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
214 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)),
215 base::Bind(&CallbackHelper::OnBufferingStateChange,
216 base::Unretained(&callbacks_)),
217 base::Bind(&CallbackHelper::OnDurationChange,
218 base::Unretained(&callbacks_)));
219 message_loop_.RunUntilIdle(); 213 message_loop_.RunUntilIdle();
220 } 214 }
221 215
222 void CreateAudioStream() { 216 void CreateAudioStream() {
223 audio_stream_ = CreateStream(DemuxerStream::AUDIO); 217 audio_stream_ = CreateStream(DemuxerStream::AUDIO);
224 } 218 }
225 219
226 void CreateVideoStream() { 220 void CreateVideoStream() {
227 video_stream_ = CreateStream(DemuxerStream::VIDEO); 221 video_stream_ = CreateStream(DemuxerStream::VIDEO);
228 video_stream_->set_video_decoder_config(video_decoder_config_); 222 video_stream_->set_video_decoder_config(video_decoder_config_);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 scoped_ptr<TextTrack> text_track(new MockTextTrack); 294 scoped_ptr<TextTrack> text_track(new MockTextTrack);
301 done_cb.Run(text_track.Pass()); 295 done_cb.Run(text_track.Pass());
302 } 296 }
303 297
304 // Fixture members. 298 // Fixture members.
305 StrictMock<CallbackHelper> callbacks_; 299 StrictMock<CallbackHelper> callbacks_;
306 base::SimpleTestTickClock test_tick_clock_; 300 base::SimpleTestTickClock test_tick_clock_;
307 base::MessageLoop message_loop_; 301 base::MessageLoop message_loop_;
308 scoped_ptr<Pipeline> pipeline_; 302 scoped_ptr<Pipeline> pipeline_;
309 303
310 scoped_ptr<FilterCollection> filter_collection_;
311 scoped_ptr<StrictMock<MockDemuxer> > demuxer_; 304 scoped_ptr<StrictMock<MockDemuxer> > demuxer_;
305 scoped_ptr<StrictMock<MockRenderer> > scoped_renderer_;
312 StrictMock<MockRenderer>* renderer_; 306 StrictMock<MockRenderer>* renderer_;
313 StrictMock<CallbackHelper> text_renderer_callbacks_; 307 StrictMock<CallbackHelper> text_renderer_callbacks_;
314 TextRenderer* text_renderer_; 308 TextRenderer* text_renderer_;
315 scoped_ptr<StrictMock<MockDemuxerStream> > audio_stream_; 309 scoped_ptr<StrictMock<MockDemuxerStream> > audio_stream_;
316 scoped_ptr<StrictMock<MockDemuxerStream> > video_stream_; 310 scoped_ptr<StrictMock<MockDemuxerStream> > video_stream_;
317 scoped_ptr<FakeTextTrackStream> text_stream_; 311 scoped_ptr<FakeTextTrackStream> text_stream_;
318 BufferingStateCB buffering_state_cb_; 312 BufferingStateCB buffering_state_cb_;
319 base::Closure ended_cb_; 313 base::Closure ended_cb_;
320 VideoDecoderConfig video_decoder_config_; 314 VideoDecoderConfig video_decoder_config_;
321 PipelineMetadata metadata_; 315 PipelineMetadata metadata_;
(...skipping 28 matching lines...) Expand all
350 EXPECT_TRUE(kZero == pipeline_->GetMediaDuration()); 344 EXPECT_TRUE(kZero == pipeline_->GetMediaDuration());
351 } 345 }
352 346
353 TEST_F(PipelineTest, NeverInitializes) { 347 TEST_F(PipelineTest, NeverInitializes) {
354 // Don't execute the callback passed into Initialize(). 348 // Don't execute the callback passed into Initialize().
355 EXPECT_CALL(*demuxer_, Initialize(_, _, _)); 349 EXPECT_CALL(*demuxer_, Initialize(_, _, _));
356 350
357 // This test hangs during initialization by never calling 351 // This test hangs during initialization by never calling
358 // InitializationComplete(). StrictMock<> will ensure that the callback is 352 // InitializationComplete(). StrictMock<> will ensure that the callback is
359 // never executed. 353 // never executed.
360 pipeline_->Start( 354 StartPipeline();
361 filter_collection_.Pass(),
362 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
363 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
364 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
365 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)),
366 base::Bind(&CallbackHelper::OnBufferingStateChange,
367 base::Unretained(&callbacks_)),
368 base::Bind(&CallbackHelper::OnDurationChange,
369 base::Unretained(&callbacks_)));
370 message_loop_.RunUntilIdle(); 355 message_loop_.RunUntilIdle();
371 356
372 // Because our callback will get executed when the test tears down, we'll 357 // Because our callback will get executed when the test tears down, we'll
373 // verify that nothing has been called, then set our expectation for the call 358 // verify that nothing has been called, then set our expectation for the call
374 // made during tear down. 359 // made during tear down.
375 Mock::VerifyAndClear(&callbacks_); 360 Mock::VerifyAndClear(&callbacks_);
376 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); 361 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK));
377 } 362 }
378 363
379 TEST_F(PipelineTest, StopWithoutStart) { 364 TEST_F(PipelineTest, StopWithoutStart) {
380 ExpectPipelineStopAndDestroyPipeline(); 365 ExpectPipelineStopAndDestroyPipeline();
381 pipeline_->Stop( 366 pipeline_->Stop(
382 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); 367 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_)));
383 message_loop_.RunUntilIdle(); 368 message_loop_.RunUntilIdle();
384 } 369 }
385 370
386 TEST_F(PipelineTest, StartThenStopImmediately) { 371 TEST_F(PipelineTest, StartThenStopImmediately) {
387 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 372 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
388 .WillOnce(RunCallback<1>(PIPELINE_OK)); 373 .WillOnce(RunCallback<1>(PIPELINE_OK));
389 EXPECT_CALL(*demuxer_, Stop(_)) 374 EXPECT_CALL(*demuxer_, Stop(_))
390 .WillOnce(RunClosure<0>()); 375 .WillOnce(RunClosure<0>());
391 376
392 EXPECT_CALL(callbacks_, OnStart(_)); 377 EXPECT_CALL(callbacks_, OnStart(_));
393 378 StartPipeline();
394 pipeline_->Start(
395 filter_collection_.Pass(),
396 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
397 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
398 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
399 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)),
400 base::Bind(&CallbackHelper::OnBufferingStateChange,
401 base::Unretained(&callbacks_)),
402 base::Bind(&CallbackHelper::OnDurationChange,
403 base::Unretained(&callbacks_)));
404 379
405 // Expect a stop callback if we were started. 380 // Expect a stop callback if we were started.
406 ExpectPipelineStopAndDestroyPipeline(); 381 ExpectPipelineStopAndDestroyPipeline();
407 pipeline_->Stop( 382 pipeline_->Stop(
408 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); 383 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_)));
409 message_loop_.RunUntilIdle(); 384 message_loop_.RunUntilIdle();
410 } 385 }
411 386
412 TEST_F(PipelineTest, DemuxerErrorDuringStop) { 387 TEST_F(PipelineTest, DemuxerErrorDuringStop) {
413 CreateAudioStream(); 388 CreateAudioStream();
414 MockDemuxerStreamVector streams; 389 MockDemuxerStreamVector streams;
415 streams.push_back(audio_stream()); 390 streams.push_back(audio_stream());
416 391
417 SetDemuxerExpectations(&streams); 392 SetDemuxerExpectations(&streams);
418 SetRendererExpectations(); 393 SetRendererExpectations();
419 394
420 StartPipeline(PIPELINE_OK); 395 StartPipelineAndExpect(PIPELINE_OK);
421 396
422 EXPECT_CALL(*demuxer_, Stop(_)) 397 EXPECT_CALL(*demuxer_, Stop(_))
423 .WillOnce(DoAll(InvokeWithoutArgs(this, &PipelineTest::OnDemuxerError), 398 .WillOnce(DoAll(InvokeWithoutArgs(this, &PipelineTest::OnDemuxerError),
424 RunClosure<0>())); 399 RunClosure<0>()));
425 ExpectPipelineStopAndDestroyPipeline(); 400 ExpectPipelineStopAndDestroyPipeline();
426 401
427 pipeline_->Stop( 402 pipeline_->Stop(
428 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); 403 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_)));
429 message_loop_.RunUntilIdle(); 404 message_loop_.RunUntilIdle();
430 } 405 }
431 406
432 TEST_F(PipelineTest, URLNotFound) { 407 TEST_F(PipelineTest, URLNotFound) {
433 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 408 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
434 .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND)); 409 .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND));
435 EXPECT_CALL(*demuxer_, Stop(_)) 410 EXPECT_CALL(*demuxer_, Stop(_))
436 .WillOnce(RunClosure<0>()); 411 .WillOnce(RunClosure<0>());
437 412
438 StartPipeline(PIPELINE_ERROR_URL_NOT_FOUND); 413 StartPipelineAndExpect(PIPELINE_ERROR_URL_NOT_FOUND);
439 } 414 }
440 415
441 TEST_F(PipelineTest, NoStreams) { 416 TEST_F(PipelineTest, NoStreams) {
442 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) 417 EXPECT_CALL(*demuxer_, Initialize(_, _, _))
443 .WillOnce(RunCallback<1>(PIPELINE_OK)); 418 .WillOnce(RunCallback<1>(PIPELINE_OK));
444 EXPECT_CALL(*demuxer_, Stop(_)) 419 EXPECT_CALL(*demuxer_, Stop(_))
445 .WillOnce(RunClosure<0>()); 420 .WillOnce(RunClosure<0>());
446 421
447 StartPipeline(PIPELINE_ERROR_COULD_NOT_RENDER); 422 StartPipelineAndExpect(PIPELINE_ERROR_COULD_NOT_RENDER);
448 } 423 }
449 424
450 TEST_F(PipelineTest, AudioStream) { 425 TEST_F(PipelineTest, AudioStream) {
451 CreateAudioStream(); 426 CreateAudioStream();
452 MockDemuxerStreamVector streams; 427 MockDemuxerStreamVector streams;
453 streams.push_back(audio_stream()); 428 streams.push_back(audio_stream());
454 429
455 SetDemuxerExpectations(&streams); 430 SetDemuxerExpectations(&streams);
456 SetRendererExpectations(); 431 SetRendererExpectations();
457 432
458 StartPipeline(PIPELINE_OK); 433 StartPipelineAndExpect(PIPELINE_OK);
459 EXPECT_TRUE(metadata_.has_audio); 434 EXPECT_TRUE(metadata_.has_audio);
460 EXPECT_FALSE(metadata_.has_video); 435 EXPECT_FALSE(metadata_.has_video);
461 } 436 }
462 437
463 TEST_F(PipelineTest, VideoStream) { 438 TEST_F(PipelineTest, VideoStream) {
464 CreateVideoStream(); 439 CreateVideoStream();
465 MockDemuxerStreamVector streams; 440 MockDemuxerStreamVector streams;
466 streams.push_back(video_stream()); 441 streams.push_back(video_stream());
467 442
468 SetDemuxerExpectations(&streams); 443 SetDemuxerExpectations(&streams);
469 SetRendererExpectations(); 444 SetRendererExpectations();
470 445
471 StartPipeline(PIPELINE_OK); 446 StartPipelineAndExpect(PIPELINE_OK);
472 EXPECT_FALSE(metadata_.has_audio); 447 EXPECT_FALSE(metadata_.has_audio);
473 EXPECT_TRUE(metadata_.has_video); 448 EXPECT_TRUE(metadata_.has_video);
474 } 449 }
475 450
476 TEST_F(PipelineTest, AudioVideoStream) { 451 TEST_F(PipelineTest, AudioVideoStream) {
477 CreateAudioStream(); 452 CreateAudioStream();
478 CreateVideoStream(); 453 CreateVideoStream();
479 MockDemuxerStreamVector streams; 454 MockDemuxerStreamVector streams;
480 streams.push_back(audio_stream()); 455 streams.push_back(audio_stream());
481 streams.push_back(video_stream()); 456 streams.push_back(video_stream());
482 457
483 SetDemuxerExpectations(&streams); 458 SetDemuxerExpectations(&streams);
484 SetRendererExpectations(); 459 SetRendererExpectations();
485 460
486 StartPipeline(PIPELINE_OK); 461 StartPipelineAndExpect(PIPELINE_OK);
487 EXPECT_TRUE(metadata_.has_audio); 462 EXPECT_TRUE(metadata_.has_audio);
488 EXPECT_TRUE(metadata_.has_video); 463 EXPECT_TRUE(metadata_.has_video);
489 } 464 }
490 465
491 TEST_F(PipelineTest, VideoTextStream) { 466 TEST_F(PipelineTest, VideoTextStream) {
492 CreateVideoStream(); 467 CreateVideoStream();
493 CreateTextStream(); 468 CreateTextStream();
494 MockDemuxerStreamVector streams; 469 MockDemuxerStreamVector streams;
495 streams.push_back(video_stream()); 470 streams.push_back(video_stream());
496 471
497 SetDemuxerExpectations(&streams); 472 SetDemuxerExpectations(&streams);
498 SetRendererExpectations(); 473 SetRendererExpectations();
499 474
500 StartPipeline(PIPELINE_OK); 475 StartPipelineAndExpect(PIPELINE_OK);
501 EXPECT_FALSE(metadata_.has_audio); 476 EXPECT_FALSE(metadata_.has_audio);
502 EXPECT_TRUE(metadata_.has_video); 477 EXPECT_TRUE(metadata_.has_video);
503 478
504 AddTextStream(); 479 AddTextStream();
505 } 480 }
506 481
507 TEST_F(PipelineTest, VideoAudioTextStream) { 482 TEST_F(PipelineTest, VideoAudioTextStream) {
508 CreateVideoStream(); 483 CreateVideoStream();
509 CreateAudioStream(); 484 CreateAudioStream();
510 CreateTextStream(); 485 CreateTextStream();
511 MockDemuxerStreamVector streams; 486 MockDemuxerStreamVector streams;
512 streams.push_back(video_stream()); 487 streams.push_back(video_stream());
513 streams.push_back(audio_stream()); 488 streams.push_back(audio_stream());
514 489
515 SetDemuxerExpectations(&streams); 490 SetDemuxerExpectations(&streams);
516 SetRendererExpectations(); 491 SetRendererExpectations();
517 492
518 StartPipeline(PIPELINE_OK); 493 StartPipelineAndExpect(PIPELINE_OK);
519 EXPECT_TRUE(metadata_.has_audio); 494 EXPECT_TRUE(metadata_.has_audio);
520 EXPECT_TRUE(metadata_.has_video); 495 EXPECT_TRUE(metadata_.has_video);
521 496
522 AddTextStream(); 497 AddTextStream();
523 } 498 }
524 499
525 TEST_F(PipelineTest, Seek) { 500 TEST_F(PipelineTest, Seek) {
526 CreateAudioStream(); 501 CreateAudioStream();
527 CreateVideoStream(); 502 CreateVideoStream();
528 CreateTextStream(); 503 CreateTextStream();
529 MockDemuxerStreamVector streams; 504 MockDemuxerStreamVector streams;
530 streams.push_back(audio_stream()); 505 streams.push_back(audio_stream());
531 streams.push_back(video_stream()); 506 streams.push_back(video_stream());
532 507
533 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000)); 508 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000));
534 SetRendererExpectations(); 509 SetRendererExpectations();
535 510
536 // Initialize then seek! 511 // Initialize then seek!
537 StartPipeline(PIPELINE_OK); 512 StartPipelineAndExpect(PIPELINE_OK);
538 513
539 // Every filter should receive a call to Seek(). 514 // Every filter should receive a call to Seek().
540 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); 515 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000);
541 ExpectSeek(expected, false); 516 ExpectSeek(expected, false);
542 DoSeek(expected); 517 DoSeek(expected);
543 } 518 }
544 519
545 TEST_F(PipelineTest, SeekAfterError) { 520 TEST_F(PipelineTest, SeekAfterError) {
546 CreateAudioStream(); 521 CreateAudioStream();
547 MockDemuxerStreamVector streams; 522 MockDemuxerStreamVector streams;
548 streams.push_back(audio_stream()); 523 streams.push_back(audio_stream());
549 524
550 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000)); 525 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000));
551 SetRendererExpectations(); 526 SetRendererExpectations();
552 527
553 // Initialize then seek! 528 // Initialize then seek!
554 StartPipeline(PIPELINE_OK); 529 StartPipelineAndExpect(PIPELINE_OK);
555 530
556 EXPECT_CALL(*demuxer_, Stop(_)) 531 EXPECT_CALL(*demuxer_, Stop(_))
557 .WillOnce(RunClosure<0>()); 532 .WillOnce(RunClosure<0>());
558 EXPECT_CALL(callbacks_, OnError(_)); 533 EXPECT_CALL(callbacks_, OnError(_));
559 534
560 static_cast<DemuxerHost*>(pipeline_.get()) 535 static_cast<DemuxerHost*>(pipeline_.get())
561 ->OnDemuxerError(PIPELINE_ERROR_ABORT); 536 ->OnDemuxerError(PIPELINE_ERROR_ABORT);
562 message_loop_.RunUntilIdle(); 537 message_loop_.RunUntilIdle();
563 538
564 pipeline_->Seek( 539 pipeline_->Seek(
565 base::TimeDelta::FromMilliseconds(100), 540 base::TimeDelta::FromMilliseconds(100),
566 base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_))); 541 base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_)));
567 message_loop_.RunUntilIdle(); 542 message_loop_.RunUntilIdle();
568 } 543 }
569 544
570 TEST_F(PipelineTest, SetVolume) { 545 TEST_F(PipelineTest, SetVolume) {
571 CreateAudioStream(); 546 CreateAudioStream();
572 MockDemuxerStreamVector streams; 547 MockDemuxerStreamVector streams;
573 streams.push_back(audio_stream()); 548 streams.push_back(audio_stream());
574 549
575 SetDemuxerExpectations(&streams); 550 SetDemuxerExpectations(&streams);
576 SetRendererExpectations(); 551 SetRendererExpectations();
577 552
578 // The audio renderer should receive a call to SetVolume(). 553 // The audio renderer should receive a call to SetVolume().
579 float expected = 0.5f; 554 float expected = 0.5f;
580 EXPECT_CALL(*renderer_, SetVolume(expected)); 555 EXPECT_CALL(*renderer_, SetVolume(expected));
581 556
582 // Initialize then set volume! 557 // Initialize then set volume!
583 StartPipeline(PIPELINE_OK); 558 StartPipelineAndExpect(PIPELINE_OK);
584 pipeline_->SetVolume(expected); 559 pipeline_->SetVolume(expected);
585 } 560 }
586 561
587 TEST_F(PipelineTest, Properties) { 562 TEST_F(PipelineTest, Properties) {
588 CreateVideoStream(); 563 CreateVideoStream();
589 MockDemuxerStreamVector streams; 564 MockDemuxerStreamVector streams;
590 streams.push_back(video_stream()); 565 streams.push_back(video_stream());
591 566
592 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); 567 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
593 SetDemuxerExpectations(&streams, kDuration); 568 SetDemuxerExpectations(&streams, kDuration);
594 SetRendererExpectations(); 569 SetRendererExpectations();
595 570
596 StartPipeline(PIPELINE_OK); 571 StartPipelineAndExpect(PIPELINE_OK);
597 EXPECT_EQ(kDuration.ToInternalValue(), 572 EXPECT_EQ(kDuration.ToInternalValue(),
598 pipeline_->GetMediaDuration().ToInternalValue()); 573 pipeline_->GetMediaDuration().ToInternalValue());
599 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 574 EXPECT_FALSE(pipeline_->DidLoadingProgress());
600 } 575 }
601 576
602 TEST_F(PipelineTest, GetBufferedTimeRanges) { 577 TEST_F(PipelineTest, GetBufferedTimeRanges) {
603 CreateVideoStream(); 578 CreateVideoStream();
604 MockDemuxerStreamVector streams; 579 MockDemuxerStreamVector streams;
605 streams.push_back(video_stream()); 580 streams.push_back(video_stream());
606 581
607 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); 582 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
608 SetDemuxerExpectations(&streams, kDuration); 583 SetDemuxerExpectations(&streams, kDuration);
609 SetRendererExpectations(); 584 SetRendererExpectations();
610 585
611 StartPipeline(PIPELINE_OK); 586 StartPipelineAndExpect(PIPELINE_OK);
612 587
613 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); 588 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size());
614 589
615 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 590 EXPECT_FALSE(pipeline_->DidLoadingProgress());
616 pipeline_->AddBufferedTimeRange(base::TimeDelta(), kDuration / 8); 591 pipeline_->AddBufferedTimeRange(base::TimeDelta(), kDuration / 8);
617 EXPECT_TRUE(pipeline_->DidLoadingProgress()); 592 EXPECT_TRUE(pipeline_->DidLoadingProgress());
618 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 593 EXPECT_FALSE(pipeline_->DidLoadingProgress());
619 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); 594 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
620 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); 595 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0));
621 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); 596 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0));
622 597
623 base::TimeDelta kSeekTime = kDuration / 2; 598 base::TimeDelta kSeekTime = kDuration / 2;
624 ExpectSeek(kSeekTime, false); 599 ExpectSeek(kSeekTime, false);
625 DoSeek(kSeekTime); 600 DoSeek(kSeekTime);
626 601
627 EXPECT_FALSE(pipeline_->DidLoadingProgress()); 602 EXPECT_FALSE(pipeline_->DidLoadingProgress());
628 } 603 }
629 604
630 TEST_F(PipelineTest, EndedCallback) { 605 TEST_F(PipelineTest, EndedCallback) {
631 CreateAudioStream(); 606 CreateAudioStream();
632 CreateVideoStream(); 607 CreateVideoStream();
633 CreateTextStream(); 608 CreateTextStream();
634 MockDemuxerStreamVector streams; 609 MockDemuxerStreamVector streams;
635 streams.push_back(audio_stream()); 610 streams.push_back(audio_stream());
636 streams.push_back(video_stream()); 611 streams.push_back(video_stream());
637 612
638 SetDemuxerExpectations(&streams); 613 SetDemuxerExpectations(&streams);
639 SetRendererExpectations(); 614 SetRendererExpectations();
640 StartPipeline(PIPELINE_OK); 615 StartPipelineAndExpect(PIPELINE_OK);
641 616
642 AddTextStream(); 617 AddTextStream();
643 618
644 // The ended callback shouldn't run until all renderers have ended. 619 // The ended callback shouldn't run until all renderers have ended.
645 ended_cb_.Run(); 620 ended_cb_.Run();
646 message_loop_.RunUntilIdle(); 621 message_loop_.RunUntilIdle();
647 622
648 EXPECT_CALL(callbacks_, OnEnded()); 623 EXPECT_CALL(callbacks_, OnEnded());
649 text_stream()->SendEosNotification(); 624 text_stream()->SendEosNotification();
650 message_loop_.RunUntilIdle(); 625 message_loop_.RunUntilIdle();
651 } 626 }
652 627
653 TEST_F(PipelineTest, ErrorDuringSeek) { 628 TEST_F(PipelineTest, ErrorDuringSeek) {
654 CreateAudioStream(); 629 CreateAudioStream();
655 MockDemuxerStreamVector streams; 630 MockDemuxerStreamVector streams;
656 streams.push_back(audio_stream()); 631 streams.push_back(audio_stream());
657 632
658 SetDemuxerExpectations(&streams); 633 SetDemuxerExpectations(&streams);
659 SetRendererExpectations(); 634 SetRendererExpectations();
660 StartPipeline(PIPELINE_OK); 635 StartPipelineAndExpect(PIPELINE_OK);
661 636
662 float playback_rate = 1.0f; 637 float playback_rate = 1.0f;
663 EXPECT_CALL(*renderer_, SetPlaybackRate(playback_rate)); 638 EXPECT_CALL(*renderer_, SetPlaybackRate(playback_rate));
664 pipeline_->SetPlaybackRate(playback_rate); 639 pipeline_->SetPlaybackRate(playback_rate);
665 message_loop_.RunUntilIdle(); 640 message_loop_.RunUntilIdle();
666 641
667 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 642 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
668 643
669 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 644 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
670 EXPECT_CALL(*renderer_, Flush(_)) 645 EXPECT_CALL(*renderer_, Flush(_))
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 EXPECT_TRUE(message_loop->IsIdleForTesting()); 677 EXPECT_TRUE(message_loop->IsIdleForTesting());
703 } 678 }
704 679
705 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { 680 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) {
706 CreateAudioStream(); 681 CreateAudioStream();
707 MockDemuxerStreamVector streams; 682 MockDemuxerStreamVector streams;
708 streams.push_back(audio_stream()); 683 streams.push_back(audio_stream());
709 684
710 SetDemuxerExpectations(&streams); 685 SetDemuxerExpectations(&streams);
711 SetRendererExpectations(); 686 SetRendererExpectations();
712 StartPipeline(PIPELINE_OK); 687 StartPipelineAndExpect(PIPELINE_OK);
713 688
714 // Trigger additional requests on the pipeline during tear down from error. 689 // Trigger additional requests on the pipeline during tear down from error.
715 base::Callback<void(PipelineStatus)> cb = base::Bind( 690 base::Callback<void(PipelineStatus)> cb = base::Bind(
716 &TestNoCallsAfterError, pipeline_.get(), &message_loop_); 691 &TestNoCallsAfterError, pipeline_.get(), &message_loop_);
717 ON_CALL(callbacks_, OnError(_)) 692 ON_CALL(callbacks_, OnError(_))
718 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); 693 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run));
719 694
720 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); 695 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5);
721 696
722 // Seek() isn't called as the demuxer errors out first. 697 // Seek() isn't called as the demuxer errors out first.
(...skipping 13 matching lines...) Expand all
736 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); 711 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ));
737 message_loop_.RunUntilIdle(); 712 message_loop_.RunUntilIdle();
738 } 713 }
739 714
740 TEST_F(PipelineTest, DestroyAfterStop) { 715 TEST_F(PipelineTest, DestroyAfterStop) {
741 CreateAudioStream(); 716 CreateAudioStream();
742 MockDemuxerStreamVector streams; 717 MockDemuxerStreamVector streams;
743 streams.push_back(audio_stream()); 718 streams.push_back(audio_stream());
744 SetDemuxerExpectations(&streams); 719 SetDemuxerExpectations(&streams);
745 SetRendererExpectations(); 720 SetRendererExpectations();
746 StartPipeline(PIPELINE_OK); 721 StartPipelineAndExpect(PIPELINE_OK);
747 722
748 ExpectDemuxerStop(); 723 ExpectDemuxerStop();
749 724
750 ExpectPipelineStopAndDestroyPipeline(); 725 ExpectPipelineStopAndDestroyPipeline();
751 pipeline_->Stop( 726 pipeline_->Stop(
752 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_))); 727 base::Bind(&CallbackHelper::OnStop, base::Unretained(&callbacks_)));
753 message_loop_.RunUntilIdle(); 728 message_loop_.RunUntilIdle();
754 } 729 }
755 730
756 TEST_F(PipelineTest, Underflow) { 731 TEST_F(PipelineTest, Underflow) {
757 CreateAudioStream(); 732 CreateAudioStream();
758 CreateVideoStream(); 733 CreateVideoStream();
759 MockDemuxerStreamVector streams; 734 MockDemuxerStreamVector streams;
760 streams.push_back(audio_stream()); 735 streams.push_back(audio_stream());
761 streams.push_back(video_stream()); 736 streams.push_back(video_stream());
762 737
763 SetDemuxerExpectations(&streams); 738 SetDemuxerExpectations(&streams);
764 SetRendererExpectations(); 739 SetRendererExpectations();
765 StartPipeline(PIPELINE_OK); 740 StartPipelineAndExpect(PIPELINE_OK);
766 741
767 // Simulate underflow. 742 // Simulate underflow.
768 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); 743 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING));
769 buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); 744 buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING);
770 745
771 // Seek while underflowed. 746 // Seek while underflowed.
772 base::TimeDelta expected = base::TimeDelta::FromSeconds(5); 747 base::TimeDelta expected = base::TimeDelta::FromSeconds(5);
773 ExpectSeek(expected, true); 748 ExpectSeek(expected, true);
774 DoSeek(expected); 749 DoSeek(expected);
775 } 750 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 790
816 private: 791 private:
817 // TODO(scherkus): We do radically different things whether teardown is 792 // TODO(scherkus): We do radically different things whether teardown is
818 // invoked via stop vs error. The teardown path should be the same, 793 // invoked via stop vs error. The teardown path should be the same,
819 // see http://crbug.com/110228 794 // see http://crbug.com/110228
820 void DoInitialize(TeardownState state, StopOrError stop_or_error) { 795 void DoInitialize(TeardownState state, StopOrError stop_or_error) {
821 PipelineStatus expected_status = 796 PipelineStatus expected_status =
822 SetInitializeExpectations(state, stop_or_error); 797 SetInitializeExpectations(state, stop_or_error);
823 798
824 EXPECT_CALL(callbacks_, OnStart(expected_status)); 799 EXPECT_CALL(callbacks_, OnStart(expected_status));
825 pipeline_->Start( 800 StartPipeline();
826 filter_collection_.Pass(),
827 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
828 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
829 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
830 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)),
831 base::Bind(&CallbackHelper::OnBufferingStateChange,
832 base::Unretained(&callbacks_)),
833 base::Bind(&CallbackHelper::OnDurationChange,
834 base::Unretained(&callbacks_)));
835 message_loop_.RunUntilIdle(); 801 message_loop_.RunUntilIdle();
836 } 802 }
837 803
838 PipelineStatus SetInitializeExpectations(TeardownState state, 804 PipelineStatus SetInitializeExpectations(TeardownState state,
839 StopOrError stop_or_error) { 805 StopOrError stop_or_error) {
840 PipelineStatus status = PIPELINE_OK; 806 PipelineStatus status = PIPELINE_OK;
841 base::Closure stop_cb = base::Bind( 807 base::Closure stop_cb = base::Bind(
842 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); 808 &CallbackHelper::OnStop, base::Unretained(&callbacks_));
843 809
844 if (state == kInitDemuxer) { 810 if (state == kInitDemuxer) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 980
1015 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); 981 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer);
1016 INSTANTIATE_TEARDOWN_TEST(Error, InitRenderer); 982 INSTANTIATE_TEARDOWN_TEST(Error, InitRenderer);
1017 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 983 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1018 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 984 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1019 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 985 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1020 986
1021 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); 987 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing);
1022 988
1023 } // namespace media 989 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | media/base/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698