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

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

Issue 1964193002: Dart: Refactors Proxies (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address comments 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 echo_apptests; 5 library echo_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/echo_service.mojom.dart'; 13 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart';
14 14
15 echoApptests(Application application, String url) { 15 echoApptests(Application application, String url) {
16 group('Echo Service Apptests', () { 16 group('Echo Service Apptests', () {
17 test('String', () async { 17 test('String', () async {
18 var echoProxy = 18 var echoProxy =
19 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 19 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
20 20
21 var v = await echoProxy.ptr.echoString("foo"); 21 var v = await echoProxy.echoString("foo");
22 expect(v.value, equals("foo")); 22 expect(v.value, equals("foo"));
23 23
24 var q = await echoProxy.ptr.echoString("quit"); 24 var q = await echoProxy.echoString("quit");
25 expect(q.value, equals("quit")); 25 expect(q.value, equals("quit"));
26 26
27 await echoProxy.close(); 27 await echoProxy.close();
28 }); 28 });
29 29
30 test('Empty String', () async { 30 test('Empty String', () async {
31 var echoProxy = 31 var echoProxy =
32 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 32 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
33 33
34 var v = await echoProxy.ptr.echoString(""); 34 var v = await echoProxy.echoString("");
35 expect(v.value, equals("")); 35 expect(v.value, equals(""));
36 36
37 var q = await echoProxy.ptr.echoString("quit"); 37 var q = await echoProxy.echoString("quit");
38 expect(q.value, equals("quit")); 38 expect(q.value, equals("quit"));
39 39
40 await echoProxy.close(); 40 await echoProxy.close();
41 }); 41 });
42 42
43 test('Null String', () async { 43 test('Null String', () async {
44 var echoProxy = 44 var echoProxy =
45 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 45 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
46 46
47 var v = await echoProxy.ptr.echoString(null); 47 var v = await echoProxy.echoString(null);
48 expect(v.value, equals(null)); 48 expect(v.value, equals(null));
49 49
50 var q = await echoProxy.ptr.echoString("quit"); 50 var q = await echoProxy.echoString("quit");
51 expect(q.value, equals("quit")); 51 expect(q.value, equals("quit"));
52 52
53 await echoProxy.close(); 53 await echoProxy.close();
54 }); 54 });
55 55
56 test('Delayed Success', () async { 56 test('Delayed Success', () async {
57 var echoProxy = 57 var echoProxy =
58 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 58 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
59 59
60 var milliseconds = 100; 60 var milliseconds = 100;
61 var watch = new Stopwatch()..start(); 61 var watch = new Stopwatch()..start();
62 var v = await echoProxy.ptr.delayedEchoString("foo", milliseconds); 62 var v = await echoProxy.delayedEchoString("foo", milliseconds);
63 var elapsed = watch.elapsedMilliseconds; 63 var elapsed = watch.elapsedMilliseconds;
64 expect(v.value, equals("foo")); 64 expect(v.value, equals("foo"));
65 expect(elapsed, greaterThanOrEqualTo(milliseconds)); 65 expect(elapsed, greaterThanOrEqualTo(milliseconds));
66 66
67 var q = await echoProxy.ptr.echoString("quit"); 67 var q = await echoProxy.echoString("quit");
68 expect(q.value, equals("quit")); 68 expect(q.value, equals("quit"));
69 69
70 await echoProxy.close(); 70 await echoProxy.close();
71 }); 71 });
72 72
73 test('Delayed Close', () { 73 test('Delayed Close', () {
74 var echoProxy = 74 var echoProxy =
75 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 75 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
76 76
77 var milliseconds = 100; 77 var milliseconds = 100;
78 echoProxy.responseOrError(echoProxy.ptr.delayedEchoString( 78 echoProxy.responseOrError(echoProxy.delayedEchoString(
79 "quit", milliseconds)).then((result) { 79 "quit", milliseconds)).then((result) {
80 fail('This future should not complete.'); 80 fail('This future should not complete.');
81 }, onError: (e) { 81 }, onError: (e) {
82 expect(e is ProxyError, isTrue); 82 expect(e is ProxyError, isTrue);
83 }); 83 });
84 84
85 return new Future.delayed( 85 return new Future.delayed(
86 new Duration(milliseconds: 10), () => echoProxy.close()); 86 new Duration(milliseconds: 10), () => echoProxy.close());
87 }); 87 });
88 88
89 test('Swap', () async { 89 test('Swap', () async {
90 var echoProxy = 90 var echoProxy =
91 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 91 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
92 92
93 for (int i = 0; i < 10; i++) { 93 for (int i = 0; i < 10; i++) {
94 var v = 94 var v =
95 await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 95 await echoProxy.responseOrError(echoProxy.echoString("foo"));
96 expect(v.value, equals("foo")); 96 expect(v.value, equals("foo"));
97 } 97 }
98 98
99 echoProxy.impl.errorFuture.then((e) { 99 echoProxy.ctrl.errorFuture.then((e) {
100 fail("echoProxy: $e"); 100 fail("echoProxy: $e");
101 }); 101 });
102 102
103 // Trigger an implementation swap in the echo server. 103 // Trigger an implementation swap in the echo server.
104 echoProxy.ptr.swap(); 104 echoProxy.swap();
105 105
106 expect(echoProxy.impl.isBound, isTrue); 106 expect(echoProxy.ctrl.isBound, isTrue);
107 107
108 for (int i = 0; i < 10; i++) { 108 for (int i = 0; i < 10; i++) {
109 var v = 109 var v =
110 await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 110 await echoProxy.responseOrError(echoProxy.echoString("foo"));
111 expect(v.value, equals("foo")); 111 expect(v.value, equals("foo"));
112 } 112 }
113 113
114 var q = await echoProxy.responseOrError(echoProxy.ptr.echoString("quit")); 114 var q = await echoProxy.responseOrError(echoProxy.echoString("quit"));
115 expect(q.value, equals("quit")); 115 expect(q.value, equals("quit"));
116 116
117 await echoProxy.close(); 117 await echoProxy.close();
118 }); 118 });
119 119
120 test('Multiple Error Checks Success', () { 120 test('Multiple Error Checks Success', () {
121 var echoProxy = 121 var echoProxy =
122 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 122 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
123 123
124 List<Future> futures = []; 124 List<Future> futures = [];
125 for (int i = 0; i < 100; i++) { 125 for (int i = 0; i < 100; i++) {
126 var f = echoProxy.responseOrError(echoProxy.ptr.echoString("foo")) 126 var f = echoProxy.responseOrError(echoProxy.echoString("foo"))
127 .then((r) { 127 .then((r) {
128 expect(r.value, equals("foo")); 128 expect(r.value, equals("foo"));
129 }, onError: (e) { 129 }, onError: (e) {
130 fail('There should be no errors'); 130 fail('There should be no errors');
131 }); 131 });
132 futures.add(f); 132 futures.add(f);
133 } 133 }
134 return Future.wait(futures).whenComplete(() => echoProxy.close()); 134 return Future.wait(futures).whenComplete(() => echoProxy.close());
135 }); 135 });
136 136
137 test('Multiple Error Checks Fail', () { 137 test('Multiple Error Checks Fail', () {
138 var echoProxy = 138 var echoProxy =
139 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 139 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
140 140
141 List<Future> futures = []; 141 List<Future> futures = [];
142 var milliseconds = 100; 142 var milliseconds = 100;
143 for (int i = 0; i < 100; i++) { 143 for (int i = 0; i < 100; i++) {
144 var f = echoProxy.responseOrError( 144 var f = echoProxy.responseOrError(
145 echoProxy.ptr.delayedEchoString("foo", milliseconds)).then((_) { 145 echoProxy.delayedEchoString("foo", milliseconds)).then((_) {
146 fail('This call should fail'); 146 fail('This call should fail');
147 }, onError: (e) { 147 }, onError: (e) {
148 expect(e is ProxyError, isTrue); 148 expect(e is ProxyError, isTrue);
149 }); 149 });
150 futures.add(f); 150 futures.add(f);
151 } 151 }
152 return echoProxy.close().then((_) => Future.wait(futures)); 152 return echoProxy.close().then((_) => Future.wait(futures));
153 }); 153 });
154 154
155 test('Uncaught Call Closed', () async { 155 test('Uncaught Call Closed', () async {
156 var echoProxy = 156 var echoProxy =
157 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 157 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
158 158
159 // Do a normal call. 159 // Do a normal call.
160 var v = await echoProxy.ptr.echoString("foo"); 160 var v = await echoProxy.echoString("foo");
161 expect(v.value, equals("foo")); 161 expect(v.value, equals("foo"));
162 162
163 // Close the proxy. 163 // Close the proxy.
164 await echoProxy.close(); 164 await echoProxy.close();
165 165
166 // Try to do another call, which should not return. 166 // Try to do another call, which should not return.
167 echoProxy.ptr.echoString("foo").then((_) { 167 echoProxy.echoString("foo").then((_) {
168 fail('This should be unreachable'); 168 fail('This should be unreachable');
169 }); 169 });
170 }); 170 });
171 171
172 test('Catch Call Closed', () async { 172 test('Catch Call Closed', () async {
173 var echoProxy = 173 var echoProxy =
174 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 174 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
175 175
176 // Do a normal call. 176 // Do a normal call.
177 var v = await echoProxy.ptr.echoString("foo"); 177 var v = await echoProxy.echoString("foo");
178 expect(v.value, equals("foo")); 178 expect(v.value, equals("foo"));
179 179
180 // Close the proxy. 180 // Close the proxy.
181 await echoProxy.close(); 181 await echoProxy.close();
182 182
183 // Try to do another call, which should fail. 183 // Try to do another call, which should fail.
184 bool caughtException = false; 184 bool caughtException = false;
185 try { 185 try {
186 v = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 186 v = await echoProxy.responseOrError(echoProxy.echoString("foo"));
187 fail('This should be unreachable'); 187 fail('This should be unreachable');
188 } on ProxyError catch (e) { 188 } on ProxyError catch (e) {
189 caughtException = true; 189 caughtException = true;
190 } 190 }
191 expect(caughtException, isTrue); 191 expect(caughtException, isTrue);
192 }); 192 });
193 193
194 test('Catch Call Sequence Closed Twice', () async { 194 test('Catch Call Sequence Closed Twice', () async {
195 var echoProxy = 195 var echoProxy =
196 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 196 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
197 197
198 // Do a normal call. 198 // Do a normal call.
199 var v = await echoProxy.ptr.echoString("foo"); 199 var v = await echoProxy.echoString("foo");
200 expect(v.value, equals("foo")); 200 expect(v.value, equals("foo"));
201 201
202 // Close the proxy. 202 // Close the proxy.
203 await echoProxy.close(); 203 await echoProxy.close();
204 204
205 // Try to do another call, which should fail. 205 // Try to do another call, which should fail.
206 bool caughtException = false; 206 bool caughtException = false;
207 try { 207 try {
208 v = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 208 v = await echoProxy.responseOrError(echoProxy.echoString("foo"));
209 fail('This should be unreachable'); 209 fail('This should be unreachable');
210 } on ProxyError catch (e) { 210 } on ProxyError catch (e) {
211 caughtException = true; 211 caughtException = true;
212 } 212 }
213 expect(caughtException, isTrue); 213 expect(caughtException, isTrue);
214 214
215 // Make sure we can catch an error more than once. 215 // Make sure we can catch an error more than once.
216 caughtException = false; 216 caughtException = false;
217 try { 217 try {
218 v = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 218 v = await echoProxy.responseOrError(echoProxy.echoString("foo"));
219 fail('This should be unreachable'); 219 fail('This should be unreachable');
220 } on ProxyError catch (e) { 220 } on ProxyError catch (e) {
221 caughtException = true; 221 caughtException = true;
222 } 222 }
223 expect(caughtException, isTrue); 223 expect(caughtException, isTrue);
224 }); 224 });
225 225
226 test('Catch Call Parallel Closed Twice', () async { 226 test('Catch Call Parallel Closed Twice', () async {
227 var echoProxy = 227 var echoProxy =
228 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 228 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
229 229
230 // Do a normal call. 230 // Do a normal call.
231 var v = await echoProxy.ptr.echoString("foo"); 231 var v = await echoProxy.echoString("foo");
232 expect(v.value, equals("foo")); 232 expect(v.value, equals("foo"));
233 233
234 // Close the proxy. 234 // Close the proxy.
235 await echoProxy.close(); 235 await echoProxy.close();
236 236
237 // Queue up two calls after the close, and make sure they both fail. 237 // Queue up two calls after the close, and make sure they both fail.
238 var f1 = echoProxy.responseOrError(echoProxy.ptr.echoString("foo")) 238 var f1 = echoProxy.responseOrError(echoProxy.echoString("foo"))
239 .then((_) { 239 .then((_) {
240 fail('This should be unreachable'); 240 fail('This should be unreachable');
241 }, onError: (e) { 241 }, onError: (e) {
242 expect(e is ProxyError, isTrue); 242 expect(e is ProxyError, isTrue);
243 }); 243 });
244 244
245 var f2 = echoProxy.responseOrError(echoProxy.ptr.echoString("foo")) 245 var f2 = echoProxy.responseOrError(echoProxy.echoString("foo"))
246 .then((_) { 246 .then((_) {
247 fail('This should be unreachable'); 247 fail('This should be unreachable');
248 }, onError: (e) { 248 }, onError: (e) {
249 expect(e is ProxyError, isTrue); 249 expect(e is ProxyError, isTrue);
250 }); 250 });
251 251
252 return Future.wait([f1, f2]); 252 return Future.wait([f1, f2]);
253 }); 253 });
254 254
255 test('Unbind, close', () async { 255 test('Unbind, close', () async {
256 var echoProxy = 256 var echoProxy =
257 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 257 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
258 258
259 var r = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 259 var r = await echoProxy.responseOrError(echoProxy.echoString("foo"));
260 expect(r.value, equals("foo")); 260 expect(r.value, equals("foo"));
261 261
262 var endpoint = echoProxy.impl.unbind(); 262 var endpoint = echoProxy.ctrl.unbind();
263 await echoProxy.close(); 263 await echoProxy.close();
264 endpoint.close(); 264 endpoint.close();
265 }); 265 });
266 266
267 test('Unbind, rebind to same', () async { 267 test('Unbind, rebind to same', () async {
268 var echoProxy = 268 var echoProxy =
269 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 269 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
270 270
271 var r = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 271 var r = await echoProxy.responseOrError(echoProxy.echoString("foo"));
272 expect(r.value, equals("foo")); 272 expect(r.value, equals("foo"));
273 273
274 var endpoint = echoProxy.impl.unbind(); 274 var endpoint = echoProxy.ctrl.unbind();
275 echoProxy.impl.bind(endpoint); 275 echoProxy.ctrl.bind(endpoint);
276 276
277 r = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 277 r = await echoProxy.responseOrError(echoProxy.echoString("foo"));
278 expect(r.value, equals("foo")); 278 expect(r.value, equals("foo"));
279 279
280 await echoProxy.close(); 280 await echoProxy.close();
281 }); 281 });
282 282
283 test('Unbind, rebind to different', () async { 283 test('Unbind, rebind to different', () async {
284 var echoProxy = 284 var echoProxy =
285 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 285 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
286 286
287 var r = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 287 var r = await echoProxy.responseOrError(echoProxy.echoString("foo"));
288 expect(r.value, equals("foo")); 288 expect(r.value, equals("foo"));
289 289
290 var endpoint = echoProxy.impl.unbind(); 290 var endpoint = echoProxy.ctrl.unbind();
291 var differentEchoProxy = new EchoServiceProxy.fromEndpoint(endpoint); 291 var differentEchoProxy = new EchoServiceProxy.fromEndpoint(endpoint);
292 292
293 r = await differentEchoProxy.responseOrError( 293 r = await differentEchoProxy.responseOrError(
294 differentEchoProxy.ptr.echoString("foo")); 294 differentEchoProxy.echoString("foo"));
295 expect(r.value, equals("foo")); 295 expect(r.value, equals("foo"));
296 296
297 await differentEchoProxy.close(); 297 await differentEchoProxy.close();
298 }); 298 });
299 299
300 test('Unbind, rebind to different, close original', () async { 300 test('Unbind, rebind to different, close original', () async {
301 var echoProxy = 301 var echoProxy =
302 new EchoServiceProxy.connectToService(application, "mojo:dart_echo"); 302 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
303 303
304 var r = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo")); 304 var r = await echoProxy.responseOrError(echoProxy.echoString("foo"));
305 expect(r.value, equals("foo")); 305 expect(r.value, equals("foo"));
306 306
307 var endpoint = echoProxy.impl.unbind(); 307 var endpoint = echoProxy.ctrl.unbind();
308 var differentEchoProxy = new EchoServiceProxy.fromEndpoint(endpoint); 308 var differentEchoProxy = new EchoServiceProxy.fromEndpoint(endpoint);
309 await echoProxy.close(); 309 await echoProxy.close();
310 310
311 r = await differentEchoProxy.responseOrError( 311 r = await differentEchoProxy.responseOrError(
312 differentEchoProxy.ptr.echoString("foo")); 312 differentEchoProxy.echoString("foo"));
313 expect(r.value, equals("foo")); 313 expect(r.value, equals("foo"));
314 314
315 await differentEchoProxy.close(); 315 await differentEchoProxy.close();
316 }); 316 });
317 }); 317 });
318 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698