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

Side by Side Diff: mojo/public/js/core_unittests.js

Issue 2131163002: [mojo] Add shared buffer support to mojo JavaScript bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initialize options.struct_size Created 4 years, 4 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
« no previous file with comments | « mojo/public/js/core.js ('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([ 5 define([
6 "gin/test/expect", 6 "gin/test/expect",
7 "mojo/public/js/core", 7 "mojo/public/js/core",
8 "gc", 8 "gc",
9 ], function(expect, core, gc) { 9 ], function(expect, core, gc) {
10 10
11 var HANDLE_SIGNAL_READWRITABLE = core.HANDLE_SIGNAL_WRITABLE | 11 var HANDLE_SIGNAL_READWRITABLE = core.HANDLE_SIGNAL_WRITABLE |
12 core.HANDLE_SIGNAL_READABLE; 12 core.HANDLE_SIGNAL_READABLE;
13 var HANDLE_SIGNAL_ALL = core.HANDLE_SIGNAL_WRITABLE | 13 var HANDLE_SIGNAL_ALL = core.HANDLE_SIGNAL_WRITABLE |
14 core.HANDLE_SIGNAL_READABLE | 14 core.HANDLE_SIGNAL_READABLE |
15 core.HANDLE_SIGNAL_PEER_CLOSED; 15 core.HANDLE_SIGNAL_PEER_CLOSED;
16 16
17 runWithMessagePipe(testNop); 17 runWithMessagePipe(testNop);
18 runWithMessagePipe(testReadAndWriteMessage); 18 runWithMessagePipe(testReadAndWriteMessage);
19 runWithMessagePipeWithOptions(testNop); 19 runWithMessagePipeWithOptions(testNop);
20 runWithMessagePipeWithOptions(testReadAndWriteMessage); 20 runWithMessagePipeWithOptions(testReadAndWriteMessage);
21 runWithDataPipe(testNop); 21 runWithDataPipe(testNop);
22 runWithDataPipe(testReadAndWriteDataPipe); 22 runWithDataPipe(testReadAndWriteDataPipe);
23 runWithDataPipeWithOptions(testNop); 23 runWithDataPipeWithOptions(testNop);
24 runWithDataPipeWithOptions(testReadAndWriteDataPipe); 24 runWithDataPipeWithOptions(testReadAndWriteDataPipe);
25 runWithMessagePipe(testIsHandleMessagePipe); 25 runWithMessagePipe(testIsHandleMessagePipe);
26 runWithDataPipe(testIsHandleDataPipe); 26 runWithDataPipe(testIsHandleDataPipe);
27 runWithSharedBuffer(testSharedBuffer);
27 gc.collectGarbage(); // should not crash 28 gc.collectGarbage(); // should not crash
28 this.result = "PASS"; 29 this.result = "PASS";
29 30
30 function runWithMessagePipe(test) { 31 function runWithMessagePipe(test) {
31 var pipe = core.createMessagePipe(); 32 var pipe = core.createMessagePipe();
32 expect(pipe.result).toBe(core.RESULT_OK); 33 expect(pipe.result).toBe(core.RESULT_OK);
33 34
34 test(pipe); 35 test(pipe);
35 36
36 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); 37 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK);
(...skipping 29 matching lines...) Expand all
66 capacityNumBytes: 64 67 capacityNumBytes: 64
67 }); 68 });
68 expect(pipe.result).toBe(core.RESULT_OK); 69 expect(pipe.result).toBe(core.RESULT_OK);
69 70
70 test(pipe); 71 test(pipe);
71 72
72 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK); 73 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
73 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK); 74 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
74 } 75 }
75 76
77 function runWithSharedBuffer(test) {
78 let buffer_size = 32;
79 let sharedBuffer = core.createSharedBuffer(buffer_size,
80 core.CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE);
81
82 expect(sharedBuffer.result).toBe(core.RESULT_OK);
83 expect(core.isHandle(sharedBuffer.handle)).toBeTruthy();
84
85 test(sharedBuffer, buffer_size);
86 }
87
76 function testNop(pipe) { 88 function testNop(pipe) {
77 } 89 }
78 90
79 function testReadAndWriteMessage(pipe) { 91 function testReadAndWriteMessage(pipe) {
80 var wait = core.waitMany([], [], 0); 92 var wait = core.waitMany([], [], 0);
81 expect(wait.result).toBe(core.RESULT_INVALID_ARGUMENT); 93 expect(wait.result).toBe(core.RESULT_INVALID_ARGUMENT);
82 expect(wait.index).toBe(null); 94 expect(wait.index).toBe(null);
83 expect(wait.signalsState).toBe(null); 95 expect(wait.signalsState).toBe(null);
84 96
85 wait = core.wait(pipe.handle0, core.HANDLE_SIGNAL_READABLE, 0); 97 wait = core.wait(pipe.handle0, core.HANDLE_SIGNAL_READABLE, 0);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 expect(core.isHandle(pipe.handle0)).toBeTruthy(); 200 expect(core.isHandle(pipe.handle0)).toBeTruthy();
189 expect(core.isHandle(pipe.handle1)).toBeTruthy(); 201 expect(core.isHandle(pipe.handle1)).toBeTruthy();
190 expect(core.isHandle(null)).toBeTruthy(); 202 expect(core.isHandle(null)).toBeTruthy();
191 } 203 }
192 204
193 function testIsHandleDataPipe(pipe) { 205 function testIsHandleDataPipe(pipe) {
194 expect(core.isHandle(pipe.consumerHandle)).toBeTruthy(); 206 expect(core.isHandle(pipe.consumerHandle)).toBeTruthy();
195 expect(core.isHandle(pipe.producerHandle)).toBeTruthy(); 207 expect(core.isHandle(pipe.producerHandle)).toBeTruthy();
196 } 208 }
197 209
210 function testSharedBuffer(sharedBuffer, buffer_size) {
211 let offset = 0;
212 let mappedBuffer0 = core.mapBuffer(sharedBuffer.handle,
213 offset,
214 buffer_size,
215 core.MAP_BUFFER_FLAG_NONE);
216
217 expect(mappedBuffer0.result).toBe(core.RESULT_OK);
218
219 let dupedBufferHandle = core.duplicateBufferHandle(sharedBuffer.handle,
220 core.DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE);
221
222 expect(dupedBufferHandle.result).toBe(core.RESULT_OK);
223 expect(core.isHandle(dupedBufferHandle.handle)).toBeTruthy();
224
225 let mappedBuffer1 = core.mapBuffer(dupedBufferHandle.handle,
226 offset,
227 buffer_size,
228 core.MAP_BUFFER_FLAG_NONE);
229
230 expect(mappedBuffer1.result).toBe(core.RESULT_OK);
231
232 let buffer0 = new Uint8Array(mappedBuffer0.buffer);
233 let buffer1 = new Uint8Array(mappedBuffer1.buffer);
234 for(let i = 0; i < buffer0.length; ++i) {
235 buffer0[i] = i;
236 expect(buffer1[i]).toBe(i);
237 }
238
239 expect(core.unmapBuffer(mappedBuffer0.buffer)).toBe(core.RESULT_OK);
240 expect(core.unmapBuffer(mappedBuffer1.buffer)).toBe(core.RESULT_OK);
241
242 expect(core.close(dupedBufferHandle.handle)).toBe(core.RESULT_OK);
243 expect(core.close(sharedBuffer.handle)).toBe(core.RESULT_OK);
244 }
245
198 }); 246 });
OLDNEW
« no previous file with comments | « mojo/public/js/core.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698