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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "dart:utf"; | 6 import "dart:utf"; |
7 import "dart:math"; | 7 import "dart:math"; |
8 import "dart:async"; | 8 import "dart:async"; |
9 import "dart:collection"; | 9 import "dart:collection"; |
10 import "dart:typed_data"; | 10 import "dart:typed_data"; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 return frame; | 94 return frame; |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 // Test processing messages which are sent in a single frame. | 98 // Test processing messages which are sent in a single frame. |
99 void testFullMessages() { | 99 void testFullMessages() { |
100 void testMessage(int opcode, List<int> message) { | 100 void testMessage(int opcode, List<int> message) { |
101 int messageCount = 0; | 101 int messageCount = 0; |
102 // Use the same web socket protocol transformer for all frames. | 102 // Use the same web socket protocol transformer for all frames. |
103 var transformer = new _WebSocketProtocolTransformer(); | 103 var transformer = new _WebSocketProtocolTransformer(); |
104 var controller = new StreamController(); | 104 var controller = new StreamController(sync: true); |
105 WebSocketMessageCollector mc = new WebSocketMessageCollector( | 105 WebSocketMessageCollector mc = new WebSocketMessageCollector( |
106 controller.stream.transform(transformer), | 106 controller.stream.transform(transformer), |
107 message); | 107 message); |
108 | 108 |
109 List<int> frame = createFrame( | 109 List<int> frame = createFrame( |
110 true, opcode, null, message, 0, message.length); | 110 true, opcode, null, message, 0, message.length); |
111 | 111 |
112 // Update the transformer with one big chunk. | 112 // Update the transformer with one big chunk. |
113 messageCount++; | 113 messageCount++; |
114 controller.add(frame); | 114 controller.add(frame); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 runTest(120, 130, 1); | 158 runTest(120, 130, 1); |
159 runTest(0, 1000, 100); | 159 runTest(0, 1000, 100); |
160 runTest(65534, 65537, 1); | 160 runTest(65534, 65537, 1); |
161 } | 161 } |
162 | 162 |
163 | 163 |
164 // Test processing of frames which are split into fragments. | 164 // Test processing of frames which are split into fragments. |
165 void testFragmentedMessages() { | 165 void testFragmentedMessages() { |
166 // Use the same web socket protocol transformer for all frames. | 166 // Use the same web socket protocol transformer for all frames. |
167 var transformer = new _WebSocketProtocolTransformer(); | 167 var transformer = new _WebSocketProtocolTransformer(); |
168 var controller = new StreamController(); | 168 var controller = new StreamController(sync: true); |
169 WebSocketMessageCollector mc = new WebSocketMessageCollector( | 169 WebSocketMessageCollector mc = new WebSocketMessageCollector( |
170 controller.stream.transform(transformer)); | 170 controller.stream.transform(transformer)); |
171 | 171 |
172 int messageCount = 0; | 172 int messageCount = 0; |
173 int frameCount = 0; | 173 int frameCount = 0; |
174 | 174 |
175 void testFragmentMessage(int opcode, List<int> message, int fragmentSize) { | 175 void testFragmentMessage(int opcode, List<int> message, int fragmentSize) { |
176 messageCount++; | 176 messageCount++; |
177 int messageIndex = 0; | 177 int messageIndex = 0; |
178 int remaining = message.length; | 178 int remaining = message.length; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 runTest(0, 10, 1); | 223 runTest(0, 10, 1); |
224 runTest(120, 130, 1); | 224 runTest(120, 130, 1); |
225 runTest(0, 1000, 100); | 225 runTest(0, 1000, 100); |
226 runTest(65534, 65537, 1); | 226 runTest(65534, 65537, 1); |
227 print("Fragment messages test, messages $messageCount, frames $frameCount"); | 227 print("Fragment messages test, messages $messageCount, frames $frameCount"); |
228 Expect.equals(messageCount, mc.messageCount); | 228 Expect.equals(messageCount, mc.messageCount); |
229 } | 229 } |
230 | 230 |
231 void testUnmaskedMessage() { | 231 void testUnmaskedMessage() { |
232 var transformer = new _WebSocketProtocolTransformer(true); | 232 var transformer = new _WebSocketProtocolTransformer(true); |
233 var controller = new StreamController(); | 233 var controller = new StreamController(sync: true); |
234 var port = new ReceivePort(); | 234 var port = new ReceivePort(); |
235 controller.stream.transform(transformer).listen((_) {}, onError: (e) { | 235 controller.stream.transform(transformer).listen((_) {}, onError: (e) { |
236 port.close(); | 236 port.close(); |
237 }); | 237 }); |
238 var message = new Uint8List(10); | 238 var message = new Uint8List(10); |
239 List<int> frame = createFrame( | 239 List<int> frame = createFrame( |
240 true, FRAME_OPCODE_BINARY, null, message, 0, message.length); | 240 true, FRAME_OPCODE_BINARY, null, message, 0, message.length); |
241 controller.add(frame); | 241 controller.add(frame); |
242 } | 242 } |
243 | 243 |
244 | 244 |
245 void main() { | 245 void main() { |
246 testFullMessages(); | 246 testFullMessages(); |
247 testFragmentedMessages(); | 247 testFragmentedMessages(); |
248 testUnmaskedMessage(); | 248 testUnmaskedMessage(); |
249 } | 249 } |
OLD | NEW |