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 WebTestRunner { |
| 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 bool MockWebRTCDataChannelHandler::ordered() const |
| 54 { |
| 55 return m_init.ordered; |
| 56 } |
| 57 |
| 58 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const |
| 59 { |
| 60 return m_init.maxRetransmitTime; |
| 61 } |
| 62 |
| 63 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const |
| 64 { |
| 65 return m_init.maxRetransmits; |
| 66 } |
| 67 |
| 68 WebString MockWebRTCDataChannelHandler::protocol() const |
| 69 { |
| 70 return m_init.protocol; |
| 71 } |
| 72 |
| 73 bool MockWebRTCDataChannelHandler::negotiated() const |
| 74 { |
| 75 return m_init.negotiated; |
| 76 } |
| 77 |
| 78 unsigned short MockWebRTCDataChannelHandler::id() const |
| 79 { |
| 80 return m_init.id; |
| 81 } |
| 82 |
| 83 unsigned long MockWebRTCDataChannelHandler::bufferedAmount() |
| 84 { |
| 85 return 0; |
| 86 } |
| 87 |
| 88 bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data) |
| 89 { |
| 90 assert(m_client); |
| 91 m_client->didReceiveStringData(data); |
| 92 return true; |
| 93 } |
| 94 |
| 95 bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size) |
| 96 { |
| 97 assert(m_client); |
| 98 m_client->didReceiveRawData(data, size); |
| 99 return true; |
| 100 } |
| 101 |
| 102 void MockWebRTCDataChannelHandler::close() |
| 103 { |
| 104 assert(m_client); |
| 105 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRTCDat
aChannelHandlerClient::ReadyStateClosed)); |
| 106 } |
| 107 |
| 108 } |
OLD | NEW |