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

Unified Diff: pkg/http/test/response_test.dart

Issue 11363063: Add an HTTP library that wraps dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « pkg/http/test/request_test.dart ('k') | pkg/http/test/streamed_request_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/test/response_test.dart
diff --git a/pkg/http/test/response_test.dart b/pkg/http/test/response_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6062dab7fcc4bd015f41735027c8e6a926dfe758
--- /dev/null
+++ b/pkg/http/test/response_test.dart
@@ -0,0 +1,68 @@
+// 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.
+
+library response_test;
+
+import 'dart:io';
+
+import '../../unittest/lib/unittest.dart';
+import '../lib/http.dart' as http;
+
+void main() {
+ group('()', () {
+ test('sets body', () {
+ var response = new http.Response("Hello, world!", 200);
+ expect(response.body, equals("Hello, world!"));
+ });
+
+ test('sets bodyBytes', () {
+ var response = new http.Response("Hello, world!", 200);
+ expect(response.bodyBytes, equals(
+ [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]));
+ });
+
+ // TODO(nweiz): test that this respects the inferred encoding when issue
+ // 6284 is fixed.
+ });
+
+ group('.bytes()', () {
+ test('sets body', () {
+ var response = new http.Response.bytes([104, 101, 108, 108, 111], 200);
+ expect(response.body, equals("hello"));
+ });
+
+ test('sets bodyBytes', () {
+ var response = new http.Response.bytes([104, 101, 108, 108, 111], 200);
+ expect(response.bodyBytes, equals([104, 101, 108, 108, 111]));
+ });
+
+ // TODO(nweiz): test that this respects the inferred encoding when issue
+ // 6284 is fixed.
+ });
+
+ group('.fromStream()', () {
+ test('sets body', () {
+ var stream = new ListInputStream();
+ var streamResponse = new http.StreamedResponse(stream, 200, 13);
+ var future = http.Response.fromStream(streamResponse)
+ .transform((response) => response.body);
+ expect(future, completion(equals("Hello, world!")));
+
+ stream.write([72, 101, 108, 108, 111, 44, 32]);
+ stream.write([119, 111, 114, 108, 100, 33]);
+ stream.markEndOfStream();
+ });
+
+ test('sets bodyBytes', () {
+ var stream = new ListInputStream();
+ var streamResponse = new http.StreamedResponse(stream, 200, 5);
+ var future = http.Response.fromStream(streamResponse)
+ .transform((response) => response.bodyBytes);
+ expect(future, completion(equals([104, 101, 108, 108, 111])));
+
+ stream.write([104, 101, 108, 108, 111]);
+ stream.markEndOfStream();
+ });
+ });
+}
« no previous file with comments | « pkg/http/test/request_test.dart ('k') | pkg/http/test/streamed_request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698