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

Side by Side Diff: mojo/dart/test/sample_service_test.dart

Issue 851173002: Dart: Encode/Decode handle and interface types. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix Interface encode parameters Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « mojo/dart/test/core_test.dart ('k') | mojo/public/dart/src/buffer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:async';
6 import 'dart:isolate';
7 import 'dart:mojo_bindings' as bindings;
8 import 'dart:mojo_core' as core;
9
10 import 'package:mojo/public/interfaces/bindings/tests/sample_service.mojom.dart' as sample;
11
12 class ExpectPortInterfaceImpl implements sample.PortInterface {
13 String _expected;
14 ExpectPortInterfaceImpl([this._expected = ""]);
15
16 void postMessage(String messageText, sample.PortClient port) {
17 assert(messageText == _expected);
18 port.close();
19 }
20 }
21
22 class ServiceImpl extends sample.ServiceInterface {
23 ServiceImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint);
24
25 void frobinate(sample.Foo foo, int baz, sample.PortClient portClient) {
26 var portInterface = new sample.PortInterface.unbound();
27 portInterface.delegate = new ExpectPortInterfaceImpl();
28 portClient.callPostMessage("frobinated", portInterface);
29 portInterface.listen();
30 callDidFrobinate(42);
31 portClient.close();
32 }
33
34 void getPort(sample.PortInterface portInterface) {
35 portInterface.delegate = new ExpectPortInterfaceImpl("port");
36 portInterface.listen();
37 }
38 }
39
40 class ServiceClientImpl extends sample.ServiceClientInterface
41 with sample.ServiceCalls {
42 Completer completer;
43
44 ServiceClientImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint);
45
46 void didFrobinate(int result) {
47 assert(result == 42);
48 completer.complete(null);
49 }
50
51 Future run() {
52 completer = new Completer();
53
54 listen();
55 var portClient = new sample.PortClient.unbound();
56 callGetPort(portClient);
57 portClient.close();
58
59 var portInterface = new sample.PortInterface.unbound();
60 portInterface.delegate = new ExpectPortInterfaceImpl("frobinated");
61 callFrobinate(new sample.Foo(), sample.BazOptions_EXTRA, portInterface);
62 portInterface.listen();
63 return completer.future;
64 }
65 }
66
67 void serviceIsolate(core.MojoMessagePipeEndpoint endpoint) {
68 var service = new ServiceImpl(endpoint);
69 service.listen();
70 }
71
72 main() async {
73 var pipe = new core.MojoMessagePipe();
74 var isolate = await Isolate.spawn(serviceIsolate, pipe.endpoints[0]);
75
76 var serviceClient = new ServiceClientImpl(pipe.endpoints[1]);
77 await serviceClient.run();
78
79 serviceClient.close();
80 }
OLDNEW
« no previous file with comments | « mojo/dart/test/core_test.dart ('k') | mojo/public/dart/src/buffer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698