| OLD | NEW |
| 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 'dart:json' as JSON; | 10 import 'dart:json' as JSON; |
| 11 import 'dart:utf' as UTF; | |
| 12 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
| 13 | 12 |
| 14 abstract class VmServiceRequestHelper { | 13 abstract class VmServiceRequestHelper { |
| 15 final Uri uri; | 14 final Uri uri; |
| 16 final HttpClient client; | 15 final HttpClient client; |
| 17 | 16 |
| 18 VmServiceRequestHelper(String url) : | 17 VmServiceRequestHelper(String url) : |
| 19 uri = Uri.parse(url), | 18 uri = Uri.parse(url), |
| 20 client = new HttpClient(); | 19 client = new HttpClient(); |
| 21 | 20 |
| 22 Future makeRequest() { | 21 Future makeRequest() { |
| 23 return client.getUrl(uri) | 22 return client.getUrl(uri) |
| 24 .then((HttpClientRequest request) => request.close()) | 23 .then((HttpClientRequest request) => request.close()) |
| 25 .then((HttpClientResponse response) { | 24 .then((HttpClientResponse response) { |
| 26 return response | 25 return response |
| 27 .fold(new BytesBuilder(), (b, d) => b..add(d)) | 26 .fold(new BytesBuilder(), (b, d) => b..add(d)) |
| 28 .then((builder) { | 27 .then((builder) { |
| 29 print('** GET: $uri'); | 28 print('** GET: $uri'); |
| 30 _requestCompleted(builder.takeBytes(), response); | 29 _requestCompleted(builder.takeBytes(), response); |
| 31 }); | 30 }); |
| 32 }).catchError((error) { | 31 }).catchError((error) { |
| 33 onRequestFailed(error); | 32 onRequestFailed(error); |
| 34 }); | 33 }); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void _requestCompleted(List<int> data, HttpClientResponse response) { | 36 void _requestCompleted(List<int> data, HttpClientResponse response) { |
| 38 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code'); | 37 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code'); |
| 39 var replyAsString; | 38 var replyAsString; |
| 40 try { | 39 try { |
| 41 replyAsString = UTF.decodeUtf8(data, 0, null, null); | 40 replyAsString = UTF8.decode(data); |
| 42 } catch (e) { | 41 } catch (e) { |
| 43 onRequestFailed(e); | 42 onRequestFailed(e); |
| 44 return; | 43 return; |
| 45 } | 44 } |
| 46 print('** Response: $replyAsString'); | 45 print('** Response: $replyAsString'); |
| 47 var reply; | 46 var reply; |
| 48 try { | 47 try { |
| 49 reply = JSON.parse(replyAsString); | 48 reply = JSON.parse(replyAsString); |
| 50 } catch (e) { | 49 } catch (e) { |
| 51 onRequestFailed(e); | 50 onRequestFailed(e); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 if (isolate['id'] == id) { | 173 if (isolate['id'] == id) { |
| 175 exists = true; | 174 exists = true; |
| 176 Expect.isTrue(isolate['name'].startsWith(name), | 175 Expect.isTrue(isolate['name'].startsWith(name), |
| 177 'Isolate $id does not have name prefix: $name' | 176 'Isolate $id does not have name prefix: $name' |
| 178 ' (was ${isolate['name']})'); | 177 ' (was ${isolate['name']})'); |
| 179 } | 178 } |
| 180 }); | 179 }); |
| 181 Expect.isTrue(exists, 'No isolate with id: $id'); | 180 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 182 } | 181 } |
| 183 } | 182 } |
| OLD | NEW |