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.
5 #include "components/test_runner/mock_webrtc_data_channel_handler.h"
7 #include "base/logging.h"
8 #include "components/test_runner/web_test_delegate.h"
9 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
11 using namespace blink
;
13 namespace test_runner
{
15 class DataChannelReadyStateTask
16 : public WebMethodTask
<MockWebRTCDataChannelHandler
> {
18 DataChannelReadyStateTask(MockWebRTCDataChannelHandler
* object
,
19 WebRTCDataChannelHandlerClient
* data_channel_client
,
20 WebRTCDataChannelHandlerClient::ReadyState state
)
21 : WebMethodTask
<MockWebRTCDataChannelHandler
>(object
),
22 data_channel_client_(data_channel_client
),
25 void RunIfValid() override
{
26 data_channel_client_
->didChangeReadyState(state_
);
30 WebRTCDataChannelHandlerClient
* data_channel_client_
;
31 WebRTCDataChannelHandlerClient::ReadyState state_
;
36 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler(
38 const WebRTCDataChannelInit
& init
,
39 WebTestDelegate
* delegate
)
40 : client_(0), label_(label
), init_(init
), delegate_(delegate
) {
41 reliable_
= (init
.ordered
&& init
.maxRetransmits
== -1 &&
42 init
.maxRetransmitTime
== -1);
45 void MockWebRTCDataChannelHandler::setClient(
46 WebRTCDataChannelHandlerClient
* client
) {
49 delegate_
->PostTask(new DataChannelReadyStateTask(
50 this, client_
, WebRTCDataChannelHandlerClient::ReadyStateOpen
));
53 blink::WebString
MockWebRTCDataChannelHandler::label() {
57 bool MockWebRTCDataChannelHandler::isReliable() {
61 bool MockWebRTCDataChannelHandler::ordered() const {
65 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const {
66 return init_
.maxRetransmitTime
;
69 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const {
70 return init_
.maxRetransmits
;
73 WebString
MockWebRTCDataChannelHandler::protocol() const {
74 return init_
.protocol
;
77 bool MockWebRTCDataChannelHandler::negotiated() const {
78 return init_
.negotiated
;
81 unsigned short MockWebRTCDataChannelHandler::id() const {
85 blink::WebRTCDataChannelHandlerClient::ReadyState
86 MockWebRTCDataChannelHandler::state() const {
87 return blink::WebRTCDataChannelHandlerClient::ReadyStateConnecting
;
90 unsigned long MockWebRTCDataChannelHandler::bufferedAmount() {
94 bool MockWebRTCDataChannelHandler::sendStringData(const WebString
& data
) {
96 client_
->didReceiveStringData(data
);
100 bool MockWebRTCDataChannelHandler::sendRawData(const char* data
, size_t size
) {
102 client_
->didReceiveRawData(data
, size
);
106 void MockWebRTCDataChannelHandler::close() {
108 delegate_
->PostTask(new DataChannelReadyStateTask(
109 this, client_
, WebRTCDataChannelHandlerClient::ReadyStateClosed
));
112 } // namespace test_runner