OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 service_describer_apptests; | 5 library service_describer_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/mojo/bindings/types/mojom_types.mojom.dart' as mojom_types; | 13 import 'package:mojo/mojo/bindings/types/mojom_types.mojom.dart' as mojom_types; |
14 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' | 14 import 'package:mojo/mojo/bindings/types/service_describer.mojom.dart' |
15 as service_describer; | 15 as service_describer; |
16 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart' | 16 import 'package:_mojo_for_test_only/test/pingpong_service.mojom.dart' |
17 as echo_service; | 17 as pingpong_service; |
18 | 18 |
19 // Tests that demonstrate that a service describer is able to obtain the same | 19 // Tests that demonstrate that a service describer is able to obtain the same |
20 // mojom type information present in a service's service description. | 20 // mojom type information present in a service's service description. |
21 // If the descriptions match, it means that you can see what services are | 21 // If the descriptions match, it means that you can see what services are |
22 // described by a mojo application without importing any of their mojom files. | 22 // described by a mojo application without importing any of their mojom files. |
23 tests(Application application, String url) { | 23 tests(Application application, String url) { |
24 group('Service Describer Apptests', () { | 24 group('Service Describer Apptests', () { |
25 test('Echo Service Verification', () async { | 25 test('PingPong Service Verification', () async { |
26 var serviceDescriberProxy = | 26 var serviceDescriberProxy = new service_describer.ServiceDescriberProxy. |
27 new service_describer.ServiceDescriberProxy.connectToService( | 27 unbound(); |
28 application, "mojo:dart_echo_with_service_describer"); | 28 serviceDescriberProxy.errorFuture.then((v) => |
| 29 fail('There was an error $v')); |
| 30 application.connectToService("mojo:dart_pingpong", serviceDescriberProxy); |
29 | 31 |
30 var serviceDescriptionProxy = | 32 var serviceDescriptionProxy = |
31 new service_describer.ServiceDescriptionProxy.unbound(); | 33 new service_describer.ServiceDescriptionProxy.unbound(); |
32 await serviceDescriberProxy.ptr | 34 serviceDescriptionProxy.errorFuture.then( |
33 .describeService("test::EchoService", serviceDescriptionProxy); | 35 (v) => fail('There was an error $v')); |
34 | 36 |
35 expect(serviceDescriptionProxy.impl, isNotNull); | 37 serviceDescriberProxy.ptr.describeService( |
36 expect(serviceDescriptionProxy.ptr, isNotNull); | 38 "test::PingPongService", serviceDescriptionProxy); |
37 | 39 |
38 // Compare the service description obtained by the service describer and | 40 // Compare the service description obtained by the service describer and |
39 // the expected description taken from the echo service import. | 41 // the expected description taken from the pingpong service import. |
40 var sd = serviceDescriptionProxy.ptr; | 42 var serviceDescription = serviceDescriptionProxy.ptr; |
41 var ed = echo_service.EchoServiceStub.serviceDescription; | 43 var serviceDescription2 = pingpong_service.PingPongServiceStub. |
| 44 serviceDescription; |
42 | 45 |
43 Function identity = (v) => v; | 46 Function identity = (v) => v; |
44 | 47 |
| 48 |
45 // Top-level Mojom Interfaces must match. | 49 // Top-level Mojom Interfaces must match. |
46 mojom_types.MojomInterface a = | 50 mojom_types.MojomInterface interfaceA = |
47 (await sd.getTopLevelInterface()).mojomInterface; | 51 (await serviceDescriptionProxy.responseOrError( |
48 mojom_types.MojomInterface b = ed.getTopLevelInterface(identity); | 52 serviceDescription.getTopLevelInterface())).mojomInterface; |
49 _compare(a, b); | |
50 | 53 |
51 String interfaceID = "echo_service_EchoService__"; | 54 mojom_types.MojomInterface interfaceB = serviceDescription2. |
52 mojom_types.MojomInterface c = | 55 getTopLevelInterface(identity); |
53 (await sd.getTypeDefinition(interfaceID)).type.interfaceType; | 56 _compare(interfaceA, interfaceB); |
54 mojom_types.MojomInterface d = | 57 |
55 ed.getTypeDefinition(interfaceID, identity).interfaceType; | 58 // Get the type key for the type of the first parameter of the |
56 _compare(a, c); | 59 // first method of the interface. |
57 _compare(c, d); | 60 mojom_types.MojomMethod setClientMethod = interfaceA.methods[0]; |
| 61 mojom_types.StructField firstParam = setClientMethod.parameters.fields[0]; |
| 62 String typeKey = firstParam.type.typeReference.typeKey; |
| 63 |
| 64 // Use getTypeDefinition() to get the type and check that it |
| 65 // is named "PingPongClient". |
| 66 mojom_types.MojomInterface pingPongClientInterface = |
| 67 (await serviceDescriptionProxy.responseOrError( |
| 68 serviceDescription.getTypeDefinition(typeKey))).type. |
| 69 interfaceType; |
| 70 expect(pingPongClientInterface.declData.shortName, |
| 71 equals("PingPongClient")); |
58 | 72 |
59 // Check that the mojom type definitions match between mappings. | 73 // Check that the mojom type definitions match between mappings. |
60 // For simplicity, check in a shallow manner. | 74 // For simplicity, check in a shallow manner. |
61 var actualDescriptions = (await sd.getAllTypeDefinitions()).definitions; | 75 var actualDescriptions = (await serviceDescriptionProxy.responseOrError( |
62 var expectedDescriptions = ed.getAllTypeDefinitions(identity); | 76 serviceDescription.getAllTypeDefinitions())).definitions; |
| 77 var expectedDescriptions = serviceDescription2. |
| 78 getAllTypeDefinitions(identity); |
63 actualDescriptions.keys.forEach((String key) { | 79 actualDescriptions.keys.forEach((String key) { |
64 var a = actualDescriptions[key]; | 80 var a = actualDescriptions[key]; |
65 var e = expectedDescriptions[key]; | 81 var e = expectedDescriptions[key]; |
66 expect(e, isNotNull); | 82 expect(e, isNotNull); |
67 expect(a.runtimeType, equals(e.runtimeType)); | 83 expect(a.runtimeType, equals(e.runtimeType)); |
68 }); | 84 }); |
69 | 85 |
70 await serviceDescriptionProxy.close(); | 86 await serviceDescriptionProxy.close(); |
71 await serviceDescriberProxy.close(); | 87 await serviceDescriberProxy.close(); |
72 }); | 88 }); |
(...skipping 25 matching lines...) Expand all Loading... |
98 expect(methodA.parameters.fields.length, | 114 expect(methodA.parameters.fields.length, |
99 equals(methodB.parameters.fields.length)); | 115 equals(methodB.parameters.fields.length)); |
100 mojom_types.MojomStruct responseA = methodA.responseParams; | 116 mojom_types.MojomStruct responseA = methodA.responseParams; |
101 mojom_types.MojomStruct responseB = methodB.responseParams; | 117 mojom_types.MojomStruct responseB = methodB.responseParams; |
102 expect(responseA == null, equals(responseB == null)); | 118 expect(responseA == null, equals(responseB == null)); |
103 if (responseA != null) { | 119 if (responseA != null) { |
104 expect(responseA.fields.length, equals(responseB.fields.length)); | 120 expect(responseA.fields.length, equals(responseB.fields.length)); |
105 } | 121 } |
106 }); | 122 }); |
107 } | 123 } |
OLD | NEW |