OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 #import("dart:math"); |
| 6 |
5 #source("../../../runtime/bin/websocket.dart"); | 7 #source("../../../runtime/bin/websocket.dart"); |
6 #source("../../../runtime/bin/websocket_impl.dart"); | 8 #source("../../../runtime/bin/websocket_impl.dart"); |
7 | 9 |
8 class WebSocketFrame { | 10 class WebSocketFrame { |
9 WebSocketFrame(int opcode, List<int> data); | 11 WebSocketFrame(int opcode, List<int> data); |
10 } | 12 } |
11 | 13 |
12 // Class that when hooked up to the web socket protocol processor will | 14 // Class that when hooked up to the web socket protocol processor will |
13 // collect the message and expect it to be equal to the | 15 // collect the message and expect it to be equal to the |
14 // expectedMessage field when fully received. | 16 // expectedMessage field when fully received. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 int messageCount = 0; | 160 int messageCount = 0; |
159 int frameCount = 0; | 161 int frameCount = 0; |
160 | 162 |
161 void testFragmentMessage(int opcode, List<int> message, int fragmentSize) { | 163 void testFragmentMessage(int opcode, List<int> message, int fragmentSize) { |
162 messageCount++; | 164 messageCount++; |
163 int messageIndex = 0; | 165 int messageIndex = 0; |
164 int remaining = message.length; | 166 int remaining = message.length; |
165 bool firstFrame = true; | 167 bool firstFrame = true; |
166 bool lastFrame = false; | 168 bool lastFrame = false; |
167 while (!lastFrame) { | 169 while (!lastFrame) { |
168 int payloadSize = Math.min(fragmentSize, remaining); | 170 int payloadSize = min(fragmentSize, remaining); |
169 lastFrame = payloadSize == remaining; | 171 lastFrame = payloadSize == remaining; |
170 List<int> frame = createFrame(lastFrame, | 172 List<int> frame = createFrame(lastFrame, |
171 firstFrame ? opcode : 0x00, | 173 firstFrame ? opcode : 0x00, |
172 null, | 174 null, |
173 message, | 175 message, |
174 messageIndex, | 176 messageIndex, |
175 payloadSize); | 177 payloadSize); |
176 frameCount++; | 178 frameCount++; |
177 messageIndex += payloadSize; | 179 messageIndex += payloadSize; |
178 processor.update(frame, 0, frame.length); | 180 processor.update(frame, 0, frame.length); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 runTest(65534, 65537, 1); | 213 runTest(65534, 65537, 1); |
212 print("Fragment messages test, messages $messageCount, frames $frameCount"); | 214 print("Fragment messages test, messages $messageCount, frames $frameCount"); |
213 Expect.equals(messageCount, mc.messageCount); | 215 Expect.equals(messageCount, mc.messageCount); |
214 Expect.equals(0, mc.closeCount); | 216 Expect.equals(0, mc.closeCount); |
215 } | 217 } |
216 | 218 |
217 void main() { | 219 void main() { |
218 testFullMessages(); | 220 testFullMessages(); |
219 testFragmentedMessages(); | 221 testFragmentedMessages(); |
220 } | 222 } |
OLD | NEW |