| 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 30 matching lines...) Expand all Loading... |
| 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 // Received a map. | 51 if (reply is! Map) { |
| 52 Expect.isTrue(reply is Map); | 52 onRequestFailed('Reply was not a map: $reply'); |
| 53 // Has a 'type' key. | 53 return; |
| 54 Expect.isNotNull(reply['type']); | 54 } |
| 55 onRequestCompleted(reply); | 55 if (reply['type'] == null) { |
| 56 onRequestFailed('Reply does not contain a type key: $reply'); |
| 57 return; |
| 58 } |
| 59 try { |
| 60 onRequestCompleted(reply); |
| 61 } catch(e) { |
| 62 onRequestFailed('Test callback failed: $e'); |
| 63 } |
| 56 } | 64 } |
| 57 | 65 |
| 58 void onRequestFailed(dynamic error) { | 66 void onRequestFailed(dynamic error) { |
| 59 Expect.fail('Failed to make request: $error'); | 67 Expect.fail('Failed to make request: $error'); |
| 60 } | 68 } |
| 61 | 69 |
| 62 void onRequestCompleted(Map response); | 70 void onRequestCompleted(Map response); |
| 63 } | 71 } |
| 64 | 72 |
| 65 class TestLauncher { | 73 class TestLauncher { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 var exists = false; | 158 var exists = false; |
| 151 isolateList['members'].forEach((isolate) { | 159 isolateList['members'].forEach((isolate) { |
| 152 if (isolate['id'] == id) { | 160 if (isolate['id'] == id) { |
| 153 exists = true; | 161 exists = true; |
| 154 Expect.isTrue(isolate['name'].startsWith(name)); | 162 Expect.isTrue(isolate['name'].startsWith(name)); |
| 155 } | 163 } |
| 156 }); | 164 }); |
| 157 Expect.isTrue(exists); | 165 Expect.isTrue(exists); |
| 158 } | 166 } |
| 159 } | 167 } |
| OLD | NEW |