| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | |
| 2 // source code is governed by a BSD-style license that can be found in the | |
| 3 // LICENSE file. | |
| 4 | |
| 5 // Mock implementation of Pipeline. Simply provides getters/setters for every | |
| 6 // pipeline state variable and queues all tasks posted to the "pipeline thread." | |
| 7 // Since there actually isn't a separate thread unit tests can control when | |
| 8 // they want to execute queued tasks by calling RunAllTasks(), which helps to | |
| 9 // assert pre- and post-conditions. | |
| 10 | |
| 11 #ifndef MEDIA_BASE_MOCK_PIPELINE_H_ | |
| 12 #define MEDIA_BASE_MOCK_PIPELINE_H_ | |
| 13 | |
| 14 #include <deque> | |
| 15 #include <string> | |
| 16 | |
| 17 #include "base/message_loop.h" | |
| 18 #include "media/base/media_format.h" | |
| 19 #include "media/base/pipeline.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 namespace media { | |
| 23 | |
| 24 class MockPipeline : public media::Pipeline { | |
| 25 public: | |
| 26 MockPipeline() { | |
| 27 Reset(false); | |
| 28 } | |
| 29 | |
| 30 virtual ~MockPipeline() {} | |
| 31 | |
| 32 // Implementation of PipelineStatus interface. | |
| 33 virtual bool IsInitialized() const { | |
| 34 return initialized_; | |
| 35 } | |
| 36 | |
| 37 virtual base::TimeDelta GetDuration() const { | |
| 38 return duration_; | |
| 39 } | |
| 40 | |
| 41 virtual base::TimeDelta GetBufferedTime() const { | |
| 42 return buffered_time_; | |
| 43 } | |
| 44 | |
| 45 virtual int64 GetTotalBytes() const { | |
| 46 return total_bytes_; | |
| 47 } | |
| 48 | |
| 49 virtual int64 GetBufferedBytes() const { | |
| 50 return buffered_bytes_; | |
| 51 } | |
| 52 | |
| 53 virtual void GetVideoSize(size_t* width_out, size_t* height_out) const { | |
| 54 *width_out = width_; | |
| 55 *height_out = height_; | |
| 56 } | |
| 57 | |
| 58 virtual float GetVolume() const { | |
| 59 return volume_; | |
| 60 } | |
| 61 | |
| 62 virtual float GetPlaybackRate() const { | |
| 63 return playback_rate_; | |
| 64 } | |
| 65 | |
| 66 virtual base::TimeDelta GetTime() const { | |
| 67 return time_; | |
| 68 } | |
| 69 | |
| 70 virtual base::TimeDelta GetInterpolatedTime() const { | |
| 71 return time_; | |
| 72 } | |
| 73 | |
| 74 virtual PipelineError GetError() const { | |
| 75 return error_; | |
| 76 } | |
| 77 | |
| 78 virtual bool IsRendered(const std::string&) const { | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 // Implementation of Pipeline interface. | |
| 83 virtual bool Start(FilterFactory* filter_factory, | |
| 84 const std::string& url, | |
| 85 PipelineCallback* init_complete_callback) { | |
| 86 EXPECT_FALSE(initialized_); | |
| 87 initialized_ = true; | |
| 88 if (init_complete_callback) { | |
| 89 init_complete_callback->Run(true); | |
| 90 delete init_complete_callback; | |
| 91 } | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 virtual void Stop() { | |
| 96 EXPECT_TRUE(initialized_ || error_ != media::PIPELINE_OK); | |
| 97 Reset(false); | |
| 98 } | |
| 99 | |
| 100 virtual void SetPlaybackRate(float playback_rate) { | |
| 101 playback_rate_ = playback_rate; | |
| 102 } | |
| 103 | |
| 104 virtual void Seek(base::TimeDelta time, | |
| 105 PipelineCallback* seek_complete_callback) { | |
| 106 time_ = time; | |
| 107 } | |
| 108 | |
| 109 virtual void SetVolume(float volume) { | |
| 110 volume_ = volume; | |
| 111 } | |
| 112 | |
| 113 // Public methods used by tests and by MockFilterHost to manipulate the | |
| 114 // state of the mock pipeline. | |
| 115 | |
| 116 // Set the state to the same as a newly created MockPipeline. If | |
| 117 // |reset_to_initialized| is true then the pipeline's |initialized_| state | |
| 118 // will be true when this method returns. | |
| 119 void Reset(bool reset_to_initialized) { | |
| 120 error_ = media::PIPELINE_OK; | |
| 121 volume_ = 1.0f; | |
| 122 playback_rate_ = 0.0f; | |
| 123 initialized_ = reset_to_initialized; | |
| 124 time_ = base::TimeDelta(); | |
| 125 duration_ = base::TimeDelta(); | |
| 126 buffered_time_ = base::TimeDelta(); | |
| 127 width_ = 0; | |
| 128 height_ = 0; | |
| 129 buffered_bytes_ = 0; | |
| 130 total_bytes_ = 0; | |
| 131 } | |
| 132 | |
| 133 void Error(media::PipelineError error) { | |
| 134 initialized_ = false; | |
| 135 error_ = error; | |
| 136 } | |
| 137 | |
| 138 void SetTime(base::TimeDelta time) { | |
| 139 time_ = time; | |
| 140 } | |
| 141 | |
| 142 virtual void SetDuration(base::TimeDelta duration) { | |
| 143 duration_ = duration; | |
| 144 } | |
| 145 | |
| 146 virtual void SetBufferedTime(base::TimeDelta buffered_time) { | |
| 147 buffered_time = buffered_time; | |
| 148 } | |
| 149 | |
| 150 virtual void SetTotalBytes(int64 total_bytes) { | |
| 151 total_bytes_ = total_bytes; | |
| 152 } | |
| 153 | |
| 154 virtual void SetBufferedBytes(int64 buffered_bytes) { | |
| 155 buffered_bytes_ = buffered_bytes; | |
| 156 } | |
| 157 | |
| 158 virtual void SetVideoSize(size_t width, size_t height) { | |
| 159 width_ = width; | |
| 160 height_ = height; | |
| 161 } | |
| 162 | |
| 163 private: | |
| 164 PipelineError error_; | |
| 165 float volume_; | |
| 166 float playback_rate_; | |
| 167 bool initialized_; | |
| 168 base::TimeDelta time_; | |
| 169 base::TimeDelta duration_; | |
| 170 base::TimeDelta buffered_time_; | |
| 171 size_t width_; | |
| 172 size_t height_; | |
| 173 int64 buffered_bytes_; | |
| 174 int64 total_bytes_; | |
| 175 | |
| 176 DISALLOW_COPY_AND_ASSIGN(MockPipeline); | |
| 177 }; | |
| 178 | |
| 179 } // namespace media | |
| 180 | |
| 181 #endif // MEDIA_BASE_MOCK_PIPELINE_H_ | |
| OLD | NEW |