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

Side by Side Diff: pkg/http/test/http_test.dart

Issue 11363063: Add an HTTP library that wraps dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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/test/client_test.dart ('k') | pkg/http/test/request_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) 2012, 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 http_test;
6
7 import 'dart:io';
8
9 import '../../unittest/lib/unittest.dart';
10 import '../lib/http.dart' as http;
11 import 'utils.dart';
12
13 main() {
14 group('http.', () {
15 setUp(startServer);
16 tearDown(stopServer);
17
18 test('head', () {
19 expect(http.head(serverUrl).transform((response) {
20 expect(response.statusCode, equals(200));
21 expect(response.body, equals(''));
22 }), completes);
23 });
24
25 test('get', () {
26 expect(http.get(serverUrl, headers: {
27 'X-Random-Header': 'Value',
28 'X-Other-Header': 'Other Value'
29 }).transform((response) {
30 expect(response.statusCode, equals(200));
31 expect(response.body, parse(equals({
32 'method': 'GET',
33 'path': '/',
34 'headers': {
35 'x-random-header': ['Value'],
36 'x-other-header': ['Other Value']
37 },
38 })));
39 }), completes);
40 });
41
42 test('post', () {
43 expect(http.post(serverUrl, headers: {
44 'X-Random-Header': 'Value',
45 'X-Other-Header': 'Other Value'
46 }, fields: {
47 'some-field': 'value',
48 'other-field': 'other value'
49 }).transform((response) {
50 expect(response.statusCode, equals(200));
51 expect(response.body, parse(equals({
52 'method': 'POST',
53 'path': '/',
54 'headers': {
55 'content-type': [
56 'application/x-www-form-urlencoded; charset=UTF-8'
57 ],
58 'content-length': ['42'],
59 'x-random-header': ['Value'],
60 'x-other-header': ['Other Value']
61 },
62 'body': 'some-field=value&other-field=other%20value'
63 })));
64 }), completes);
65 });
66
67 test('post without fields', () {
68 expect(http.post(serverUrl, headers: {
69 'X-Random-Header': 'Value',
70 'X-Other-Header': 'Other Value',
71 'Content-Type': 'text/plain'
72 }).transform((response) {
73 expect(response.statusCode, equals(200));
74 expect(response.body, parse(equals({
75 'method': 'POST',
76 'path': '/',
77 'headers': {
78 'content-type': ['text/plain'],
79 'x-random-header': ['Value'],
80 'x-other-header': ['Other Value']
81 }
82 })));
83 }), completes);
84 });
85
86 test('put', () {
87 expect(http.put(serverUrl, headers: {
88 'X-Random-Header': 'Value',
89 'X-Other-Header': 'Other Value'
90 }, fields: {
91 'some-field': 'value',
92 'other-field': 'other value'
93 }).transform((response) {
94 expect(response.statusCode, equals(200));
95 expect(response.body, parse(equals({
96 'method': 'PUT',
97 'path': '/',
98 'headers': {
99 'content-type': [
100 'application/x-www-form-urlencoded; charset=UTF-8'
101 ],
102 'content-length': ['42'],
103 'x-random-header': ['Value'],
104 'x-other-header': ['Other Value']
105 },
106 'body': 'some-field=value&other-field=other%20value'
107 })));
108 }), completes);
109 });
110
111 test('put without fields', () {
112 expect(http.put(serverUrl, headers: {
113 'X-Random-Header': 'Value',
114 'X-Other-Header': 'Other Value',
115 'Content-Type': 'text/plain'
116 }).transform((response) {
117 expect(response.statusCode, equals(200));
118 expect(response.body, parse(equals({
119 'method': 'PUT',
120 'path': '/',
121 'headers': {
122 'content-type': ['text/plain'],
123 'x-random-header': ['Value'],
124 'x-other-header': ['Other Value']
125 }
126 })));
127 }), completes);
128 });
129
130 test('delete', () {
131 expect(http.delete(serverUrl, headers: {
132 'X-Random-Header': 'Value',
133 'X-Other-Header': 'Other Value'
134 }).transform((response) {
135 expect(response.statusCode, equals(200));
136 expect(response.body, parse(equals({
137 'method': 'DELETE',
138 'path': '/',
139 'headers': {
140 'x-random-header': ['Value'],
141 'x-other-header': ['Other Value']
142 }
143 })));
144 }), completes);
145 });
146
147 test('read', () {
148 expect(http.read(serverUrl, headers: {
149 'X-Random-Header': 'Value',
150 'X-Other-Header': 'Other Value'
151 }), completion(parse(equals({
152 'method': 'GET',
153 'path': '/',
154 'headers': {
155 'x-random-header': ['Value'],
156 'x-other-header': ['Other Value']
157 },
158 }))));
159 });
160
161 test('read throws an error for a 4** status code', () {
162 expect(http.read(serverUrl.resolve('/error')), throwsHttpException);
163 });
164
165 test('readBytes', () {
166 var future = http.readBytes(serverUrl, headers: {
167 'X-Random-Header': 'Value',
168 'X-Other-Header': 'Other Value'
169 }).transform((bytes) => new String.fromCharCodes(bytes));
170
171 expect(future, completion(parse(equals({
172 'method': 'GET',
173 'path': '/',
174 'headers': {
175 'x-random-header': ['Value'],
176 'x-other-header': ['Other Value']
177 },
178 }))));
179 });
180
181 test('readBytes throws an error for a 4** status code', () {
182 expect(http.readBytes(serverUrl.resolve('/error')), throwsHttpException);
183 });
184 });
185 }
OLDNEW
« no previous file with comments | « pkg/http/test/client_test.dart ('k') | pkg/http/test/request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698