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

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

Issue 2578333002: Mojo JS bindings: BindingSet support. (Closed)
Patch Set: 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 | « no previous file | mojo/edk/js/tests/interface_ptr_tests.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/js/bindings", 7 "mojo/public/js/bindings",
8 "mojo/public/interfaces/bindings/tests/math_calculator.mojom", 8 "mojo/public/interfaces/bindings/tests/math_calculator.mojom",
9 "mojo/public/js/threading", 9 "mojo/public/js/threading",
10 "gc", 10 "gc",
11 ], function(expect, 11 ], function(expect,
12 bindings, 12 bindings,
13 math, 13 math,
14 threading, 14 threading,
15 gc) { 15 gc) {
16 testIsBound() 16 testIsBound()
17 .then(testReusable) 17 .then(testReusable)
18 .then(testConnectionError) 18 .then(testConnectionError)
19 .then(testUnbind) 19 .then(testUnbind)
20 .then(testBindingSet)
20 .then(function() { 21 .then(function() {
21 this.result = "PASS"; 22 this.result = "PASS";
22 gc.collectGarbage(); // should not crash 23 gc.collectGarbage(); // should not crash
23 threading.quit(); 24 threading.quit();
24 }.bind(this)).catch(function(e) { 25 }.bind(this)).catch(function(e) {
25 this.result = "FAIL: " + (e.stack || e); 26 this.result = "FAIL: " + (e.stack || e);
26 threading.quit(); 27 threading.quit();
27 }.bind(this)); 28 }.bind(this));
28 29
29 function CalculatorImpl() { 30 function CalculatorImpl() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 new CalculatorImpl(), 112 new CalculatorImpl(),
112 interfaceRequest); 113 interfaceRequest);
113 return calc.add(2); 114 return calc.add(2);
114 }).then(function(response) { 115 }).then(function(response) {
115 expect(response.value).toBe(2); 116 expect(response.value).toBe(2);
116 return Promise.resolve(); 117 return Promise.resolve();
117 }); 118 });
118 119
119 return promise; 120 return promise;
120 } 121 }
122
123 function testBindingSet() {
124 var calc1 = new math.CalculatorPtr();
125 var calc2 = new math.CalculatorPtr();
126 var calcImpl = new CalculatorImpl();
127
128 var bindingSet = new bindings.BindingSet(math.Calculator);
129 expect(bindingSet.isEmpty()).toBeTruthy();
130 bindingSet.addBinding(calcImpl, bindings.makeRequest(calc1));
131 bindingSet.addBinding(calcImpl, bindings.makeRequest(calc2));
132 expect(bindingSet.isEmpty()).toBeFalsy();
133
134 var promise = calc1.add(3).then(function(response) {
135 expect(response.value).toBe(3);
136 return calc2.add(4);
137 }).then(function(response) {
138 expect(response.value).toBe(7);
139
140 var promiseOfConnectionError = new Promise(function(resolve, reject) {
141 bindingSet.setConnectionErrorHandler(function() {
142 resolve();
143 });
144 });
145 calc1.ptr.reset();
146 return promiseOfConnectionError;
147 }).then(function() {
148 return calc2.add(5);
149 }).then(function(response) {
150 expect(response.value).toBe(12);
151
152 bindingSet.closeAllBindings();
153 expect(bindingSet.isEmpty()).toBeTruthy();
154 return Promise.resolve();
155 });
156
157 return promise;
158 }
121 }); 159 });
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/js/tests/interface_ptr_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698