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

Side by Side Diff: tests/standalone/io/http_date_test.dart

Issue 16812004: Make some HTTP utility functions public (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: One more status file update Created 7 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/standalone/io/http_cookie_date_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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 import "dart:io";
9 part '../../../sdk/lib/io/common.dart';
10 part "../../../sdk/lib/io/io_sink.dart";
11 part "../../../sdk/lib/io/http.dart";
12 part "../../../sdk/lib/io/http_impl.dart";
13 part "../../../sdk/lib/io/http_parser.dart";
14 part "../../../sdk/lib/io/http_utils.dart";
15 part "../../../sdk/lib/io/socket.dart";
16 9
17 void testParseHttpDate() { 10 void testParseHttpDate() {
18 DateTime date; 11 DateTime date;
19 date = new DateTime.utc(1999, DateTime.JUNE, 11, 18, 46, 53, 0); 12 date = new DateTime.utc(1999, DateTime.JUNE, 11, 18, 46, 53, 0);
20 Expect.equals(date, _HttpUtils.parseDate("Fri, 11 Jun 1999 18:46:53 GMT")); 13 Expect.equals(date, HttpDate.parse("Fri, 11 Jun 1999 18:46:53 GMT"));
21 Expect.equals(date, _HttpUtils.parseDate("Friday, 11-Jun-1999 18:46:53 GMT")); 14 Expect.equals(date, HttpDate.parse("Friday, 11-Jun-1999 18:46:53 GMT"));
22 Expect.equals(date, _HttpUtils.parseDate("Fri Jun 11 18:46:53 1999")); 15 Expect.equals(date, HttpDate.parse("Fri Jun 11 18:46:53 1999"));
23 16
24 date = new DateTime.utc(1970, DateTime.JANUARY, 1, 0, 0, 0, 0); 17 date = new DateTime.utc(1970, DateTime.JANUARY, 1, 0, 0, 0, 0);
25 Expect.equals(date, _HttpUtils.parseDate("Thu, 1 Jan 1970 00:00:00 GMT")); 18 Expect.equals(date, HttpDate.parse("Thu, 1 Jan 1970 00:00:00 GMT"));
26 Expect.equals(date, 19 Expect.equals(date,
27 _HttpUtils.parseDate("Thursday, 1-Jan-1970 00:00:00 GMT")); 20 HttpDate.parse("Thursday, 1-Jan-1970 00:00:00 GMT"));
28 Expect.equals(date, _HttpUtils.parseDate("Thu Jan 1 00:00:00 1970")); 21 Expect.equals(date, HttpDate.parse("Thu Jan 1 00:00:00 1970"));
29 22
30 date = new DateTime.utc(2012, DateTime.MARCH, 5, 23, 59, 59, 0); 23 date = new DateTime.utc(2012, DateTime.MARCH, 5, 23, 59, 59, 0);
31 Expect.equals(date, _HttpUtils.parseDate("Mon, 5 Mar 2012 23:59:59 GMT")); 24 Expect.equals(date, HttpDate.parse("Mon, 5 Mar 2012 23:59:59 GMT"));
32 Expect.equals(date, _HttpUtils.parseDate("Monday, 5-Mar-2012 23:59:59 GMT")); 25 Expect.equals(date, HttpDate.parse("Monday, 5-Mar-2012 23:59:59 GMT"));
33 Expect.equals(date, _HttpUtils.parseDate("Mon Mar 5 23:59:59 2012")); 26 Expect.equals(date, HttpDate.parse("Mon Mar 5 23:59:59 2012"));
34 } 27 }
35 28
36 void testFormatParseHttpDate() { 29 void testFormatParseHttpDate() {
37 test(int year, 30 test(int year,
38 int month, 31 int month,
39 int day, 32 int day,
40 int hours, 33 int hours,
41 int minutes, 34 int minutes,
42 int seconds, 35 int seconds,
43 String expectedFormatted) { 36 String expectedFormatted) {
44 DateTime date; 37 DateTime date;
45 String formatted; 38 String formatted;
46 date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0); 39 date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0);
47 formatted = _HttpUtils.formatDate(date); 40 formatted = HttpDate.format(date);
48 Expect.equals(expectedFormatted, formatted); 41 Expect.equals(expectedFormatted, formatted);
49 Expect.equals(date, _HttpUtils.parseDate(formatted)); 42 Expect.equals(date, HttpDate.parse(formatted));
50 } 43 }
51 44
52 test(1999, DateTime.JUNE, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT"); 45 test(1999, DateTime.JUNE, 11, 18, 46, 53, "Fri, 11 Jun 1999 18:46:53 GMT");
53 test(1970, DateTime.JANUARY, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT"); 46 test(1970, DateTime.JANUARY, 1, 0, 0, 0, "Thu, 1 Jan 1970 00:00:00 GMT");
54 test(2012, DateTime.MARCH, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT"); 47 test(2012, DateTime.MARCH, 5, 23, 59, 59, "Mon, 5 Mar 2012 23:59:59 GMT");
55 } 48 }
56 49
57 void testParseHttpDateFailures() { 50 void testParseHttpDateFailures() {
58 Expect.throws(() { 51 Expect.throws(() {
59 _HttpUtils.parseDate(""); 52 HttpDate.parse("");
60 }); 53 });
61 String valid = "Mon, 5 Mar 2012 23:59:59 GMT"; 54 String valid = "Mon, 5 Mar 2012 23:59:59 GMT";
62 for (int i = 1; i < valid.length - 1; i++) { 55 for (int i = 1; i < valid.length - 1; i++) {
63 String tmp = valid.substring(0, i); 56 String tmp = valid.substring(0, i);
64 Expect.throws(() { 57 Expect.throws(() {
65 _HttpUtils.parseDate(tmp); 58 HttpDate.parse(tmp);
66 }); 59 });
67 Expect.throws(() { 60 Expect.throws(() {
68 _HttpUtils.parseDate(" $tmp"); 61 HttpDate.parse(" $tmp");
69 }); 62 });
70 Expect.throws(() { 63 Expect.throws(() {
71 _HttpUtils.parseDate(" $tmp "); 64 HttpDate.parse(" $tmp ");
72 }); 65 });
73 Expect.throws(() { 66 Expect.throws(() {
74 _HttpUtils.parseDate("$tmp "); 67 HttpDate.parse("$tmp ");
75 }); 68 });
76 } 69 }
77 Expect.throws(() { 70 Expect.throws(() {
78 _HttpUtils.parseDate(" $valid"); 71 HttpDate.parse(" $valid");
79 }); 72 });
80 Expect.throws(() { 73 Expect.throws(() {
81 _HttpUtils.parseDate(" $valid "); 74 HttpDate.parse(" $valid ");
82 }); 75 });
83 Expect.throws(() { 76 Expect.throws(() {
84 _HttpUtils.parseDate("$valid "); 77 HttpDate.parse("$valid ");
85 }); 78 });
86 } 79 }
87 80
88 void testParseHttpCookieDate() {
89 Expect.throws(() => _HttpUtils.parseCookieDate(""));
90
91 test(int year,
92 int month,
93 int day,
94 int hours,
95 int minutes,
96 int seconds,
97 String formatted) {
98 DateTime date = new DateTime.utc(year, month, day, hours, minutes, seconds, 0);
99 Expect.equals(date, _HttpUtils.parseCookieDate(formatted));
100 }
101
102 test(2012, DateTime.JUNE, 19, 14, 15, 01, "tue, 19-jun-12 14:15:01 gmt");
103 test(2021, DateTime.JUNE, 09, 10, 18, 14, "Wed, 09-Jun-2021 10:18:14 GMT");
104 test(2021, DateTime.JANUARY, 13, 22, 23, 01, "Wed, 13-Jan-2021 22:23:01 GMT");
105 test(2013, DateTime.JANUARY, 15, 21, 47, 38, "Tue, 15-Jan-2013 21:47:38 GMT");
106 test(1970, DateTime.JANUARY, 01, 00, 00, 01, "Thu, 01-Jan-1970 00:00:01 GMT");
107 }
108
109 void main() { 81 void main() {
110 testParseHttpDate(); 82 testParseHttpDate();
111 testFormatParseHttpDate(); 83 testFormatParseHttpDate();
112 testParseHttpDateFailures(); 84 testParseHttpDateFailures();
113 testParseHttpCookieDate();
114 } 85 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_cookie_date_test.dart ('k') | tests/standalone/standalone.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698