[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / content / shell / renderer / test_runner / MockWebRTCDataChannelHandler.cpp
blobf70fa0013a6ebefb42a8e4eca8243d7dd25a3e52
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"
7 #include <assert.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> {
17 public:
18 DataChannelReadyStateTask(MockWebRTCDataChannelHandler* object, WebRTCDataChannelHandlerClient* dataChannelClient, WebRTCDataChannelHandlerClient::ReadyState state)
19 : WebMethodTask<MockWebRTCDataChannelHandler>(object)
20 , m_dataChannelClient(dataChannelClient)
21 , m_state(state)
25 virtual void runIfValid() OVERRIDE
27 m_dataChannelClient->didChangeReadyState(m_state);
30 private:
31 WebRTCDataChannelHandlerClient* m_dataChannelClient;
32 WebRTCDataChannelHandlerClient::ReadyState m_state;
35 /////////////////////
37 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler(WebString label, const WebRTCDataChannelInit& init, WebTestDelegate* delegate)
38 : m_client(0)
39 , m_label(label)
40 , m_init(init)
41 , m_delegate(delegate)
43 m_reliable = (init.ordered && init.maxRetransmits == -1 && init.maxRetransmitTime == -1);
46 void MockWebRTCDataChannelHandler::setClient(WebRTCDataChannelHandlerClient* client)
48 m_client = client;
49 if (m_client)
50 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRTCDataChannelHandlerClient::ReadyStateOpen));
53 blink::WebString MockWebRTCDataChannelHandler::label()
55 return m_label;
58 bool MockWebRTCDataChannelHandler::isReliable()
60 return m_reliable;
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
90 return m_init.id;
93 unsigned long MockWebRTCDataChannelHandler::bufferedAmount()
95 return 0;
98 bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data)
100 assert(m_client);
101 m_client->didReceiveStringData(data);
102 return true;
105 bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size)
107 assert(m_client);
108 m_client->didReceiveRawData(data, size);
109 return true;
112 void MockWebRTCDataChannelHandler::close()
114 assert(m_client);
115 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRTCDataChannelHandlerClient::ReadyStateClosed));