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

Side by Side Diff: pkg/shelf/test/request_test.dart

Issue 219283008: pkg/shelf (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits Created 6 years, 8 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 | « pkg/shelf/test/media_type_test.dart ('k') | pkg/shelf/test/response_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library shelf.request_test;
6
7 import 'dart:async';
8 import 'dart:convert';
9
10 import 'package:shelf/shelf.dart';
11 import 'package:unittest/unittest.dart';
12
13 Request _request([Map<String, String> headers, Stream<List<int>> body]) {
14 if (headers == null) headers = {};
15 return new Request("/", "", "GET", "", "1.1", Uri.parse('http://localhost/'),
16 headers, body: body);
17 }
18
19 void main() {
20 group("contentLength", () {
21 test("is null without a content-length header", () {
22 var request = _request();
23 expect(request.contentLength, isNull);
24 });
25
26 test("comes from the content-length header", () {
27 var request = _request({
28 'content-length': '42'
29 });
30 expect(request.contentLength, 42);
31 });
32 });
33
34 group("ifModifiedSince", () {
35 test("is null without an If-Modified-Since header", () {
36 var request = _request();
37 expect(request.ifModifiedSince, isNull);
38 });
39
40 test("comes from the Last-Modified header", () {
41 var request = _request({
42 'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT'
43 });
44 expect(request.ifModifiedSince,
45 equals(DateTime.parse("1994-11-06 08:49:37z")));
46 });
47 });
48
49 group("readAsString", () {
50 test("supports a null body", () {
51 var request = _request();
52 expect(request.readAsString(), completion(equals("")));
53 });
54
55 test("supports a Stream<List<int>> body", () {
56 var controller = new StreamController();
57 var request = _request({}, controller.stream);
58 expect(request.readAsString(), completion(equals("hello, world")));
59
60 controller.add([104, 101, 108, 108, 111, 44]);
61 return new Future(() {
62 controller
63 ..add([32, 119, 111, 114, 108, 100])
64 ..close();
65 });
66 });
67
68 test("defaults to UTF-8", () {
69 var request = _request({}, new Stream.fromIterable([[195, 168]]));
70 expect(request.readAsString(), completion(equals("è")));
71 });
72
73 test("the content-type header overrides the default", () {
74 var request = _request({'content-type': 'text/plain; charset=iso-8859-1'},
75 new Stream.fromIterable([[195, 168]]));
76 expect(request.readAsString(), completion(equals("è")));
77 });
78
79 test("an explicit encoding overrides the content-type header", () {
80 var request = _request({'content-type': 'text/plain; charset=iso-8859-1'},
81 new Stream.fromIterable([[195, 168]]));
82 expect(request.readAsString(LATIN1), completion(equals("è")));
83 });
84 });
85
86 group("read", () {
87 test("supports a null body", () {
88 var request = _request();
89 expect(request.read().toList(), completion(isEmpty));
90 });
91
92 test("supports a Stream<List<int>> body", () {
93 var controller = new StreamController();
94 var request = _request({}, controller.stream);
95 expect(request.read().toList(), completion(equals([
96 [104, 101, 108, 108, 111, 44],
97 [32, 119, 111, 114, 108, 100]
98 ])));
99
100 controller.add([104, 101, 108, 108, 111, 44]);
101 return new Future(() {
102 controller
103 ..add([32, 119, 111, 114, 108, 100])
104 ..close();
105 });
106 });
107 });
108
109 group("mimeType", () {
110 test("is null without a content-type header", () {
111 expect(_request().mimeType, isNull);
112 });
113
114 test("comes from the content-type header", () {
115 expect(_request({
116 'content-type': 'text/plain'
117 }).mimeType, equals('text/plain'));
118 });
119
120 test("doesn't include parameters", () {
121 expect(_request({
122 'content-type': 'text/plain; foo=bar; bar=baz'
123 }).mimeType, equals('text/plain'));
124 });
125 });
126
127 group("encoding", () {
128 test("is null without a content-type header", () {
129 expect(_request().encoding, isNull);
130 });
131
132 test("is null without a charset parameter", () {
133 expect(_request({
134 'content-type': 'text/plain'
135 }).encoding, isNull);
136 });
137
138 test("is null with an unrecognized charset parameter", () {
139 expect(_request({
140 'content-type': 'text/plain; charset=fblthp'
141 }).encoding, isNull);
142 });
143
144 test("comes from the content-type charset parameter", () {
145 expect(_request({
146 'content-type': 'text/plain; charset=iso-8859-1'
147 }).encoding, equals(LATIN1));
148 });
149 });
150 }
OLDNEW
« no previous file with comments | « pkg/shelf/test/media_type_test.dart ('k') | pkg/shelf/test/response_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698