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

Unified Diff: mojo/public/js/tests/interface_ptr_unittest.js

Issue 2676443005: Add interface versioning. Methods queryVersion and requireVersion. (Closed)
Patch Set: Expect the result inside the error handler for test. Code formatting and address codereview comment… Created 3 years, 10 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/public/js/router.js ('k') | mojo/public/js/validator.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/js/tests/interface_ptr_unittest.js
diff --git a/mojo/public/js/tests/interface_ptr_unittest.js b/mojo/public/js/tests/interface_ptr_unittest.js
index 22e0d6f15f3db3e3d1291050cbb8b9bb8adc028a..6203154d204c96c2e24cc7bf348446a49a627f56 100644
--- a/mojo/public/js/tests/interface_ptr_unittest.js
+++ b/mojo/public/js/tests/interface_ptr_unittest.js
@@ -7,12 +7,14 @@ define([
"mojo/public/js/bindings",
"mojo/public/js/core",
"mojo/public/interfaces/bindings/tests/math_calculator.mojom",
+ "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom",
"mojo/public/js/threading",
"gc",
], function(expect,
bindings,
core,
math,
+ sampleInterfaces,
threading,
gc) {
testIsBound()
@@ -21,6 +23,8 @@ define([
.then(testConnectionError)
.then(testPassInterface)
.then(testBindRawHandle)
+ .then(testQueryVersion)
+ .then(testRequireVersion)
.then(function() {
this.result = "PASS";
gc.collectGarbage(); // should not crash
@@ -49,6 +53,18 @@ define([
return Promise.resolve({value: this.total});
};
+ function IntegerAccessorImpl() {
+ this.integer = 0;
+ }
+
+ IntegerAccessorImpl.prototype.getInteger = function() {
+ return Promise.resolve({data: this.integer});
+ };
+
+ IntegerAccessorImpl.prototype.setInteger = function(value) {
+ this.integer = value;
+ };
+
function testIsBound() {
var calc = new math.CalculatorPtr();
expect(calc.ptr.isBound()).toBeFalsy();
@@ -157,4 +173,68 @@ define([
return promise;
}
+
+ function testQueryVersion() {
+ var integerAccessorPtr = new sampleInterfaces.IntegerAccessorPtr();
+
+ var integerAccessorBinding = new bindings.Binding(
+ sampleInterfaces.IntegerAccessor,
+ new IntegerAccessorImpl(),
+ bindings.makeRequest(integerAccessorPtr));
+ expect(integerAccessorPtr.ptr.version).toBe(0);
+
+ return integerAccessorPtr.ptr.queryVersion().then(function(version) {
+ expect(version).toBe(3);
+ expect(integerAccessorPtr.ptr.version).toBe(3);
+ });
+ }
+
+ function testRequireVersion() {
+ var integerAccessorImpl = new IntegerAccessorImpl();
+ var integerAccessorPtr = new sampleInterfaces.IntegerAccessorPtr();
+ var integerAccessorBinding = new bindings.Binding(
+ sampleInterfaces.IntegerAccessor,
+ integerAccessorImpl,
+ bindings.makeRequest(integerAccessorPtr));
+
+ // Inital version is 0.
+ expect(integerAccessorPtr.ptr.version).toBe(0);
+
+ function requireVersion1() {
+ integerAccessorPtr.ptr.requireVersion(1);
+ expect(integerAccessorPtr.ptr.version).toBe(1);
+ integerAccessorPtr.setInteger(123, sampleInterfaces.Enum.VALUE);
+ return integerAccessorPtr.getInteger().then(function(responseParams) {
+ expect(responseParams.data).toBe(123);
+ });
+ }
+
+ function requireVersion3() {
+ integerAccessorPtr.ptr.requireVersion(3);
+ expect(integerAccessorPtr.ptr.version).toBe(3);
+ integerAccessorPtr.setInteger(456, sampleInterfaces.Enum.VALUE);
+ return integerAccessorPtr.getInteger().then(function(responseParams) {
+ expect(responseParams.data).toBe(456);
+ });
+ }
+
+ // Require a version that is not supported by the impl side.
+ function requireVersion4() {
+ integerAccessorPtr.ptr.requireVersion(4);
+ expect(integerAccessorPtr.ptr.version).toBe(4);
+ integerAccessorPtr.setInteger(789, sampleInterfaces.Enum.VALUE);
+
+ var promise = new Promise(function(resolve, reject) {
+ integerAccessorPtr.ptr.setConnectionErrorHandler(function() {
+ // The call to setInteger() after requireVersion(4) is ignored.
+ expect(integerAccessorImpl.integer).toBe(456);
+ resolve();
+ });
+ });
+
+ return promise;
+ }
+
+ return requireVersion1().then(requireVersion3).then(requireVersion4);
+ }
});
« no previous file with comments | « mojo/public/js/router.js ('k') | mojo/public/js/validator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698