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 library dart.io; | 5 library dart.io; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import "dart:async"; | 8 import "dart:async"; |
9 import "dart:collection"; | 9 import "dart:collection"; |
10 import "dart:convert"; | 10 import "dart:convert"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 Expect.isNull(headers[HttpHeaders.PRAGMA]); | 45 Expect.isNull(headers[HttpHeaders.PRAGMA]); |
46 headers.add(HttpHeaders.PRAGMA, "pragma1"); | 46 headers.add(HttpHeaders.PRAGMA, "pragma1"); |
47 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); | 47 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); |
48 Expect.equals(1, headers["pragma"].length); | 48 Expect.equals(1, headers["pragma"].length); |
49 Expect.equals(1, headers["Pragma"].length); | 49 Expect.equals(1, headers["Pragma"].length); |
50 Expect.equals(1, headers["PRAGMA"].length); | 50 Expect.equals(1, headers["PRAGMA"].length); |
51 Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA)); | 51 Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA)); |
52 | 52 |
53 headers.add(HttpHeaders.PRAGMA, "pragma2"); | 53 headers.add(HttpHeaders.PRAGMA, "pragma2"); |
54 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); | 54 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); |
55 Expect.throws(() => headers.value(HttpHeaders.PRAGMA), | 55 Expect.throws( |
56 (e) => e is HttpException); | 56 () => headers.value(HttpHeaders.PRAGMA), (e) => e is HttpException); |
57 | 57 |
58 headers.add(HttpHeaders.PRAGMA, ["pragma3", "pragma4"]); | 58 headers.add(HttpHeaders.PRAGMA, ["pragma3", "pragma4"]); |
59 Expect.listEquals(["pragma1", "pragma2", "pragma3", "pragma4"], | 59 Expect.listEquals(["pragma1", "pragma2", "pragma3", "pragma4"], |
60 headers[HttpHeaders.PRAGMA]); | 60 headers[HttpHeaders.PRAGMA]); |
61 | 61 |
62 headers.remove(HttpHeaders.PRAGMA, "pragma3"); | 62 headers.remove(HttpHeaders.PRAGMA, "pragma3"); |
63 Expect.equals(3, headers[HttpHeaders.PRAGMA].length); | 63 Expect.equals(3, headers[HttpHeaders.PRAGMA].length); |
64 Expect.listEquals(["pragma1", "pragma2", "pragma4"], | 64 Expect.listEquals( |
65 headers[HttpHeaders.PRAGMA]); | 65 ["pragma1", "pragma2", "pragma4"], headers[HttpHeaders.PRAGMA]); |
66 | 66 |
67 headers.remove(HttpHeaders.PRAGMA, "pragma3"); | 67 headers.remove(HttpHeaders.PRAGMA, "pragma3"); |
68 Expect.equals(3, headers[HttpHeaders.PRAGMA].length); | 68 Expect.equals(3, headers[HttpHeaders.PRAGMA].length); |
69 | 69 |
70 headers.set(HttpHeaders.PRAGMA, "pragma5"); | 70 headers.set(HttpHeaders.PRAGMA, "pragma5"); |
71 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); | 71 Expect.equals(1, headers[HttpHeaders.PRAGMA].length); |
72 | 72 |
73 headers.set(HttpHeaders.PRAGMA, ["pragma6", "pragma7"]); | 73 headers.set(HttpHeaders.PRAGMA, ["pragma6", "pragma7"]); |
74 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); | 74 Expect.equals(2, headers[HttpHeaders.PRAGMA].length); |
75 | 75 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 Expect.equals(parameters.length, headerValue.parameters.length); | 268 Expect.equals(parameters.length, headerValue.parameters.length); |
269 parameters.forEach((String name, String value) { | 269 parameters.forEach((String name, String value) { |
270 Expect.equals(value, headerValue.parameters[name]); | 270 Expect.equals(value, headerValue.parameters[name]); |
271 }); | 271 }); |
272 } else { | 272 } else { |
273 Expect.equals(0, headerValue.parameters.length); | 273 Expect.equals(0, headerValue.parameters.length); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 HeaderValue headerValue; | 277 HeaderValue headerValue; |
278 headerValue = HeaderValue.parse( | 278 headerValue = |
279 "xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); | 279 HeaderValue.parse("xxx; aaa=bbb; ccc=\"\\\";\\a\"; ddd=\" \""); |
280 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 280 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
281 headerValue = new HeaderValue("xxx", | 281 headerValue = |
282 {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 282 new HeaderValue("xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
283 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); | 283 check(headerValue, "xxx", {"aaa": "bbb", "ccc": '\";a', "ddd": " "}); |
284 | 284 |
285 headerValue = HeaderValue.parse( | 285 headerValue = HeaderValue.parse("attachment; filename=genome.jpeg;" |
286 "attachment; filename=genome.jpeg;" | 286 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); |
287 "modification-date=\"Wed, 12 February 1997 16:29:51 -0500\""); | |
288 var parameters = { | 287 var parameters = { |
289 "filename": "genome.jpeg", | 288 "filename": "genome.jpeg", |
290 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" | 289 "modification-date": "Wed, 12 February 1997 16:29:51 -0500" |
291 }; | 290 }; |
292 check(headerValue, "attachment", parameters); | 291 check(headerValue, "attachment", parameters); |
293 headerValue = new HeaderValue("attachment", parameters); | 292 headerValue = new HeaderValue("attachment", parameters); |
294 check(headerValue, "attachment", parameters); | 293 check(headerValue, "attachment", parameters); |
295 headerValue = HeaderValue.parse( | 294 headerValue = HeaderValue.parse(" attachment ;filename=genome.jpeg ;" |
296 " attachment ;filename=genome.jpeg ;" | 295 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\""); |
297 "modification-date = \"Wed, 12 February 1997 16:29:51 -0500\"" ); | |
298 check(headerValue, "attachment", parameters); | 296 check(headerValue, "attachment", parameters); |
299 headerValue = HeaderValue.parse("xxx; aaa; bbb; ccc"); | 297 headerValue = HeaderValue.parse("xxx; aaa; bbb; ccc"); |
300 check(headerValue, "xxx", {"aaa": null, "bbb": null, "ccc": null}); | 298 check(headerValue, "xxx", {"aaa": null, "bbb": null, "ccc": null}); |
301 } | 299 } |
302 | 300 |
303 void testContentType() { | 301 void testContentType() { |
304 void check(ContentType contentType, | 302 void check(ContentType contentType, String primaryType, String subType, |
305 String primaryType, | 303 [Map parameters]) { |
306 String subType, | |
307 [Map parameters]) { | |
308 Expect.equals(primaryType, contentType.primaryType); | 304 Expect.equals(primaryType, contentType.primaryType); |
309 Expect.equals(subType, contentType.subType); | 305 Expect.equals(subType, contentType.subType); |
310 Expect.equals("$primaryType/$subType", contentType.value); | 306 Expect.equals("$primaryType/$subType", contentType.value); |
311 if (parameters != null) { | 307 if (parameters != null) { |
312 Expect.equals(parameters.length, contentType.parameters.length); | 308 Expect.equals(parameters.length, contentType.parameters.length); |
313 parameters.forEach((String name, String value) { | 309 parameters.forEach((String name, String value) { |
314 Expect.equals(value, contentType.parameters[name]); | 310 Expect.equals(value, contentType.parameters[name]); |
315 }); | 311 }); |
316 } else { | 312 } else { |
317 Expect.equals(0, contentType.parameters.length); | 313 Expect.equals(0, contentType.parameters.length); |
318 } | 314 } |
319 } | 315 } |
320 | 316 |
321 ContentType contentType; | 317 ContentType contentType; |
322 contentType = new ContentType("", ""); | 318 contentType = new ContentType("", ""); |
323 Expect.equals("", contentType.primaryType); | 319 Expect.equals("", contentType.primaryType); |
324 Expect.equals("", contentType.subType); | 320 Expect.equals("", contentType.subType); |
325 Expect.equals("/", contentType.value); | 321 Expect.equals("/", contentType.value); |
326 Expect.throws(() => contentType.parameters["xxx"] = "yyy", | 322 Expect.throws(() => contentType.parameters["xxx"] = "yyy", |
327 (e) => e is UnsupportedError); | 323 (e) => e is UnsupportedError); |
328 | 324 |
329 contentType = ContentType.parse("text/html"); | 325 contentType = ContentType.parse("text/html"); |
330 check(contentType, "text", "html"); | 326 check(contentType, "text", "html"); |
331 Expect.equals("text/html", contentType.toString()); | 327 Expect.equals("text/html", contentType.toString()); |
332 contentType = new ContentType("text", "html", charset: "utf-8"); | 328 contentType = new ContentType("text", "html", charset: "utf-8"); |
333 check(contentType, "text", "html", {"charset": "utf-8"}); | 329 check(contentType, "text", "html", {"charset": "utf-8"}); |
334 Expect.equals("text/html; charset=utf-8", contentType.toString()); | 330 Expect.equals("text/html; charset=utf-8", contentType.toString()); |
335 Expect.throws(() => contentType.parameters["xxx"] = "yyy", | 331 Expect.throws(() => contentType.parameters["xxx"] = "yyy", |
336 (e) => e is UnsupportedError); | 332 (e) => e is UnsupportedError); |
337 | 333 |
338 contentType = new ContentType("text", | 334 contentType = new ContentType("text", "html", |
339 "html", | 335 parameters: {"CHARSET": "UTF-8", "xxx": "YYY"}); |
340 parameters: {"CHARSET": "UTF-8", "xxx": "YYY"}); | |
341 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "YYY"}); | 336 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "YYY"}); |
342 String s = contentType.toString(); | 337 String s = contentType.toString(); |
343 bool expectedToString = (s == "text/html; charset=utf-8; xxx=YYY" || | 338 bool expectedToString = (s == "text/html; charset=utf-8; xxx=YYY" || |
344 s == "text/html; xxx=YYY; charset=utf-8"); | 339 s == "text/html; xxx=YYY; charset=utf-8"); |
345 Expect.isTrue(expectedToString); | 340 Expect.isTrue(expectedToString); |
346 contentType = ContentType.parse("text/html; CHARSET=UTF-8; xxx=YYY"); | 341 contentType = ContentType.parse("text/html; CHARSET=UTF-8; xxx=YYY"); |
347 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "YYY"}); | 342 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "YYY"}); |
348 Expect.throws(() => contentType.parameters["xxx"] = "yyy", | 343 Expect.throws(() => contentType.parameters["xxx"] = "yyy", |
349 (e) => e is UnsupportedError); | 344 (e) => e is UnsupportedError); |
350 | 345 |
351 contentType = new ContentType("text", | 346 contentType = new ContentType("text", "html", |
352 "html", | 347 charset: "ISO-8859-1", parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); |
353 charset: "ISO-8859-1", | |
354 parameters: {"CHARSET": "UTF-8", "xxx": "yyy"}); | |
355 check(contentType, "text", "html", {"charset": "iso-8859-1", "xxx": "yyy"}); | 348 check(contentType, "text", "html", {"charset": "iso-8859-1", "xxx": "yyy"}); |
356 s = contentType.toString(); | 349 s = contentType.toString(); |
357 expectedToString = (s == "text/html; charset=iso-8859-1; xxx=yyy" || | 350 expectedToString = (s == "text/html; charset=iso-8859-1; xxx=yyy" || |
358 s == "text/html; xxx=yyy; charset=iso-8859-1"); | 351 s == "text/html; xxx=yyy; charset=iso-8859-1"); |
359 Expect.isTrue(expectedToString); | 352 Expect.isTrue(expectedToString); |
360 | 353 |
361 contentType = ContentType.parse("text/html"); | 354 contentType = ContentType.parse("text/html"); |
362 check(contentType, "text", "html"); | 355 check(contentType, "text", "html"); |
363 contentType = ContentType.parse(" text/html "); | 356 contentType = ContentType.parse(" text/html "); |
364 check(contentType, "text", "html"); | 357 check(contentType, "text", "html"); |
365 contentType = ContentType.parse("text/html; charset=utf-8"); | 358 contentType = ContentType.parse("text/html; charset=utf-8"); |
366 check(contentType, "text", "html", {"charset": "utf-8"}); | 359 check(contentType, "text", "html", {"charset": "utf-8"}); |
367 contentType = ContentType.parse( | 360 contentType = ContentType.parse(" text/html ; charset = utf-8 "); |
368 " text/html ; charset = utf-8 "); | |
369 check(contentType, "text", "html", {"charset": "utf-8"}); | 361 check(contentType, "text", "html", {"charset": "utf-8"}); |
370 contentType = ContentType.parse( | 362 contentType = ContentType.parse("text/html; charset=utf-8; xxx=yyy"); |
371 "text/html; charset=utf-8; xxx=yyy"); | |
372 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 363 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
373 contentType = ContentType.parse( | 364 contentType = |
374 " text/html ; charset = utf-8 ; xxx=yyy "); | 365 ContentType.parse(" text/html ; charset = utf-8 ; xxx=yyy "); |
375 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 366 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
376 contentType = ContentType.parse( | 367 contentType = ContentType.parse('text/html; charset=utf-8; xxx="yyy"'); |
377 'text/html; charset=utf-8; xxx="yyy"'); | |
378 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 368 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
379 contentType = ContentType.parse( | 369 contentType = |
380 " text/html ; charset = utf-8 ; xxx=yyy "); | 370 ContentType.parse(" text/html ; charset = utf-8 ; xxx=yyy "); |
381 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); | 371 check(contentType, "text", "html", {"charset": "utf-8", "xxx": "yyy"}); |
382 | 372 |
383 contentType = ContentType.parse("text/html; charset=;"); | 373 contentType = ContentType.parse("text/html; charset=;"); |
384 check(contentType, "text", "html", {"charset": null}); | 374 check(contentType, "text", "html", {"charset": null}); |
385 contentType = ContentType.parse("text/html; charset;"); | 375 contentType = ContentType.parse("text/html; charset;"); |
386 check(contentType, "text", "html", {"charset": null}); | 376 check(contentType, "text", "html", {"charset": null}); |
387 | 377 |
388 // Test builtin content types. | 378 // Test builtin content types. |
389 check(ContentType.TEXT, "text", "plain", {"charset": "utf-8"}); | 379 check(ContentType.TEXT, "text", "plain", {"charset": "utf-8"}); |
390 check(ContentType.HTML, "text", "html", {"charset": "utf-8"}); | 380 check(ContentType.HTML, "text", "html", {"charset": "utf-8"}); |
(...skipping 24 matching lines...) Expand all Loading... |
415 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); | 405 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); |
416 Expect.equals("text", headers.contentType.primaryType); | 406 Expect.equals("text", headers.contentType.primaryType); |
417 Expect.equals("plain", headers.contentType.subType); | 407 Expect.equals("plain", headers.contentType.subType); |
418 Expect.equals("text/plain", headers.contentType.value); | 408 Expect.equals("text/plain", headers.contentType.value); |
419 headers.removeAll(HttpHeaders.CONTENT_TYPE); | 409 headers.removeAll(HttpHeaders.CONTENT_TYPE); |
420 Expect.isNull(headers.contentType); | 410 Expect.isNull(headers.contentType); |
421 } | 411 } |
422 | 412 |
423 void testCookie() { | 413 void testCookie() { |
424 test(String name, String value) { | 414 test(String name, String value) { |
425 | |
426 void checkCookiesEquals(a, b) { | 415 void checkCookiesEquals(a, b) { |
427 Expect.equals(a.name, b.name); | 416 Expect.equals(a.name, b.name); |
428 Expect.equals(a.value, b.value); | 417 Expect.equals(a.value, b.value); |
429 Expect.equals(a.expires, b.expires); | 418 Expect.equals(a.expires, b.expires); |
430 Expect.equals(a.toString(), b.toString()); | 419 Expect.equals(a.toString(), b.toString()); |
431 } | 420 } |
432 | 421 |
433 void checkCookie(cookie, s) { | 422 void checkCookie(cookie, s) { |
434 Expect.equals(s, cookie.toString()); | 423 Expect.equals(s, cookie.toString()); |
435 var c = new _Cookie.fromSetCookieValue(s); | 424 var c = new _Cookie.fromSetCookieValue(s); |
436 checkCookiesEquals(cookie, c); | 425 checkCookiesEquals(cookie, c); |
437 } | 426 } |
438 | 427 |
439 Cookie cookie; | 428 Cookie cookie; |
440 cookie = new Cookie(name, value); | 429 cookie = new Cookie(name, value); |
441 Expect.equals("$name=$value; HttpOnly", cookie.toString()); | 430 Expect.equals("$name=$value; HttpOnly", cookie.toString()); |
442 DateTime date = new DateTime.utc(2014, DateTime.JANUARY, 5, 23, 59, 59, 0); | 431 DateTime date = new DateTime.utc(2014, DateTime.JANUARY, 5, 23, 59, 59, 0); |
443 cookie.expires = date; | 432 cookie.expires = date; |
444 checkCookie(cookie, "$name=$value" | 433 checkCookie( |
445 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" | 434 cookie, |
446 "; HttpOnly"); | 435 "$name=$value" |
| 436 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" |
| 437 "; HttpOnly"); |
447 cookie.maxAge = 567; | 438 cookie.maxAge = 567; |
448 checkCookie(cookie, "$name=$value" | 439 checkCookie( |
449 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" | 440 cookie, |
450 "; Max-Age=567" | 441 "$name=$value" |
451 "; HttpOnly"); | 442 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" |
| 443 "; Max-Age=567" |
| 444 "; HttpOnly"); |
452 cookie.domain = "example.com"; | 445 cookie.domain = "example.com"; |
453 checkCookie(cookie, "$name=$value" | 446 checkCookie( |
454 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" | 447 cookie, |
455 "; Max-Age=567" | 448 "$name=$value" |
456 "; Domain=example.com" | 449 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" |
457 "; HttpOnly"); | 450 "; Max-Age=567" |
| 451 "; Domain=example.com" |
| 452 "; HttpOnly"); |
458 cookie.path = "/xxx"; | 453 cookie.path = "/xxx"; |
459 checkCookie(cookie, "$name=$value" | 454 checkCookie( |
460 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" | 455 cookie, |
461 "; Max-Age=567" | 456 "$name=$value" |
462 "; Domain=example.com" | 457 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" |
463 "; Path=/xxx" | 458 "; Max-Age=567" |
464 "; HttpOnly"); | 459 "; Domain=example.com" |
| 460 "; Path=/xxx" |
| 461 "; HttpOnly"); |
465 cookie.secure = true; | 462 cookie.secure = true; |
466 checkCookie(cookie, "$name=$value" | 463 checkCookie( |
467 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" | 464 cookie, |
468 "; Max-Age=567" | 465 "$name=$value" |
469 "; Domain=example.com" | 466 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" |
470 "; Path=/xxx" | 467 "; Max-Age=567" |
471 "; Secure" | 468 "; Domain=example.com" |
472 "; HttpOnly"); | 469 "; Path=/xxx" |
| 470 "; Secure" |
| 471 "; HttpOnly"); |
473 cookie.httpOnly = false; | 472 cookie.httpOnly = false; |
474 checkCookie(cookie, "$name=$value" | 473 checkCookie( |
475 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" | 474 cookie, |
476 "; Max-Age=567" | 475 "$name=$value" |
477 "; Domain=example.com" | 476 "; Expires=Sun, 05 Jan 2014 23:59:59 GMT" |
478 "; Path=/xxx" | 477 "; Max-Age=567" |
479 "; Secure"); | 478 "; Domain=example.com" |
| 479 "; Path=/xxx" |
| 480 "; Secure"); |
480 cookie.expires = null; | 481 cookie.expires = null; |
481 checkCookie(cookie, "$name=$value" | 482 checkCookie( |
482 "; Max-Age=567" | 483 cookie, |
483 "; Domain=example.com" | 484 "$name=$value" |
484 "; Path=/xxx" | 485 "; Max-Age=567" |
485 "; Secure"); | 486 "; Domain=example.com" |
| 487 "; Path=/xxx" |
| 488 "; Secure"); |
486 cookie.maxAge = null; | 489 cookie.maxAge = null; |
487 checkCookie(cookie, "$name=$value" | 490 checkCookie( |
488 "; Domain=example.com" | 491 cookie, |
489 "; Path=/xxx" | 492 "$name=$value" |
490 "; Secure"); | 493 "; Domain=example.com" |
| 494 "; Path=/xxx" |
| 495 "; Secure"); |
491 cookie.domain = null; | 496 cookie.domain = null; |
492 checkCookie(cookie, "$name=$value" | 497 checkCookie( |
493 "; Path=/xxx" | 498 cookie, |
494 "; Secure"); | 499 "$name=$value" |
| 500 "; Path=/xxx" |
| 501 "; Secure"); |
495 cookie.path = null; | 502 cookie.path = null; |
496 checkCookie(cookie, "$name=$value" | 503 checkCookie( |
497 "; Secure"); | 504 cookie, |
| 505 "$name=$value" |
| 506 "; Secure"); |
498 cookie.secure = false; | 507 cookie.secure = false; |
499 checkCookie(cookie, "$name=$value"); | 508 checkCookie(cookie, "$name=$value"); |
500 } | 509 } |
| 510 |
501 test("name", "value"); | 511 test("name", "value"); |
502 test("abc", "def"); | 512 test("abc", "def"); |
503 test("ABC", "DEF"); | 513 test("ABC", "DEF"); |
504 test("Abc", "Def"); | 514 test("Abc", "Def"); |
505 test("SID", "sJdkjKSJD12343kjKj78"); | 515 test("SID", "sJdkjKSJD12343kjKj78"); |
506 } | 516 } |
507 | 517 |
508 void testInvalidCookie() { | 518 void testInvalidCookie() { |
509 Expect.throws(() => new _Cookie.fromSetCookieValue("")); | 519 Expect.throws(() => new _Cookie.fromSetCookieValue("")); |
510 Expect.throws(() => new _Cookie.fromSetCookieValue("=")); | 520 Expect.throws(() => new _Cookie.fromSetCookieValue("=")); |
511 Expect.throws(() => new _Cookie.fromSetCookieValue("=xxx")); | 521 Expect.throws(() => new _Cookie.fromSetCookieValue("=xxx")); |
512 Expect.throws(() => new _Cookie.fromSetCookieValue("xxx")); | 522 Expect.throws(() => new _Cookie.fromSetCookieValue("xxx")); |
513 Expect.throws(() => new _Cookie.fromSetCookieValue( | 523 Expect.throws( |
514 "xxx=yyy; expires=12 jan 2013")); | 524 () => new _Cookie.fromSetCookieValue("xxx=yyy; expires=12 jan 2013")); |
515 Expect.throws(() => new _Cookie.fromSetCookieValue("x x = y y")); | 525 Expect.throws(() => new _Cookie.fromSetCookieValue("x x = y y")); |
516 Expect.throws(() => new _Cookie("[4", "y")); | 526 Expect.throws(() => new _Cookie("[4", "y")); |
517 Expect.throws(() => new _Cookie("4", "y\"")); | 527 Expect.throws(() => new _Cookie("4", "y\"")); |
518 | 528 |
519 _HttpHeaders headers = new _HttpHeaders("1.1"); | 529 _HttpHeaders headers = new _HttpHeaders("1.1"); |
520 headers.set('Cookie', | 530 headers.set( |
521 'DARTSESSID=d3d6fdd78d51aaaf2924c32e991f4349; undefined'); | 531 'Cookie', 'DARTSESSID=d3d6fdd78d51aaaf2924c32e991f4349; undefined'); |
522 Expect.equals('DARTSESSID', headers._parseCookies().single.name); | 532 Expect.equals('DARTSESSID', headers._parseCookies().single.name); |
523 Expect.equals('d3d6fdd78d51aaaf2924c32e991f4349', | 533 Expect.equals( |
524 headers._parseCookies().single.value); | 534 'd3d6fdd78d51aaaf2924c32e991f4349', headers._parseCookies().single.value); |
525 } | 535 } |
526 | 536 |
527 void testHeaderLists() { | 537 void testHeaderLists() { |
528 HttpHeaders.GENERAL_HEADERS.forEach((x) => null); | 538 HttpHeaders.GENERAL_HEADERS.forEach((x) => null); |
529 HttpHeaders.ENTITY_HEADERS.forEach((x) => null); | 539 HttpHeaders.ENTITY_HEADERS.forEach((x) => null); |
530 HttpHeaders.RESPONSE_HEADERS.forEach((x) => null); | 540 HttpHeaders.RESPONSE_HEADERS.forEach((x) => null); |
531 HttpHeaders.REQUEST_HEADERS.forEach((x) => null); | 541 HttpHeaders.REQUEST_HEADERS.forEach((x) => null); |
532 } | 542 } |
533 | 543 |
534 void testInvalidFieldName() { | 544 void testInvalidFieldName() { |
535 void test(String field) { | 545 void test(String field) { |
536 _HttpHeaders headers = new _HttpHeaders("1.1"); | 546 _HttpHeaders headers = new _HttpHeaders("1.1"); |
537 Expect.throws(() => headers.add(field, "value"), | 547 Expect.throws( |
538 (e) => e is FormatException); | 548 () => headers.add(field, "value"), (e) => e is FormatException); |
539 Expect.throws(() => headers.set(field, "value"), | 549 Expect.throws( |
540 (e) => e is FormatException); | 550 () => headers.set(field, "value"), (e) => e is FormatException); |
541 Expect.throws(() => headers.remove(field, "value"), | 551 Expect.throws( |
542 (e) => e is FormatException); | 552 () => headers.remove(field, "value"), (e) => e is FormatException); |
543 Expect.throws(() => headers.removeAll(field), | 553 Expect.throws(() => headers.removeAll(field), (e) => e is FormatException); |
544 (e) => e is FormatException); | |
545 } | 554 } |
| 555 |
546 test('\r'); | 556 test('\r'); |
547 test('\n'); | 557 test('\n'); |
548 test(','); | 558 test(','); |
549 test('test\x00'); | 559 test('test\x00'); |
550 } | 560 } |
551 | 561 |
552 void testInvalidFieldValue() { | 562 void testInvalidFieldValue() { |
553 void test(value, {bool remove: true}) { | 563 void test(value, {bool remove: true}) { |
554 _HttpHeaders headers = new _HttpHeaders("1.1"); | 564 _HttpHeaders headers = new _HttpHeaders("1.1"); |
555 Expect.throws(() => headers.add("field", value), | 565 Expect.throws( |
556 (e) => e is FormatException); | 566 () => headers.add("field", value), (e) => e is FormatException); |
557 Expect.throws(() => headers.set("field", value), | 567 Expect.throws( |
558 (e) => e is FormatException); | 568 () => headers.set("field", value), (e) => e is FormatException); |
559 if (remove) { | 569 if (remove) { |
560 Expect.throws(() => headers.remove("field", value), | 570 Expect.throws( |
561 (e) => e is FormatException); | 571 () => headers.remove("field", value), (e) => e is FormatException); |
562 } | 572 } |
563 } | 573 } |
| 574 |
564 test('\r'); | 575 test('\r'); |
565 test('\n'); | 576 test('\n'); |
566 test('test\x00'); | 577 test('test\x00'); |
567 // Test we handle other types correctly. | 578 // Test we handle other types correctly. |
568 test(new StringBuffer('\x00'), remove: false); | 579 test(new StringBuffer('\x00'), remove: false); |
569 } | 580 } |
570 | 581 |
571 void testClear() { | 582 void testClear() { |
572 _HttpHeaders headers = new _HttpHeaders("1.1"); | 583 _HttpHeaders headers = new _HttpHeaders("1.1"); |
573 headers.add("a", "b"); | 584 headers.add("a", "b"); |
(...skipping 17 matching lines...) Expand all Loading... |
591 testContentType(); | 602 testContentType(); |
592 testKnownContentTypes(); | 603 testKnownContentTypes(); |
593 testContentTypeCache(); | 604 testContentTypeCache(); |
594 testCookie(); | 605 testCookie(); |
595 testInvalidCookie(); | 606 testInvalidCookie(); |
596 testHeaderLists(); | 607 testHeaderLists(); |
597 testInvalidFieldName(); | 608 testInvalidFieldName(); |
598 testInvalidFieldValue(); | 609 testInvalidFieldValue(); |
599 testClear(); | 610 testClear(); |
600 } | 611 } |
OLD | NEW |