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

Side by Side Diff: tests/standalone/vmservice/test_helper.dart

Issue 24075002: Expose field data, use class id, and merge all collections into "objects" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library vmservice_test_helper; 5 library vmservice_test_helper;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
11 11
12 abstract class VmServiceRequestHelper { 12 abstract class VmServiceRequestHelper {
13 final Uri uri; 13 final Uri uri;
14 final HttpClient client; 14 final HttpClient client;
15 15
16 VmServiceRequestHelper(String url) : 16 VmServiceRequestHelper(String url) :
17 uri = Uri.parse(url), 17 uri = Uri.parse(url),
18 client = new HttpClient(); 18 client = new HttpClient();
19 19
20 Future makeRequest() { 20 Future makeRequest() {
21 return client.getUrl(uri) 21 return client.getUrl(uri)
22 .then((HttpClientRequest request) => request.close()) 22 .then((HttpClientRequest request) => request.close())
23 .then((HttpClientResponse response) { 23 .then((HttpClientResponse response) {
24 return response 24 return response
25 .fold(new BytesBuilder(), (b, d) => b..add(d)) 25 .fold(new BytesBuilder(), (b, d) => b..add(d))
26 .then((builder) { 26 .then((builder) {
27 print('** GET: $uri'); 27 print('** GET: $uri');
28 _requestCompleted(builder.takeBytes(), response); 28 return _requestCompleted(builder.takeBytes(), response);
29 }); 29 });
30 }).catchError((error) { 30 }).catchError((error) {
31 onRequestFailed(error); 31 onRequestFailed(error);
32 }); 32 });
33 } 33 }
34 34
35 void _requestCompleted(List<int> data, HttpClientResponse response) { 35 Future _requestCompleted(List<int> data, HttpClientResponse response) {
36 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code'); 36 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code');
37 var replyAsString; 37 var replyAsString;
38 try { 38 try {
39 replyAsString = UTF8.decode(data); 39 replyAsString = UTF8.decode(data);
40 } catch (e) { 40 } catch (e) {
41 onRequestFailed(e); 41 onRequestFailed(e);
42 return; 42 return null;
43 } 43 }
44 print('** Response: $replyAsString'); 44 print('** Response: $replyAsString');
45 var reply; 45 var reply;
46 try { 46 try {
47 reply = JSON.decode(replyAsString); 47 reply = JSON.decode(replyAsString);
48 } catch (e) { 48 } catch (e) {
49 onRequestFailed(e); 49 onRequestFailed(e);
50 return; 50 return null;
51 } 51 }
52 if (reply is! Map) { 52 if (reply is! Map) {
53 onRequestFailed('Reply was not a map: $reply'); 53 onRequestFailed('Reply was not a map: $reply');
54 return; 54 return null;
55 } 55 }
56 if (reply['type'] == null) { 56 if (reply['type'] == null) {
57 onRequestFailed('Reply does not contain a type key: $reply'); 57 onRequestFailed('Reply does not contain a type key: $reply');
58 return; 58 return null;
59 } 59 }
60 var r;
60 try { 61 try {
61 onRequestCompleted(reply); 62 r = onRequestCompleted(reply);
62 } catch (e) { 63 } catch (e) {
63 onRequestFailed('Test callback failed: $e'); 64 r = onRequestFailed('Test callback failed: $e');
64 } 65 }
66 return r;
65 } 67 }
66 68
67 void onRequestFailed(dynamic error) { 69 Future onRequestFailed(dynamic error) {
68 Expect.fail('Failed to make request: $error'); 70 Expect.fail('Failed to make request: $error');
69 } 71 }
70 72
71 void onRequestCompleted(Map response); 73 Future onRequestCompleted(Map response);
72 } 74 }
73 75
74 class TestLauncher { 76 class TestLauncher {
75 final String script; 77 final String script;
76 Process process; 78 Process process;
77 79
78 TestLauncher(this.script); 80 TestLauncher(this.script);
79 81
80 String get scriptPath { 82 String get scriptPath {
81 var dartScript = Platform.script; 83 var dartScript = Platform.script;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (isolate['id'] == id) { 174 if (isolate['id'] == id) {
173 exists = true; 175 exists = true;
174 Expect.isTrue(isolate['name'].startsWith(name), 176 Expect.isTrue(isolate['name'].startsWith(name),
175 'Isolate $id does not have name prefix: $name' 177 'Isolate $id does not have name prefix: $name'
176 ' (was ${isolate['name']})'); 178 ' (was ${isolate['name']})');
177 } 179 }
178 }); 180 });
179 Expect.isTrue(exists, 'No isolate with id: $id'); 181 Expect.isTrue(exists, 'No isolate with id: $id');
180 } 182 }
181 } 183 }
184
185 class ClassTableHelper {
186 final Map classTable;
187
188 ClassTableHelper(this.classTable) {
189 Expect.equals('ClassList', classTable['type'], 'Not a ClassTable.');
190 }
191
192 bool classExists(String user_name) {
193 List members = classTable['members'];
194 for (var i = 0; i < members.length; i++) {
195 Map klass = members[i];
196 if (klass['user_name'] == user_name) {
197 return true;
198 }
199 }
200 return false;
201 }
202
203 int classId(String user_name) {
204 List members = classTable['members'];
205 for (var i = 0; i < members.length; i++) {
206 Map klass = members[i];
207 if (klass['user_name'] == user_name) {
208 return klass['id'];
209 }
210 }
211 return -1;
212 }
213 }
214
215 class FieldRequestHelper extends VmServiceRequestHelper {
216 FieldRequestHelper(port, isolate_id, field_id) :
217 super('http://127.0.0.1:$port/isolates/$isolate_id/objects/$field_id');
218 Map field;
219 onRequestCompleted(Map reply) {
220 Expect.equals('Field', reply['type']);
221 field = reply;
222 return this;
223 }
224 }
225
226 class ClassFieldRequestHelper extends VmServiceRequestHelper {
227 final List<String> fieldNames;
228 int port_;
229 int isolate_id_;
230 ClassFieldRequestHelper(port, isolate_id, class_id, this.fieldNames) :
231 super('http://127.0.0.1:$port/isolates/$isolate_id/classes/$class_id') {
232 port_ = port;
233 isolate_id_ = isolate_id;
234 }
235 final Map<String, Map> fields = new Map<String, Map>();
236
237 onRequestCompleted(Map reply) {
238 Expect.equals('Class', reply['type']);
239 List<Map> class_fields = reply['fields'];
240 List<Future> requests = new List<Future>();
241 fieldNames.forEach((fn) {
242 class_fields.forEach((f) {
243 if (f['user_name'] == fn) {
244 var request = new FieldRequestHelper(port_, isolate_id_, f['id']);
245 requests.add(request.makeRequest());
246 }
247 });
248 });
249 return Future.wait(requests).then((a) {
250 a.forEach((FieldRequestHelper field) {
251 fields[field.field['user_name']] = field.field;
252 });
253 return this;
254 });
255 }
256 }
OLDNEW
« no previous file with comments | « tests/standalone/vmservice/isolate_library_test.dart ('k') | tests/standalone/vmservice/unknown_isolate_command_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698