Chromium Code Reviews| 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 = |
| 27 new service_describer.ServiceDescriberProxy.connectToService( | 27 new service_describer.ServiceDescriberProxy.connectToService( |
| 28 application, "mojo:dart_echo_with_service_describer"); | 28 application, "mojo:dart_pingpong"); |
| 29 | 29 |
| 30 var serviceDescriptionProxy = | 30 var serviceDescriptionProxy = |
| 31 new service_describer.ServiceDescriptionProxy.unbound(); | 31 new service_describer.ServiceDescriptionProxy.unbound(); |
| 32 await serviceDescriberProxy.ptr | 32 await serviceDescriberProxy.ptr |
|
zra
2016/03/03 16:52:36
What is the value being dropped here?
This should
rudominer
2016/03/03 22:46:14
Done (as modified by our discussion over hangouts.
| |
| 33 .describeService("test::EchoService", serviceDescriptionProxy); | 33 .describeService("test::PingPongService", serviceDescriptionProxy); |
| 34 | 34 |
| 35 expect(serviceDescriptionProxy.impl, isNotNull); | 35 expect(serviceDescriptionProxy.impl, isNotNull); |
| 36 expect(serviceDescriptionProxy.ptr, isNotNull); | 36 expect(serviceDescriptionProxy.ptr, isNotNull); |
| 37 | 37 |
| 38 // Compare the service description obtained by the service describer and | 38 // Compare the service description obtained by the service describer and |
| 39 // the expected description taken from the echo service import. | 39 // the expected description taken from the pingpong service import. |
| 40 var sd = serviceDescriptionProxy.ptr; | 40 var sd = serviceDescriptionProxy.ptr; |
|
zra
2016/03/03 16:52:36
Dart style is to use more descriptive variable nam
rudominer
2016/03/03 22:46:14
Done.
| |
| 41 var ed = echo_service.EchoServiceStub.serviceDescription; | 41 var ed = pingpong_service.PingPongServiceStub.serviceDescription; |
| 42 | 42 |
| 43 Function identity = (v) => v; | 43 Function identity = (v) => v; |
| 44 | 44 |
| 45 // Top-level Mojom Interfaces must match. | 45 // Top-level Mojom Interfaces must match. |
| 46 mojom_types.MojomInterface a = | 46 mojom_types.MojomInterface a = |
|
zra
2016/03/03 16:52:36
ditto
| |
| 47 (await sd.getTopLevelInterface()).mojomInterface; | 47 (await sd.getTopLevelInterface()).mojomInterface; |
| 48 mojom_types.MojomInterface b = ed.getTopLevelInterface(identity); | 48 mojom_types.MojomInterface b = ed.getTopLevelInterface(identity); |
|
zra
2016/03/03 16:52:37
ditto
| |
| 49 _compare(a, b); | 49 _compare(a, b); |
| 50 | 50 |
| 51 String interfaceID = "echo_service_EchoService__"; | 51 // Get the type key for the type of the first parameter of the |
| 52 mojom_types.MojomInterface c = | 52 // first method of the interface. |
| 53 (await sd.getTypeDefinition(interfaceID)).type.interfaceType; | 53 mojom_types.MojomMethod setClientMethod = a.methods[0]; |
| 54 mojom_types.MojomInterface d = | 54 mojom_types.StructField firstParam = setClientMethod.parameters.fields[0]; |
| 55 ed.getTypeDefinition(interfaceID, identity).interfaceType; | 55 String typeKey = firstParam.type.typeReference.typeKey; |
| 56 _compare(a, c); | 56 |
| 57 _compare(c, d); | 57 // Use getTypeDefinition() to get the type and check that it |
| 58 // is named "PingPongClient". | |
| 59 mojom_types.MojomInterface pingPongClientInterface = | |
| 60 (await sd.getTypeDefinition(typeKey)).type.interfaceType; | |
| 61 expect(pingPongClientInterface.declData.shortName, | |
| 62 equals("PingPongClient")); | |
| 58 | 63 |
| 59 // Check that the mojom type definitions match between mappings. | 64 // Check that the mojom type definitions match between mappings. |
| 60 // For simplicity, check in a shallow manner. | 65 // For simplicity, check in a shallow manner. |
| 61 var actualDescriptions = (await sd.getAllTypeDefinitions()).definitions; | 66 var actualDescriptions = (await sd.getAllTypeDefinitions()).definitions; |
| 62 var expectedDescriptions = ed.getAllTypeDefinitions(identity); | 67 var expectedDescriptions = ed.getAllTypeDefinitions(identity); |
| 63 actualDescriptions.keys.forEach((String key) { | 68 actualDescriptions.keys.forEach((String key) { |
| 64 var a = actualDescriptions[key]; | 69 var a = actualDescriptions[key]; |
| 65 var e = expectedDescriptions[key]; | 70 var e = expectedDescriptions[key]; |
| 66 expect(e, isNotNull); | 71 expect(e, isNotNull); |
| 67 expect(a.runtimeType, equals(e.runtimeType)); | 72 expect(a.runtimeType, equals(e.runtimeType)); |
| 68 }); | 73 }); |
| 69 | 74 |
| 70 await serviceDescriptionProxy.close(); | 75 await serviceDescriptionProxy.close(); |
| 71 await serviceDescriberProxy.close(); | 76 await serviceDescriberProxy.close(); |
| 77 | |
|
alexfandrianto
2016/03/03 02:26:23
optional: remove
rudominer
2016/03/03 22:46:14
Done.
| |
| 72 }); | 78 }); |
| 73 }); | 79 }); |
| 74 } | 80 } |
| 75 | 81 |
| 76 // Helper to compare two mojom interfaces for matches. | 82 // Helper to compare two mojom interfaces for matches. |
| 77 void _compare(mojom_types.MojomInterface a, mojom_types.MojomInterface b) { | 83 void _compare(mojom_types.MojomInterface a, mojom_types.MojomInterface b) { |
| 78 // Match the generated decl data. | 84 // Match the generated decl data. |
| 79 expect(a.declData, isNotNull); | 85 expect(a.declData, isNotNull); |
| 80 expect(b.declData, isNotNull); | 86 expect(b.declData, isNotNull); |
| 81 expect(a.declData.shortName, equals(b.declData.shortName)); | 87 expect(a.declData.shortName, equals(b.declData.shortName)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 98 expect(methodA.parameters.fields.length, | 104 expect(methodA.parameters.fields.length, |
| 99 equals(methodB.parameters.fields.length)); | 105 equals(methodB.parameters.fields.length)); |
| 100 mojom_types.MojomStruct responseA = methodA.responseParams; | 106 mojom_types.MojomStruct responseA = methodA.responseParams; |
| 101 mojom_types.MojomStruct responseB = methodB.responseParams; | 107 mojom_types.MojomStruct responseB = methodB.responseParams; |
| 102 expect(responseA == null, equals(responseB == null)); | 108 expect(responseA == null, equals(responseB == null)); |
| 103 if (responseA != null) { | 109 if (responseA != null) { |
| 104 expect(responseA.fields.length, equals(responseB.fields.length)); | 110 expect(responseA.fields.length, equals(responseB.fields.length)); |
| 105 } | 111 } |
| 106 }); | 112 }); |
| 107 } | 113 } |
| OLD | NEW |