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

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 225 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

Powered by Google App Engine
This is Rietveld 408576698