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

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

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