| 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 "base/memory/ptr_util.h" | |
| 16 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" | 15 #include "content/shell/test_runner/mock_webrtc_data_channel_handler.h" |
| 17 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" | 16 #include "content/shell/test_runner/mock_webrtc_dtmf_sender_handler.h" |
| 18 #include "content/shell/test_runner/test_interfaces.h" | 17 #include "content/shell/test_runner/test_interfaces.h" |
| 19 #include "content/shell/test_runner/web_test_delegate.h" | 18 #include "content/shell/test_runner/web_test_delegate.h" |
| 20 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 19 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 23 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 22 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
| 24 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 23 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
| 25 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 24 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
| 26 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | 25 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" |
| 27 #include "third_party/WebKit/public/platform/WebRTCRtpContributingSource.h" | |
| 28 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" | 26 #include "third_party/WebKit/public/platform/WebRTCRtpReceiver.h" |
| 29 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 27 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
| 30 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 28 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
| 31 #include "third_party/WebKit/public/platform/WebString.h" | 29 #include "third_party/WebKit/public/platform/WebString.h" |
| 32 #include "third_party/WebKit/public/platform/WebVector.h" | 30 #include "third_party/WebKit/public/platform/WebVector.h" |
| 33 | 31 |
| 34 using namespace blink; | 32 using namespace blink; |
| 35 | 33 |
| 36 namespace test_runner { | 34 namespace test_runner { |
| 37 | 35 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return nullptr; | 230 return nullptr; |
| 233 return std::unique_ptr<blink::WebRTCStats>( | 231 return std::unique_ptr<blink::WebRTCStats>( |
| 234 new MockWebRTCStats(stats_[i_++])); | 232 new MockWebRTCStats(stats_[i_++])); |
| 235 } | 233 } |
| 236 | 234 |
| 237 private: | 235 private: |
| 238 std::vector<MockWebRTCStats> stats_; | 236 std::vector<MockWebRTCStats> stats_; |
| 239 size_t i_; | 237 size_t i_; |
| 240 }; | 238 }; |
| 241 | 239 |
| 242 class MockWebRTCRtpContributingSource | |
| 243 : public blink::WebRTCRtpContributingSource { | |
| 244 public: | |
| 245 MockWebRTCRtpContributingSource( | |
| 246 blink::WebRTCRtpContributingSourceType source_type, | |
| 247 double timestamp_ms, | |
| 248 uint32_t source) | |
| 249 : source_type_(source_type), | |
| 250 timestamp_ms_(timestamp_ms), | |
| 251 source_(source) {} | |
| 252 ~MockWebRTCRtpContributingSource() override {} | |
| 253 | |
| 254 blink::WebRTCRtpContributingSourceType SourceType() const override { | |
| 255 return source_type_; | |
| 256 } | |
| 257 double TimestampMs() const override { return timestamp_ms_; } | |
| 258 uint32_t Source() const override { return source_; } | |
| 259 | |
| 260 private: | |
| 261 blink::WebRTCRtpContributingSourceType source_type_; | |
| 262 double timestamp_ms_; | |
| 263 uint32_t source_; | |
| 264 }; | |
| 265 | |
| 266 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { | 240 class MockWebRTCRtpReceiver : public blink::WebRTCRtpReceiver { |
| 267 public: | 241 public: |
| 268 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) | 242 MockWebRTCRtpReceiver(uintptr_t id, const blink::WebMediaStreamTrack& track) |
| 269 : id_(id), track_(track), num_packets_(0) {} | 243 : id_(id), track_(track) {} |
| 270 ~MockWebRTCRtpReceiver() override {} | 244 ~MockWebRTCRtpReceiver() override {} |
| 271 | 245 |
| 272 uintptr_t Id() const override { return id_; } | 246 uintptr_t Id() const override { return id_; } |
| 273 const blink::WebMediaStreamTrack& Track() const override { return track_; } | 247 const blink::WebMediaStreamTrack& Track() const override { return track_; } |
| 274 | 248 |
| 275 // Every time called, mocks that a new packet has arrived updating the i-th | |
| 276 // CSRC such that the |kNumCSRCsActive| latest updated CSRCs are returned. "i" | |
| 277 // is the sequence number modulo number of CSRCs. Also returns an SSRC with | |
| 278 // the latest timestamp. For example, if 2 out of 3 CSRCs should be active, | |
| 279 // this will return the following "(type, source, timestamp)": | |
| 280 // - 1st call: { (CSRC, 0, 0), (SSRC, 0, 0) } | |
| 281 // - 2nd call: { (CSRC, 0, 0000), (CSRC, 1, 5000), (SSRC, 0, 5000) } | |
| 282 // - 3rd call: { (CSRC, 1, 5000), (CSRC, 2, 10000), (SSRC, 0, 10000) } | |
| 283 // - 4th call: { (CSRC, 2, 10000), (CSRC, 0, 15000), (SSRC, 0, 15000) } | |
| 284 // RTCPeerConnection-getReceivers.html depends on this behavior. | |
| 285 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> | |
| 286 GetSources() override { | |
| 287 ++num_packets_; | |
| 288 size_t num_csrcs = std::min(kNumCSRCsActive, num_packets_); | |
| 289 blink::WebVector<std::unique_ptr<blink::WebRTCRtpContributingSource>> | |
| 290 contributing_sources(num_csrcs + 1); | |
| 291 for (size_t i = 0; i < num_csrcs; ++i) { | |
| 292 size_t sequence_number = num_packets_ - num_csrcs + i; | |
| 293 contributing_sources[i] = | |
| 294 base::MakeUnique<MockWebRTCRtpContributingSource>( | |
| 295 blink::WebRTCRtpContributingSourceType::CSRC, | |
| 296 // Return value should include timestamps for the last 10 seconds, | |
| 297 // we pretend |10000.0 / kNumCSRCsActive| milliseconds have passed | |
| 298 // per packet in the sequence, starting from 0. This is not | |
| 299 // relative to any real clock. | |
| 300 sequence_number * 10000.0 / kNumCSRCsActive, | |
| 301 sequence_number % kNumCSRCs); | |
| 302 } | |
| 303 contributing_sources[num_csrcs] = | |
| 304 base::MakeUnique<MockWebRTCRtpContributingSource>( | |
| 305 blink::WebRTCRtpContributingSourceType::SSRC, | |
| 306 contributing_sources[num_csrcs - 1]->TimestampMs(), 0); | |
| 307 return contributing_sources; | |
| 308 } | |
| 309 | |
| 310 private: | 249 private: |
| 311 const size_t kNumCSRCs = 3; | |
| 312 const size_t kNumCSRCsActive = 2; | |
| 313 | |
| 314 uintptr_t id_; | 250 uintptr_t id_; |
| 315 blink::WebMediaStreamTrack track_; | 251 blink::WebMediaStreamTrack track_; |
| 316 size_t num_packets_; | |
| 317 }; | 252 }; |
| 318 | 253 |
| 319 } // namespace | 254 } // namespace |
| 320 | 255 |
| 321 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() | 256 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() |
| 322 : weak_factory_(this) {} | 257 : weak_factory_(this) {} |
| 323 | 258 |
| 324 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} | 259 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() {} |
| 325 | 260 |
| 326 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( | 261 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 const WebMediaStreamTrack& track) { | 609 const WebMediaStreamTrack& track) { |
| 675 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 610 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
| 676 } | 611 } |
| 677 | 612 |
| 678 void MockWebRTCPeerConnectionHandler::Stop() { | 613 void MockWebRTCPeerConnectionHandler::Stop() { |
| 679 stopped_ = true; | 614 stopped_ = true; |
| 680 weak_factory_.InvalidateWeakPtrs(); | 615 weak_factory_.InvalidateWeakPtrs(); |
| 681 } | 616 } |
| 682 | 617 |
| 683 } // namespace test_runner | 618 } // namespace test_runner |
| OLD | NEW |