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

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

Issue 112223002: WebSocket client for VM service (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 ServiceWebSocketRequestHelper {
13 final String url;
14 final Completer _completer = new Completer();
15 WebSocket _socket;
16
17 ServiceWebSocketRequestHelper(this.url);
18
19 // Returns [this] when connected.
20 Future connect() {
21 return WebSocket.connect(url).then((ws) {
22 _socket = ws;
23 _socket.listen((message) {
24 var map = JSON.decode(message);
25 var response = JSON.decode(map['response']);
26 onResponse(map['seq'], response);
27 });
28 return this;
29 });
30 }
31
32 void complete() {
33 _completer.complete(this);
34 }
35
36 Future get completed => _completer.future;
37
38 // Must call complete.
39 void onResponse(var seq, Map response);
40 void runTest();
41
42 Future sendMessage(var seq, List<String> path) {
43 var map = {
44 'seq': seq,
45 'path': path
46 };
47 var message = JSON.encode(map);
48 _socket.add(message);
49 return _completer.future;
50 }
51 }
52
12 abstract class VmServiceRequestHelper { 53 abstract class VmServiceRequestHelper {
13 final Uri uri; 54 final Uri uri;
14 final HttpClient client; 55 final HttpClient client;
15 56
16 VmServiceRequestHelper(String url) : 57 VmServiceRequestHelper(String url) :
17 uri = Uri.parse(url), 58 uri = Uri.parse(url),
18 client = new HttpClient(); 59 client = new HttpClient();
19 60
20 Future makeRequest() { 61 Future makeRequest() {
21 print('** GET: $uri'); 62 print('** GET: $uri');
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return Process.start(dartExecutable, 133 return Process.start(dartExecutable,
93 ['--enable-vm-service:0', scriptPath]).then((p) { 134 ['--enable-vm-service:0', scriptPath]).then((p) {
94 135
95 Completer completer = new Completer(); 136 Completer completer = new Completer();
96 process = p; 137 process = p;
97 var portNumber; 138 var portNumber;
98 var blank; 139 var blank;
99 var first = true; 140 var first = true;
100 process.stdout.transform(UTF8.decoder) 141 process.stdout.transform(UTF8.decoder)
101 .transform(new LineSplitter()).listen((line) { 142 .transform(new LineSplitter()).listen((line) {
102 if (line.startsWith('VmService listening on port ')) { 143 if (line.startsWith('VMService listening on port ')) {
103 RegExp portExp = new RegExp(r"\d+"); 144 RegExp portExp = new RegExp(r"\d+");
104 var port = portExp.stringMatch(line); 145 var port = portExp.stringMatch(line);
105 portNumber = int.parse(port); 146 portNumber = int.parse(port);
106 } 147 }
107 if (line == '') { 148 if (line == '') {
108 // Received blank line. 149 // Received blank line.
109 blank = true; 150 blank = true;
110 } 151 }
111 if (portNumber != null && blank == true && first == true) { 152 if (portNumber != null && blank == true && first == true) {
112 completer.complete(portNumber); 153 completer.complete(portNumber);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 }); 288 });
248 }); 289 });
249 return Future.wait(requests).then((a) { 290 return Future.wait(requests).then((a) {
250 a.forEach((FieldRequestHelper field) { 291 a.forEach((FieldRequestHelper field) {
251 fields[field.field['user_name']] = field.field; 292 fields[field.field['user_name']] = field.field;
252 }); 293 });
253 return this; 294 return this;
254 }); 295 });
255 } 296 }
256 } 297 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/vmservice_io.dart ('k') | tests/standalone/vmservice/websocket_client_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698