OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 { |
11 WebSocketFrame(int opcode, List<int> data); | 11 WebSocketFrame(int opcode, List<int> data); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 int messageCount = 0; | 101 int messageCount = 0; |
102 | 102 |
103 void testMessage(int opcode, List<int> message) { | 103 void testMessage(int opcode, List<int> message) { |
104 mc.expectedMessage = message; | 104 mc.expectedMessage = message; |
105 List<int> frame = createFrame( | 105 List<int> frame = createFrame( |
106 true, opcode, null, message, 0, message.length); | 106 true, opcode, null, message, 0, message.length); |
107 | 107 |
108 // Update the processor with one big chunk. | 108 // Update the processor with one big chunk. |
109 messageCount++; | 109 messageCount++; |
110 processor.update(frame, 0, frame.length); | 110 processor.update(frame); |
111 Expect.isNull(mc.data); | 111 Expect.isNull(mc.data); |
112 Expect.equals(0, processor._state); | 112 Expect.equals(0, processor._state); |
113 | 113 |
114 // Only run this part on small messages. | 114 // Only run this part on small messages. |
115 if (message.length < 1000) { | 115 if (message.length < 1000) { |
116 // Update the processor one byte at the time. | 116 // Update the processor one byte at the time. |
117 messageCount++; | 117 messageCount++; |
118 for (int i = 0; i < frame.length; i++) { | 118 for (int i = 0; i < frame.length; i++) { |
119 processor.update(frame, i, 1); | 119 processor.update(frame.getRange(i, 1)); |
120 } | 120 } |
121 Expect.equals(0, processor._state); | 121 Expect.equals(0, processor._state); |
122 Expect.isNull(mc.data); | 122 Expect.isNull(mc.data); |
123 | 123 |
124 // Update the processor two bytes at the time. | 124 // Update the processor two bytes at the time. |
125 messageCount++; | 125 messageCount++; |
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.getRange(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>.fixedLength(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; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 int payloadSize = min(fragmentSize, remaining); | 170 int payloadSize = min(fragmentSize, remaining); |
171 lastFrame = payloadSize == remaining; | 171 lastFrame = payloadSize == remaining; |
172 List<int> frame = createFrame(lastFrame, | 172 List<int> frame = createFrame(lastFrame, |
173 firstFrame ? opcode : 0x00, | 173 firstFrame ? opcode : 0x00, |
174 null, | 174 null, |
175 message, | 175 message, |
176 messageIndex, | 176 messageIndex, |
177 payloadSize); | 177 payloadSize); |
178 frameCount++; | 178 frameCount++; |
179 messageIndex += payloadSize; | 179 messageIndex += payloadSize; |
180 processor.update(frame, 0, frame.length); | 180 processor.update(frame); |
181 remaining -= payloadSize; | 181 remaining -= payloadSize; |
182 firstFrame = false; | 182 firstFrame = false; |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 void testMessageFragmentation(int opcode, List<int> message) { | 186 void testMessageFragmentation(int opcode, List<int> message) { |
187 mc.expectedMessage = message; | 187 mc.expectedMessage = message; |
188 | 188 |
189 // Test with fragmenting the message in different fragment sizes. | 189 // Test with fragmenting the message in different fragment sizes. |
190 if (message.length <= 10) { | 190 if (message.length <= 10) { |
(...skipping 22 matching lines...) Expand all Loading... |
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 |