| OLD | NEW |
| 1 // Copyright (c) 2012, 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:math'; | 6 import 'dart:math'; |
| 7 | 7 |
| 8 part "../../../sdk/lib/io/io_sink.dart"; | 8 part "../../../sdk/lib/io/io_sink.dart"; |
| 9 part "../../../sdk/lib/io/http.dart"; | 9 part "../../../sdk/lib/io/http.dart"; |
| 10 part "../../../sdk/lib/io/http_headers.dart"; | 10 part "../../../sdk/lib/io/http_headers.dart"; |
| 11 part "../../../sdk/lib/io/http_impl.dart"; | 11 part "../../../sdk/lib/io/http_impl.dart"; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 }); | 198 }); |
| 199 } else { | 199 } else { |
| 200 Expect.equals(0, headerValue.parameters.length); | 200 Expect.equals(0, headerValue.parameters.length); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 HeaderValue headerValue; | 204 HeaderValue headerValue; |
| 205 headerValue = new HeaderValue.fromString( | 205 headerValue = new HeaderValue.fromString( |
| 206 "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); | 206 "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); |
| 207 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 207 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| 208 headerValue = new HeaderValue("xxx", |
| 209 {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| 210 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| 211 |
| 208 headerValue = new HeaderValue.fromString( | 212 headerValue = new HeaderValue.fromString( |
| 209 "attachment; filename=genome.jpeg;" | 213 "attachment; filename=genome.jpeg;" |
| 210 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); | 214 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); |
| 211 var parameters = { | 215 var parameters = { |
| 212 "filename": "genome.jpeg", | 216 "filename": "genome.jpeg", |
| 213 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" | 217 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" |
| 214 }; | 218 }; |
| 215 check(headerValue, "attachment", parameters); | 219 check(headerValue, "attachment", parameters); |
| 220 headerValue = new HeaderValue("attachment", parameters); |
| 221 check(headerValue, "attachment", parameters); |
| 216 headerValue = new HeaderValue.fromString( | 222 headerValue = new HeaderValue.fromString( |
| 217 " attachment ;filename=genome.jpeg ;" | 223 " attachment ;filename=genome.jpeg ;" |
| 218 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); | 224 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); |
| 219 check(headerValue, "attachment", parameters); | 225 check(headerValue, "attachment", parameters); |
| 220 } | 226 } |
| 221 | 227 |
| 222 void testContentType() { | 228 void testContentType() { |
| 223 void check(ContentType contentType, | 229 void check(ContentType contentType, |
| 224 String primaryType, | 230 String primaryType, |
| 225 String subType, | 231 String subType, |
| 226 [Map parameters]) { | 232 [Map parameters]) { |
| 227 Expect.equals(primaryType, contentType.primaryType); | 233 Expect.equals(primaryType, contentType.primaryType); |
| 228 Expect.equals(subType, contentType.subType); | 234 Expect.equals(subType, contentType.subType); |
| 229 Expect.equals("$primaryType/$subType", contentType.value); | 235 Expect.equals("$primaryType/$subType", contentType.value); |
| 230 if (parameters != null) { | 236 if (parameters != null) { |
| 231 Expect.equals(parameters.length, contentType.parameters.length); | 237 Expect.equals(parameters.length, contentType.parameters.length); |
| 232 parameters.forEach((String name, String value) { | 238 parameters.forEach((String name, String value) { |
| 233 Expect.equals(value, contentType.parameters[name]); | 239 Expect.equals(value, contentType.parameters[name]); |
| 234 }); | 240 }); |
| 235 } else { | 241 } else { |
| 236 Expect.equals(0, contentType.parameters.length); | 242 Expect.equals(0, contentType.parameters.length); |
| 237 } | 243 } |
| 238 } | 244 } |
| 239 | 245 |
| 240 ContentType contentType; | 246 ContentType contentType; |
| 241 contentType = new ContentType(); | 247 contentType = new ContentType(); |
| 242 Expect.equals("", contentType.primaryType); | 248 Expect.equals("", contentType.primaryType); |
| 243 Expect.equals("", contentType.subType); | 249 Expect.equals("", contentType.subType); |
| 244 Expect.equals("/", contentType.value); | 250 Expect.equals("/", contentType.value); |
| 245 contentType.value = "text/html"; | |
| 246 Expect.equals("text", contentType.primaryType); | |
| 247 Expect.equals("html", contentType.subType); | |
| 248 Expect.equals("text/html", contentType.value); | |
| 249 | 251 |
| 250 contentType = new _ContentType.fromString("text/html"); | 252 contentType = new _ContentType.fromString("text/html"); |
| 251 check(contentType, "text", "html"); | 253 check(contentType, "text", "html"); |
| 252 Expect.equals("text/html", contentType.toString()); | 254 Expect.equals("text/html", contentType.toString()); |
| 253 contentType.parameters["charset"] = "utf-8"; | 255 contentType = new _ContentType.fromString("text/html; charset=utf-8"); |
| 254 check(contentType, "text", "html", {"charset": "utf-8"}); | 256 check(contentType, "text", "html", {"charset": "utf-8"}); |
| 255 Expect.equals("text/html; charset=utf-8", contentType.toString()); | 257 Expect.equals("text/html; charset=utf-8", contentType.toString()); |
| 256 contentType.parameters["xxx"] = "yyy"; | 258 contentType.parameters["xxx"] = "yyy"; |
| 257 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 259 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 258 String s = contentType.toString(); | 260 String s = contentType.toString(); |
| 259 bool expectedToString = (s == "text/html; charset=utf-8; xxx=yyy" || | 261 bool expectedToString = (s == "text/html; charset=utf-8; xxx=yyy" || |
| 260 s == "text/html; xxx=yyy; charset=utf-8"); | 262 s == "text/html; xxx=yyy; charset=utf-8"); |
| 261 Expect.isTrue(expectedToString); | 263 Expect.isTrue(expectedToString); |
| 262 | 264 |
| 263 contentType = new _ContentType.fromString("text/html"); | 265 contentType = new _ContentType.fromString("text/html"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 287 _HttpHeaders headers = new _HttpHeaders("1.1"); | 289 _HttpHeaders headers = new _HttpHeaders("1.1"); |
| 288 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); | 290 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 289 Expect.equals("text", headers.contentType.primaryType); | 291 Expect.equals("text", headers.contentType.primaryType); |
| 290 Expect.equals("html", headers.contentType.subType); | 292 Expect.equals("html", headers.contentType.subType); |
| 291 Expect.equals("text/html", headers.contentType.value); | 293 Expect.equals("text/html", headers.contentType.value); |
| 292 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); | 294 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); |
| 293 Expect.equals("text", headers.contentType.primaryType); | 295 Expect.equals("text", headers.contentType.primaryType); |
| 294 Expect.equals("plain", headers.contentType.subType); | 296 Expect.equals("plain", headers.contentType.subType); |
| 295 Expect.equals("text/plain", headers.contentType.value); | 297 Expect.equals("text/plain", headers.contentType.value); |
| 296 headers.removeAll(HttpHeaders.CONTENT_TYPE); | 298 headers.removeAll(HttpHeaders.CONTENT_TYPE); |
| 297 Expect.equals("", headers.contentType.primaryType); | 299 Expect.isNull(headers.contentType); |
| 298 Expect.equals("", headers.contentType.subType); | |
| 299 Expect.equals("/", headers.contentType.value); | |
| 300 } | 300 } |
| 301 | 301 |
| 302 void testCookie() { | 302 void testCookie() { |
| 303 void checkCookiesEquals(a, b) { | 303 void checkCookiesEquals(a, b) { |
| 304 Expect.equals(a.name, b.name); | 304 Expect.equals(a.name, b.name); |
| 305 Expect.equals(a.value, b.value); | 305 Expect.equals(a.value, b.value); |
| 306 Expect.equals(a.expires, b.expires); | 306 Expect.equals(a.expires, b.expires); |
| 307 Expect.equals(a.toString(), b.toString()); | 307 Expect.equals(a.toString(), b.toString()); |
| 308 } | 308 } |
| 309 | 309 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 testIfModifiedSince(); | 401 testIfModifiedSince(); |
| 402 testHost(); | 402 testHost(); |
| 403 testEnumeration(); | 403 testEnumeration(); |
| 404 testHeaderValue(); | 404 testHeaderValue(); |
| 405 testContentType(); | 405 testContentType(); |
| 406 testContentTypeCache(); | 406 testContentTypeCache(); |
| 407 testCookie(); | 407 testCookie(); |
| 408 testInvalidCookie(); | 408 testInvalidCookie(); |
| 409 testHeaderLists(); | 409 testHeaderLists(); |
| 410 } | 410 } |
| OLD | NEW |