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

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

Issue 1090293003: Kill service_test.cc tests in favor of dart tests for the service protocol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix tests Created 5 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override
5
6 library get_object_rpc_test;
7
8 import 'dart:async';
9
10 import 'package:observatory/service_io.dart';
11 import 'package:unittest/unittest.dart';
12
13 import 'test_helper.dart';
14
15 class _DummyClass {
16 static var dummyVar = 11;
17 void dummyFunction() {
18 }
19 }
20
21 class _DummySubClass extends _DummyClass {
22 }
23
24 void warmup() {
25 new _DummyClass().dummyFunction();
26 }
27
28 eval(Isolate isolate, String expression) async {
29 Map params = {
30 'targetId': isolate.rootLib.id,
31 'expression': expression,
32 };
33 return await isolate.invokeRpcNoUpgrade('eval', params);
34 }
35
36 var tests = [
37 // null object.
38 (Isolate isolate) async {
39 var params = {
40 'objectId': 'objects/null',
41 };
42 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
43 expect(result['type'], equals('null'));
44 expect(result['id'], equals('objects/null'));
45 expect(result['valueAsString'], equals('null'));
46 expect(result['class']['type'], equals('@Class'));
47 expect(result['class']['name'], equals('Null'));
48 expect(result['size'], isPositive);
49 },
50
51 // bool object.
52 (Isolate isolate) async {
53 var params = {
54 'objectId': 'objects/bool-true',
55 };
56 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
57 expect(result['type'], equals('bool'));
58 expect(result['id'], equals('objects/bool-true'));
59 expect(result['valueAsString'], equals('true'));
60 expect(result['class']['type'], equals('@Class'));
61 expect(result['class']['name'], equals('bool'));
62 expect(result['size'], isPositive);
63 expect(result['fields'], isEmpty);
64 },
65
66 // int object.
67 (Isolate isolate) async {
68 var params = {
69 'objectId': 'objects/int-123',
70 };
71 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
72 expect(result['type'], equals('int'));
73 expect(result['_vmType'], equals('Smi'));
74 expect(result['id'], equals('objects/int-123'));
75 expect(result['valueAsString'], equals('123'));
76 expect(result['class']['type'], equals('@Class'));
77 expect(result['class']['name'], equals('_Smi'));
78 expect(result['size'], isZero);
79 expect(result['fields'], isEmpty);
80 },
81
82 // A general Dart object.
83 (Isolate isolate) async {
84 // Call eval to get a Dart list.
85 var evalResult = await eval(isolate, '[3, 2, 1]');
86 var params = {
87 'objectId': evalResult['id'],
88 };
89 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
90 expect(result['type'], equals('List'));
91 expect(result['_vmType'], equals('GrowableObjectArray'));
92 expect(result['id'], startsWith('objects/'));
93 expect(result['valueAsString'], isNull);
94 expect(result['class']['type'], equals('@Class'));
95 expect(result['class']['name'], equals('_GrowableList'));
96 expect(result['size'], isPositive);
97 expect(result['fields'], isEmpty);
98 expect(result['elements'].length, equals(3));
99 expect(result['elements'][0]['index'], equals(0));
100 expect(result['elements'][0]['value']['type'], equals('@int'));
101 expect(result['elements'][0]['value']['valueAsString'], equals('3'));
102 },
103
104 // An expired object.
105 (Isolate isolate) async {
106 var params = {
107 'objectId': 'objects/99999999',
108 };
109 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
110 expect(result['type'], equals('Sentinel'));
111 expect(result['id'], startsWith('objects/expired'));
112 expect(result['valueAsString'], equals('<expired>'));
113 expect(result['class'], isNull);
114 expect(result['size'], isNull);
115 },
116
117 // library.
118 (Isolate isolate) async {
119 var params = {
120 'objectId': isolate.rootLib.id,
121 };
122 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
123 expect(result['type'], equals('Library'));
124 expect(result['id'], startsWith('libraries/'));
125 expect(result['name'], equals('get_object_rpc_test'));
126 expect(result['url'], startsWith('file:'));
127 expect(result['url'], endsWith('get_object_rpc_test.dart'));
128 expect(result['imports'].length, isPositive);
129 expect(result['imports'][0]['type'], equals('@Library'));
130 expect(result['scripts'].length, isPositive);
131 expect(result['scripts'][0]['type'], equals('@Script'));
132 expect(result['variables'].length, isPositive);
133 expect(result['variables'][0]['type'], equals('@Field'));
134 expect(result['functions'].length, isPositive);
135 expect(result['functions'][0]['type'], equals('@Function'));
136 expect(result['classes'].length, isPositive);
137 expect(result['classes'][0]['type'], equals('@Class'));
138 },
139
140 // invalid library.
141 (Isolate isolate) async {
142 var params = {
143 'objectId': 'libraries/9999999',
144 };
145 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
146 expect(result['type'], equals('Error'));
147 expect(result['message'], startsWith('Unrecognized object id'));
148 },
149
150 // script.
151 (Isolate isolate) async {
152 // Get the library first.
153 var params = {
154 'objectId': isolate.rootLib.id,
155 };
156 var libResult = await isolate.invokeRpcNoUpgrade('getObject', params);
157 // Get the first script.
158 params = {
159 'objectId': libResult['scripts'][0]['id'],
160 };
161 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
162 expect(result['type'], equals('Script'));
163 expect(result['id'], startsWith('libraries/'));
164 expect(result['name'], startsWith('file:'));
165 expect(result['name'], endsWith('get_object_rpc_test.dart'));
166 expect(result['kind'], equals('script'));
167 expect(result['library']['type'], equals('@Library'));
168 expect(result['source'], startsWith('// Copyright (c)'));
169 expect(result['tokenPosTable'].length, isPositive);
170 expect(result['tokenPosTable'][0], new isInstanceOf<List>());
171 expect(result['tokenPosTable'][0].length, isPositive);
172 expect(result['tokenPosTable'][0][0], new isInstanceOf<int>());
173 },
174
175 // invalid script.
176 (Isolate isolate) async {
177 var params = {
178 'objectId': 'scripts/9999999',
179 };
180 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
181 expect(result['type'], equals('Error'));
182 expect(result['message'], startsWith('Unrecognized object id'));
183 },
184
185 // class
186 (Isolate isolate) async {
187 // Call eval to get a class id.
188 var evalResult = await eval(isolate, 'new _DummyClass()');
189 var params = {
190 'objectId': evalResult['class']['id'],
191 };
192 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
193 expect(result['type'], equals('Class'));
194 expect(result['id'], startsWith('classes/'));
195 expect(result['name'], equals('_DummyClass'));
196 expect(result['_vmName'], startsWith('_DummyClass@'));
197 expect(result['abstract'], equals(false));
198 expect(result['const'], equals(false));
199 expect(result['finalized'], equals(true));
200 expect(result['implemented'], equals(false));
201 expect(result['patch'], equals(false));
202 expect(result['library']['type'], equals('@Library'));
203 expect(result['script']['type'], equals('@Script'));
204 expect(result['super']['type'], equals('@Class'));
205 expect(result['interfaces'].length, isZero);
206 expect(result['fields'].length, isPositive);
207 expect(result['fields'][0]['type'], equals('@Field'));
208 expect(result['functions'].length, isPositive);
209 expect(result['functions'][0]['type'], equals('@Function'));
210 expect(result['subclasses'].length, isPositive);
211 expect(result['subclasses'][0]['type'], equals('@Class'));
212 },
213
214 // invalid class.
215 (Isolate isolate) async {
216 var params = {
217 'objectId': 'classes/9999999',
218 };
219 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
220 expect(result['type'], equals('Error'));
221 expect(result['message'], startsWith('Unrecognized object id'));
222 },
223
224 // type.
225 (Isolate isolate) async {
226 // Call eval to get a class id.
227 var evalResult = await eval(isolate, 'new _DummyClass()');
228 var id = "${evalResult['class']['id']}/types/0";
229 var params = {
230 'objectId': id,
231 };
232 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
233 expect(result['type'], equals('Type'));
234 expect(result['id'], equals(id));
235 expect(result['class']['type'], equals('@Class'));
236 expect(result['class']['name'], equals('_Type'));
237 expect(result['size'], isPositive);
238 expect(result['fields'], isEmpty);
239 expect(result['typeClass']['type'], equals('@Class'));
240 expect(result['typeClass']['name'], equals('_DummyClass'));
241 },
242
243 // invalid type.
244 (Isolate isolate) async {
245 var evalResult = await eval(isolate, 'new _DummyClass()');
246 var id = "${evalResult['class']['id']}/types/9999999";
247 var params = {
248 'objectId': id,
249 };
250 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
251 expect(result['type'], equals('Error'));
252 expect(result['message'], startsWith('Unrecognized object id'));
253 },
254
255 // function.
256 (Isolate isolate) async {
257 // Call eval to get a class id.
258 var evalResult = await eval(isolate, 'new _DummyClass()');
259 var id = "${evalResult['class']['id']}/functions/dummyFunction";
260 var params = {
261 'objectId': id,
262 };
263 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
264 expect(result['type'], equals('Function'));
265 expect(result['id'], equals(id));
266 expect(result['name'], equals('dummyFunction'));
267 expect(result['kind'], equals('RegularFunction'));
268 expect(result['static'], equals(false));
269 expect(result['const'], equals(false));
270 expect(result['script']['type'], equals('@Script'));
271 expect(result['tokenPos'], isPositive);
272 expect(result['code']['type'], equals('@Code'));
273 expect(result['_optimizable'], equals(true));
274 expect(result['_inlinable'], equals(true));
275 expect(result['_usageCounter'], isPositive);
276 expect(result['_optimizedCallSiteCount'], isZero);
277 expect(result['_deoptimizations'], isZero);
278 },
279
280 // invalid function.
281 (Isolate isolate) async {
282 // Call eval to get a class id.
283 var evalResult = await eval(isolate, 'new _DummyClass()');
284 var id = "${evalResult['class']['id']}/functions/invalid";
285 var params = {
286 'objectId': id,
287 };
288 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
289 expect(result['type'], equals('Error'));
290 expect(result['message'], startsWith('Unrecognized object id'));
291 },
292
293 // field
294 (Isolate isolate) async {
295 // Call eval to get a class id.
296 var evalResult = await eval(isolate, 'new _DummyClass()');
297 var id = "${evalResult['class']['id']}/fields/0";
298 var params = {
299 'objectId': id,
300 };
301 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
302 expect(result['type'], equals('Field'));
303 expect(result['id'], equals(id));
304 expect(result['name'], equals('dummyVar'));
305 expect(result['value']['valueAsString'], equals('11'));
306 expect(result['const'], equals(false));
307 expect(result['static'], equals(true));
308 expect(result['final'], equals(false));
309 expect(result['script']['type'], equals('@Script'));
310 expect(result['tokenPos'], isPositive);
311 expect(result['_guardNullable'], isNotNull);
312 expect(result['_guardClass'], isNotNull);
313 expect(result['_guardLength'], isNotNull);
314 },
315
316 // invalid field.
317 (Isolate isolate) async {
318 // Call eval to get a class id.
319 var evalResult = await eval(isolate, 'new _DummyClass()');
320 var id = "${evalResult['class']['id']}/fields/9999";
321 var params = {
322 'objectId': id,
323 };
324 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
325 expect(result['type'], equals('Error'));
326 expect(result['message'], startsWith('Unrecognized object id'));
327 },
328
329 // code.
330 (Isolate isolate) async {
331 // Call eval to get a class id.
332 var evalResult = await eval(isolate, 'new _DummyClass()');
333 var funcId = "${evalResult['class']['id']}/functions/dummyFunction";
334 var params = {
335 'objectId': funcId,
336 };
337 var funcResult = await isolate.invokeRpcNoUpgrade('getObject', params);
338 params = {
339 'objectId': funcResult['code']['id'],
340 };
341 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
342 expect(result['type'], equals('Code'));
343 expect(result['name'], equals('_DummyClass.dummyFunction'));
344 expect(result['_vmName'], equals('dummyFunction'));
345 expect(result['kind'], equals('Dart'));
346 expect(result['_optimized'], new isInstanceOf<bool>());
347 expect(result['function']['type'], equals('@Function'));
348 expect(result['_startAddress'], new isInstanceOf<String>());
349 expect(result['_endAddress'], new isInstanceOf<String>());
350 expect(result['_objectPool'], isNotNull);
351 expect(result['_disassembly'], isNotNull);
352 expect(result['_descriptors'], isNotNull);
353 expect(result['_inlinedFunctions'], isNotNull);
354 expect(result['_inlinedIntervals'], isNotNull);
355 },
356
357 // invalid code.
358 (Isolate isolate) async {
359 // Call eval to get a class id.
360 var params = {
361 'objectId': 'code/0',
362 };
363 var result = await isolate.invokeRpcNoUpgrade('getObject', params);
364 expect(result['type'], equals('Error'));
365 expect(result['message'], startsWith('Unrecognized object id'));
366 },
367 ];
368
369 main(args) async => runIsolateTests(args, tests, testeeBefore:warmup);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698