OLD | NEW |
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 base::Unretained(&callbacks_))); | 115 base::Unretained(&callbacks_))); |
116 message_loop_.RunUntilIdle(); | 116 message_loop_.RunUntilIdle(); |
117 } | 117 } |
118 | 118 |
119 protected: | 119 protected: |
120 // Sets up expectations to allow the demuxer to initialize. | 120 // Sets up expectations to allow the demuxer to initialize. |
121 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 121 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
122 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 122 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
123 const base::TimeDelta& duration) { | 123 const base::TimeDelta& duration) { |
124 EXPECT_CALL(callbacks_, OnDurationChange()); | 124 EXPECT_CALL(callbacks_, OnDurationChange()); |
125 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 125 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
126 .WillOnce(DoAll(SetDemuxerProperties(duration), | 126 .WillOnce(DoAll(SetDemuxerProperties(duration), |
127 RunCallback<1>(PIPELINE_OK))); | 127 RunCallback<1>(PIPELINE_OK))); |
128 | 128 |
129 // Configure the demuxer to return the streams. | 129 // Configure the demuxer to return the streams. |
130 for (size_t i = 0; i < streams->size(); ++i) { | 130 for (size_t i = 0; i < streams->size(); ++i) { |
131 DemuxerStream* stream = (*streams)[i]; | 131 DemuxerStream* stream = (*streams)[i]; |
132 EXPECT_CALL(*demuxer_, GetStream(stream->type())) | 132 EXPECT_CALL(*demuxer_, GetStream(stream->type())) |
133 .WillRepeatedly(Return(stream)); | 133 .WillRepeatedly(Return(stream)); |
134 } | 134 } |
135 } | 135 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 // Should always get set to zero. | 332 // Should always get set to zero. |
333 gfx::Size size(1, 1); | 333 gfx::Size size(1, 1); |
334 pipeline_->GetNaturalVideoSize(&size); | 334 pipeline_->GetNaturalVideoSize(&size); |
335 EXPECT_EQ(0, size.width()); | 335 EXPECT_EQ(0, size.width()); |
336 EXPECT_EQ(0, size.height()); | 336 EXPECT_EQ(0, size.height()); |
337 } | 337 } |
338 | 338 |
339 TEST_F(PipelineTest, NeverInitializes) { | 339 TEST_F(PipelineTest, NeverInitializes) { |
340 // Don't execute the callback passed into Initialize(). | 340 // Don't execute the callback passed into Initialize(). |
341 EXPECT_CALL(*demuxer_, Initialize(_, _)); | 341 EXPECT_CALL(*demuxer_, Initialize(_, _, _)); |
342 | 342 |
343 // This test hangs during initialization by never calling | 343 // This test hangs during initialization by never calling |
344 // InitializationComplete(). StrictMock<> will ensure that the callback is | 344 // InitializationComplete(). StrictMock<> will ensure that the callback is |
345 // never executed. | 345 // never executed. |
346 pipeline_->Start( | 346 pipeline_->Start( |
347 filter_collection_.Pass(), | 347 filter_collection_.Pass(), |
348 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 348 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
349 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 349 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
350 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), | 350 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), |
351 base::Bind(&CallbackHelper::OnBufferingState, | 351 base::Bind(&CallbackHelper::OnBufferingState, |
352 base::Unretained(&callbacks_)), | 352 base::Unretained(&callbacks_)), |
353 base::Bind(&CallbackHelper::OnDurationChange, | 353 base::Bind(&CallbackHelper::OnDurationChange, |
354 base::Unretained(&callbacks_))); | 354 base::Unretained(&callbacks_))); |
355 message_loop_.RunUntilIdle(); | 355 message_loop_.RunUntilIdle(); |
356 | 356 |
357 | 357 |
358 // Because our callback will get executed when the test tears down, we'll | 358 // Because our callback will get executed when the test tears down, we'll |
359 // verify that nothing has been called, then set our expectation for the call | 359 // verify that nothing has been called, then set our expectation for the call |
360 // made during tear down. | 360 // made during tear down. |
361 Mock::VerifyAndClear(&callbacks_); | 361 Mock::VerifyAndClear(&callbacks_); |
362 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); | 362 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); |
363 } | 363 } |
364 | 364 |
365 TEST_F(PipelineTest, URLNotFound) { | 365 TEST_F(PipelineTest, URLNotFound) { |
366 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 366 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
367 .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND)); | 367 .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND)); |
368 EXPECT_CALL(*demuxer_, Stop(_)) | 368 EXPECT_CALL(*demuxer_, Stop(_)) |
369 .WillOnce(RunClosure<0>()); | 369 .WillOnce(RunClosure<0>()); |
370 | 370 |
371 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); | 371 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); |
372 } | 372 } |
373 | 373 |
374 TEST_F(PipelineTest, NoStreams) { | 374 TEST_F(PipelineTest, NoStreams) { |
375 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 375 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
376 .WillOnce(RunCallback<1>(PIPELINE_OK)); | 376 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
377 EXPECT_CALL(*demuxer_, Stop(_)) | 377 EXPECT_CALL(*demuxer_, Stop(_)) |
378 .WillOnce(RunClosure<0>()); | 378 .WillOnce(RunClosure<0>()); |
379 | 379 |
380 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); | 380 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); |
381 } | 381 } |
382 | 382 |
383 TEST_F(PipelineTest, AudioStream) { | 383 TEST_F(PipelineTest, AudioStream) { |
384 CreateAudioStream(); | 384 CreateAudioStream(); |
385 MockDemuxerStreamVector streams; | 385 MockDemuxerStreamVector streams; |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 } | 916 } |
917 | 917 |
918 PipelineStatus SetInitializeExpectations(TeardownState state, | 918 PipelineStatus SetInitializeExpectations(TeardownState state, |
919 StopOrError stop_or_error) { | 919 StopOrError stop_or_error) { |
920 PipelineStatus status = PIPELINE_OK; | 920 PipelineStatus status = PIPELINE_OK; |
921 base::Closure stop_cb = base::Bind( | 921 base::Closure stop_cb = base::Bind( |
922 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | 922 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
923 | 923 |
924 if (state == kInitDemuxer) { | 924 if (state == kInitDemuxer) { |
925 if (stop_or_error == kStop) { | 925 if (stop_or_error == kStop) { |
926 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 926 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
927 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), | 927 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), |
928 RunCallback<1>(PIPELINE_OK))); | 928 RunCallback<1>(PIPELINE_OK))); |
929 EXPECT_CALL(callbacks_, OnStop()); | 929 EXPECT_CALL(callbacks_, OnStop()); |
930 } else { | 930 } else { |
931 status = DEMUXER_ERROR_COULD_NOT_OPEN; | 931 status = DEMUXER_ERROR_COULD_NOT_OPEN; |
932 EXPECT_CALL(*demuxer_, Initialize(_, _)) | 932 EXPECT_CALL(*demuxer_, Initialize(_, _, _)) |
933 .WillOnce(RunCallback<1>(status)); | 933 .WillOnce(RunCallback<1>(status)); |
934 } | 934 } |
935 | 935 |
936 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>()); | 936 EXPECT_CALL(*demuxer_, Stop(_)).WillOnce(RunClosure<0>()); |
937 return status; | 937 return status; |
938 } | 938 } |
939 | 939 |
940 CreateAudioStream(); | 940 CreateAudioStream(); |
941 CreateVideoStream(); | 941 CreateVideoStream(); |
942 MockDemuxerStreamVector streams; | 942 MockDemuxerStreamVector streams; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1175 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
1176 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1176 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
1177 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1177 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
1178 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1178 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
1179 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1179 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
1180 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1180 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
1181 | 1181 |
1182 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); | 1182 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); |
1183 | 1183 |
1184 } // namespace media | 1184 } // namespace media |
OLD | NEW |