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"; | 5 import "dart:math"; |
6 | 6 |
7 part "../../../sdk/lib/io/websocket.dart"; | 7 part "../../../sdk/lib/io/websocket.dart"; |
8 part "../../../sdk/lib/io/websocket_impl.dart"; | 8 part "../../../sdk/lib/io/websocket_impl.dart"; |
9 | 9 |
10 class WebSocketFrame { | 10 class WebSocketFrame { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 int maskingKey, | 65 int maskingKey, |
66 List<int> data, | 66 List<int> data, |
67 int offset, | 67 int offset, |
68 int count) { | 68 int count) { |
69 int frameSize = 2; | 69 int frameSize = 2; |
70 if (count > 125) frameSize += 2; | 70 if (count > 125) frameSize += 2; |
71 if (count > 65535) frameSize += 6; | 71 if (count > 65535) frameSize += 6; |
72 frameSize += count; | 72 frameSize += count; |
73 // No masking. | 73 // No masking. |
74 assert(maskingKey == null); | 74 assert(maskingKey == null); |
75 List<int> frame = new List<int>(frameSize); | 75 List<int> frame = new List<int>.fixedLength(frameSize); |
76 int frameIndex = 0; | 76 int frameIndex = 0; |
77 frame[frameIndex++] = (fin ? 0x80 : 0x00) | opcode; | 77 frame[frameIndex++] = (fin ? 0x80 : 0x00) | opcode; |
78 if (count < 126) { | 78 if (count < 126) { |
79 frame[frameIndex++] = count; | 79 frame[frameIndex++] = count; |
80 } else if (count < 65536) { | 80 } else if (count < 65536) { |
81 frame[frameIndex++] = 126; | 81 frame[frameIndex++] = 126; |
82 frame[frameIndex++] = count >> 8; | 82 frame[frameIndex++] = count >> 8; |
83 frame[frameIndex++] = count & 0xFF; | 83 frame[frameIndex++] = count & 0xFF; |
84 } else { | 84 } else { |
85 frame[frameIndex++] = 127; | 85 frame[frameIndex++] = 127; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 for (int i = 0; i < frame.length; i += 2) { | 126 for (int i = 0; i < frame.length; i += 2) { |
127 processor.update(frame, i, i + 1 < frame.length ? 2 : 1); | 127 processor.update(frame, i, i + 1 < frame.length ? 2 : 1); |
128 } | 128 } |
129 Expect.equals(0, processor._state); | 129 Expect.equals(0, processor._state); |
130 Expect.isNull(mc.data); | 130 Expect.isNull(mc.data); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 void runTest(int from, int to, int step) { | 134 void runTest(int from, int to, int step) { |
135 for (int messageLength = from; messageLength < to; messageLength += step) { | 135 for (int messageLength = from; messageLength < to; messageLength += step) { |
136 List<int> message = new List<int>(messageLength); | 136 List<int> message = new List<int>.fixedLength(messageLength); |
137 for (int i = 0; i < messageLength; i++) message[i] = i & 0xFF; | 137 for (int i = 0; i < messageLength; i++) message[i] = i & 0xFF; |
138 testMessage(FRAME_OPCODE_TEXT, message); | 138 testMessage(FRAME_OPCODE_TEXT, message); |
139 testMessage(FRAME_OPCODE_BINARY, message); | 139 testMessage(FRAME_OPCODE_BINARY, message); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 // Test different message sizes. | 143 // Test different message sizes. |
144 runTest(0, 10, 1); | 144 runTest(0, 10, 1); |
145 runTest(120, 130, 1); | 145 runTest(120, 130, 1); |
146 runTest(0, 1000, 100); | 146 runTest(0, 1000, 100); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 testFragmentMessage(opcode, message, i); | 192 testFragmentMessage(opcode, message, i); |
193 } | 193 } |
194 } else { | 194 } else { |
195 testFragmentMessage(opcode, message, 10); | 195 testFragmentMessage(opcode, message, 10); |
196 testFragmentMessage(opcode, message, 100); | 196 testFragmentMessage(opcode, message, 100); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 void runTest(int from, int to, int step) { | 200 void runTest(int from, int to, int step) { |
201 for (int messageLength = from; messageLength < to; messageLength += step) { | 201 for (int messageLength = from; messageLength < to; messageLength += step) { |
202 List<int> message = new List<int>(messageLength); | 202 List<int> message = new List<int>.fixedLength(messageLength); |
203 for (int i = 0; i < messageLength; i++) message[i] = i & 0xFF; | 203 for (int i = 0; i < messageLength; i++) message[i] = i & 0xFF; |
204 testMessageFragmentation(FRAME_OPCODE_TEXT, message); | 204 testMessageFragmentation(FRAME_OPCODE_TEXT, message); |
205 testMessageFragmentation(FRAME_OPCODE_BINARY, message); | 205 testMessageFragmentation(FRAME_OPCODE_BINARY, message); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 // Test different message sizes. | 209 // Test different message sizes. |
210 runTest(0, 10, 1); | 210 runTest(0, 10, 1); |
211 runTest(120, 130, 1); | 211 runTest(120, 130, 1); |
212 runTest(0, 1000, 100); | 212 runTest(0, 1000, 100); |
213 runTest(65534, 65537, 1); | 213 runTest(65534, 65537, 1); |
214 print("Fragment messages test, messages $messageCount, frames $frameCount"); | 214 print("Fragment messages test, messages $messageCount, frames $frameCount"); |
215 Expect.equals(messageCount, mc.messageCount); | 215 Expect.equals(messageCount, mc.messageCount); |
216 Expect.equals(0, mc.closeCount); | 216 Expect.equals(0, mc.closeCount); |
217 } | 217 } |
218 | 218 |
219 void main() { | 219 void main() { |
220 testFullMessages(); | 220 testFullMessages(); |
221 testFragmentedMessages(); | 221 testFragmentedMessages(); |
222 } | 222 } |
OLD | NEW |