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 "components/test_runner/mock_webrtc_peer_connection_handler.h" | 5 #include "components/test_runner/mock_webrtc_peer_connection_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> |
| 12 |
9 #include "base/bind.h" | 13 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
11 #include "components/test_runner/mock_webrtc_data_channel_handler.h" | 15 #include "components/test_runner/mock_webrtc_data_channel_handler.h" |
12 #include "components/test_runner/mock_webrtc_dtmf_sender_handler.h" | 16 #include "components/test_runner/mock_webrtc_dtmf_sender_handler.h" |
13 #include "components/test_runner/test_interfaces.h" | 17 #include "components/test_runner/test_interfaces.h" |
14 #include "components/test_runner/web_task.h" | 18 #include "components/test_runner/web_task.h" |
15 #include "components/test_runner/web_test_delegate.h" | 19 #include "components/test_runner/web_test_delegate.h" |
16 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
19 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 23 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
20 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 24 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
21 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 25 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
22 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" | 26 #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandlerClient.h
" |
23 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" | 27 #include "third_party/WebKit/public/platform/WebRTCStatsResponse.h" |
24 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" | 28 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" |
25 #include "third_party/WebKit/public/platform/WebString.h" | 29 #include "third_party/WebKit/public/platform/WebString.h" |
26 #include "third_party/WebKit/public/platform/WebVector.h" | 30 #include "third_party/WebKit/public/platform/WebVector.h" |
27 | 31 |
28 using namespace blink; | 32 using namespace blink; |
29 | 33 |
30 namespace test_runner { | 34 namespace test_runner { |
31 | 35 |
| 36 namespace { |
| 37 |
| 38 class MockWebRTCStats : public blink::WebRTCStats { |
| 39 public: |
| 40 class MemberIterator : public blink::WebRTCStatsMemberIterator { |
| 41 public: |
| 42 MemberIterator( |
| 43 const std::vector<std::pair<std::string, std::string>>* values) |
| 44 : values_(values) {} |
| 45 |
| 46 // blink::WebRTCStatsMemberIterator |
| 47 bool isEnd() const override { return i >= values_->size(); } |
| 48 void next() override { ++i; } |
| 49 blink::WebRTCStatsMemberName name() const override { |
| 50 return blink::WebRTCStatsMemberNameUnknown; |
| 51 } |
| 52 blink::WebString displayName() const override { |
| 53 return blink::WebString::fromUTF8((*values_)[i].first); |
| 54 } |
| 55 blink::WebRTCStatsMemberType type() const override { |
| 56 return blink::WebRTCStatsMemberTypeString; |
| 57 } |
| 58 int valueInt() const override { |
| 59 NOTREACHED(); |
| 60 return 0; |
| 61 } |
| 62 int64_t valueInt64() const override { |
| 63 NOTREACHED(); |
| 64 return 0; |
| 65 } |
| 66 float valueFloat() const override { |
| 67 NOTREACHED(); |
| 68 return 0.0f; |
| 69 } |
| 70 blink::WebString valueString() const override { |
| 71 return blink::WebString::fromUTF8((*values_)[i].second); |
| 72 } |
| 73 bool valueBool() const override { |
| 74 NOTREACHED(); |
| 75 return false; |
| 76 } |
| 77 blink::WebString valueToString() const override { |
| 78 return valueString(); |
| 79 } |
| 80 |
| 81 private: |
| 82 size_t i = 0; |
| 83 const std::vector<std::pair<std::string, std::string>>* values_; |
| 84 }; |
| 85 |
| 86 MockWebRTCStats(const char* id, const char* type_name, double timestamp) |
| 87 : id_(id), type_name_(type_name), timestamp_(timestamp) {} |
| 88 |
| 89 // blink::WebRTCStats |
| 90 blink::WebString id() const override { |
| 91 return blink::WebString::fromUTF8(id_); |
| 92 } |
| 93 blink::WebRTCStatsType type() const override { |
| 94 return blink::WebRTCStatsTypeUnknown; |
| 95 } |
| 96 blink::WebString typeToString() const override { |
| 97 return blink::WebString::fromUTF8(type_name_); |
| 98 } |
| 99 double timestamp() const override { |
| 100 return timestamp_; |
| 101 } |
| 102 blink::WebRTCStatsMemberIterator* iterator() const override { |
| 103 return new MemberIterator(&values_); |
| 104 } |
| 105 |
| 106 void addStatistic(const std::string& name, const std::string& value) { |
| 107 values_.push_back(std::make_pair(name, value)); |
| 108 } |
| 109 |
| 110 private: |
| 111 const std::string id_; |
| 112 const std::string type_name_; |
| 113 const double timestamp_; |
| 114 // (name, value) pairs. |
| 115 std::vector<std::pair<std::string, std::string>> values_; |
| 116 }; |
| 117 |
| 118 } // namespace |
| 119 |
32 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() | 120 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler() |
33 : weak_factory_(this) {} | 121 : weak_factory_(this) {} |
34 | 122 |
35 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() { | 123 MockWebRTCPeerConnectionHandler::~MockWebRTCPeerConnectionHandler() { |
36 } | 124 } |
37 | 125 |
38 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( | 126 MockWebRTCPeerConnectionHandler::MockWebRTCPeerConnectionHandler( |
39 WebRTCPeerConnectionHandlerClient* client, | 127 WebRTCPeerConnectionHandlerClient* client, |
40 TestInterfaces* interfaces) | 128 TestInterfaces* interfaces) |
41 : client_(client), | 129 : client_(client), |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 client_->negotiationNeeded(); | 372 client_->negotiationNeeded(); |
285 } | 373 } |
286 | 374 |
287 void MockWebRTCPeerConnectionHandler::getStats( | 375 void MockWebRTCPeerConnectionHandler::getStats( |
288 const WebRTCStatsRequest& request) { | 376 const WebRTCStatsRequest& request) { |
289 WebRTCStatsResponse response = request.createResponse(); | 377 WebRTCStatsResponse response = request.createResponse(); |
290 double current_date = | 378 double current_date = |
291 interfaces_->GetDelegate()->GetCurrentTimeInMillisecond(); | 379 interfaces_->GetDelegate()->GetCurrentTimeInMillisecond(); |
292 if (request.hasSelector()) { | 380 if (request.hasSelector()) { |
293 // FIXME: There is no check that the fetched values are valid. | 381 // FIXME: There is no check that the fetched values are valid. |
294 size_t report_index = | 382 MockWebRTCStats stats("Mock video", "ssrc", current_date); |
295 response.addReport("Mock video", "ssrc", current_date); | 383 stats.addStatistic("type", "video"); |
296 response.addStatistic(report_index, "type", "video"); | 384 response.addStats(stats); |
297 } else { | 385 } else { |
298 for (int i = 0; i < stream_count_; ++i) { | 386 for (int i = 0; i < stream_count_; ++i) { |
299 size_t report_index = | 387 MockWebRTCStats audio_stats("Mock audio", "ssrc", current_date); |
300 response.addReport("Mock audio", "ssrc", current_date); | 388 audio_stats.addStatistic("type", "audio"); |
301 response.addStatistic(report_index, "type", "audio"); | 389 response.addStats(audio_stats); |
302 report_index = response.addReport("Mock video", "ssrc", current_date); | 390 |
303 response.addStatistic(report_index, "type", "video"); | 391 MockWebRTCStats video_stats("Mock video", "ssrc", current_date); |
| 392 video_stats.addStatistic("type", "video"); |
| 393 response.addStats(video_stats); |
304 } | 394 } |
305 } | 395 } |
306 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( | 396 interfaces_->GetDelegate()->PostTask(new WebCallbackTask( |
307 base::Bind(&blink::WebRTCStatsRequest::requestSucceeded, | 397 base::Bind(&blink::WebRTCStatsRequest::requestSucceeded, |
308 base::Owned(new WebRTCStatsRequest(request)), response))); | 398 base::Owned(new WebRTCStatsRequest(request)), response))); |
309 } | 399 } |
310 | 400 |
311 void MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel() { | 401 void MockWebRTCPeerConnectionHandler::ReportCreationOfDataChannel() { |
312 WebRTCDataChannelInit init; | 402 WebRTCDataChannelInit init; |
313 WebRTCDataChannelHandler* remote_data_channel = | 403 WebRTCDataChannelHandler* remote_data_channel = |
(...skipping 19 matching lines...) Expand all Loading... |
333 const WebMediaStreamTrack& track) { | 423 const WebMediaStreamTrack& track) { |
334 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); | 424 return new MockWebRTCDTMFSenderHandler(track, interfaces_->GetDelegate()); |
335 } | 425 } |
336 | 426 |
337 void MockWebRTCPeerConnectionHandler::stop() { | 427 void MockWebRTCPeerConnectionHandler::stop() { |
338 stopped_ = true; | 428 stopped_ = true; |
339 weak_factory_.InvalidateWeakPtrs(); | 429 weak_factory_.InvalidateWeakPtrs(); |
340 } | 430 } |
341 | 431 |
342 } // namespace test_runner | 432 } // namespace test_runner |
OLD | NEW |