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

Unified Diff: mojo/edk/js/tests/binding_tests.js

Issue 2645873003: Cleanup mojo-js tests. (Closed)
Patch Set: more deps fixes Created 3 years, 11 months 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/connection_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
deleted file mode 100644
index 7bf9a89e3c405c41eb4517708f1747d806c1533d..0000000000000000000000000000000000000000
--- a/mojo/edk/js/tests/binding_tests.js
+++ /dev/null
@@ -1,159 +0,0 @@
-// 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(testConnectionError)
- .then(testUnbind)
- .then(testBindingSet)
- .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;
- }
-
- function testConnectionError() {
- var calc = new math.CalculatorPtr();
- var calcBinding = new bindings.Binding(math.Calculator,
- new CalculatorImpl(),
- bindings.makeRequest(calc));
-
- var promise = new Promise(function(resolve, reject) {
- calcBinding.setConnectionErrorHandler(function() {
- resolve();
- });
- calc.ptr.reset();
- });
-
- return promise;
- }
-
- function testUnbind() {
- var calc = new math.CalculatorPtr();
- var calcBinding = new bindings.Binding(math.Calculator,
- new CalculatorImpl(),
- bindings.makeRequest(calc));
- var newCalcBinding = null;
-
- var promise = calc.add(2).then(function(response) {
- expect(response.value).toBe(2);
- var interfaceRequest = calcBinding.unbind();
- expect(calcBinding.isBound()).toBeFalsy();
- newCalcBinding = new bindings.Binding(math.Calculator,
- new CalculatorImpl(),
- interfaceRequest);
- return calc.add(2);
- }).then(function(response) {
- expect(response.value).toBe(2);
- return Promise.resolve();
- });
-
- return promise;
- }
-
- function testBindingSet() {
- var calc1 = new math.CalculatorPtr();
- var calc2 = new math.CalculatorPtr();
- var calcImpl = new CalculatorImpl();
-
- var bindingSet = new bindings.BindingSet(math.Calculator);
- expect(bindingSet.isEmpty()).toBeTruthy();
- bindingSet.addBinding(calcImpl, bindings.makeRequest(calc1));
- bindingSet.addBinding(calcImpl, bindings.makeRequest(calc2));
- expect(bindingSet.isEmpty()).toBeFalsy();
-
- var promise = calc1.add(3).then(function(response) {
- expect(response.value).toBe(3);
- return calc2.add(4);
- }).then(function(response) {
- expect(response.value).toBe(7);
-
- var promiseOfConnectionError = new Promise(function(resolve, reject) {
- bindingSet.setConnectionErrorHandler(function() {
- resolve();
- });
- });
- calc1.ptr.reset();
- return promiseOfConnectionError;
- }).then(function() {
- return calc2.add(5);
- }).then(function(response) {
- expect(response.value).toBe(12);
-
- bindingSet.closeAllBindings();
- expect(bindingSet.isEmpty()).toBeTruthy();
- return Promise.resolve();
- });
-
- return promise;
- }
-});
« no previous file with comments | « mojo/edk/js/tests/BUILD.gn ('k') | mojo/edk/js/tests/connection_tests.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698