Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: tests/standalone/io/web_socket_protocol_processor_test.dart

Issue 12316036: Merge IO v2 branch to bleeding edge (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r18818 Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, 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 7
8 part "../../../sdk/lib/io/http.dart";
9 part "../../../sdk/lib/io/io_stream_consumer.dart";
7 part "../../../sdk/lib/io/websocket.dart"; 10 part "../../../sdk/lib/io/websocket.dart";
8 part "../../../sdk/lib/io/websocket_impl.dart"; 11 part "../../../sdk/lib/io/websocket_impl.dart";
9 12
10 class WebSocketFrame { 13 class WebSocketFrame {
11 WebSocketFrame(int opcode, List<int> data); 14 WebSocketFrame(int opcode, List<int> data);
12 } 15 }
13 16
14 // Class that when hooked up to the web socket protocol processor will 17 // Class that when hooked up to the web socket protocol processor will
15 // collect the message and expect it to be equal to the 18 // collect the message and expect it to be equal to the
16 // expectedMessage field when fully received. 19 // expectedMessage field when fully received.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 103
101 int messageCount = 0; 104 int messageCount = 0;
102 105
103 void testMessage(int opcode, List<int> message) { 106 void testMessage(int opcode, List<int> message) {
104 mc.expectedMessage = message; 107 mc.expectedMessage = message;
105 List<int> frame = createFrame( 108 List<int> frame = createFrame(
106 true, opcode, null, message, 0, message.length); 109 true, opcode, null, message, 0, message.length);
107 110
108 // Update the processor with one big chunk. 111 // Update the processor with one big chunk.
109 messageCount++; 112 messageCount++;
110 processor.update(frame); 113 processor.update(frame, 0, frame.length);
111 Expect.isNull(mc.data); 114 Expect.isNull(mc.data);
112 Expect.equals(0, processor._state); 115 Expect.equals(0, processor._state);
113 116
114 // Only run this part on small messages. 117 // Only run this part on small messages.
115 if (message.length < 1000) { 118 if (message.length < 1000) {
116 // Update the processor one byte at the time. 119 // Update the processor one byte at the time.
117 messageCount++; 120 messageCount++;
118 for (int i = 0; i < frame.length; i++) { 121 for (int i = 0; i < frame.length; i++) {
119 processor.update(frame.getRange(i, 1)); 122 processor.update(frame, i, 1);
120 } 123 }
121 Expect.equals(0, processor._state); 124 Expect.equals(0, processor._state);
122 Expect.isNull(mc.data); 125 Expect.isNull(mc.data);
123 126
124 // Update the processor two bytes at the time. 127 // Update the processor two bytes at the time.
125 messageCount++; 128 messageCount++;
126 for (int i = 0; i < frame.length; i += 2) { 129 for (int i = 0; i < frame.length; i += 2) {
127 processor.update(frame.getRange(i, i + 1 < frame.length ? 2 : 1)); 130 processor.update(frame, i, i + 1 < frame.length ? 2 : 1);
128 } 131 }
129 Expect.equals(0, processor._state); 132 Expect.equals(0, processor._state);
130 Expect.isNull(mc.data); 133 Expect.isNull(mc.data);
131 } 134 }
132 } 135 }
133 136
134 void runTest(int from, int to, int step) { 137 void runTest(int from, int to, int step) {
135 for (int messageLength = from; messageLength < to; messageLength += step) { 138 for (int messageLength = from; messageLength < to; messageLength += step) {
136 List<int> message = new List<int>.fixedLength(messageLength); 139 List<int> message = new List<int>.fixedLength(messageLength);
137 for (int i = 0; i < messageLength; i++) message[i] = i & 0xFF; 140 for (int i = 0; i < messageLength; i++) message[i] = i & 0xFF;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 int payloadSize = min(fragmentSize, remaining); 173 int payloadSize = min(fragmentSize, remaining);
171 lastFrame = payloadSize == remaining; 174 lastFrame = payloadSize == remaining;
172 List<int> frame = createFrame(lastFrame, 175 List<int> frame = createFrame(lastFrame,
173 firstFrame ? opcode : 0x00, 176 firstFrame ? opcode : 0x00,
174 null, 177 null,
175 message, 178 message,
176 messageIndex, 179 messageIndex,
177 payloadSize); 180 payloadSize);
178 frameCount++; 181 frameCount++;
179 messageIndex += payloadSize; 182 messageIndex += payloadSize;
180 processor.update(frame); 183 processor.update(frame, 0, frame.length);
181 remaining -= payloadSize; 184 remaining -= payloadSize;
182 firstFrame = false; 185 firstFrame = false;
183 } 186 }
184 } 187 }
185 188
186 void testMessageFragmentation(int opcode, List<int> message) { 189 void testMessageFragmentation(int opcode, List<int> message) {
187 mc.expectedMessage = message; 190 mc.expectedMessage = message;
188 191
189 // Test with fragmenting the message in different fragment sizes. 192 // Test with fragmenting the message in different fragment sizes.
190 if (message.length <= 10) { 193 if (message.length <= 10) {
(...skipping 22 matching lines...) Expand all
213 runTest(65534, 65537, 1); 216 runTest(65534, 65537, 1);
214 print("Fragment messages test, messages $messageCount, frames $frameCount"); 217 print("Fragment messages test, messages $messageCount, frames $frameCount");
215 Expect.equals(messageCount, mc.messageCount); 218 Expect.equals(messageCount, mc.messageCount);
216 Expect.equals(0, mc.closeCount); 219 Expect.equals(0, mc.closeCount);
217 } 220 }
218 221
219 void main() { 222 void main() {
220 testFullMessages(); 223 testFullMessages();
221 testFragmentedMessages(); 224 testFragmentedMessages();
222 } 225 }
OLDNEW
« no previous file with comments | « tests/standalone/io/web_socket_no_secure_test.dart ('k') | tests/standalone/io/web_socket_secure_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698