| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 Expect.equals("text/html", headers.contentType.value); | 307 Expect.equals("text/html", headers.contentType.value); |
| 308 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); | 308 headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8"); |
| 309 Expect.equals("text", headers.contentType.primaryType); | 309 Expect.equals("text", headers.contentType.primaryType); |
| 310 Expect.equals("plain", headers.contentType.subType); | 310 Expect.equals("plain", headers.contentType.subType); |
| 311 Expect.equals("text/plain", headers.contentType.value); | 311 Expect.equals("text/plain", headers.contentType.value); |
| 312 headers.removeAll(HttpHeaders.CONTENT_TYPE); | 312 headers.removeAll(HttpHeaders.CONTENT_TYPE); |
| 313 Expect.isNull(headers.contentType); | 313 Expect.isNull(headers.contentType); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void testCookie() { | 316 void testCookie() { |
| 317 void checkCookiesEquals(a, b) { | 317 test(String name, String value) { |
| 318 Expect.equals(a.name, b.name); | 318 |
| 319 Expect.equals(a.value, b.value); | 319 void checkCookiesEquals(a, b) { |
| 320 Expect.equals(a.expires, b.expires); | 320 Expect.equals(a.name, b.name); |
| 321 Expect.equals(a.toString(), b.toString()); | 321 Expect.equals(a.value, b.value); |
| 322 Expect.equals(a.expires, b.expires); |
| 323 Expect.equals(a.toString(), b.toString()); |
| 324 } |
| 325 |
| 326 void checkCookie(cookie, s) { |
| 327 Expect.equals(s, cookie.toString()); |
| 328 var c = new _Cookie.fromSetCookieValue(s); |
| 329 checkCookiesEquals(cookie, c); |
| 330 } |
| 331 |
| 332 Cookie cookie; |
| 333 cookie = new Cookie(name, value); |
| 334 Expect.equals("$name=$value", cookie.toString()); |
| 335 DateTime date = new DateTime.utc(2014, DateTime.JANUARY, 5, 23, 59, 59, 0); |
| 336 cookie.expires = date; |
| 337 checkCookie(cookie, "$name=$value" |
| 338 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT"); |
| 339 cookie.maxAge = 567; |
| 340 checkCookie(cookie, "$name=$value" |
| 341 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" |
| 342 "; Max-Age=567"); |
| 343 cookie.domain = "example.com"; |
| 344 checkCookie(cookie, "$name=$value" |
| 345 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" |
| 346 "; Max-Age=567" |
| 347 "; Domain=example.com"); |
| 348 cookie.path = "/xxx"; |
| 349 checkCookie(cookie, "$name=$value" |
| 350 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" |
| 351 "; Max-Age=567" |
| 352 "; Domain=example.com" |
| 353 "; Path=/xxx"); |
| 354 cookie.secure = true; |
| 355 checkCookie(cookie, "$name=$value" |
| 356 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" |
| 357 "; Max-Age=567" |
| 358 "; Domain=example.com" |
| 359 "; Path=/xxx" |
| 360 "; Secure"); |
| 361 cookie.httpOnly = true; |
| 362 checkCookie(cookie, "$name=$value" |
| 363 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" |
| 364 "; Max-Age=567" |
| 365 "; Domain=example.com" |
| 366 "; Path=/xxx" |
| 367 "; Secure" |
| 368 "; HttpOnly"); |
| 369 cookie.expires = null; |
| 370 checkCookie(cookie, "$name=$value" |
| 371 "; Max-Age=567" |
| 372 "; Domain=example.com" |
| 373 "; Path=/xxx" |
| 374 "; Secure" |
| 375 "; HttpOnly"); |
| 376 cookie.maxAge = null; |
| 377 checkCookie(cookie, "$name=$value" |
| 378 "; Domain=example.com" |
| 379 "; Path=/xxx" |
| 380 "; Secure" |
| 381 "; HttpOnly"); |
| 382 cookie.domain = null; |
| 383 checkCookie(cookie, "$name=$value" |
| 384 "; Path=/xxx" |
| 385 "; Secure" |
| 386 "; HttpOnly"); |
| 387 cookie.path = null; |
| 388 checkCookie(cookie, "$name=$value" |
| 389 "; Secure" |
| 390 "; HttpOnly"); |
| 391 cookie.secure = false; |
| 392 checkCookie(cookie, "$name=$value" |
| 393 "; HttpOnly"); |
| 394 cookie.httpOnly = false; |
| 395 checkCookie(cookie, "$name=$value"); |
| 322 } | 396 } |
| 323 | 397 test("name", "value"); |
| 324 void checkCookie(cookie, s) { | 398 test("abc", "def"); |
| 325 Expect.equals(s, cookie.toString()); | 399 test("ABC", "DEF"); |
| 326 var c = new _Cookie.fromSetCookieValue(s); | 400 test("Abc", "Def"); |
| 327 checkCookiesEquals(cookie, c); | 401 test("SID", "sJdkjKSJD12343kjKj78"); |
| 328 } | |
| 329 | |
| 330 Cookie cookie; | |
| 331 cookie = new Cookie("name", "value"); | |
| 332 Expect.equals("name=value", cookie.toString()); | |
| 333 DateTime date = new DateTime.utc(2014, DateTime.JANUARY, 5, 23, 59, 59, 0); | |
| 334 cookie.expires = date; | |
| 335 checkCookie(cookie, "name=value" | |
| 336 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT"); | |
| 337 cookie.maxAge = 567; | |
| 338 checkCookie(cookie, "name=value" | |
| 339 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" | |
| 340 "; Max-Age=567"); | |
| 341 cookie.domain = "example.com"; | |
| 342 checkCookie(cookie, "name=value" | |
| 343 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" | |
| 344 "; Max-Age=567" | |
| 345 "; Domain=example.com"); | |
| 346 cookie.path = "/xxx"; | |
| 347 checkCookie(cookie, "name=value" | |
| 348 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" | |
| 349 "; Max-Age=567" | |
| 350 "; Domain=example.com" | |
| 351 "; Path=/xxx"); | |
| 352 cookie.secure = true; | |
| 353 checkCookie(cookie, "name=value" | |
| 354 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" | |
| 355 "; Max-Age=567" | |
| 356 "; Domain=example.com" | |
| 357 "; Path=/xxx" | |
| 358 "; Secure"); | |
| 359 cookie.httpOnly = true; | |
| 360 checkCookie(cookie, "name=value" | |
| 361 "; Expires=Sun, 5 Jan 2014 23:59:59 GMT" | |
| 362 "; Max-Age=567" | |
| 363 "; Domain=example.com" | |
| 364 "; Path=/xxx" | |
| 365 "; Secure" | |
| 366 "; HttpOnly"); | |
| 367 cookie.expires = null; | |
| 368 checkCookie(cookie, "name=value" | |
| 369 "; Max-Age=567" | |
| 370 "; Domain=example.com" | |
| 371 "; Path=/xxx" | |
| 372 "; Secure" | |
| 373 "; HttpOnly"); | |
| 374 cookie.maxAge = null; | |
| 375 checkCookie(cookie, "name=value" | |
| 376 "; Domain=example.com" | |
| 377 "; Path=/xxx" | |
| 378 "; Secure" | |
| 379 "; HttpOnly"); | |
| 380 cookie.domain = null; | |
| 381 checkCookie(cookie, "name=value" | |
| 382 "; Path=/xxx" | |
| 383 "; Secure" | |
| 384 "; HttpOnly"); | |
| 385 cookie.path = null; | |
| 386 checkCookie(cookie, "name=value" | |
| 387 "; Secure" | |
| 388 "; HttpOnly"); | |
| 389 cookie.secure = false; | |
| 390 checkCookie(cookie, "name=value" | |
| 391 "; HttpOnly"); | |
| 392 cookie.httpOnly = false; | |
| 393 checkCookie(cookie, "name=value"); | |
| 394 } | 402 } |
| 395 | 403 |
| 396 void testInvalidCookie() { | 404 void testInvalidCookie() { |
| 397 Expect.throws(() => new _Cookie.fromSetCookieValue("")); | 405 Expect.throws(() => new _Cookie.fromSetCookieValue("")); |
| 398 Expect.throws(() => new _Cookie.fromSetCookieValue("=")); | 406 Expect.throws(() => new _Cookie.fromSetCookieValue("=")); |
| 399 Expect.throws(() => new _Cookie.fromSetCookieValue("=xxx")); | 407 Expect.throws(() => new _Cookie.fromSetCookieValue("=xxx")); |
| 400 Expect.throws(() => new _Cookie.fromSetCookieValue("xxx")); | 408 Expect.throws(() => new _Cookie.fromSetCookieValue("xxx")); |
| 401 Expect.throws(() => new _Cookie.fromSetCookieValue("xxx=yyy; expires=12 jan 20
13")); | 409 Expect.throws(() => new _Cookie.fromSetCookieValue("xxx=yyy; expires=12 jan 20
13")); |
| 402 } | 410 } |
| 403 | 411 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 415 testIfModifiedSince(); | 423 testIfModifiedSince(); |
| 416 testHost(); | 424 testHost(); |
| 417 testEnumeration(); | 425 testEnumeration(); |
| 418 testHeaderValue(); | 426 testHeaderValue(); |
| 419 testContentType(); | 427 testContentType(); |
| 420 testContentTypeCache(); | 428 testContentTypeCache(); |
| 421 testCookie(); | 429 testCookie(); |
| 422 testInvalidCookie(); | 430 testInvalidCookie(); |
| 423 testHeaderLists(); | 431 testHeaderLists(); |
| 424 } | 432 } |
| OLD | NEW |