| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/shell/renderer/test_runner/MockWebRTCDataChannelHandler.h" | |
| 6 | |
| 7 #include <assert.h> | |
| 8 | |
| 9 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | |
| 10 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h" | |
| 11 | |
| 12 using namespace blink; | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 class DataChannelReadyStateTask : public WebMethodTask<MockWebRTCDataChannelHand
ler> { | |
| 17 public: | |
| 18 DataChannelReadyStateTask(MockWebRTCDataChannelHandler* object, WebRTCDataCh
annelHandlerClient* dataChannelClient, WebRTCDataChannelHandlerClient::ReadyStat
e state) | |
| 19 : WebMethodTask<MockWebRTCDataChannelHandler>(object) | |
| 20 , m_dataChannelClient(dataChannelClient) | |
| 21 , m_state(state) | |
| 22 { | |
| 23 } | |
| 24 | |
| 25 virtual void runIfValid() OVERRIDE | |
| 26 { | |
| 27 m_dataChannelClient->didChangeReadyState(m_state); | |
| 28 } | |
| 29 | |
| 30 private: | |
| 31 WebRTCDataChannelHandlerClient* m_dataChannelClient; | |
| 32 WebRTCDataChannelHandlerClient::ReadyState m_state; | |
| 33 }; | |
| 34 | |
| 35 ///////////////////// | |
| 36 | |
| 37 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler(WebString label, cons
t WebRTCDataChannelInit& init, WebTestDelegate* delegate) | |
| 38 : m_client(0) | |
| 39 , m_label(label) | |
| 40 , m_init(init) | |
| 41 , m_delegate(delegate) | |
| 42 { | |
| 43 m_reliable = (init.ordered && init.maxRetransmits == -1 && init.maxRetransmi
tTime == -1); | |
| 44 } | |
| 45 | |
| 46 void MockWebRTCDataChannelHandler::setClient(WebRTCDataChannelHandlerClient* cli
ent) | |
| 47 { | |
| 48 m_client = client; | |
| 49 if (m_client) | |
| 50 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRT
CDataChannelHandlerClient::ReadyStateOpen)); | |
| 51 } | |
| 52 | |
| 53 blink::WebString MockWebRTCDataChannelHandler::label() | |
| 54 { | |
| 55 return m_label; | |
| 56 } | |
| 57 | |
| 58 bool MockWebRTCDataChannelHandler::isReliable() | |
| 59 { | |
| 60 return m_reliable; | |
| 61 } | |
| 62 | |
| 63 bool MockWebRTCDataChannelHandler::ordered() const | |
| 64 { | |
| 65 return m_init.ordered; | |
| 66 } | |
| 67 | |
| 68 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const | |
| 69 { | |
| 70 return m_init.maxRetransmitTime; | |
| 71 } | |
| 72 | |
| 73 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const | |
| 74 { | |
| 75 return m_init.maxRetransmits; | |
| 76 } | |
| 77 | |
| 78 WebString MockWebRTCDataChannelHandler::protocol() const | |
| 79 { | |
| 80 return m_init.protocol; | |
| 81 } | |
| 82 | |
| 83 bool MockWebRTCDataChannelHandler::negotiated() const | |
| 84 { | |
| 85 return m_init.negotiated; | |
| 86 } | |
| 87 | |
| 88 unsigned short MockWebRTCDataChannelHandler::id() const | |
| 89 { | |
| 90 return m_init.id; | |
| 91 } | |
| 92 | |
| 93 unsigned long MockWebRTCDataChannelHandler::bufferedAmount() | |
| 94 { | |
| 95 return 0; | |
| 96 } | |
| 97 | |
| 98 bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data) | |
| 99 { | |
| 100 assert(m_client); | |
| 101 m_client->didReceiveStringData(data); | |
| 102 return true; | |
| 103 } | |
| 104 | |
| 105 bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size) | |
| 106 { | |
| 107 assert(m_client); | |
| 108 m_client->didReceiveRawData(data, size); | |
| 109 return true; | |
| 110 } | |
| 111 | |
| 112 void MockWebRTCDataChannelHandler::close() | |
| 113 { | |
| 114 assert(m_client); | |
| 115 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRTCDat
aChannelHandlerClient::ReadyStateClosed)); | |
| 116 } | |
| 117 | |
| 118 } // namespace content | |
| OLD | NEW |