OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'mojo:application'; | 6 import 'mojo:application'; |
7 import 'mojo:bindings'; | 7 import 'mojo:bindings'; |
8 import 'mojo:core'; | 8 import 'mojo:core'; |
9 | 9 |
10 import 'package:apptest/apptest.dart'; | 10 import 'package:apptest/apptest.dart'; |
(...skipping 15 matching lines...) Expand all Loading... |
26 void pong(int pongValue) { | 26 void pong(int pongValue) { |
27 _completer.complete(pongValue); | 27 _completer.complete(pongValue); |
28 _completer = null; | 28 _completer = null; |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 pingpongApptests(Application application) { | 32 pingpongApptests(Application application) { |
33 group('Ping-Pong Service Apptests', () { | 33 group('Ping-Pong Service Apptests', () { |
34 // Verify that "pingpong.dart" implements the PingPongService interface | 34 // Verify that "pingpong.dart" implements the PingPongService interface |
35 // and sends responses to our client. | 35 // and sends responses to our client. |
36 test('Ping Service To Pong Client', () { (() async { | 36 test('Ping Service To Pong Client', () async { |
37 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 37 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
38 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); | 38 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); |
39 | 39 |
40 var pingPongClient = new _TestingPingPongClient.unbound(); | 40 var pingPongClient = new _TestingPingPongClient.unbound(); |
41 pingPongServiceProxy.ptr.setClient(pingPongClient.stub); | 41 pingPongServiceProxy.ptr.setClient(pingPongClient.stub); |
42 pingPongClient.stub.listen(); | 42 pingPongClient.stub.listen(); |
43 | 43 |
44 pingPongServiceProxy.ptr.ping(1); | 44 pingPongServiceProxy.ptr.ping(1); |
45 var pongValue = await pingPongClient.waitForPong(); | 45 var pongValue = await pingPongClient.waitForPong(); |
46 expect(pongValue, equals(2)); | 46 expect(pongValue, equals(2)); |
47 | 47 |
48 pingPongServiceProxy.ptr.ping(100); | 48 pingPongServiceProxy.ptr.ping(100); |
49 pongValue = await pingPongClient.waitForPong(); | 49 pongValue = await pingPongClient.waitForPong(); |
50 expect(pongValue, equals(101)); | 50 expect(pongValue, equals(101)); |
51 | 51 |
52 pingPongClient.stub.close(); | 52 pingPongClient.stub.close(); |
53 pingPongServiceProxy.close(); | 53 pingPongServiceProxy.close(); |
54 })().then(expectAsync((_) => null));}); | 54 }); |
55 | 55 |
56 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as | 56 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as |
57 // its client, and return a Future that only resolves after the | 57 // its client, and return a Future that only resolves after the |
58 // target.ping() => client.pong() methods have executed 9 times. | 58 // target.ping() => client.pong() methods have executed 9 times. |
59 test('Ping Target URL', () { (() async { | 59 test('Ping Target URL', () async { |
60 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 60 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
61 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); | 61 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); |
62 | 62 |
63 var r = await pingPongServiceProxy.ptr.pingTargetUrl( | 63 var r = await pingPongServiceProxy.ptr.pingTargetUrl( |
64 "mojo:dart_pingpong_target", 9); | 64 "mojo:dart_pingpong_target", 9); |
65 expect(r.ok, equals(true)); | 65 expect(r.ok, equals(true)); |
66 | 66 |
67 pingPongServiceProxy.close(); | 67 pingPongServiceProxy.close(); |
68 })().then(expectAsync((_) => null));}); | 68 }); |
69 | 69 |
70 // Same as the previous test except that instead of providing the | 70 // Same as the previous test except that instead of providing the |
71 // pingpong_target.dart URL, we provide a connection to its PingPongService. | 71 // pingpong_target.dart URL, we provide a connection to its PingPongService. |
72 test('Ping Target Service', () { (() async { | 72 test('Ping Target Service', () async { |
73 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 73 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
74 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); | 74 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); |
75 | 75 |
76 var targetServiceProxy = new PingPongServiceProxy.unbound(); | 76 var targetServiceProxy = new PingPongServiceProxy.unbound(); |
77 application.connectToService( | 77 application.connectToService( |
78 "mojo:dart_pingpong_target", | 78 "mojo:dart_pingpong_target", |
79 targetServiceProxy); | 79 targetServiceProxy); |
80 | 80 |
81 // TODO(erg): The dart bindings can't currently pass a proxy that we've | 81 // TODO(erg): The dart bindings can't currently pass a proxy that we've |
82 // received from another service and pass it it as a parameter to a call | 82 // received from another service and pass it it as a parameter to a call |
83 // to another service. Uncomment this once this works. | 83 // to another service. Uncomment this once this works. |
84 // | 84 // |
85 // var r = await pingPongServiceProxy.ptr.pingTargetService( | 85 // var r = await pingPongServiceProxy.ptr.pingTargetService( |
86 // targetServiceProxy.impl, 9); | 86 // targetServiceProxy.impl, 9); |
87 // expect(r.ok, equals(true)); | 87 // expect(r.ok, equals(true)); |
88 | 88 |
89 targetServiceProxy.close(); | 89 targetServiceProxy.close(); |
90 pingPongServiceProxy.close(); | 90 pingPongServiceProxy.close(); |
91 })().then(expectAsync((_) => null));}); | 91 }); |
92 | 92 |
93 // Verify that Dart can implement an interface "request" parameter. | 93 // Verify that Dart can implement an interface "request" parameter. |
94 test('Get Target Service', () { (() async { | 94 test('Get Target Service', () async { |
95 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 95 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
96 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); | 96 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy); |
97 | 97 |
98 var targetServiceProxy = new PingPongServiceProxy.unbound(); | 98 var targetServiceProxy = new PingPongServiceProxy.unbound(); |
99 pingPongServiceProxy.ptr.getPingPongService(targetServiceProxy); | 99 pingPongServiceProxy.ptr.getPingPongService(targetServiceProxy); |
100 | 100 |
101 var pingPongClient = new _TestingPingPongClient.unbound(); | 101 var pingPongClient = new _TestingPingPongClient.unbound(); |
102 targetServiceProxy.ptr.setClient(pingPongClient.stub); | 102 targetServiceProxy.ptr.setClient(pingPongClient.stub); |
103 pingPongClient.stub.listen(); | 103 pingPongClient.stub.listen(); |
104 | 104 |
105 targetServiceProxy.ptr.ping(1); | 105 targetServiceProxy.ptr.ping(1); |
106 var pongValue = await pingPongClient.waitForPong(); | 106 var pongValue = await pingPongClient.waitForPong(); |
107 expect(pongValue, equals(2)); | 107 expect(pongValue, equals(2)); |
108 | 108 |
109 targetServiceProxy.ptr.ping(100); | 109 targetServiceProxy.ptr.ping(100); |
110 pongValue = await pingPongClient.waitForPong(); | 110 pongValue = await pingPongClient.waitForPong(); |
111 expect(pongValue, equals(101)); | 111 expect(pongValue, equals(101)); |
112 | 112 |
113 pingPongClient.stub.close(); | 113 pingPongClient.stub.close(); |
114 targetServiceProxy.close(); | 114 targetServiceProxy.close(); |
115 pingPongServiceProxy.close(); | 115 pingPongServiceProxy.close(); |
116 })().then(expectAsync((_) => null));}); | 116 }); |
117 }); | 117 }); |
118 } | 118 } |
OLD | NEW |