Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 6 |
| 7 import 'package:async/async.dart'; | 7 import 'package:async/async.dart'; |
| 8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 9 import 'package:vm_service_client/vm_service_client.dart'; | 9 import 'package:vm_service_client/vm_service_client.dart'; |
| 10 | 10 |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 test("works before the isolate is runnable", () async { | 368 test("works before the isolate is runnable", () async { |
| 369 client = await runAndConnect(flags: ['--pause-isolates-on-start']); | 369 client = await runAndConnect(flags: ['--pause-isolates-on-start']); |
| 370 | 370 |
| 371 // We should be able to set a breakpoint before the relevant library is | 371 // We should be able to set a breakpoint before the relevant library is |
| 372 // loaded, although it may fail to resolve if the line number is bogus. | 372 // loaded, although it may fail to resolve if the line number is bogus. |
| 373 var isolate = (await client.getVM()).isolates.first; | 373 var isolate = (await client.getVM()).isolates.first; |
| 374 var breakpoint = await isolate.addBreakpoint('my/script.dart', 0); | 374 var breakpoint = await isolate.addBreakpoint('my/script.dart', 0); |
| 375 expect(breakpoint.number, equals(1)); | 375 expect(breakpoint.number, equals(1)); |
| 376 }); | 376 }); |
| 377 }); | 377 }); |
| 378 | |
| 379 group("invokeExtension", () { | |
| 380 test("enforces ext. prefix", () async { | |
| 381 var client = await runAndConnect(); | |
| 382 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); | |
| 383 expect(() => isolate.invokeExtension('noprefix'), throwsArgumentError); | |
| 384 }); | |
| 385 | |
| 386 test("forwards to scope", () async { | |
| 387 var client = await runAndConnect(main: r""" | |
| 388 registerExtension('ext.ping', (_, __) async { | |
| 389 return new ServiceExtensionResponse.result('{"type": "pong"}'); | |
| 390 }); | |
| 391 """); | |
| 392 | |
| 393 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); | |
| 394 Map response = await isolate.invokeExtension('ext.ping'); | |
| 395 expect(response, {'type': 'pong'}); | |
| 396 }); | |
| 397 | |
| 398 test("passes parameters", () async { | |
| 399 var client = await runAndConnect(main: r""" | |
| 400 registerExtension('ext.params', (_, params) async { | |
| 401 return new ServiceExtensionResponse.result('''{ | |
| 402 "type": "params", | |
| 403 "foo": "${params['foo']}", | |
| 404 "baz": "${params['baz']}" | |
| 405 }'''); | |
| 406 }); | |
| 407 """); | |
| 408 | |
| 409 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); | |
| 410 Map response = await isolate.invokeExtension('ext.params', { | |
|
nweiz
2016/02/10 22:17:11
Nit: "var response" (also above).
yjbanov
2016/02/10 23:06:37
Ugh, Flutter code style is getting into me. Done.
| |
| 411 'foo': 'bar', | |
| 412 'baz': 1, // VM service string-encodes parameter values | |
| 413 }); | |
| 414 expect(response, { | |
| 415 'type': 'params', | |
| 416 'foo': 'bar', | |
| 417 'baz': '1', | |
| 418 }); | |
| 419 }); | |
| 420 }); | |
| 378 } | 421 } |
| 379 | 422 |
| 380 /// Starts a client with two unpaused empty isolates. | 423 /// Starts a client with two unpaused empty isolates. |
| 381 Future<List<VMRunnableIsolate>> _twoIsolates() async { | 424 Future<List<VMRunnableIsolate>> _twoIsolates() async { |
| 382 client = await runAndConnect(topLevel: r""" | 425 client = await runAndConnect(topLevel: r""" |
| 383 void otherIsolate(_) {} | 426 void otherIsolate(_) {} |
| 384 """, main: r""" | 427 """, main: r""" |
| 385 Isolate.spawn(otherIsolate, null); | 428 Isolate.spawn(otherIsolate, null); |
| 386 """, flags: ["--pause-isolates-on-start", "--pause-isolates-on-exit"]); | 429 """, flags: ["--pause-isolates-on-start", "--pause-isolates-on-exit"]); |
| 387 | 430 |
| 388 var vm = await client.getVM(); | 431 var vm = await client.getVM(); |
| 389 var main = vm.isolates.first; | 432 var main = vm.isolates.first; |
| 390 | 433 |
| 391 var otherFuture = client.onIsolateRunnable.first; | 434 var otherFuture = client.onIsolateRunnable.first; |
| 392 await main.resume(); | 435 await main.resume(); |
| 393 var other = await otherFuture; | 436 var other = await otherFuture; |
| 394 await other.resume(); | 437 await other.resume(); |
| 395 | 438 |
| 396 return [main, other]; | 439 return [main, other]; |
| 397 } | 440 } |
| OLD | NEW |