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

Side by Side Diff: services/dart/dart_apptests/lib/src/echo_apptests.dart

Issue 1545483003: Dart: Reorganize files (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix build file Created 4 years, 12 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 library echo_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/echo_service.mojom.dart';
14
15 echoApptests(Application application, String url) {
16 group('Echo Service Apptests', () {
17 test('String', () async {
18 var echoProxy =
19 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
20
21 var v = await echoProxy.ptr.echoString("foo");
22 expect(v.value, equals("foo"));
23
24 var q = await echoProxy.ptr.echoString("quit");
25 expect(q.value, equals("quit"));
26
27 await echoProxy.close();
28 });
29
30 test('Empty String', () async {
31 var echoProxy =
32 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
33
34 var v = await echoProxy.ptr.echoString("");
35 expect(v.value, equals(""));
36
37 var q = await echoProxy.ptr.echoString("quit");
38 expect(q.value, equals("quit"));
39
40 await echoProxy.close();
41 });
42
43 test('Null String', () async {
44 var echoProxy =
45 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
46
47 var v = await echoProxy.ptr.echoString(null);
48 expect(v.value, equals(null));
49
50 var q = await echoProxy.ptr.echoString("quit");
51 expect(q.value, equals("quit"));
52
53 await echoProxy.close();
54 });
55
56 test('Delayed Success', () async {
57 var echoProxy =
58 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
59
60 var milliseconds = 100;
61 var watch = new Stopwatch()..start();
62 var v = await echoProxy.ptr.delayedEchoString("foo", milliseconds);
63 var elapsed = watch.elapsedMilliseconds;
64 expect(v.value, equals("foo"));
65 expect(elapsed, greaterThanOrEqualTo(milliseconds));
66
67 var q = await echoProxy.ptr.echoString("quit");
68 expect(q.value, equals("quit"));
69
70 await echoProxy.close();
71 });
72
73 test('Delayed Close', () {
74 var echoProxy =
75 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
76
77 var milliseconds = 100;
78 echoProxy.responseOrError(echoProxy.ptr.delayedEchoString(
79 "quit", milliseconds)).then((result) {
80 fail('This future should not complete.');
81 }, onError: (e) {
82 expect(e is ProxyError, isTrue);
83 });
84
85 return new Future.delayed(
86 new Duration(milliseconds: 10), () => echoProxy.close());
87 });
88
89 test('Multiple Error Checks Success', () {
90 var echoProxy =
91 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
92
93 List<Future> futures = [];
94 for (int i = 0; i < 100; i++) {
95 var f = echoProxy.responseOrError(echoProxy.ptr.echoString("foo"))
96 .then((r) {
97 expect(r.value, equals("foo"));
98 }, onError: (e) {
99 fail('There should be no errors');
100 });
101 futures.add(f);
102 }
103 return Future.wait(futures).whenComplete(() => echoProxy.close());
104 });
105
106 test('Multiple Error Checks Fail', () {
107 var echoProxy =
108 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
109
110 List<Future> futures = [];
111 var milliseconds = 100;
112 for (int i = 0; i < 100; i++) {
113 var f = echoProxy.responseOrError(
114 echoProxy.ptr.delayedEchoString("foo", milliseconds)).then((_) {
115 fail('This call should fail');
116 }, onError: (e) {
117 expect(e is ProxyError, isTrue);
118 });
119 futures.add(f);
120 }
121 return echoProxy.close().then((_) => Future.wait(futures));
122 });
123
124 test('Uncaught Call Closed', () async {
125 var echoProxy =
126 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
127
128 // Do a normal call.
129 var v = await echoProxy.ptr.echoString("foo");
130 expect(v.value, equals("foo"));
131
132 // Close the proxy.
133 await echoProxy.close();
134
135 // Try to do another call, which should not return.
136 echoProxy.ptr.echoString("foo").then((_) {
137 fail('This should be unreachable');
138 });
139 });
140
141 test('Catch Call Closed', () async {
142 var echoProxy =
143 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
144
145 // Do a normal call.
146 var v = await echoProxy.ptr.echoString("foo");
147 expect(v.value, equals("foo"));
148
149 // Close the proxy.
150 await echoProxy.close();
151
152 // Try to do another call, which should fail.
153 bool caughtException = false;
154 try {
155 v = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo"));
156 fail('This should be unreachable');
157 } on ProxyError catch (e) {
158 caughtException = true;
159 }
160 expect(caughtException, isTrue);
161 });
162
163 test('Catch Call Sequence Closed Twice', () async {
164 var echoProxy =
165 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
166
167 // Do a normal call.
168 var v = await echoProxy.ptr.echoString("foo");
169 expect(v.value, equals("foo"));
170
171 // Close the proxy.
172 await echoProxy.close();
173
174 // Try to do another call, which should fail.
175 bool caughtException = false;
176 try {
177 v = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo"));
178 fail('This should be unreachable');
179 } on ProxyError catch (e) {
180 caughtException = true;
181 }
182 expect(caughtException, isTrue);
183
184 // Make sure we can catch an error more than once.
185 caughtException = false;
186 try {
187 v = await echoProxy.responseOrError(echoProxy.ptr.echoString("foo"));
188 fail('This should be unreachable');
189 } on ProxyError catch (e) {
190 caughtException = true;
191 }
192 expect(caughtException, isTrue);
193 });
194
195 test('Catch Call Parallel Closed Twice', () async {
196 var echoProxy =
197 new EchoServiceProxy.connectToService(application, "mojo:dart_echo");
198
199 // Do a normal call.
200 var v = await echoProxy.ptr.echoString("foo");
201 expect(v.value, equals("foo"));
202
203 // Close the proxy.
204 await echoProxy.close();
205
206 // Queue up two calls after the close, and make sure they both fail.
207 var f1 = echoProxy.responseOrError(echoProxy.ptr.echoString("foo"))
208 .then((_) {
209 fail('This should be unreachable');
210 }, onError: (e) {
211 expect(e is ProxyError, isTrue);
212 });
213
214 var f2 = echoProxy.responseOrError(echoProxy.ptr.echoString("foo"))
215 .then((_) {
216 fail('This should be unreachable');
217 }, onError: (e) {
218 expect(e is ProxyError, isTrue);
219 });
220
221 return Future.wait([f1, f2]);
222 });
223 });
224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698