Index: runtime/observatory/tests/service/get_retained_size_rpc_test.dart |
diff --git a/runtime/observatory/tests/service/get_retained_size_rpc_test.dart b/runtime/observatory/tests/service/get_retained_size_rpc_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a8a66f6eb07a690ff3f5364e185b9716416f8faa |
--- /dev/null |
+++ b/runtime/observatory/tests/service/get_retained_size_rpc_test.dart |
@@ -0,0 +1,68 @@ |
+// Copyright (c) 2015, 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. |
+// VMOptions=--compile-all --error_on_bad_type --error_on_bad_override |
+ |
+import 'dart:async'; |
+ |
+import 'package:observatory/service_io.dart'; |
+import 'package:unittest/unittest.dart'; |
+ |
+import 'test_helper.dart'; |
+ |
+class _TestClass { |
+ _TestClass(this.x, this.y); |
+ var x; |
+ var y; |
+} |
+ |
+var myVar; |
+ |
+eval(Isolate isolate, String expression) async { |
+ Map params = { |
+ 'targetId': isolate.rootLib.id, |
+ 'expression': expression, |
+ }; |
+ return await isolate.invokeRpcNoUpgrade('eval', params); |
+} |
+ |
+var tests = [ |
+ (Isolate isolate) async { |
+ // One instance of _TestClass retained. |
+ var evalResult = await eval( |
+ isolate, 'myVar = new _TestClass(null, null)'); |
+ var params = { |
+ 'targetId': evalResult['id'], |
+ }; |
+ var result = await isolate.invokeRpcNoUpgrade('_getRetainedSize', params); |
+ expect(result['type'], equals('@int')); |
+ int value1 = int.parse(result['valueAsString']); |
+ expect(value1, isPositive); |
+ |
+ // Two instances of _TestClass retained. |
+ evalResult = await eval( |
+ isolate, 'myVar = new _TestClass(new _TestClass(null, null), null)'); |
+ params = { |
+ 'targetId': evalResult['id'], |
+ }; |
+ result = await isolate.invokeRpcNoUpgrade('_getRetainedSize', params); |
+ expect(result['type'], equals('@int')); |
+ int value2 = int.parse(result['valueAsString']); |
+ expect(value2, isPositive); |
+ |
+ // Size has doubled. |
+ expect(value2, equals(2 * value1)); |
+ |
+ // Get the retained size for class _TestClass. |
+ params = { |
+ 'targetId': evalResult['class']['id'], |
+ }; |
+ result = await isolate.invokeRpcNoUpgrade('_getRetainedSize', params); |
+ expect(result['type'], equals('@int')); |
+ int value3 = int.parse(result['valueAsString']); |
+ expect(value3, isPositive); |
+ expect(value3, equals(value2)); |
+ }, |
+]; |
+ |
+main(args) async => runIsolateTests(args, tests); |