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

Side by Side Diff: test/hijack_test.dart

Issue 1640323004: Start switching hijacking to use StreamChannel. (Closed) Base URL: git@github.com:dart-lang/shelf@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « pubspec.yaml ('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) 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:test/test.dart'; 7 import 'package:test/test.dart';
8 import 'package:shelf/shelf.dart'; 8 import 'package:shelf/shelf.dart';
9 9
10 import 'test_util.dart'; 10 import 'test_util.dart';
11 11
12 void main() { 12 void main() {
13 test('hijacking a non-hijackable request throws a StateError', () { 13 test('hijacking a non-hijackable request throws a StateError', () {
14 expect(() => new Request('GET', LOCALHOST_URI).hijack((_, __) => null), 14 expect(() => new Request('GET', LOCALHOST_URI).hijack((_) => null),
15 throwsStateError); 15 throwsStateError);
16 }); 16 });
17 17
18 test('hijacking a hijackable request throws a HijackException and calls ' 18 test('hijacking a hijackable request throws a HijackException and calls '
19 'onHijack', () { 19 'onHijack', () {
20 var request = new Request('GET', LOCALHOST_URI, 20 var request = new Request('GET', LOCALHOST_URI,
21 onHijack: expectAsync((callback) { 21 onHijack: expectAsync((callback) {
22 var streamController = new StreamController(); 22 var streamController = new StreamController();
23 streamController.add([1, 2, 3]); 23 streamController.add([1, 2, 3]);
24 streamController.close(); 24 streamController.close();
25 25
26 var sinkController = new StreamController(); 26 var sinkController = new StreamController();
27 expect(sinkController.stream.first, completion(equals([4, 5, 6]))); 27 expect(sinkController.stream.first, completion(equals([4, 5, 6])));
28 28
29 callback(streamController.stream, sinkController); 29 callback(streamController.stream, sinkController);
30 })); 30 }));
31 31
32 expect(() => request.hijack(expectAsync((stream, sink) { 32 expect(() => request.hijack(expectAsync((channel) {
33 expect(stream.first, completion(equals([1, 2, 3]))); 33 expect(channel.stream.first, completion(equals([1, 2, 3])));
34 sink.add([4, 5, 6]); 34 channel.sink.add([4, 5, 6]);
35 sink.close(); 35 channel.sink.close();
36 })), throwsA(new isInstanceOf<HijackException>())); 36 })), throwsA(new isInstanceOf<HijackException>()));
37 }); 37 });
38 38
39 test('hijacking a hijackable request twice throws a StateError', () { 39 test('hijacking a hijackable request twice throws a StateError', () {
40 // Assert that the [onHijack] callback is only called once. 40 // Assert that the [onHijack] callback is only called once.
41 var request = new Request('GET', LOCALHOST_URI, 41 var request = new Request('GET', LOCALHOST_URI,
42 onHijack: expectAsync((_) => null, count: 1)); 42 onHijack: expectAsync((_) => null, count: 1));
43 43
44 expect(() => request.hijack((_, __) => null), 44 expect(() => request.hijack((_) => null),
45 throwsA(new isInstanceOf<HijackException>())); 45 throwsA(new isInstanceOf<HijackException>()));
46 46
47 expect(() => request.hijack((_, __) => null), throwsStateError); 47 expect(() => request.hijack((_) => null), throwsStateError);
48 }); 48 });
49 49
50 group('calling change', () { 50 group('calling change', () {
51 test('hijacking a non-hijackable request throws a StateError', () { 51 test('hijacking a non-hijackable request throws a StateError', () {
52 var request = new Request('GET', LOCALHOST_URI); 52 var request = new Request('GET', LOCALHOST_URI);
53 var newRequest = request.change(); 53 var newRequest = request.change();
54 expect(() => newRequest.hijack((_, __) => null), throwsStateError); 54 expect(() => newRequest.hijack((_) => null), throwsStateError);
55 }); 55 });
56 56
57 test('hijacking a hijackable request throws a HijackException and calls ' 57 test('hijacking a hijackable request throws a HijackException and calls '
58 'onHijack', () { 58 'onHijack', () {
59 var request = new Request('GET', LOCALHOST_URI, 59 var request = new Request('GET', LOCALHOST_URI,
60 onHijack: expectAsync((callback) { 60 onHijack: expectAsync((callback) {
61 var streamController = new StreamController(); 61 var streamController = new StreamController();
62 streamController.add([1, 2, 3]); 62 streamController.add([1, 2, 3]);
63 streamController.close(); 63 streamController.close();
64 64
65 var sinkController = new StreamController(); 65 var sinkController = new StreamController();
66 expect(sinkController.stream.first, completion(equals([4, 5, 6]))); 66 expect(sinkController.stream.first, completion(equals([4, 5, 6])));
67 67
68 callback(streamController.stream, sinkController); 68 callback(streamController.stream, sinkController);
69 })); 69 }));
70 70
71 var newRequest = request.change(); 71 var newRequest = request.change();
72 72
73 expect(() => newRequest.hijack(expectAsync((stream, sink) { 73 expect(() => newRequest.hijack(expectAsync((channel) {
74 expect(stream.first, completion(equals([1, 2, 3]))); 74 expect(channel.stream.first, completion(equals([1, 2, 3])));
75 sink.add([4, 5, 6]); 75 channel.sink.add([4, 5, 6]);
76 sink.close(); 76 channel.sink.close();
77 })), throwsA(new isInstanceOf<HijackException>())); 77 })), throwsA(new isInstanceOf<HijackException>()));
78 }); 78 });
79 79
80 test('hijacking the original request after calling change throws a ' 80 test('hijacking the original request after calling change throws a '
81 'StateError', () { 81 'StateError', () {
82 // Assert that the [onHijack] callback is only called once. 82 // Assert that the [onHijack] callback is only called once.
83 var request = new Request('GET', LOCALHOST_URI, 83 var request = new Request('GET', LOCALHOST_URI,
84 onHijack: expectAsync((_) => null, count: 1)); 84 onHijack: expectAsync((_) => null, count: 1));
85 85
86 var newRequest = request.change(); 86 var newRequest = request.change();
87 87
88 expect(() => newRequest.hijack((_, __) => null), 88 expect(() => newRequest.hijack((_) => null),
89 throwsA(new isInstanceOf<HijackException>())); 89 throwsA(new isInstanceOf<HijackException>()));
90 90
91 expect(() => request.hijack((_, __) => null), throwsStateError); 91 expect(() => request.hijack((_) => null), throwsStateError);
92 }); 92 });
93 }); 93 });
94 } 94 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698