Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // | |
| 5 // SharedOptions=-Da=true -Db=false -Dc=NOTBOOL -Dd=True | |
|
Søren Gjesse
2014/06/10 07:00:37
Whar are these SharedOptions for?
Anders Johnsen
2014/06/10 07:13:20
Done.
| |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:convert'; | |
| 9 import 'dart:io'; | |
| 10 import 'dart:mirrors'; | |
| 11 | |
| 12 import 'package:expect/expect.dart'; | |
| 13 import 'package:async_helper/async_helper.dart'; | |
| 14 | |
| 15 Map lookupServiceObject(String path) { | |
| 16 var io = currentMirrorSystem().findLibrary(const Symbol('dart.io')); | |
| 17 var m = MirrorSystem.getSymbol('_serviceObjectHandler', io); | |
| 18 var paths = Uri.parse(path).pathSegments; | |
| 19 Expect.equals('io', paths.first); | |
| 20 return JSON.decode( | |
| 21 io.invoke(m, [paths.sublist(1), [], []]).reflectee); | |
| 22 } | |
| 23 | |
| 24 | |
| 25 String getServicePath(obj) { | |
| 26 var io = currentMirrorSystem().findLibrary(const Symbol('dart.io')); | |
| 27 var m = MirrorSystem.getSymbol('_getServicePath', io); | |
| 28 return io.invoke(m, [obj]).reflectee; | |
| 29 } | |
| 30 | |
| 31 | |
| 32 Future testHttpServer1() { | |
| 33 return HttpServer.bind('localhost', 0).then((server) { | |
| 34 var path = getServicePath(server); | |
| 35 var map = lookupServiceObject(path); | |
| 36 Expect.equals(map['type'], 'HttpServer'); | |
| 37 Expect.equals(map['id'], path); | |
| 38 Expect.equals(map['address'], 'localhost'); | |
| 39 Expect.equals(map['port'], server.port); | |
| 40 Expect.equals(map['closed'], false); | |
| 41 Expect.equals(map['idle'], 0); | |
| 42 Expect.equals(map['active'], 0); | |
| 43 var socket = map['socket']; | |
| 44 Expect.equals(socket['type'], '@Socket'); | |
| 45 Expect.equals(socket['kind'], 'Listening'); | |
| 46 // Validate owner back-ref. | |
| 47 socket = lookupServiceObject(socket['id']); | |
| 48 Expect.equals(socket['owner']['id'], path); | |
| 49 return server.close(); | |
| 50 }); | |
| 51 } | |
| 52 | |
| 53 | |
| 54 void main() { | |
| 55 final tests = [ | |
| 56 testHttpServer1(), | |
| 57 ]; | |
| 58 | |
| 59 asyncStart(); | |
| 60 // Run one test at a time. | |
| 61 Future.forEach(tests, (f) => f) | |
| 62 .then((_) { | |
| 63 asyncEnd(); | |
| 64 }); | |
| 65 } | |
| OLD | NEW |