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

Side by Side Diff: mojo/edk/js/tests/sample_service_tests.js

Issue 2549683002: Mojo JS bindings: introduce concepts that are more similar to C++ bindings: (Closed)
Patch Set: put interface control methods in the |ptr| property Created 4 years 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
« no previous file with comments | « mojo/edk/js/tests/interface_ptr_tests.js ('k') | mojo/public/js/bindings.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 define([ 5 define([
6 "gin/test/expect", 6 "gin/test/expect",
7 "mojo/public/interfaces/bindings/tests/sample_service.mojom", 7 "mojo/public/interfaces/bindings/tests/sample_service.mojom",
8 "mojo/public/interfaces/bindings/tests/sample_import.mojom", 8 "mojo/public/interfaces/bindings/tests/sample_import.mojom",
9 "mojo/public/interfaces/bindings/tests/sample_import2.mojom", 9 "mojo/public/interfaces/bindings/tests/sample_import2.mojom",
10 "mojo/public/js/connection", 10 "mojo/public/js/bindings",
11 "mojo/public/js/core", 11 "mojo/public/js/core",
12 "mojo/public/js/threading", 12 "mojo/public/js/threading",
13 ], function(expect, sample, imported, imported2, connection, core, 13 ], function(expect, sample, imported, imported2, bindings, core, threading) {
14 threading) {
15 testDefaultValues() 14 testDefaultValues()
16 .then(testSampleService) 15 .then(testSampleService)
17 .then(function() { 16 .then(function() {
18 this.result = "PASS"; 17 this.result = "PASS";
19 threading.quit(); 18 threading.quit();
20 }.bind(this)).catch(function(e) { 19 }.bind(this)).catch(function(e) {
21 this.result = "FAIL: " + (e.stack || e); 20 this.result = "FAIL: " + (e.stack || e);
22 threading.quit(); 21 threading.quit();
23 }.bind(this)); 22 }.bind(this));
24 23
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 expect(defaults.a24).toBe(0x123456789); 63 expect(defaults.a24).toBe(0x123456789);
65 expect(defaults.a25).toBe(-0x123456789); 64 expect(defaults.a25).toBe(-0x123456789);
66 65
67 return Promise.resolve(); 66 return Promise.resolve();
68 } 67 }
69 68
70 function testSampleService() { 69 function testSampleService() {
71 function ServiceImpl() { 70 function ServiceImpl() {
72 } 71 }
73 72
74 ServiceImpl.prototype = Object.create(sample.Service.stubClass.prototype);
75
76 ServiceImpl.prototype.frobinate = function(foo, baz, port) { 73 ServiceImpl.prototype.frobinate = function(foo, baz, port) {
77 checkFoo(foo); 74 checkFoo(foo);
78 expect(baz).toBe(sample.Service.BazOptions.EXTRA); 75 expect(baz).toBe(sample.Service.BazOptions.EXTRA);
79 expect(core.isHandle(port)).toBeTruthy(); 76 bindings.ProxyBindings(port).close();
80 return Promise.resolve({result: 1234}); 77 return Promise.resolve({result: 1234});
81 }; 78 };
82 79
83 var foo = makeFoo(); 80 var foo = makeFoo();
84 checkFoo(foo); 81 checkFoo(foo);
85 82
86 var sampleServicePipe = core.createMessagePipe(); 83 var service = new sample.ServicePtr();
87 var connection0 = new connection.Connection(sampleServicePipe.handle0, 84 var request = bindings.makeRequest(service);
88 ServiceImpl); 85 var serviceBinding = new bindings.Binding(
89 var connection1 = new connection.Connection( 86 sample.Service, new ServiceImpl(), request);
90 sampleServicePipe.handle1, undefined, sample.Service.proxyClass);
91 87
92 var pipe = core.createMessagePipe(); 88 var pipe = core.createMessagePipe();
93 var promise = connection1.remote.frobinate( 89 var promise = service.frobinate(
94 foo, sample.Service.BazOptions.EXTRA, pipe.handle0) 90 foo, sample.Service.BazOptions.EXTRA, pipe.handle0)
95 .then(function(response) { 91 .then(function(response) {
96 expect(response.result).toBe(1234); 92 expect(response.result).toBe(1234);
97 93
98 return Promise.resolve(); 94 return Promise.resolve();
99 }); 95 });
100 96
101 return promise; 97 return promise;
102 } 98 }
103 99
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 expect(foo.extra_bars[i].type).toBe(type); 163 expect(foo.extra_bars[i].type).toBe(type);
168 } 164 }
169 165
170 expect(foo.data.length).toBe(10); 166 expect(foo.data.length).toBe(10);
171 for (var i = 0; i < foo.data.length; ++i) 167 for (var i = 0; i < foo.data.length; ++i)
172 expect(foo.data[i]).toBe(foo.data.length - i); 168 expect(foo.data[i]).toBe(foo.data.length - i);
173 169
174 expect(core.isHandle(foo.source)).toBeTruthy(); 170 expect(core.isHandle(foo.source)).toBeTruthy();
175 } 171 }
176 }); 172 });
OLDNEW
« no previous file with comments | « mojo/edk/js/tests/interface_ptr_tests.js ('k') | mojo/public/js/bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698