blob: f87d89732694a6b9ad994c344e26a17786f5e3b3 [file] [log] [blame]
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:observatory_2/service_io.dart";
import "package:test/test.dart";
import "test_helper.dart";
class Class {}
class Subclass extends Class {}
class Implementor implements Class {}
var aClass;
var aSubclass;
var anImplementor;
allocate() {
aClass = new Class();
aSubclass = new Subclass();
anImplementor = new Implementor();
var tests = <IsolateTest>[
(Isolate isolate) async {
invoke(String selector) async {
Map params = {
"selector": selector,
"argumentIds": <String>[],
return await isolate.invokeRpcNoUpgrade("invoke", params);
Future<int> instanceCount(String className,
{bool includeSubclasses: false,
bool includeImplementors: false}) async {
Map params = {
"objectId": isolate.rootLibrary.classes
.singleWhere((cls) => == className)
"includeSubclasses": includeSubclasses,
"includeImplementors": includeImplementors,
var result =
await isolate.invokeRpcNoUpgrade("_getInstancesAsArray", params);
expect(result["type"], equals("@Instance"));
expect(result["kind"], equals("List"));
return result["length"] as int;
await isolate.rootLibrary.load();
expect(await instanceCount("Class"), equals(0));
expect(await instanceCount("Class", includeSubclasses: true), equals(0));
expect(await instanceCount("Class", includeImplementors: true), equals(0));
await invoke("allocate");
expect(await instanceCount("Class"), equals(1));
expect(await instanceCount("Class", includeSubclasses: true), equals(2));
expect(await instanceCount("Class", includeImplementors: true), equals(3));
main(args) async => runIsolateTests(args, tests);