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

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

Issue 13937008: Fix pkg:http tests to include the accept-encoding header. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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/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
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 library http_test; 5 library http_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:http/http.dart' as http; 9 import 'package:http/http.dart' as http;
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 18 matching lines...) Expand all
29 expect(http.get(serverUrl, headers: { 29 expect(http.get(serverUrl, headers: {
30 'X-Random-Header': 'Value', 30 'X-Random-Header': 'Value',
31 'X-Other-Header': 'Other Value' 31 'X-Other-Header': 'Other Value'
32 }).then((response) { 32 }).then((response) {
33 expect(response.statusCode, equals(200)); 33 expect(response.statusCode, equals(200));
34 expect(response.body, parse(equals({ 34 expect(response.body, parse(equals({
35 'method': 'GET', 35 'method': 'GET',
36 'path': '/', 36 'path': '/',
37 'headers': { 37 'headers': {
38 'content-length': ['0'], 38 'content-length': ['0'],
39 'accept-encoding': ['gzip'],
39 'x-random-header': ['Value'], 40 'x-random-header': ['Value'],
40 'x-other-header': ['Other Value'] 41 'x-other-header': ['Other Value']
41 }, 42 },
42 }))); 43 })));
43 }), completes); 44 }), completes);
44 }), completes); 45 }), completes);
45 }); 46 });
46 47
47 test('post', () { 48 test('post', () {
48 expect(startServer().then((_) { 49 expect(startServer().then((_) {
49 expect(http.post(serverUrl, headers: { 50 expect(http.post(serverUrl, headers: {
50 'X-Random-Header': 'Value', 51 'X-Random-Header': 'Value',
51 'X-Other-Header': 'Other Value' 52 'X-Other-Header': 'Other Value'
52 }, fields: { 53 }, fields: {
53 'some-field': 'value', 54 'some-field': 'value',
54 'other-field': 'other value' 55 'other-field': 'other value'
55 }).then((response) { 56 }).then((response) {
56 expect(response.statusCode, equals(200)); 57 expect(response.statusCode, equals(200));
57 expect(response.body, parse(equals({ 58 expect(response.body, parse(equals({
58 'method': 'POST', 59 'method': 'POST',
59 'path': '/', 60 'path': '/',
60 'headers': { 61 'headers': {
61 'content-type': [ 62 'content-type': [
62 'application/x-www-form-urlencoded; charset=utf-8' 63 'application/x-www-form-urlencoded; charset=utf-8'
63 ], 64 ],
64 'content-length': ['40'], 65 'content-length': ['40'],
66 'accept-encoding': ['gzip'],
65 'x-random-header': ['Value'], 67 'x-random-header': ['Value'],
66 'x-other-header': ['Other Value'] 68 'x-other-header': ['Other Value']
67 }, 69 },
68 'body': 'some-field=value&other-field=other+value' 70 'body': 'some-field=value&other-field=other+value'
69 }))); 71 })));
70 }), completes); 72 }), completes);
71 }), completes); 73 }), completes);
72 }); 74 });
73 75
74 test('post without fields', () { 76 test('post without fields', () {
75 expect(startServer().then((_) { 77 expect(startServer().then((_) {
76 expect(http.post(serverUrl, headers: { 78 expect(http.post(serverUrl, headers: {
77 'X-Random-Header': 'Value', 79 'X-Random-Header': 'Value',
78 'X-Other-Header': 'Other Value', 80 'X-Other-Header': 'Other Value',
79 'Content-Type': 'text/plain' 81 'Content-Type': 'text/plain'
80 }).then((response) { 82 }).then((response) {
81 expect(response.statusCode, equals(200)); 83 expect(response.statusCode, equals(200));
82 expect(response.body, parse(equals({ 84 expect(response.body, parse(equals({
83 'method': 'POST', 85 'method': 'POST',
84 'path': '/', 86 'path': '/',
85 'headers': { 87 'headers': {
88 'accept-encoding': ['gzip'],
86 'content-length': ['0'], 89 'content-length': ['0'],
87 'content-type': ['text/plain'], 90 'content-type': ['text/plain'],
88 'x-random-header': ['Value'], 91 'x-random-header': ['Value'],
89 'x-other-header': ['Other Value'] 92 'x-other-header': ['Other Value']
90 } 93 }
91 }))); 94 })));
92 }), completes); 95 }), completes);
93 }), completes); 96 }), completes);
94 }); 97 });
95 98
96 test('put', () { 99 test('put', () {
97 expect(startServer().then((_) { 100 expect(startServer().then((_) {
98 expect(http.put(serverUrl, headers: { 101 expect(http.put(serverUrl, headers: {
99 'X-Random-Header': 'Value', 102 'X-Random-Header': 'Value',
100 'X-Other-Header': 'Other Value' 103 'X-Other-Header': 'Other Value'
101 }, fields: { 104 }, fields: {
102 'some-field': 'value', 105 'some-field': 'value',
103 'other-field': 'other value' 106 'other-field': 'other value'
104 }).then((response) { 107 }).then((response) {
105 expect(response.statusCode, equals(200)); 108 expect(response.statusCode, equals(200));
106 expect(response.body, parse(equals({ 109 expect(response.body, parse(equals({
107 'method': 'PUT', 110 'method': 'PUT',
108 'path': '/', 111 'path': '/',
109 'headers': { 112 'headers': {
110 'content-type': [ 113 'content-type': [
111 'application/x-www-form-urlencoded; charset=utf-8' 114 'application/x-www-form-urlencoded; charset=utf-8'
112 ], 115 ],
116 'accept-encoding': ['gzip'],
113 'content-length': ['40'], 117 'content-length': ['40'],
114 'x-random-header': ['Value'], 118 'x-random-header': ['Value'],
115 'x-other-header': ['Other Value'] 119 'x-other-header': ['Other Value']
116 }, 120 },
117 'body': 'some-field=value&other-field=other+value' 121 'body': 'some-field=value&other-field=other+value'
118 }))); 122 })));
119 }), completes); 123 }), completes);
120 }), completes); 124 }), completes);
121 }); 125 });
122 126
123 test('put without fields', () { 127 test('put without fields', () {
124 expect(startServer().then((_) { 128 expect(startServer().then((_) {
125 expect(http.put(serverUrl, headers: { 129 expect(http.put(serverUrl, headers: {
126 'X-Random-Header': 'Value', 130 'X-Random-Header': 'Value',
127 'X-Other-Header': 'Other Value', 131 'X-Other-Header': 'Other Value',
128 'Content-Type': 'text/plain' 132 'Content-Type': 'text/plain'
129 }).then((response) { 133 }).then((response) {
130 expect(response.statusCode, equals(200)); 134 expect(response.statusCode, equals(200));
131 expect(response.body, parse(equals({ 135 expect(response.body, parse(equals({
132 'method': 'PUT', 136 'method': 'PUT',
133 'path': '/', 137 'path': '/',
134 'headers': { 138 'headers': {
135 'content-length': ['0'], 139 'content-length': ['0'],
140 'accept-encoding': ['gzip'],
136 'content-type': ['text/plain'], 141 'content-type': ['text/plain'],
137 'x-random-header': ['Value'], 142 'x-random-header': ['Value'],
138 'x-other-header': ['Other Value'] 143 'x-other-header': ['Other Value']
139 } 144 }
140 }))); 145 })));
141 }), completes); 146 }), completes);
142 }), completes); 147 }), completes);
143 }); 148 });
144 149
145 test('delete', () { 150 test('delete', () {
146 expect(startServer().then((_) { 151 expect(startServer().then((_) {
147 expect(http.delete(serverUrl, headers: { 152 expect(http.delete(serverUrl, headers: {
148 'X-Random-Header': 'Value', 153 'X-Random-Header': 'Value',
149 'X-Other-Header': 'Other Value' 154 'X-Other-Header': 'Other Value'
150 }).then((response) { 155 }).then((response) {
151 expect(response.statusCode, equals(200)); 156 expect(response.statusCode, equals(200));
152 expect(response.body, parse(equals({ 157 expect(response.body, parse(equals({
153 'method': 'DELETE', 158 'method': 'DELETE',
154 'path': '/', 159 'path': '/',
155 'headers': { 160 'headers': {
156 'content-length': ['0'], 161 'content-length': ['0'],
162 'accept-encoding': ['gzip'],
157 'x-random-header': ['Value'], 163 'x-random-header': ['Value'],
158 'x-other-header': ['Other Value'] 164 'x-other-header': ['Other Value']
159 } 165 }
160 }))); 166 })));
161 }), completes); 167 }), completes);
162 }), completes); 168 }), completes);
163 }); 169 });
164 170
165 test('read', () { 171 test('read', () {
166 expect(startServer().then((_) { 172 expect(startServer().then((_) {
167 expect(http.read(serverUrl, headers: { 173 expect(http.read(serverUrl, headers: {
168 'X-Random-Header': 'Value', 174 'X-Random-Header': 'Value',
169 'X-Other-Header': 'Other Value' 175 'X-Other-Header': 'Other Value'
170 }).then((val) => val), completion(parse(equals({ 176 }).then((val) => val), completion(parse(equals({
171 'method': 'GET', 177 'method': 'GET',
172 'path': '/', 178 'path': '/',
173 'headers': { 179 'headers': {
174 'content-length': ['0'], 180 'content-length': ['0'],
181 'accept-encoding': ['gzip'],
175 'x-random-header': ['Value'], 182 'x-random-header': ['Value'],
176 'x-other-header': ['Other Value'] 183 'x-other-header': ['Other Value']
177 }, 184 },
178 })))); 185 }))));
179 }), completes); 186 }), completes);
180 }); 187 });
181 188
182 test('read throws an error for a 4** status code', () { 189 test('read throws an error for a 4** status code', () {
183 expect(startServer().then((_) { 190 expect(startServer().then((_) {
184 expect(http.read(serverUrl.resolve('/error')), throwsHttpException); 191 expect(http.read(serverUrl.resolve('/error')), throwsHttpException);
185 }), completes); 192 }), completes);
186 }); 193 });
187 194
188 test('readBytes', () { 195 test('readBytes', () {
189 expect(startServer().then((_) { 196 expect(startServer().then((_) {
190 var future = http.readBytes(serverUrl, headers: { 197 var future = http.readBytes(serverUrl, headers: {
191 'X-Random-Header': 'Value', 198 'X-Random-Header': 'Value',
192 'X-Other-Header': 'Other Value' 199 'X-Other-Header': 'Other Value'
193 }).then((bytes) => new String.fromCharCodes(bytes)); 200 }).then((bytes) => new String.fromCharCodes(bytes));
194 201
195 expect(future, completion(parse(equals({ 202 expect(future, completion(parse(equals({
196 'method': 'GET', 203 'method': 'GET',
197 'path': '/', 204 'path': '/',
198 'headers': { 205 'headers': {
199 'content-length': ['0'], 206 'content-length': ['0'],
207 'accept-encoding': ['gzip'],
200 'x-random-header': ['Value'], 208 'x-random-header': ['Value'],
201 'x-other-header': ['Other Value'] 209 'x-other-header': ['Other Value']
202 }, 210 },
203 })))); 211 }))));
204 }), completes); 212 }), completes);
205 }); 213 });
206 214
207 test('readBytes throws an error for a 4** status code', () { 215 test('readBytes throws an error for a 4** status code', () {
208 expect(startServer().then((_) { 216 expect(startServer().then((_) {
209 expect(http.readBytes(serverUrl.resolve('/error')), throwsHttpException) ; 217 expect(http.readBytes(serverUrl.resolve('/error')), throwsHttpException) ;
210 }), completes); 218 }), completes);
211 }); 219 });
212 }); 220 });
213 } 221 }
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