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

Side by Side Diff: runtime/observatory/tests/service/service_test_common.dart

Issue 2361183002: Respect setLibraryDebuggable (Closed)
Patch Set: Respect setLibraryDebuggable Created 4 years, 3 months 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
OLDNEW
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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 ServiceMap stack = await isolate.getStack(); 221 ServiceMap stack = await isolate.getStack();
222 expect(stack.type, equals('Stack')); 222 expect(stack.type, equals('Stack'));
223 223
224 List<Frame> frames = stack['frames']; 224 List<Frame> frames = stack['frames'];
225 expect(frames.length, greaterThanOrEqualTo(1)); 225 expect(frames.length, greaterThanOrEqualTo(1));
226 226
227 Frame top = frames[0]; 227 Frame top = frames[0];
228 Script script = await top.location.script.load(); 228 Script script = await top.location.script.load();
229 int actualLine = script.tokenToLine(top.location.tokenPos); 229 int actualLine = script.tokenToLine(top.location.tokenPos);
230 if (actualLine != line) { 230 if (actualLine != line) {
231 var sb = new StringBuffer(); 231 StringBuffer sb = new StringBuffer();
232 sb.write("Expected to be at line $line but actually at line $actualLine"); 232 sb.write("Expected to be at line $line but actually at line $actualLine");
233 sb.write("\nFull stack trace:\n"); 233 sb.write("\nFull stack trace:\n");
234 for (Frame f in stack['frames']) { 234 for (Frame f in stack['frames']) {
235 sb.write(" $f [${await f.location.getLine()}]\n"); 235 sb.write(" $f [${await f.location.getLine()}]\n");
236 } 236 }
237 throw sb.toString(); 237 throw sb.toString();
238 } else { 238 } else {
239 print('Program is stopped at line: $line'); 239 print('Program is stopped at line: $line');
240 } 240 }
241 }; 241 };
242 } 242 }
243 243
244 244
245 IsolateTest stoppedInFunction(String functionName, {bool contains: false}) {
246 return (Isolate isolate) async {
247 print("Checking we are in function: $functionName");
248
249 ServiceMap stack = await isolate.getStack();
250 expect(stack.type, equals('Stack'));
251
252 List<Frame> frames = stack['frames'];
253 expect(frames.length, greaterThanOrEqualTo(1));
254
255 Frame topFrame = stack['frames'][0];
256 ServiceFunction function = await topFrame.function.load();
257 final bool matches =
258 contains ? function.name.contains(functionName) :
259 function.name == functionName;
260 if (!matches) {
261 StringBuffer sb = new StringBuffer();
262 sb.write("Expected to be in function $functionName but "
263 "actually in function ${function.name}");
264 sb.write("\nFull stack trace:\n");
265 for (Frame f in stack['frames']) {
266 await f.function.load();
267 await (f.function.dartOwner as ServiceObject).load();
268 String name = f.function.name;
269 String ownerName = (f.function.dartOwner as ServiceObject).name;
270 sb.write(" $f [$name] [$ownerName]\n");
271 }
272 throw sb.toString();
273 } else {
274 print('Program is stopped in function: $functionName');
275 }
276 };
277 }
278
279
245 Future<Isolate> resumeIsolate(Isolate isolate) { 280 Future<Isolate> resumeIsolate(Isolate isolate) {
246 Completer completer = new Completer(); 281 Completer completer = new Completer();
247 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { 282 isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
248 var subscription; 283 var subscription;
249 subscription = stream.listen((ServiceEvent event) { 284 subscription = stream.listen((ServiceEvent event) {
250 if (event.kind == ServiceEvent.kResume) { 285 if (event.kind == ServiceEvent.kResume) {
251 subscription.cancel(); 286 subscription.cancel();
252 completer.complete(); 287 completer.complete();
253 } 288 }
254 }); 289 });
(...skipping 30 matching lines...) Expand all
285 Future<Isolate> stepOver(Isolate isolate) async { 320 Future<Isolate> stepOver(Isolate isolate) async {
286 await isolate.stepOver(); 321 await isolate.stepOver();
287 return hasStoppedAtBreakpoint(isolate); 322 return hasStoppedAtBreakpoint(isolate);
288 } 323 }
289 324
290 Future<Isolate> stepInto(Isolate isolate) async { 325 Future<Isolate> stepInto(Isolate isolate) async {
291 await isolate.stepInto(); 326 await isolate.stepInto();
292 return hasStoppedAtBreakpoint(isolate); 327 return hasStoppedAtBreakpoint(isolate);
293 } 328 }
294 329
330 Future<Isolate> stepOut(Isolate isolate) async {
331 await isolate.stepOut();
332 return hasStoppedAtBreakpoint(isolate);
333 }
334
335
295 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { 336 Future<Class> getClassFromRootLib(Isolate isolate, String className) async {
296 Library rootLib = await isolate.rootLibrary.load(); 337 Library rootLib = await isolate.rootLibrary.load();
297 for (var i = 0; i < rootLib.classes.length; i++) { 338 for (var i = 0; i < rootLib.classes.length; i++) {
298 Class cls = rootLib.classes[i]; 339 Class cls = rootLib.classes[i];
299 if (cls.name == className) { 340 if (cls.name == className) {
300 return cls; 341 return cls;
301 } 342 }
302 } 343 }
303 return null; 344 return null;
304 } 345 }
305 346
306 347
307 Future<Instance> rootLibraryFieldValue(Isolate isolate, 348 Future<Instance> rootLibraryFieldValue(Isolate isolate,
308 String fieldName) async { 349 String fieldName) async {
309 Library rootLib = await isolate.rootLibrary.load(); 350 Library rootLib = await isolate.rootLibrary.load();
310 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); 351 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName);
311 await field.load(); 352 await field.load();
312 Instance value = field.staticValue; 353 Instance value = field.staticValue;
313 await value.load(); 354 await value.load();
314 return value; 355 return value;
315 } 356 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698