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

Side by Side Diff: test/server_test.dart

Issue 12578002: Add Router.defaultStream Base URL: https://github.com/dart-lang/route.git@master
Patch Set: Created 7 years, 9 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
« lib/server.dart ('K') | « lib/server.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 5
6 import 'package:unittest/unittest.dart'; 6 import 'package:unittest/unittest.dart';
7 import 'package:unittest/mock.dart'; 7 import 'package:unittest/mock.dart';
8 import 'package:route/server.dart'; 8 import 'package:route/server.dart';
9 import 'dart:async'; 9 import 'dart:async';
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 var controller = new StreamController<HttpRequest>(); 54 var controller = new StreamController<HttpRequest>();
55 var router = new Router(controller.stream); 55 var router = new Router(controller.stream);
56 var testReq = new HttpRequestMock(new Uri('/bar')); 56 var testReq = new HttpRequestMock(new Uri('/bar'));
57 testReq.response._onClose = expectAsync0(() { 57 testReq.response._onClose = expectAsync0(() {
58 expect(testReq.response.statusCode, 404); 58 expect(testReq.response.statusCode, 404);
59 }); 59 });
60 router.serve('/foo').listen(expectAsync1((req) {}, count: 0)); 60 router.serve('/foo').listen(expectAsync1((req) {}, count: 0));
61 controller.add(testReq); 61 controller.add(testReq);
62 }); 62 });
63 63
64 test('default', () {
65 var controller = new StreamController<HttpRequest>();
66 var router = new Router(controller.stream);
67 var testReq = new HttpRequestMock(new Uri('/bar'));
68 testReq.response._onClose = expectAsync0(() {
69 expect(testReq.response.statusCode, 200);
70 });
71 router.defaultStream.listen(expectAsync1((HttpRequest req) {
72 req.response.statusCode = 200;
73 req.response.close();
74 }));
75 controller.add(testReq);
76 });
64 77
65 test('filter pass', () { 78 test('filter pass', () {
66 var controller = new StreamController<HttpRequest>(); 79 var controller = new StreamController<HttpRequest>();
67 var router = new Router(controller.stream); 80 var router = new Router(controller.stream);
68 var testReq = new HttpRequestMock(new Uri('/foo')); 81 var testReq = new HttpRequestMock(new Uri('/foo'));
69 router.filter('/foo', expectAsync1((req) { 82 router.filter('/foo', expectAsync1((req) {
70 expect(req, testReq); 83 expect(req, testReq);
71 return new Future.immediate(true); 84 return new Future.immediate(true);
72 })); 85 }));
73 router.serve('/foo').listen(expectAsync1((req) { 86 router.serve('/foo').listen(expectAsync1((req) {
74 expect(req, testReq); 87 expect(req, testReq);
75 })); 88 }));
76 controller.add(testReq); 89 controller.add(testReq);
77 }); 90 });
78 91
79 test('filter no-pass', () { 92 test('filter no-pass', () {
80 var controller = new StreamController<HttpRequest>(); 93 var controller = new StreamController<HttpRequest>();
81 var router = new Router(controller.stream); 94 var router = new Router(controller.stream);
82 var testReq = new HttpRequestMock(new Uri('/foo')); 95 var testReq = new HttpRequestMock(new Uri('/foo'));
83 router.filter('/foo', expectAsync1((req) { 96 router.filter('/foo', expectAsync1((req) {
84 expect(req, testReq); 97 expect(req, testReq);
85 return new Future.immediate(false); 98 return new Future.immediate(false);
86 })); 99 }));
87 router.serve('/foo').listen(expectAsync1((req) {}, count: 0)); 100 router.serve('/foo').listen(expectAsync1((req) {}, count: 0));
88 controller.add(testReq); 101 controller.add(testReq);
89 }); 102 });
90 103
91 } 104 }
OLDNEW
« lib/server.dart ('K') | « lib/server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698