OLD | NEW |
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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 ACTION_P2(SetError, pipeline, status) { | 50 ACTION_P2(SetError, pipeline, status) { |
51 pipeline->SetErrorForTesting(status); | 51 pipeline->SetErrorForTesting(status); |
52 } | 52 } |
53 | 53 |
54 ACTION_P2(SetBufferingState, cb, buffering_state) { | 54 ACTION_P2(SetBufferingState, cb, buffering_state) { |
55 cb->Run(buffering_state); | 55 cb->Run(buffering_state); |
56 } | 56 } |
57 | 57 |
58 ACTION_TEMPLATE(PostCallback, | 58 ACTION_TEMPLATE(PostCallback, |
59 HAS_1_TEMPLATE_PARAMS(int, k), | 59 HAS_1_TEMPLATE_PARAMS(int, k), |
60 AND_0_VALUE_PARAMS()) { | |
61 return base::MessageLoop::current()->PostTask(FROM_HERE, | |
62 ::std::tr1::get<k>(args)); | |
63 } | |
64 | |
65 ACTION_TEMPLATE(PostCallback, | |
66 HAS_1_TEMPLATE_PARAMS(int, k), | |
67 AND_1_VALUE_PARAMS(p0)) { | 60 AND_1_VALUE_PARAMS(p0)) { |
68 return base::MessageLoop::current()->PostTask( | 61 return base::MessageLoop::current()->PostTask( |
69 FROM_HERE, base::Bind(::std::tr1::get<k>(args), p0)); | 62 FROM_HERE, base::Bind(::std::tr1::get<k>(args), p0)); |
70 } | 63 } |
71 | 64 |
72 // TODO(scherkus): even though some filters are initialized on separate | 65 // TODO(scherkus): even though some filters are initialized on separate |
73 // threads these test aren't flaky... why? It's because filters' Initialize() | 66 // threads these test aren't flaky... why? It's because filters' Initialize() |
74 // is executed on |message_loop_| and the mock filters instantly call | 67 // is executed on |message_loop_| and the mock filters instantly call |
75 // InitializationComplete(), which keeps the pipeline humming along. If | 68 // InitializationComplete(), which keeps the pipeline humming along. If |
76 // either filters don't call InitializationComplete() immediately or filter | 69 // either filters don't call InitializationComplete() immediately or filter |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 scoped_ptr<StrictMock<MockDemuxerStream> > stream( | 166 scoped_ptr<StrictMock<MockDemuxerStream> > stream( |
174 new StrictMock<MockDemuxerStream>(type)); | 167 new StrictMock<MockDemuxerStream>(type)); |
175 return stream.Pass(); | 168 return stream.Pass(); |
176 } | 169 } |
177 | 170 |
178 // Sets up expectations to allow the video renderer to initialize. | 171 // Sets up expectations to allow the video renderer to initialize. |
179 void SetRendererExpectations() { | 172 void SetRendererExpectations() { |
180 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) | 173 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) |
181 .WillOnce(DoAll(SaveArg<3>(&buffering_state_cb_), | 174 .WillOnce(DoAll(SaveArg<3>(&buffering_state_cb_), |
182 SaveArg<5>(&ended_cb_), | 175 SaveArg<5>(&ended_cb_), |
183 PostCallback<1>())); | 176 PostCallback<1>(PIPELINE_OK))); |
184 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(audio_stream())); | 177 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(audio_stream())); |
185 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(video_stream())); | 178 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(video_stream())); |
186 } | 179 } |
187 | 180 |
188 void AddTextStream() { | 181 void AddTextStream() { |
189 EXPECT_CALL(*this, OnAddTextTrack(_,_)) | 182 EXPECT_CALL(*this, OnAddTextTrack(_,_)) |
190 .WillOnce(Invoke(this, &PipelineTest::DoOnAddTextTrack)); | 183 .WillOnce(Invoke(this, &PipelineTest::DoOnAddTextTrack)); |
191 static_cast<DemuxerHost*>(pipeline_.get())->AddTextStream(text_stream(), | 184 static_cast<DemuxerHost*>(pipeline_.get())->AddTextStream(text_stream(), |
192 TextTrackConfig(kTextSubtitles, "", "", "")); | 185 TextTrackConfig(kTextSubtitles, "", "", "")); |
193 message_loop_.RunUntilIdle(); | 186 message_loop_.RunUntilIdle(); |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 streams.push_back(video_stream()); | 851 streams.push_back(video_stream()); |
859 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000)); | 852 SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000)); |
860 | 853 |
861 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(true)); | 854 EXPECT_CALL(*renderer_, HasAudio()).WillRepeatedly(Return(true)); |
862 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(true)); | 855 EXPECT_CALL(*renderer_, HasVideo()).WillRepeatedly(Return(true)); |
863 | 856 |
864 if (state == kInitRenderer) { | 857 if (state == kInitRenderer) { |
865 if (stop_or_error == kStop) { | 858 if (stop_or_error == kStop) { |
866 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) | 859 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) |
867 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), | 860 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), |
868 PostCallback<1>())); | 861 PostCallback<1>(PIPELINE_OK))); |
869 ExpectPipelineStopAndDestroyPipeline(); | 862 ExpectPipelineStopAndDestroyPipeline(); |
870 } else { | 863 } else { |
871 status = PIPELINE_ERROR_INITIALIZATION_FAILED; | 864 status = PIPELINE_ERROR_INITIALIZATION_FAILED; |
872 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) | 865 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) |
873 .WillOnce( | 866 .WillOnce(PostCallback<1>(status)); |
874 DoAll(RunCallback<6>(status), PostCallback<1>())); | |
875 } | 867 } |
876 | 868 |
877 EXPECT_CALL(*demuxer_, Stop()); | 869 EXPECT_CALL(*demuxer_, Stop()); |
878 return status; | 870 return status; |
879 } | 871 } |
880 | 872 |
881 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) | 873 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _)) |
882 .WillOnce(DoAll(SaveArg<3>(&buffering_state_cb_), | 874 .WillOnce(DoAll(SaveArg<3>(&buffering_state_cb_), |
883 PostCallback<1>())); | 875 PostCallback<1>(PIPELINE_OK))); |
884 | 876 |
885 EXPECT_CALL(callbacks_, OnMetadata(_)); | 877 EXPECT_CALL(callbacks_, OnMetadata(_)); |
886 | 878 |
887 // If we get here it's a successful initialization. | 879 // If we get here it's a successful initialization. |
888 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0f)); | 880 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0f)); |
889 EXPECT_CALL(*renderer_, SetVolume(1.0f)); | 881 EXPECT_CALL(*renderer_, SetVolume(1.0f)); |
890 EXPECT_CALL(*renderer_, StartPlayingFrom(base::TimeDelta())) | 882 EXPECT_CALL(*renderer_, StartPlayingFrom(base::TimeDelta())) |
891 .WillOnce(SetBufferingState(&buffering_state_cb_, | 883 .WillOnce(SetBufferingState(&buffering_state_cb_, |
892 BUFFERING_HAVE_ENOUGH)); | 884 BUFFERING_HAVE_ENOUGH)); |
893 | 885 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 | 1002 |
1011 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); | 1003 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); |
1012 INSTANTIATE_TEARDOWN_TEST(Error, InitRenderer); | 1004 INSTANTIATE_TEARDOWN_TEST(Error, InitRenderer); |
1013 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1005 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
1014 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1006 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
1015 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1007 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
1016 | 1008 |
1017 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); | 1009 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); |
1018 | 1010 |
1019 } // namespace media | 1011 } // namespace media |
OLD | NEW |