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 // 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 class MockFilter : public Filter { | 52 class MockFilter : public Filter { |
53 public: | 53 public: |
54 MockFilter(); | 54 MockFilter(); |
55 | 55 |
56 // Filter implementation. | 56 // Filter implementation. |
57 MOCK_METHOD1(Play, void(const base::Closure& callback)); | 57 MOCK_METHOD1(Play, void(const base::Closure& callback)); |
58 MOCK_METHOD1(Pause, void(const base::Closure& callback)); | 58 MOCK_METHOD1(Pause, void(const base::Closure& callback)); |
59 MOCK_METHOD1(Flush, void(const base::Closure& callback)); | 59 MOCK_METHOD1(Flush, void(const base::Closure& callback)); |
60 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 60 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
61 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 61 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
62 MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); | 62 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
63 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 63 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
64 | 64 |
65 protected: | 65 protected: |
66 virtual ~MockFilter(); | 66 virtual ~MockFilter(); |
67 | 67 |
68 private: | 68 private: |
69 DISALLOW_COPY_AND_ASSIGN(MockFilter); | 69 DISALLOW_COPY_AND_ASSIGN(MockFilter); |
70 }; | 70 }; |
71 | 71 |
72 class MockDataSource : public DataSource { | 72 class MockDataSource : public DataSource { |
73 public: | 73 public: |
74 MockDataSource(); | 74 MockDataSource(); |
75 | 75 |
76 virtual void set_host(DataSourceHost* data_source_host); | 76 virtual void set_host(DataSourceHost* data_source_host); |
77 | 77 |
78 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 78 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
79 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 79 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
80 MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); | 80 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
81 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 81 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
82 | 82 |
83 // DataSource implementation. | 83 // DataSource implementation. |
84 MOCK_METHOD4(Read, void(int64 position, size_t size, uint8* data, | 84 MOCK_METHOD4(Read, void(int64 position, size_t size, uint8* data, |
85 const DataSource::ReadCB& callback)); | 85 const DataSource::ReadCB& callback)); |
86 MOCK_METHOD1(GetSize, bool(int64* size_out)); | 86 MOCK_METHOD1(GetSize, bool(int64* size_out)); |
87 MOCK_METHOD1(SetPreload, void(Preload preload)); | 87 MOCK_METHOD1(SetPreload, void(Preload preload)); |
88 MOCK_METHOD1(SetBitrate, void(int bitrate)); | 88 MOCK_METHOD1(SetBitrate, void(int bitrate)); |
89 MOCK_METHOD0(IsStreaming, bool()); | 89 MOCK_METHOD0(IsStreaming, bool()); |
90 | 90 |
(...skipping 12 matching lines...) Expand all Loading... |
103 }; | 103 }; |
104 | 104 |
105 class MockDemuxer : public Demuxer { | 105 class MockDemuxer : public Demuxer { |
106 public: | 106 public: |
107 MockDemuxer(); | 107 MockDemuxer(); |
108 | 108 |
109 virtual void set_host(DemuxerHost* demuxer_host); | 109 virtual void set_host(DemuxerHost* demuxer_host); |
110 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 110 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
111 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 111 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
112 MOCK_METHOD1(SetPreload, void(Preload preload)); | 112 MOCK_METHOD1(SetPreload, void(Preload preload)); |
113 MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); | 113 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
114 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 114 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
115 MOCK_METHOD0(GetBitrate, int()); | 115 MOCK_METHOD0(GetBitrate, int()); |
116 MOCK_METHOD0(IsLocalSource, bool()); | 116 MOCK_METHOD0(IsLocalSource, bool()); |
117 MOCK_METHOD0(IsSeekable, bool()); | 117 MOCK_METHOD0(IsSeekable, bool()); |
118 | 118 |
119 // Demuxer implementation. | 119 // Demuxer implementation. |
120 MOCK_METHOD2(Initialize, void(DataSource* data_source, | 120 MOCK_METHOD2(Initialize, void(DataSource* data_source, |
121 const base::Closure& callback)); | 121 const base::Closure& callback)); |
122 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); | 122 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); |
123 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); | 123 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 DISALLOW_COPY_AND_ASSIGN(MockDemuxerStream); | 175 DISALLOW_COPY_AND_ASSIGN(MockDemuxerStream); |
176 }; | 176 }; |
177 | 177 |
178 class MockVideoDecoder : public VideoDecoder { | 178 class MockVideoDecoder : public VideoDecoder { |
179 public: | 179 public: |
180 MockVideoDecoder(); | 180 MockVideoDecoder(); |
181 | 181 |
182 // Filter implementation. | 182 // Filter implementation. |
183 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 183 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
184 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 184 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
185 MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); | 185 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
186 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 186 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
187 | 187 |
188 // VideoDecoder implementation. | 188 // VideoDecoder implementation. |
189 MOCK_METHOD3(Initialize, void(DemuxerStream* stream, | 189 MOCK_METHOD3(Initialize, void(DemuxerStream* stream, |
190 const PipelineStatusCB& status_cb, | 190 const PipelineStatusCB& status_cb, |
191 const StatisticsCB& statistics_cb)); | 191 const StatisticsCB& statistics_cb)); |
192 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); | 192 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); |
193 MOCK_METHOD0(natural_size, const gfx::Size&()); | 193 MOCK_METHOD0(natural_size, const gfx::Size&()); |
194 MOCK_CONST_METHOD0(HasAlpha, bool()); | 194 MOCK_CONST_METHOD0(HasAlpha, bool()); |
195 | 195 |
(...skipping 26 matching lines...) Expand all Loading... |
222 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); | 222 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); |
223 }; | 223 }; |
224 | 224 |
225 class MockVideoRenderer : public VideoRenderer { | 225 class MockVideoRenderer : public VideoRenderer { |
226 public: | 226 public: |
227 MockVideoRenderer(); | 227 MockVideoRenderer(); |
228 | 228 |
229 // Filter implementation. | 229 // Filter implementation. |
230 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 230 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
231 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 231 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
232 MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); | 232 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
233 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 233 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
234 | 234 |
235 // VideoRenderer implementation. | 235 // VideoRenderer implementation. |
236 MOCK_METHOD4(Initialize, void(VideoDecoder* decoder, | 236 MOCK_METHOD4(Initialize, void(VideoDecoder* decoder, |
237 const PipelineStatusCB& status_cb, | 237 const PipelineStatusCB& status_cb, |
238 const StatisticsCB& statistics_cb, | 238 const StatisticsCB& statistics_cb, |
239 const TimeCB& time_cb)); | 239 const TimeCB& time_cb)); |
240 | 240 |
241 MOCK_METHOD0(HasEnded, bool()); | 241 MOCK_METHOD0(HasEnded, bool()); |
242 | 242 |
243 // TODO(scherkus): although VideoRendererBase defines this method, this really | 243 // TODO(scherkus): although VideoRendererBase defines this method, this really |
244 // shouldn't be here OR should be renamed. | 244 // shouldn't be here OR should be renamed. |
245 MOCK_METHOD1(ConsumeVideoFrame, void(scoped_refptr<VideoFrame> frame)); | 245 MOCK_METHOD1(ConsumeVideoFrame, void(scoped_refptr<VideoFrame> frame)); |
246 | 246 |
247 protected: | 247 protected: |
248 virtual ~MockVideoRenderer(); | 248 virtual ~MockVideoRenderer(); |
249 | 249 |
250 private: | 250 private: |
251 DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer); | 251 DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer); |
252 }; | 252 }; |
253 | 253 |
254 class MockAudioRenderer : public AudioRenderer { | 254 class MockAudioRenderer : public AudioRenderer { |
255 public: | 255 public: |
256 MockAudioRenderer(); | 256 MockAudioRenderer(); |
257 | 257 |
258 // Filter implementation. | 258 // Filter implementation. |
259 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 259 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
260 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 260 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
261 MOCK_METHOD2(Seek, void(base::TimeDelta time, const FilterStatusCB& cb)); | 261 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
262 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 262 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
263 | 263 |
264 // AudioRenderer implementation. | 264 // AudioRenderer implementation. |
265 MOCK_METHOD4(Initialize, void(const scoped_refptr<AudioDecoder>& decoder, | 265 MOCK_METHOD4(Initialize, void(const scoped_refptr<AudioDecoder>& decoder, |
266 const PipelineStatusCB& init_cb, | 266 const PipelineStatusCB& init_cb, |
267 const base::Closure& underflow_cb, | 267 const base::Closure& underflow_cb, |
268 const TimeCB& time_cb)); | 268 const TimeCB& time_cb)); |
269 MOCK_METHOD0(HasEnded, bool()); | 269 MOCK_METHOD0(HasEnded, bool()); |
270 MOCK_METHOD1(SetVolume, void(float volume)); | 270 MOCK_METHOD1(SetVolume, void(float volume)); |
271 | 271 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 scoped_refptr<MockAudioDecoder> audio_decoder_; | 306 scoped_refptr<MockAudioDecoder> audio_decoder_; |
307 scoped_refptr<MockVideoRenderer> video_renderer_; | 307 scoped_refptr<MockVideoRenderer> video_renderer_; |
308 scoped_refptr<MockAudioRenderer> audio_renderer_; | 308 scoped_refptr<MockAudioRenderer> audio_renderer_; |
309 | 309 |
310 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); | 310 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); |
311 }; | 311 }; |
312 | 312 |
313 // Helper gmock functions that immediately executes and destroys the | 313 // Helper gmock functions that immediately executes and destroys the |
314 // Closure on behalf of the provided filter. Can be used when mocking | 314 // Closure on behalf of the provided filter. Can be used when mocking |
315 // the Initialize() and Seek() methods. | 315 // the Initialize() and Seek() methods. |
316 void RunFilterCallback(::testing::Unused, const base::Closure& callback); | 316 void RunFilterCallback(::testing::Unused, const base::Closure& closure); |
317 void RunFilterStatusCB(::testing::Unused, const FilterStatusCB& cb); | 317 void RunPipelineStatusCB(::testing::Unused, const PipelineStatusCB& status_cb); |
318 void RunPipelineStatusCB(PipelineStatus status, const PipelineStatusCB& cb); | |
319 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, | 318 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, |
320 ::testing::Unused); | 319 ::testing::Unused); |
321 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, | 320 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, |
322 ::testing::Unused, ::testing::Unused); | 321 ::testing::Unused, ::testing::Unused); |
323 // Helper gmock function that immediately executes the Closure on behalf of the | 322 // Helper gmock function that immediately executes the Closure on behalf of the |
324 // provided filter. Can be used when mocking the Stop() method. | 323 // provided filter. Can be used when mocking the Stop() method. |
325 void RunStopFilterCallback(const base::Closure& callback); | 324 void RunStopFilterCallback(const base::Closure& closure); |
326 | 325 |
327 // Helper gmock action that calls SetError() on behalf of the provided filter. | 326 // Helper gmock action that calls SetError() on behalf of the provided filter. |
328 ACTION_P2(SetError, filter, error) { | 327 ACTION_P2(SetError, filter, error) { |
329 filter->host()->SetError(error); | 328 filter->host()->SetError(error); |
330 } | 329 } |
331 | 330 |
332 // Helper gmock action that calls SetDuration() on behalf of the provided | 331 // Helper gmock action that calls SetDuration() on behalf of the provided |
333 // filter. | 332 // filter. |
334 ACTION_P2(SetDuration, filter, duration) { | 333 ACTION_P2(SetDuration, filter, duration) { |
335 filter->host()->SetDuration(duration); | 334 filter->host()->SetDuration(duration); |
(...skipping 10 matching lines...) Expand all Loading... |
346 public: | 345 public: |
347 MockStatisticsCB(); | 346 MockStatisticsCB(); |
348 ~MockStatisticsCB(); | 347 ~MockStatisticsCB(); |
349 | 348 |
350 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 349 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
351 }; | 350 }; |
352 | 351 |
353 } // namespace media | 352 } // namespace media |
354 | 353 |
355 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 354 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |