Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: tests/standalone/src/io/HttpDateTest.dart

Issue 9602011: Add handling of HTTP header "Expires" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/http_utils.dart ('k') | tests/standalone/src/io/HttpTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/src/io/HttpDateTest.dart
diff --git a/tests/standalone/src/io/HttpDateTest.dart b/tests/standalone/src/io/HttpDateTest.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0b02ca7fa27e981fe1fdbb90533d1970f4d1dd41
--- /dev/null
+++ b/tests/standalone/src/io/HttpDateTest.dart
@@ -0,0 +1,91 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#source("../../../../runtime/bin/http_utils.dart");
+
+class HttpException implements Exception {
+ const HttpException([String this.message = ""]);
+ String toString() => "HttpException: $message";
+ final String message;
+}
+
+void testParseHttpDate() {
+ TimeZone utc = new TimeZone.utc();
+ Date date;
+ date = new Date.withTimeZone(1999, Date.JUN, 11, 18, 46, 53, 0, utc);
+ Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT"));
+ Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT"));
+ Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999"));
+
+ date = new Date.withTimeZone(1970, Date.JAN, 1, 0, 0, 0, 0, utc);
+ Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT"));
+ Expect.equals(date,
+ _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT"));
+ Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970"));
+
+ date = new Date.withTimeZone(2012, Date.MAR, 5, 23, 59, 59, 0, utc);
+ Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT"));
+ Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT"));
+ Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012"));
+}
+
+void testFormatParseHttpDate() {
+ test(int year,
+ int month,
+ int day,
+ int hours,
+ int minutes,
+ int seconds,
+ String expectedFormatted) {
+ TimeZone utc = new TimeZone.utc();
+ Date date;
+ String formatted;
+ date = new Date.withTimeZone(
+ year, month, day, hours, minutes, seconds, 0, utc);
+ formatted = _HttpUtils.formatDate(date);
+ Expect.equals(expectedFormatted, formatted);
+ Expect.equals(date, _HttpUtils.parseDate(formatted));
+ }
+
+ test(1999, Date.JUN, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT");
+ test(1970, Date.JAN, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT");
+ test(2012, Date.MAR, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT");
+}
+
+void testParseHttpDateFailures() {
+ Expect.throws(() {
+ _HttpUtils.parseDate("");
+ });
+ String valid = "Mon, 5 Mar 2012 23:59:59 GMT";
+ for (int i = 1; i < valid.length - 1; i++) {
+ String tmp = valid.substring(0, i);
+ Expect.throws(() {
+ _HttpUtils.parseDate(tmp);
+ });
+ Expect.throws(() {
+ _HttpUtils.parseDate(" $tmp");
+ });
+ Expect.throws(() {
+ _HttpUtils.parseDate(" $tmp ");
+ });
+ Expect.throws(() {
+ _HttpUtils.parseDate("$tmp ");
+ });
+ }
+ Expect.throws(() {
+ _HttpUtils.parseDate(" $valid");
+ });
+ Expect.throws(() {
+ _HttpUtils.parseDate(" $valid ");
+ });
+ Expect.throws(() {
+ _HttpUtils.parseDate("$valid ");
+ });
+}
+
+void main() {
+ testParseHttpDate();
+ testFormatParseHttpDate();
+ testParseHttpDateFailures();
+}
« no previous file with comments | « runtime/bin/http_utils.dart ('k') | tests/standalone/src/io/HttpTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698