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

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

Issue 10533078: Enable standalone/io/http_test, splitting it into three separate tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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 #import("dart:io"); 1 #import("dart:io");
2 #import("dart:isolate"); 2 #import("dart:isolate");
3 3
4 void sendData(List<int> data, int port) { 4 void sendData(List<int> data, int port) {
5 Socket socket = new Socket("127.0.0.1", port); 5 Socket socket = new Socket("127.0.0.1", port);
6 socket.onConnect = () { 6 socket.onConnect = () {
7 socket.onData = () { 7 socket.onData = () {
8 Expect.fail("No data response was expected"); 8 Expect.fail("No data response was expected");
9 }; 9 };
10 socket.outputStream.onNoPendingWrites = () { 10 socket.outputStream.onNoPendingWrites = () {
11 socket.close(true); 11 socket.close(true);
12 }; 12 };
13 socket.outputStream.write(data); 13 socket.outputStream.write(data);
14 }; 14 };
15 } 15 }
16 16
17 class EarlyCloseTest { 17 class EarlyCloseTest {
18 EarlyCloseTest(Object this.data, 18 EarlyCloseTest(this.data,
19 String this.exception, 19 String this.exception,
20 [bool this.expectRequest = false]); 20 [bool this.expectRequest = false]);
21 21
22 Future execute(HttpServer server) { 22 Future execute(HttpServer server) {
23 Completer c = new Completer(); 23 Completer c = new Completer();
24 24
25 bool calledOnRequest = false; 25 bool calledOnRequest = false;
26 bool calledOnError = false; 26 bool calledOnError = false;
27 server.defaultRequestHandler = 27 server.defaultRequestHandler =
28 (HttpRequest request, HttpResponse response) { 28 (HttpRequest request, HttpResponse response) {
29 Expect.isTrue(expectRequest); 29 Expect.isTrue(expectRequest);
30 Expect.isFalse(calledOnError); 30 Expect.isFalse(calledOnError);
31 Expect.isFalse(calledOnRequest, "onRequest called multiple times"); 31 Expect.isFalse(calledOnRequest, "onRequest called multiple times");
32 calledOnRequest = true; 32 calledOnRequest = true;
33 }; 33 };
34 ReceivePort port = new ReceivePort(); 34 ReceivePort port = new ReceivePort();
35 server.onError = (Exception error) { 35 server.onError = (error) {
36 Expect.isFalse(calledOnError); 36 Expect.isFalse(calledOnError);
37 Expect.equals(exception, error.message); 37 Expect.equals(exception, error.message);
38 Expect.equals(expectRequest, calledOnRequest); 38 Expect.equals(expectRequest, calledOnRequest);
39 calledOnError = true; 39 calledOnError = true;
40 port.close(); 40 port.close();
41 c.complete(null); 41 c.complete(null);
42 }; 42 };
43 43
44 List<int> d; 44 List<int> d;
45 if (data is List<int>) d = data; 45 if (data is List<int>) d = data;
46 if (data is String) d = data.charCodes(); 46 if (data is String) d = data.charCodes();
47 if (d == null) Expect.fail("Invalid data"); 47 if (d == null) Expect.fail("Invalid data");
48 sendData(d, server.port); 48 sendData(d, server.port);
49 49
50 return c.future; 50 return c.future;
51 } 51 }
52 52
53 final Object data; 53 final data;
54 final String exception; 54 final String exception;
55 final bool expectRequest; 55 final bool expectRequest;
56 } 56 }
57 57
58 void testEarlyClose() { 58 void testEarlyClose() {
59 List<EarlyCloseTest> tests = new List<EarlyCloseTest>(); 59 List<EarlyCloseTest> tests = new List<EarlyCloseTest>();
60 void add(Object data, String exception, [bool expectRequest = false]) { 60 void add(Object data, String exception, [bool expectRequest = false]) {
61 tests.add(new EarlyCloseTest(data, exception, expectRequest)); 61 tests.add(new EarlyCloseTest(data, exception, expectRequest));
62 } 62 }
63 // The empty packet is valid. 63 // The empty packet is valid.
(...skipping 21 matching lines...) Expand all
85 } else { 85 } else {
86 server.close(); 86 server.close();
87 } 87 }
88 } 88 }
89 runTest(tests.iterator()); 89 runTest(tests.iterator());
90 } 90 }
91 91
92 void main() { 92 void main() {
93 testEarlyClose(); 93 testEarlyClose();
94 } 94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698