| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); | 231 EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); |
| 228 | 232 |
| 229 // Because our callback will get executed when the test tears down, we'll | 233 // Because our callback will get executed when the test tears down, we'll |
| 230 // verify that nothing has been called, then set our expectation for the call | 234 // verify that nothing has been called, then set our expectation for the call |
| 231 // made during tear down. | 235 // made during tear down. |
| 232 Mock::VerifyAndClear(&callbacks_); | 236 Mock::VerifyAndClear(&callbacks_); |
| 233 EXPECT_CALL(callbacks_, OnStart()); | 237 EXPECT_CALL(callbacks_, OnStart()); |
| 234 } | 238 } |
| 235 | 239 |
| 236 TEST_F(PipelineImplTest, RequiredFilterMissing) { | 240 TEST_F(PipelineImplTest, RequiredFilterMissing) { |
| 241 EXPECT_CALL(callbacks_, OnError()); |
| 237 mocks_->set_creation_successful(false); | 242 mocks_->set_creation_successful(false); |
| 238 | 243 |
| 239 InitializePipeline(); | 244 InitializePipeline(); |
| 240 EXPECT_FALSE(pipeline_->IsInitialized()); | 245 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 241 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, | 246 EXPECT_EQ(PIPELINE_ERROR_REQUIRED_FILTER_MISSING, |
| 242 pipeline_->GetError()); | 247 pipeline_->GetError()); |
| 243 } | 248 } |
| 244 | 249 |
| 245 TEST_F(PipelineImplTest, URLNotFound) { | 250 TEST_F(PipelineImplTest, URLNotFound) { |
| 246 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 251 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 247 .WillOnce(DoAll(SetError(mocks_->data_source(), | 252 .WillOnce(DoAll(SetError(mocks_->data_source(), |
| 248 PIPELINE_ERROR_URL_NOT_FOUND), | 253 PIPELINE_ERROR_URL_NOT_FOUND), |
| 249 Invoke(&RunFilterCallback))); | 254 Invoke(&RunFilterCallback))); |
| 255 EXPECT_CALL(callbacks_, OnError()); |
| 250 EXPECT_CALL(*mocks_->data_source(), Stop()); | 256 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 251 | 257 |
| 252 InitializePipeline(); | 258 InitializePipeline(); |
| 253 EXPECT_FALSE(pipeline_->IsInitialized()); | 259 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 254 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); | 260 EXPECT_EQ(PIPELINE_ERROR_URL_NOT_FOUND, pipeline_->GetError()); |
| 255 } | 261 } |
| 256 | 262 |
| 257 TEST_F(PipelineImplTest, NoStreams) { | 263 TEST_F(PipelineImplTest, NoStreams) { |
| 258 // Manually set these expectations because SetPlaybackRate() is not called if | 264 // Manually set these expectations because SetPlaybackRate() is not called if |
| 259 // we cannot fully initialize the pipeline. | 265 // we cannot fully initialize the pipeline. |
| 260 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) | 266 EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) |
| 261 .WillOnce(Invoke(&RunFilterCallback)); | 267 .WillOnce(Invoke(&RunFilterCallback)); |
| 262 EXPECT_CALL(*mocks_->data_source(), Stop()); | 268 EXPECT_CALL(*mocks_->data_source(), Stop()); |
| 263 | 269 |
| 264 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) | 270 EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) |
| 265 .WillOnce(Invoke(&RunFilterCallback)); | 271 .WillOnce(Invoke(&RunFilterCallback)); |
| 266 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) | 272 EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) |
| 267 .WillRepeatedly(Return(0)); | 273 .WillRepeatedly(Return(0)); |
| 268 EXPECT_CALL(*mocks_->demuxer(), Stop()); | 274 EXPECT_CALL(*mocks_->demuxer(), Stop()); |
| 275 EXPECT_CALL(callbacks_, OnError()); |
| 269 | 276 |
| 270 InitializePipeline(); | 277 InitializePipeline(); |
| 271 EXPECT_FALSE(pipeline_->IsInitialized()); | 278 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 272 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); | 279 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, pipeline_->GetError()); |
| 273 } | 280 } |
| 274 | 281 |
| 275 TEST_F(PipelineImplTest, AudioStream) { | 282 TEST_F(PipelineImplTest, AudioStream) { |
| 276 scoped_refptr<StrictMock<MockDemuxerStream> > stream = | 283 scoped_refptr<StrictMock<MockDemuxerStream> > stream = |
| 277 new StrictMock<MockDemuxerStream>("audio/x-foo"); | 284 new StrictMock<MockDemuxerStream>("audio/x-foo"); |
| 278 MockDemuxerStreamVector streams; | 285 MockDemuxerStreamVector streams; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // The audio renderer should receive a call to SetVolume(). | 398 // The audio renderer should receive a call to SetVolume(). |
| 392 float expected = 0.5f; | 399 float expected = 0.5f; |
| 393 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 400 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 394 | 401 |
| 395 // Initialize then set volume! | 402 // Initialize then set volume! |
| 396 InitializePipeline(); | 403 InitializePipeline(); |
| 397 pipeline_->SetVolume(expected); | 404 pipeline_->SetVolume(expected); |
| 398 } | 405 } |
| 399 | 406 |
| 400 } // namespace media | 407 } // namespace media |
| OLD | NEW |