Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: content/test/layout_tests/runner/MockWebRTCPeerConnectionHandler.cpp

Issue 110533009: Import TestRunner library into chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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.
4
5 /*
6 * Copyright (C) 2012 Google Inc. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Google Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include "content/test/layout_tests/runner/MockWebRTCPeerConnectionHandler.h"
36
37 #include "content/public/test/layout_tests/WebTestDelegate.h"
38 #include "content/test/layout_tests/runner/MockConstraints.h"
39 #include "content/test/layout_tests/runner/MockWebRTCDataChannelHandler.h"
40 #include "content/test/layout_tests/runner/MockWebRTCDTMFSenderHandler.h"
41 #include "content/test/layout_tests/runner/TestInterfaces.h"
42 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
43 #include "third_party/WebKit/public/platform/WebMediaStream.h"
44 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
45 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
46 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h "
47 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h"
48 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h"
49 #include "third_party/WebKit/public/platform/WebString.h"
50 #include "third_party/WebKit/public/platform/WebVector.h"
51
52 using namespace blink;
53
54 namespace WebTestRunner {
55
56 class RTCSessionDescriptionRequestSuccededTask : public WebMethodTask<MockWebRTC PeerConnectionHandler> {
57 public:
58 RTCSessionDescriptionRequestSuccededTask(MockWebRTCPeerConnectionHandler* ob ject, const WebRTCSessionDescriptionRequest& request, const WebRTCSessionDescrip tion& result)
59 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object)
60 , m_request(request)
61 , m_result(result)
62 {
63 }
64
65 virtual void runIfValid() OVERRIDE
66 {
67 m_request.requestSucceeded(m_result);
68 }
69
70 private:
71 WebRTCSessionDescriptionRequest m_request;
72 WebRTCSessionDescription m_result;
73 };
74
75 class RTCSessionDescriptionRequestFailedTask : public WebMethodTask<MockWebRTCPe erConnectionHandler> {
76 public:
77 RTCSessionDescriptionRequestFailedTask(MockWebRTCPeerConnectionHandler* obje ct, const WebRTCSessionDescriptionRequest& request)
78 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object)
79 , m_request(request)
80 {
81 }
82
83 virtual void runIfValid() OVERRIDE
84 {
85 m_request.requestFailed("TEST_ERROR");
86 }
87
88 private:
89 WebRTCSessionDescriptionRequest m_request;
90 };
91
92 class RTCStatsRequestSucceededTask : public WebMethodTask<MockWebRTCPeerConnecti onHandler> {
93 public:
94 RTCStatsRequestSucceededTask(MockWebRTCPeerConnectionHandler* object, const blink::WebRTCStatsRequest& request, const blink::WebRTCStatsResponse& response)
95 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object)
96 , m_request(request)
97 , m_response(response)
98 {
99 }
100
101 virtual void runIfValid() OVERRIDE
102 {
103 m_request.requestSucceeded(m_response);
104 }
105
106 private:
107 blink::WebRTCStatsRequest m_request;
108 blink::WebRTCStatsResponse m_response;
109 };
110
111 class RTCVoidRequestTask : public WebMethodTask<MockWebRTCPeerConnectionHandler> {
112 public:
113 RTCVoidRequestTask(MockWebRTCPeerConnectionHandler* object, const WebRTCVoid Request& request, bool succeeded)
114 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object)
115 , m_request(request)
116 , m_succeeded(succeeded)
117 {
118 }
119
120 virtual void runIfValid() OVERRIDE
121 {
122 if (m_succeeded)
123 m_request.requestSucceeded();
124 else
125 m_request.requestFailed("TEST_ERROR");
126 }
127
128 private:
129 WebRTCVoidRequest m_request;
130 bool m_succeeded;
131 };
132
133 class RTCPeerConnectionStateTask : public WebMethodTask<MockWebRTCPeerConnection Handler> {
134 public:
135 RTCPeerConnectionStateTask(MockWebRTCPeerConnectionHandler* object, WebRTCPe erConnectionHandlerClient* client, WebRTCPeerConnectionHandlerClient::ICEConnect ionState connectionState, WebRTCPeerConnectionHandlerClient::ICEGatheringState g atheringState)
136 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object)
137 , m_client(client)
138 , m_connectionState(connectionState)
139 , m_gatheringState(gatheringState)
140 {
141 }
142
143 virtual void runIfValid() OVERRIDE
144 {
145 m_client->didChangeICEGatheringState(m_gatheringState);
146 m_client->didChangeICEConnectionState(m_connectionState);
147 }
148
149 private:
150 WebRTCPeerConnectionHandlerClient* m_client;
151 WebRTCPeerConnectionHandlerClient::ICEConnectionState m_connectionState;
152 WebRTCPeerConnectionHandlerClient::ICEGatheringState m_gatheringState;
153 };
154
155 class RemoteDataChannelTask : public WebMethodTask<MockWebRTCPeerConnectionHandl er> {
156 public:
157 RemoteDataChannelTask(MockWebRTCPeerConnectionHandler* object, WebRTCPeerCon nectionHandlerClient* client, WebTestDelegate* delegate)
158 : WebMethodTask<MockWebRTCPeerConnectionHandler>(object)
159 , m_client(client)
160 , m_delegate(delegate)
161 {
162 }
163
164 virtual void runIfValid() OVERRIDE
165 {
166 WebRTCDataChannelInit init;
167 WebRTCDataChannelHandler* remoteDataChannel = new MockWebRTCDataChannelH andler("MockRemoteDataChannel", init, m_delegate);
168 m_client->didAddRemoteDataChannel(remoteDataChannel);
169 }
170
171 private:
172 WebRTCPeerConnectionHandlerClient* m_client;
173 WebTestDelegate* m_delegate;
174 };
175
176 /////////////////////
177
178 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler(WebRTCPeerConne ctionHandlerClient* client, TestInterfaces* interfaces)
179 : m_client(client)
180 , m_stopped(false)
181 , m_streamCount(0)
182 , m_interfaces(interfaces)
183 {
184 }
185
186 bool MockWebRTCPeerConnectionHandler::initialize(const WebRTCConfiguration&, con st WebMediaConstraints& constraints)
187 {
188 if (MockConstraints::verifyConstraints(constraints)) {
189 m_interfaces->delegate()->postTask(new RTCPeerConnectionStateTask(this, m_client, WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted, WebRTC PeerConnectionHandlerClient::ICEGatheringStateComplete));
190 return true;
191 }
192
193 return false;
194 }
195
196 void MockWebRTCPeerConnectionHandler::createOffer(const WebRTCSessionDescription Request& request, const WebMediaConstraints& constraints)
197 {
198 WebString shouldSucceed;
199 if (constraints.getMandatoryConstraintValue("succeed", shouldSucceed) && sho uldSucceed == "true") {
200 WebRTCSessionDescription sessionDescription;
201 sessionDescription.initialize("offer", "local");
202 m_interfaces->delegate()->postTask(new RTCSessionDescriptionRequestSucce dedTask(this, request, sessionDescription));
203 } else
204 m_interfaces->delegate()->postTask(new RTCSessionDescriptionRequestFaile dTask(this, request));
205 }
206
207 void MockWebRTCPeerConnectionHandler::createAnswer(const WebRTCSessionDescriptio nRequest& request, const WebMediaConstraints&)
208 {
209 if (!m_remoteDescription.isNull()) {
210 WebRTCSessionDescription sessionDescription;
211 sessionDescription.initialize("answer", "local");
212 m_interfaces->delegate()->postTask(new RTCSessionDescriptionRequestSucce dedTask(this, request, sessionDescription));
213 } else
214 m_interfaces->delegate()->postTask(new RTCSessionDescriptionRequestFaile dTask(this, request));
215 }
216
217 void MockWebRTCPeerConnectionHandler::setLocalDescription(const WebRTCVoidReques t& request, const WebRTCSessionDescription& localDescription)
218 {
219 if (!localDescription.isNull() && localDescription.sdp() == "local") {
220 m_localDescription = localDescription;
221 m_interfaces->delegate()->postTask(new RTCVoidRequestTask(this, request, true));
222 } else
223 m_interfaces->delegate()->postTask(new RTCVoidRequestTask(this, request, false));
224 }
225
226 void MockWebRTCPeerConnectionHandler::setRemoteDescription(const WebRTCVoidReque st& request, const WebRTCSessionDescription& remoteDescription)
227 {
228 if (!remoteDescription.isNull() && remoteDescription.sdp() == "remote") {
229 m_remoteDescription = remoteDescription;
230 m_interfaces->delegate()->postTask(new RTCVoidRequestTask(this, request, true));
231 } else
232 m_interfaces->delegate()->postTask(new RTCVoidRequestTask(this, request, false));
233 }
234
235 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::localDescription()
236 {
237 return m_localDescription;
238 }
239
240 WebRTCSessionDescription MockWebRTCPeerConnectionHandler::remoteDescription()
241 {
242 return m_remoteDescription;
243 }
244
245 bool MockWebRTCPeerConnectionHandler::updateICE(const WebRTCConfiguration&, cons t WebMediaConstraints&)
246 {
247 return true;
248 }
249
250 bool MockWebRTCPeerConnectionHandler::addICECandidate(const WebRTCICECandidate& iceCandidate)
251 {
252 m_client->didGenerateICECandidate(iceCandidate);
253 return true;
254 }
255
256 bool MockWebRTCPeerConnectionHandler::addICECandidate(const WebRTCVoidRequest& r equest, const WebRTCICECandidate& iceCandidate)
257 {
258 m_interfaces->delegate()->postTask(new RTCVoidRequestTask(this, request, tru e));
259 return true;
260 }
261
262 bool MockWebRTCPeerConnectionHandler::addStream(const WebMediaStream& stream, co nst WebMediaConstraints&)
263 {
264 ++m_streamCount;
265 m_client->negotiationNeeded();
266 return true;
267 }
268
269 void MockWebRTCPeerConnectionHandler::removeStream(const WebMediaStream& stream)
270 {
271 --m_streamCount;
272 m_client->negotiationNeeded();
273 }
274
275 void MockWebRTCPeerConnectionHandler::getStats(const WebRTCStatsRequest& request )
276 {
277 WebRTCStatsResponse response = request.createResponse();
278 double currentDate = m_interfaces->delegate()->getCurrentTimeInMillisecond() ;
279 if (request.hasSelector()) {
280 // FIXME: There is no check that the fetched values are valid.
281 size_t reportIndex = response.addReport("Mock video", "ssrc", currentDat e);
282 response.addStatistic(reportIndex, "type", "video");
283 } else {
284 for (int i = 0; i < m_streamCount; ++i) {
285 size_t reportIndex = response.addReport("Mock audio", "ssrc", curren tDate);
286 response.addStatistic(reportIndex, "type", "audio");
287 reportIndex = response.addReport("Mock video", "ssrc", currentDate);
288 response.addStatistic(reportIndex, "type", "video");
289 }
290 }
291 m_interfaces->delegate()->postTask(new RTCStatsRequestSucceededTask(this, re quest, response));
292 }
293
294 WebRTCDataChannelHandler* MockWebRTCPeerConnectionHandler::createDataChannel(con st WebString& label, const blink::WebRTCDataChannelInit& init)
295 {
296 m_interfaces->delegate()->postTask(new RemoteDataChannelTask(this, m_client, m_interfaces->delegate()));
297
298 return new MockWebRTCDataChannelHandler(label, init, m_interfaces->delegate( ));
299 }
300
301 WebRTCDTMFSenderHandler* MockWebRTCPeerConnectionHandler::createDTMFSender(const WebMediaStreamTrack& track)
302 {
303 return new MockWebRTCDTMFSenderHandler(track, m_interfaces->delegate());
304 }
305
306 void MockWebRTCPeerConnectionHandler::stop()
307 {
308 m_stopped = true;
309 }
310
311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698