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

Side by Side Diff: mojo/apps/js/test/js_to_cpp_unittest.js

Issue 267343006: Pass data down pipes in mojo fuzzing tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase on clean branch. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/apps/js/test/js_to_cpp_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 define("mojo/apps/js/test/js_to_cpp_unittest", [ 5 define('mojo/apps/js/test/js_to_cpp_unittest', [
6 "mojo/apps/js/test/js_to_cpp.mojom", 6 'console',
7 "mojo/public/js/bindings/connection", 7 'mojo/apps/js/test/js_to_cpp.mojom',
8 "mojo/public/js/bindings/connector", 8 'mojo/public/js/bindings/connection',
9 "mojo/public/js/bindings/core", 9 'mojo/public/js/bindings/connector',
10 ], function (jsToCpp, connection, connector, core) { 10 'mojo/public/js/bindings/core',
11 ], function (console, jsToCpp, connection, connector, core) {
11 var retainedConnection; 12 var retainedConnection;
13 var senderData;
12 var BAD_VALUE = 13; 14 var BAD_VALUE = 13;
13 var DATA_PIPE_PARAMS = { 15 var DATA_PIPE_PARAMS = {
14 flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, 16 flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
15 elementNumBytes: 1, 17 elementNumBytes: 1,
16 capacityNumBytes: 64 18 capacityNumBytes: 64
17 }; 19 };
18 20
19 function JsSideConnection(cppSide) { 21 function JsSideConnection(cppSide) {
20 this.cppSide_ = cppSide; 22 this.cppSide_ = cppSide;
21 cppSide.startTest(); 23 cppSide.startTest();
22 } 24 }
23 25
24 JsSideConnection.prototype = Object.create(jsToCpp.JsSideStub.prototype); 26 JsSideConnection.prototype = Object.create(jsToCpp.JsSideStub.prototype);
25 27
26 JsSideConnection.prototype.ping = function (arg) { 28 JsSideConnection.prototype.ping = function (arg) {
27 this.cppSide_.pingResponse(); 29 this.cppSide_.pingResponse();
28 }; 30 };
29 31
30 JsSideConnection.prototype.echo = function (numIterations, arg) { 32 JsSideConnection.prototype.echo = function (numIterations, arg) {
31 var arg2; 33 var arg2;
32 var data_pipe1; 34 var dataPipe1;
33 var data_pipe2; 35 var dataPipe2;
34 var i; 36 var i;
35 var message_pipe1; 37 var messagePipe1;
36 var message_pipe2; 38 var messagePipe2;
37 39
38 // Ensure expected negative values are negative. 40 // Ensure expected negative values are negative.
39 if (arg.si64 > 0) 41 if (arg.si64 > 0)
40 arg.si64 = BAD_VALUE; 42 arg.si64 = BAD_VALUE;
41 43
42 if (arg.si32 > 0) 44 if (arg.si32 > 0)
43 arg.si32 = BAD_VALUE; 45 arg.si32 = BAD_VALUE;
44 46
45 if (arg.si16 > 0) 47 if (arg.si16 > 0)
46 arg.si16 = BAD_VALUE; 48 arg.si16 = BAD_VALUE;
47 49
48 if (arg.si8 > 0) 50 if (arg.si8 > 0)
49 arg.si8 = BAD_VALUE; 51 arg.si8 = BAD_VALUE;
50 52
51 for (i = 0; i < numIterations; ++i) { 53 for (i = 0; i < numIterations; ++i) {
52 data_pipe1 = core.createDataPipe(DATA_PIPE_PARAMS); 54 dataPipe1 = core.createDataPipe(DATA_PIPE_PARAMS);
53 data_pipe2 = core.createDataPipe(DATA_PIPE_PARAMS); 55 dataPipe2 = core.createDataPipe(DATA_PIPE_PARAMS);
54 message_pipe1 = core.createMessagePipe(); 56 messagePipe1 = core.createMessagePipe();
55 message_pipe2 = core.createMessagePipe(); 57 messagePipe2 = core.createMessagePipe();
56 58
57 arg.data_handle = data_pipe1.consumerHandle; 59 arg.data_handle = dataPipe1.consumerHandle;
58 arg.message_handle = message_pipe1.handle1; 60 arg.message_handle = messagePipe1.handle1;
59 61
60 arg2 = new jsToCpp.EchoArgs(); 62 arg2 = new jsToCpp.EchoArgs();
61 arg2.si64 = -1; 63 arg2.si64 = -1;
62 arg2.si32 = -1; 64 arg2.si32 = -1;
63 arg2.si16 = -1; 65 arg2.si16 = -1;
64 arg2.si8 = -1; 66 arg2.si8 = -1;
65 arg2.name = "going"; 67 arg2.name = 'going';
66 arg2.data_handle = data_pipe2.consumerHandle; 68 arg2.data_handle = dataPipe2.consumerHandle;
67 arg2.message_handle = message_pipe2.handle1; 69 arg2.message_handle = messagePipe2.handle1;
68 70
71 writeDataPipe(dataPipe1, senderData);
72 writeDataPipe(dataPipe2, senderData);
69 this.cppSide_.echoResponse(arg, arg2); 73 this.cppSide_.echoResponse(arg, arg2);
70 74
71 core.close(data_pipe1.producerHandle); 75 core.close(dataPipe1.producerHandle);
72 core.close(data_pipe2.producerHandle); 76 core.close(dataPipe2.producerHandle);
73 core.close(message_pipe1.handle0); 77 core.close(messagePipe1.handle0);
74 core.close(message_pipe2.handle0); 78 core.close(messagePipe2.handle0);
75 } 79 }
76 this.cppSide_.testFinished(); 80 this.cppSide_.testFinished();
77 }; 81 };
78 82
79 JsSideConnection.prototype.bitFlip = function (arg) { 83 JsSideConnection.prototype.bitFlip = function (arg) {
80 var iteration = 0; 84 var iteration = 0;
81 var data_pipe; 85 var dataPipe;
82 var message_pipe; 86 var messagePipe;
83 var stopSignalled = false; 87 var stopSignalled = false;
84 var proto = connector.Connector.prototype; 88 var proto = connector.Connector.prototype;
89
85 proto.realAccept = proto.accept; 90 proto.realAccept = proto.accept;
86 proto.accept = function (message) { 91 proto.accept = function (message) {
87 var offset = iteration / 8; 92 var offset = iteration / 8;
88 var mask; 93 var mask;
89 var value; 94 var value;
90 if (offset < message.buffer.arrayBuffer.byteLength) { 95 if (offset < message.buffer.arrayBuffer.byteLength) {
91 mask = 1 << (iteration % 8); 96 mask = 1 << (iteration % 8);
92 value = message.buffer.dataView.getUint8(offset) ^ mask; 97 value = message.buffer.dataView.getUint8(offset) ^ mask;
93 message.buffer.dataView.setUint8(offset, value); 98 message.buffer.dataView.setUint8(offset, value);
94 return this.realAccept(message); 99 return this.realAccept(message);
95 } 100 }
96 stopSignalled = true; 101 stopSignalled = true;
97 return false; 102 return false;
98 }; 103 };
104
99 while (!stopSignalled) { 105 while (!stopSignalled) {
100 data_pipe = core.createDataPipe(DATA_PIPE_PARAMS); 106 dataPipe = core.createDataPipe(DATA_PIPE_PARAMS);
101 message_pipe = core.createMessagePipe(); 107 messagePipe = core.createMessagePipe();
102 arg.data_handle = data_pipe.consumerHandle; 108 writeDataPipe(dataPipe, senderData);
103 arg.message_handle = message_pipe.handle1; 109 arg.data_handle = dataPipe.consumerHandle;
110 arg.message_handle = messagePipe.handle1;
104 this.cppSide_.bitFlipResponse(arg); 111 this.cppSide_.bitFlipResponse(arg);
105 core.close(data_pipe.producerHandle); 112 core.close(dataPipe.producerHandle);
106 core.close(message_pipe.handle0); 113 core.close(messagePipe.handle0);
107 iteration += 1; 114 iteration += 1;
108 } 115 }
116
109 proto.accept = proto.realAccept; 117 proto.accept = proto.realAccept;
110 proto.realAccept = null; 118 proto.realAccept = null;
111 this.cppSide_.testFinished(); 119 this.cppSide_.testFinished();
112 }; 120 };
113 121
122 function writeDataPipe(pipe, data) {
123 var writeResult = core.writeData(
124 pipe.producerHandle, data, core.WRITE_DATA_FLAG_ALL_OR_NONE);
125
126 if (writeResult.result != core.RESULT_OK) {
127 console.log('ERROR: Write result was ' + writeResult.result);
128 return false;
129 }
130 if (writeResult.numBytes != data.length) {
131 console.log('ERROR: Write length was ' + writeResult.numBytes);
132 return false;
133 }
134 return true;
135 }
136
114 return function(handle) { 137 return function(handle) {
138 var i;
139 senderData = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes);
140 for (i = 0; i < senderData.length; ++i)
141 senderData[i] = i;
142
115 retainedConnection = new connection.Connection(handle, JsSideConnection, 143 retainedConnection = new connection.Connection(handle, JsSideConnection,
116 jsToCpp.CppSideProxy); 144 jsToCpp.CppSideProxy);
117 }; 145 };
118 }); 146 });
OLDNEW
« 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