Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #source("../../../runtime/bin/input_stream.dart"); | 5 #source("../../../runtime/bin/input_stream.dart"); |
| 6 #source("../../../runtime/bin/output_stream.dart"); | 6 #source("../../../runtime/bin/output_stream.dart"); |
| 7 #source("../../../runtime/bin/chunked_stream.dart"); | 7 #source("../../../runtime/bin/chunked_stream.dart"); |
| 8 #source("../../../runtime/bin/string_stream.dart"); | 8 #source("../../../runtime/bin/string_stream.dart"); |
| 9 #source("../../../runtime/bin/stream_util.dart"); | 9 #source("../../../runtime/bin/stream_util.dart"); |
| 10 #source("../../../runtime/bin/http.dart"); | 10 #source("../../../runtime/bin/http.dart"); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (name == "my-header-2") { | 158 if (name == "my-header-2") { |
| 159 myHeader2 = true; | 159 myHeader2 = true; |
| 160 Expect.isTrue(values.indexOf("value 2") != -1); | 160 Expect.isTrue(values.indexOf("value 2") != -1); |
| 161 } | 161 } |
| 162 }); | 162 }); |
| 163 Expect.isTrue(myHeader1); | 163 Expect.isTrue(myHeader1); |
| 164 Expect.isTrue(myHeader2); | 164 Expect.isTrue(myHeader2); |
| 165 Expect.equals(3, totalValues); | 165 Expect.equals(3, totalValues); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void testHeaderValue() { | |
| 169 void check(HeaderValue headerValue, String value, [Map parameters]) { | |
| 170 Expect.equals(value, headerValue.value); | |
| 171 if (parameters != null) { | |
| 172 Expect.equals(parameters.length, headerValue.parameters.length); | |
| 173 parameters.forEach((String name, String value) { | |
| 174 Expect.equals(value, headerValue.parameters[name]); | |
| 175 }); | |
| 176 } else { | |
| 177 Expect.equals(0, headerValue.parameters.length); | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 HeaderValue headerValue; | |
| 182 headerValue = new HeaderValue.fromString( | |
| 183 "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); | |
| 184 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | |
| 185 headerValue = new HeaderValue.fromString( | |
| 186 "attachment; filename=genome.jpeg;" | |
| 187 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); | |
| 188 var parameters = { | |
| 189 "filename": "genome.jpeg", | |
| 190 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" | |
| 191 }; | |
| 192 check(headerValue, "attachment", parameters); | |
| 193 headerValue = new HeaderValue.fromString( | |
| 194 " attachment ;filename=genome.jpeg ;" | |
| 195 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); | |
| 196 check(headerValue, "attachment", parameters); | |
| 197 } | |
| 198 | |
| 199 void testContentType() { | |
| 200 void check(ContentType contentType, | |
| 201 String primaryType, | |
| 202 String subType, | |
| 203 [Map parameters]) { | |
| 204 Expect.equals(primaryType, contentType.primaryType); | |
| 205 Expect.equals(subType, contentType.subType); | |
| 206 Expect.equals("$primaryType/$subType", contentType.value); | |
| 207 if (parameters != null) { | |
| 208 Expect.equals(parameters.length, contentType.parameters.length); | |
| 209 parameters.forEach((String name, String value) { | |
| 210 Expect.equals(value, contentType.parameters[name]); | |
| 211 }); | |
| 212 } else { | |
| 213 Expect.equals(0, contentType.parameters.length); | |
| 214 } | |
| 215 } | |
| 216 | |
| 217 _ContentType contentType; | |
| 218 contentType = new _ContentType(); | |
| 219 Expect.equals("", contentType.primaryType); | |
| 220 Expect.equals("", contentType.subType); | |
| 221 Expect.equals("/", contentType.value); | |
| 222 contentType.value = "text/html"; | |
| 223 Expect.equals("text", contentType.primaryType); | |
| 224 Expect.equals("html", contentType.subType); | |
| 225 Expect.equals("text/html", contentType.value); | |
| 226 | |
| 227 contentType = new _ContentType.fromString("text/html"); | |
| 228 check(contentType, "text", "html"); | |
| 229 Expect.equals("text/html", contentType.toString()); | |
| 230 contentType.parameters["charset"] = "utf-8"; | |
| 231 check(contentType, "text", "html", {"charset": "utf-8"}); | |
| 232 Expect.equals("text/html; charset=utf-8", contentType.toString()); | |
| 233 contentType.parameters["xxx"] = "yyy"; | |
| 234 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | |
| 235 Expect.equals("text/html; charset=utf-8; xxx=yyy", contentType.toString()); | |
| 236 | |
| 237 contentType = new _ContentType.fromString("text/html"); | |
| 238 check(contentType, "text", "html"); | |
| 239 contentType = new _ContentType.fromString(" text/html "); | |
| 240 check(contentType, "text", "html"); | |
| 241 contentType = new _ContentType.fromString("text/html; charset=utf-8"); | |
| 242 check(contentType, "text", "html", {"charset": "utf-8"}); | |
| 243 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.
| |
| 244 check(contentType, "text", "html", {"charset": "utf-8"}); | |
| 245 contentType = new _ContentType.fromString("text/html; charset=utf-8; xxx=yyy") ; | |
| 246 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | |
| 247 contentType = new _ContentType.fromString(" text/html ; charset = utf-8 ; xxx=yyy "); | |
| 248 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | |
| 249 contentType = new _ContentType.fromString('text/html; charset=utf-8; xxx="yyy" '); | |
| 250 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | |
| 251 contentType = new _ContentType.fromString(" text/html ; charset = utf-8 ; xxx=yyy "); | |
| 252 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | |
| 253 } | |
| 254 | |
| 168 main() { | 255 main() { |
| 169 testMultiValue(); | 256 testMultiValue(); |
| 170 testExpires(); | 257 testExpires(); |
| 171 testHost(); | 258 testHost(); |
| 172 testEnumeration(); | 259 testEnumeration(); |
| 260 testHeaderValue(); | |
| 261 testContentType(); | |
| 173 } | 262 } |
| OLD | NEW |