| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/waitable_event.h" | 7 #include "base/waitable_event.h" |
| 8 #include "media/base/pipeline_impl.h" | 8 #include "media/base/pipeline_impl.h" |
| 9 #include "media/base/media_format.h" | 9 #include "media/base/media_format.h" |
| 10 #include "media/base/filters.h" | 10 #include "media/base/filters.h" |
| 11 #include "media/base/factory.h" | 11 #include "media/base/factory.h" |
| 12 #include "media/base/filter_host.h" | 12 #include "media/base/filter_host.h" |
| 13 #include "media/base/mock_filters.h" | 13 #include "media/base/mock_filters.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using ::testing::DoAll; | 16 using ::testing::DoAll; |
| 17 using ::testing::InSequence; |
| 17 using ::testing::Invoke; | 18 using ::testing::Invoke; |
| 18 using ::testing::Mock; | 19 using ::testing::Mock; |
| 19 using ::testing::NotNull; | 20 using ::testing::NotNull; |
| 20 using ::testing::Return; | 21 using ::testing::Return; |
| 21 using ::testing::StrictMock; | 22 using ::testing::StrictMock; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Total bytes of the data source. | 26 // Total bytes of the data source. |
| 26 const int kTotalBytes = 1024; | 27 const int kTotalBytes = 1024; |
| 27 | 28 |
| 28 // Buffered bytes of the data source. | 29 // Buffered bytes of the data source. |
| 29 const int kBufferedBytes = 1024; | 30 const int kBufferedBytes = 1024; |
| 30 | 31 |
| 31 } // namespace | 32 } // namespace |
| 32 | 33 |
| 33 namespace media { | 34 namespace media { |
| 34 | 35 |
| 35 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 36 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
| 36 // also lets us test for missing callbacks. | 37 // also lets us test for missing callbacks. |
| 37 class CallbackHelper { | 38 class CallbackHelper { |
| 38 public: | 39 public: |
| 39 CallbackHelper() {} | 40 CallbackHelper() {} |
| 40 virtual ~CallbackHelper() {} | 41 virtual ~CallbackHelper() {} |
| 41 | 42 |
| 42 MOCK_METHOD0(OnStart, void()); | 43 MOCK_METHOD0(OnStart, void()); |
| 43 MOCK_METHOD0(OnSeek, void()); | 44 MOCK_METHOD0(OnSeek, void()); |
| 44 MOCK_METHOD0(OnStop, void()); | 45 MOCK_METHOD0(OnStop, void()); |
| 46 MOCK_METHOD0(OnEnded, void()); |
| 45 MOCK_METHOD0(OnError, void()); | 47 MOCK_METHOD0(OnError, void()); |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 50 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 // TODO(scherkus): even though some filters are initialized on separate | 53 // TODO(scherkus): even though some filters are initialized on separate |
| 52 // threads these test aren't flaky... why? It's because filters' Initialize() | 54 // threads these test aren't flaky... why? It's because filters' Initialize() |
| 53 // is executed on |message_loop_| and the mock filters instantly call | 55 // is executed on |message_loop_| and the mock filters instantly call |
| 54 // InitializationComplete(), which keeps the pipeline humming along. If | 56 // InitializationComplete(), which keeps the pipeline humming along. If |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 EXPECT_CALL(*mocks_->audio_renderer(), | 475 EXPECT_CALL(*mocks_->audio_renderer(), |
| 474 OnReceivedMessage(kMsgDisableAudio)); | 476 OnReceivedMessage(kMsgDisableAudio)); |
| 475 EXPECT_CALL(*mocks_->video_decoder(), | 477 EXPECT_CALL(*mocks_->video_decoder(), |
| 476 OnReceivedMessage(kMsgDisableAudio)); | 478 OnReceivedMessage(kMsgDisableAudio)); |
| 477 EXPECT_CALL(*mocks_->video_renderer(), | 479 EXPECT_CALL(*mocks_->video_renderer(), |
| 478 OnReceivedMessage(kMsgDisableAudio)); | 480 OnReceivedMessage(kMsgDisableAudio)); |
| 479 | 481 |
| 480 mocks_->audio_renderer()->SetPlaybackRate(1.0f); | 482 mocks_->audio_renderer()->SetPlaybackRate(1.0f); |
| 481 } | 483 } |
| 482 | 484 |
| 485 TEST_F(PipelineImplTest, EndedCallback) { |
| 486 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream = |
| 487 new StrictMock<MockDemuxerStream>("audio/x-foo"); |
| 488 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream = |
| 489 new StrictMock<MockDemuxerStream>("video/x-foo"); |
| 490 MockDemuxerStreamVector streams; |
| 491 streams.push_back(audio_stream); |
| 492 streams.push_back(video_stream); |
| 493 |
| 494 // Set our ended callback. |
| 495 pipeline_->SetPipelineEndedCallback( |
| 496 NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 497 &CallbackHelper::OnEnded)); |
| 498 |
| 499 InitializeDataSource(); |
| 500 InitializeDemuxer(&streams, base::TimeDelta()); |
| 501 InitializeAudioDecoder(audio_stream); |
| 502 InitializeAudioRenderer(); |
| 503 InitializeVideoDecoder(video_stream); |
| 504 InitializeVideoRenderer(); |
| 505 InitializePipeline(); |
| 506 |
| 507 // For convenience to simulate filters calling the methods. |
| 508 FilterHost* host = pipeline_; |
| 509 |
| 510 // Due to short circuit evaluation we only need to test a subset of cases. |
| 511 InSequence s; |
| 512 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 513 .WillOnce(Return(false)); |
| 514 host->NotifyEnded(); |
| 515 |
| 516 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 517 .WillOnce(Return(true)); |
| 518 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 519 .WillOnce(Return(false)); |
| 520 host->NotifyEnded(); |
| 521 |
| 522 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 523 .WillOnce(Return(true)); |
| 524 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 525 .WillOnce(Return(true)); |
| 526 EXPECT_CALL(callbacks_, OnEnded()); |
| 527 host->NotifyEnded(); |
| 528 } |
| 529 |
| 483 } // namespace media | 530 } // namespace media |
| OLD | NEW |