| 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:io'; | 8 import 'dart:io'; |
| 9 import 'dart:json' as JSON; | 9 import 'dart:json' as JSON; |
| 10 import 'dart:utf' as UTF; | 10 import 'dart:utf' as UTF; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 .fold(new BytesBuilder(), (b, d) => b..add(d)) | 26 .fold(new BytesBuilder(), (b, d) => b..add(d)) |
| 27 .then((builder) { | 27 .then((builder) { |
| 28 _requestCompleted(builder.takeBytes(), response); | 28 _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 void _requestCompleted(List<int> data, HttpClientResponse response) { |
| 36 Expect.equals(200, response.statusCode); | 36 Expect.equals(200, response.statusCode, 'Invalid HTTP Status Code'); |
| 37 var replyAsString; | 37 var replyAsString; |
| 38 try { | 38 try { |
| 39 replyAsString = UTF.decodeUtf8(data, 0, null, null); | 39 replyAsString = UTF.decodeUtf8(data, 0, null, null); |
| 40 } catch (e) { | 40 } catch (e) { |
| 41 onRequestFailed(e); | 41 onRequestFailed(e); |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 var reply; | 44 var reply; |
| 45 try { | 45 try { |
| 46 reply = JSON.parse(replyAsString); | 46 reply = JSON.parse(replyAsString); |
| 47 } catch (e) { | 47 } catch (e) { |
| 48 onRequestFailed(e); | 48 onRequestFailed(e); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 if (reply is! Map) { | 51 if (reply is! Map) { |
| 52 onRequestFailed('Reply was not a map: $reply'); | 52 onRequestFailed('Reply was not a map: $reply'); |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 if (reply['type'] == null) { | 55 if (reply['type'] == null) { |
| 56 onRequestFailed('Reply does not contain a type key: $reply'); | 56 onRequestFailed('Reply does not contain a type key: $reply'); |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 try { | 59 try { |
| 60 onRequestCompleted(reply); | 60 onRequestCompleted(reply); |
| 61 } catch(e) { | 61 } catch (e) { |
| 62 onRequestFailed('Test callback failed: $e'); | 62 onRequestFailed('Test callback failed: $e'); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void onRequestFailed(dynamic error) { | 66 void onRequestFailed(dynamic error) { |
| 67 Expect.fail('Failed to make request: $error'); | 67 Expect.fail('Failed to make request: $error'); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void onRequestCompleted(Map response); | 70 void onRequestCompleted(Map response); |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 void requestExit() { | 120 void requestExit() { |
| 121 process.stdin.add([32]); | 121 process.stdin.add([32]); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 class IsolateListTester { | 125 class IsolateListTester { |
| 126 final Map isolateList; | 126 final Map isolateList; |
| 127 | 127 |
| 128 IsolateListTester(this.isolateList) { | 128 IsolateListTester(this.isolateList) { |
| 129 // The reply is an IsolateList. | 129 // The reply is an IsolateList. |
| 130 Expect.equals('IsolateList', isolateList['type']); | 130 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void checkIsolateCount(int n) { | 133 void checkIsolateCount(int n) { |
| 134 Expect.equals(n, isolateList['members'].length); | 134 Expect.equals(n, isolateList['members'].length, 'Isolate count not $n'); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void checkIsolateIdExists(int id) { | 137 void checkIsolateIdExists(int id) { |
| 138 var exists = false; | 138 var exists = false; |
| 139 isolateList['members'].forEach((isolate) { | 139 isolateList['members'].forEach((isolate) { |
| 140 if (isolate['id'] == id) { | 140 if (isolate['id'] == id) { |
| 141 exists = true; | 141 exists = true; |
| 142 } | 142 } |
| 143 }); | 143 }); |
| 144 Expect.isTrue(exists); | 144 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void checkIsolateNameContains(String name) { | 147 void checkIsolateNameContains(String name) { |
| 148 var exists = false; | 148 var exists = false; |
| 149 isolateList['members'].forEach((isolate) { | 149 isolateList['members'].forEach((isolate) { |
| 150 if (isolate['name'].contains(name)) { | 150 if (isolate['name'].contains(name)) { |
| 151 exists = true; | 151 exists = true; |
| 152 } | 152 } |
| 153 }); | 153 }); |
| 154 Expect.isTrue(exists); | 154 Expect.isTrue(exists, 'No isolate with name: $name'); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void checkIsolateNamePrefix(int id, String name) { | 157 void checkIsolateNamePrefix(int id, String name) { |
| 158 var exists = false; | 158 var exists = false; |
| 159 isolateList['members'].forEach((isolate) { | 159 isolateList['members'].forEach((isolate) { |
| 160 if (isolate['id'] == id) { | 160 if (isolate['id'] == id) { |
| 161 exists = true; | 161 exists = true; |
| 162 Expect.isTrue(isolate['name'].startsWith(name)); | 162 Expect.isTrue(isolate['name'].startsWith(name), |
| 163 'Isolate $id does not have name prefix: $name'); |
| 163 } | 164 } |
| 164 }); | 165 }); |
| 165 Expect.isTrue(exists); | 166 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 166 } | 167 } |
| 167 } | 168 } |
| OLD | NEW |