| OLD | NEW |
| 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 part "../../../sdk/lib/io/io_sink.dart"; | 9 part "../../../sdk/lib/io/io_sink.dart"; |
| 10 part "../../../sdk/lib/io/http.dart"; | 10 part "../../../sdk/lib/io/http.dart"; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 Expect.equals(parameters.length, headerValue.parameters.length); | 196 Expect.equals(parameters.length, headerValue.parameters.length); |
| 197 parameters.forEach((String name, String value) { | 197 parameters.forEach((String name, String value) { |
| 198 Expect.equals(value, headerValue.parameters[name]); | 198 Expect.equals(value, headerValue.parameters[name]); |
| 199 }); | 199 }); |
| 200 } else { | 200 } else { |
| 201 Expect.equals(0, headerValue.parameters.length); | 201 Expect.equals(0, headerValue.parameters.length); |
| 202 } | 202 } |
| 203 } | 203 } |
| 204 | 204 |
| 205 HeaderValue headerValue; | 205 HeaderValue headerValue; |
| 206 headerValue = new HeaderValue.fromString( | 206 headerValue = HeaderValue.parse( |
| 207 "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); | 207 "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); |
| 208 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 208 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| 209 headerValue = new HeaderValue("xxx", | 209 headerValue = new HeaderValue("xxx", |
| 210 {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 210 {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| 211 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 211 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| 212 | 212 |
| 213 headerValue = new HeaderValue.fromString( | 213 headerValue = HeaderValue.parse( |
| 214 "attachment; filename=genome.jpeg;" | 214 "attachment; filename=genome.jpeg;" |
| 215 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); | 215 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); |
| 216 var parameters = { | 216 var parameters = { |
| 217 "filename": "genome.jpeg", | 217 "filename": "genome.jpeg", |
| 218 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" | 218 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" |
| 219 }; | 219 }; |
| 220 check(headerValue, "attachment", parameters); | 220 check(headerValue, "attachment", parameters); |
| 221 headerValue = new HeaderValue("attachment", parameters); | 221 headerValue = new HeaderValue("attachment", parameters); |
| 222 check(headerValue, "attachment", parameters); | 222 check(headerValue, "attachment", parameters); |
| 223 headerValue = new HeaderValue.fromString( | 223 headerValue = HeaderValue.parse( |
| 224 " attachment ;filename=genome.jpeg ;" | 224 " attachment ;filename=genome.jpeg ;" |
| 225 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); | 225 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); |
| 226 check(headerValue, "attachment", parameters); | 226 check(headerValue, "attachment", parameters); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void testContentType() { | 229 void testContentType() { |
| 230 void check(ContentType contentType, | 230 void check(ContentType contentType, |
| 231 String primaryType, | 231 String primaryType, |
| 232 String subType, | 232 String subType, |
| 233 [Map parameters]) { | 233 [Map parameters]) { |
| 234 Expect.equals(primaryType, contentType.primaryType); | 234 Expect.equals(primaryType, contentType.primaryType); |
| 235 Expect.equals(subType, contentType.subType); | 235 Expect.equals(subType, contentType.subType); |
| 236 Expect.equals("$primaryType/$subType", contentType.value); | 236 Expect.equals("$primaryType/$subType", contentType.value); |
| 237 if (parameters != null) { | 237 if (parameters != null) { |
| 238 Expect.equals(parameters.length, contentType.parameters.length); | 238 Expect.equals(parameters.length, contentType.parameters.length); |
| 239 parameters.forEach((String name, String value) { | 239 parameters.forEach((String name, String value) { |
| 240 Expect.equals(value, contentType.parameters[name]); | 240 Expect.equals(value, contentType.parameters[name]); |
| 241 }); | 241 }); |
| 242 } else { | 242 } else { |
| 243 Expect.equals(0, contentType.parameters.length); | 243 Expect.equals(0, contentType.parameters.length); |
| 244 } | 244 } |
| 245 } | 245 } |
| 246 | 246 |
| 247 ContentType contentType; | 247 ContentType contentType; |
| 248 contentType = new ContentType("", ""); | 248 contentType = new ContentType("", ""); |
| 249 Expect.equals("", contentType.primaryType); | 249 Expect.equals("", contentType.primaryType); |
| 250 Expect.equals("", contentType.subType); | 250 Expect.equals("", contentType.subType); |
| 251 Expect.equals("/", contentType.value); | 251 Expect.equals("/", contentType.value); |
| 252 | 252 |
| 253 contentType = new ContentType.fromString("text/html"); | 253 contentType = ContentType.parse("text/html"); |
| 254 check(contentType, "text", "html"); | 254 check(contentType, "text", "html"); |
| 255 Expect.equals("text/html", contentType.toString()); | 255 Expect.equals("text/html", contentType.toString()); |
| 256 contentType = new ContentType("text", "html", charset: "utf-8"); | 256 contentType = new ContentType("text", "html", charset: "utf-8"); |
| 257 check(contentType, "text", "html", {"charset": "utf-8"}); | 257 check(contentType, "text", "html", {"charset": "utf-8"}); |
| 258 Expect.equals("text/html; charset=utf-8", contentType.toString()); | 258 Expect.equals("text/html; charset=utf-8", contentType.toString()); |
| 259 | 259 |
| 260 contentType = new ContentType("text", | 260 contentType = new ContentType("text", |
| 261 "html", | 261 "html", |
| 262 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); | 262 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); |
| 263 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 263 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 264 String s = contentType.toString(); | 264 String s = contentType.toString(); |
| 265 bool expectedToString = (s == "text/html; charset=utf-8; xxx=yyy" || | 265 bool expectedToString = (s == "text/html; charset=utf-8; xxx=yyy" || |
| 266 s == "text/html; xxx=yyy; charset=utf-8"); | 266 s == "text/html; xxx=yyy; charset=utf-8"); |
| 267 Expect.isTrue(expectedToString); | 267 Expect.isTrue(expectedToString); |
| 268 | 268 |
| 269 contentType = new ContentType("text", | 269 contentType = new ContentType("text", |
| 270 "html", | 270 "html", |
| 271 charset: "ISO-8859-1", | 271 charset: "ISO-8859-1", |
| 272 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); | 272 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); |
| 273 check(contentType, "text", "html", {"charset": "iso-8859-1", "xxx": "yyy"}); | 273 check(contentType, "text", "html", {"charset": "iso-8859-1", "xxx": "yyy"}); |
| 274 s = contentType.toString(); | 274 s = contentType.toString(); |
| 275 expectedToString = (s == "text/html; charset=iso-8859-1; xxx=yyy" || | 275 expectedToString = (s == "text/html; charset=iso-8859-1; xxx=yyy" || |
| 276 s == "text/html; xxx=yyy; charset=iso-8859-1"); | 276 s == "text/html; xxx=yyy; charset=iso-8859-1"); |
| 277 Expect.isTrue(expectedToString); | 277 Expect.isTrue(expectedToString); |
| 278 | 278 |
| 279 contentType = new ContentType.fromString("text/html"); | 279 contentType = ContentType.parse("text/html"); |
| 280 check(contentType, "text", "html"); | 280 check(contentType, "text", "html"); |
| 281 contentType = new ContentType.fromString(" text/html "); | 281 contentType = ContentType.parse(" text/html "); |
| 282 check(contentType, "text", "html"); | 282 check(contentType, "text", "html"); |
| 283 contentType = new ContentType.fromString("text/html; charset=utf-8"); | 283 contentType = ContentType.parse("text/html; charset=utf-8"); |
| 284 check(contentType, "text", "html", {"charset": "utf-8"}); | 284 check(contentType, "text", "html", {"charset": "utf-8"}); |
| 285 contentType = new ContentType.fromString( | 285 contentType = ContentType.parse( |
| 286 " text/html ; charset = utf-8 "); | 286 " text/html ; charset = utf-8 "); |
| 287 check(contentType, "text", "html", {"charset": "utf-8"}); | 287 check(contentType, "text", "html", {"charset": "utf-8"}); |
| 288 contentType = new ContentType.fromString( | 288 contentType = ContentType.parse( |
| 289 "text/html; charset=utf-8; xxx=yyy"); | 289 "text/html; charset=utf-8; xxx=yyy"); |
| 290 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 290 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 291 contentType = new ContentType.fromString( | 291 contentType = ContentType.parse( |
| 292 " text/html ; charset = utf-8 ; xxx=yyy "); | 292 " text/html ; charset = utf-8 ; xxx=yyy "); |
| 293 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 293 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 294 contentType = new ContentType.fromString( | 294 contentType = ContentType.parse( |
| 295 'text/html; charset=utf-8; xxx="yyy"'); | 295 'text/html; charset=utf-8; xxx="yyy"'); |
| 296 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 296 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 297 contentType = new ContentType.fromString( | 297 contentType = ContentType.parse( |
| 298 " text/html ; charset = utf-8 ; xxx=yyy "); | 298 " text/html ; charset = utf-8 ; xxx=yyy "); |
| 299 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 299 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void testContentTypeCache() { | 302 void testContentTypeCache() { |
| 303 _HttpHeaders headers = new _HttpHeaders("1.1"); | 303 _HttpHeaders headers = new _HttpHeaders("1.1"); |
| 304 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); | 304 headers.set(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 305 Expect.equals("text", headers.contentType.primaryType); | 305 Expect.equals("text", headers.contentType.primaryType); |
| 306 Expect.equals("html", headers.contentType.subType); | 306 Expect.equals("html", headers.contentType.subType); |
| 307 Expect.equals("text/html", headers.contentType.value); | 307 Expect.equals("text/html", headers.contentType.value); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 testIfModifiedSince(); | 415 testIfModifiedSince(); |
| 416 testHost(); | 416 testHost(); |
| 417 testEnumeration(); | 417 testEnumeration(); |
| 418 testHeaderValue(); | 418 testHeaderValue(); |
| 419 testContentType(); | 419 testContentType(); |
| 420 testContentTypeCache(); | 420 testContentTypeCache(); |
| 421 testCookie(); | 421 testCookie(); |
| 422 testInvalidCookie(); | 422 testInvalidCookie(); |
| 423 testHeaderLists(); | 423 testHeaderLists(); |
| 424 } | 424 } |
| OLD | NEW |