OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 public: | 42 public: |
43 CallbackHelper() {} | 43 CallbackHelper() {} |
44 virtual ~CallbackHelper() {} | 44 virtual ~CallbackHelper() {} |
45 | 45 |
46 MOCK_METHOD1(OnInitialize, void(PipelineStatus)); | 46 MOCK_METHOD1(OnInitialize, void(PipelineStatus)); |
47 MOCK_METHOD0(OnFlushed, void()); | 47 MOCK_METHOD0(OnFlushed, void()); |
48 MOCK_METHOD0(OnEnded, void()); | 48 MOCK_METHOD0(OnEnded, void()); |
49 MOCK_METHOD1(OnError, void(PipelineStatus)); | 49 MOCK_METHOD1(OnError, void(PipelineStatus)); |
50 MOCK_METHOD1(OnUpdateStatistics, void(const PipelineStatistics&)); | 50 MOCK_METHOD1(OnUpdateStatistics, void(const PipelineStatistics&)); |
51 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); | 51 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState)); |
| 52 MOCK_METHOD1(OnVideoFramePaint, void(const scoped_refptr<VideoFrame>&)); |
52 MOCK_METHOD0(OnWaitingForDecryptionKey, void()); | 53 MOCK_METHOD0(OnWaitingForDecryptionKey, void()); |
53 | 54 |
54 private: | 55 private: |
55 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 56 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
56 }; | 57 }; |
57 | 58 |
58 RendererImplTest() | 59 RendererImplTest() |
59 : demuxer_(new StrictMock<MockDemuxer>()), | 60 : demuxer_(new StrictMock<MockDemuxer>()), |
60 video_renderer_(new StrictMock<MockVideoRenderer>()), | 61 video_renderer_(new StrictMock<MockVideoRenderer>()), |
61 audio_renderer_(new StrictMock<MockAudioRenderer>()), | 62 audio_renderer_(new StrictMock<MockAudioRenderer>()), |
(...skipping 28 matching lines...) Expand all Loading... |
90 EXPECT_CALL(*audio_renderer_, | 91 EXPECT_CALL(*audio_renderer_, |
91 Initialize(audio_stream_.get(), _, _, _, _, _, _, _)) | 92 Initialize(audio_stream_.get(), _, _, _, _, _, _, _)) |
92 .WillOnce(DoAll(SaveArg<4>(&audio_buffering_state_cb_), | 93 .WillOnce(DoAll(SaveArg<4>(&audio_buffering_state_cb_), |
93 SaveArg<5>(&audio_ended_cb_), | 94 SaveArg<5>(&audio_ended_cb_), |
94 SaveArg<6>(&audio_error_cb_), RunCallback<1>(status))); | 95 SaveArg<6>(&audio_error_cb_), RunCallback<1>(status))); |
95 } | 96 } |
96 | 97 |
97 // Sets up expectations to allow the video renderer to initialize. | 98 // Sets up expectations to allow the video renderer to initialize. |
98 void SetVideoRendererInitializeExpectations(PipelineStatus status) { | 99 void SetVideoRendererInitializeExpectations(PipelineStatus status) { |
99 EXPECT_CALL(*video_renderer_, | 100 EXPECT_CALL(*video_renderer_, |
100 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _)) | 101 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _, _)) |
101 .WillOnce(DoAll(SaveArg<4>(&video_buffering_state_cb_), | 102 .WillOnce(DoAll(SaveArg<4>(&video_buffering_state_cb_), |
102 SaveArg<5>(&video_ended_cb_), RunCallback<1>(status))); | 103 SaveArg<6>(&video_ended_cb_), RunCallback<1>(status))); |
103 } | 104 } |
104 | 105 |
105 void InitializeAndExpect(PipelineStatus start_status) { | 106 void InitializeAndExpect(PipelineStatus start_status) { |
106 EXPECT_CALL(callbacks_, OnInitialize(start_status)); | 107 EXPECT_CALL(callbacks_, OnInitialize(start_status)); |
107 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0); | 108 EXPECT_CALL(callbacks_, OnWaitingForDecryptionKey()).Times(0); |
108 | 109 |
109 if (start_status == PIPELINE_OK && audio_stream_) { | 110 if (start_status == PIPELINE_OK && audio_stream_) { |
110 EXPECT_CALL(*audio_renderer_, GetTimeSource()) | 111 EXPECT_CALL(*audio_renderer_, GetTimeSource()) |
111 .WillOnce(Return(&time_source_)); | 112 .WillOnce(Return(&time_source_)); |
112 } else { | 113 } else { |
113 renderer_impl_->set_time_source_for_testing(&time_source_); | 114 renderer_impl_->set_time_source_for_testing(&time_source_); |
114 } | 115 } |
115 | 116 |
116 renderer_impl_->Initialize( | 117 renderer_impl_->Initialize( |
117 demuxer_.get(), | 118 demuxer_.get(), |
118 base::Bind(&CallbackHelper::OnInitialize, | 119 base::Bind(&CallbackHelper::OnInitialize, |
119 base::Unretained(&callbacks_)), | 120 base::Unretained(&callbacks_)), |
120 base::Bind(&CallbackHelper::OnUpdateStatistics, | 121 base::Bind(&CallbackHelper::OnUpdateStatistics, |
121 base::Unretained(&callbacks_)), | 122 base::Unretained(&callbacks_)), |
122 base::Bind(&CallbackHelper::OnBufferingStateChange, | 123 base::Bind(&CallbackHelper::OnBufferingStateChange, |
123 base::Unretained(&callbacks_)), | 124 base::Unretained(&callbacks_)), |
| 125 base::Bind(&CallbackHelper::OnVideoFramePaint, |
| 126 base::Unretained(&callbacks_)), |
124 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 127 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
125 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 128 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
126 base::Bind(&CallbackHelper::OnWaitingForDecryptionKey, | 129 base::Bind(&CallbackHelper::OnWaitingForDecryptionKey, |
127 base::Unretained(&callbacks_))); | 130 base::Unretained(&callbacks_))); |
128 base::RunLoop().RunUntilIdle(); | 131 base::RunLoop().RunUntilIdle(); |
129 } | 132 } |
130 | 133 |
131 void CreateAudioStream() { | 134 void CreateAudioStream() { |
132 audio_stream_ = CreateStream(DemuxerStream::AUDIO); | 135 audio_stream_ = CreateStream(DemuxerStream::AUDIO); |
133 streams_.push_back(audio_stream_.get()); | 136 streams_.push_back(audio_stream_.get()); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 audio_error_cb_.Run(PIPELINE_ERROR_DECODE); | 468 audio_error_cb_.Run(PIPELINE_ERROR_DECODE); |
466 base::RunLoop().RunUntilIdle(); | 469 base::RunLoop().RunUntilIdle(); |
467 } | 470 } |
468 | 471 |
469 TEST_F(RendererImplTest, ErrorDuringInitialize) { | 472 TEST_F(RendererImplTest, ErrorDuringInitialize) { |
470 CreateAudioAndVideoStream(); | 473 CreateAudioAndVideoStream(); |
471 SetAudioRendererInitializeExpectations(PIPELINE_OK); | 474 SetAudioRendererInitializeExpectations(PIPELINE_OK); |
472 | 475 |
473 // Force an audio error to occur during video renderer initialization. | 476 // Force an audio error to occur during video renderer initialization. |
474 EXPECT_CALL(*video_renderer_, | 477 EXPECT_CALL(*video_renderer_, |
475 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _)) | 478 Initialize(video_stream_.get(), _, _, _, _, _, _, _, _, _)) |
476 .WillOnce(DoAll(AudioError(&audio_error_cb_, PIPELINE_ERROR_DECODE), | 479 .WillOnce(DoAll(AudioError(&audio_error_cb_, PIPELINE_ERROR_DECODE), |
477 SaveArg<4>(&video_buffering_state_cb_), | 480 SaveArg<4>(&video_buffering_state_cb_), |
478 SaveArg<5>(&video_ended_cb_), | 481 SaveArg<6>(&video_ended_cb_), |
479 RunCallback<1>(PIPELINE_OK))); | 482 RunCallback<1>(PIPELINE_OK))); |
480 | 483 |
481 InitializeAndExpect(PIPELINE_ERROR_DECODE); | 484 InitializeAndExpect(PIPELINE_ERROR_DECODE); |
482 } | 485 } |
483 | 486 |
484 TEST_F(RendererImplTest, AudioUnderflow) { | 487 TEST_F(RendererImplTest, AudioUnderflow) { |
485 InitializeWithAudio(); | 488 InitializeWithAudio(); |
486 Play(); | 489 Play(); |
487 | 490 |
488 // Underflow should occur immediately with a single audio track. | 491 // Underflow should occur immediately with a single audio track. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 Mock::VerifyAndClearExpectations(&time_source_); | 561 Mock::VerifyAndClearExpectations(&time_source_); |
559 | 562 |
560 EXPECT_CALL(time_source_, StopTicking()); | 563 EXPECT_CALL(time_source_, StopTicking()); |
561 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); | 564 audio_buffering_state_cb_.Run(BUFFERING_HAVE_NOTHING); |
562 | 565 |
563 // Nothing else should primed on the message loop. | 566 // Nothing else should primed on the message loop. |
564 base::RunLoop().RunUntilIdle(); | 567 base::RunLoop().RunUntilIdle(); |
565 } | 568 } |
566 | 569 |
567 } // namespace media | 570 } // namespace media |
OLD | NEW |