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

Side by Side Diff: mojo/edk/js/tests/binding_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/BUILD.gn ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 define([
6 "gin/test/expect",
7 "mojo/public/js/bindings",
8 "mojo/public/interfaces/bindings/tests/math_calculator.mojom",
9 "mojo/public/js/threading",
10 "gc",
11 ], function(expect,
12 bindings,
13 math,
14 threading,
15 gc) {
16 testIsBound()
17 .then(testReusable)
18 .then(function() {
19 this.result = "PASS";
20 gc.collectGarbage(); // should not crash
21 threading.quit();
22 }.bind(this)).catch(function(e) {
23 this.result = "FAIL: " + (e.stack || e);
24 threading.quit();
25 }.bind(this));
26
27 function CalculatorImpl() {
28 this.total = 0;
29 }
30
31 CalculatorImpl.prototype.clear = function() {
32 this.total = 0;
33 return Promise.resolve({value: this.total});
34 };
35
36 CalculatorImpl.prototype.add = function(value) {
37 this.total += value;
38 return Promise.resolve({value: this.total});
39 };
40
41 CalculatorImpl.prototype.multiply = function(value) {
42 this.total *= value;
43 return Promise.resolve({value: this.total});
44 };
45
46 function testIsBound() {
47 var binding = new bindings.Binding(math.Calculator, new CalculatorImpl());
48 expect(binding.isBound()).toBeFalsy();
49
50 var calc = new math.CalculatorPtr();
51 var request = bindings.makeRequest(calc);
52 binding.bind(request);
53 expect(binding.isBound()).toBeTruthy();
54
55 binding.close();
56 expect(binding.isBound()).toBeFalsy();
57
58 return Promise.resolve();
59 }
60
61 function testReusable() {
62 var calc1 = new math.CalculatorPtr();
63 var calc2 = new math.CalculatorPtr();
64
65 var calcBinding = new bindings.Binding(math.Calculator,
66 new CalculatorImpl(),
67 bindings.makeRequest(calc1));
68
69 var promise = calc1.add(2).then(function(response) {
70 expect(response.value).toBe(2);
71 calcBinding.bind(bindings.makeRequest(calc2));
72 return calc2.add(2);
73 }).then(function(response) {
74 expect(response.value).toBe(4);
75 return Promise.resolve();
76 });
77
78 return promise;
79 }
80 });
OLDNEW
« no previous file with comments | « mojo/edk/js/tests/BUILD.gn ('k') | mojo/edk/js/tests/interface_ptr_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698