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.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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 class CallbackHelper { | 55 class CallbackHelper { |
56 public: | 56 public: |
57 CallbackHelper() {} | 57 CallbackHelper() {} |
58 virtual ~CallbackHelper() {} | 58 virtual ~CallbackHelper() {} |
59 | 59 |
60 MOCK_METHOD1(OnStart, void(PipelineStatus)); | 60 MOCK_METHOD1(OnStart, void(PipelineStatus)); |
61 MOCK_METHOD1(OnSeek, void(PipelineStatus)); | 61 MOCK_METHOD1(OnSeek, void(PipelineStatus)); |
62 MOCK_METHOD0(OnStop, void()); | 62 MOCK_METHOD0(OnStop, void()); |
63 MOCK_METHOD1(OnEnded, void(PipelineStatus)); | 63 MOCK_METHOD1(OnEnded, void(PipelineStatus)); |
64 MOCK_METHOD1(OnError, void(PipelineStatus)); | 64 MOCK_METHOD1(OnError, void(PipelineStatus)); |
| 65 MOCK_METHOD0(OnNewDuration, void()); |
65 | 66 |
66 private: | 67 private: |
67 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 68 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
68 }; | 69 }; |
69 | 70 |
70 // TODO(scherkus): even though some filters are initialized on separate | 71 // TODO(scherkus): even though some filters are initialized on separate |
71 // threads these test aren't flaky... why? It's because filters' Initialize() | 72 // threads these test aren't flaky... why? It's because filters' Initialize() |
72 // is executed on |message_loop_| and the mock filters instantly call | 73 // is executed on |message_loop_| and the mock filters instantly call |
73 // InitializationComplete(), which keeps the pipeline humming along. If | 74 // InitializationComplete(), which keeps the pipeline humming along. If |
74 // either filters don't call InitializationComplete() immediately or filter | 75 // either filters don't call InitializationComplete() immediately or filter |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) | 215 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) |
215 .WillOnce(RunPipelineStatusCB1()); | 216 .WillOnce(RunPipelineStatusCB1()); |
216 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 217 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
217 .WillOnce(RunClosure()); | 218 .WillOnce(RunClosure()); |
218 } | 219 } |
219 | 220 |
220 // Sets up expectations on the callback and initializes the pipeline. Called | 221 // Sets up expectations on the callback and initializes the pipeline. Called |
221 // after tests have set expectations any filters they wish to use. | 222 // after tests have set expectations any filters they wish to use. |
222 void InitializePipeline(PipelineStatus start_status) { | 223 void InitializePipeline(PipelineStatus start_status) { |
223 EXPECT_CALL(callbacks_, OnStart(start_status)); | 224 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 225 if (start_status == PIPELINE_OK) |
| 226 EXPECT_CALL(callbacks_, OnNewDuration()); |
224 | 227 |
225 pipeline_->Start( | 228 pipeline_->Start( |
226 mocks_->Create().Pass(), | 229 mocks_->Create().Pass(), |
227 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 230 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
228 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 231 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
229 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 232 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), |
| 233 base::Bind(&CallbackHelper::OnNewDuration, |
| 234 base::Unretained(&callbacks_))); |
230 message_loop_.RunAllPending(); | 235 message_loop_.RunAllPending(); |
231 } | 236 } |
232 | 237 |
233 void CreateAudioStream() { | 238 void CreateAudioStream() { |
234 audio_stream_ = CreateStream(DemuxerStream::AUDIO); | 239 audio_stream_ = CreateStream(DemuxerStream::AUDIO); |
235 } | 240 } |
236 | 241 |
237 void CreateVideoStream() { | 242 void CreateVideoStream() { |
238 video_stream_ = CreateStream(DemuxerStream::VIDEO); | 243 video_stream_ = CreateStream(DemuxerStream::VIDEO); |
239 } | 244 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 349 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
345 .WillOnce(RunClosure()); | 350 .WillOnce(RunClosure()); |
346 | 351 |
347 // This test hangs during initialization by never calling | 352 // This test hangs during initialization by never calling |
348 // InitializationComplete(). StrictMock<> will ensure that the callback is | 353 // InitializationComplete(). StrictMock<> will ensure that the callback is |
349 // never executed. | 354 // never executed. |
350 pipeline_->Start( | 355 pipeline_->Start( |
351 mocks_->Create().Pass(), | 356 mocks_->Create().Pass(), |
352 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 357 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
353 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 358 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
354 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 359 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), |
| 360 base::Bind(&CallbackHelper::OnNewDuration, |
| 361 base::Unretained(&callbacks_))); |
355 message_loop_.RunAllPending(); | 362 message_loop_.RunAllPending(); |
356 | 363 |
357 EXPECT_FALSE(pipeline_->IsInitialized()); | 364 EXPECT_FALSE(pipeline_->IsInitialized()); |
358 | 365 |
359 // Because our callback will get executed when the test tears down, we'll | 366 // Because our callback will get executed when the test tears down, we'll |
360 // verify that nothing has been called, then set our expectation for the call | 367 // verify that nothing has been called, then set our expectation for the call |
361 // made during tear down. | 368 // made during tear down. |
362 Mock::VerifyAndClear(&callbacks_); | 369 Mock::VerifyAndClear(&callbacks_); |
363 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); | 370 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); |
364 } | 371 } |
365 | 372 |
366 TEST_F(PipelineTest, RequiredFilterMissing) { | 373 TEST_F(PipelineTest, RequiredFilterMissing) { |
367 // Create a filter collection with missing filter. | 374 // Create a filter collection with missing filter. |
368 scoped_ptr<FilterCollection> collection(mocks_->Create()); | 375 scoped_ptr<FilterCollection> collection(mocks_->Create()); |
369 collection->SetDemuxer(NULL); | 376 collection->SetDemuxer(NULL); |
370 | 377 |
371 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); | 378 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); |
372 pipeline_->Start( | 379 pipeline_->Start( |
373 collection.Pass(), | 380 collection.Pass(), |
374 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 381 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
375 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 382 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
376 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 383 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), |
| 384 base::Bind(&CallbackHelper::OnNewDuration, |
| 385 base::Unretained(&callbacks_))); |
377 message_loop_.RunAllPending(); | 386 message_loop_.RunAllPending(); |
378 EXPECT_FALSE(pipeline_->IsInitialized()); | 387 EXPECT_FALSE(pipeline_->IsInitialized()); |
379 } | 388 } |
380 | 389 |
381 TEST_F(PipelineTest, URLNotFound) { | 390 TEST_F(PipelineTest, URLNotFound) { |
382 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 391 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
383 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); | 392 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); |
384 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 393 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
385 .WillOnce(RunClosure()); | 394 .WillOnce(RunClosure()); |
386 | 395 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 965 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
957 } | 966 } |
958 | 967 |
959 // Test that different-thread, some-delay callback (the expected common case) | 968 // Test that different-thread, some-delay callback (the expected common case) |
960 // works correctly. | 969 // works correctly. |
961 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 970 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
962 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 971 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
963 } | 972 } |
964 | 973 |
965 } // namespace media | 974 } // namespace media |
OLD | NEW |