| 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 /* |
| 6 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions |
| 10 * are met: |
| 11 * 1. Redistributions of source code must retain the above copyright |
| 12 * notice, this list of conditions and the following disclaimer. |
| 13 * 2. Redistributions in binary form must reproduce the above copyright |
| 14 * notice, this list of conditions and the following disclaimer in the |
| 15 * documentation and/or other materials provided with the distribution. |
| 16 * |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ |
| 28 |
| 29 #include "content/test/layout_tests/runner/MockWebRTCDataChannelHandler.h" |
| 30 |
| 31 #include <assert.h> |
| 32 |
| 33 #include "content/public/test/layout_tests/WebTestDelegate.h" |
| 34 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandlerClient.h" |
| 35 |
| 36 using namespace blink; |
| 37 |
| 38 namespace WebTestRunner { |
| 39 |
| 40 class DataChannelReadyStateTask : public WebMethodTask<MockWebRTCDataChannelHand
ler> { |
| 41 public: |
| 42 DataChannelReadyStateTask(MockWebRTCDataChannelHandler* object, WebRTCDataCh
annelHandlerClient* dataChannelClient, WebRTCDataChannelHandlerClient::ReadyStat
e state) |
| 43 : WebMethodTask<MockWebRTCDataChannelHandler>(object) |
| 44 , m_dataChannelClient(dataChannelClient) |
| 45 , m_state(state) |
| 46 { |
| 47 } |
| 48 |
| 49 virtual void runIfValid() OVERRIDE |
| 50 { |
| 51 m_dataChannelClient->didChangeReadyState(m_state); |
| 52 } |
| 53 |
| 54 private: |
| 55 WebRTCDataChannelHandlerClient* m_dataChannelClient; |
| 56 WebRTCDataChannelHandlerClient::ReadyState m_state; |
| 57 }; |
| 58 |
| 59 ///////////////////// |
| 60 |
| 61 MockWebRTCDataChannelHandler::MockWebRTCDataChannelHandler(WebString label, cons
t WebRTCDataChannelInit& init, WebTestDelegate* delegate) |
| 62 : m_client(0) |
| 63 , m_label(label) |
| 64 , m_init(init) |
| 65 , m_delegate(delegate) |
| 66 { |
| 67 m_reliable = (init.ordered && init.maxRetransmits == -1 && init.maxRetransmi
tTime == -1); |
| 68 } |
| 69 |
| 70 void MockWebRTCDataChannelHandler::setClient(WebRTCDataChannelHandlerClient* cli
ent) |
| 71 { |
| 72 m_client = client; |
| 73 if (m_client) |
| 74 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRT
CDataChannelHandlerClient::ReadyStateOpen)); |
| 75 } |
| 76 |
| 77 bool MockWebRTCDataChannelHandler::ordered() const |
| 78 { |
| 79 return m_init.ordered; |
| 80 } |
| 81 |
| 82 unsigned short MockWebRTCDataChannelHandler::maxRetransmitTime() const |
| 83 { |
| 84 return m_init.maxRetransmitTime; |
| 85 } |
| 86 |
| 87 unsigned short MockWebRTCDataChannelHandler::maxRetransmits() const |
| 88 { |
| 89 return m_init.maxRetransmits; |
| 90 } |
| 91 |
| 92 WebString MockWebRTCDataChannelHandler::protocol() const |
| 93 { |
| 94 return m_init.protocol; |
| 95 } |
| 96 |
| 97 bool MockWebRTCDataChannelHandler::negotiated() const |
| 98 { |
| 99 return m_init.negotiated; |
| 100 } |
| 101 |
| 102 unsigned short MockWebRTCDataChannelHandler::id() const |
| 103 { |
| 104 return m_init.id; |
| 105 } |
| 106 |
| 107 unsigned long MockWebRTCDataChannelHandler::bufferedAmount() |
| 108 { |
| 109 return 0; |
| 110 } |
| 111 |
| 112 bool MockWebRTCDataChannelHandler::sendStringData(const WebString& data) |
| 113 { |
| 114 assert(m_client); |
| 115 m_client->didReceiveStringData(data); |
| 116 return true; |
| 117 } |
| 118 |
| 119 bool MockWebRTCDataChannelHandler::sendRawData(const char* data, size_t size) |
| 120 { |
| 121 assert(m_client); |
| 122 m_client->didReceiveRawData(data, size); |
| 123 return true; |
| 124 } |
| 125 |
| 126 void MockWebRTCDataChannelHandler::close() |
| 127 { |
| 128 assert(m_client); |
| 129 m_delegate->postTask(new DataChannelReadyStateTask(this, m_client, WebRTCDat
aChannelHandlerClient::ReadyStateClosed)); |
| 130 } |
| 131 |
| 132 } |
| OLD | NEW |