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

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

Issue 11607003: Add a Clock and TickClock interface for mocking out time (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix warnings Created 7 years, 10 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
« no previous file with comments | « media/base/pipeline.cc ('k') | sync/notifier/ack_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/test/simple_test_clock.h"
10 #include "base/threading/simple_thread.h" 11 #include "base/threading/simple_thread.h"
12 #include "base/time/clock.h"
11 #include "media/base/clock.h" 13 #include "media/base/clock.h"
12 #include "media/base/gmock_callback_support.h" 14 #include "media/base/gmock_callback_support.h"
13 #include "media/base/media_log.h" 15 #include "media/base/media_log.h"
14 #include "media/base/mock_filters.h" 16 #include "media/base/mock_filters.h"
15 #include "media/base/pipeline.h" 17 #include "media/base/pipeline.h"
16 #include "media/base/test_helpers.h" 18 #include "media/base/test_helpers.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
19 21
20 using ::testing::_; 22 using ::testing::_;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 base::Unretained(&callbacks_))); 293 base::Unretained(&callbacks_)));
292 294
293 // We expect the time to be updated only after the seek has completed. 295 // We expect the time to be updated only after the seek has completed.
294 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); 296 EXPECT_NE(seek_time, pipeline_->GetMediaTime());
295 message_loop_.RunUntilIdle(); 297 message_loop_.RunUntilIdle();
296 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); 298 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
297 } 299 }
298 300
299 // Fixture members. 301 // Fixture members.
300 StrictMock<CallbackHelper> callbacks_; 302 StrictMock<CallbackHelper> callbacks_;
303 base::SimpleTestClock test_clock_;
301 MessageLoop message_loop_; 304 MessageLoop message_loop_;
302 scoped_refptr<Pipeline> pipeline_; 305 scoped_refptr<Pipeline> pipeline_;
303 306
304 scoped_ptr<FilterCollection> filter_collection_; 307 scoped_ptr<FilterCollection> filter_collection_;
305 scoped_refptr<MockDemuxer> demuxer_; 308 scoped_refptr<MockDemuxer> demuxer_;
306 scoped_refptr<MockVideoDecoder> video_decoder_; 309 scoped_refptr<MockVideoDecoder> video_decoder_;
307 scoped_refptr<MockAudioDecoder> audio_decoder_; 310 scoped_refptr<MockAudioDecoder> audio_decoder_;
308 MockVideoRenderer* video_renderer_; 311 MockVideoRenderer* video_renderer_;
309 MockAudioRenderer* audio_renderer_; 312 MockAudioRenderer* audio_renderer_;
310 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; 313 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 604
602 // The ended callback shouldn't run until both renderers have ended. 605 // The ended callback shouldn't run until both renderers have ended.
603 pipeline_->OnAudioRendererEnded(); 606 pipeline_->OnAudioRendererEnded();
604 message_loop_.RunUntilIdle(); 607 message_loop_.RunUntilIdle();
605 608
606 EXPECT_CALL(callbacks_, OnEnded()); 609 EXPECT_CALL(callbacks_, OnEnded());
607 pipeline_->OnVideoRendererEnded(); 610 pipeline_->OnVideoRendererEnded();
608 message_loop_.RunUntilIdle(); 611 message_loop_.RunUntilIdle();
609 } 612 }
610 613
611 // Static function & time variable used to simulate changes in wallclock time.
612 static int64 g_static_clock_time;
613 static base::Time StaticClockFunction() {
614 return base::Time::FromInternalValue(g_static_clock_time);
615 }
616
617 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { 614 TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
618 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); 615 base::TimeDelta duration = base::TimeDelta::FromSeconds(10);
619 616
620 CreateAudioStream(); 617 CreateAudioStream();
621 CreateVideoStream(); 618 CreateVideoStream();
622 MockDemuxerStreamVector streams; 619 MockDemuxerStreamVector streams;
623 streams.push_back(audio_stream()); 620 streams.push_back(audio_stream());
624 streams.push_back(video_stream()); 621 streams.push_back(video_stream());
625 622
626 // Replace the clock so we can simulate wallclock time advancing w/o using 623 // Replace the clock so we can simulate wallclock time advancing w/o using
627 // Sleep(). 624 // Sleep().
628 pipeline_->SetClockForTesting(new Clock(&StaticClockFunction)); 625 pipeline_->SetClockForTesting(new Clock(&test_clock_));
629 626
630 InitializeDemuxer(&streams, duration); 627 InitializeDemuxer(&streams, duration);
631 InitializeAudioRenderer(audio_stream(), false); 628 InitializeAudioRenderer(audio_stream(), false);
632 InitializeVideoRenderer(video_stream()); 629 InitializeVideoRenderer(video_stream());
633 InitializePipeline(PIPELINE_OK); 630 InitializePipeline(PIPELINE_OK);
634 631
635 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue()); 632 EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue());
636 633
637 float playback_rate = 1.0f; 634 float playback_rate = 1.0f;
638 EXPECT_CALL(*demuxer_, SetPlaybackRate(playback_rate)); 635 EXPECT_CALL(*demuxer_, SetPlaybackRate(playback_rate));
639 EXPECT_CALL(*video_renderer_, SetPlaybackRate(playback_rate)); 636 EXPECT_CALL(*video_renderer_, SetPlaybackRate(playback_rate));
640 EXPECT_CALL(*audio_renderer_, SetPlaybackRate(playback_rate)); 637 EXPECT_CALL(*audio_renderer_, SetPlaybackRate(playback_rate));
641 pipeline_->SetPlaybackRate(playback_rate); 638 pipeline_->SetPlaybackRate(playback_rate);
642 message_loop_.RunUntilIdle(); 639 message_loop_.RunUntilIdle();
643 640
644 InSequence s; 641 InSequence s;
645 642
646 // Verify that the clock doesn't advance since it hasn't been started by 643 // Verify that the clock doesn't advance since it hasn't been started by
647 // a time update from the audio stream. 644 // a time update from the audio stream.
648 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); 645 int64 start_time = pipeline_->GetMediaTime().ToInternalValue();
649 g_static_clock_time += 646 test_clock_.Advance(base::TimeDelta::FromMilliseconds(100));
650 base::TimeDelta::FromMilliseconds(100).ToInternalValue();
651 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); 647 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time);
652 648
653 // Signal end of audio stream. 649 // Signal end of audio stream.
654 pipeline_->OnAudioRendererEnded(); 650 pipeline_->OnAudioRendererEnded();
655 message_loop_.RunUntilIdle(); 651 message_loop_.RunUntilIdle();
656 652
657 // Verify that the clock advances. 653 // Verify that the clock advances.
658 start_time = pipeline_->GetMediaTime().ToInternalValue(); 654 start_time = pipeline_->GetMediaTime().ToInternalValue();
659 g_static_clock_time += 655 test_clock_.Advance(base::TimeDelta::FromMilliseconds(100));
660 base::TimeDelta::FromMilliseconds(100).ToInternalValue();
661 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); 656 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time);
662 657
663 // Signal end of video stream and make sure OnEnded() callback occurs. 658 // Signal end of video stream and make sure OnEnded() callback occurs.
664 EXPECT_CALL(callbacks_, OnEnded()); 659 EXPECT_CALL(callbacks_, OnEnded());
665 pipeline_->OnVideoRendererEnded(); 660 pipeline_->OnVideoRendererEnded();
666 } 661 }
667 662
668 TEST_F(PipelineTest, ErrorDuringSeek) { 663 TEST_F(PipelineTest, ErrorDuringSeek) {
669 CreateAudioStream(); 664 CreateAudioStream();
670 MockDemuxerStreamVector streams; 665 MockDemuxerStreamVector streams;
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); 1226 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer);
1232 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); 1227 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer);
1233 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); 1228 INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
1234 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 1229 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1235 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1230 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1236 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); 1231 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
1237 INSTANTIATE_TEARDOWN_TEST(Error, Starting); 1232 INSTANTIATE_TEARDOWN_TEST(Error, Starting);
1238 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1233 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1239 1234
1240 } // namespace media 1235 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | sync/notifier/ack_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698