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 library pingpong_apptests; | 5 library pingpong_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'; |
(...skipping 19 matching lines...) Loading... |
30 _completer = null; | 30 _completer = null; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 pingpongApptests(Application application, String url) { | 34 pingpongApptests(Application application, String url) { |
35 group('Ping-Pong Service Apptests', () { | 35 group('Ping-Pong Service Apptests', () { |
36 // Verify that "pingpong.dart" implements the PingPongService interface | 36 // Verify that "pingpong.dart" implements the PingPongService interface |
37 // and sends responses to our client. | 37 // and sends responses to our client. |
38 test('Ping Service To Pong Client', () async { | 38 test('Ping Service To Pong Client', () async { |
39 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 39 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
40 pingPongServiceProxy.errorFuture.then((e) => fail('$e')); | 40 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
41 application.connectToService( | 41 application.connectToService( |
42 "mojo:dart_pingpong", pingPongServiceProxy); | 42 "mojo:dart_pingpong", pingPongServiceProxy); |
43 | 43 |
44 var pingPongClient = new _TestingPingPongClient.unbound(); | 44 var pingPongClient = new _TestingPingPongClient.unbound(); |
45 pingPongServiceProxy.ptr.setClient(pingPongClient.stub); | 45 pingPongServiceProxy.setClient(pingPongClient.stub); |
46 | 46 |
47 pingPongServiceProxy.ptr.ping(1); | 47 pingPongServiceProxy.ping(1); |
48 var pongValue = await pingPongClient.waitForPong(); | 48 var pongValue = await pingPongClient.waitForPong(); |
49 expect(pongValue, equals(2)); | 49 expect(pongValue, equals(2)); |
50 | 50 |
51 pingPongServiceProxy.ptr.ping(100); | 51 pingPongServiceProxy.ping(100); |
52 pongValue = await pingPongClient.waitForPong(); | 52 pongValue = await pingPongClient.waitForPong(); |
53 expect(pongValue, equals(101)); | 53 expect(pongValue, equals(101)); |
54 | 54 |
55 await pingPongClient.stub.close(); | 55 await pingPongClient.stub.close(); |
56 await pingPongServiceProxy.close(); | 56 await pingPongServiceProxy.close(); |
57 }); | 57 }); |
58 | 58 |
59 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as | 59 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as |
60 // its client, and return a Future that only resolves after the | 60 // its client, and return a Future that only resolves after the |
61 // target.ping() => client.pong() methods have executed 9 times. | 61 // target.ping() => client.pong() methods have executed 9 times. |
62 test('Ping Target URL', () async { | 62 test('Ping Target URL', () async { |
63 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 63 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
64 pingPongServiceProxy.errorFuture.then((e) => fail('$e')); | 64 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
65 application.connectToService( | 65 application.connectToService( |
66 "mojo:dart_pingpong", pingPongServiceProxy); | 66 "mojo:dart_pingpong", pingPongServiceProxy); |
67 | 67 |
68 var r = await pingPongServiceProxy.ptr.pingTargetUrl( | 68 var r = await pingPongServiceProxy.pingTargetUrl( |
69 "mojo:dart_pingpong_target", 9); | 69 "mojo:dart_pingpong_target", 9); |
70 expect(r.ok, equals(true)); | 70 expect(r.ok, equals(true)); |
71 | 71 |
72 await pingPongServiceProxy.close(); | 72 await pingPongServiceProxy.close(); |
73 }); | 73 }); |
74 | 74 |
75 // Same as the previous test except that instead of providing the | 75 // Same as the previous test except that instead of providing the |
76 // pingpong_target.dart URL, we provide a connection to its PingPongService. | 76 // pingpong_target.dart URL, we provide a connection to its PingPongService. |
77 test('Ping Target Service', () async { | 77 test('Ping Target Service', () async { |
78 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 78 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
79 pingPongServiceProxy.errorFuture.then((e) => fail('$e')); | 79 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
80 application.connectToService( | 80 application.connectToService( |
81 "mojo:dart_pingpong", pingPongServiceProxy); | 81 "mojo:dart_pingpong", pingPongServiceProxy); |
82 | 82 |
83 var targetServiceProxy = new PingPongServiceProxy.unbound(); | 83 var targetServiceProxy = new PingPongServiceProxy.unbound(); |
84 targetServiceProxy.errorFuture.then((e) => fail('$e')); | 84 targetServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
85 application.connectToService( | 85 application.connectToService( |
86 "mojo:dart_pingpong_target", targetServiceProxy); | 86 "mojo:dart_pingpong_target", targetServiceProxy); |
87 | 87 |
88 var r = await pingPongServiceProxy.ptr.pingTargetService( | 88 var r = await pingPongServiceProxy.pingTargetService( |
89 targetServiceProxy.impl, 9); | 89 targetServiceProxy, 9); |
90 expect(r.ok, equals(true)); | 90 expect(r.ok, equals(true)); |
91 // This side no longer has access to the pipe. | 91 // This side no longer has access to the pipe. |
92 expect(targetServiceProxy.impl.isOpen, equals(false)); | 92 expect(targetServiceProxy.ctrl.isOpen, equals(false)); |
93 expect(targetServiceProxy.impl.isBound, equals(false)); | 93 expect(targetServiceProxy.ctrl.isBound, equals(false)); |
94 | 94 |
95 await pingPongServiceProxy.close(); | 95 await pingPongServiceProxy.close(); |
96 }); | 96 }); |
97 | 97 |
98 // Verify that Dart can implement an interface "request" parameter. | 98 // Verify that Dart can implement an interface "request" parameter. |
99 test('Get Target Service', () async { | 99 test('Get Target Service', () async { |
100 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 100 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
101 pingPongServiceProxy.errorFuture.then((e) => fail('$e')); | 101 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
102 application.connectToService( | 102 application.connectToService( |
103 "mojo:dart_pingpong", pingPongServiceProxy); | 103 "mojo:dart_pingpong", pingPongServiceProxy); |
104 | 104 |
105 var targetServiceProxy = new PingPongServiceProxy.unbound(); | 105 var targetServiceProxy = new PingPongServiceProxy.unbound(); |
106 targetServiceProxy.errorFuture.then((e) => fail('$e')); | 106 targetServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
107 pingPongServiceProxy.ptr.getPingPongService(targetServiceProxy); | 107 pingPongServiceProxy.getPingPongService(targetServiceProxy); |
108 | 108 |
109 var pingPongClient = new _TestingPingPongClient.unbound(); | 109 var pingPongClient = new _TestingPingPongClient.unbound(); |
110 targetServiceProxy.ptr.setClient(pingPongClient.stub); | 110 targetServiceProxy.setClient(pingPongClient.stub); |
111 | 111 |
112 targetServiceProxy.ptr.ping(1); | 112 targetServiceProxy.ping(1); |
113 var pongValue = await pingPongClient.waitForPong(); | 113 var pongValue = await pingPongClient.waitForPong(); |
114 expect(pongValue, equals(2)); | 114 expect(pongValue, equals(2)); |
115 | 115 |
116 targetServiceProxy.ptr.ping(100); | 116 targetServiceProxy.ping(100); |
117 pongValue = await pingPongClient.waitForPong(); | 117 pongValue = await pingPongClient.waitForPong(); |
118 expect(pongValue, equals(101)); | 118 expect(pongValue, equals(101)); |
119 | 119 |
120 await pingPongClient.stub.close(); | 120 await pingPongClient.stub.close(); |
121 await targetServiceProxy.close(); | 121 await targetServiceProxy.close(); |
122 await pingPongServiceProxy.close(); | 122 await pingPongServiceProxy.close(); |
123 }); | 123 }); |
124 | 124 |
125 // Verify that Dart can implement an interface "request" parameter that | 125 // Verify that Dart can implement an interface "request" parameter that |
126 // isn't hooked up to an actual service implementation until after some | 126 // isn't hooked up to an actual service implementation until after some |
127 // delay. | 127 // delay. |
128 test('Get Target Service Delayed', () async { | 128 test('Get Target Service Delayed', () async { |
129 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | 129 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); |
130 pingPongServiceProxy.errorFuture.then((e) => fail('$e')); | 130 pingPongServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
131 application.connectToService( | 131 application.connectToService( |
132 "mojo:dart_pingpong", pingPongServiceProxy); | 132 "mojo:dart_pingpong", pingPongServiceProxy); |
133 | 133 |
134 var targetServiceProxy = new PingPongServiceProxy.unbound(); | 134 var targetServiceProxy = new PingPongServiceProxy.unbound(); |
135 targetServiceProxy.errorFuture.then((e) => fail('$e')); | 135 targetServiceProxy.ctrl.errorFuture.then((e) => fail('$e')); |
136 pingPongServiceProxy.ptr.getPingPongServiceDelayed(targetServiceProxy); | 136 pingPongServiceProxy.getPingPongServiceDelayed(targetServiceProxy); |
137 | 137 |
138 var pingPongClient = new _TestingPingPongClient.unbound(); | 138 var pingPongClient = new _TestingPingPongClient.unbound(); |
139 targetServiceProxy.ptr.setClient(pingPongClient.stub); | 139 targetServiceProxy.setClient(pingPongClient.stub); |
140 | 140 |
141 targetServiceProxy.ptr.ping(1); | 141 targetServiceProxy.ping(1); |
142 var pongValue = await pingPongClient.waitForPong(); | 142 var pongValue = await pingPongClient.waitForPong(); |
143 expect(pongValue, equals(2)); | 143 expect(pongValue, equals(2)); |
144 | 144 |
145 targetServiceProxy.ptr.ping(100); | 145 targetServiceProxy.ping(100); |
146 pongValue = await pingPongClient.waitForPong(); | 146 pongValue = await pingPongClient.waitForPong(); |
147 expect(pongValue, equals(101)); | 147 expect(pongValue, equals(101)); |
148 | 148 |
149 await pingPongClient.stub.close(); | 149 await pingPongClient.stub.close(); |
150 await targetServiceProxy.close(); | 150 await targetServiceProxy.close(); |
151 await pingPongServiceProxy.close(); | 151 await pingPongServiceProxy.close(); |
152 }); | 152 }); |
153 }); | 153 }); |
154 } | 154 } |
OLD | NEW |