[ServiceWorker] Implement WebServiceWorkerContextClient::openWindow().
[chromium-blink-merge.git] / content / renderer / media / webrtc / mock_peer_connection_dependency_factory.h
blobb04282411c71f5bc1a2911d6eec52355a23c6196
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
15 #include "third_party/libjingle/source/talk/media/base/videorenderer.h"
17 namespace content {
19 class WebAudioCapturerSource;
20 typedef std::set<webrtc::ObserverInterface*> ObserverSet;
22 class MockVideoRenderer : public cricket::VideoRenderer {
23 public:
24 MockVideoRenderer();
25 ~MockVideoRenderer() override;
26 bool SetSize(int width, int height, int reserved) override;
27 bool RenderFrame(const cricket::VideoFrame* frame) override;
29 int width() const { return width_; }
30 int height() const { return height_; }
31 int num() const { return num_; }
33 private:
34 int width_;
35 int height_;
36 int num_;
39 class MockVideoSource : public webrtc::VideoSourceInterface {
40 public:
41 MockVideoSource();
43 void RegisterObserver(webrtc::ObserverInterface* observer) override;
44 void UnregisterObserver(webrtc::ObserverInterface* observer) override;
45 MediaSourceInterface::SourceState state() const override;
46 cricket::VideoCapturer* GetVideoCapturer() override;
47 void AddSink(cricket::VideoRenderer* output) override;
48 void RemoveSink(cricket::VideoRenderer* output) override;
49 cricket::VideoRenderer* FrameInput() override;
50 const cricket::VideoOptions* options() const override;
52 // Changes the state of the source to live and notifies the observer.
53 void SetLive();
54 // Changes the state of the source to ended and notifies the observer.
55 void SetEnded();
56 // Set the video capturer.
57 void SetVideoCapturer(cricket::VideoCapturer* capturer);
59 // Test helpers.
60 int GetLastFrameWidth() const;
61 int GetLastFrameHeight() const;
62 int GetFrameNum() const;
64 protected:
65 ~MockVideoSource() override;
67 private:
68 void FireOnChanged();
70 std::vector<webrtc::ObserverInterface*> observers_;
71 MediaSourceInterface::SourceState state_;
72 scoped_ptr<cricket::VideoCapturer> capturer_;
73 MockVideoRenderer renderer_;
76 class MockAudioSource : public webrtc::AudioSourceInterface {
77 public:
78 explicit MockAudioSource(
79 const webrtc::MediaConstraintsInterface* constraints);
81 void RegisterObserver(webrtc::ObserverInterface* observer) override;
82 void UnregisterObserver(webrtc::ObserverInterface* observer) override;
83 MediaSourceInterface::SourceState state() const override;
85 // Changes the state of the source to live and notifies the observer.
86 void SetLive();
87 // Changes the state of the source to ended and notifies the observer.
88 void SetEnded();
90 const webrtc::MediaConstraintsInterface::Constraints& optional_constraints() {
91 return optional_constraints_;
94 const webrtc::MediaConstraintsInterface::Constraints&
95 mandatory_constraints() {
96 return mandatory_constraints_;
99 protected:
100 ~MockAudioSource() override;
102 private:
103 ObserverSet observers_;
104 MediaSourceInterface::SourceState state_;
105 webrtc::MediaConstraintsInterface::Constraints optional_constraints_;
106 webrtc::MediaConstraintsInterface::Constraints mandatory_constraints_;
109 class MockWebRtcVideoTrack : public webrtc::VideoTrackInterface {
110 public:
111 MockWebRtcVideoTrack(const std::string& id,
112 webrtc::VideoSourceInterface* source);
113 void AddRenderer(webrtc::VideoRendererInterface* renderer) override;
114 void RemoveRenderer(webrtc::VideoRendererInterface* renderer) override;
115 std::string kind() const override;
116 std::string id() const override;
117 bool enabled() const override;
118 TrackState state() const override;
119 bool set_enabled(bool enable) override;
120 bool set_state(TrackState new_state) override;
121 void RegisterObserver(webrtc::ObserverInterface* observer) override;
122 void UnregisterObserver(webrtc::ObserverInterface* observer) override;
123 webrtc::VideoSourceInterface* GetSource() const override;
125 protected:
126 ~MockWebRtcVideoTrack() override;
128 private:
129 bool enabled_;
130 std::string id_;
131 TrackState state_;
132 scoped_refptr<webrtc::VideoSourceInterface> source_;
133 ObserverSet observers_;
134 webrtc::VideoRendererInterface* renderer_;
137 class MockMediaStream : public webrtc::MediaStreamInterface {
138 public:
139 explicit MockMediaStream(const std::string& label);
141 bool AddTrack(webrtc::AudioTrackInterface* track) override;
142 bool AddTrack(webrtc::VideoTrackInterface* track) override;
143 bool RemoveTrack(webrtc::AudioTrackInterface* track) override;
144 bool RemoveTrack(webrtc::VideoTrackInterface* track) override;
145 std::string label() const override;
146 webrtc::AudioTrackVector GetAudioTracks() override;
147 webrtc::VideoTrackVector GetVideoTracks() override;
148 rtc::scoped_refptr<webrtc::AudioTrackInterface> FindAudioTrack(
149 const std::string& track_id) override;
150 rtc::scoped_refptr<webrtc::VideoTrackInterface> FindVideoTrack(
151 const std::string& track_id) override;
152 void RegisterObserver(webrtc::ObserverInterface* observer) override;
153 void UnregisterObserver(webrtc::ObserverInterface* observer) override;
155 protected:
156 ~MockMediaStream() override;
158 private:
159 void NotifyObservers();
161 std::string label_;
162 webrtc::AudioTrackVector audio_track_vector_;
163 webrtc::VideoTrackVector video_track_vector_;
165 ObserverSet observers_;
168 // A mock factory for creating different objects for
169 // RTC PeerConnections.
170 class MockPeerConnectionDependencyFactory
171 : public PeerConnectionDependencyFactory {
172 public:
173 MockPeerConnectionDependencyFactory();
174 ~MockPeerConnectionDependencyFactory() override;
176 scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
177 const webrtc::PeerConnectionInterface::RTCConfiguration& config,
178 const webrtc::MediaConstraintsInterface* constraints,
179 blink::WebFrame* frame,
180 webrtc::PeerConnectionObserver* observer) override;
181 scoped_refptr<webrtc::AudioSourceInterface> CreateLocalAudioSource(
182 const webrtc::MediaConstraintsInterface* constraints) override;
183 WebRtcVideoCapturerAdapter* CreateVideoCapturer(
184 bool is_screen_capture) override;
185 scoped_refptr<webrtc::VideoSourceInterface> CreateVideoSource(
186 cricket::VideoCapturer* capturer,
187 const blink::WebMediaConstraints& constraints) override;
188 scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource(
189 blink::WebMediaStreamSource* source) override;
190 scoped_refptr<webrtc::MediaStreamInterface> CreateLocalMediaStream(
191 const std::string& label) override;
192 scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack(
193 const std::string& id,
194 webrtc::VideoSourceInterface* source) override;
195 scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack(
196 const std::string& id,
197 cricket::VideoCapturer* capturer) override;
198 webrtc::SessionDescriptionInterface* CreateSessionDescription(
199 const std::string& type,
200 const std::string& sdp,
201 webrtc::SdpParseError* error) override;
202 webrtc::IceCandidateInterface* CreateIceCandidate(
203 const std::string& sdp_mid,
204 int sdp_mline_index,
205 const std::string& sdp) override;
207 scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer(
208 int render_view_id,
209 const StreamDeviceInfo& device_info,
210 const blink::WebMediaConstraints& constraints,
211 MediaStreamAudioSource* audio_source) override;
212 void FailToCreateNextAudioCapturer() {
213 fail_to_create_next_audio_capturer_ = true;
216 void StartLocalAudioTrack(WebRtcLocalAudioTrack* audio_track) override;
218 MockAudioSource* last_audio_source() { return last_audio_source_.get(); }
219 MockVideoSource* last_video_source() { return last_video_source_.get(); }
221 private:
222 bool fail_to_create_next_audio_capturer_;
223 scoped_refptr <MockAudioSource> last_audio_source_;
224 scoped_refptr <MockVideoSource> last_video_source_;
226 DISALLOW_COPY_AND_ASSIGN(MockPeerConnectionDependencyFactory);
229 } // namespace content
231 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_MOCK_PEER_CONNECTION_DEPENDENCY_FACTORY_H_