OLD | NEW |
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 'console', | 6 'console', |
7 'mojo/apps/js/test/js_to_cpp.mojom', | 7 'mojo/apps/js/test/js_to_cpp.mojom', |
8 'mojo/public/js/bindings/connection', | 8 'mojo/public/js/bindings/connection', |
9 'mojo/public/js/bindings/connector', | 9 'mojo/public/js/bindings/connector', |
10 'mojo/public/js/bindings/core', | 10 'mojo/public/js/bindings/core', |
(...skipping 11 matching lines...) Expand all Loading... |
22 this.cppSide_ = cppSide; | 22 this.cppSide_ = cppSide; |
23 cppSide.startTest(); | 23 cppSide.startTest(); |
24 } | 24 } |
25 | 25 |
26 JsSideConnection.prototype = Object.create(jsToCpp.JsSideStub.prototype); | 26 JsSideConnection.prototype = Object.create(jsToCpp.JsSideStub.prototype); |
27 | 27 |
28 JsSideConnection.prototype.ping = function (arg) { | 28 JsSideConnection.prototype.ping = function (arg) { |
29 this.cppSide_.pingResponse(); | 29 this.cppSide_.pingResponse(); |
30 }; | 30 }; |
31 | 31 |
32 JsSideConnection.prototype.echo = function (numIterations, arg) { | 32 JsSideConnection.prototype.echo = function (numIterations, list) { |
33 var arg2; | 33 var arg = list.item; |
34 var dataPipe1; | 34 var dataPipe1; |
35 var dataPipe2; | 35 var dataPipe2; |
36 var i; | 36 var i; |
37 var messagePipe1; | 37 var messagePipe1; |
38 var messagePipe2; | 38 var messagePipe2; |
| 39 var resultList; |
| 40 var specialArg; |
39 | 41 |
40 // Ensure expected negative values are negative. | 42 // Ensure expected negative values are negative. |
41 if (arg.si64 > 0) | 43 if (arg.si64 > 0) |
42 arg.si64 = BAD_VALUE; | 44 arg.si64 = BAD_VALUE; |
43 | 45 |
44 if (arg.si32 > 0) | 46 if (arg.si32 > 0) |
45 arg.si32 = BAD_VALUE; | 47 arg.si32 = BAD_VALUE; |
46 | 48 |
47 if (arg.si16 > 0) | 49 if (arg.si16 > 0) |
48 arg.si16 = BAD_VALUE; | 50 arg.si16 = BAD_VALUE; |
49 | 51 |
50 if (arg.si8 > 0) | 52 if (arg.si8 > 0) |
51 arg.si8 = BAD_VALUE; | 53 arg.si8 = BAD_VALUE; |
52 | 54 |
53 for (i = 0; i < numIterations; ++i) { | 55 for (i = 0; i < numIterations; ++i) { |
54 dataPipe1 = core.createDataPipe(DATA_PIPE_PARAMS); | 56 dataPipe1 = core.createDataPipe(DATA_PIPE_PARAMS); |
55 dataPipe2 = core.createDataPipe(DATA_PIPE_PARAMS); | 57 dataPipe2 = core.createDataPipe(DATA_PIPE_PARAMS); |
56 messagePipe1 = core.createMessagePipe(); | 58 messagePipe1 = core.createMessagePipe(); |
57 messagePipe2 = core.createMessagePipe(); | 59 messagePipe2 = core.createMessagePipe(); |
58 | 60 |
59 arg.data_handle = dataPipe1.consumerHandle; | 61 arg.data_handle = dataPipe1.consumerHandle; |
60 arg.message_handle = messagePipe1.handle1; | 62 arg.message_handle = messagePipe1.handle1; |
61 | 63 |
62 arg2 = new jsToCpp.EchoArgs(); | 64 specialArg = new jsToCpp.EchoArgs(); |
63 arg2.si64 = -1; | 65 specialArg.si64 = -1; |
64 arg2.si32 = -1; | 66 specialArg.si32 = -1; |
65 arg2.si16 = -1; | 67 specialArg.si16 = -1; |
66 arg2.si8 = -1; | 68 specialArg.si8 = -1; |
67 arg2.name = 'going'; | 69 specialArg.name = 'going'; |
68 arg2.data_handle = dataPipe2.consumerHandle; | 70 specialArg.data_handle = dataPipe2.consumerHandle; |
69 arg2.message_handle = messagePipe2.handle1; | 71 specialArg.message_handle = messagePipe2.handle1; |
70 | 72 |
71 writeDataPipe(dataPipe1, senderData); | 73 writeDataPipe(dataPipe1, senderData); |
72 writeDataPipe(dataPipe2, senderData); | 74 writeDataPipe(dataPipe2, senderData); |
73 this.cppSide_.echoResponse(arg, arg2); | 75 |
| 76 resultList = new jsToCpp.EchoArgsList(); |
| 77 resultList.next = new jsToCpp.EchoArgsList(); |
| 78 resultList.item = specialArg; |
| 79 resultList.next.item = arg; |
| 80 |
| 81 this.cppSide_.echoResponse(resultList); |
74 | 82 |
75 core.close(dataPipe1.producerHandle); | 83 core.close(dataPipe1.producerHandle); |
76 core.close(dataPipe2.producerHandle); | 84 core.close(dataPipe2.producerHandle); |
77 core.close(messagePipe1.handle0); | 85 core.close(messagePipe1.handle0); |
78 core.close(messagePipe2.handle0); | 86 core.close(messagePipe2.handle0); |
79 } | 87 } |
80 this.cppSide_.testFinished(); | 88 this.cppSide_.testFinished(); |
81 }; | 89 }; |
82 | 90 |
83 JsSideConnection.prototype.bitFlip = function (arg) { | 91 JsSideConnection.prototype.bitFlip = function (arg) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 return function(handle) { | 145 return function(handle) { |
138 var i; | 146 var i; |
139 senderData = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes); | 147 senderData = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes); |
140 for (i = 0; i < senderData.length; ++i) | 148 for (i = 0; i < senderData.length; ++i) |
141 senderData[i] = i; | 149 senderData[i] = i; |
142 | 150 |
143 retainedConnection = new connection.Connection(handle, JsSideConnection, | 151 retainedConnection = new connection.Connection(handle, JsSideConnection, |
144 jsToCpp.CppSideProxy); | 152 jsToCpp.CppSideProxy); |
145 }; | 153 }; |
146 }); | 154 }); |
OLD | NEW |