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

Unified Diff: tests/standalone/io/observatory.dart

Issue 311153003: Add Observatory test of io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/observatory.dart
diff --git a/tests/standalone/io/observatory.dart b/tests/standalone/io/observatory.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b22bbc2aa6e23c94ec0df290e93a0112392b2637
--- /dev/null
+++ b/tests/standalone/io/observatory.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+import 'package:async_helper/async_helper.dart';
+
+Map lookupServiceObject(String path) {
+ var io = currentMirrorSystem().findLibrary(const Symbol('dart.io'));
+ var m = MirrorSystem.getSymbol('_serviceObjectHandler', io);
+ var paths = Uri.parse(path).pathSegments;
+ Expect.equals('io', paths.first);
+ return JSON.decode(
+ io.invoke(m, [paths.sublist(1), [], []]).reflectee);
+}
+
+
+String getServicePath(obj) {
+ var io = currentMirrorSystem().findLibrary(const Symbol('dart.io'));
+ var m = MirrorSystem.getSymbol('_getServicePath', io);
+ return io.invoke(m, [obj]).reflectee;
+}
+
+
+Future testHttpServer1() {
+ return HttpServer.bind('localhost', 0).then((server) {
+ var path = getServicePath(server);
+ var map = lookupServiceObject(path);
+ Expect.equals(map['type'], 'HttpServer');
+ Expect.equals(map['id'], path);
+ Expect.equals(map['address'], 'localhost');
+ Expect.equals(map['port'], server.port);
+ Expect.equals(map['closed'], false);
+ Expect.equals(map['idle'], 0);
+ Expect.equals(map['active'], 0);
+ var socket = map['socket'];
+ Expect.equals(socket['type'], '@Socket');
+ Expect.equals(socket['kind'], 'Listening');
+ // Validate owner back-ref.
+ socket = lookupServiceObject(socket['id']);
+ Expect.equals(socket['owner']['id'], path);
+ return server.close();
+ });
+}
+
+
+void main() {
+ final tests = [
+ testHttpServer1(),
+ ];
+
+ asyncStart();
+ // Run one test at a time.
+ Future.forEach(tests, (f) => f)
+ .then((_) {
+ asyncEnd();
+ });
+}
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | tests/standalone/io/raw_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698