Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: media/base/pipeline_unittest.cc

Issue 10854151: Allow transitioning to HAVE_METADATA before pipeline initialization completes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/simple_thread.h" 10 #include "base/threading/simple_thread.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 class CallbackHelper { 71 class CallbackHelper {
72 public: 72 public:
73 CallbackHelper() {} 73 CallbackHelper() {}
74 virtual ~CallbackHelper() {} 74 virtual ~CallbackHelper() {}
75 75
76 MOCK_METHOD1(OnStart, void(PipelineStatus)); 76 MOCK_METHOD1(OnStart, void(PipelineStatus));
77 MOCK_METHOD1(OnSeek, void(PipelineStatus)); 77 MOCK_METHOD1(OnSeek, void(PipelineStatus));
78 MOCK_METHOD0(OnStop, void()); 78 MOCK_METHOD0(OnStop, void());
79 MOCK_METHOD1(OnEnded, void(PipelineStatus)); 79 MOCK_METHOD1(OnEnded, void(PipelineStatus));
80 MOCK_METHOD1(OnError, void(PipelineStatus)); 80 MOCK_METHOD1(OnError, void(PipelineStatus));
81 MOCK_METHOD1(OnReadyState, void(Pipeline::ReadyState));
81 82
82 private: 83 private:
83 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); 84 DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
84 }; 85 };
85 86
86 // TODO(scherkus): even though some filters are initialized on separate 87 // TODO(scherkus): even though some filters are initialized on separate
87 // threads these test aren't flaky... why? It's because filters' Initialize() 88 // threads these test aren't flaky... why? It's because filters' Initialize()
88 // is executed on |message_loop_| and the mock filters instantly call 89 // is executed on |message_loop_| and the mock filters instantly call
89 // InitializationComplete(), which keeps the pipeline humming along. If 90 // InitializationComplete(), which keeps the pipeline humming along. If
90 // either filters don't call InitializationComplete() immediately or filter 91 // either filters don't call InitializationComplete() immediately or filter
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 .WillOnce(RunPipelineStatusCB()); 228 .WillOnce(RunPipelineStatusCB());
228 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) 229 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
229 .WillOnce(RunClosure()); 230 .WillOnce(RunClosure());
230 } 231 }
231 } 232 }
232 233
233 pipeline_->Start( 234 pipeline_->Start(
234 mocks_->Create().Pass(), 235 mocks_->Create().Pass(),
235 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 236 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
236 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 237 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
237 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 238 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
239 base::Bind(&CallbackHelper::OnReadyState,
240 base::Unretained(&callbacks_)));
238 message_loop_.RunAllPending(); 241 message_loop_.RunAllPending();
239 } 242 }
240 243
241 void CreateAudioStream() { 244 void CreateAudioStream() {
242 audio_stream_ = CreateStream(DemuxerStream::AUDIO); 245 audio_stream_ = CreateStream(DemuxerStream::AUDIO);
243 } 246 }
244 247
245 void CreateVideoStream() { 248 void CreateVideoStream() {
246 video_stream_ = CreateStream(DemuxerStream::VIDEO); 249 video_stream_ = CreateStream(DemuxerStream::VIDEO);
247 } 250 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // Don't execute the callback passed into Initialize(). 352 // Don't execute the callback passed into Initialize().
350 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)); 353 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _));
351 354
352 // This test hangs during initialization by never calling 355 // This test hangs during initialization by never calling
353 // InitializationComplete(). StrictMock<> will ensure that the callback is 356 // InitializationComplete(). StrictMock<> will ensure that the callback is
354 // never executed. 357 // never executed.
355 pipeline_->Start( 358 pipeline_->Start(
356 mocks_->Create().Pass(), 359 mocks_->Create().Pass(),
357 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 360 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
358 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 361 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
359 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 362 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
363 base::Bind(&CallbackHelper::OnReadyState,
364 base::Unretained(&callbacks_)));
360 message_loop_.RunAllPending(); 365 message_loop_.RunAllPending();
361 366
362 367
363 // Because our callback will get executed when the test tears down, we'll 368 // Because our callback will get executed when the test tears down, we'll
364 // verify that nothing has been called, then set our expectation for the call 369 // verify that nothing has been called, then set our expectation for the call
365 // made during tear down. 370 // made during tear down.
366 Mock::VerifyAndClear(&callbacks_); 371 Mock::VerifyAndClear(&callbacks_);
367 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); 372 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK));
368 } 373 }
369 374
370 TEST_F(PipelineTest, RequiredFilterMissing) { 375 TEST_F(PipelineTest, RequiredFilterMissing) {
371 // Create a filter collection with missing filter. 376 // Create a filter collection with missing filter.
372 scoped_ptr<FilterCollection> collection(mocks_->Create()); 377 scoped_ptr<FilterCollection> collection(mocks_->Create());
373 collection->SetDemuxer(NULL); 378 collection->SetDemuxer(NULL);
374 379
375 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); 380 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING));
376 pipeline_->Start( 381 pipeline_->Start(
377 collection.Pass(), 382 collection.Pass(),
378 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 383 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
379 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 384 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
380 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 385 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
386 base::Bind(&CallbackHelper::OnReadyState,
387 base::Unretained(&callbacks_)));
381 message_loop_.RunAllPending(); 388 message_loop_.RunAllPending();
382 } 389 }
383 390
384 TEST_F(PipelineTest, URLNotFound) { 391 TEST_F(PipelineTest, URLNotFound) {
385 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) 392 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
386 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); 393 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_URL_NOT_FOUND));
387 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 394 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
388 .WillOnce(RunClosure()); 395 .WillOnce(RunClosure());
389 396
390 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); 397 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND);
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 // see http://crbug.com/110228 998 // see http://crbug.com/110228
992 void DoInitialize(TeardownState state, StopOrError stop_or_error) { 999 void DoInitialize(TeardownState state, StopOrError stop_or_error) {
993 PipelineStatus expected_status = 1000 PipelineStatus expected_status =
994 SetInitializeExpectations(state, stop_or_error); 1001 SetInitializeExpectations(state, stop_or_error);
995 1002
996 EXPECT_CALL(callbacks_, OnStart(expected_status)); 1003 EXPECT_CALL(callbacks_, OnStart(expected_status));
997 pipeline_->Start( 1004 pipeline_->Start(
998 mocks_->Create().Pass(), 1005 mocks_->Create().Pass(),
999 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 1006 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
1000 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 1007 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
1001 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 1008 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
1009 base::Bind(&CallbackHelper::OnReadyState,
1010 base::Unretained(&callbacks_)));
1002 message_loop_.RunAllPending(); 1011 message_loop_.RunAllPending();
1003 } 1012 }
1004 1013
1005 PipelineStatus SetInitializeExpectations(TeardownState state, 1014 PipelineStatus SetInitializeExpectations(TeardownState state,
1006 StopOrError stop_or_error) { 1015 StopOrError stop_or_error) {
1007 PipelineStatus status = PIPELINE_OK; 1016 PipelineStatus status = PIPELINE_OK;
1008 base::Closure stop_cb = base::Bind( 1017 base::Closure stop_cb = base::Bind(
1009 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); 1018 &CallbackHelper::OnStop, base::Unretained(&callbacks_));
1010 1019
1011 if (state == kInitDemuxer) { 1020 if (state == kInitDemuxer) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); 1304 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer);
1296 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); 1305 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer);
1297 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); 1306 INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
1298 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 1307 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1299 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1308 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1300 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); 1309 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
1301 INSTANTIATE_TEARDOWN_TEST(Error, Starting); 1310 INSTANTIATE_TEARDOWN_TEST(Error, Starting);
1302 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1311 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1303 1312
1304 } // namespace media 1313 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698