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

Side by Side Diff: third_party/WebKit/Source/core/mojo/tests/JsToCppTest.js

Issue 2920383004: Reland of Moves mojo_js_integration_tests into blink. (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 (function () {
6 var retainedJsSide;
7 var sampleData;
8 var sampleMessage;
9 var BAD_VALUE = 13;
10 var DATA_PIPE_PARAMS = {
11 elementNumBytes: 1,
12 capacityNumBytes: 64
13 };
14
15 function JsSideConnection() {
16 this.binding = new mojo.Binding(jsToCpp.JsSide, this);
17 }
18
19 JsSideConnection.prototype.setCppSide = function(cppSide) {
20 this.cppSide_ = cppSide;
21 this.cppSide_.startTest();
22 };
23
24 JsSideConnection.prototype.ping = function (arg) {
25 this.cppSide_.pingResponse();
26 };
27
28 JsSideConnection.prototype.echo = function (numIterations, arg) {
29 var dataPipe1;
30 var dataPipe2;
31 var i;
32 var messagePipe1;
33 var messagePipe2;
34 var specialArg;
35
36 // Ensure expected negative values are negative.
37 if (arg.si64 > 0)
38 arg.si64 = BAD_VALUE;
39
40 if (arg.si32 > 0)
41 arg.si32 = BAD_VALUE;
42
43 if (arg.si16 > 0)
44 arg.si16 = BAD_VALUE;
45
46 if (arg.si8 > 0)
47 arg.si8 = BAD_VALUE;
48
49 for (i = 0; i < numIterations; ++i) {
50 dataPipe1 = Mojo.createDataPipe(DATA_PIPE_PARAMS);
51 dataPipe2 = Mojo.createDataPipe(DATA_PIPE_PARAMS);
52 messagePipe1 = Mojo.createMessagePipe();
53 messagePipe2 = Mojo.createMessagePipe();
54
55 arg.dataHandle = dataPipe1.consumer;
56 arg.messageHandle = messagePipe1.handle1;
57
58 specialArg = new jsToCpp.EchoArgs();
59 specialArg.si64 = -1;
60 specialArg.si32 = -1;
61 specialArg.si16 = -1;
62 specialArg.si8 = -1;
63 specialArg.name = 'going';
64 specialArg.dataHandle = dataPipe2.consumer;
65 specialArg.messageHandle = messagePipe2.handle1;
66
67 writeDataPipe(dataPipe1, sampleData);
68 writeDataPipe(dataPipe2, sampleData);
69 writeMessagePipe(messagePipe1, sampleMessage);
70 writeMessagePipe(messagePipe2, sampleMessage);
71 this.cppSide_.echoResponse(createEchoArgsList(specialArg, arg));
72
73 dataPipe1.producer.close();
74 dataPipe2.producer.close();
75 messagePipe1.handle0.close();
76 messagePipe2.handle0.close();
77 }
78 this.cppSide_.testFinished();
79 };
80
81 JsSideConnection.prototype.bitFlip = function (arg) {
82 var iteration = 0;
83 var dataPipe;
84 var messagePipe;
85 var proto = mojo.internal.Connector.prototype;
86 var stopSignalled = false;
87
88 proto.realAccept = proto.accept;
89 proto.accept = function (message) {
90 var offset = iteration / 8;
91 var mask;
92 var value;
93 if (offset < message.buffer.arrayBuffer.byteLength) {
94 mask = 1 << (iteration % 8);
95 value = message.buffer.getUint8(offset) ^ mask;
96 message.buffer.setUint8(offset, value);
97 return this.realAccept(message);
98 }
99 stopSignalled = true;
100 return false;
101 };
102
103 while (!stopSignalled) {
104 messagePipe = Mojo.createMessagePipe();
105 writeMessagePipe(messagePipe, sampleMessage);
106 arg.messageHandle = messagePipe.handle1;
107
108 this.cppSide_.bitFlipResponse(createEchoArgsList(arg), null);
109
110 messagePipe.handle0.close();
111 iteration += 1;
112 }
113
114 proto.accept = proto.realAccept;
115 proto.realAccept = null;
116 this.cppSide_.testFinished();
117 };
118
119 JsSideConnection.prototype.backPointer = function (arg) {
120 var iteration = 0;
121 var dataPipe;
122 var messagePipe;
123 var proto = mojo.internal.Connector.prototype;
124 var stopSignalled = false;
125
126 proto.realAccept = proto.accept;
127 proto.accept = function (message) {
128 var delta = 8 * (1 + iteration % 32);
129 var offset = 8 * ((iteration / 32) | 0);
130 if (offset < message.buffer.arrayBuffer.byteLength - 4) {
131 message.buffer.dataView.setUint32(offset, 0x100000000 - delta, true);
132 message.buffer.dataView.setUint32(offset + 4, 0xffffffff, true);
133 return this.realAccept(message);
134 }
135 stopSignalled = true;
136 return false;
137 };
138
139 while (!stopSignalled) {
140 messagePipe = Mojo.createMessagePipe();
141 writeMessagePipe(messagePipe, sampleMessage);
142 arg.messageHandle = messagePipe.handle1;
143
144 this.cppSide_.backPointerResponse(createEchoArgsList(arg));
145
146 messagePipe.handle0.close();
147 iteration += 1;
148 }
149
150 proto.accept = proto.realAccept;
151 proto.realAccept = null;
152 this.cppSide_.testFinished();
153 };
154
155 function writeDataPipe(pipe, data) {
156 var writeResult = pipe.producer.writeData(data);
157
158 if (writeResult.result != Mojo.RESULT_OK) {
159 console.log('ERROR: Data pipe write result was ' + writeResult.result);
160 return false;
161 }
162 if (writeResult.numBytes != data.length) {
163 console.log('ERROR: Data pipe write length was ' + writeResult.numBytes);
164 return false;
165 }
166 return true;
167 }
168
169 function writeMessagePipe(pipe, arrayBuffer) {
170 var result = pipe.handle0.writeMessage(arrayBuffer, []);
171 if (result != Mojo.RESULT_OK) {
172 console.log('ERROR: Message pipe write result was ' + result);
173 return false;
174 }
175 return true;
176 }
177
178 function createEchoArgsListElement(item, next) {
179 var list = new jsToCpp.EchoArgsList();
180 list.item = item;
181 list.next = next;
182 return list;
183 }
184
185 function createEchoArgsList() {
186 var genuineArray = Array.prototype.slice.call(arguments);
187 return genuineArray.reduceRight(function (previous, current) {
188 return createEchoArgsListElement(current, previous);
189 }, null);
190 }
191
192 return function(jsSideRequestHandle) {
193 var i;
194 sampleData = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes);
195 for (i = 0; i < sampleData.length; ++i) {
196 sampleData[i] = i;
197 }
198 sampleMessage = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes);
199 for (i = 0; i < sampleMessage.length; ++i) {
200 sampleMessage[i] = 255 - i;
201 }
202 retainedJsSide = new JsSideConnection;
203 retainedJsSide.binding.bind(jsSideRequestHandle);
204 };
205 })();
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/mojo/tests/JsToCppTest.cpp ('k') | third_party/WebKit/Source/core/mojo/tests/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698