| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 25 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
| 26 // also lets us test for missing callbacks. | 26 // also lets us test for missing callbacks. |
| 27 class CallbackHelper { | 27 class CallbackHelper { |
| 28 public: | 28 public: |
| 29 CallbackHelper() {} | 29 CallbackHelper() {} |
| 30 virtual ~CallbackHelper() {} | 30 virtual ~CallbackHelper() {} |
| 31 | 31 |
| 32 MOCK_METHOD0(OnStart, void()); | 32 MOCK_METHOD0(OnStart, void()); |
| 33 MOCK_METHOD0(OnSeek, void()); | 33 MOCK_METHOD0(OnSeek, void()); |
| 34 MOCK_METHOD0(OnStop, void()); | 34 MOCK_METHOD0(OnStop, void()); |
| 35 MOCK_METHOD0(OnError, void()); |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 38 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // TODO(scherkus): even though some filters are initialized on separate | 41 // TODO(scherkus): even though some filters are initialized on separate |
| 41 // threads these test aren't flaky... why? It's because filters' Initialize() | 42 // threads these test aren't flaky... why? It's because filters' Initialize() |
| 42 // is executed on |message_loop_| and the mock filters instantly call | 43 // is executed on |message_loop_| and the mock filters instantly call |
| 43 // InitializationComplete(), which keeps the pipeline humming along. If | 44 // InitializationComplete(), which keeps the pipeline humming along. If |
| 44 // either filters don't call InitializationComplete() immediately or filter | 45 // either filters don't call InitializationComplete() immediately or filter |
| 45 // initialization is moved to a separate thread this test will become flaky. | 46 // initialization is moved to a separate thread this test will become flaky. |
| 46 class PipelineImplTest : public ::testing::Test { | 47 class PipelineImplTest : public ::testing::Test { |
| 47 public: | 48 public: |
| 48 PipelineImplTest() | 49 PipelineImplTest() |
| 49 : pipeline_(new PipelineImpl(&message_loop_)), | 50 : pipeline_(new PipelineImpl(&message_loop_)), |
| 50 mocks_(new MockFilterFactory()) { | 51 mocks_(new MockFilterFactory()) { |
| 52 pipeline_->SetPipelineErrorCallback(NewCallback( |
| 53 reinterpret_cast<CallbackHelper*>(&callbacks_), |
| 54 &CallbackHelper::OnError)); |
| 51 } | 55 } |
| 52 | 56 |
| 53 virtual ~PipelineImplTest() { | 57 virtual ~PipelineImplTest() { |
| 54 if (!pipeline_->IsRunning()) { | 58 if (!pipeline_->IsRunning()) { |
| 55 return; | 59 return; |
| 56 } | 60 } |
| 57 | 61 |
| 58 // Expect a stop callback if we were started. | 62 // Expect a stop callback if we were started. |
| 59 EXPECT_CALL(callbacks_, OnStop()); | 63 EXPECT_CALL(callbacks_, OnStop()); |
| 60 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), | 64 pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_), |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 229 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 226 | 230 |
| 227 // Because our callback will get executed when the test tears down, we'll | 231 // Because our callback will get executed when the test tears down, we'll |
| 228 // verify that nothing has been called, then set our expectation for the call | 232 // verify that nothing has been called, then set our expectation for the call |
| 229 // made during tear down. | 233 // made during tear down. |
| 230 Mock::VerifyAndClear(&callbacks_); | 234 Mock::VerifyAndClear(&callbacks_); |
| 231 EXPECT_CALL(callbacks_, OnStart()); | 235 EXPECT_CALL(callbacks_, OnStart()); |
| 232 } | 236 } |
| 233 | 237 |
| 234 TEST_F(PipelineImplTest, RequiredFilterMissing) { | 238 TEST_F(PipelineImplTest, RequiredFilterMissing) { |
| 239 EXPECT_CALL(callbacks_, OnError()); |
| 235 mocks_->set_creation_successful(false); | 240 mocks_->set_creation_successful(false); |
| 236 | 241 |
| 237 InitializePipeline(); | 242 InitializePipeline(); |
| 238 EXPECT_FALSE(pipeline_->IsInitialized()); | 243 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 239 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, | 244 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, |
| 240 pipeline_->GetError()); | 245 pipeline_->GetError()); |
| 241 } | 246 } |
| 242 | 247 |
| 243 TEST_F(PipelineImplTest, URLNotFound) { | 248 TEST_F(PipelineImplTest, URLNotFound) { |
| 244 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 249 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 245 .WillOnce(DoAll(SetError(mocks_->data_source(), | 250 .WillOnce(DoAll(SetError(mocks_->data_source(), |
| 246 PIPELINE_ERROR_URL_NOT_FOUND), | 251 PIPELINE_ERROR_URL_NOT_FOUND), |
| 247 Invoke(&RunFilterCallback))); | 252 Invoke(&RunFilterCallback))); |
| 253 EXPECT_CALL(callbacks_, OnError()); |
| 248 EXPECT_CALL(*mocks_->data_source(), Stop()); | 254 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 249 | 255 |
| 250 InitializePipeline(); | 256 InitializePipeline(); |
| 251 EXPECT_FALSE(pipeline_->IsInitialized()); | 257 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 252 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); | 258 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); |
| 253 } | 259 } |
| 254 | 260 |
| 255 TEST_F(PipelineImplTest, NoStreams) { | 261 TEST_F(PipelineImplTest, NoStreams) { |
| 256 // Manually set these expectations because SetPlaybackRate() is not called if | 262 // Manually set these expectations because SetPlaybackRate() is not called if |
| 257 // we cannot fully initialize the pipeline. | 263 // we cannot fully initialize the pipeline. |
| 258 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 264 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 259 .WillOnce(Invoke(&RunFilterCallback)); | 265 .WillOnce(Invoke(&RunFilterCallback)); |
| 260 EXPECT_CALL(*mocks_->data_source(), Stop()); | 266 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 261 | 267 |
| 262 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) | 268 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) |
| 263 .WillOnce(Invoke(&RunFilterCallback)); | 269 .WillOnce(Invoke(&RunFilterCallback)); |
| 264 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 270 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 265 .WillRepeatedly(Return(0)); | 271 .WillRepeatedly(Return(0)); |
| 266 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 272 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
| 273 EXPECT_CALL(callbacks_, OnError()); |
| 267 | 274 |
| 268 InitializePipeline(); | 275 InitializePipeline(); |
| 269 EXPECT_FALSE(pipeline_->IsInitialized()); | 276 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 270 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); | 277 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); |
| 271 } | 278 } |
| 272 | 279 |
| 273 TEST_F(PipelineImplTest, AudioStream) { | 280 TEST_F(PipelineImplTest, AudioStream) { |
| 274 scoped_refptr<StrictMock<MockDemuxerStream> > stream = | 281 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 275 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 282 new StrictMock<MockDemuxerStream>("audio/x-foo"); |
| 276 MockDemuxerStreamVector streams; | 283 MockDemuxerStreamVector streams; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // The audio renderer should receive a call to SetVolume(). | 396 // The audio renderer should receive a call to SetVolume(). |
| 390 float expected = 0.5f; | 397 float expected = 0.5f; |
| 391 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 398 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 392 | 399 |
| 393 // Initialize then set volume! | 400 // Initialize then set volume! |
| 394 InitializePipeline(); | 401 InitializePipeline(); |
| 395 pipeline_->SetVolume(expected); | 402 pipeline_->SetVolume(expected); |
| 396 } | 403 } |
| 397 | 404 |
| 398 } // namespace media | 405 } // namespace media |
| OLD | NEW |