OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 service_test_common; | 5 library service_test_common; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:observatory/service_common.dart'; | 8 import 'package:observatory/service_common.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 | 10 |
11 typedef Future IsolateTest(Isolate isolate); | 11 typedef Future IsolateTest(Isolate isolate); |
12 typedef Future VMTest(VM vm); | 12 typedef Future VMTest(VM vm); |
13 | 13 |
| 14 Map<String, StreamSubscription> streamSubscriptions = {}; |
| 15 |
| 16 Future subscribeToStream(VM vm, String streamName, onEvent) async { |
| 17 assert(streamSubscriptions[streamName] == null); |
| 18 |
| 19 Stream stream = await vm.getEventStream(streamName); |
| 20 StreamSubscription subscription = stream.listen(onEvent); |
| 21 streamSubscriptions[streamName] = subscription; |
| 22 } |
| 23 |
| 24 Future cancelStreamSubscription(String streamName) async { |
| 25 StreamSubscription subscription = streamSubscriptions[streamName]; |
| 26 subscription.cancel(); |
| 27 streamSubscriptions.remove(streamName); |
| 28 } |
| 29 |
14 Future asyncStepOver(Isolate isolate) async { | 30 Future asyncStepOver(Isolate isolate) async { |
15 final Completer pausedAtSyntheticBreakpoint = new Completer(); | 31 final Completer pausedAtSyntheticBreakpoint = new Completer(); |
16 StreamSubscription subscription; | 32 StreamSubscription subscription; |
17 | 33 |
18 // Cancel the subscription. | 34 // Cancel the subscription. |
19 cancelSubscription() { | 35 cancelSubscription() { |
20 if (subscription != null) { | 36 if (subscription != null) { |
21 subscription.cancel(); | 37 subscription.cancel(); |
22 subscription = null; | 38 subscription = null; |
23 } | 39 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 243 |
228 Future<Instance> rootLibraryFieldValue(Isolate isolate, | 244 Future<Instance> rootLibraryFieldValue(Isolate isolate, |
229 String fieldName) async { | 245 String fieldName) async { |
230 Library rootLib = await isolate.rootLibrary.load(); | 246 Library rootLib = await isolate.rootLibrary.load(); |
231 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); | 247 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); |
232 await field.load(); | 248 await field.load(); |
233 Instance value = field.staticValue; | 249 Instance value = field.staticValue; |
234 await value.load(); | 250 await value.load(); |
235 return value; | 251 return value; |
236 } | 252 } |
OLD | NEW |