| 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/demuxer.h" | 21 #include "media/base/demuxer.h" |
| 22 #include "media/base/filters.h" | 22 #include "media/base/filters.h" |
| 23 #include "media/base/filter_collection.h" | 23 #include "media/base/filter_collection.h" |
| 24 #include "media/base/pipeline.h" | 24 #include "media/base/pipeline.h" |
| 25 #include "media/base/video_decoder.h" | 25 #include "media/base/video_decoder.h" |
| 26 #include "media/base/video_decoder_config.h" | 26 #include "media/base/video_decoder_config.h" |
| 27 #include "media/base/video_frame.h" | 27 #include "media/base/video_frame.h" |
| 28 #include "media/base/video_renderer.h" | 28 #include "media/base/video_renderer.h" |
| 29 #include "media/crypto/decryptor_client.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 | 31 |
| 31 namespace media { | 32 namespace media { |
| 32 | 33 |
| 33 // Use this template to test for object destruction by setting expectations on | 34 // Use this template to test for object destruction by setting expectations on |
| 34 // the method OnDestroy(). | 35 // the method OnDestroy(). |
| 35 // | 36 // |
| 36 // TODO(scherkus): not sure about the naming... perhaps contribute this back | 37 // TODO(scherkus): not sure about the naming... perhaps contribute this back |
| 37 // to gmock itself! | 38 // to gmock itself! |
| 38 template<class MockClass> | 39 template<class MockClass> |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 203 |
| 203 MOCK_METHOD1(ResumeAfterUnderflow, void(bool buffer_more_audio)); | 204 MOCK_METHOD1(ResumeAfterUnderflow, void(bool buffer_more_audio)); |
| 204 | 205 |
| 205 protected: | 206 protected: |
| 206 virtual ~MockAudioRenderer(); | 207 virtual ~MockAudioRenderer(); |
| 207 | 208 |
| 208 private: | 209 private: |
| 209 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderer); | 210 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderer); |
| 210 }; | 211 }; |
| 211 | 212 |
| 213 class MockDecryptorClient : public DecryptorClient { |
| 214 public: |
| 215 MockDecryptorClient(); |
| 216 virtual ~MockDecryptorClient(); |
| 217 |
| 218 MOCK_METHOD2(KeyAdded, void(const std::string&, const std::string&)); |
| 219 MOCK_METHOD4(KeyError, void(const std::string&, const std::string&, |
| 220 AesDecryptor::KeyError, int)); |
| 221 // TODO(xhwang): This is a workaround of the issue that move-only parameters |
| 222 // are not supported in mocked methods. Remove this when the issue is fixed |
| 223 // (http://code.google.com/p/googletest/issues/detail?id=395) or when we use |
| 224 // std::string instead of scoped_array<uint8> (http://crbug.com/130689). |
| 225 MOCK_METHOD5(KeyMessageMock, void(const std::string& key_system, |
| 226 const std::string& session_id, |
| 227 const uint8* message, |
| 228 int message_length, |
| 229 const std::string& default_url)); |
| 230 MOCK_METHOD4(NeedKeyMock, void(const std::string& key_system, |
| 231 const std::string& session_id, |
| 232 const uint8* init_data, |
| 233 int init_data_length)); |
| 234 virtual void KeyMessage(const std::string& key_system, |
| 235 const std::string& session_id, |
| 236 scoped_array<uint8> message, |
| 237 int message_length, |
| 238 const std::string& default_url) OVERRIDE; |
| 239 virtual void NeedKey(const std::string& key_system, |
| 240 const std::string& session_id, |
| 241 scoped_array<uint8> init_data, |
| 242 int init_data_length) OVERRIDE; |
| 243 |
| 244 private: |
| 245 DISALLOW_COPY_AND_ASSIGN(MockDecryptorClient); |
| 246 }; |
| 247 |
| 212 // FilterFactory that returns canned instances of mock filters. You can set | 248 // FilterFactory that returns canned instances of mock filters. You can set |
| 213 // expectations on the filters and then pass the collection into a pipeline. | 249 // expectations on the filters and then pass the collection into a pipeline. |
| 214 class MockFilterCollection { | 250 class MockFilterCollection { |
| 215 public: | 251 public: |
| 216 MockFilterCollection(); | 252 MockFilterCollection(); |
| 217 virtual ~MockFilterCollection(); | 253 virtual ~MockFilterCollection(); |
| 218 | 254 |
| 219 // Mock accessors. | 255 // Mock accessors. |
| 220 MockDemuxer* demuxer() const { return demuxer_; } | 256 MockDemuxer* demuxer() const { return demuxer_; } |
| 221 MockVideoDecoder* video_decoder() const { return video_decoder_; } | 257 MockVideoDecoder* video_decoder() const { return video_decoder_; } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 public: | 307 public: |
| 272 MockStatisticsCB(); | 308 MockStatisticsCB(); |
| 273 ~MockStatisticsCB(); | 309 ~MockStatisticsCB(); |
| 274 | 310 |
| 275 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 311 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
| 276 }; | 312 }; |
| 277 | 313 |
| 278 } // namespace media | 314 } // namespace media |
| 279 | 315 |
| 280 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 316 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
| OLD | NEW |