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

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

Issue 10800041: Update media duration if data is appended after the previous duration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to CR + fix unittest compiles Created 8 years, 5 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 class CallbackHelper { 55 class CallbackHelper {
56 public: 56 public:
57 CallbackHelper() {} 57 CallbackHelper() {}
58 virtual ~CallbackHelper() {} 58 virtual ~CallbackHelper() {}
59 59
60 MOCK_METHOD1(OnStart, void(PipelineStatus)); 60 MOCK_METHOD1(OnStart, void(PipelineStatus));
61 MOCK_METHOD1(OnSeek, void(PipelineStatus)); 61 MOCK_METHOD1(OnSeek, void(PipelineStatus));
62 MOCK_METHOD0(OnStop, void()); 62 MOCK_METHOD0(OnStop, void());
63 MOCK_METHOD1(OnEnded, void(PipelineStatus)); 63 MOCK_METHOD1(OnEnded, void(PipelineStatus));
64 MOCK_METHOD1(OnError, void(PipelineStatus)); 64 MOCK_METHOD1(OnError, void(PipelineStatus));
65 MOCK_METHOD0(OnNewDuration, void());
65 66
66 private: 67 private:
67 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); 68 DISALLOW_COPY_AND_ASSIGN(CallbackHelper);
68 }; 69 };
69 70
70 // TODO(scherkus): even though some filters are initialized on separate 71 // TODO(scherkus): even though some filters are initialized on separate
71 // threads these test aren't flaky... why? It's because filters' Initialize() 72 // threads these test aren't flaky... why? It's because filters' Initialize()
72 // is executed on |message_loop_| and the mock filters instantly call 73 // is executed on |message_loop_| and the mock filters instantly call
73 // InitializationComplete(), which keeps the pipeline humming along. If 74 // InitializationComplete(), which keeps the pipeline humming along. If
74 // either filters don't call InitializationComplete() immediately or filter 75 // either filters don't call InitializationComplete() immediately or filter
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 220
220 // Sets up expectations on the callback and initializes the pipeline. Called 221 // Sets up expectations on the callback and initializes the pipeline. Called
221 // after tests have set expectations any filters they wish to use. 222 // after tests have set expectations any filters they wish to use.
222 void InitializePipeline(PipelineStatus start_status) { 223 void InitializePipeline(PipelineStatus start_status) {
223 EXPECT_CALL(callbacks_, OnStart(start_status)); 224 EXPECT_CALL(callbacks_, OnStart(start_status));
224 225
225 pipeline_->Start( 226 pipeline_->Start(
226 mocks_->Create().Pass(), 227 mocks_->Create().Pass(),
227 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 228 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
228 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 229 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
229 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 230 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
231 base::Bind(&CallbackHelper::OnNewDuration,
232 base::Unretained(&callbacks_)));
230 message_loop_.RunAllPending(); 233 message_loop_.RunAllPending();
231 } 234 }
232 235
233 void CreateAudioStream() { 236 void CreateAudioStream() {
234 audio_stream_ = CreateStream(DemuxerStream::AUDIO); 237 audio_stream_ = CreateStream(DemuxerStream::AUDIO);
235 } 238 }
236 239
237 void CreateVideoStream() { 240 void CreateVideoStream() {
238 video_stream_ = CreateStream(DemuxerStream::VIDEO); 241 video_stream_ = CreateStream(DemuxerStream::VIDEO);
239 } 242 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 347 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
345 .WillOnce(RunClosure()); 348 .WillOnce(RunClosure());
346 349
347 // This test hangs during initialization by never calling 350 // This test hangs during initialization by never calling
348 // InitializationComplete(). StrictMock<> will ensure that the callback is 351 // InitializationComplete(). StrictMock<> will ensure that the callback is
349 // never executed. 352 // never executed.
350 pipeline_->Start( 353 pipeline_->Start(
351 mocks_->Create().Pass(), 354 mocks_->Create().Pass(),
352 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 355 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
353 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 356 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
354 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 357 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
358 base::Bind(&CallbackHelper::OnNewDuration,
359 base::Unretained(&callbacks_)));
355 message_loop_.RunAllPending(); 360 message_loop_.RunAllPending();
356 361
357 EXPECT_FALSE(pipeline_->IsInitialized()); 362 EXPECT_FALSE(pipeline_->IsInitialized());
358 363
359 // Because our callback will get executed when the test tears down, we'll 364 // Because our callback will get executed when the test tears down, we'll
360 // verify that nothing has been called, then set our expectation for the call 365 // verify that nothing has been called, then set our expectation for the call
361 // made during tear down. 366 // made during tear down.
362 Mock::VerifyAndClear(&callbacks_); 367 Mock::VerifyAndClear(&callbacks_);
363 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); 368 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK));
364 } 369 }
365 370
366 TEST_F(PipelineTest, RequiredFilterMissing) { 371 TEST_F(PipelineTest, RequiredFilterMissing) {
367 // Create a filter collection with missing filter. 372 // Create a filter collection with missing filter.
368 scoped_ptr<FilterCollection> collection(mocks_->Create()); 373 scoped_ptr<FilterCollection> collection(mocks_->Create());
369 collection->SetDemuxer(NULL); 374 collection->SetDemuxer(NULL);
370 375
371 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); 376 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING));
372 pipeline_->Start( 377 pipeline_->Start(
373 collection.Pass(), 378 collection.Pass(),
374 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), 379 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
375 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), 380 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
376 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); 381 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)),
382 base::Bind(&CallbackHelper::OnNewDuration,
383 base::Unretained(&callbacks_)));
377 message_loop_.RunAllPending(); 384 message_loop_.RunAllPending();
378 EXPECT_FALSE(pipeline_->IsInitialized()); 385 EXPECT_FALSE(pipeline_->IsInitialized());
379 } 386 }
380 387
381 TEST_F(PipelineTest, URLNotFound) { 388 TEST_F(PipelineTest, URLNotFound) {
382 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) 389 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
383 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); 390 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND));
384 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) 391 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
385 .WillOnce(RunClosure()); 392 .WillOnce(RunClosure());
386 393
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); 963 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0));
957 } 964 }
958 965
959 // Test that different-thread, some-delay callback (the expected common case) 966 // Test that different-thread, some-delay callback (the expected common case)
960 // works correctly. 967 // works correctly.
961 TEST(PipelineStatusNotificationTest, DelayedCallback) { 968 TEST(PipelineStatusNotificationTest, DelayedCallback) {
962 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); 969 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20));
963 } 970 }
964 971
965 } // namespace media 972 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698