| 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/models.dart' as M; |
| 8 import 'package:observatory/service_common.dart'; | 9 import 'package:observatory/service_common.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 10 | 11 |
| 11 typedef Future IsolateTest(Isolate isolate); | 12 typedef Future IsolateTest(Isolate isolate); |
| 12 typedef Future VMTest(VM vm); | 13 typedef Future VMTest(VM vm); |
| 13 | 14 |
| 14 Map<String, StreamSubscription> streamSubscriptions = {}; | 15 Map<String, StreamSubscription> streamSubscriptions = {}; |
| 15 | 16 |
| 16 Future subscribeToStream(VM vm, String streamName, onEvent) async { | 17 Future subscribeToStream(VM vm, String streamName, onEvent) async { |
| 17 assert(streamSubscriptions[streamName] == null); | 18 assert(streamSubscriptions[streamName] == null); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } catch (e) { | 90 } catch (e) { |
| 90 // This can fail when another client issued the same resume command | 91 // This can fail when another client issued the same resume command |
| 91 // or another client has moved the isolate forward. | 92 // or another client has moved the isolate forward. |
| 92 cancelSubscription(); | 93 cancelSubscription(); |
| 93 completeError(e); | 94 completeError(e); |
| 94 } | 95 } |
| 95 | 96 |
| 96 return pausedAtSyntheticBreakpoint.future; | 97 return pausedAtSyntheticBreakpoint.future; |
| 97 } | 98 } |
| 98 | 99 |
| 100 bool isEventOfKind(M.Event event, String kind) { |
| 101 switch (kind) { |
| 102 case ServiceEvent.kPauseBreakpoint: |
| 103 return event is M.PauseBreakpointEvent; |
| 104 case ServiceEvent.kPauseException: |
| 105 return event is M.PauseExceptionEvent; |
| 106 case ServiceEvent.kPauseExit: |
| 107 return event is M.PauseExitEvent; |
| 108 case ServiceEvent.kPauseStart: |
| 109 return event is M.PauseStartEvent; |
| 110 default: |
| 111 return false; |
| 112 } |
| 113 } |
| 99 | 114 |
| 100 Future<Isolate> hasPausedFor(Isolate isolate, String kind) { | 115 Future<Isolate> hasPausedFor(Isolate isolate, String kind) { |
| 101 // Set up a listener to wait for breakpoint events. | 116 // Set up a listener to wait for breakpoint events. |
| 102 Completer completer = new Completer(); | 117 Completer completer = new Completer(); |
| 103 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { | 118 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
| 104 var subscription; | 119 var subscription; |
| 105 subscription = stream.listen((ServiceEvent event) { | 120 subscription = stream.listen((ServiceEvent event) { |
| 106 if (event.kind == kind) { | 121 if (event.kind == kind) { |
| 107 if (completer != null) { | 122 if (completer != null) { |
| 108 // Reload to update isolate.pauseEvent. | 123 // Reload to update isolate.pauseEvent. |
| 109 print('Paused with $kind'); | 124 print('Paused with $kind'); |
| 110 subscription.cancel(); | 125 subscription.cancel(); |
| 111 completer.complete(isolate.reload()); | 126 completer.complete(isolate.reload()); |
| 112 completer = null; | 127 completer = null; |
| 113 } | 128 } |
| 114 } | 129 } |
| 115 }); | 130 }); |
| 116 | 131 |
| 117 // Pause may have happened before we subscribed. | 132 // Pause may have happened before we subscribed. |
| 118 isolate.reload().then((_) { | 133 isolate.reload().then((_) { |
| 119 if ((isolate.pauseEvent != null) && | 134 if ((isolate.pauseEvent != null) && |
| 120 (isolate.pauseEvent.kind == kind)) { | 135 isEventOfKind(isolate.pauseEvent, kind)) { |
| 121 // Already waiting at a breakpoint. | 136 // Already waiting at a breakpoint. |
| 122 if (completer != null) { | 137 if (completer != null) { |
| 123 print('Paused with $kind'); | 138 print('Paused with $kind'); |
| 124 subscription.cancel(); | 139 subscription.cancel(); |
| 125 completer.complete(isolate); | 140 completer.complete(isolate); |
| 126 completer = null; | 141 completer = null; |
| 127 } | 142 } |
| 128 } | 143 } |
| 129 }); | 144 }); |
| 130 }); | 145 }); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 267 |
| 253 Future<Instance> rootLibraryFieldValue(Isolate isolate, | 268 Future<Instance> rootLibraryFieldValue(Isolate isolate, |
| 254 String fieldName) async { | 269 String fieldName) async { |
| 255 Library rootLib = await isolate.rootLibrary.load(); | 270 Library rootLib = await isolate.rootLibrary.load(); |
| 256 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); | 271 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); |
| 257 await field.load(); | 272 await field.load(); |
| 258 Instance value = field.staticValue; | 273 Instance value = field.staticValue; |
| 259 await value.load(); | 274 await value.load(); |
| 260 return value; | 275 return value; |
| 261 } | 276 } |
| OLD | NEW |