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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 PipelineStatusCB& 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, int size, uint8* data, | 84 MOCK_METHOD4(Read, void(int64 position, int 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)); | |
88 MOCK_METHOD1(SetBitrate, void(int bitrate)); | 87 MOCK_METHOD1(SetBitrate, void(int bitrate)); |
89 MOCK_METHOD0(IsStreaming, bool()); | 88 MOCK_METHOD0(IsStreaming, bool()); |
90 | 89 |
91 // Sets the TotalBytes & BufferedBytes values to be sent to host() when | 90 // Sets the TotalBytes & BufferedBytes values to be sent to host() when |
92 // the set_host() is called. | 91 // the set_host() is called. |
93 void SetTotalAndBufferedBytes(int64 total_bytes, int64 buffered_bytes); | 92 void SetTotalAndBufferedBytes(int64 total_bytes, int64 buffered_bytes); |
94 | 93 |
95 protected: | 94 protected: |
96 virtual ~MockDataSource(); | 95 virtual ~MockDataSource(); |
97 | 96 |
98 private: | 97 private: |
99 int64 total_bytes_; | 98 int64 total_bytes_; |
100 int64 buffered_bytes_; | 99 int64 buffered_bytes_; |
101 | 100 |
102 DISALLOW_COPY_AND_ASSIGN(MockDataSource); | 101 DISALLOW_COPY_AND_ASSIGN(MockDataSource); |
103 }; | 102 }; |
104 | 103 |
105 class MockDemuxer : public Demuxer { | 104 class MockDemuxer : public Demuxer { |
106 public: | 105 public: |
107 MockDemuxer(); | 106 MockDemuxer(); |
108 | 107 |
| 108 MOCK_METHOD1(Initialize, void(const PipelineStatusCB& cb)); |
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)); | |
113 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); | 112 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
114 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 113 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
115 MOCK_METHOD0(GetBitrate, int()); | 114 MOCK_METHOD0(GetBitrate, int()); |
116 MOCK_METHOD0(IsLocalSource, bool()); | 115 MOCK_METHOD0(IsLocalSource, bool()); |
117 MOCK_METHOD0(IsSeekable, bool()); | 116 MOCK_METHOD0(IsSeekable, bool()); |
118 | 117 |
119 // Demuxer implementation. | 118 // Demuxer implementation. |
120 MOCK_METHOD2(Initialize, void(DataSource* data_source, | 119 MOCK_METHOD2(Initialize, void(DataSource* data_source, |
121 const base::Closure& callback)); | 120 const base::Closure& callback)); |
122 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); | 121 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); |
123 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); | 122 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); |
124 | 123 |
125 // Sets the TotalBytes, BufferedBytes, & Duration values to be sent to host() | 124 // Sets the TotalBytes, BufferedBytes, & Duration values to be sent to host() |
126 // when set_host() is called. | 125 // when set_host() is called. |
127 void SetTotalAndBufferedBytesAndDuration( | 126 void SetTotalAndBufferedBytesAndDuration( |
128 int64 total_bytes, int64 buffered_bytes, const base::TimeDelta& duration); | 127 int64 total_bytes, int64 buffered_bytes, const base::TimeDelta& duration); |
129 | 128 |
130 protected: | 129 protected: |
131 virtual ~MockDemuxer(); | 130 virtual ~MockDemuxer(); |
132 | 131 |
133 private: | 132 private: |
134 int64 total_bytes_; | 133 int64 total_bytes_; |
135 int64 buffered_bytes_; | 134 int64 buffered_bytes_; |
136 base::TimeDelta duration_; | 135 base::TimeDelta duration_; |
137 | 136 |
138 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); | 137 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); |
139 }; | 138 }; |
140 | 139 |
141 class MockDemuxerFactory : public DemuxerFactory { | |
142 public: | |
143 explicit MockDemuxerFactory(MockDemuxer* demuxer); | |
144 virtual ~MockDemuxerFactory(); | |
145 | |
146 void SetError(PipelineStatus error); | |
147 void RunBuildCallback(const std::string& url, const BuildCallback& callback); | |
148 | |
149 // DemuxerFactory methods. | |
150 MOCK_METHOD2(Build, void(const std::string& url, | |
151 const BuildCallback& callback)); | |
152 | |
153 private: | |
154 scoped_refptr<MockDemuxer> demuxer_; | |
155 PipelineStatus status_; | |
156 | |
157 DISALLOW_COPY_AND_ASSIGN(MockDemuxerFactory); | |
158 }; | |
159 | |
160 class MockDemuxerStream : public DemuxerStream { | 140 class MockDemuxerStream : public DemuxerStream { |
161 public: | 141 public: |
162 MockDemuxerStream(); | 142 MockDemuxerStream(); |
163 | 143 |
164 // DemuxerStream implementation. | 144 // DemuxerStream implementation. |
165 MOCK_METHOD0(type, Type()); | 145 MOCK_METHOD0(type, Type()); |
166 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); | 146 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); |
167 MOCK_METHOD0(audio_decoder_config, const AudioDecoderConfig&()); | 147 MOCK_METHOD0(audio_decoder_config, const AudioDecoderConfig&()); |
168 MOCK_METHOD0(video_decoder_config, const VideoDecoderConfig&()); | 148 MOCK_METHOD0(video_decoder_config, const VideoDecoderConfig&()); |
169 MOCK_METHOD0(EnableBitstreamConverter, void()); | 149 MOCK_METHOD0(EnableBitstreamConverter, void()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 MockFilterCollection(); | 265 MockFilterCollection(); |
286 virtual ~MockFilterCollection(); | 266 virtual ~MockFilterCollection(); |
287 | 267 |
288 // Mock accessors. | 268 // Mock accessors. |
289 MockDemuxer* demuxer() const { return demuxer_; } | 269 MockDemuxer* demuxer() const { return demuxer_; } |
290 MockVideoDecoder* video_decoder() const { return video_decoder_; } | 270 MockVideoDecoder* video_decoder() const { return video_decoder_; } |
291 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } | 271 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } |
292 MockVideoRenderer* video_renderer() const { return video_renderer_; } | 272 MockVideoRenderer* video_renderer() const { return video_renderer_; } |
293 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } | 273 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } |
294 | 274 |
295 scoped_ptr<FilterCollection> filter_collection() const { | 275 // Creates the FilterCollection containing the mocks. |
296 return filter_collection(true, true, true, PIPELINE_OK).Pass(); | 276 scoped_ptr<FilterCollection> Create(); |
297 } | |
298 | |
299 scoped_ptr<FilterCollection> filter_collection( | |
300 bool include_demuxer, bool run_build_cb, bool run_build, | |
301 PipelineStatus build_status) const; | |
302 | 277 |
303 private: | 278 private: |
304 scoped_refptr<MockDemuxer> demuxer_; | 279 scoped_refptr<MockDemuxer> demuxer_; |
305 scoped_refptr<MockVideoDecoder> video_decoder_; | 280 scoped_refptr<MockVideoDecoder> video_decoder_; |
306 scoped_refptr<MockAudioDecoder> audio_decoder_; | 281 scoped_refptr<MockAudioDecoder> audio_decoder_; |
307 scoped_refptr<MockVideoRenderer> video_renderer_; | 282 scoped_refptr<MockVideoRenderer> video_renderer_; |
308 scoped_refptr<MockAudioRenderer> audio_renderer_; | 283 scoped_refptr<MockAudioRenderer> audio_renderer_; |
309 | 284 |
310 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); | 285 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); |
311 }; | 286 }; |
312 | 287 |
313 // Helper gmock functions that immediately executes and destroys the | 288 // Helper gmock functions that immediately executes and destroys the |
314 // 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 |
315 // the Initialize() and Seek() methods. | 290 // the Initialize() and Seek() methods. |
316 void RunFilterCallback(::testing::Unused, const base::Closure& closure); | 291 void RunFilterCallback(::testing::Unused, const base::Closure& closure); |
317 void RunPipelineStatusCB(::testing::Unused, const PipelineStatusCB& status_cb); | 292 void RunPipelineStatusCB(const PipelineStatusCB& status_cb); |
| 293 void RunPipelineStatusCB2(::testing::Unused, const PipelineStatusCB& status_cb); |
318 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, | 294 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, |
319 ::testing::Unused); | 295 ::testing::Unused); |
320 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, | 296 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, |
321 ::testing::Unused, ::testing::Unused); | 297 ::testing::Unused, ::testing::Unused); |
322 // 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 |
323 // provided filter. Can be used when mocking the Stop() method. | 299 // provided filter. Can be used when mocking the Stop() method. |
324 void RunStopFilterCallback(const base::Closure& closure); | 300 void RunStopFilterCallback(const base::Closure& closure); |
325 | 301 |
| 302 ACTION_P(RunPipelineStatusCBWithError, error) { |
| 303 arg0.Run(error); |
| 304 } |
| 305 |
326 // 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. |
327 ACTION_P2(SetError, filter, error) { | 307 ACTION_P2(SetError, filter, error) { |
328 filter->host()->SetError(error); | 308 filter->host()->SetError(error); |
329 } | 309 } |
330 | 310 |
331 // Helper gmock action that calls SetDuration() on behalf of the provided | 311 // Helper gmock action that calls SetDuration() on behalf of the provided |
332 // filter. | 312 // filter. |
333 ACTION_P2(SetDuration, filter, duration) { | 313 ACTION_P2(SetDuration, filter, duration) { |
334 filter->host()->SetDuration(duration); | 314 filter->host()->SetDuration(duration); |
335 } | 315 } |
336 | 316 |
337 // Helper gmock action that calls DisableAudioRenderer() on behalf of the | 317 // Helper gmock action that calls DisableAudioRenderer() on behalf of the |
338 // provided filter. | 318 // provided filter. |
339 ACTION_P(DisableAudioRenderer, filter) { | 319 ACTION_P(DisableAudioRenderer, filter) { |
340 filter->host()->DisableAudioRenderer(); | 320 filter->host()->DisableAudioRenderer(); |
341 } | 321 } |
342 | 322 |
343 // Helper mock statistics callback. | 323 // Helper mock statistics callback. |
344 class MockStatisticsCB { | 324 class MockStatisticsCB { |
345 public: | 325 public: |
346 MockStatisticsCB(); | 326 MockStatisticsCB(); |
347 ~MockStatisticsCB(); | 327 ~MockStatisticsCB(); |
348 | 328 |
349 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 329 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
350 }; | 330 }; |
351 | 331 |
352 } // namespace media | 332 } // namespace media |
353 | 333 |
354 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 334 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |