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

Side by Side Diff: tests/standalone/io/file_stream_test.dart

Issue 51883004: Let the stream of File:openRead handle cancel correctly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | « tests/standalone/io/directory_list_pause_test.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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "dart:async";
6 import "dart:io";
7
8 import "package:async_helper/async_helper.dart";
9 import "package:expect/expect.dart";
10
11 void testPauseResumeCancelStream() {
12 asyncStart();
13 Directory.systemTemp.createTemp('file_stream').then((d) {
14 var file = new File("${d.path}/file");
15 new File(Platform.executable).openRead().pipe(file.openWrite())
16 .then((_) {
17 var subscription;
18 subscription = file.openRead().listen((data) {
19 subscription.pause();
20 subscription.resume();
21 void close() {
22 d.deleteSync(recursive: true);
23 asyncEnd();
24 }
25 var future = subscription.cancel();
26 if (future != null) {
27 future.whenComplete(close);
28 } else {
29 close();
30 }
31 }, onDone: () {
32 Expect.fail('the stream was canceled, onDone should not happend');
33 });
34 });
35 });
36 }
37
38 void testStreamIsEmpty() {
39 asyncStart();
40 Directory.systemTemp.createTemp('file_stream').then((d) {
41 var file = new File("${d.path}/file");
42 new File(Platform.executable).openRead().pipe(file.openWrite())
43 .then((_) {
44 // isEmpty will cancel the stream after first data event.
45 file.openRead().isEmpty.then((empty) {
46 Expect.isFalse(empty);
47 d.deleteSync(recursive: true);
48 asyncEnd();
49 });
50 });
51 });
52 }
53
54 void main() {
55 testPauseResumeCancelStream();
56 testStreamIsEmpty();
57 }
OLDNEW
« no previous file with comments | « tests/standalone/io/directory_list_pause_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698