OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/shell/test_runner/mock_webrtc_peer_connection_handler.h" | 5 #include "content/shell/test_runner/mock_webrtc_peer_connection_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" | 15 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" |
16 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" | 16 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" |
17 #include "content/shell/test_runner/test_interfaces.h" | 17 #include "content/shell/test_runner/test_interfaces.h" |
18 #include "content/shell/test_runner/web_test_delegate.h" | 18 #include "content/shell/test_runner/web_test_delegate.h" |
19 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 19 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " | 25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h " |
26 #include "third_party/WebKit/public/platform/WebRTCRtpContributingSource.h" | |
26 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" | 27 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" |
27 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 28 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
28 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 29 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
29 #include "third_party/WebKit/public/platform/WebString.h" | 30 #include "third_party/WebKit/public/platform/WebString.h" |
30 #include "third_party/WebKit/public/platform/WebVector.h" | 31 #include "third_party/WebKit/public/platform/WebVector.h" |
31 | 32 |
32 using namespace blink; | 33 using namespace blink; |
33 | 34 |
34 namespace test_runner { | 35 namespace test_runner { |
35 | 36 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 return nullptr; | 231 return nullptr; |
231 return std::unique_ptr<blink::WebRTCStats>( | 232 return std::unique_ptr<blink::WebRTCStats>( |
232 new MockWebRTCStats(stats_[i_++])); | 233 new MockWebRTCStats(stats_[i_++])); |
233 } | 234 } |
234 | 235 |
235 private: | 236 private: |
236 std::vector<MockWebRTCStats> stats_; | 237 std::vector<MockWebRTCStats> stats_; |
237 size_t i_; | 238 size_t i_; |
238 }; | 239 }; |
239 | 240 |
241 class MockWebRTCRtpContributingSource | |
foolip
2017/04/06 10:07:23
Didn't look closely at this. Would this mock get c
hbos_chromium
2017/04/06 11:10:15
Yes, all LayoutTests use mock_webrtc_peer_connecti
| |
242 : public blink::WebRTCRtpContributingSource { | |
243 public: | |
244 MockWebRTCRtpContributingSource( | |
245 blink::WebRTCRtpContributingSourceType source_type, | |
246 double timestamp_ms, | |
247 uint32_t source) | |
248 : source_type_(source_type), | |
249 timestamp_ms_(timestamp_ms), | |
250 source_(source) {} | |
251 ~MockWebRTCRtpContributingSource() override {} | |
252 | |
253 blink::WebRTCRtpContributingSourceType sourceType() const override { | |
254 return source_type_; | |
255 } | |
256 double timestampMs() const override { return timestamp_ms_; } | |
257 uint32_t source() const override { return source_; } | |
258 | |
259 private: | |
260 blink::WebRTCRtpContributingSourceType source_type_; | |
261 double timestamp_ms_; | |
262 uint32_t source_; | |
263 }; | |
264 | |
240 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { | 265 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { |
241 public: | 266 public: |
242 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) | 267 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) |
243 : id_(id), track_(track) {} | 268 : id_(id), track_(track), num_packets_(0) {} |
244 ~MockWebRTCRtpReceiver() override {} | 269 ~MockWebRTCRtpReceiver() override {} |
245 | 270 |
246 uintptr_t id() const override { return id_; } | 271 uintptr_t id() const override { return id_; } |
247 const blink::WebMediaStreamTrack& track() const override { return track_; } | 272 const blink::WebMediaStreamTrack& track() const override { return track_; } |
248 | 273 |
274 // Every time called, mocks that a new packet has arrived updating the i-th | |
275 // CSRC such that the |kNumCSRCsActive| latest updated CSRCs are returned. "i" | |
276 // is the sequence number modulo number of CSRCs. Also returns an SSRC with | |
277 // the latest timestamp. For example, if 2 out of 3 CSRCs should be active, | |
278 // this will return the following "(type, source, timestamp)": | |
279 // - 1st call: { (CSRC, 0, 0), (SSRC, 0, 0) } | |
280 // - 2nd call: { (CSRC, 0, 0000), (CSRC, 1, 5000), (SSRC, 0, 5000) } | |
281 // - 3rd call: { (CSRC, 1, 5000), (CSRC, 2, 10000), (SSRC, 0, 10000) } | |
282 // - 4th call: { (CSRC, 2, 10000), (CSRC, 0, 15000), (SSRC, 0, 15000) } | |
283 // RTCPeerConnection-getReceivers.html depends on this behavior. | |
284 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> | |
285 getSources() override { | |
286 ++num_packets_; | |
287 size_t num_csrcs = std::min(kNumCSRCsActive, num_packets_); | |
288 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> | |
289 contributing_sources(num_csrcs + 1); | |
290 for (size_t i = 0; i < num_csrcs; ++i) { | |
291 size_t sequence_number = num_packets_ - num_csrcs + i; | |
292 contributing_sources[i].reset(new MockWebRTCRtpContributingSource( | |
293 blink::WebRTCRtpContributingSourceType::CSRC, | |
294 // Return value should include timestamps for the last 10 seconds, we | |
295 // pretend |10000.0 / kNumCSRCsActive| milliseconds have passed | |
296 // per packet in the sequence, starting from 0. This is not relative | |
297 // to any real clock. | |
298 sequence_number * 10000.0 / kNumCSRCsActive, | |
299 sequence_number % kNumCSRCs)); | |
300 } | |
301 contributing_sources[num_csrcs].reset(new MockWebRTCRtpContributingSource( | |
302 blink::WebRTCRtpContributingSourceType::SSRC, | |
303 contributing_sources[num_csrcs - 1]->timestampMs(), 0)); | |
304 return contributing_sources; | |
305 } | |
306 | |
249 private: | 307 private: |
308 const size_t kNumCSRCs = 3; | |
309 const size_t kNumCSRCsActive = 2; | |
310 | |
250 uintptr_t id_; | 311 uintptr_t id_; |
251 blink::WebMediaStreamTrack track_; | 312 blink::WebMediaStreamTrack track_; |
313 size_t num_packets_; | |
252 }; | 314 }; |
253 | 315 |
254 } // namespace | 316 } // namespace |
255 | 317 |
256 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() | 318 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() |
257 : weak_factory_(this) {} | 319 : weak_factory_(this) {} |
258 | 320 |
259 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} | 321 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} |
260 | 322 |
261 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( | 323 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 const WebMediaStreamTrack& track) { | 667 const WebMediaStreamTrack& track) { |
606 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 668 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
607 } | 669 } |
608 | 670 |
609 void MockWebRTCPeerConnectionHandler::stop() { | 671 void MockWebRTCPeerConnectionHandler::stop() { |
610 stopped_ = true; | 672 stopped_ = true; |
611 weak_factory_.InvalidateWeakPtrs(); | 673 weak_factory_.InvalidateWeakPtrs(); |
612 } | 674 } |
613 | 675 |
614 } // namespace test_runner | 676 } // namespace test_runner |
OLD | NEW |