Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: services/dart/dart_apptests/pingpong_apptests.dart

Issue 971083002: Create an apptesting framework for dart. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Update upload_binaries.py to add the apptest.dartzip artifact. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 import 'dart:async';
6 import 'mojo:application';
7 import 'mojo:bindings';
8 import 'mojo:core';
9
10 import 'package:apptest/apptest.dart';
11 import 'package:services/dart/test/pingpong_service.mojom.dart';
12
13 class _TestingPingPongClient extends PingPongClient {
14 final PingPongClientStub stub;
15 Completer _completer;
16
17 _TestingPingPongClient.unbound() : stub = new PingPongClientStub.unbound() {
18 stub.delegate = this;
19 }
20
21 waitForPong() async {
22 _completer = new Completer();
23 return _completer.future;
24 }
25
26 void pong(int pongValue) {
27 _completer.complete(pongValue);
28 _completer = null;
29 }
30 }
31
32 pingpongApptests(Application application) {
33 group('Ping-Pong Service Apptests', () {
34 // Verify that "pingpong.dart" implements the PingPongService interface
35 // and sends responses to our client.
36 test('Ping Service To Pong Client', () async {
37 var pingPongServiceProxy = new PingPongServiceProxy.unbound();
38 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy);
39
40 var pingPongClient = new _TestingPingPongClient.unbound();
41 pingPongServiceProxy.ptr.setClient(pingPongClient.stub);
42 pingPongClient.stub.listen();
43
44 pingPongServiceProxy.ptr.ping(1);
45 var pongValue = await pingPongClient.waitForPong();
46 expect(pongValue, equals(2));
47
48 pingPongServiceProxy.ptr.ping(100);
49 pongValue = await pingPongClient.waitForPong();
50 expect(pongValue, equals(101));
51
52 pingPongClient.stub.close();
53 pingPongServiceProxy.close();
54 });
55
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
58 // target.ping() => client.pong() methods have executed 9 times.
59 test('Ping Target URL', () async {
60 var pingPongServiceProxy = new PingPongServiceProxy.unbound();
61 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy);
62
63 var r = await pingPongServiceProxy.ptr.pingTargetUrl(
64 "mojo:dart_pingpong_target", 9);
65 expect(r.ok, equals(true));
66
67 pingPongServiceProxy.close();
68 });
69
70 // Same as the previous test except that instead of providing the
71 // pingpong_target.dart URL, we provide a connection to its PingPongService.
72 test('Ping Target Service', () async {
73 var pingPongServiceProxy = new PingPongServiceProxy.unbound();
74 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy);
75
76 var targetServiceProxy = new PingPongServiceProxy.unbound();
77 application.connectToService(
78 "mojo:dart_pingpong_target",
79 targetServiceProxy);
80
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
83 // to another service. Uncomment this once this works.
84 //
85 // var r = await pingPongServiceProxy.ptr.pingTargetService(
86 // targetServiceProxy.impl, 9);
87 // expect(r.ok, equals(true));
88
89 targetServiceProxy.close();
90 pingPongServiceProxy.close();
91 });
92
93 // Verify that Dart can implement an interface "request" parameter.
94 test('Get Target Service', () async {
95 var pingPongServiceProxy = new PingPongServiceProxy.unbound();
96 application.connectToService("mojo:dart_pingpong", pingPongServiceProxy);
97
98 var targetServiceProxy = new PingPongServiceProxy.unbound();
99 pingPongServiceProxy.ptr.getPingPongService(targetServiceProxy);
100
101 var pingPongClient = new _TestingPingPongClient.unbound();
102 targetServiceProxy.ptr.setClient(pingPongClient.stub);
103 pingPongClient.stub.listen();
104
105 targetServiceProxy.ptr.ping(1);
106 var pongValue = await pingPongClient.waitForPong();
107 expect(pongValue, equals(2));
108
109 targetServiceProxy.ptr.ping(100);
110 pongValue = await pingPongClient.waitForPong();
111 expect(pongValue, equals(101));
112
113 pingPongClient.stub.close();
114 targetServiceProxy.close();
115 pingPongServiceProxy.close();
116 });
117 });
118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698