| 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..97e7a88e5f0481fa2034dff222d3b431257d4556 100644
|
| --- a/tests/standalone/io/http_headers_test.dart
|
| +++ b/tests/standalone/io/http_headers_test.dart
|
| @@ -165,9 +165,120 @@ 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 ");
|
| + 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"});
|
| +}
|
| +
|
| +void testContentTypeCache() {
|
| + _HttpHeaders headers = new _HttpHeaders();
|
| + headers.set(HttpHeaders.CONTENT_TYPE, "text/html");
|
| + Expect.equals("text", headers.contentType.primaryType);
|
| + Expect.equals("html", headers.contentType.subType);
|
| + Expect.equals("text/html", headers.contentType.value);
|
| + headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8");
|
| + Expect.equals("text", headers.contentType.primaryType);
|
| + Expect.equals("plain", headers.contentType.subType);
|
| + Expect.equals("text/plain", headers.contentType.value);
|
| + headers.removeAll(HttpHeaders.CONTENT_TYPE);
|
| + Expect.equals("", headers.contentType.primaryType);
|
| + Expect.equals("", headers.contentType.subType);
|
| + Expect.equals("/", headers.contentType.value);
|
| +}
|
| +
|
| main() {
|
| testMultiValue();
|
| testExpires();
|
| testHost();
|
| testEnumeration();
|
| + testHeaderValue();
|
| + testContentType();
|
| + testContentTypeCache();
|
| }
|
|
|