Chromium Code Reviews| Index: tests/standalone/io/http_headers_test.dart |
| diff --git a/tests/standalone/io/http_headers_test.dart b/tests/standalone/io/http_headers_test.dart |
| index 980c7c610cdd4f3a73a4da71c0550d52d8788ba2..e26c9fb54fb8906578dd9b5fba78a9b5f71061c7 100644 |
| --- a/tests/standalone/io/http_headers_test.dart |
| +++ b/tests/standalone/io/http_headers_test.dart |
| @@ -165,9 +165,98 @@ void testEnumeration() { |
| Expect.equals(3, totalValues); |
| } |
| +void testHeaderValue() { |
| + void check(HeaderValue headerValue, String value, [Map parameters]) { |
| + Expect.equals(value, headerValue.value); |
| + if (parameters != null) { |
| + Expect.equals(parameters.length, headerValue.parameters.length); |
| + parameters.forEach((String name, String value) { |
| + Expect.equals(value, headerValue.parameters[name]); |
| + }); |
| + } else { |
| + Expect.equals(0, headerValue.parameters.length); |
| + } |
| + } |
| + |
| + HeaderValue headerValue; |
| + headerValue = new HeaderValue.fromString( |
| + "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); |
| + check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
| + headerValue = new HeaderValue.fromString( |
| + "attachment; filename=genome.jpeg;" |
| + "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); |
| + var parameters = { |
| + "filename": "genome.jpeg", |
| + "modification-date": "Wed, 12 February 1997 16:29:51 -0500" |
| + }; |
| + check(headerValue, "attachment", parameters); |
| + headerValue = new HeaderValue.fromString( |
| + " attachment ;filename=genome.jpeg ;" |
| + "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); |
| + check(headerValue, "attachment", parameters); |
| +} |
| + |
| +void testContentType() { |
| + void check(ContentType contentType, |
| + String primaryType, |
| + String subType, |
| + [Map parameters]) { |
| + Expect.equals(primaryType, contentType.primaryType); |
| + Expect.equals(subType, contentType.subType); |
| + Expect.equals("$primaryType/$subType", contentType.value); |
| + if (parameters != null) { |
| + Expect.equals(parameters.length, contentType.parameters.length); |
| + parameters.forEach((String name, String value) { |
| + Expect.equals(value, contentType.parameters[name]); |
| + }); |
| + } else { |
| + Expect.equals(0, contentType.parameters.length); |
| + } |
| + } |
| + |
| + _ContentType contentType; |
| + contentType = new _ContentType(); |
| + Expect.equals("", contentType.primaryType); |
| + Expect.equals("", contentType.subType); |
| + Expect.equals("/", contentType.value); |
| + contentType.value = "text/html"; |
| + Expect.equals("text", contentType.primaryType); |
| + Expect.equals("html", contentType.subType); |
| + Expect.equals("text/html", contentType.value); |
| + |
| + contentType = new _ContentType.fromString("text/html"); |
| + check(contentType, "text", "html"); |
| + Expect.equals("text/html", contentType.toString()); |
| + contentType.parameters["charset"] = "utf-8"; |
| + check(contentType, "text", "html", {"charset": "utf-8"}); |
| + Expect.equals("text/html; charset=utf-8", contentType.toString()); |
| + contentType.parameters["xxx"] = "yyy"; |
| + check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| + Expect.equals("text/html; charset=utf-8; xxx=yyy", contentType.toString()); |
| + |
| + contentType = new _ContentType.fromString("text/html"); |
| + check(contentType, "text", "html"); |
| + contentType = new _ContentType.fromString(" text/html "); |
| + check(contentType, "text", "html"); |
| + contentType = new _ContentType.fromString("text/html; charset=utf-8"); |
| + check(contentType, "text", "html", {"charset": "utf-8"}); |
| + contentType = new _ContentType.fromString(" text/html ; charset = utf-8 "); |
|
Mads Ager (google)
2012/05/21 07:40:39
Long lines.
Søren Gjesse
2012/05/21 11:11:06
Done.
|
| + check(contentType, "text", "html", {"charset": "utf-8"}); |
| + contentType = new _ContentType.fromString("text/html; charset=utf-8; xxx=yyy"); |
| + check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| + contentType = new _ContentType.fromString(" text/html ; charset = utf-8 ; xxx=yyy "); |
| + check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| + contentType = new _ContentType.fromString('text/html; charset=utf-8; xxx="yyy"'); |
| + check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| + contentType = new _ContentType.fromString(" text/html ; charset = utf-8 ; xxx=yyy "); |
| + check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
| +} |
| + |
| main() { |
| testMultiValue(); |
| testExpires(); |
| testHost(); |
| testEnumeration(); |
| + testHeaderValue(); |
| + testContentType(); |
| } |