OLD | NEW |
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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 import "dart:typeddata"; | 8 import "dart:typeddata"; |
9 | 9 |
10 void testClientRequest(void handler(request)) { | 10 void testClientRequest(void handler(request)) { |
(...skipping 17 matching lines...) Expand all Loading... |
28 }) | 28 }) |
29 .catchError((error) { | 29 .catchError((error) { |
30 server.close(); | 30 server.close(); |
31 client.close(); | 31 client.close(); |
32 }); | 32 }); |
33 }); | 33 }); |
34 } | 34 } |
35 | 35 |
36 void testResponseDone() { | 36 void testResponseDone() { |
37 testClientRequest((request) { | 37 testClientRequest((request) { |
38 request.close(); | 38 request.close().then((res1) { |
39 request.done.then((res1) { | 39 request.done.then((res2) { |
40 request.response.then((res2) { | |
41 Expect.equals(res1, res2); | 40 Expect.equals(res1, res2); |
42 }); | 41 }); |
43 }); | 42 }); |
44 return request.response; | 43 return request.done; |
45 }); | 44 }); |
46 } | 45 } |
47 | 46 |
48 void testBadResponseAdd() { | 47 void testBadResponseAdd() { |
49 testClientRequest((request) { | 48 testClientRequest((request) { |
50 var port = new ReceivePort(); | 49 var port = new ReceivePort(); |
51 request.contentLength = 0; | 50 request.contentLength = 0; |
52 request.writeBytes([0]); | 51 request.writeBytes([0]); |
53 request.close(); | 52 request.close(); |
54 request.done.catchError((error) { | 53 request.done.catchError((error) { |
55 port.close(); | 54 port.close(); |
56 }, test: (e) => e is HttpException); | 55 }, test: (e) => e is HttpException); |
57 return request.response; | 56 return request.done; |
58 }); | 57 }); |
59 | 58 |
60 testClientRequest((request) { | 59 testClientRequest((request) { |
61 var port = new ReceivePort(); | 60 var port = new ReceivePort(); |
62 request.contentLength = 5; | 61 request.contentLength = 5; |
63 request.writeBytes([0, 0, 0]); | 62 request.writeBytes([0, 0, 0]); |
64 request.writeBytes([0, 0, 0]); | 63 request.writeBytes([0, 0, 0]); |
65 request.close(); | 64 request.close(); |
66 request.done.catchError((error) { | 65 request.done.catchError((error) { |
67 port.close(); | 66 port.close(); |
68 }, test: (e) => e is HttpException); | 67 }, test: (e) => e is HttpException); |
69 return request.response; | 68 return request.done; |
70 }); | 69 }); |
71 | 70 |
72 testClientRequest((request) { | 71 testClientRequest((request) { |
73 var port = new ReceivePort(); | 72 var port = new ReceivePort(); |
74 request.contentLength = 0; | 73 request.contentLength = 0; |
75 request.writeBytes(new Uint8List(64 * 1024)); | 74 request.writeBytes(new Uint8List(64 * 1024)); |
76 request.writeBytes(new Uint8List(64 * 1024)); | 75 request.writeBytes(new Uint8List(64 * 1024)); |
77 request.writeBytes(new Uint8List(64 * 1024)); | 76 request.writeBytes(new Uint8List(64 * 1024)); |
78 request.close(); | 77 request.close(); |
79 request.done.catchError((error) { | 78 request.done.catchError((error) { |
80 port.close(); | 79 port.close(); |
81 }, test: (e) => e is HttpException); | 80 }, test: (e) => e is HttpException); |
82 return request.response; | 81 return request.done; |
83 }); | 82 }); |
84 } | 83 } |
85 | 84 |
86 void testBadResponseClose() { | 85 void testBadResponseClose() { |
87 testClientRequest((request) { | 86 testClientRequest((request) { |
88 var port = new ReceivePort(); | 87 var port = new ReceivePort(); |
89 request.contentLength = 5; | 88 request.contentLength = 5; |
90 request.close(); | 89 request.close(); |
91 request.done.catchError((error) { | 90 request.done.catchError((error) { |
92 port.close(); | 91 port.close(); |
93 }, test: (e) => e is HttpException); | 92 }, test: (e) => e is HttpException); |
94 return request.response; | 93 return request.done; |
95 }); | 94 }); |
96 | 95 |
97 testClientRequest((request) { | 96 testClientRequest((request) { |
98 var port = new ReceivePort(); | 97 var port = new ReceivePort(); |
99 request.contentLength = 5; | 98 request.contentLength = 5; |
100 request.writeBytes([0]); | 99 request.writeBytes([0]); |
101 request.close(); | 100 request.close(); |
102 request.done.catchError((error) { | 101 request.done.catchError((error) { |
103 port.close(); | 102 port.close(); |
104 }, test: (e) => e is HttpException); | 103 }, test: (e) => e is HttpException); |
105 return request.response; | 104 return request.done; |
106 }); | 105 }); |
107 } | 106 } |
108 | 107 |
109 void main() { | 108 void main() { |
110 testResponseDone(); | 109 testResponseDone(); |
111 testBadResponseAdd(); | 110 testBadResponseAdd(); |
112 testBadResponseClose(); | 111 testBadResponseClose(); |
113 } | 112 } |
OLD | NEW |