| Index: mojo/apps/js/bindings/connection_unittests.js
|
| diff --git a/mojo/apps/js/bindings/connector_unittests.js b/mojo/apps/js/bindings/connection_unittests.js
|
| similarity index 18%
|
| rename from mojo/apps/js/bindings/connector_unittests.js
|
| rename to mojo/apps/js/bindings/connection_unittests.js
|
| index d50f740502e32657f3938e24f702a8a7549dcc01..14bb92f9502a419b4072a70944763f19ab5d869c 100644
|
| --- a/mojo/apps/js/bindings/connector_unittests.js
|
| +++ b/mojo/apps/js/bindings/connection_unittests.js
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -32,8 +32,10 @@ define("mojo/bindings/js/support", function() {
|
| function pumpOnce(result) {
|
| var callbacks = waitingCallbacks;
|
| waitingCallbacks = [];
|
| - for (var i = 0; i < callbacks.length; ++i)
|
| - callbacks[i](result);
|
| + for (var i = 0; i < callbacks.length; ++i) {
|
| + if (callbacks[i])
|
| + callbacks[i](result);
|
| + }
|
| }
|
|
|
| var exports = {};
|
| @@ -48,85 +50,188 @@ define([
|
| "gin/test/expect",
|
| "mojo/bindings/js/support",
|
| "mojo/bindings/js/core",
|
| - "mojo/public/bindings/js/connector",
|
| + "mojo/public/bindings/js/connection",
|
| + "mojo/public/bindings/tests/sample_interfaces.mojom",
|
| "mojo/public/bindings/tests/sample_service.mojom",
|
| -], function(expect, mockSupport, core, connector, sample) {
|
| +], function(expect,
|
| + mockSupport,
|
| + core,
|
| + connection,
|
| + sample_interfaces,
|
| + sample_service) {
|
| + testClientServer();
|
| + testWriteToClosedPipe();
|
| + testRequestResponse();
|
| + this.result = "PASS";
|
| +
|
| + function testClientServer() {
|
| + var receivedFrobinate = false;
|
| + var receivedDidFrobinate = false;
|
| +
|
| + // ServiceImpl -------------------------------------------------------------
|
| +
|
| + function ServiceImpl(peer) {
|
| + this.peer = peer;
|
| + }
|
| +
|
| + ServiceImpl.prototype = Object.create(sample_service.ServiceStub.prototype);
|
| +
|
| + ServiceImpl.prototype.frobinate = function(foo, baz, port) {
|
| + receivedFrobinate = true;
|
| +
|
| + expect(foo.name).toBe("Example name");
|
| + expect(baz).toBeTruthy();
|
| + expect(core.close(port)).toBe(core.RESULT_OK);
|
| +
|
| + this.peer.didFrobinate(42);
|
| + };
|
| +
|
| + // ServiceImpl -------------------------------------------------------------
|
| +
|
| + function ServiceClientImpl(peer) {
|
| + this.peer = peer;
|
| + }
|
| +
|
| + ServiceClientImpl.prototype =
|
| + Object.create(sample_service.ServiceClientStub.prototype);
|
| +
|
| + ServiceClientImpl.prototype.didFrobinate = function(result) {
|
| + receivedDidFrobinate = true;
|
| +
|
| + expect(result).toBe(42);
|
| + };
|
| +
|
| + var pipe = core.createMessagePipe();
|
| + var anotherPipe = core.createMessagePipe();
|
| + var sourcePipe = core.createMessagePipe();
|
| +
|
| + var connection0 = new connection.Connection(
|
| + pipe.handle0, ServiceImpl, sample_service.ServiceClientProxy);
|
| +
|
| + var connection1 = new connection.Connection(
|
| + pipe.handle1, ServiceClientImpl, sample_service.ServiceProxy);
|
| +
|
| + var foo = new sample_service.Foo();
|
| + foo.bar = new sample_service.Bar();
|
| + foo.name = "Example name";
|
| + foo.source = sourcePipe.handle0;
|
| + connection1.remote.frobinate(foo, true, anotherPipe.handle0);
|
|
|
| - var receivedFrobinate = false;
|
| - var receivedDidFrobinate = false;
|
| + mockSupport.pumpOnce(core.RESULT_OK);
|
|
|
| - // ServiceImpl --------------------------------------------------------------
|
| + expect(receivedFrobinate).toBeTruthy();
|
| + expect(receivedDidFrobinate).toBeTruthy();
|
|
|
| - function ServiceImpl(peer) {
|
| - this.peer = peer;
|
| + connection0.close();
|
| + connection1.close();
|
| +
|
| + expect(mockSupport.numberOfWaitingCallbacks()).toBe(0);
|
| +
|
| + // sourcePipe.handle0 was closed automatically when sent over IPC.
|
| + expect(core.close(sourcePipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| + // sourcePipe.handle1 hasn't been closed yet.
|
| + expect(core.close(sourcePipe.handle1)).toBe(core.RESULT_OK);
|
| +
|
| + // anotherPipe.handle0 was closed automatically when sent over IPC.
|
| + expect(core.close(anotherPipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| + // anotherPipe.handle1 hasn't been closed yet.
|
| + expect(core.close(anotherPipe.handle1)).toBe(core.RESULT_OK);
|
| +
|
| + // The Connection object is responsible for closing these handles.
|
| + expect(core.close(pipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| + expect(core.close(pipe.handle1)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| }
|
|
|
| - ServiceImpl.prototype = Object.create(sample.ServiceStub.prototype);
|
| + function testWriteToClosedPipe() {
|
| + var pipe = core.createMessagePipe();
|
| +
|
| + var connection1 = new connection.Connection(
|
| + pipe.handle1, function() {}, sample_service.ServiceProxy);
|
|
|
| - ServiceImpl.prototype.frobinate = function(foo, baz, port) {
|
| - receivedFrobinate = true;
|
| + // Close the other end of the pipe.
|
| + core.close(pipe.handle0);
|
|
|
| - expect(foo.name).toBe("Example name");
|
| - expect(baz).toBeTruthy();
|
| - expect(core.close(port)).toBe(core.RESULT_OK);
|
| + // Not observed yet because we haven't pumped events yet.
|
| + expect(connection1.encounteredError()).toBeFalsy();
|
|
|
| - this.peer.didFrobinate(42);
|
| - };
|
| + var foo = new sample_service.Foo();
|
| + foo.bar = new sample_service.Bar();
|
| + // TODO(darin): crbug.com/357043: pass null in place of |foo| here.
|
| + connection1.remote.frobinate(foo, true, core.kInvalidHandle);
|
|
|
| - // ServiceImpl --------------------------------------------------------------
|
| + // Write failures are not reported.
|
| + expect(connection1.encounteredError()).toBeFalsy();
|
|
|
| - function ServiceClientImpl(peer) {
|
| - this.peer = peer;
|
| + // Pump events, and then we should start observing the closed pipe.
|
| + mockSupport.pumpOnce(core.RESULT_OK);
|
| +
|
| + expect(connection1.encounteredError()).toBeTruthy();
|
| +
|
| + connection1.close();
|
| }
|
|
|
| - ServiceClientImpl.prototype =
|
| - Object.create(sample.ServiceClientStub.prototype);
|
| + function testRequestResponse() {
|
|
|
| - ServiceClientImpl.prototype.didFrobinate = function(result) {
|
| - receivedDidFrobinate = true;
|
| + // ProviderImpl ------------------------------------------------------------
|
|
|
| - expect(result).toBe(42);
|
| - };
|
| + function ProviderImpl(peer) {
|
| + this.peer = peer;
|
| + }
|
|
|
| - var pipe = core.createMessagePipe();
|
| - var anotherPipe = core.createMessagePipe();
|
| - var sourcePipe = core.createMessagePipe();
|
| + ProviderImpl.prototype =
|
| + Object.create(sample_interfaces.ProviderStub.prototype);
|
|
|
| - var connection0 = new connector.Connection(
|
| - pipe.handle0, ServiceImpl, sample.ServiceClientProxy);
|
| + ProviderImpl.prototype.echoString = function(a, callback) {
|
| + callback(a);
|
| + };
|
|
|
| - var connection1 = new connector.Connection(
|
| - pipe.handle1, ServiceClientImpl, sample.ServiceProxy);
|
| + ProviderImpl.prototype.echoStrings = function(a, b, callback) {
|
| + callback(a, b);
|
| + };
|
|
|
| - var foo = new sample.Foo();
|
| - foo.bar = new sample.Bar();
|
| - foo.name = "Example name";
|
| - foo.source = sourcePipe.handle0;
|
| - connection1.remote.frobinate(foo, true, anotherPipe.handle0);
|
| + // ProviderClientImpl ------------------------------------------------------
|
|
|
| - mockSupport.pumpOnce(core.RESULT_OK);
|
| + function ProviderClientImpl(peer) {
|
| + this.peer = peer;
|
| + }
|
|
|
| - expect(receivedFrobinate).toBeTruthy();
|
| - expect(receivedDidFrobinate).toBeTruthy();
|
| + ProviderClientImpl.prototype =
|
| + Object.create(sample_interfaces.ProviderClientStub.prototype);
|
|
|
| - connection0.close();
|
| - connection1.close();
|
| + ProviderClientImpl.prototype.didFrobinate = function(result) {
|
| + receivedDidFrobinate = true;
|
|
|
| - expect(mockSupport.numberOfWaitingCallbacks()).toBe(0);
|
| + expect(result).toBe(42);
|
| + };
|
|
|
| - // sourcePipe.handle0 was closed automatically when sent over IPC.
|
| - expect(core.close(sourcePipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| - // sourcePipe.handle1 hasn't been closed yet.
|
| - expect(core.close(sourcePipe.handle1)).toBe(core.RESULT_OK);
|
| + var pipe = core.createMessagePipe();
|
|
|
| - // anotherPipe.handle0 was closed automatically when sent over IPC.
|
| - expect(core.close(anotherPipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| - // anotherPipe.handle1 hasn't been closed yet.
|
| - expect(core.close(anotherPipe.handle1)).toBe(core.RESULT_OK);
|
| + var connection0 = new connection.Connection(
|
| + pipe.handle0, ProviderImpl, sample_interfaces.ProviderClientProxy);
|
|
|
| - // The Connection object is responsible for closing these handles.
|
| - expect(core.close(pipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| - expect(core.close(pipe.handle1)).toBe(core.RESULT_INVALID_ARGUMENT);
|
| + var connection1 = new connection.Connection(
|
| + pipe.handle1, ProviderClientImpl, sample_interfaces.ProviderProxy);
|
|
|
| - this.result = "PASS";
|
| + var echoedString;
|
| +
|
| + // echoString
|
| +
|
| + connection1.remote.echoString("hello", function(a) {
|
| + echoedString = a;
|
| + });
|
| +
|
| + mockSupport.pumpOnce(core.RESULT_OK);
|
| +
|
| + expect(echoedString).toBe("hello");
|
| +
|
| + // echoStrings
|
| +
|
| + connection1.remote.echoStrings("hello", "world", function(a, b) {
|
| + echoedString = a + " " + b;
|
| + });
|
| +
|
| + mockSupport.pumpOnce(core.RESULT_OK);
|
| +
|
| + expect(echoedString).toBe("hello world");
|
| + }
|
| });
|
|
|