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

Side by Side Diff: pkg/shelf/test/hijack_test.dart

Issue 616463004: pkg/shelf: include the original `onHijack` callback for Request.change (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cl nits Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/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 library shelf.hijack_test; 5 library shelf.hijack_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 import 'package:shelf/shelf.dart'; 10 import 'package:shelf/shelf.dart';
(...skipping 30 matching lines...) Expand all
41 test('hijacking a hijackable request twice throws a StateError', () { 41 test('hijacking a hijackable request twice throws a StateError', () {
42 // Assert that the [onHijack] callback is only called once. 42 // Assert that the [onHijack] callback is only called once.
43 var request = new Request('GET', LOCALHOST_URI, 43 var request = new Request('GET', LOCALHOST_URI,
44 onHijack: expectAsync((_) => null, count: 1)); 44 onHijack: expectAsync((_) => null, count: 1));
45 45
46 expect(() => request.hijack((_, __) => null), 46 expect(() => request.hijack((_, __) => null),
47 throwsA(new isInstanceOf<HijackException>())); 47 throwsA(new isInstanceOf<HijackException>()));
48 48
49 expect(() => request.hijack((_, __) => null), throwsStateError); 49 expect(() => request.hijack((_, __) => null), throwsStateError);
50 }); 50 });
51
52 group('calling change', () {
53 test('hijacking a non-hijackable request throws a StateError', () {
54 var request = new Request('GET', LOCALHOST_URI);
55 var newRequest = request.change();
56 expect(() => newRequest.hijack((_, __) => null),
57 throwsStateError);
58 });
59
60 test('hijacking a hijackable request throws a HijackException and calls '
61 'onHijack', () {
62 var request = new Request('GET', LOCALHOST_URI,
63 onHijack: expectAsync((callback) {
64 var streamController = new StreamController();
65 streamController.add([1, 2, 3]);
66 streamController.close();
67
68 var sinkController = new StreamController();
69 expect(sinkController.stream.first, completion(equals([4, 5, 6])));
70
71 callback(streamController.stream, sinkController);
72 }));
73
74 var newRequest = request.change();
75
76 expect(() => newRequest.hijack(expectAsync((stream, sink) {
77 expect(stream.first, completion(equals([1, 2, 3])));
78 sink.add([4, 5, 6]);
79 sink.close();
80 })), throwsA(new isInstanceOf<HijackException>()));
81 });
82
83 test('hijacking the original request after calling change throws a '
84 'StateError', () {
85 // Assert that the [onHijack] callback is only called once.
86 var request = new Request('GET', LOCALHOST_URI,
87 onHijack: expectAsync((_) => null, count: 1));
88
89 var newRequest = request.change();
90
91 expect(() => newRequest.hijack((_, __) => null),
92 throwsA(new isInstanceOf<HijackException>()));
93
94 expect(() => request.hijack((_, __) => null), throwsStateError);
95 });
96 });
51 } 97 }
OLDNEW
« no previous file with comments | « pkg/shelf/pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698