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. | 6 // actions if you need interesting side-effects. |
7 // | 7 // |
8 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock | 8 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock |
9 // filters to fail the test or do nothing when an unexpected method is called. | 9 // filters to fail the test or do nothing when an unexpected method is called. |
10 // http://code.google.com/p/googlemock/wiki/CookBook#Nice_Mocks_and_Strict_Mocks | 10 // http://code.google.com/p/googlemock/wiki/CookBook#Nice_Mocks_and_Strict_Mocks |
11 | 11 |
12 #ifndef MEDIA_BASE_MOCK_FILTERS_H_ | 12 #ifndef MEDIA_BASE_MOCK_FILTERS_H_ |
13 #define MEDIA_BASE_MOCK_FILTERS_H_ | 13 #define MEDIA_BASE_MOCK_FILTERS_H_ |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "media/base/audio_decoder.h" | 18 #include "media/base/audio_decoder.h" |
19 #include "media/base/audio_decoder_config.h" | 19 #include "media/base/audio_decoder_config.h" |
20 #include "media/base/audio_renderer.h" | 20 #include "media/base/audio_renderer.h" |
21 #include "media/base/decoder_buffer.h" | 21 #include "media/base/decoder_buffer.h" |
22 #include "media/base/decryptor.h" | 22 #include "media/base/decryptor.h" |
23 #include "media/base/decryptor_client.h" | |
24 #include "media/base/demuxer.h" | 23 #include "media/base/demuxer.h" |
25 #include "media/base/filter_collection.h" | 24 #include "media/base/filter_collection.h" |
26 #include "media/base/pipeline_status.h" | 25 #include "media/base/pipeline_status.h" |
27 #include "media/base/video_decoder.h" | 26 #include "media/base/video_decoder.h" |
28 #include "media/base/video_decoder_config.h" | 27 #include "media/base/video_decoder_config.h" |
29 #include "media/base/video_frame.h" | 28 #include "media/base/video_frame.h" |
30 #include "media/base/video_renderer.h" | 29 #include "media/base/video_renderer.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
32 | 31 |
33 namespace media { | 32 namespace media { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 const uint8* init_data, | 200 const uint8* init_data, |
202 int init_data_length)); | 201 int init_data_length)); |
203 MOCK_METHOD6(AddKey, void(const std::string& key_system, | 202 MOCK_METHOD6(AddKey, void(const std::string& key_system, |
204 const uint8* key, | 203 const uint8* key, |
205 int key_length, | 204 int key_length, |
206 const uint8* init_data, | 205 const uint8* init_data, |
207 int init_data_length, | 206 int init_data_length, |
208 const std::string& session_id)); | 207 const std::string& session_id)); |
209 MOCK_METHOD2(CancelKeyRequest, void(const std::string& key_system, | 208 MOCK_METHOD2(CancelKeyRequest, void(const std::string& key_system, |
210 const std::string& session_id)); | 209 const std::string& session_id)); |
211 MOCK_METHOD2(RegisterKeyAddedCB, void(StreamType stream_type, | 210 MOCK_METHOD2(RegisterNewKeyCB, void(StreamType stream_type, |
212 const KeyAddedCB& key_added_cb)); | 211 const NewKeyCB& new_key_cb)); |
213 MOCK_METHOD3(Decrypt, void(StreamType stream_type, | 212 MOCK_METHOD3(Decrypt, void(StreamType stream_type, |
214 const scoped_refptr<DecoderBuffer>& encrypted, | 213 const scoped_refptr<DecoderBuffer>& encrypted, |
215 const DecryptCB& decrypt_cb)); | 214 const DecryptCB& decrypt_cb)); |
216 MOCK_METHOD1(CancelDecrypt, void(StreamType stream_type)); | 215 MOCK_METHOD1(CancelDecrypt, void(StreamType stream_type)); |
217 // TODO(xhwang): The following two methods are workarounds of the issue that | 216 // TODO(xhwang): The following two methods are workarounds of the issue that |
218 // move-only parameters are not supported in mocked methods. Remove when the | 217 // move-only parameters are not supported in mocked methods. Remove when the |
219 // issue is fixed: http://code.google.com/p/googletest/issues/detail?id=395 | 218 // issue is fixed: http://code.google.com/p/googletest/issues/detail?id=395 |
220 MOCK_METHOD2(InitializeAudioDecoderMock, | 219 MOCK_METHOD2(InitializeAudioDecoderMock, |
221 void(const AudioDecoderConfig& config, | 220 void(const AudioDecoderConfig& config, |
222 const DecoderInitCB& init_cb)); | 221 const DecoderInitCB& init_cb)); |
(...skipping 11 matching lines...) Expand all Loading... |
234 | 233 |
235 virtual void InitializeAudioDecoder(scoped_ptr<AudioDecoderConfig> config, | 234 virtual void InitializeAudioDecoder(scoped_ptr<AudioDecoderConfig> config, |
236 const DecoderInitCB& init_cb) OVERRIDE; | 235 const DecoderInitCB& init_cb) OVERRIDE; |
237 virtual void InitializeVideoDecoder(scoped_ptr<VideoDecoderConfig> config, | 236 virtual void InitializeVideoDecoder(scoped_ptr<VideoDecoderConfig> config, |
238 const DecoderInitCB& init_cb) OVERRIDE; | 237 const DecoderInitCB& init_cb) OVERRIDE; |
239 | 238 |
240 private: | 239 private: |
241 DISALLOW_COPY_AND_ASSIGN(MockDecryptor); | 240 DISALLOW_COPY_AND_ASSIGN(MockDecryptor); |
242 }; | 241 }; |
243 | 242 |
244 class MockDecryptorClient : public DecryptorClient { | |
245 public: | |
246 MockDecryptorClient(); | |
247 virtual ~MockDecryptorClient(); | |
248 | |
249 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); | |
250 MOCK_METHOD4(KeyError, void(const std::string&, const std::string&, | |
251 Decryptor::KeyError, int)); | |
252 MOCK_METHOD4(KeyMessage, void(const std::string& key_system, | |
253 const std::string& session_id, | |
254 const std::string& message, | |
255 const std::string& default_url)); | |
256 // TODO(xhwang): This is a workaround of the issue that move-only parameters | |
257 // are not supported in mocked methods. Remove this when the issue is fixed | |
258 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use | |
259 // std::string instead of scoped_array<uint8> (http://crbug.com/130689). | |
260 MOCK_METHOD5(NeedKeyMock, void(const std::string& key_system, | |
261 const std::string& session_id, | |
262 const std::string& type, | |
263 const uint8* init_data, | |
264 int init_data_length)); | |
265 virtual void NeedKey(const std::string& key_system, | |
266 const std::string& session_id, | |
267 const std::string& type, | |
268 scoped_array<uint8> init_data, | |
269 int init_data_length) OVERRIDE; | |
270 | |
271 private: | |
272 DISALLOW_COPY_AND_ASSIGN(MockDecryptorClient); | |
273 }; | |
274 | |
275 // FilterFactory that returns canned instances of mock filters. You can set | 243 // FilterFactory that returns canned instances of mock filters. You can set |
276 // expectations on the filters and then pass the collection into a pipeline. | 244 // expectations on the filters and then pass the collection into a pipeline. |
277 class MockFilterCollection { | 245 class MockFilterCollection { |
278 public: | 246 public: |
279 MockFilterCollection(); | 247 MockFilterCollection(); |
280 virtual ~MockFilterCollection(); | 248 virtual ~MockFilterCollection(); |
281 | 249 |
282 // Mock accessors. | 250 // Mock accessors. |
283 MockDemuxer* demuxer() const { return demuxer_; } | 251 MockDemuxer* demuxer() const { return demuxer_; } |
284 MockVideoDecoder* video_decoder() const { return video_decoder_; } | 252 MockVideoDecoder* video_decoder() const { return video_decoder_; } |
(...skipping 19 matching lines...) Expand all Loading... |
304 public: | 272 public: |
305 MockStatisticsCB(); | 273 MockStatisticsCB(); |
306 ~MockStatisticsCB(); | 274 ~MockStatisticsCB(); |
307 | 275 |
308 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 276 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
309 }; | 277 }; |
310 | 278 |
311 } // namespace media | 279 } // namespace media |
312 | 280 |
313 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 281 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |