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

Side by Side Diff: mojo/public/dart/third_party/shelf/test/pipeline_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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library shelf.pipeline_test;
6
7 import 'package:shelf/shelf.dart';
8 import 'package:test/test.dart';
9
10 import 'test_util.dart';
11
12 void main() {
13 test('compose middleware with Pipeline', () {
14 int accessLocation = 0;
15
16 var middlewareA = createMiddleware(requestHandler: (request) {
17 expect(accessLocation, 0);
18 accessLocation = 1;
19 return null;
20 }, responseHandler: (response) {
21 expect(accessLocation, 4);
22 accessLocation = 5;
23 return response;
24 });
25
26 var middlewareB = createMiddleware(requestHandler: (request) {
27 expect(accessLocation, 1);
28 accessLocation = 2;
29 return null;
30 }, responseHandler: (response) {
31 expect(accessLocation, 3);
32 accessLocation = 4;
33 return response;
34 });
35
36 var handler = const Pipeline()
37 .addMiddleware(middlewareA)
38 .addMiddleware(middlewareB)
39 .addHandler((request) {
40 expect(accessLocation, 2);
41 accessLocation = 3;
42 return syncHandler(request);
43 });
44
45 return makeSimpleRequest(handler).then((response) {
46 expect(response, isNotNull);
47 expect(accessLocation, 5);
48 });
49 });
50
51 test('Pipeline can be used as middleware', () {
52 int accessLocation = 0;
53
54 var middlewareA = createMiddleware(requestHandler: (request) {
55 expect(accessLocation, 0);
56 accessLocation = 1;
57 return null;
58 }, responseHandler: (response) {
59 expect(accessLocation, 4);
60 accessLocation = 5;
61 return response;
62 });
63
64 var middlewareB = createMiddleware(requestHandler: (request) {
65 expect(accessLocation, 1);
66 accessLocation = 2;
67 return null;
68 }, responseHandler: (response) {
69 expect(accessLocation, 3);
70 accessLocation = 4;
71 return response;
72 });
73
74 var innerPipeline =
75 const Pipeline().addMiddleware(middlewareA).addMiddleware(middlewareB);
76
77 var handler = const Pipeline()
78 .addMiddleware(innerPipeline.middleware)
79 .addHandler((request) {
80 expect(accessLocation, 2);
81 accessLocation = 3;
82 return syncHandler(request);
83 });
84
85 return makeSimpleRequest(handler).then((response) {
86 expect(response, isNotNull);
87 expect(accessLocation, 5);
88 });
89 });
90 }
OLDNEW
« no previous file with comments | « mojo/public/dart/third_party/shelf/test/message_test.dart ('k') | mojo/public/dart/third_party/shelf/test/request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698