OLD | NEW |
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/js/core", | 8 "mojo/public/js/core", |
9 "mojo/public/interfaces/bindings/tests/math_calculator.mojom", | 9 "mojo/public/interfaces/bindings/tests/math_calculator.mojom", |
10 "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom", | 10 "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom", |
11 "mojo/public/js/threading", | 11 "mojo/public/js/threading", |
12 "gc", | 12 "gc", |
13 ], function(expect, | 13 ], function(expect, |
14 bindings, | 14 bindings, |
15 core, | 15 core, |
16 math, | 16 math, |
17 sampleInterfaces, | 17 sampleInterfaces, |
18 threading, | 18 threading, |
19 gc) { | 19 gc) { |
20 testIsBound() | 20 testIsBound() |
21 .then(testEndToEnd) | 21 .then(testEndToEnd) |
22 .then(testReusable) | 22 .then(testReusable) |
23 .then(testConnectionError) | 23 .then(testConnectionError) |
| 24 .then(testConnectionErrorWithReason) |
| 25 .then(testResetWithReason) |
24 .then(testPassInterface) | 26 .then(testPassInterface) |
25 .then(testBindRawHandle) | 27 .then(testBindRawHandle) |
26 .then(testQueryVersion) | 28 .then(testQueryVersion) |
27 .then(testRequireVersion) | 29 .then(testRequireVersion) |
28 .then(function() { | 30 .then(function() { |
29 this.result = "PASS"; | 31 this.result = "PASS"; |
30 gc.collectGarbage(); // should not crash | 32 gc.collectGarbage(); // should not crash |
31 threading.quit(); | 33 threading.quit(); |
32 }.bind(this)).catch(function(e) { | 34 }.bind(this)).catch(function(e) { |
33 this.result = "FAIL: " + (e.stack || e); | 35 this.result = "FAIL: " + (e.stack || e); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 var promise = new Promise(function(resolve, reject) { | 132 var promise = new Promise(function(resolve, reject) { |
131 calc.ptr.setConnectionErrorHandler(function() { | 133 calc.ptr.setConnectionErrorHandler(function() { |
132 resolve(); | 134 resolve(); |
133 }); | 135 }); |
134 calcBinding.close(); | 136 calcBinding.close(); |
135 }); | 137 }); |
136 | 138 |
137 return promise; | 139 return promise; |
138 } | 140 } |
139 | 141 |
| 142 function testConnectionErrorWithReason() { |
| 143 var calc = new math.CalculatorPtr(); |
| 144 var calcBinding = new bindings.Binding(math.Calculator, |
| 145 new CalculatorImpl(), |
| 146 bindings.makeRequest(calc)); |
| 147 |
| 148 var promise = new Promise(function(resolve, reject) { |
| 149 calc.ptr.setConnectionErrorHandler(function({custom_reason, |
| 150 description}) { |
| 151 expect(custom_reason).toBe(42); |
| 152 expect(description).toBe('hey'); |
| 153 resolve(); |
| 154 }); |
| 155 calcBinding.closeWithReason({custom_reason: 42, description: 'hey'}); |
| 156 }); |
| 157 |
| 158 return promise; |
| 159 } |
| 160 |
| 161 function testResetWithReason() { |
| 162 var calc = new math.CalculatorPtr(); |
| 163 var calcBinding = new bindings.Binding(math.Calculator, |
| 164 new CalculatorImpl(), |
| 165 bindings.makeRequest(calc)); |
| 166 |
| 167 var promise = new Promise(function(resolve, reject) { |
| 168 calcBinding.setConnectionErrorHandler(function({custom_reason, |
| 169 description}) { |
| 170 expect(custom_reason).toBe(32); |
| 171 expect(description).toBe('goodbye'); |
| 172 resolve(); |
| 173 }); |
| 174 calc.ptr.resetWithReason({custom_reason: 32, description: 'goodbye'}); |
| 175 }); |
| 176 |
| 177 return promise; |
| 178 } |
| 179 |
140 function testPassInterface() { | 180 function testPassInterface() { |
141 var calc = new math.CalculatorPtr(); | 181 var calc = new math.CalculatorPtr(); |
142 var newCalc = null; | 182 var newCalc = null; |
143 var calcBinding = new bindings.Binding(math.Calculator, | 183 var calcBinding = new bindings.Binding(math.Calculator, |
144 new CalculatorImpl(), | 184 new CalculatorImpl(), |
145 bindings.makeRequest(calc)); | 185 bindings.makeRequest(calc)); |
146 | 186 |
147 var promise = calc.add(2).then(function(response) { | 187 var promise = calc.add(2).then(function(response) { |
148 expect(response.value).toBe(2); | 188 expect(response.value).toBe(2); |
149 newCalc = new math.CalculatorPtr(); | 189 newCalc = new math.CalculatorPtr(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 resolve(); | 271 resolve(); |
232 }); | 272 }); |
233 }); | 273 }); |
234 | 274 |
235 return promise; | 275 return promise; |
236 } | 276 } |
237 | 277 |
238 return requireVersion1().then(requireVersion3).then(requireVersion4); | 278 return requireVersion1().then(requireVersion3).then(requireVersion4); |
239 } | 279 } |
240 }); | 280 }); |
OLD | NEW |