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

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

Issue 15993018: Reland: Use a shared thread for media operations (round 3). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix stop race Created 7 years, 6 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') | webkit/mocks/test_media_stream_client.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/test/simple_test_clock.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // streams. 98 // streams.
99 DemuxerStream* null_pointer = NULL; 99 DemuxerStream* null_pointer = NULL;
100 EXPECT_CALL(*demuxer_, GetStream(_)) 100 EXPECT_CALL(*demuxer_, GetStream(_))
101 .WillRepeatedly(Return(null_pointer)); 101 .WillRepeatedly(Return(null_pointer));
102 102
103 EXPECT_CALL(*demuxer_, GetStartTime()) 103 EXPECT_CALL(*demuxer_, GetStartTime())
104 .WillRepeatedly(Return(base::TimeDelta())); 104 .WillRepeatedly(Return(base::TimeDelta()));
105 } 105 }
106 106
107 virtual ~PipelineTest() { 107 virtual ~PipelineTest() {
108 // Shutdown sequence. 108 if (!pipeline_ || !pipeline_->IsRunning())
109 if (pipeline_->IsRunning()) { 109 return;
110 EXPECT_CALL(*demuxer_, Stop(_))
111 .WillOnce(RunClosure<0>());
112 110
113 if (audio_stream_) 111 ExpectStop();
114 EXPECT_CALL(*audio_renderer_, Stop(_))
115 .WillOnce(RunClosure<0>());
116
117 if (video_stream_)
118 EXPECT_CALL(*video_renderer_, Stop(_))
119 .WillOnce(RunClosure<0>());
120 }
121 112
122 // Expect a stop callback if we were started. 113 // Expect a stop callback if we were started.
123 EXPECT_CALL(callbacks_, OnStop()); 114 EXPECT_CALL(callbacks_, OnStop());
124 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, 115 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop,
125 base::Unretained(&callbacks_))); 116 base::Unretained(&callbacks_)));
126 message_loop_.RunUntilIdle(); 117 message_loop_.RunUntilIdle();
127
128 filter_collection_.reset();
129 pipeline_.reset();
130 } 118 }
131 119
132 protected: 120 protected:
133 // Sets up expectations to allow the demuxer to initialize. 121 // Sets up expectations to allow the demuxer to initialize.
134 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; 122 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector;
135 void InitializeDemuxer(MockDemuxerStreamVector* streams, 123 void InitializeDemuxer(MockDemuxerStreamVector* streams,
136 const base::TimeDelta& duration) { 124 const base::TimeDelta& duration) {
137 EXPECT_CALL(callbacks_, OnDurationChange()); 125 EXPECT_CALL(callbacks_, OnDurationChange());
138 EXPECT_CALL(*demuxer_, Initialize(_, _)) 126 EXPECT_CALL(*demuxer_, Initialize(_, _))
139 .WillOnce(DoAll(SetDemuxerProperties(duration), 127 .WillOnce(DoAll(SetDemuxerProperties(duration),
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 pipeline_->Seek(seek_time, 266 pipeline_->Seek(seek_time,
279 base::Bind(&CallbackHelper::OnSeek, 267 base::Bind(&CallbackHelper::OnSeek,
280 base::Unretained(&callbacks_))); 268 base::Unretained(&callbacks_)));
281 269
282 // We expect the time to be updated only after the seek has completed. 270 // We expect the time to be updated only after the seek has completed.
283 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); 271 EXPECT_NE(seek_time, pipeline_->GetMediaTime());
284 message_loop_.RunUntilIdle(); 272 message_loop_.RunUntilIdle();
285 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); 273 EXPECT_EQ(seek_time, pipeline_->GetMediaTime());
286 } 274 }
287 275
276 void ExpectStop() {
277 if (demuxer_)
acolwell GONE FROM CHROMIUM 2013/06/05 01:09:05 nit: Add { } here and below since these take up mu
scherkus (not reviewing) 2013/06/05 18:40:43 actually all of these can fit on a single line
278 EXPECT_CALL(*demuxer_, Stop(_))
279 .WillOnce(RunClosure<0>());
280
281 if (audio_stream_)
282 EXPECT_CALL(*audio_renderer_, Stop(_))
283 .WillOnce(RunClosure<0>());
284
285 if (video_stream_)
286 EXPECT_CALL(*video_renderer_, Stop(_))
287 .WillOnce(RunClosure<0>());
288 }
289
288 // Fixture members. 290 // Fixture members.
289 StrictMock<CallbackHelper> callbacks_; 291 StrictMock<CallbackHelper> callbacks_;
290 base::SimpleTestClock test_clock_; 292 base::SimpleTestClock test_clock_;
291 base::MessageLoop message_loop_; 293 base::MessageLoop message_loop_;
292 scoped_ptr<Pipeline> pipeline_; 294 scoped_ptr<Pipeline> pipeline_;
293 295
294 scoped_ptr<FilterCollection> filter_collection_; 296 scoped_ptr<FilterCollection> filter_collection_;
295 scoped_ptr<MockDemuxer> demuxer_; 297 scoped_ptr<MockDemuxer> demuxer_;
296 MockVideoRenderer* video_renderer_; 298 MockVideoRenderer* video_renderer_;
297 MockAudioRenderer* audio_renderer_; 299 MockAudioRenderer* audio_renderer_;
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); 831 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time);
830 832
831 // Now that the seek is complete, verify that time updates advance the current 833 // Now that the seek is complete, verify that time updates advance the current
832 // time. 834 // time.
833 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); 835 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100);
834 audio_time_cb_.Run(new_time, new_time); 836 audio_time_cb_.Run(new_time, new_time);
835 837
836 EXPECT_EQ(pipeline_->GetMediaTime(), new_time); 838 EXPECT_EQ(pipeline_->GetMediaTime(), new_time);
837 } 839 }
838 840
841 static void DeletePipeline(scoped_ptr<Pipeline> pipeline) {
842 // |pipeline| will go out of scope.
843 }
844
845 TEST_F(PipelineTest, DeleteAfterStop) {
846 CreateAudioStream();
847 MockDemuxerStreamVector streams;
848 streams.push_back(audio_stream());
849 InitializeDemuxer(&streams);
850 InitializeAudioRenderer(audio_stream(), false);
851 InitializePipeline(PIPELINE_OK);
852
853 ExpectStop();
854
855 pipeline_->Stop(base::Bind(&DeletePipeline, base::Passed(&pipeline_)));
acolwell GONE FROM CHROMIUM 2013/06/05 01:09:05 Whoa... how is this not crashing? Isn't the Passed
scherkus (not reviewing) 2013/06/05 18:40:43 Turns out it _is_ crashing! (check out try bot res
856 message_loop_.RunUntilIdle();
857 }
858
839 class PipelineTeardownTest : public PipelineTest { 859 class PipelineTeardownTest : public PipelineTest {
840 public: 860 public:
841 enum TeardownState { 861 enum TeardownState {
842 kInitDemuxer, 862 kInitDemuxer,
843 kInitAudioRenderer, 863 kInitAudioRenderer,
844 kInitVideoRenderer, 864 kInitVideoRenderer,
845 kPausing, 865 kPausing,
846 kFlushing, 866 kFlushing,
847 kSeeking, 867 kSeeking,
848 kPrerolling, 868 kPrerolling,
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); 1172 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer);
1153 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); 1173 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer);
1154 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); 1174 INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
1155 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 1175 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1156 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1176 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1157 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); 1177 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
1158 INSTANTIATE_TEARDOWN_TEST(Error, Starting); 1178 INSTANTIATE_TEARDOWN_TEST(Error, Starting);
1159 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1179 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1160 1180
1161 } // namespace media 1181 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | webkit/mocks/test_media_stream_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698