OLD | NEW |
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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 | 7 |
8 import "package:async_helper/async_helper.dart"; | 8 import "package:async_helper/async_helper.dart"; |
9 import "package:expect/expect.dart"; | 9 import "package:expect/expect.dart"; |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 count++; | 36 count++; |
37 } | 37 } |
38 }, onDone: () { | 38 }, onDone: () { |
39 Expect.notEquals(TOTAL, count); | 39 Expect.notEquals(TOTAL, count); |
40 Expect.isTrue(count > 0); | 40 Expect.isTrue(count > 0); |
41 d.delete(recursive: true).then((ignore) => asyncEnd()); | 41 d.delete(recursive: true).then((ignore) => asyncEnd()); |
42 }); | 42 }); |
43 }); | 43 }); |
44 } | 44 } |
45 | 45 |
| 46 |
| 47 void testPauseResumeCancelList() { |
| 48 asyncStart(); |
| 49 // TOTAL should be bigger the our directory listing buffer. |
| 50 const int TOTAL = 128; |
| 51 Directory.systemTemp.createTemp('dart_directory_list_pause').then((d) { |
| 52 for (int i = 0; i < TOTAL; i++) { |
| 53 new Directory("${d.path}/$i").createSync(); |
| 54 new File("${d.path}/$i/file").createSync(); |
| 55 } |
| 56 var subscription; |
| 57 subscription = d.list(recursive: true).listen((entity) { |
| 58 subscription.pause(); |
| 59 subscription.resume(); |
| 60 void close() { |
| 61 d.deleteSync(recursive: true); |
| 62 asyncEnd(); |
| 63 } |
| 64 var future = subscription.cancel(); |
| 65 if (future != null) { |
| 66 future.whenComplete(close); |
| 67 } else { |
| 68 close(); |
| 69 } |
| 70 }, onDone: () { |
| 71 Expect.fail('the stream was canceled, onDone should not happend'); |
| 72 }); |
| 73 }); |
| 74 } |
| 75 |
| 76 void testListIsEmpty() { |
| 77 asyncStart(); |
| 78 // TOTAL should be bigger the our directory listing buffer. |
| 79 const int TOTAL = 128; |
| 80 Directory.systemTemp.createTemp('dart_directory_list_pause').then((d) { |
| 81 for (int i = 0; i < TOTAL; i++) { |
| 82 new Directory("${d.path}/$i").createSync(); |
| 83 new File("${d.path}/$i/file").createSync(); |
| 84 } |
| 85 d.list(recursive: true).isEmpty.then((empty) { |
| 86 Expect.isFalse(empty); |
| 87 d.deleteSync(recursive: true); |
| 88 asyncEnd(); |
| 89 }); |
| 90 }); |
| 91 } |
| 92 |
46 void main() { | 93 void main() { |
47 testPauseList(); | 94 testPauseList(); |
| 95 testPauseResumeCancelList(); |
| 96 testListIsEmpty(); |
48 } | 97 } |
OLD | NEW |