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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/dart/test/sample_service_test.dart
diff --git a/mojo/dart/test/sample_service_test.dart b/mojo/dart/test/sample_service_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..29eb16b51f91bea4cbfdeefcf3456b5fb6d3822b
--- /dev/null
+++ b/mojo/dart/test/sample_service_test.dart
@@ -0,0 +1,80 @@
+// Copyright 2014 The Chromium Authors. 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:isolate';
+import 'dart:mojo_bindings' as bindings;
+import 'dart:mojo_core' as core;
+
+import 'package:mojo/public/interfaces/bindings/tests/sample_service.mojom.dart' as sample;
+
+class ExpectPortInterfaceImpl implements sample.PortInterface {
+ String _expected;
+ ExpectPortInterfaceImpl([this._expected = ""]);
+
+ void postMessage(String messageText, sample.PortClient port) {
+ assert(messageText == _expected);
+ port.close();
+ }
+}
+
+class ServiceImpl extends sample.ServiceInterface {
+ ServiceImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint);
+
+ void frobinate(sample.Foo foo, int baz, sample.PortClient portClient) {
+ var portInterface = new sample.PortInterface.unbound();
+ portInterface.delegate = new ExpectPortInterfaceImpl();
+ portClient.callPostMessage("frobinated", portInterface);
+ portInterface.listen();
+ callDidFrobinate(42);
+ portClient.close();
+ }
+
+ void getPort(sample.PortInterface portInterface) {
+ portInterface.delegate = new ExpectPortInterfaceImpl("port");
+ portInterface.listen();
+ }
+}
+
+class ServiceClientImpl extends sample.ServiceClientInterface
+ with sample.ServiceCalls {
+ Completer completer;
+
+ ServiceClientImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint);
+
+ void didFrobinate(int result) {
+ assert(result == 42);
+ completer.complete(null);
+ }
+
+ Future run() {
+ completer = new Completer();
+
+ listen();
+ var portClient = new sample.PortClient.unbound();
+ callGetPort(portClient);
+ portClient.close();
+
+ var portInterface = new sample.PortInterface.unbound();
+ portInterface.delegate = new ExpectPortInterfaceImpl("frobinated");
+ callFrobinate(new sample.Foo(), sample.BazOptions_EXTRA, portInterface);
+ portInterface.listen();
+ return completer.future;
+ }
+}
+
+void serviceIsolate(core.MojoMessagePipeEndpoint endpoint) {
+ var service = new ServiceImpl(endpoint);
+ service.listen();
+}
+
+main() async {
+ var pipe = new core.MojoMessagePipe();
+ var isolate = await Isolate.spawn(serviceIsolate, pipe.endpoints[0]);
+
+ var serviceClient = new ServiceClientImpl(pipe.endpoints[1]);
+ await serviceClient.run();
+
+ serviceClient.close();
+}
« 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