| 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::Invoke; | 17 using ::testing::Invoke; |
| 18 using ::testing::Mock; | 18 using ::testing::Mock; |
| 19 using ::testing::NotNull; | 19 using ::testing::NotNull; |
| 20 using ::testing::Return; | 20 using ::testing::Return; |
| 21 using ::testing::StrictMock; | 21 using ::testing::StrictMock; |
| 22 | 22 |
| 23 namespace { |
| 24 |
| 25 // Total bytes of the data source. |
| 26 const int kTotalBytes = 1024; |
| 27 |
| 28 // Buffered bytes of the data source. |
| 29 const int kBufferedBytes = 1024; |
| 30 |
| 31 } // namespace |
| 32 |
| 23 namespace media { | 33 namespace media { |
| 24 | 34 |
| 25 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 35 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
| 26 // also lets us test for missing callbacks. | 36 // also lets us test for missing callbacks. |
| 27 class CallbackHelper { | 37 class CallbackHelper { |
| 28 public: | 38 public: |
| 29 CallbackHelper() {} | 39 CallbackHelper() {} |
| 30 virtual ~CallbackHelper() {} | 40 virtual ~CallbackHelper() {} |
| 31 | 41 |
| 32 MOCK_METHOD0(OnStart, void()); | 42 MOCK_METHOD0(OnStart, void()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 EXPECT_CALL(callbacks_, OnStop()); | 69 EXPECT_CALL(callbacks_, OnStop()); |
| 60 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 70 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 61 &CallbackHelper::OnStop)); | 71 &CallbackHelper::OnStop)); |
| 62 message_loop_.RunAllPending(); | 72 message_loop_.RunAllPending(); |
| 63 } | 73 } |
| 64 | 74 |
| 65 protected: | 75 protected: |
| 66 // Sets up expectations to allow the data source to initialize. | 76 // Sets up expectations to allow the data source to initialize. |
| 67 void InitializeDataSource() { | 77 void InitializeDataSource() { |
| 68 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 78 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 69 .WillOnce(Invoke(&RunFilterCallback)); | 79 .WillOnce(DoAll(SetTotalBytes(mocks_->data_source(), kTotalBytes), |
| 80 SetBufferedBytes(mocks_->data_source(), kBufferedBytes), |
| 81 Invoke(&RunFilterCallback))); |
| 70 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); | 82 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); |
| 71 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) | 83 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) |
| 72 .WillOnce(Invoke(&RunFilterCallback)); | 84 .WillOnce(Invoke(&RunFilterCallback)); |
| 73 EXPECT_CALL(*mocks_->data_source(), Stop()); | 85 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 74 } | 86 } |
| 75 | 87 |
| 76 // Sets up expectations to allow the demuxer to initialize. | 88 // Sets up expectations to allow the demuxer to initialize. |
| 77 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 89 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 78 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 90 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 79 const base::TimeDelta& duration) { | 91 const base::TimeDelta& duration) { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 402 |
| 391 // The audio renderer should receive a call to SetVolume(). | 403 // The audio renderer should receive a call to SetVolume(). |
| 392 float expected = 0.5f; | 404 float expected = 0.5f; |
| 393 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 405 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 394 | 406 |
| 395 // Initialize then set volume! | 407 // Initialize then set volume! |
| 396 InitializePipeline(); | 408 InitializePipeline(); |
| 397 pipeline_->SetVolume(expected); | 409 pipeline_->SetVolume(expected); |
| 398 } | 410 } |
| 399 | 411 |
| 412 TEST_F(PipelineImplTest, Properties) { |
| 413 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 414 new StrictMock<MockDemuxerStream>("video/x-foo"); |
| 415 MockDemuxerStreamVector streams; |
| 416 streams.push_back(stream); |
| 417 |
| 418 InitializeDataSource(); |
| 419 base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 420 InitializeDemuxer(&streams, kDuration); |
| 421 InitializeVideoDecoder(stream); |
| 422 InitializeVideoRenderer(); |
| 423 |
| 424 InitializePipeline(); |
| 425 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 426 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 427 EXPECT_EQ(kDuration.ToInternalValue(), |
| 428 pipeline_->GetDuration().ToInternalValue()); |
| 429 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 430 EXPECT_EQ(kBufferedBytes, pipeline_->GetBufferedBytes()); |
| 431 EXPECT_EQ(kDuration.ToInternalValue(), |
| 432 pipeline_->GetBufferedTime().ToInternalValue()); |
| 433 } |
| 434 |
| 400 } // namespace media | 435 } // namespace media |
| OLD | NEW |