| 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("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 |
| 259 contentType = new ContentType("text", |
| 260 "html", |
| 261 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); |
| 257 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 262 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 258 String s = contentType.toString(); | 263 String s = contentType.toString(); |
| 259 bool expectedToString = (s == "text/html; charset=utf-8; xxx=yyy" || | 264 bool expectedToString = (s == "text/html; charset=utf-8; xxx=yyy" || |
| 260 s == "text/html; xxx=yyy; charset=utf-8"); | 265 s == "text/html; xxx=yyy; charset=utf-8"); |
| 261 Expect.isTrue(expectedToString); | 266 Expect.isTrue(expectedToString); |
| 262 | 267 |
| 263 contentType = new _ContentType.fromString("text/html"); | 268 contentType = new ContentType("text", |
| 269 "html", |
| 270 charset: "ISO-8859-1", |
| 271 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); |
| 272 check(contentType, "text", "html", {"charset": "iso-8859-1", "xxx": "yyy"}); |
| 273 s = contentType.toString(); |
| 274 expectedToString = (s == "text/html; charset=iso-8859-1; xxx=yyy" || |
| 275 s == "text/html; xxx=yyy; charset=iso-8859-1"); |
| 276 Expect.isTrue(expectedToString); |
| 277 |
| 278 contentType = new ContentType.fromString("text/html"); |
| 264 check(contentType, "text", "html"); | 279 check(contentType, "text", "html"); |
| 265 contentType = new _ContentType.fromString(" text/html "); | 280 contentType = new ContentType.fromString(" text/html "); |
| 266 check(contentType, "text", "html"); | 281 check(contentType, "text", "html"); |
| 267 contentType = new _ContentType.fromString("text/html; charset=utf-8"); | 282 contentType = new ContentType.fromString("text/html; charset=utf-8"); |
| 268 check(contentType, "text", "html", {"charset": "utf-8"}); | 283 check(contentType, "text", "html", {"charset": "utf-8"}); |
| 269 contentType = new _ContentType.fromString( | 284 contentType = new ContentType.fromString( |
| 270 " text/html ; charset = utf-8 "); | 285 " text/html ; charset = utf-8 "); |
| 271 check(contentType, "text", "html", {"charset": "utf-8"}); | 286 check(contentType, "text", "html", {"charset": "utf-8"}); |
| 272 contentType = new _ContentType.fromString( | 287 contentType = new ContentType.fromString( |
| 273 "text/html; charset=utf-8; xxx=yyy"); | 288 "text/html; charset=utf-8; xxx=yyy"); |
| 274 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 289 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 275 contentType = new _ContentType.fromString( | 290 contentType = new ContentType.fromString( |
| 276 " text/html ; charset = utf-8 ; xxx=yyy "); | 291 " text/html ; charset = utf-8 ; xxx=yyy "); |
| 277 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 292 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 278 contentType = new _ContentType.fromString( | 293 contentType = new ContentType.fromString( |
| 279 'text/html; charset=utf-8; xxx="yyy"'); | 294 'text/html; charset=utf-8; xxx="yyy"'); |
| 280 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 295 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 281 contentType = new _ContentType.fromString( | 296 contentType = new ContentType.fromString( |
| 282 " text/html ; charset = utf-8 ; xxx=yyy "); | 297 " text/html ; charset = utf-8 ; xxx=yyy "); |
| 283 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 298 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 284 } | 299 } |
| 285 | 300 |
| 286 void testContentTypeCache() { | 301 void testContentTypeCache() { |
| 287 _HttpHeaders headers = new _HttpHeaders("1.1"); | 302 _HttpHeaders headers = new _HttpHeaders("1.1"); |
| 288 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); | 303 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 289 Expect.equals("text", headers.contentType.primaryType); | 304 Expect.equals("text", headers.contentType.primaryType); |
| 290 Expect.equals("html", headers.contentType.subType); | 305 Expect.equals("html", headers.contentType.subType); |
| 291 Expect.equals("text/html", headers.contentType.value); | 306 Expect.equals("text/html", headers.contentType.value); |
| 292 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); | 307 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); |
| 293 Expect.equals("text", headers.contentType.primaryType); | 308 Expect.equals("text", headers.contentType.primaryType); |
| 294 Expect.equals("plain", headers.contentType.subType); | 309 Expect.equals("plain", headers.contentType.subType); |
| 295 Expect.equals("text/plain", headers.contentType.value); | 310 Expect.equals("text/plain", headers.contentType.value); |
| 296 headers.removeAll(HttpHeaders.CONTENT_TYPE); | 311 headers.removeAll(HttpHeaders.CONTENT_TYPE); |
| 297 Expect.equals("", headers.contentType.primaryType); | 312 Expect.isNull(headers.contentType); |
| 298 Expect.equals("", headers.contentType.subType); | |
| 299 Expect.equals("/", headers.contentType.value); | |
| 300 } | 313 } |
| 301 | 314 |
| 302 void testCookie() { | 315 void testCookie() { |
| 303 void checkCookiesEquals(a, b) { | 316 void checkCookiesEquals(a, b) { |
| 304 Expect.equals(a.name, b.name); | 317 Expect.equals(a.name, b.name); |
| 305 Expect.equals(a.value, b.value); | 318 Expect.equals(a.value, b.value); |
| 306 Expect.equals(a.expires, b.expires); | 319 Expect.equals(a.expires, b.expires); |
| 307 Expect.equals(a.toString(), b.toString()); | 320 Expect.equals(a.toString(), b.toString()); |
| 308 } | 321 } |
| 309 | 322 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 testIfModifiedSince(); | 414 testIfModifiedSince(); |
| 402 testHost(); | 415 testHost(); |
| 403 testEnumeration(); | 416 testEnumeration(); |
| 404 testHeaderValue(); | 417 testHeaderValue(); |
| 405 testContentType(); | 418 testContentType(); |
| 406 testContentTypeCache(); | 419 testContentTypeCache(); |
| 407 testCookie(); | 420 testCookie(); |
| 408 testInvalidCookie(); | 421 testInvalidCookie(); |
| 409 testHeaderLists(); | 422 testHeaderLists(); |
| 410 } | 423 } |
| OLD | NEW |