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

Unified Diff: mojo/apps/js/test/js_to_cpp_unittest.js

Issue 292243002: Add mojo bindings backpointer tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove stray "explicit" keywords. Created 6 years, 7 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/apps/js/test/js_to_cpp_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/apps/js/test/js_to_cpp_unittest.js
diff --git a/mojo/apps/js/test/js_to_cpp_unittest.js b/mojo/apps/js/test/js_to_cpp_unittest.js
index 9ce456e70e5b9b85ba8c4f6b1e0aceb0f28a505a..976bd3ea4fe092f363caf8dc18e345657804a441 100644
--- a/mojo/apps/js/test/js_to_cpp_unittest.js
+++ b/mojo/apps/js/test/js_to_cpp_unittest.js
@@ -29,14 +29,12 @@ define('mojo/apps/js/test/js_to_cpp_unittest', [
this.cppSide_.pingResponse();
};
- JsSideConnection.prototype.echo = function (numIterations, list) {
- var arg = list.item;
+ JsSideConnection.prototype.echo = function (numIterations, arg) {
var dataPipe1;
var dataPipe2;
var i;
var messagePipe1;
var messagePipe2;
- var resultList;
var specialArg;
// Ensure expected negative values are negative.
@@ -73,12 +71,7 @@ define('mojo/apps/js/test/js_to_cpp_unittest', [
writeDataPipe(dataPipe1, senderData);
writeDataPipe(dataPipe2, senderData);
- resultList = new jsToCpp.EchoArgsList();
- resultList.next = new jsToCpp.EchoArgsList();
- resultList.item = specialArg;
- resultList.next.item = arg;
-
- this.cppSide_.echoResponse(resultList);
+ this.cppSide_.echoResponse(createEchoArgsList(specialArg, arg));
core.close(dataPipe1.producerHandle);
core.close(dataPipe2.producerHandle);
@@ -92,8 +85,9 @@ define('mojo/apps/js/test/js_to_cpp_unittest', [
var iteration = 0;
var dataPipe;
var messagePipe;
- var stopSignalled = false;
var proto = connector.Connector.prototype;
+ var resultList;
+ var stopSignalled = false;
proto.realAccept = proto.accept;
proto.accept = function (message) {
@@ -116,7 +110,46 @@ define('mojo/apps/js/test/js_to_cpp_unittest', [
writeDataPipe(dataPipe, senderData);
arg.data_handle = dataPipe.consumerHandle;
arg.message_handle = messagePipe.handle1;
- this.cppSide_.bitFlipResponse(arg);
+ resultList = createEchoArgsList(arg);
+ this.cppSide_.bitFlipResponse(resultList);
+ core.close(dataPipe.producerHandle);
+ core.close(messagePipe.handle0);
+ iteration += 1;
+ }
+
+ proto.accept = proto.realAccept;
+ proto.realAccept = null;
+ this.cppSide_.testFinished();
+ };
+
+ JsSideConnection.prototype.backPointer = function (arg) {
+ var iteration = 0;
+ var dataPipe;
+ var messagePipe;
+ var proto = connector.Connector.prototype;
+ var resultList = createEchoArgsList(arg);
+ var stopSignalled = false;
+
+ proto.realAccept = proto.accept;
+ proto.accept = function (message) {
+ var delta = 8 * (1 + iteration % 32);
+ var offset = 8 * ((iteration / 32) | 0);
+ if (offset < message.buffer.arrayBuffer.byteLength - 4) {
+ message.buffer.dataView.setUint32(offset, 0x100000000 - delta, true);
+ message.buffer.dataView.setUint32(offset + 4, 0xffffffff, true);
+ return this.realAccept(message);
+ }
+ stopSignalled = true;
+ return false;
+ };
+
+ while (!stopSignalled) {
+ dataPipe = core.createDataPipe(DATA_PIPE_PARAMS);
+ messagePipe = core.createMessagePipe();
+ writeDataPipe(dataPipe, senderData);
+ arg.data_handle = dataPipe.consumerHandle;
+ arg.message_handle = messagePipe.handle1;
+ this.cppSide_.backPointerResponse(resultList);
core.close(dataPipe.producerHandle);
core.close(messagePipe.handle0);
iteration += 1;
@@ -142,6 +175,20 @@ define('mojo/apps/js/test/js_to_cpp_unittest', [
return true;
}
+ function createEchoArgsListElement(item, next) {
+ var list = new jsToCpp.EchoArgsList();
+ list.item = item;
+ list.next = next;
+ return list;
+ }
+
+ function createEchoArgsList() {
+ var genuineArray = Array.prototype.slice.call(arguments);
+ return genuineArray.reduceRight(function (previous, current) {
+ return createEchoArgsListElement(current, previous);
+ }, null);
+ }
+
return function(handle) {
var i;
senderData = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes);
« no previous file with comments | « mojo/apps/js/test/js_to_cpp_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698