| Index: mojo/dart/apptests/dart_apptests/lib/src/echo_apptests.dart
|
| diff --git a/mojo/dart/apptests/dart_apptests/lib/src/echo_apptests.dart b/mojo/dart/apptests/dart_apptests/lib/src/echo_apptests.dart
|
| index 65b5a8b683a5415f20bab6cd37c4ed960549e811..c7e13c934ecadfeb446bee7f3ad95e033bab836b 100644
|
| --- a/mojo/dart/apptests/dart_apptests/lib/src/echo_apptests.dart
|
| +++ b/mojo/dart/apptests/dart_apptests/lib/src/echo_apptests.dart
|
| @@ -17,11 +17,22 @@ echoApptests(Application application, String url) {
|
| test('String', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var v = await echo.echoString("foo");
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| - var q = await echo.echoString("quit");
|
| - expect(q.value, equals("quit"));
|
| + c = new Completer();
|
| + echo.echoString("quit", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + }
|
|
|
| await echo.close();
|
| });
|
| @@ -29,11 +40,22 @@ echoApptests(Application application, String url) {
|
| test('Empty String', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var v = await echo.echoString("");
|
| - expect(v.value, equals(""));
|
| + var c = new Completer();
|
| + echo.echoString("", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals(""));
|
|
|
| - var q = await echo.echoString("quit");
|
| - expect(q.value, equals("quit"));
|
| + c = new Completer();
|
| + echo.echoString("quit", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + }
|
|
|
| await echo.close();
|
| });
|
| @@ -41,11 +63,22 @@ echoApptests(Application application, String url) {
|
| test('Null String', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var v = await echo.echoString(null);
|
| - expect(v.value, equals(null));
|
| + var c = new Completer();
|
| + echo.echoString(null, (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals(null));
|
|
|
| - var q = await echo.echoString("quit");
|
| - expect(q.value, equals("quit"));
|
| + c = new Completer();
|
| + echo.echoString("quit", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + }
|
|
|
| await echo.close();
|
| });
|
| @@ -55,27 +88,43 @@ echoApptests(Application application, String url) {
|
|
|
| var milliseconds = 100;
|
| var watch = new Stopwatch()..start();
|
| - var v = await echo.delayedEchoString("foo", milliseconds);
|
| - var elapsed = watch.elapsedMilliseconds;
|
| - expect(v.value, equals("foo"));
|
| - expect(elapsed, greaterThanOrEqualTo(milliseconds));
|
| + var c = new Completer();
|
| + echo.delayedEchoString("foo", milliseconds, (String value) {
|
| + var elapsed = watch.elapsedMilliseconds;
|
| + c.complete([value, elapsed]);
|
| + });
|
| + var result = await echo.responseOrError(c.future);
|
| + expect(result[0], equals("foo"));
|
| + expect(result[1], greaterThanOrEqualTo(milliseconds));
|
|
|
| - var q = await echo.echoString("quit");
|
| - expect(q.value, equals("quit"));
|
| + c = new Completer();
|
| + echo.echoString("quit", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + }
|
|
|
| await echo.close();
|
| });
|
|
|
| - test('Delayed Close', () {
|
| + test('Delayed Close', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| var milliseconds = 100;
|
| - echo.responseOrError(echo.delayedEchoString(
|
| - "quit", milliseconds)).then((result) {
|
| - fail('This future should not complete.');
|
| - }, onError: (e) {
|
| - expect(e is ProxyError, isTrue);
|
| + var c = new Completer();
|
| + echo.delayedEchoString("quit", milliseconds, (String value) {
|
| + fail("unreachable");
|
| });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + };
|
|
|
| return new Future.delayed(
|
| new Duration(milliseconds: 10), () => echo.close());
|
| @@ -85,8 +134,11 @@ echoApptests(Application application, String url) {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| for (int i = 0; i < 10; i++) {
|
| - var v = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
| }
|
|
|
| echo.ctrl.errorFuture.then((e) {
|
| @@ -99,13 +151,13 @@ echoApptests(Application application, String url) {
|
| expect(echo.ctrl.isBound, isTrue);
|
|
|
| for (int i = 0; i < 10; i++) {
|
| - var v = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
| }
|
|
|
| - var q = await echo.responseOrError(echo.echoString("quit"));
|
| - expect(q.value, equals("quit"));
|
| -
|
| await echo.close();
|
| });
|
|
|
| @@ -114,12 +166,11 @@ echoApptests(Application application, String url) {
|
|
|
| List<Future> futures = [];
|
| for (int i = 0; i < 100; i++) {
|
| - var f = echo.responseOrError(echo.echoString("foo")).then((r) {
|
| - expect(r.value, equals("foo"));
|
| - }, onError: (e) {
|
| - fail('There should be no errors');
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| });
|
| - futures.add(f);
|
| + futures.add(echo.responseOrError(c.future));
|
| }
|
| return Future.wait(futures).whenComplete(() => echo.close());
|
| });
|
| @@ -130,9 +181,12 @@ echoApptests(Application application, String url) {
|
| List<Future> futures = [];
|
| var milliseconds = 100;
|
| for (int i = 0; i < 100; i++) {
|
| - var f = echo.responseOrError(
|
| - echo.delayedEchoString("foo", milliseconds)).then((_) {
|
| - fail('This call should fail');
|
| + var c = new Completer();
|
| + echo.delayedEchoString("foo", milliseconds, (String value) {
|
| + fail("unreachable");
|
| + });
|
| + var f = echo.responseOrError(c.future).then((_) {
|
| + fail("unreachable");
|
| }, onError: (e) {
|
| expect(e is ProxyError, isTrue);
|
| });
|
| @@ -145,14 +199,17 @@ echoApptests(Application application, String url) {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| // Do a normal call.
|
| - var v = await echo.echoString("foo");
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| // Close the proxy.
|
| await echo.close();
|
|
|
| // Try to do another call, which should not return.
|
| - echo.echoString("foo").then((_) {
|
| + echo.echoString("foo", (_) {
|
| fail('This should be unreachable');
|
| });
|
| });
|
| @@ -161,16 +218,23 @@ echoApptests(Application application, String url) {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| // Do a normal call.
|
| - var v = await echo.echoString("foo");
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| // Close the proxy.
|
| await echo.close();
|
|
|
| // Try to do another call, which should fail.
|
| bool caughtException = false;
|
| + c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + fail("unreachable");
|
| + });
|
| try {
|
| - v = await echo.responseOrError(echo.echoString("foo"));
|
| + await echo.responseOrError(c.future);
|
| fail('This should be unreachable');
|
| } on ProxyError catch (e) {
|
| caughtException = true;
|
| @@ -182,26 +246,37 @@ echoApptests(Application application, String url) {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| // Do a normal call.
|
| - var v = await echo.echoString("foo");
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| // Close the proxy.
|
| await echo.close();
|
|
|
| // Try to do another call, which should fail.
|
| bool caughtException = false;
|
| + c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + fail("unreachable");
|
| + });
|
| try {
|
| - v = await echo.responseOrError(echo.echoString("foo"));
|
| + await echo.responseOrError(c.future);
|
| fail('This should be unreachable');
|
| } on ProxyError catch (e) {
|
| caughtException = true;
|
| }
|
| expect(caughtException, isTrue);
|
|
|
| - // Make sure we can catch an error more than once.
|
| + // Try to do another call, which should fail.
|
| caughtException = false;
|
| + c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + fail("unreachable");
|
| + });
|
| try {
|
| - v = await echo.responseOrError(echo.echoString("foo"));
|
| + await echo.responseOrError(c.future);
|
| fail('This should be unreachable');
|
| } on ProxyError catch (e) {
|
| caughtException = true;
|
| @@ -213,21 +288,31 @@ echoApptests(Application application, String url) {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| // Do a normal call.
|
| - var v = await echo.echoString("foo");
|
| - expect(v.value, equals("foo"));
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| // Close the proxy.
|
| await echo.close();
|
|
|
| // Queue up two calls after the close, and make sure they both fail.
|
| - var f1 = echo.responseOrError(echo.echoString("foo")).then((_) {
|
| - fail('This should be unreachable');
|
| + var c1 = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + var c2 = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + var f1 = echo.responseOrError(c1.future).then((_) {
|
| + fail("unreachable");
|
| }, onError: (e) {
|
| expect(e is ProxyError, isTrue);
|
| });
|
| -
|
| - var f2 = echo.responseOrError(echo.echoString("foo")).then((_) {
|
| - fail('This should be unreachable');
|
| + var f2 = echo.responseOrError(c2.future).then((_) {
|
| + fail("unreachable");
|
| }, onError: (e) {
|
| expect(e is ProxyError, isTrue);
|
| });
|
| @@ -235,28 +320,63 @@ echoApptests(Application application, String url) {
|
| return Future.wait([f1, f2]);
|
| });
|
|
|
| - test('Unbind, close', () async {
|
| + test('Unbind, Rebind, Close', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var r = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| var endpoint = echo.ctrl.unbind();
|
| + echo.ctrl.bind(endpoint);
|
| +
|
| + c = new Completer();
|
| + echo.echoString("quit", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + }
|
| +
|
| await echo.close();
|
| - endpoint.close();
|
| });
|
|
|
| test('Unbind, rebind to same', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var r = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| var endpoint = echo.ctrl.unbind();
|
| echo.ctrl.bind(endpoint);
|
|
|
| - r = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
| +
|
| + c = new Completer();
|
| + echo.echoString("quit", (String value) {
|
| + fail("unreachable");
|
| + });
|
| + try {
|
| + await echo.responseOrError(c.future);
|
| + fail("unreachable");
|
| + } catch (e) {
|
| + expect(e is ProxyError, isTrue);
|
| + }
|
|
|
| await echo.close();
|
| });
|
| @@ -264,15 +384,22 @@ echoApptests(Application application, String url) {
|
| test('Unbind, rebind to different', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var r = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| var endpoint = echo.ctrl.unbind();
|
| var differentEchoProxy = new EchoServiceProxy.fromEndpoint(endpoint);
|
|
|
| - r = await differentEchoProxy.responseOrError(
|
| - differentEchoProxy.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + c = new Completer();
|
| + differentEchoProxy.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await differentEchoProxy.responseOrError(c.future), equals("foo"));
|
|
|
| await differentEchoProxy.close();
|
| });
|
| @@ -280,16 +407,23 @@ echoApptests(Application application, String url) {
|
| test('Unbind, rebind to different, close original', () async {
|
| var echo = EchoService.connectToService(application, "mojo:dart_echo");
|
|
|
| - var r = await echo.responseOrError(echo.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + var c = new Completer();
|
| + echo.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await echo.responseOrError(c.future), equals("foo"));
|
|
|
| var endpoint = echo.ctrl.unbind();
|
| var differentEchoProxy = new EchoServiceProxy.fromEndpoint(endpoint);
|
| await echo.close();
|
|
|
| - r = await differentEchoProxy.responseOrError(
|
| - differentEchoProxy.echoString("foo"));
|
| - expect(r.value, equals("foo"));
|
| + // Do a normal call.
|
| + c = new Completer();
|
| + differentEchoProxy.echoString("foo", (String value) {
|
| + c.complete(value);
|
| + });
|
| + expect(await differentEchoProxy.responseOrError(c.future), equals("foo"));
|
|
|
| await differentEchoProxy.close();
|
| });
|
|
|