OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 library service_describer_apptests; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:mojo_apptest/apptest.dart'; |
| 10 import 'package:mojo/application.dart'; |
| 11 import 'package:mojo/bindings.dart'; |
| 12 import 'package:mojo/core.dart'; |
| 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' |
| 15 as service_describer; |
| 16 import 'package:_mojo_for_test_only/test/echo_service.mojom.dart' |
| 17 as echo_service; |
| 18 |
| 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. |
| 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. |
| 23 tests(Application application, String url) { |
| 24 group('Service Describer Apptests', () { |
| 25 test('Echo Service Verification', () async { |
| 26 var serviceDescriberProxy = |
| 27 new service_describer.ServiceDescriberProxy.connectToService( |
| 28 application, "mojo:dart_echo_with_service_describer"); |
| 29 |
| 30 var serviceDescriptionProxy = |
| 31 new service_describer.ServiceDescriptionProxy.unbound(); |
| 32 await serviceDescriberProxy.ptr |
| 33 .describeService("test::EchoService", serviceDescriptionProxy); |
| 34 |
| 35 expect(serviceDescriptionProxy.impl, isNotNull); |
| 36 expect(serviceDescriptionProxy.ptr, isNotNull); |
| 37 |
| 38 // Compare the service description obtained by the service describer and |
| 39 // the expected description taken from the echo service import. |
| 40 var sd = serviceDescriptionProxy.ptr; |
| 41 var ed = echo_service.EchoServiceStub.serviceDescription; |
| 42 |
| 43 Function identity = (v) => v; |
| 44 |
| 45 // Top-level Mojom Interfaces must match. |
| 46 mojom_types.MojomInterface a = |
| 47 (await sd.getTopLevelInterface()).mojomInterface; |
| 48 mojom_types.MojomInterface b = ed.getTopLevelInterface(identity); |
| 49 _compare(a, b); |
| 50 |
| 51 String interfaceID = "echo_service_EchoService__"; |
| 52 mojom_types.MojomInterface c = |
| 53 (await sd.getTypeDefinition(interfaceID)).type.interfaceType; |
| 54 mojom_types.MojomInterface d = |
| 55 ed.getTypeDefinition(interfaceID, identity).interfaceType; |
| 56 _compare(a, c); |
| 57 _compare(c, d); |
| 58 |
| 59 // Check that the mojom type definitions match between mappings. |
| 60 // For simplicity, check in a shallow manner. |
| 61 var actualDescriptions = (await sd.getAllTypeDefinitions()).definitions; |
| 62 var expectedDescriptions = ed.getAllTypeDefinitions(identity); |
| 63 actualDescriptions.keys.forEach((String key) { |
| 64 var a = actualDescriptions[key]; |
| 65 var e = expectedDescriptions[key]; |
| 66 expect(e, isNotNull); |
| 67 expect(a.runtimeType, equals(e.runtimeType)); |
| 68 }); |
| 69 |
| 70 await serviceDescriptionProxy.close(); |
| 71 await serviceDescriberProxy.close(); |
| 72 }); |
| 73 }); |
| 74 } |
| 75 |
| 76 // Helper to compare two mojom interfaces for matches. |
| 77 void _compare(mojom_types.MojomInterface a, mojom_types.MojomInterface b) { |
| 78 // Match the generated decl data. |
| 79 expect(a.declData, isNotNull); |
| 80 expect(b.declData, isNotNull); |
| 81 expect(a.declData.shortName, equals(b.declData.shortName)); |
| 82 expect(a.declData.fullIdentifier, equals(b.declData.fullIdentifier)); |
| 83 |
| 84 // Verify that the number of methods matches the expected ones. |
| 85 expect(a.methods.length, equals(b.methods.length)); |
| 86 |
| 87 // Each MojomMethod must be named, typed, and "ordinal"ed the same way. |
| 88 a.methods.forEach((int ordinal, mojom_types.MojomMethod methodA) { |
| 89 mojom_types.MojomMethod methodB = b.methods[ordinal]; |
| 90 expect(methodB, isNotNull); |
| 91 |
| 92 // Compare declData. |
| 93 expect(methodA.declData, isNotNull); |
| 94 expect(methodB.declData, isNotNull); |
| 95 expect(methodA.declData.shortName, equals(methodB.declData.shortName)); |
| 96 |
| 97 // Lastly, compare parameters and responses (generally). |
| 98 expect(methodA.parameters.fields.length, |
| 99 equals(methodB.parameters.fields.length)); |
| 100 mojom_types.MojomStruct responseA = methodA.responseParams; |
| 101 mojom_types.MojomStruct responseB = methodB.responseParams; |
| 102 expect(responseA == null, equals(responseB == null)); |
| 103 if (responseA != null) { |
| 104 expect(responseA.fields.length, equals(responseB.fields.length)); |
| 105 } |
| 106 }); |
| 107 } |
OLD | NEW |