| 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 30 matching lines...) Expand all Loading... |
| 63 EXPECT_CALL(callbacks_, OnStop()); | 73 EXPECT_CALL(callbacks_, OnStop()); |
| 64 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 74 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 65 &CallbackHelper::OnStop)); | 75 &CallbackHelper::OnStop)); |
| 66 message_loop_.RunAllPending(); | 76 message_loop_.RunAllPending(); |
| 67 } | 77 } |
| 68 | 78 |
| 69 protected: | 79 protected: |
| 70 // Sets up expectations to allow the data source to initialize. | 80 // Sets up expectations to allow the data source to initialize. |
| 71 void InitializeDataSource() { | 81 void InitializeDataSource() { |
| 72 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 82 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 73 .WillOnce(Invoke(&RunFilterCallback)); | 83 .WillOnce(DoAll(SetTotalBytes(mocks_->data_source(), kTotalBytes), |
| 84 SetBufferedBytes(mocks_->data_source(), kBufferedBytes), |
| 85 Invoke(&RunFilterCallback))); |
| 74 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); | 86 EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); |
| 75 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) | 87 EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull())) |
| 76 .WillOnce(Invoke(&RunFilterCallback)); | 88 .WillOnce(Invoke(&RunFilterCallback)); |
| 77 EXPECT_CALL(*mocks_->data_source(), Stop()); | 89 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 78 } | 90 } |
| 79 | 91 |
| 80 // Sets up expectations to allow the demuxer to initialize. | 92 // Sets up expectations to allow the demuxer to initialize. |
| 81 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 93 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 82 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 94 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 83 const base::TimeDelta& duration) { | 95 const base::TimeDelta& duration) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 409 |
| 398 // The audio renderer should receive a call to SetVolume(). | 410 // The audio renderer should receive a call to SetVolume(). |
| 399 float expected = 0.5f; | 411 float expected = 0.5f; |
| 400 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 412 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 401 | 413 |
| 402 // Initialize then set volume! | 414 // Initialize then set volume! |
| 403 InitializePipeline(); | 415 InitializePipeline(); |
| 404 pipeline_->SetVolume(expected); | 416 pipeline_->SetVolume(expected); |
| 405 } | 417 } |
| 406 | 418 |
| 419 TEST_F(PipelineImplTest, Properties) { |
| 420 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 421 new StrictMock<MockDemuxerStream>("video/x-foo"); |
| 422 MockDemuxerStreamVector streams; |
| 423 streams.push_back(stream); |
| 424 |
| 425 InitializeDataSource(); |
| 426 base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 427 InitializeDemuxer(&streams, kDuration); |
| 428 InitializeVideoDecoder(stream); |
| 429 InitializeVideoRenderer(); |
| 430 |
| 431 InitializePipeline(); |
| 432 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 433 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 434 EXPECT_EQ(kDuration.ToInternalValue(), |
| 435 pipeline_->GetDuration().ToInternalValue()); |
| 436 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 437 EXPECT_EQ(kBufferedBytes, pipeline_->GetBufferedBytes()); |
| 438 EXPECT_EQ(kDuration.ToInternalValue(), |
| 439 pipeline_->GetBufferedTime().ToInternalValue()); |
| 440 } |
| 441 |
| 407 } // namespace media | 442 } // namespace media |
| OLD | NEW |