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

Side by Side Diff: mojo/dart/apptests/dart_apptests/lib/src/pingpong_apptests.dart

Issue 1998433002: Dart: Adds Interface and InterfaceRequest interfaces. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge Created 4 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 library pingpong_apptests; 5 library pingpong_apptests;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:mojo_apptest/apptest.dart'; 9 import 'package:mojo_apptest/apptest.dart';
10 import 'package:mojo/application.dart'; 10 import 'package:mojo/application.dart';
11 import 'package:mojo/bindings.dart'; 11 import 'package:mojo/bindings.dart';
12 import 'package:mojo/core.dart'; 12 import 'package:mojo/core.dart';
13 import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart'; 13 import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart';
14 14
15 class _TestingPingPongClient extends PingPongClient { 15 class _TestingPingPongClient extends PingPongClient {
16 final PingPongClientStub stub; 16 PingPongClientInterface client;
17 Completer _completer; 17 Completer _completer;
18 18
19 _TestingPingPongClient.unbound() : stub = new PingPongClientStub.unbound() { 19 _TestingPingPongClient() {
20 stub.impl = this; 20 client = new PingPongClientInterface(this);
21 } 21 }
22 22
23 waitForPong() async { 23 waitForPong() async {
24 _completer = new Completer(); 24 _completer = new Completer();
25 return _completer.future; 25 return _completer.future;
26 } 26 }
27 27
28 void pong(int pongValue) { 28 void pong(int pongValue) {
29 _completer.complete(pongValue); 29 _completer.complete(pongValue);
30 _completer = null; 30 _completer = null;
31 } 31 }
32 } 32 }
33 33
34 pingpongApptests(Application application, String url) { 34 pingpongApptests(Application application, String url) {
35 group('Ping-Pong Service Apptests', () { 35 group('Ping-Pong Service Apptests', () {
36 // Verify that "pingpong.dart" implements the PingPongService interface 36 // Verify that "pingpong.dart" implements the PingPongService interface
37 // and sends responses to our client. 37 // and sends responses to our client.
38 test('Ping Service To Pong Client', () async { 38 test('Ping Service To Pong Client', () async {
39 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); 39 var pingPongService = new PingPongServiceInterfaceRequest();
40 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 40 pingPongService.ctrl.errorFuture.then((e) => fail('$e'));
41 application.connectToService( 41 application.connectToService("mojo:dart_pingpong", pingPongService);
42 "mojo:dart_pingpong", pingPongServiceProxy);
43 42
44 var pingPongClient = new _TestingPingPongClient.unbound(); 43 var pingPongClient = new _TestingPingPongClient();
45 pingPongServiceProxy.setClient(pingPongClient.stub); 44 pingPongService.setClient(pingPongClient.client);
46 45
47 pingPongServiceProxy.ping(1); 46 pingPongService.ping(1);
48 var pongValue = await pingPongClient.waitForPong(); 47 var pongValue = await pingPongClient.waitForPong();
49 expect(pongValue, equals(2)); 48 expect(pongValue, equals(2));
50 49
51 pingPongServiceProxy.ping(100); 50 pingPongService.ping(100);
52 pongValue = await pingPongClient.waitForPong(); 51 pongValue = await pingPongClient.waitForPong();
53 expect(pongValue, equals(101)); 52 expect(pongValue, equals(101));
54 53
55 await pingPongClient.stub.close(); 54 await pingPongClient.client.close();
56 await pingPongServiceProxy.close(); 55 await pingPongService.close();
57 }); 56 });
58 57
59 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as 58 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as
60 // its client, and return a Future that only resolves after the 59 // its client, and return a Future that only resolves after the
61 // target.ping() => client.pong() methods have executed 9 times. 60 // target.ping() => client.pong() methods have executed 9 times.
62 test('Ping Target URL', () async { 61 test('Ping Target URL', () async {
63 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); 62 var pingPongService = new PingPongServiceInterfaceRequest();
64 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 63 pingPongService.ctrl.errorFuture.then((e) => fail('$e'));
65 application.connectToService( 64 application.connectToService("mojo:dart_pingpong", pingPongService);
66 "mojo:dart_pingpong", pingPongServiceProxy);
67 65
68 var r = await pingPongServiceProxy.pingTargetUrl( 66 var r = await pingPongService.pingTargetUrl(
69 "mojo:dart_pingpong_target", 9); 67 "mojo:dart_pingpong_target", 9);
70 expect(r.ok, equals(true)); 68 expect(r.ok, equals(true));
71 69
72 await pingPongServiceProxy.close(); 70 await pingPongService.close();
73 }); 71 });
74 72
75 // Same as the previous test except that instead of providing the 73 // Same as the previous test except that instead of providing the
76 // pingpong_target.dart URL, we provide a connection to its PingPongService. 74 // pingpong_target.dart URL, we provide a connection to its PingPongService.
77 test('Ping Target Service', () async { 75 test('Ping Target Service', () async {
78 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); 76 var pingPongService = new PingPongServiceInterfaceRequest();
79 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 77 pingPongService.ctrl.errorFuture.then((e) => fail('$e'));
80 application.connectToService( 78 application.connectToService("mojo:dart_pingpong", pingPongService);
81 "mojo:dart_pingpong", pingPongServiceProxy);
82 79
83 var targetServiceProxy = new PingPongServiceProxy.unbound(); 80 var targetService = new PingPongServiceInterfaceRequest();
84 targetServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 81 targetService.ctrl.errorFuture.then((e) => fail('$e'));
85 application.connectToService( 82 application.connectToService("mojo:dart_pingpong_target", targetService);
86 "mojo:dart_pingpong_target", targetServiceProxy);
87 83
88 var r = await pingPongServiceProxy.pingTargetService( 84 var r = await pingPongService.pingTargetService(targetService, 9);
89 targetServiceProxy, 9);
90 expect(r.ok, equals(true)); 85 expect(r.ok, equals(true));
91 // This side no longer has access to the pipe. 86 // This side no longer has access to the pipe.
92 expect(targetServiceProxy.ctrl.isOpen, equals(false)); 87 expect(targetService.ctrl.isOpen, equals(false));
93 expect(targetServiceProxy.ctrl.isBound, equals(false)); 88 expect(targetService.ctrl.isBound, equals(false));
94 89
95 await pingPongServiceProxy.close(); 90 await pingPongService.close();
96 }); 91 });
97 92
98 // Verify that Dart can implement an interface "request" parameter. 93 // Verify that Dart can implement an interface "request" parameter.
99 test('Get Target Service', () async { 94 test('Get Target Service', () async {
100 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); 95 var pingPongService = new PingPongServiceInterfaceRequest();
101 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 96 pingPongService.ctrl.errorFuture.then((e) => fail('$e'));
102 application.connectToService( 97 application.connectToService("mojo:dart_pingpong", pingPongService);
103 "mojo:dart_pingpong", pingPongServiceProxy);
104 98
105 var targetServiceProxy = new PingPongServiceProxy.unbound(); 99 var targetService = new PingPongServiceInterfaceRequest();
106 targetServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 100 targetService.ctrl.errorFuture.then((e) => fail('$e'));
107 pingPongServiceProxy.getPingPongService(targetServiceProxy); 101 pingPongService.getPingPongService(targetService);
108 102
109 var pingPongClient = new _TestingPingPongClient.unbound(); 103 var pingPongClient = new _TestingPingPongClient();
110 targetServiceProxy.setClient(pingPongClient.stub); 104 targetService.setClient(pingPongClient.client);
111 105
112 targetServiceProxy.ping(1); 106 targetService.ping(1);
113 var pongValue = await pingPongClient.waitForPong(); 107 var pongValue = await pingPongClient.waitForPong();
114 expect(pongValue, equals(2)); 108 expect(pongValue, equals(2));
115 109
116 targetServiceProxy.ping(100); 110 targetService.ping(100);
117 pongValue = await pingPongClient.waitForPong(); 111 pongValue = await pingPongClient.waitForPong();
118 expect(pongValue, equals(101)); 112 expect(pongValue, equals(101));
119 113
120 await pingPongClient.stub.close(); 114 await pingPongClient.client.close();
121 await targetServiceProxy.close(); 115 await targetService.close();
122 await pingPongServiceProxy.close(); 116 await pingPongService.close();
123 }); 117 });
124 118
125 // Verify that Dart can implement an interface "request" parameter that 119 // Verify that Dart can implement an interface "request" parameter that
126 // isn't hooked up to an actual service implementation until after some 120 // isn't hooked up to an actual service implementation until after some
127 // delay. 121 // delay.
128 test('Get Target Service Delayed', () async { 122 test('Get Target Service Delayed', () async {
129 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); 123 var pingPongService = new PingPongServiceInterfaceRequest();
130 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 124 pingPongService.ctrl.errorFuture.then((e) => fail('$e'));
131 application.connectToService( 125 application.connectToService("mojo:dart_pingpong", pingPongService);
132 "mojo:dart_pingpong", pingPongServiceProxy);
133 126
134 var targetServiceProxy = new PingPongServiceProxy.unbound(); 127 var targetService = new PingPongServiceInterfaceRequest();
135 targetServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); 128 targetService.ctrl.errorFuture.then((e) => fail('$e'));
136 pingPongServiceProxy.getPingPongServiceDelayed(targetServiceProxy); 129 pingPongService.getPingPongServiceDelayed(targetService);
137 130
138 var pingPongClient = new _TestingPingPongClient.unbound(); 131 var pingPongClient = new _TestingPingPongClient();
139 targetServiceProxy.setClient(pingPongClient.stub); 132 targetService.setClient(pingPongClient.client);
140 133
141 targetServiceProxy.ping(1); 134 targetService.ping(1);
142 var pongValue = await pingPongClient.waitForPong(); 135 var pongValue = await pingPongClient.waitForPong();
143 expect(pongValue, equals(2)); 136 expect(pongValue, equals(2));
144 137
145 targetServiceProxy.ping(100); 138 targetService.ping(100);
146 pongValue = await pingPongClient.waitForPong(); 139 pongValue = await pingPongClient.waitForPong();
147 expect(pongValue, equals(101)); 140 expect(pongValue, equals(101));
148 141
149 await pingPongClient.stub.close(); 142 await pingPongClient.client.close();
150 await targetServiceProxy.close(); 143 await targetService.close();
151 await pingPongServiceProxy.close(); 144 await pingPongService.close();
152 }); 145 });
153 }); 146 });
154 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698