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