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

Unified Diff: mojo/public/dart/third_party/shelf/test/response_test.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
Index: mojo/public/dart/third_party/shelf/test/response_test.dart
diff --git a/mojo/public/dart/third_party/shelf/test/response_test.dart b/mojo/public/dart/third_party/shelf/test/response_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..57c5c1c4d660893126ebf013e1b43332a4c6cba7
--- /dev/null
+++ b/mojo/public/dart/third_party/shelf/test/response_test.dart
@@ -0,0 +1,143 @@
+// Copyright (c) 2014, 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 shelf.response_test;
+
+import 'dart:async';
+import 'dart:convert';
+
+import 'package:shelf/shelf.dart' hide Request;
+import 'package:test/test.dart';
+
+import 'test_util.dart';
+
+void main() {
+ group("supports a String body", () {
+ test("readAsString", () {
+ var response = new Response.ok("hello, world");
+ expect(response.readAsString(), completion(equals("hello, world")));
+ });
+
+ test("read", () {
+ var helloWorldBytes = new List.from(HELLO_BYTES)..addAll(WORLD_BYTES);
+
+ var response = new Response.ok("hello, world");
+ expect(response.read().toList(), completion(equals([helloWorldBytes])));
+ });
+ });
+
+ group("new Response.internalServerError without a body", () {
+ test('sets the body to "Internal Server Error"', () {
+ var response = new Response.internalServerError();
+ expect(
+ response.readAsString(), completion(equals("Internal Server Error")));
+ });
+
+ test('sets the content-type header to text/plain', () {
+ var response = new Response.internalServerError();
+ expect(response.headers, containsPair('content-type', 'text/plain'));
+ });
+
+ test('preserves content-type parameters', () {
+ var response = new Response.internalServerError(
+ headers: {
+ 'content-type': 'application/octet-stream; param=whatever'
+ });
+ expect(response.headers,
+ containsPair('content-type', 'text/plain; param=whatever'));
+ });
+ });
+
+ group("Response redirect", () {
+ test("sets the location header for a String", () {
+ var response = new Response.found('/foo');
+ expect(response.headers, containsPair('location', '/foo'));
+ });
+
+ test("sets the location header for a Uri", () {
+ var response = new Response.found(new Uri(path: '/foo'));
+ expect(response.headers, containsPair('location', '/foo'));
+ });
+ });
+
+ group("expires", () {
+ test("is null without an Expires header", () {
+ expect(new Response.ok("okay!").expires, isNull);
+ });
+
+ test("comes from the Expires header", () {
+ expect(new Response.ok("okay!",
+ headers: {
+ 'expires': 'Sun, 06 Nov 1994 08:49:37 GMT'
+ }).expires, equals(DateTime.parse("1994-11-06 08:49:37z")));
+ });
+ });
+
+ group("lastModified", () {
+ test("is null without a Last-Modified header", () {
+ expect(new Response.ok("okay!").lastModified, isNull);
+ });
+
+ test("comes from the Last-Modified header", () {
+ expect(new Response.ok("okay!",
+ headers: {
+ 'last-modified': 'Sun, 06 Nov 1994 08:49:37 GMT'
+ }).lastModified, equals(DateTime.parse("1994-11-06 08:49:37z")));
+ });
+ });
+
+ group('change', () {
+ test('with no arguments returns instance with equal values', () {
+ var controller = new StreamController();
+
+ var request = new Response(345,
+ body: 'hèllo, world',
+ encoding: LATIN1,
+ headers: {'header1': 'header value 1'},
+ context: {'context1': 'context value 1'});
+
+ var copy = request.change();
+
+ expect(copy.statusCode, request.statusCode);
+ expect(copy.readAsString(), completion('hèllo, world'));
+ expect(copy.headers, same(request.headers));
+ expect(copy.encoding, request.encoding);
+ expect(copy.context, same(request.context));
+
+ controller.add(HELLO_BYTES);
+ return new Future(() {
+ controller
+ ..add(WORLD_BYTES)
+ ..close();
+ });
+ });
+
+
+ test("allows the original response to be read", () {
+ var response = new Response.ok(null);
+ var changed = response.change();
+
+ expect(response.read().toList(), completion(isEmpty));
+ expect(changed.read, throwsStateError);
+ });
+
+ test("allows the changed response to be read", () {
+ var response = new Response.ok(null);
+ var changed = response.change();
+
+ expect(changed.read().toList(), completion(isEmpty));
+ expect(response.read, throwsStateError);
+ });
+
+ test("allows another changed response to be read", () {
+ var response = new Response.ok(null);
+ var changed1 = response.change();
+ var changed2 = response.change();
+
+ expect(changed2.read().toList(), completion(isEmpty));
+ expect(changed1.read, throwsStateError);
+ expect(response.read, throwsStateError);
+ });
+ });
+}
« no previous file with comments | « mojo/public/dart/third_party/shelf/test/request_test.dart ('k') | mojo/public/dart/third_party/shelf/test/shelf_io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698