| 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/models.dart' as M; |
| 9 import 'package:observatory/service_common.dart'; | 9 import 'package:observatory/service_common.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 390 |
| 391 Future<Instance> rootLibraryFieldValue(Isolate isolate, | 391 Future<Instance> rootLibraryFieldValue(Isolate isolate, |
| 392 String fieldName) async { | 392 String fieldName) async { |
| 393 Library rootLib = await isolate.rootLibrary.load(); | 393 Library rootLib = await isolate.rootLibrary.load(); |
| 394 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); | 394 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); |
| 395 await field.load(); | 395 await field.load(); |
| 396 Instance value = field.staticValue; | 396 Instance value = field.staticValue; |
| 397 await value.load(); | 397 await value.load(); |
| 398 return value; | 398 return value; |
| 399 } | 399 } |
| 400 |
| 401 IsolateTest runStepThroughProgramRecordingStops(List<String> recordStops) { |
| 402 return (Isolate isolate) async { |
| 403 Completer completer = new Completer(); |
| 404 |
| 405 await subscribeToStream(isolate.vm, VM.kDebugStream, |
| 406 (ServiceEvent event) async { |
| 407 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 408 await isolate.reload(); |
| 409 // We are paused: Step further. |
| 410 Frame frame = isolate.topFrame; |
| 411 recordStops.add(await frame.location.toUserString()); |
| 412 if (event.atAsyncSuspension) { |
| 413 isolate.stepOverAsyncSuspension(); |
| 414 } else { |
| 415 isolate.stepOver(); |
| 416 } |
| 417 } else if (event.kind == ServiceEvent.kPauseExit) { |
| 418 // We are at the exit: The test is done. |
| 419 await cancelStreamSubscription(VM.kDebugStream); |
| 420 completer.complete(); |
| 421 } |
| 422 }); |
| 423 isolate.resume(); |
| 424 return completer.future; |
| 425 }; |
| 426 } |
| 427 |
| 428 IsolateTest checkRecordedStops( |
| 429 List<String> recordStops, List<String> expectedStops) { |
| 430 return (Isolate isolate) async { |
| 431 int end = recordStops.length < expectedStops.length |
| 432 ? recordStops.length |
| 433 : expectedStops.length; |
| 434 for (int i = 0; i < end; ++i) { |
| 435 expect(recordStops[i], expectedStops[i]); |
| 436 } |
| 437 |
| 438 expect(recordStops.length >= expectedStops.length, true, |
| 439 reason: "Expects at least ${expectedStops.length} breaks."); |
| 440 }; |
| 441 } |
| OLD | NEW |