OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:mojo/bindings.dart' as bindings; | 10 import 'package:mojo/bindings.dart' as bindings; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { | 52 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { |
53 new ProviderImpl(endpoint); | 53 new ProviderImpl(endpoint); |
54 } | 54 } |
55 | 55 |
56 Future<bool> testCallResponse() { | 56 Future<bool> testCallResponse() { |
57 var pipe = new core.MojoMessagePipe(); | 57 var pipe = new core.MojoMessagePipe(); |
58 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); | 58 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
59 var c = new Completer(); | 59 var c = new Completer(); |
60 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { | 60 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { |
61 client.ptr.echoString("hello!").then((echoStringResponse) { | 61 client.echoString("hello!").then((echoStringResponse) { |
62 Expect.equals("hello!", echoStringResponse.a); | 62 Expect.equals("hello!", echoStringResponse.a); |
63 }).then((_) { | 63 }).then((_) { |
64 client.ptr.echoStrings("hello", "mojo!").then((echoStringsResponse) { | 64 client.echoStrings("hello", "mojo!").then((echoStringsResponse) { |
65 Expect.equals("hello", echoStringsResponse.a); | 65 Expect.equals("hello", echoStringsResponse.a); |
66 Expect.equals("mojo!", echoStringsResponse.b); | 66 Expect.equals("mojo!", echoStringsResponse.b); |
67 client.close().then((_) { | 67 client.close().then((_) { |
68 c.complete(true); | 68 c.complete(true); |
69 }); | 69 }); |
70 }); | 70 }); |
71 }); | 71 }); |
72 }); | 72 }); |
73 return c.future; | 73 return c.future; |
74 } | 74 } |
75 | 75 |
76 Future testAwaitCallResponse() async { | 76 Future testAwaitCallResponse() async { |
77 var pipe = new core.MojoMessagePipe(); | 77 var pipe = new core.MojoMessagePipe(); |
78 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); | 78 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
79 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); | 79 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); |
80 | 80 |
81 var echoStringResponse = await client.ptr.echoString("hello!"); | 81 var echoStringResponse = await client.echoString("hello!"); |
82 Expect.equals("hello!", echoStringResponse.a); | 82 Expect.equals("hello!", echoStringResponse.a); |
83 | 83 |
84 var echoStringsResponse = await client.ptr.echoStrings("hello", "mojo!"); | 84 var echoStringsResponse = await client.echoStrings("hello", "mojo!"); |
85 Expect.equals("hello", echoStringsResponse.a); | 85 Expect.equals("hello", echoStringsResponse.a); |
86 Expect.equals("mojo!", echoStringsResponse.b); | 86 Expect.equals("mojo!", echoStringsResponse.b); |
87 | 87 |
88 await client.close(); | 88 await client.close(); |
89 } | 89 } |
90 | 90 |
91 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => | 91 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => |
92 s.serializeWithHeader(new bindings.MessageHeader(0)); | 92 s.serializeWithHeader(new bindings.MessageHeader(0)); |
93 | 93 |
94 testSerializeNamedRegion() { | 94 testSerializeNamedRegion() { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 checkEnumCapsIsolate(core.MojoMessagePipeEndpoint endpoint) { | 276 checkEnumCapsIsolate(core.MojoMessagePipeEndpoint endpoint) { |
277 new CheckEnumCapsImpl(endpoint); | 277 new CheckEnumCapsImpl(endpoint); |
278 } | 278 } |
279 | 279 |
280 testCheckEnumCapsImpl() { | 280 testCheckEnumCapsImpl() { |
281 var pipe = new core.MojoMessagePipe(); | 281 var pipe = new core.MojoMessagePipe(); |
282 var client = | 282 var client = |
283 new regression.CheckEnumCapsProxy.fromEndpoint(pipe.endpoints[0]); | 283 new regression.CheckEnumCapsProxy.fromEndpoint(pipe.endpoints[0]); |
284 var c = new Completer(); | 284 var c = new Completer(); |
285 Isolate.spawn(checkEnumCapsIsolate, pipe.endpoints[1]).then((_) { | 285 Isolate.spawn(checkEnumCapsIsolate, pipe.endpoints[1]).then((_) { |
286 client.ptr.setEnumWithInternalAllCaps( | 286 client.setEnumWithInternalAllCaps( |
287 regression.EnumWithInternalAllCaps.standard); | 287 regression.EnumWithInternalAllCaps.standard); |
288 client.close().then((_) { | 288 client.close().then((_) { |
289 c.complete(null); | 289 c.complete(null); |
290 }); | 290 }); |
291 }); | 291 }); |
292 return c.future; | 292 return c.future; |
293 } | 293 } |
294 | 294 |
295 testSerializeEnum() { | 295 testSerializeEnum() { |
296 var constants = new structs.ScopedConstants(); | 296 var constants = new structs.ScopedConstants(); |
(...skipping 16 matching lines...) Expand all Loading... |
313 | 313 |
314 void closingProviderIsolate(core.MojoMessagePipeEndpoint endpoint) { | 314 void closingProviderIsolate(core.MojoMessagePipeEndpoint endpoint) { |
315 var provider = new ProviderImpl(endpoint); | 315 var provider = new ProviderImpl(endpoint); |
316 provider._stub.close(); | 316 provider._stub.close(); |
317 } | 317 } |
318 | 318 |
319 Future<bool> runOnClosedTest() { | 319 Future<bool> runOnClosedTest() { |
320 var testCompleter = new Completer(); | 320 var testCompleter = new Completer(); |
321 var pipe = new core.MojoMessagePipe(); | 321 var pipe = new core.MojoMessagePipe(); |
322 var proxy = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); | 322 var proxy = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
323 proxy.impl.onError = (_) => testCompleter.complete(true); | 323 proxy.ctrl.onError = (_) => testCompleter.complete(true); |
324 Isolate.spawn(closingProviderIsolate, pipe.endpoints[1]); | 324 Isolate.spawn(closingProviderIsolate, pipe.endpoints[1]); |
325 return testCompleter.future.then((b) { | 325 return testCompleter.future.then((b) { |
326 Expect.isTrue(b); | 326 Expect.isTrue(b); |
327 }); | 327 }); |
328 } | 328 } |
329 | 329 |
330 class Regression551Impl implements regression.Regression551 { | 330 class Regression551Impl implements regression.Regression551 { |
331 regression.Regression551Stub _stub; | 331 regression.Regression551Stub _stub; |
332 | 332 |
333 Regression551Impl(core.MojoMessagePipeEndpoint endpoint) { | 333 Regression551Impl(core.MojoMessagePipeEndpoint endpoint) { |
334 _stub = new regression.Regression551Stub.fromEndpoint(endpoint, this); | 334 _stub = new regression.Regression551Stub.fromEndpoint(endpoint, this); |
335 } | 335 } |
336 | 336 |
337 dynamic get(List<String> keyPrefixes, Function responseFactory) => | 337 dynamic get(List<String> keyPrefixes, Function responseFactory) => |
338 responseFactory(0); | 338 responseFactory(0); |
339 } | 339 } |
340 | 340 |
341 void regression551Isolate(core.MojoMessagePipeEndpoint endpoint) { | 341 void regression551Isolate(core.MojoMessagePipeEndpoint endpoint) { |
342 new Regression551Impl(endpoint); | 342 new Regression551Impl(endpoint); |
343 } | 343 } |
344 | 344 |
345 Future<bool> testRegression551() { | 345 Future<bool> testRegression551() { |
346 var pipe = new core.MojoMessagePipe(); | 346 var pipe = new core.MojoMessagePipe(); |
347 var client = new regression.Regression551Proxy.fromEndpoint(pipe.endpoints[0])
; | 347 var client = new regression.Regression551Proxy.fromEndpoint(pipe.endpoints[0])
; |
348 var c = new Completer(); | 348 var c = new Completer(); |
349 Isolate.spawn(regression551Isolate, pipe.endpoints[1]).then((_) { | 349 Isolate.spawn(regression551Isolate, pipe.endpoints[1]).then((_) { |
350 client.ptr.get(["hello!"]).then((response) { | 350 client.get(["hello!"]).then((response) { |
351 Expect.equals(0, response.result); | 351 Expect.equals(0, response.result); |
352 client.close().then((_) { | 352 client.close().then((_) { |
353 c.complete(true); | 353 c.complete(true); |
354 }); | 354 }); |
355 }); | 355 }); |
356 }); | 356 }); |
357 return c.future; | 357 return c.future; |
358 } | 358 } |
359 | 359 |
360 class ServiceNameImpl implements regression.ServiceName { | 360 class ServiceNameImpl implements regression.ServiceName { |
361 regression.ServiceNameStub _stub; | 361 regression.ServiceNameStub _stub; |
362 | 362 |
363 ServiceNameImpl(core.MojoMessagePipeEndpoint endpoint) { | 363 ServiceNameImpl(core.MojoMessagePipeEndpoint endpoint) { |
364 _stub = new regression.ServiceNameStub.fromEndpoint(endpoint, this); | 364 _stub = new regression.ServiceNameStub.fromEndpoint(endpoint, this); |
365 } | 365 } |
366 | 366 |
367 dynamic serviceName_(Function responseFactory) => | 367 dynamic serviceName_(Function responseFactory) => |
368 responseFactory(regression.ServiceName.serviceName); | 368 responseFactory(regression.ServiceName.serviceName); |
369 } | 369 } |
370 | 370 |
371 void serviceNameIsolate(core.MojoMessagePipeEndpoint endpoint) { | 371 void serviceNameIsolate(core.MojoMessagePipeEndpoint endpoint) { |
372 new ServiceNameImpl(endpoint); | 372 new ServiceNameImpl(endpoint); |
373 } | 373 } |
374 | 374 |
375 Future<bool> testServiceName() { | 375 Future<bool> testServiceName() { |
376 var pipe = new core.MojoMessagePipe(); | 376 var pipe = new core.MojoMessagePipe(); |
377 var client = new regression.ServiceNameProxy.fromEndpoint(pipe.endpoints[0]); | 377 var client = new regression.ServiceNameProxy.fromEndpoint(pipe.endpoints[0]); |
378 var c = new Completer(); | 378 var c = new Completer(); |
379 Isolate.spawn(serviceNameIsolate, pipe.endpoints[1]).then((_) { | 379 Isolate.spawn(serviceNameIsolate, pipe.endpoints[1]).then((_) { |
380 client.ptr.serviceName_().then((response) { | 380 client.serviceName_().then((response) { |
381 Expect.equals(ServiceName.serviceName, response.serviceName_); | 381 Expect.equals(ServiceName.serviceName, response.serviceName_); |
382 client.close().then((_) { | 382 client.close().then((_) { |
383 c.complete(true); | 383 c.complete(true); |
384 }); | 384 }); |
385 }); | 385 }); |
386 }); | 386 }); |
387 return c.future; | 387 return c.future; |
388 } | 388 } |
389 | 389 |
390 | 390 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 | 647 |
648 mojom_types.UserDefinedType udt = testValidationDescriptor[interfaceID]; | 648 mojom_types.UserDefinedType udt = testValidationDescriptor[interfaceID]; |
649 Expect.isNotNull(udt); | 649 Expect.isNotNull(udt); |
650 | 650 |
651 mojom_types.MojomInterface mi = udt.interfaceType; | 651 mojom_types.MojomInterface mi = udt.interfaceType; |
652 Expect.isNotNull(mi); | 652 Expect.isNotNull(mi); |
653 | 653 |
654 _checkMojomInterface(mi, shortName, fullIdentifier, methodMap); | 654 _checkMojomInterface(mi, shortName, fullIdentifier, methodMap); |
655 | 655 |
656 // The proxy and stub need to have a valid serviceDescription. | 656 // The proxy and stub need to have a valid serviceDescription. |
657 var boundsCheckProxyImpl = | 657 var boundsCheckProxyController = |
658 new validation.BoundsCheckTestInterfaceProxy.unbound().impl; | 658 new validation.BoundsCheckTestInterfaceProxy.unbound().ctrl; |
659 var boundsCheckStubDescription = | 659 var boundsCheckStubDescription = |
660 validation.BoundsCheckTestInterfaceStub.serviceDescription; | 660 validation.BoundsCheckTestInterfaceStub.serviceDescription; |
661 | 661 |
662 _checkServiceDescription( | 662 _checkServiceDescription( |
663 boundsCheckProxyImpl.serviceDescription, interfaceID, shortName, | 663 boundsCheckProxyController.serviceDescription, interfaceID, shortName, |
664 fullIdentifier, methodMap); | 664 fullIdentifier, methodMap); |
665 _checkServiceDescription( | 665 _checkServiceDescription( |
666 boundsCheckStubDescription, interfaceID, shortName, fullIdentifier, | 666 boundsCheckStubDescription, interfaceID, shortName, fullIdentifier, |
667 methodMap); | 667 methodMap); |
668 } | 668 } |
669 | 669 |
670 _checkServiceDescription(service_describer.ServiceDescription sd, | 670 _checkServiceDescription(service_describer.ServiceDescription sd, |
671 String interfaceID, String shortName, String fullIdentifier, | 671 String interfaceID, String shortName, String fullIdentifier, |
672 Map<int, String> methodMap) { | 672 Map<int, String> methodMap) { |
673 // Check the top level interface, which must pass _checkMojomInterface. | 673 // Check the top level interface, which must pass _checkMojomInterface. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 testValidateMojomTypes(); | 755 testValidateMojomTypes(); |
756 testCamelCase(); | 756 testCamelCase(); |
757 testSerializeErrorMessage(); | 757 testSerializeErrorMessage(); |
758 await testEnums(); | 758 await testEnums(); |
759 await testCallResponse(); | 759 await testCallResponse(); |
760 await testAwaitCallResponse(); | 760 await testAwaitCallResponse(); |
761 await runOnClosedTest(); | 761 await runOnClosedTest(); |
762 await testRegression551(); | 762 await testRegression551(); |
763 await testServiceName(); | 763 await testServiceName(); |
764 } | 764 } |
OLD | NEW |