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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 try { | 158 try { |
159 await other.load(); | 159 await other.load(); |
160 } on VMSentinelException catch (_) { | 160 } on VMSentinelException catch (_) { |
161 break; | 161 break; |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 expect(other.onExit, completes); | 165 expect(other.onExit, completes); |
166 }); | 166 }); |
167 }); | 167 }); |
| 168 |
| 169 test("onServiceExtensionAdded fires when an extension is added", () async { |
| 170 client = await runAndConnect(main: """ |
| 171 registerExtension('ext.test', (_, __) {}); |
| 172 """, flags: ["--pause-isolates-on-start"]); |
| 173 |
| 174 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); |
| 175 await isolate.waitUntilPaused(); |
| 176 await isolate.resume(); |
| 177 |
| 178 VMServiceExtension ext = await isolate.onServiceExtensionAdded.first; |
| 179 expect(ext.method, 'ext.test'); |
| 180 }); |
168 }); | 181 }); |
169 | 182 |
170 group("loadRunnable", () { | 183 group("loadRunnable", () { |
171 test("for an unrunnable isolate", () async { | 184 test("for an unrunnable isolate", () async { |
172 client = await runAndConnect(flags: ["--pause-isolates-on-start"]); | 185 client = await runAndConnect(flags: ["--pause-isolates-on-start"]); |
173 | 186 |
174 var isolate = (await client.getVM()).isolates.first; | 187 var isolate = (await client.getVM()).isolates.first; |
175 expect(isolate, isNot(new isInstanceOf<VMRunnableIsolate>())); | 188 expect(isolate, isNot(new isInstanceOf<VMRunnableIsolate>())); |
176 | 189 |
177 isolate = await isolate.loadRunnable(); | 190 isolate = await isolate.loadRunnable(); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 test("works before the isolate is runnable", () async { | 381 test("works before the isolate is runnable", () async { |
369 client = await runAndConnect(flags: ['--pause-isolates-on-start']); | 382 client = await runAndConnect(flags: ['--pause-isolates-on-start']); |
370 | 383 |
371 // We should be able to set a breakpoint before the relevant library is | 384 // 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. | 385 // loaded, although it may fail to resolve if the line number is bogus. |
373 var isolate = (await client.getVM()).isolates.first; | 386 var isolate = (await client.getVM()).isolates.first; |
374 var breakpoint = await isolate.addBreakpoint('my/script.dart', 0); | 387 var breakpoint = await isolate.addBreakpoint('my/script.dart', 0); |
375 expect(breakpoint.number, equals(1)); | 388 expect(breakpoint.number, equals(1)); |
376 }); | 389 }); |
377 }); | 390 }); |
| 391 |
| 392 group("invokeExtension", () { |
| 393 test("enforces ext. prefix", () async { |
| 394 var client = await runAndConnect(); |
| 395 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); |
| 396 expect(() => isolate.invokeExtension('noprefix'), throwsArgumentError); |
| 397 }); |
| 398 |
| 399 test("forwards to scope", () async { |
| 400 var client = await runAndConnect(main: r""" |
| 401 registerExtension('ext.ping', (_, __) async { |
| 402 return new ServiceExtensionResponse.result('{"type": "pong"}'); |
| 403 }); |
| 404 """); |
| 405 |
| 406 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); |
| 407 var response = await isolate.invokeExtension('ext.ping'); |
| 408 expect(response, {'type': 'pong'}); |
| 409 }); |
| 410 |
| 411 test("passes parameters", () async { |
| 412 var client = await runAndConnect(main: r""" |
| 413 registerExtension('ext.params', (_, params) async { |
| 414 return new ServiceExtensionResponse.result('''{ |
| 415 "foo": "${params['foo']}" |
| 416 }'''); |
| 417 }); |
| 418 """); |
| 419 |
| 420 var isolate = await (await client.getVM()).isolates.first.loadRunnable(); |
| 421 var response = await isolate.invokeExtension('ext.params', { |
| 422 'foo': 'bar', |
| 423 }); |
| 424 expect(response, { |
| 425 'foo': 'bar', |
| 426 }); |
| 427 }); |
| 428 }); |
378 } | 429 } |
379 | 430 |
380 /// Starts a client with two unpaused empty isolates. | 431 /// Starts a client with two unpaused empty isolates. |
381 Future<List<VMRunnableIsolate>> _twoIsolates() async { | 432 Future<List<VMRunnableIsolate>> _twoIsolates() async { |
382 client = await runAndConnect(topLevel: r""" | 433 client = await runAndConnect(topLevel: r""" |
383 void otherIsolate(_) {} | 434 void otherIsolate(_) {} |
384 """, main: r""" | 435 """, main: r""" |
385 Isolate.spawn(otherIsolate, null); | 436 Isolate.spawn(otherIsolate, null); |
386 """, flags: ["--pause-isolates-on-start", "--pause-isolates-on-exit"]); | 437 """, flags: ["--pause-isolates-on-start", "--pause-isolates-on-exit"]); |
387 | 438 |
388 var vm = await client.getVM(); | 439 var vm = await client.getVM(); |
389 var main = vm.isolates.first; | 440 var main = vm.isolates.first; |
390 | 441 |
391 var otherFuture = client.onIsolateRunnable.first; | 442 var otherFuture = client.onIsolateRunnable.first; |
392 await main.resume(); | 443 await main.resume(); |
393 var other = await otherFuture; | 444 var other = await otherFuture; |
394 await other.resume(); | 445 await other.resume(); |
395 | 446 |
396 return [main, other]; | 447 return [main, other]; |
397 } | 448 } |
OLD | NEW |