| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 library pingpong_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_for_test_only/test/pingpong_service.mojom.dart'; | |
| 14 | |
| 15 class _TestingPingPongClient extends PingPongClient { | |
| 16 final PingPongClientStub stub; | |
| 17 Completer _completer; | |
| 18 | |
| 19 _TestingPingPongClient.unbound() : stub = new PingPongClientStub.unbound() { | |
| 20 stub.impl = this; | |
| 21 } | |
| 22 | |
| 23 waitForPong() async { | |
| 24 _completer = new Completer(); | |
| 25 return _completer.future; | |
| 26 } | |
| 27 | |
| 28 void pong(int pongValue) { | |
| 29 _completer.complete(pongValue); | |
| 30 _completer = null; | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 pingpongApptests(Application application, String url) { | |
| 35 group('Ping-Pong Service Apptests', () { | |
| 36 // Verify that "pingpong.dart" implements the PingPongService interface | |
| 37 // and sends responses to our client. | |
| 38 test('Ping Service To Pong Client', () async { | |
| 39 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | |
| 40 application.connectToService( | |
| 41 "mojo:dart_pingpong", pingPongServiceProxy); | |
| 42 | |
| 43 var pingPongClient = new _TestingPingPongClient.unbound(); | |
| 44 pingPongServiceProxy.ptr.setClient(pingPongClient.stub); | |
| 45 | |
| 46 pingPongServiceProxy.ptr.ping(1); | |
| 47 var pongValue = await pingPongClient.waitForPong(); | |
| 48 expect(pongValue, equals(2)); | |
| 49 | |
| 50 pingPongServiceProxy.ptr.ping(100); | |
| 51 pongValue = await pingPongClient.waitForPong(); | |
| 52 expect(pongValue, equals(101)); | |
| 53 | |
| 54 await pingPongClient.stub.close(); | |
| 55 await pingPongServiceProxy.close(); | |
| 56 }); | |
| 57 | |
| 58 // Verify that "pingpong.dart" can connect to "pingpong_target.dart", act as | |
| 59 // its client, and return a Future that only resolves after the | |
| 60 // target.ping() => client.pong() methods have executed 9 times. | |
| 61 test('Ping Target URL', () async { | |
| 62 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | |
| 63 application.connectToService( | |
| 64 "mojo:dart_pingpong", pingPongServiceProxy); | |
| 65 | |
| 66 var r = await pingPongServiceProxy.ptr.pingTargetUrl( | |
| 67 "mojo:dart_pingpong_target", 9); | |
| 68 expect(r.ok, equals(true)); | |
| 69 | |
| 70 await pingPongServiceProxy.close(); | |
| 71 }); | |
| 72 | |
| 73 // Same as the previous test except that instead of providing the | |
| 74 // pingpong_target.dart URL, we provide a connection to its PingPongService. | |
| 75 test('Ping Target Service', () async { | |
| 76 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | |
| 77 application.connectToService( | |
| 78 "mojo:dart_pingpong", pingPongServiceProxy); | |
| 79 | |
| 80 var targetServiceProxy = new PingPongServiceProxy.unbound(); | |
| 81 application.connectToService( | |
| 82 "mojo:dart_pingpong_target", targetServiceProxy); | |
| 83 | |
| 84 var r = await pingPongServiceProxy.ptr.pingTargetService( | |
| 85 targetServiceProxy.impl, 9); | |
| 86 expect(r.ok, equals(true)); | |
| 87 // This side no longer has access to the pipe. | |
| 88 expect(targetServiceProxy.impl.isOpen, equals(false)); | |
| 89 expect(targetServiceProxy.impl.isBound, equals(false)); | |
| 90 | |
| 91 await pingPongServiceProxy.close(); | |
| 92 }); | |
| 93 | |
| 94 // Verify that Dart can implement an interface "request" parameter. | |
| 95 test('Get Target Service', () async { | |
| 96 var pingPongServiceProxy = new PingPongServiceProxy.unbound(); | |
| 97 application.connectToService( | |
| 98 "mojo:dart_pingpong", pingPongServiceProxy); | |
| 99 | |
| 100 var targetServiceProxy = new PingPongServiceProxy.unbound(); | |
| 101 pingPongServiceProxy.ptr.getPingPongService(targetServiceProxy); | |
| 102 | |
| 103 var pingPongClient = new _TestingPingPongClient.unbound(); | |
| 104 targetServiceProxy.ptr.setClient(pingPongClient.stub); | |
| 105 | |
| 106 targetServiceProxy.ptr.ping(1); | |
| 107 var pongValue = await pingPongClient.waitForPong(); | |
| 108 expect(pongValue, equals(2)); | |
| 109 | |
| 110 targetServiceProxy.ptr.ping(100); | |
| 111 pongValue = await pingPongClient.waitForPong(); | |
| 112 expect(pongValue, equals(101)); | |
| 113 | |
| 114 await pingPongClient.stub.close(); | |
| 115 await targetServiceProxy.close(); | |
| 116 await pingPongServiceProxy.close(); | |
| 117 }); | |
| 118 }); | |
| 119 } | |
| OLD | NEW |