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

Side by Side Diff: mojo/apps/js/bindings/connection_unittests.js

Issue 628763002: Mojo JS bindings: simplify mojo.connectToService() usage - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed template indentation Created 6 years, 2 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Mock out the support module to avoid depending on the message loop. 5 // Mock out the support module to avoid depending on the message loop.
6 define("mojo/public/js/bindings/support", ["timer"], function(timer) { 6 define("mojo/public/js/bindings/support", ["timer"], function(timer) {
7 var waitingCallbacks = []; 7 var waitingCallbacks = [];
8 8
9 function WaitCookie(id) { 9 function WaitCookie(id) {
10 this.id = id; 10 this.id = id;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 threading.quit(); 78 threading.quit();
79 }.bind(this)).catch(function(e) { 79 }.bind(this)).catch(function(e) {
80 this.result = "FAIL: " + (e.stack || e); 80 this.result = "FAIL: " + (e.stack || e);
81 threading.quit(); 81 threading.quit();
82 }.bind(this)); 82 }.bind(this));
83 83
84 function testClientServer() { 84 function testClientServer() {
85 var receivedFrobinate = false; 85 var receivedFrobinate = false;
86 var receivedDidFrobinate = false; 86 var receivedDidFrobinate = false;
87 87
88 // ServiceImpl ------------------------------------------------------------- 88 // ServiceImpl ------------------------------------------------------------
89 89
90 function ServiceImpl(peer) { 90 function ServiceImpl(peer) {
91 this.peer = peer; 91 this.peer = peer;
92 } 92 }
93 93
94 ServiceImpl.prototype = Object.create(sample_service.ServiceStub.prototype); 94 ServiceImpl.prototype = Object.create(
95 sample_service.Service.stubClass.prototype);
95 96
96 ServiceImpl.prototype.frobinate = function(foo, baz, port) { 97 ServiceImpl.prototype.frobinate = function(foo, baz, port) {
97 receivedFrobinate = true; 98 receivedFrobinate = true;
98 99
99 expect(foo.name).toBe("Example name"); 100 expect(foo.name).toBe("Example name");
100 expect(baz).toBeTruthy(); 101 expect(baz).toBeTruthy();
101 expect(core.close(port)).toBe(core.RESULT_OK); 102 expect(core.close(port)).toBe(core.RESULT_OK);
102 103
103 this.peer.didFrobinate(42); 104 this.peer.didFrobinate(42);
104 }; 105 };
105 106
106 // ServiceImpl ------------------------------------------------------------- 107 // ServiceClientImpl ------------------------------------------------------
107 108
108 function ServiceClientImpl(peer) { 109 function ServiceClientImpl(peer) {
109 this.peer = peer; 110 this.peer = peer;
110 } 111 }
111 112
112 ServiceClientImpl.prototype = 113 ServiceClientImpl.prototype =
113 Object.create(sample_service.ServiceClientStub.prototype); 114 Object.create(sample_service.ServiceClient.stubClass.prototype);
114 115
115 ServiceClientImpl.prototype.didFrobinate = function(result) { 116 ServiceClientImpl.prototype.didFrobinate = function(result) {
116 receivedDidFrobinate = true; 117 receivedDidFrobinate = true;
117 118
118 expect(result).toBe(42); 119 expect(result).toBe(42);
119 }; 120 };
120 121
121 var pipe = core.createMessagePipe(); 122 var pipe = core.createMessagePipe();
122 var anotherPipe = core.createMessagePipe(); 123 var anotherPipe = core.createMessagePipe();
123 var sourcePipe = core.createMessagePipe(); 124 var sourcePipe = core.createMessagePipe();
124 125
125 var connection0 = new connection.Connection( 126 var connection0 = new connection.Connection(
126 pipe.handle0, ServiceImpl, sample_service.ServiceClientProxy); 127 pipe.handle0, ServiceImpl, sample_service.ServiceClient.proxyClass);
127 128
128 var connection1 = new connection.Connection( 129 var connection1 = new connection.Connection(
129 pipe.handle1, ServiceClientImpl, sample_service.ServiceProxy); 130 pipe.handle1, ServiceClientImpl, sample_service.Service.proxyClass);
130 131
131 var foo = new sample_service.Foo(); 132 var foo = new sample_service.Foo();
132 foo.bar = new sample_service.Bar(); 133 foo.bar = new sample_service.Bar();
133 foo.name = "Example name"; 134 foo.name = "Example name";
134 foo.source = sourcePipe.handle0; 135 foo.source = sourcePipe.handle0;
135 connection1.remote.frobinate(foo, true, anotherPipe.handle0); 136 connection1.remote.frobinate(foo, true, anotherPipe.handle0);
136 137
137 mockSupport.pumpOnce(core.RESULT_OK); 138 mockSupport.pumpOnce(core.RESULT_OK);
138 139
139 expect(receivedFrobinate).toBeTruthy(); 140 expect(receivedFrobinate).toBeTruthy();
(...skipping 16 matching lines...) Expand all
156 157
157 // The Connection object is responsible for closing these handles. 158 // The Connection object is responsible for closing these handles.
158 expect(core.close(pipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT); 159 expect(core.close(pipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
159 expect(core.close(pipe.handle1)).toBe(core.RESULT_INVALID_ARGUMENT); 160 expect(core.close(pipe.handle1)).toBe(core.RESULT_INVALID_ARGUMENT);
160 } 161 }
161 162
162 function testWriteToClosedPipe() { 163 function testWriteToClosedPipe() {
163 var pipe = core.createMessagePipe(); 164 var pipe = core.createMessagePipe();
164 165
165 var connection1 = new connection.Connection( 166 var connection1 = new connection.Connection(
166 pipe.handle1, function() {}, sample_service.ServiceProxy); 167 pipe.handle1, function() {}, sample_service.Service.proxyClass);
167 168
168 // Close the other end of the pipe. 169 // Close the other end of the pipe.
169 core.close(pipe.handle0); 170 core.close(pipe.handle0);
170 171
171 // Not observed yet because we haven't pumped events yet. 172 // Not observed yet because we haven't pumped events yet.
172 expect(connection1.encounteredError()).toBeFalsy(); 173 expect(connection1.encounteredError()).toBeFalsy();
173 174
174 var foo = new sample_service.Foo(); 175 var foo = new sample_service.Foo();
175 foo.bar = new sample_service.Bar(); 176 foo.bar = new sample_service.Bar();
176 // TODO(darin): crbug.com/357043: pass null in place of |foo| here. 177 // TODO(darin): crbug.com/357043: pass null in place of |foo| here.
(...skipping 12 matching lines...) Expand all
189 190
190 function testRequestResponse() { 191 function testRequestResponse() {
191 192
192 // ProviderImpl ------------------------------------------------------------ 193 // ProviderImpl ------------------------------------------------------------
193 194
194 function ProviderImpl(peer) { 195 function ProviderImpl(peer) {
195 this.peer = peer; 196 this.peer = peer;
196 } 197 }
197 198
198 ProviderImpl.prototype = 199 ProviderImpl.prototype =
199 Object.create(sample_interfaces.ProviderStub.prototype); 200 Object.create(sample_interfaces.Provider.stubClass.prototype);
200 201
201 ProviderImpl.prototype.echoString = function(a) { 202 ProviderImpl.prototype.echoString = function(a) {
202 mockSupport.queuePump(core.RESULT_OK); 203 mockSupport.queuePump(core.RESULT_OK);
203 return Promise.resolve({a: a}); 204 return Promise.resolve({a: a});
204 }; 205 };
205 206
206 ProviderImpl.prototype.echoStrings = function(a, b) { 207 ProviderImpl.prototype.echoStrings = function(a, b) {
207 mockSupport.queuePump(core.RESULT_OK); 208 mockSupport.queuePump(core.RESULT_OK);
208 return Promise.resolve({a: a, b: b}); 209 return Promise.resolve({a: a, b: b});
209 }; 210 };
210 211
211 // ProviderClientImpl ------------------------------------------------------ 212 // ProviderClientImpl ------------------------------------------------------
212 213
213 function ProviderClientImpl(peer) { 214 function ProviderClientImpl(peer) {
214 this.peer = peer; 215 this.peer = peer;
215 } 216 }
216 217
217 ProviderClientImpl.prototype = 218 ProviderClientImpl.prototype =
218 Object.create(sample_interfaces.ProviderClientStub.prototype); 219 Object.create(sample_interfaces.ProviderClient.stubClass.prototype);
219 220
220 var pipe = core.createMessagePipe(); 221 var pipe = core.createMessagePipe();
221 222
222 var connection0 = new connection.Connection( 223 var connection0 = new connection.Connection(
223 pipe.handle0, ProviderImpl, sample_interfaces.ProviderClientProxy); 224 pipe.handle0,
225 ProviderImpl,
226 sample_interfaces.ProviderClient.proxyClass);
224 227
225 var connection1 = new connection.Connection( 228 var connection1 = new connection.Connection(
226 pipe.handle1, ProviderClientImpl, sample_interfaces.ProviderProxy); 229 pipe.handle1,
230 ProviderClientImpl,
231 sample_interfaces.Provider.proxyClass);
227 232
228 var origReadMessage = core.readMessage; 233 var origReadMessage = core.readMessage;
229 // echoString 234 // echoString
230 mockSupport.queuePump(core.RESULT_OK); 235 mockSupport.queuePump(core.RESULT_OK);
231 return connection1.remote.echoString("hello").then(function(response) { 236 return connection1.remote.echoString("hello").then(function(response) {
232 expect(response.a).toBe("hello"); 237 expect(response.a).toBe("hello");
233 }).then(function() { 238 }).then(function() {
234 // echoStrings 239 // echoStrings
235 mockSupport.queuePump(core.RESULT_OK); 240 mockSupport.queuePump(core.RESULT_OK);
236 return connection1.remote.echoStrings("hello", "world"); 241 return connection1.remote.echoStrings("hello", "world");
(...skipping 10 matching lines...) Expand all
247 }).then(function() { 252 }).then(function() {
248 throw Error("Expected echoString to fail."); 253 throw Error("Expected echoString to fail.");
249 }, function(error) { 254 }, function(error) {
250 expect(error.message).toBe("Connection error: " + core.RESULT_UNKNOWN); 255 expect(error.message).toBe("Connection error: " + core.RESULT_UNKNOWN);
251 256
252 // Clean up. 257 // Clean up.
253 core.readMessage = origReadMessage; 258 core.readMessage = origReadMessage;
254 }); 259 });
255 } 260 }
256 }); 261 });
OLDNEW
« no previous file with comments | « extensions/test/data/data_sender_unittest.js ('k') | mojo/apps/js/bindings/sample_service_unittests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698