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

Side by Side Diff: pkg/http_server/test/http_body_test.dart

Issue 46043003: The request may be canceled by http_body, thus allow that when testing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | « pkg/http_server/lib/src/http_body_impl.dart ('k') | no next file » | 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 import 'dart:io'; 5 import 'dart:io';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:http_server/http_server.dart'; 8 import 'package:http_server/http_server.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void testHttpServerRequestBody() { 83 void testHttpServerRequestBody() {
84 void test(String mimeType, 84 void test(String mimeType,
85 List<int> content, 85 List<int> content,
86 dynamic expectedBody, 86 dynamic expectedBody,
87 String type, 87 String type,
88 {bool shouldFail: false, 88 {bool shouldFail: false,
89 Encoding defaultEncoding: UTF8}) { 89 Encoding defaultEncoding: UTF8}) {
90 HttpServer.bind("127.0.0.1", 0).then((server) { 90 HttpServer.bind("127.0.0.1", 0).then((server) {
91 server.transform(new HttpBodyHandler(defaultEncoding: defaultEncoding)) 91 server.transform(new HttpBodyHandler(defaultEncoding: defaultEncoding))
92 .listen((body) { 92 .listen((body) {
93 if (shouldFail) return;
93 expect(shouldFail, isFalse); 94 expect(shouldFail, isFalse);
94 expect(body.type, equals(type)); 95 expect(body.type, equals(type));
95 switch (type) { 96 switch (type) {
96 case "text": 97 case "text":
97 expect(body.request.headers.contentType.mimeType, 98 expect(body.request.headers.contentType.mimeType,
98 equals("text/plain")); 99 equals("text/plain"));
99 expect(body.body, equals(expectedBody)); 100 expect(body.body, equals(expectedBody));
100 break; 101 break;
101 102
102 case "json": 103 case "json":
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 151 }
151 request.add(content); 152 request.add(content);
152 return request.close(); 153 return request.close();
153 }) 154 })
154 .then((response) { 155 .then((response) {
155 if (shouldFail) { 156 if (shouldFail) {
156 expect(response.statusCode, equals(HttpStatus.BAD_REQUEST)); 157 expect(response.statusCode, equals(HttpStatus.BAD_REQUEST));
157 } 158 }
158 return response.drain(); 159 return response.drain();
159 }) 160 })
160 .then((_) { 161 .whenComplete(() {
161 client.close(); 162 client.close();
162 server.close(); 163 server.close();
164 })
165 .catchError((e) {
166 if (!shouldFail) throw e;
163 }); 167 });
164 }); 168 });
165 } 169 }
166 170
167 test("text/plain", "body".codeUnits, "body", "text"); 171 test("text/plain", "body".codeUnits, "body", "text");
168 test("text/plain; charset=utf-8", 172 test("text/plain; charset=utf-8",
169 "body".codeUnits, 173 "body".codeUnits,
170 "body", 174 "body",
171 "text"); 175 "text");
172 test("text/plain; charset=utf-8", [42], "*", "text"); 176 test("text/plain; charset=utf-8", [42], "*", "text");
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 test('application/x-www-form-urlencoded', 332 test('application/x-www-form-urlencoded',
329 'name=%C8%A4%C8%A4'.codeUnits, 333 'name=%C8%A4%C8%A4'.codeUnits,
330 { 'name' : 'ȤȤ' }, 334 { 'name' : 'ȤȤ' },
331 "form"); 335 "form");
332 } 336 }
333 337
334 void main() { 338 void main() {
335 testHttpClientResponseBody(); 339 testHttpClientResponseBody();
336 testHttpServerRequestBody(); 340 testHttpServerRequestBody();
337 } 341 }
OLDNEW
« no previous file with comments | « pkg/http_server/lib/src/http_body_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698