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

Side by Side Diff: media/base/mock_filters.h

Issue 9860027: Remove DemuxerFactory and URL parameter from Pipeline. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: fix prerender Created 8 years, 8 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 // A new breed of mock media filters, this time using gmock! Feel free to add 5 // A new breed of mock media filters, this time using gmock! Feel free to add
6 // actions if you need interesting side-effects (i.e., copying data to the 6 // actions if you need interesting side-effects (i.e., copying data to the
7 // buffer passed into MockDataSource::Read()). 7 // buffer passed into MockDataSource::Read()).
8 // 8 //
9 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock 9 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock
10 // filters to fail the test or do nothing when an unexpected method is called. 10 // filters to fail the test or do nothing when an unexpected method is called.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 int64 total_bytes_; 98 int64 total_bytes_;
99 int64 buffered_bytes_; 99 int64 buffered_bytes_;
100 100
101 DISALLOW_COPY_AND_ASSIGN(MockDataSource); 101 DISALLOW_COPY_AND_ASSIGN(MockDataSource);
102 }; 102 };
103 103
104 class MockDemuxer : public Demuxer { 104 class MockDemuxer : public Demuxer {
105 public: 105 public:
106 MockDemuxer(); 106 MockDemuxer();
107 107
108 MOCK_METHOD1(Initialize, void(const PipelineStatusCB& cb));
108 virtual void set_host(DemuxerHost* demuxer_host); 109 virtual void set_host(DemuxerHost* demuxer_host);
109 MOCK_METHOD1(Stop, void(const base::Closure& callback)); 110 MOCK_METHOD1(Stop, void(const base::Closure& callback));
110 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); 111 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
111 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); 112 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb));
112 MOCK_METHOD0(OnAudioRendererDisabled, void()); 113 MOCK_METHOD0(OnAudioRendererDisabled, void());
113 MOCK_METHOD0(GetBitrate, int()); 114 MOCK_METHOD0(GetBitrate, int());
114 MOCK_METHOD0(IsLocalSource, bool()); 115 MOCK_METHOD0(IsLocalSource, bool());
115 MOCK_METHOD0(IsSeekable, bool()); 116 MOCK_METHOD0(IsSeekable, bool());
116 117
117 // Demuxer implementation. 118 // Demuxer implementation.
(...skipping 11 matching lines...) Expand all
129 virtual ~MockDemuxer(); 130 virtual ~MockDemuxer();
130 131
131 private: 132 private:
132 int64 total_bytes_; 133 int64 total_bytes_;
133 int64 buffered_bytes_; 134 int64 buffered_bytes_;
134 base::TimeDelta duration_; 135 base::TimeDelta duration_;
135 136
136 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); 137 DISALLOW_COPY_AND_ASSIGN(MockDemuxer);
137 }; 138 };
138 139
139 class MockDemuxerFactory : public DemuxerFactory {
140 public:
141 explicit MockDemuxerFactory(MockDemuxer* demuxer);
142 virtual ~MockDemuxerFactory();
143
144 void SetError(PipelineStatus error);
145 void RunBuildCallback(const std::string& url, const BuildCallback& callback);
146
147 // DemuxerFactory methods.
148 MOCK_METHOD2(Build, void(const std::string& url,
149 const BuildCallback& callback));
150
151 private:
152 scoped_refptr<MockDemuxer> demuxer_;
153 PipelineStatus status_;
154
155 DISALLOW_COPY_AND_ASSIGN(MockDemuxerFactory);
156 };
157
158 class MockDemuxerStream : public DemuxerStream { 140 class MockDemuxerStream : public DemuxerStream {
159 public: 141 public:
160 MockDemuxerStream(); 142 MockDemuxerStream();
161 143
162 // DemuxerStream implementation. 144 // DemuxerStream implementation.
163 MOCK_METHOD0(type, Type()); 145 MOCK_METHOD0(type, Type());
164 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); 146 MOCK_METHOD1(Read, void(const ReadCB& read_cb));
165 MOCK_METHOD0(audio_decoder_config, const AudioDecoderConfig&()); 147 MOCK_METHOD0(audio_decoder_config, const AudioDecoderConfig&());
166 MOCK_METHOD0(video_decoder_config, const VideoDecoderConfig&()); 148 MOCK_METHOD0(video_decoder_config, const VideoDecoderConfig&());
167 MOCK_METHOD0(EnableBitstreamConverter, void()); 149 MOCK_METHOD0(EnableBitstreamConverter, void());
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 MockFilterCollection(); 265 MockFilterCollection();
284 virtual ~MockFilterCollection(); 266 virtual ~MockFilterCollection();
285 267
286 // Mock accessors. 268 // Mock accessors.
287 MockDemuxer* demuxer() const { return demuxer_; } 269 MockDemuxer* demuxer() const { return demuxer_; }
288 MockVideoDecoder* video_decoder() const { return video_decoder_; } 270 MockVideoDecoder* video_decoder() const { return video_decoder_; }
289 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } 271 MockAudioDecoder* audio_decoder() const { return audio_decoder_; }
290 MockVideoRenderer* video_renderer() const { return video_renderer_; } 272 MockVideoRenderer* video_renderer() const { return video_renderer_; }
291 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } 273 MockAudioRenderer* audio_renderer() const { return audio_renderer_; }
292 274
293 scoped_ptr<FilterCollection> filter_collection() const { 275 // Creates the FilterCollection containing the mocks.
294 return filter_collection(true, true, true, PIPELINE_OK).Pass(); 276 scoped_ptr<FilterCollection> Create();
295 }
296
297 scoped_ptr<FilterCollection> filter_collection(
298 bool include_demuxer, bool run_build_cb, bool run_build,
299 PipelineStatus build_status) const;
300 277
301 private: 278 private:
302 scoped_refptr<MockDemuxer> demuxer_; 279 scoped_refptr<MockDemuxer> demuxer_;
303 scoped_refptr<MockVideoDecoder> video_decoder_; 280 scoped_refptr<MockVideoDecoder> video_decoder_;
304 scoped_refptr<MockAudioDecoder> audio_decoder_; 281 scoped_refptr<MockAudioDecoder> audio_decoder_;
305 scoped_refptr<MockVideoRenderer> video_renderer_; 282 scoped_refptr<MockVideoRenderer> video_renderer_;
306 scoped_refptr<MockAudioRenderer> audio_renderer_; 283 scoped_refptr<MockAudioRenderer> audio_renderer_;
307 284
308 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); 285 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection);
309 }; 286 };
310 287
311 // Helper gmock functions that immediately executes and destroys the 288 // Helper gmock functions that immediately executes and destroys the
312 // Closure on behalf of the provided filter. Can be used when mocking 289 // Closure on behalf of the provided filter. Can be used when mocking
313 // the Initialize() and Seek() methods. 290 // the Initialize() and Seek() methods.
314 void RunFilterCallback(::testing::Unused, const base::Closure& closure); 291 void RunFilterCallback(::testing::Unused, const base::Closure& closure);
315 void RunPipelineStatusCB(::testing::Unused, const PipelineStatusCB& status_cb); 292 void RunPipelineStatusCB(const PipelineStatusCB& status_cb);
293 void RunPipelineStatusCB2(::testing::Unused, const PipelineStatusCB& status_cb);
316 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, 294 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb,
317 ::testing::Unused); 295 ::testing::Unused);
318 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, 296 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb,
319 ::testing::Unused, ::testing::Unused); 297 ::testing::Unused, ::testing::Unused);
320 // Helper gmock function that immediately executes the Closure on behalf of the 298 // Helper gmock function that immediately executes the Closure on behalf of the
321 // provided filter. Can be used when mocking the Stop() method. 299 // provided filter. Can be used when mocking the Stop() method.
322 void RunStopFilterCallback(const base::Closure& closure); 300 void RunStopFilterCallback(const base::Closure& closure);
323 301
302 ACTION_P(RunPipelineStatusCBWithError, error) {
303 arg0.Run(error);
304 }
305
324 // Helper gmock action that calls SetError() on behalf of the provided filter. 306 // Helper gmock action that calls SetError() on behalf of the provided filter.
325 ACTION_P2(SetError, filter, error) { 307 ACTION_P2(SetError, filter, error) {
326 filter->host()->SetError(error); 308 filter->host()->SetError(error);
327 } 309 }
328 310
329 // Helper gmock action that calls SetDuration() on behalf of the provided 311 // Helper gmock action that calls SetDuration() on behalf of the provided
330 // filter. 312 // filter.
331 ACTION_P2(SetDuration, filter, duration) { 313 ACTION_P2(SetDuration, filter, duration) {
332 filter->host()->SetDuration(duration); 314 filter->host()->SetDuration(duration);
333 } 315 }
334 316
335 // Helper gmock action that calls DisableAudioRenderer() on behalf of the 317 // Helper gmock action that calls DisableAudioRenderer() on behalf of the
336 // provided filter. 318 // provided filter.
337 ACTION_P(DisableAudioRenderer, filter) { 319 ACTION_P(DisableAudioRenderer, filter) {
338 filter->host()->DisableAudioRenderer(); 320 filter->host()->DisableAudioRenderer();
339 } 321 }
340 322
341 // Helper mock statistics callback. 323 // Helper mock statistics callback.
342 class MockStatisticsCB { 324 class MockStatisticsCB {
343 public: 325 public:
344 MockStatisticsCB(); 326 MockStatisticsCB();
345 ~MockStatisticsCB(); 327 ~MockStatisticsCB();
346 328
347 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); 329 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics));
348 }; 330 };
349 331
350 } // namespace media 332 } // namespace media
351 333
352 #endif // MEDIA_BASE_MOCK_FILTERS_H_ 334 #endif // MEDIA_BASE_MOCK_FILTERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698