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

Side by Side Diff: tests/standalone/src/io/HttpHeadersTest.dart

Issue 10252020: test rename overhaul: step 12 - standalone (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #source("../../../../runtime/bin/input_stream.dart");
6 #source("../../../../runtime/bin/output_stream.dart");
7 #source("../../../../runtime/bin/chunked_stream.dart");
8 #source("../../../../runtime/bin/string_stream.dart");
9 #source("../../../../runtime/bin/stream_util.dart");
10 #source("../../../../runtime/bin/http.dart");
11 #source("../../../../runtime/bin/http_impl.dart");
12 #source("../../../../runtime/bin/http_parser.dart");
13 #source("../../../../runtime/bin/http_utils.dart");
14
15 void testMultiValue() {
16 _HttpHeaders headers = new _HttpHeaders();
17 Expect.isNull(headers[HttpHeaders.PRAGMA]);
18 headers.add(HttpHeaders.PRAGMA, "pragma1");
19 Expect.equals(1, headers[HttpHeaders.PRAGMA].length);
20 Expect.equals(1, headers["pragma"].length);
21 Expect.equals(1, headers["Pragma"].length);
22 Expect.equals(1, headers["PRAGMA"].length);
23 Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA));
24
25 headers.add(HttpHeaders.PRAGMA, "pragma2");
26 Expect.equals(2, headers[HttpHeaders.PRAGMA].length);
27 Expect.throws(() => headers.value(HttpHeaders.PRAGMA),
28 (e) => e is HttpException);
29
30 headers.add(HttpHeaders.PRAGMA, ["pragma3", "pragma4"]);
31 Expect.listEquals(["pragma1", "pragma2", "pragma3", "pragma4"],
32 headers[HttpHeaders.PRAGMA]);
33
34 headers.remove(HttpHeaders.PRAGMA, "pragma3");
35 Expect.equals(3, headers[HttpHeaders.PRAGMA].length);
36 Expect.listEquals(["pragma1", "pragma2", "pragma4"],
37 headers[HttpHeaders.PRAGMA]);
38
39 headers.remove(HttpHeaders.PRAGMA, "pragma3");
40 Expect.equals(3, headers[HttpHeaders.PRAGMA].length);
41
42 headers.set(HttpHeaders.PRAGMA, "pragma5");
43 Expect.equals(1, headers[HttpHeaders.PRAGMA].length);
44
45 headers.set(HttpHeaders.PRAGMA, ["pragma6", "pragma7"]);
46 Expect.equals(2, headers[HttpHeaders.PRAGMA].length);
47
48 headers.removeAll(HttpHeaders.PRAGMA);
49 Expect.isNull(headers[HttpHeaders.PRAGMA]);
50 }
51
52 void testDate() {
53 Date date1 = new Date.withTimeZone(
54 1999, Date.JUN, 11, 18, 46, 53, 0, new TimeZone.utc());
55 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT";
56 Date date2 = new Date.withTimeZone(
57 2000, Date.AUG, 16, 12, 34, 56, 0, new TimeZone.utc());
58 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT";
59
60 _HttpHeaders headers = new _HttpHeaders();
61 Expect.isNull(headers.date);
62 headers.date = date1;
63 Expect.equals(date1, headers.date);
64 Expect.equals(httpDate1, headers.value(HttpHeaders.DATE));
65 Expect.equals(1, headers[HttpHeaders.DATE].length);
66 headers.add(HttpHeaders.DATE, httpDate2);
67 Expect.equals(1, headers[HttpHeaders.DATE].length);
68 Expect.equals(date2, headers.date);
69 Expect.equals(httpDate2, headers.value(HttpHeaders.DATE));
70 headers.set(HttpHeaders.DATE, httpDate1);
71 Expect.equals(1, headers[HttpHeaders.DATE].length);
72 Expect.equals(date1, headers.date);
73 Expect.equals(httpDate1, headers.value(HttpHeaders.DATE));
74
75 headers.set(HttpHeaders.DATE, "xxx");
76 Expect.equals("xxx", headers.value(HttpHeaders.DATE));
77 Expect.equals(null, headers.date);
78 }
79
80 void testExpires() {
81 Date date1 = new Date.withTimeZone(
82 1999, Date.JUN, 11, 18, 46, 53, 0, new TimeZone.utc());
83 String httpDate1 = "Fri, 11 Jun 1999 18:46:53 GMT";
84 Date date2 = new Date.withTimeZone(
85 2000, Date.AUG, 16, 12, 34, 56, 0, new TimeZone.utc());
86 String httpDate2 = "Wed, 16 Aug 2000 12:34:56 GMT";
87
88 _HttpHeaders headers = new _HttpHeaders();
89 Expect.isNull(headers.expires);
90 headers.expires = date1;
91 Expect.equals(date1, headers.expires);
92 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES));
93 Expect.equals(1, headers[HttpHeaders.EXPIRES].length);
94 headers.add(HttpHeaders.EXPIRES, httpDate2);
95 Expect.equals(1, headers[HttpHeaders.EXPIRES].length);
96 Expect.equals(date2, headers.expires);
97 Expect.equals(httpDate2, headers.value(HttpHeaders.EXPIRES));
98 headers.set(HttpHeaders.EXPIRES, httpDate1);
99 Expect.equals(1, headers[HttpHeaders.EXPIRES].length);
100 Expect.equals(date1, headers.expires);
101 Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES));
102
103 headers.set(HttpHeaders.EXPIRES, "xxx");
104 Expect.equals("xxx", headers.value(HttpHeaders.EXPIRES));
105 Expect.equals(null, headers.expires);
106 }
107
108 void testHost() {
109 String host = "www.google.com";
110 _HttpHeaders headers = new _HttpHeaders();
111 Expect.isNull(headers.host);
112 Expect.isNull(headers.port);
113 headers.host = host;
114 Expect.equals(host, headers.value(HttpHeaders.HOST));
115 headers.port = 1234;
116 Expect.equals("$host:1234", headers.value(HttpHeaders.HOST));
117 headers.port = HttpClient.DEFAULT_HTTP_PORT;
118 Expect.equals(host, headers.value(HttpHeaders.HOST));
119
120 headers = new _HttpHeaders();
121 headers.add(HttpHeaders.HOST, host);
122 Expect.equals(host, headers.host);
123 Expect.equals(HttpClient.DEFAULT_HTTP_PORT, headers.port);
124 headers.add(HttpHeaders.HOST, "$host:4567");
125 Expect.equals(1, headers[HttpHeaders.HOST].length);
126 Expect.equals(host, headers.host);
127 Expect.equals(4567, headers.port);
128
129 headers = new _HttpHeaders();
130 headers.add(HttpHeaders.HOST, "$host:xxx");
131 Expect.equals("$host:xxx", headers.value(HttpHeaders.HOST));
132 Expect.equals(host, headers.host);
133 Expect.isNull(headers.port);
134
135 headers = new _HttpHeaders();
136 headers.add(HttpHeaders.HOST, ":1234");
137 Expect.equals(":1234", headers.value(HttpHeaders.HOST));
138 Expect.isNull(headers.host);
139 Expect.equals(1234, headers.port);
140 }
141
142 main() {
143 testMultiValue();
144 testExpires();
145 testHost();
146 }
OLDNEW
« no previous file with comments | « tests/standalone/src/io/HttpHeadersState.dart ('k') | tests/standalone/src/io/HttpParserTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698