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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Demuxer implementation. |
109 virtual void set_host(DemuxerHost* demuxer_host); | 109 MOCK_METHOD2(Initialize, void(DemuxerHost* host, const PipelineStatusCB& cb)); |
110 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | |
111 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 110 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
112 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); | 111 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
| 112 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
113 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 113 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
| 114 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); |
| 115 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); |
114 MOCK_METHOD0(GetBitrate, int()); | 116 MOCK_METHOD0(GetBitrate, int()); |
115 MOCK_METHOD0(IsLocalSource, bool()); | 117 MOCK_METHOD0(IsLocalSource, bool()); |
116 MOCK_METHOD0(IsSeekable, bool()); | 118 MOCK_METHOD0(IsSeekable, bool()); |
117 | 119 |
118 // Demuxer implementation. | |
119 MOCK_METHOD2(Initialize, void(DataSource* data_source, | |
120 const base::Closure& callback)); | |
121 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); | |
122 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); | |
123 | |
124 // Sets the TotalBytes, BufferedBytes, & Duration values to be sent to host() | |
125 // when set_host() is called. | |
126 void SetTotalAndBufferedBytesAndDuration( | |
127 int64 total_bytes, int64 buffered_bytes, const base::TimeDelta& duration); | |
128 | |
129 protected: | 120 protected: |
130 virtual ~MockDemuxer(); | 121 virtual ~MockDemuxer(); |
131 | 122 |
132 private: | 123 private: |
133 int64 total_bytes_; | |
134 int64 buffered_bytes_; | |
135 base::TimeDelta duration_; | |
136 | |
137 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); | 124 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); |
138 }; | 125 }; |
139 | 126 |
140 class MockDemuxerStream : public DemuxerStream { | 127 class MockDemuxerStream : public DemuxerStream { |
141 public: | 128 public: |
142 MockDemuxerStream(); | 129 MockDemuxerStream(); |
143 | 130 |
144 // DemuxerStream implementation. | 131 // DemuxerStream implementation. |
145 MOCK_METHOD0(type, Type()); | 132 MOCK_METHOD0(type, Type()); |
146 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); | 133 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 void RunPipelineStatusCB(const PipelineStatusCB& status_cb); | 279 void RunPipelineStatusCB(const PipelineStatusCB& status_cb); |
293 void RunPipelineStatusCB2(::testing::Unused, const PipelineStatusCB& status_cb); | 280 void RunPipelineStatusCB2(::testing::Unused, const PipelineStatusCB& status_cb); |
294 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, | 281 void RunPipelineStatusCB3(::testing::Unused, const PipelineStatusCB& status_cb, |
295 ::testing::Unused); | 282 ::testing::Unused); |
296 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, | 283 void RunPipelineStatusCB4(::testing::Unused, const PipelineStatusCB& status_cb, |
297 ::testing::Unused, ::testing::Unused); | 284 ::testing::Unused, ::testing::Unused); |
298 // Helper gmock function that immediately executes the Closure on behalf of the | 285 // Helper gmock function that immediately executes the Closure on behalf of the |
299 // provided filter. Can be used when mocking the Stop() method. | 286 // provided filter. Can be used when mocking the Stop() method. |
300 void RunStopFilterCallback(const base::Closure& closure); | 287 void RunStopFilterCallback(const base::Closure& closure); |
301 | 288 |
302 ACTION_P(RunPipelineStatusCBWithError, error) { | |
303 arg0.Run(error); | |
304 } | |
305 | |
306 // Helper gmock action that calls SetError() on behalf of the provided filter. | 289 // Helper gmock action that calls SetError() on behalf of the provided filter. |
307 ACTION_P2(SetError, filter, error) { | 290 ACTION_P2(SetError, filter, error) { |
308 filter->host()->SetError(error); | 291 filter->host()->SetError(error); |
309 } | 292 } |
310 | 293 |
311 // Helper gmock action that calls SetDuration() on behalf of the provided | 294 // Helper gmock action that calls SetDuration() on behalf of the provided |
312 // filter. | 295 // filter. |
313 ACTION_P2(SetDuration, filter, duration) { | 296 ACTION_P2(SetDuration, filter, duration) { |
314 filter->host()->SetDuration(duration); | 297 filter->host()->SetDuration(duration); |
315 } | 298 } |
316 | 299 |
317 // Helper gmock action that calls DisableAudioRenderer() on behalf of the | 300 // Helper gmock action that calls DisableAudioRenderer() on behalf of the |
318 // provided filter. | 301 // provided filter. |
319 ACTION_P(DisableAudioRenderer, filter) { | 302 ACTION_P(DisableAudioRenderer, filter) { |
320 filter->host()->DisableAudioRenderer(); | 303 filter->host()->DisableAudioRenderer(); |
321 } | 304 } |
322 | 305 |
323 // Helper mock statistics callback. | 306 // Helper mock statistics callback. |
324 class MockStatisticsCB { | 307 class MockStatisticsCB { |
325 public: | 308 public: |
326 MockStatisticsCB(); | 309 MockStatisticsCB(); |
327 ~MockStatisticsCB(); | 310 ~MockStatisticsCB(); |
328 | 311 |
329 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 312 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
330 }; | 313 }; |
331 | 314 |
332 } // namespace media | 315 } // namespace media |
333 | 316 |
334 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 317 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |