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

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

Issue 10414076: Support for cookies in the HTTP library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed second round of comments 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
« no previous file with comments | « tests/standalone/io/http_headers_test.dart ('k') | no next file » | 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 // VMOptions= 5 // VMOptions=
6 // VMOptions=--short_socket_read 6 // VMOptions=--short_socket_read
7 // VMOptions=--short_socket_write 7 // VMOptions=--short_socket_write
8 // VMOptions=--short_socket_read --short_socket_write 8 // VMOptions=--short_socket_read --short_socket_write
9 9
10 #import("dart:isolate"); 10 #import("dart:isolate");
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 Expect.equals("text/html", request.headers.contentType.value); 170 Expect.equals("text/html", request.headers.contentType.value);
171 Expect.equals("text", request.headers.contentType.primaryType); 171 Expect.equals("text", request.headers.contentType.primaryType);
172 Expect.equals("html", request.headers.contentType.subType); 172 Expect.equals("html", request.headers.contentType.subType);
173 Expect.equals("utf-8", request.headers.contentType.parameters["charset"]); 173 Expect.equals("utf-8", request.headers.contentType.parameters["charset"]);
174 174
175 response.headers.set(HttpHeaders.CONTENT_TYPE, 175 response.headers.set(HttpHeaders.CONTENT_TYPE,
176 "text/html; charset = utf-8"); 176 "text/html; charset = utf-8");
177 response.outputStream.close(); 177 response.outputStream.close();
178 } 178 }
179 179
180 void _cookie1Handler(HttpRequest request, HttpResponse response) {
181 // No cookies passed with this request.
182 Expect.equals(0, request.cookies.length);
183
184 Cookie cookie1 = new Cookie("name1", "value1");
185 TimeZone utc = new TimeZone.utc();
186 Date date = new Date.withTimeZone(2014, Date.JAN, 5, 23, 59, 59, 0, utc);
187 cookie1.expires = date;
188 cookie1.domain = "www.example.com";
189 cookie1.httpOnly = true;
190 response.cookies.add(cookie1);
191 Cookie cookie2 = new Cookie("name2", "value2");
192 cookie2.maxAge = 100;
193 cookie2.domain = ".example.com";
194 cookie2.path = "/shop";
195 response.cookies.add(cookie2);
196 response.outputStream.close();
197 }
198
199 void _cookie2Handler(HttpRequest request, HttpResponse response) {
200 // Two cookies passed with this request.
201 Expect.equals(2, request.cookies.length);
202 response.outputStream.close();
203 }
204
180 void main() { 205 void main() {
181 // Setup request handlers. 206 // Setup request handlers.
182 _requestHandlers = new Map(); 207 _requestHandlers = new Map();
183 _requestHandlers["/echo"] = (HttpRequest request, HttpResponse response) { 208 _requestHandlers["/echo"] = (HttpRequest request, HttpResponse response) {
184 _echoHandler(request, response); 209 _echoHandler(request, response);
185 }; 210 };
186 _requestHandlers["/0123456789"] = 211 _requestHandlers["/0123456789"] =
187 (HttpRequest request, HttpResponse response) { 212 (HttpRequest request, HttpResponse response) {
188 _zeroToTenHandler(request, response); 213 _zeroToTenHandler(request, response);
189 }; 214 };
(...skipping 14 matching lines...) Expand all
204 _expires2Handler(request, response); 229 _expires2Handler(request, response);
205 }; 230 };
206 _requestHandlers["/contenttype1"] = 231 _requestHandlers["/contenttype1"] =
207 (HttpRequest request, HttpResponse response) { 232 (HttpRequest request, HttpResponse response) {
208 _contentType1Handler(request, response); 233 _contentType1Handler(request, response);
209 }; 234 };
210 _requestHandlers["/contenttype2"] = 235 _requestHandlers["/contenttype2"] =
211 (HttpRequest request, HttpResponse response) { 236 (HttpRequest request, HttpResponse response) {
212 _contentType2Handler(request, response); 237 _contentType2Handler(request, response);
213 }; 238 };
239 _requestHandlers["/cookie1"] =
240 (HttpRequest request, HttpResponse response) {
241 _cookie1Handler(request, response);
242 };
243 _requestHandlers["/cookie2"] =
244 (HttpRequest request, HttpResponse response) {
245 _cookie2Handler(request, response);
246 };
214 247
215 this.port.receive((var message, SendPort replyTo) { 248 this.port.receive((var message, SendPort replyTo) {
216 if (message.isStart) { 249 if (message.isStart) {
217 _server = new HttpServer(); 250 _server = new HttpServer();
218 try { 251 try {
219 _server.listen("127.0.0.1", 0); 252 _server.listen("127.0.0.1", 0);
220 _server.defaultRequestHandler = (HttpRequest req, HttpResponse rsp) { 253 _server.defaultRequestHandler = (HttpRequest req, HttpResponse rsp) {
221 _requestReceivedHandler(req, rsp); 254 _requestReceivedHandler(req, rsp);
222 }; 255 };
223 replyTo.send(new TestServerStatus.started(_server.port), null); 256 replyTo.send(new TestServerStatus.started(_server.port), null);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 "text/html; charset = utf-8"); 619 "text/html; charset = utf-8");
587 request.outputStream.close(); 620 request.outputStream.close();
588 }; 621 };
589 conn2.onResponse = (HttpClientResponse response) { 622 conn2.onResponse = (HttpClientResponse response) {
590 processResponse(response); 623 processResponse(response);
591 }; 624 };
592 }); 625 });
593 testServerMain.start(); 626 testServerMain.start();
594 } 627 }
595 628
629 void testCookies() {
630 TestServerMain testServerMain = new TestServerMain();
631 testServerMain.setServerStartedHandler((int port) {
632 int responses = 0;
633 HttpClient httpClient = new HttpClient();
634
635 HttpClientConnection conn1 =
636 httpClient.get("127.0.0.1", port, "/cookie1");
637 conn1.onResponse = (HttpClientResponse response) {
638 Expect.equals(2, response.cookies.length);
639 response.cookies.forEach((cookie) {
640 if (cookie.name == "name1") {
641 Expect.equals("value1", cookie.value);
642 TimeZone utc = new TimeZone.utc();
643 Date date =
644 new Date.withTimeZone(2014, Date.JAN, 5, 23, 59, 59, 0, utc);
645 Expect.equals(date, cookie.expires);
646 Expect.equals("www.example.com", cookie.domain);
647 Expect.isTrue(cookie.httpOnly);
648 } else if (cookie.name == "name2") {
649 Expect.equals("value2", cookie.value);
650 Expect.equals(100, cookie.maxAge);
651 Expect.equals(".example.com", cookie.domain);
652 Expect.equals("/shop", cookie.path);
653 } else {
654 Expect.fail("Unexpected cookie");
655 }
656 });
657 HttpClientConnection conn2 =
658 httpClient.get("127.0.0.1", port, "/cookie2");
659 conn2.onRequest = (HttpClientRequest request) {
660 request.cookies.add(response.cookies[0]);
661 request.cookies.add(response.cookies[1]);
662 request.outputStream.close();
663 };
664 conn2.onResponse = (HttpClientRequest request) {
665 httpClient.shutdown();
666 testServerMain.shutdown();
667 };
668 };
669 });
670 testServerMain.start();
671 }
596 672
597 void main() { 673 void main() {
598 testStartStop(); 674 testStartStop();
599 testGET(); 675 testGET();
600 testPOST(true); 676 testPOST(true);
601 testPOST(false); 677 testPOST(false);
602 testReadInto(true); 678 testReadInto(true);
603 testReadInto(false); 679 testReadInto(false);
604 testReadShort(true); 680 testReadShort(true);
605 testReadShort(false); 681 testReadShort(false);
606 test404(); 682 test404();
607 testReasonPhrase(); 683 testReasonPhrase();
608 testHost(); 684 testHost();
609 testExpires(); 685 testExpires();
610 testContentType(); 686 testContentType();
687 testCookies();
611 } 688 }
OLDNEW
« no previous file with comments | « tests/standalone/io/http_headers_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698