OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bindings/core", | 7 "mojo/public/js/bindings/core", |
8 "gc", | 8 "gc", |
9 ], function(expect, core, gc) { | 9 ], function(expect, core, gc) { |
10 runWithMessagePipe(testNop); | 10 runWithMessagePipe(testNop); |
11 runWithMessagePipe(testReadAndWriteMessage); | 11 runWithMessagePipe(testReadAndWriteMessage); |
| 12 runWithMessagePipeWithOptions(testNop); |
| 13 runWithMessagePipeWithOptions(testReadAndWriteMessage); |
12 runWithDataPipe(testNop); | 14 runWithDataPipe(testNop); |
13 runWithDataPipe(testReadAndWriteDataPipe); | 15 runWithDataPipe(testReadAndWriteDataPipe); |
| 16 runWithDataPipeWithOptions(testNop); |
| 17 runWithDataPipeWithOptions(testReadAndWriteDataPipe); |
14 gc.collectGarbage(); // should not crash | 18 gc.collectGarbage(); // should not crash |
15 this.result = "PASS"; | 19 this.result = "PASS"; |
16 | 20 |
17 function runWithMessagePipe(test) { | 21 function runWithMessagePipe(test) { |
18 var pipe = core.createMessagePipe(); | 22 var pipe = core.createMessagePipe(); |
| 23 expect(pipe.result).toBe(core.RESULT_OK); |
19 | 24 |
20 test(pipe); | 25 test(pipe); |
21 | 26 |
| 27 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); |
| 28 expect(core.close(pipe.handle1)).toBe(core.RESULT_OK); |
| 29 } |
| 30 |
| 31 function runWithMessagePipeWithOptions(test) { |
| 32 var pipe = core.createMessagePipe({ |
| 33 flags: core.CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE |
| 34 }); |
| 35 expect(pipe.result).toBe(core.RESULT_OK); |
| 36 |
| 37 test(pipe); |
| 38 |
22 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); | 39 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); |
23 expect(core.close(pipe.handle1)).toBe(core.RESULT_OK); | 40 expect(core.close(pipe.handle1)).toBe(core.RESULT_OK); |
24 } | 41 } |
25 | 42 |
26 function runWithDataPipe(test) { | 43 function runWithDataPipe(test) { |
| 44 var pipe = core.createDataPipe(); |
| 45 expect(pipe.result).toBe(core.RESULT_OK); |
| 46 |
| 47 test(pipe); |
| 48 |
| 49 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK); |
| 50 expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK); |
| 51 } |
| 52 |
| 53 function runWithDataPipeWithOptions(test) { |
27 var pipe = core.createDataPipe({ | 54 var pipe = core.createDataPipe({ |
28 flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, | 55 flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, |
29 elementNumBytes: 1, | 56 elementNumBytes: 1, |
30 capacityNumBytes: 64 | 57 capacityNumBytes: 64 |
31 }); | 58 }); |
32 expect(pipe.result).toBe(core.RESULT_OK); | 59 expect(pipe.result).toBe(core.RESULT_OK); |
33 | 60 |
34 test(pipe); | 61 test(pipe); |
35 | 62 |
36 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK); | 63 expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 109 |
83 expect(read.result).toBe(core.RESULT_OK); | 110 expect(read.result).toBe(core.RESULT_OK); |
84 expect(read.buffer.byteLength).toBe(42); | 111 expect(read.buffer.byteLength).toBe(42); |
85 | 112 |
86 var memory = new Uint8Array(read.buffer); | 113 var memory = new Uint8Array(read.buffer); |
87 for (var i = 0; i < memory.length; ++i) | 114 for (var i = 0; i < memory.length; ++i) |
88 expect(memory[i]).toBe((i * i) & 0xFF); | 115 expect(memory[i]).toBe((i * i) & 0xFF); |
89 } | 116 } |
90 | 117 |
91 }); | 118 }); |
OLD | NEW |