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/mock_webrtc_data_channel_handler.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 |
| 17 : public WebMethodTask<MockWebRTCDataChannelHandler> { |
| 18 public: |
| 19 DataChannelReadyStateTask(MockWebRTCDataChannelHandler* object, |
| 20 WebRTCDataChannelHandlerClient* data_channel_client, |
| 21 WebRTCDataChannelHandlerClient::ReadyState state) |
| 22 : WebMethodTask<MockWebRTCDataChannelHandler>(object), |
| 23 data_channel_client_(data_channel_client), |
| 24 state_(state) {} |
| 25 |
| 26 virtual void runIfValid() OVERRIDE { |
| 27 data_channel_client_->didChangeReadyState(state_); |
| 28 } |
| 29 |
| 30 private: |
| 31 WebRTCDataChannelHandlerClient* data_channel_client_; |
| 32 WebRTCDataChannelHandlerClient::ReadyState state_; |
| 33 }; |
| 34 |
| 35 ///////////////////// |
| 36 |
| 37 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler( |
| 38 WebString label, |
| 39 const WebRTCDataChannelInit& init, |
| 40 WebTestDelegate* delegate) |
| 41 : client_(0), label_(label), init_(init), delegate_(delegate) { |
| 42 reliable_ = (init.ordered && init.maxRetransmits == -1 && |
| 43 init.maxRetransmitTime == -1); |
| 44 } |
| 45 |
| 46 void MockWebRTCDataChannelHandler::setClient( |
| 47 WebRTCDataChannelHandlerClient* client) { |
| 48 client_ = client; |
| 49 if (client_) |
| 50 delegate_->postTask(new DataChannelReadyStateTask( |
| 51 this, client_, WebRTCDataChannelHandlerClient::ReadyStateOpen)); |
| 52 } |
| 53 |
| 54 blink::WebString MockWebRTCDataChannelHandler::label() { |
| 55 return label_; |
| 56 } |
| 57 |
| 58 bool MockWebRTCDataChannelHandler::isReliable() { |
| 59 return reliable_; |
| 60 } |
| 61 |
| 62 bool MockWebRTCDataChannelHandler::ordered() const { |
| 63 return init_.ordered; |
| 64 } |
| 65 |
| 66 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const { |
| 67 return init_.maxRetransmitTime; |
| 68 } |
| 69 |
| 70 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const { |
| 71 return init_.maxRetransmits; |
| 72 } |
| 73 |
| 74 WebString MockWebRTCDataChannelHandler::protocol() const { |
| 75 return init_.protocol; |
| 76 } |
| 77 |
| 78 bool MockWebRTCDataChannelHandler::negotiated() const { |
| 79 return init_.negotiated; |
| 80 } |
| 81 |
| 82 unsigned short MockWebRTCDataChannelHandler::id() const { |
| 83 return init_.id; |
| 84 } |
| 85 |
| 86 unsigned long MockWebRTCDataChannelHandler::bufferedAmount() { |
| 87 return 0; |
| 88 } |
| 89 |
| 90 bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data) { |
| 91 assert(client_); |
| 92 client_->didReceiveStringData(data); |
| 93 return true; |
| 94 } |
| 95 |
| 96 bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size) { |
| 97 assert(client_); |
| 98 client_->didReceiveRawData(data, size); |
| 99 return true; |
| 100 } |
| 101 |
| 102 void MockWebRTCDataChannelHandler::close() { |
| 103 assert(client_); |
| 104 delegate_->postTask(new DataChannelReadyStateTask( |
| 105 this, client_, WebRTCDataChannelHandlerClient::ReadyStateClosed)); |
| 106 } |
| 107 |
| 108 } // namespace content |
OLD | NEW |