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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/js/tests/binding_tests.js
diff --git a/mojo/edk/js/tests/binding_tests.js b/mojo/edk/js/tests/binding_tests.js
new file mode 100644
index 0000000000000000000000000000000000000000..26031d055f05a0688866324a8f87d81ee0593215
--- /dev/null
+++ b/mojo/edk/js/tests/binding_tests.js
@@ -0,0 +1,80 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+define([
+ "gin/test/expect",
+ "mojo/public/js/bindings",
+ "mojo/public/interfaces/bindings/tests/math_calculator.mojom",
+ "mojo/public/js/threading",
+ "gc",
+], function(expect,
+ bindings,
+ math,
+ threading,
+ gc) {
+ testIsBound()
+ .then(testReusable)
+ .then(function() {
+ this.result = "PASS";
+ gc.collectGarbage(); // should not crash
+ threading.quit();
+ }.bind(this)).catch(function(e) {
+ this.result = "FAIL: " + (e.stack || e);
+ threading.quit();
+ }.bind(this));
+
+ function CalculatorImpl() {
+ this.total = 0;
+ }
+
+ CalculatorImpl.prototype.clear = function() {
+ this.total = 0;
+ return Promise.resolve({value: this.total});
+ };
+
+ CalculatorImpl.prototype.add = function(value) {
+ this.total += value;
+ return Promise.resolve({value: this.total});
+ };
+
+ CalculatorImpl.prototype.multiply = function(value) {
+ this.total *= value;
+ return Promise.resolve({value: this.total});
+ };
+
+ function testIsBound() {
+ var binding = new bindings.Binding(math.Calculator, new CalculatorImpl());
+ expect(binding.isBound()).toBeFalsy();
+
+ var calc = new math.CalculatorPtr();
+ var request = bindings.makeRequest(calc);
+ binding.bind(request);
+ expect(binding.isBound()).toBeTruthy();
+
+ binding.close();
+ expect(binding.isBound()).toBeFalsy();
+
+ return Promise.resolve();
+ }
+
+ function testReusable() {
+ var calc1 = new math.CalculatorPtr();
+ var calc2 = new math.CalculatorPtr();
+
+ var calcBinding = new bindings.Binding(math.Calculator,
+ new CalculatorImpl(),
+ bindings.makeRequest(calc1));
+
+ var promise = calc1.add(2).then(function(response) {
+ expect(response.value).toBe(2);
+ calcBinding.bind(bindings.makeRequest(calc2));
+ return calc2.add(2);
+ }).then(function(response) {
+ expect(response.value).toBe(4);
+ return Promise.resolve();
+ });
+
+ return promise;
+ }
+});
« 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