| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "components/test_runner/mock_webrtc_data_channel_handler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "components/test_runner/web_test_delegate.h" | |
| 11 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h" | |
| 12 | |
| 13 using namespace blink; | |
| 14 | |
| 15 namespace test_runner { | |
| 16 | |
| 17 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler( | |
| 18 WebString label, | |
| 19 const WebRTCDataChannelInit& init, | |
| 20 WebTestDelegate* delegate) | |
| 21 : client_(0), | |
| 22 label_(label), | |
| 23 init_(init), | |
| 24 delegate_(delegate), | |
| 25 weak_factory_(this) { | |
| 26 reliable_ = (init.ordered && init.maxRetransmits == -1 && | |
| 27 init.maxRetransmitTime == -1); | |
| 28 } | |
| 29 | |
| 30 MockWebRTCDataChannelHandler::~MockWebRTCDataChannelHandler() {} | |
| 31 | |
| 32 void MockWebRTCDataChannelHandler::setClient( | |
| 33 WebRTCDataChannelHandlerClient* client) { | |
| 34 client_ = client; | |
| 35 if (client_) | |
| 36 delegate_->PostTask( | |
| 37 base::Bind(&MockWebRTCDataChannelHandler::ReportOpenedState, | |
| 38 weak_factory_.GetWeakPtr())); | |
| 39 } | |
| 40 | |
| 41 blink::WebString MockWebRTCDataChannelHandler::label() { | |
| 42 return label_; | |
| 43 } | |
| 44 | |
| 45 bool MockWebRTCDataChannelHandler::isReliable() { | |
| 46 return reliable_; | |
| 47 } | |
| 48 | |
| 49 bool MockWebRTCDataChannelHandler::ordered() const { | |
| 50 return init_.ordered; | |
| 51 } | |
| 52 | |
| 53 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const { | |
| 54 return init_.maxRetransmitTime; | |
| 55 } | |
| 56 | |
| 57 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const { | |
| 58 return init_.maxRetransmits; | |
| 59 } | |
| 60 | |
| 61 WebString MockWebRTCDataChannelHandler::protocol() const { | |
| 62 return init_.protocol; | |
| 63 } | |
| 64 | |
| 65 bool MockWebRTCDataChannelHandler::negotiated() const { | |
| 66 return init_.negotiated; | |
| 67 } | |
| 68 | |
| 69 unsigned short MockWebRTCDataChannelHandler::id() const { | |
| 70 return init_.id; | |
| 71 } | |
| 72 | |
| 73 blink::WebRTCDataChannelHandlerClient::ReadyState | |
| 74 MockWebRTCDataChannelHandler::state() const { | |
| 75 return blink::WebRTCDataChannelHandlerClient::ReadyStateConnecting; | |
| 76 } | |
| 77 | |
| 78 unsigned long MockWebRTCDataChannelHandler::bufferedAmount() { | |
| 79 return 0; | |
| 80 } | |
| 81 | |
| 82 bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data) { | |
| 83 DCHECK(client_); | |
| 84 client_->didReceiveStringData(data); | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size) { | |
| 89 DCHECK(client_); | |
| 90 client_->didReceiveRawData(data, size); | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 void MockWebRTCDataChannelHandler::close() { | |
| 95 DCHECK(client_); | |
| 96 delegate_->PostTask( | |
| 97 base::Bind(&MockWebRTCDataChannelHandler::ReportClosedState, | |
| 98 weak_factory_.GetWeakPtr())); | |
| 99 } | |
| 100 | |
| 101 void MockWebRTCDataChannelHandler::ReportOpenedState() { | |
| 102 client_->didChangeReadyState(WebRTCDataChannelHandlerClient::ReadyStateOpen); | |
| 103 } | |
| 104 | |
| 105 void MockWebRTCDataChannelHandler::ReportClosedState() { | |
| 106 client_->didChangeReadyState( | |
| 107 WebRTCDataChannelHandlerClient::ReadyStateClosed); | |
| 108 } | |
| 109 | |
| 110 } // namespace test_runner | |
| OLD | NEW |