1 // Copyright 2013 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 "content/shell/renderer/test_runner/MockWebRTCDataChannelHandler.h"
9 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
10 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h"
12 using namespace blink
;
14 namespace WebTestRunner
{
16 class DataChannelReadyStateTask
: public WebMethodTask
<MockWebRTCDataChannelHandler
> {
18 DataChannelReadyStateTask(MockWebRTCDataChannelHandler
* object
, WebRTCDataChannelHandlerClient
* dataChannelClient
, WebRTCDataChannelHandlerClient::ReadyState state
)
19 : WebMethodTask
<MockWebRTCDataChannelHandler
>(object
)
20 , m_dataChannelClient(dataChannelClient
)
25 virtual void runIfValid() OVERRIDE
27 m_dataChannelClient
->didChangeReadyState(m_state
);
31 WebRTCDataChannelHandlerClient
* m_dataChannelClient
;
32 WebRTCDataChannelHandlerClient::ReadyState m_state
;
37 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler(WebString label
, const WebRTCDataChannelInit
& init
, WebTestDelegate
* delegate
)
41 , m_delegate(delegate
)
43 m_reliable
= (init
.ordered
&& init
.maxRetransmits
== -1 && init
.maxRetransmitTime
== -1);
46 void MockWebRTCDataChannelHandler::setClient(WebRTCDataChannelHandlerClient
* client
)
50 m_delegate
->postTask(new DataChannelReadyStateTask(this, m_client
, WebRTCDataChannelHandlerClient::ReadyStateOpen
));
53 blink::WebString
MockWebRTCDataChannelHandler::label()
58 bool MockWebRTCDataChannelHandler::isReliable()
63 bool MockWebRTCDataChannelHandler::ordered() const
65 return m_init
.ordered
;
68 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const
70 return m_init
.maxRetransmitTime
;
73 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const
75 return m_init
.maxRetransmits
;
78 WebString
MockWebRTCDataChannelHandler::protocol() const
80 return m_init
.protocol
;
83 bool MockWebRTCDataChannelHandler::negotiated() const
85 return m_init
.negotiated
;
88 unsigned short MockWebRTCDataChannelHandler::id() const
93 unsigned long MockWebRTCDataChannelHandler::bufferedAmount()
98 bool MockWebRTCDataChannelHandler::sendStringData(const WebString
& data
)
101 m_client
->didReceiveStringData(data
);
105 bool MockWebRTCDataChannelHandler::sendRawData(const char* data
, size_t size
)
108 m_client
->didReceiveRawData(data
, size
);
112 void MockWebRTCDataChannelHandler::close()
115 m_delegate
->postTask(new DataChannelReadyStateTask(this, m_client
, WebRTCDataChannelHandlerClient::ReadyStateClosed
));