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

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

Issue 550173007: Version 1.6.1 (Closed) Base URL: http://dart.googlecode.com/svn/branches/1.6/
Patch Set: Created 6 years, 3 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
« no previous file with comments | « dart/tests/corelib/uri_test.dart ('k') | dart/tools/VERSION » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 import "dart:async"; 10 import "dart:async";
(...skipping 25 matching lines...) Expand all
36 certificateName: CERT_NAME) 36 certificateName: CERT_NAME)
37 : HttpServer.bind(HOST_NAME, 37 : HttpServer.bind(HOST_NAME,
38 0, 38 0,
39 backlog: backlog); 39 backlog: backlog);
40 40
41 Future<WebSocket> createClient(int port) => 41 Future<WebSocket> createClient(int port) =>
42 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/'); 42 WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/');
43 43
44 void testRequestResponseClientCloses(int totalConnections, 44 void testRequestResponseClientCloses(int totalConnections,
45 int closeStatus, 45 int closeStatus,
46 String closeReason) { 46 String closeReason,
47 int numberOfMessages) {
48 assert (numberOfMessages >= 1);
49
50 asyncStart();
47 createServer().then((server) { 51 createServer().then((server) {
48 server.transform(new WebSocketTransformer()).listen((webSocket) { 52 server.transform(new WebSocketTransformer()).listen((webSocket) {
53 asyncStart();
49 webSocket.listen( 54 webSocket.listen(
50 webSocket.add, 55 webSocket.add,
51 onDone: () { 56 onDone: () {
52 Expect.equals(closeStatus == null 57 Expect.equals(closeStatus == null
53 ? WebSocketStatus.NO_STATUS_RECEIVED 58 ? WebSocketStatus.NO_STATUS_RECEIVED
54 : closeStatus, webSocket.closeCode); 59 : closeStatus, webSocket.closeCode);
55 Expect.equals( 60 Expect.equals(
56 closeReason == null ? "" 61 closeReason == null ? ""
57 : closeReason, webSocket.closeReason); 62 : closeReason, webSocket.closeReason);
63 asyncEnd();
58 }); 64 });
65 }, onDone: () {
66 asyncEnd();
59 }); 67 });
60 68
61 int closeCount = 0; 69 int closeCount = 0;
62 String messageText = "Hello, world!"; 70 String messageText = "Hello, world!";
63 for (int i = 0; i < totalConnections; i++) { 71 for (int i = 0; i < totalConnections; i++) {
64 int messageCount = 0; 72 asyncStart();
65 createClient(server.port).then((webSocket) { 73 createClient(server.port).then((webSocket) {
66 webSocket.add(messageText); 74 webSocket.add(messageText);
67 webSocket.listen( 75 webSocket.listen(
68 (message) { 76 (message) {
69 messageCount++; 77 numberOfMessages--;
70 if (messageCount < 1 ) { 78 Expect.equals(messageText, message);
71 Expect.equals(messageText, message); 79
80 if (numberOfMessages > 0) {
72 webSocket.add(message); 81 webSocket.add(message);
73 } else { 82 } else {
74 webSocket.close(closeStatus, closeReason); 83 webSocket.close(closeStatus, closeReason);
75 } 84 }
76 }, 85 },
77 onDone: () { 86 onDone: () {
78 Expect.equals(closeStatus == null 87 Expect.equals(closeStatus == null
79 ? WebSocketStatus.NO_STATUS_RECEIVED 88 ? WebSocketStatus.NO_STATUS_RECEIVED
80 : closeStatus, webSocket.closeCode); 89 : closeStatus, webSocket.closeCode);
81 Expect.equals("", webSocket.closeReason); 90 Expect.equals("", webSocket.closeReason);
82 closeCount++; 91 closeCount++;
83 if (closeCount == totalConnections) { 92 if (closeCount == totalConnections) {
84 server.close(); 93 server.close();
85 } 94 }
95 asyncEnd();
86 }); 96 });
87 }); 97 });
88 } 98 }
89 }); 99 });
90 } 100 }
91 101
92 void testRequestResponseServerCloses(int totalConnections, 102 void testRequestResponseServerCloses(int totalConnections,
93 int closeStatus, 103 int closeStatus,
94 String closeReason) { 104 String closeReason) {
95 createServer().then((server) { 105 createServer().then((server) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 WebSocket.connect(url).then((websocket) { 426 WebSocket.connect(url).then((websocket) {
417 return websocket.listen((message) { 427 return websocket.listen((message) {
418 Expect.equals("Hello", message); 428 Expect.equals("Hello", message);
419 websocket.close(); 429 websocket.close();
420 }).asFuture(); 430 }).asFuture();
421 }).then((_) => server.close()); 431 }).then((_) => server.close());
422 }); 432 });
423 } 433 }
424 434
425 void runTests() { 435 void runTests() {
426 testRequestResponseClientCloses(2, null, null); 436 testRequestResponseClientCloses(2, null, null, 1);
427 testRequestResponseClientCloses(2, 3001, null); 437 testRequestResponseClientCloses(2, 3001, null, 2);
428 testRequestResponseClientCloses(2, 3002, "Got tired"); 438 testRequestResponseClientCloses(2, 3002, "Got tired", 3);
429 testRequestResponseServerCloses(2, null, null); 439 testRequestResponseServerCloses(2, null, null);
430 testRequestResponseServerCloses(2, 3001, null); 440 testRequestResponseServerCloses(2, 3001, null);
431 testRequestResponseServerCloses(2, 3002, "Got tired"); 441 testRequestResponseServerCloses(2, 3002, "Got tired");
432 testMessageLength(125); 442 testMessageLength(125);
433 testMessageLength(126); 443 testMessageLength(126);
434 testMessageLength(127); 444 testMessageLength(127);
435 testMessageLength(65535); 445 testMessageLength(65535);
436 testMessageLength(65536); 446 testMessageLength(65536);
437 testDoubleCloseClient(); 447 testDoubleCloseClient();
438 testDoubleCloseServer(); 448 testDoubleCloseServer();
439 testImmediateCloseServer(); 449 testImmediateCloseServer();
440 testImmediateCloseClient(); 450 testImmediateCloseClient();
441 testNoUpgrade(); 451 testNoUpgrade();
442 testUsePOST(); 452 testUsePOST();
443 testConnections(10, 3002, "Got tired"); 453 testConnections(10, 3002, "Got tired");
444 testIndividualUpgrade(5); 454 testIndividualUpgrade(5);
445 testFromUpgradedSocket(); 455 testFromUpgradedSocket();
446 } 456 }
447 } 457 }
448 458
449 459
450 void initializeSSL() { 460 void initializeSSL() {
451 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath(); 461 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath();
452 SecureSocket.initialize(database: testPkcertDatabase, 462 SecureSocket.initialize(database: testPkcertDatabase,
453 password: "dartdart"); 463 password: "dartdart");
454 } 464 }
455 465
456 466
457 main() { 467 main() {
458 asyncStart();
459 new SecurityConfiguration(secure: false).runTests(); 468 new SecurityConfiguration(secure: false).runTests();
460 initializeSSL(); 469 initializeSSL();
461 new SecurityConfiguration(secure: true).runTests(); 470 new SecurityConfiguration(secure: true).runTests();
462 asyncEnd();
463 } 471 }
OLDNEW
« no previous file with comments | « dart/tests/corelib/uri_test.dart ('k') | dart/tools/VERSION » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698