Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library shelf.request_test; | 5 library shelf.request_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:shelf/shelf.dart'; | 9 import 'package:shelf/shelf.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 | 11 |
| 12 import 'test_change.dart'; | |
| 12 import 'test_util.dart'; | 13 import 'test_util.dart'; |
| 13 | 14 |
| 14 Request _request([Map<String, String> headers, Stream<List<int>> body]) { | 15 Request _request([Map<String, String> headers, Stream<List<int>> body]) { |
| 15 return new Request("GET", LOCALHOST_URI, headers: headers, body: body); | 16 return new Request("GET", LOCALHOST_URI, headers: headers, body: body); |
| 16 } | 17 } |
| 17 | 18 |
| 18 void main() { | 19 void main() { |
| 19 group('constructor', () { | 20 group('constructor', () { |
| 20 test('protocolVersion defaults to "1.1"', () { | 21 test('protocolVersion defaults to "1.1"', () { |
| 21 var request = new Request('GET', LOCALHOST_URI); | 22 var request = new Request('GET', LOCALHOST_URI); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 130 |
| 130 test("comes from the Last-Modified header", () { | 131 test("comes from the Last-Modified header", () { |
| 131 var request = _request({ | 132 var request = _request({ |
| 132 'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT' | 133 'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT' |
| 133 }); | 134 }); |
| 134 expect(request.ifModifiedSince, | 135 expect(request.ifModifiedSince, |
| 135 equals(DateTime.parse("1994-11-06 08:49:37z"))); | 136 equals(DateTime.parse("1994-11-06 08:49:37z"))); |
| 136 }); | 137 }); |
| 137 }); | 138 }); |
| 138 | 139 |
| 139 group("readAsString", () { | 140 group('change', () { |
| 140 test("supports a null body", () { | 141 test('with no arguments returns instance with equal values', () { |
| 141 var request = _request(); | 142 var controller = new StreamController(); |
| 142 expect(request.readAsString(), completion(equals(""))); | |
| 143 }); | |
| 144 | 143 |
| 145 test("supports a Stream<List<int>> body", () { | 144 var uri = Uri.parse('https://test.example.com/static/file.html'); |
| 146 var controller = new StreamController(); | |
| 147 var request = _request({}, controller.stream); | |
| 148 expect(request.readAsString(), completion(equals("hello, world"))); | |
| 149 | 145 |
| 150 controller.add([104, 101, 108, 108, 111, 44]); | 146 var request = new Request('GET', uri, |
| 147 protocolVersion: '2.0', | |
| 148 headers: {'header1': 'header value 1'}, | |
| 149 url: Uri.parse('/file.html'), | |
| 150 scriptName: '/static', | |
| 151 body: controller.stream, | |
| 152 context: {'context1': 'context value 1'}); | |
| 153 | |
| 154 var copy = request.change(); | |
| 155 | |
| 156 expect(copy.method, request.method); | |
| 157 expect(copy.requestedUri, request.requestedUri); | |
| 158 expect(copy.protocolVersion, request.protocolVersion); | |
| 159 expect(copy.headers, same(request.headers)); | |
| 160 expect(copy.url, request.url); | |
| 161 expect(copy.scriptName, request.scriptName); | |
| 162 expect(copy.context, same(request.context)); | |
| 163 expect(copy.readAsString(), completion('hello, world')); | |
| 164 | |
| 165 controller.add(HELLO_BYTES); | |
| 151 return new Future(() { | 166 return new Future(() { |
| 152 controller | 167 controller |
| 153 ..add([32, 119, 111, 114, 108, 100]) | 168 ..add(WORLD_BYTES) |
| 154 ..close(); | 169 ..close(); |
| 155 }); | 170 }); |
| 156 }); | 171 }); |
| 157 }); | |
| 158 | 172 |
| 159 group("read", () { | 173 testChange(({headers, context}) { |
|
nweiz
2014/04/29 19:48:48
Why are these named parameters?
kevmoo
2014/04/30 14:27:52
They align exactly with the shared ctor signature.
| |
| 160 test("supports a null body", () { | 174 return new Request('GET', LOCALHOST_URI, headers: headers, |
| 161 var request = _request(); | 175 context: context); |
| 162 expect(request.read().toList(), completion(isEmpty)); | |
| 163 }); | |
| 164 | |
| 165 test("supports a Stream<List<int>> body", () { | |
| 166 var controller = new StreamController(); | |
| 167 var request = _request({}, controller.stream); | |
| 168 expect(request.read().toList(), completion(equals([ | |
| 169 [104, 101, 108, 108, 111, 44], | |
| 170 [32, 119, 111, 114, 108, 100] | |
| 171 ]))); | |
| 172 | |
| 173 controller.add([104, 101, 108, 108, 111, 44]); | |
| 174 return new Future(() { | |
| 175 controller | |
| 176 ..add([32, 119, 111, 114, 108, 100]) | |
| 177 ..close(); | |
| 178 }); | |
| 179 }); | 176 }); |
| 180 }); | 177 }); |
| 181 } | 178 } |
| OLD | NEW |