| 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 "console", | 6 "console", |
| 7 "mojo/edk/js/test/hexdump", | 7 "mojo/edk/js/test/hexdump", |
| 8 "gin/test/expect", | 8 "gin/test/expect", |
| 9 "mojo/public/interfaces/bindings/tests/sample_service.mojom", | 9 "mojo/public/interfaces/bindings/tests/sample_service.mojom", |
| 10 "mojo/public/interfaces/bindings/tests/sample_import.mojom", | 10 "mojo/public/interfaces/bindings/tests/sample_import.mojom", |
| 11 "mojo/public/interfaces/bindings/tests/sample_import2.mojom", | 11 "mojo/public/interfaces/bindings/tests/sample_import2.mojom", |
| 12 ], function(console, hexdump, expect, sample, imported, imported2) { | 12 "mojo/public/js/core", |
| 13 ], function(console, hexdump, expect, sample, imported, imported2, core) { |
| 13 | 14 |
| 14 var global = this; | 15 var global = this; |
| 15 | 16 |
| 16 // Set this variable to true to print the binary message in hex. | 17 // Set this variable to true to print the binary message in hex. |
| 17 var dumpMessageAsHex = false; | 18 var dumpMessageAsHex = false; |
| 18 | 19 |
| 19 function makeFoo() { | 20 function makeFoo() { |
| 20 var bar = new sample.Bar(); | 21 var bar = new sample.Bar(); |
| 21 bar.alpha = 20; | 22 bar.alpha = 20; |
| 22 bar.beta = 40; | 23 bar.beta = 40; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 132 } |
| 132 | 133 |
| 133 function ServiceImpl() { | 134 function ServiceImpl() { |
| 134 } | 135 } |
| 135 | 136 |
| 136 ServiceImpl.prototype = Object.create(sample.Service.stubClass.prototype); | 137 ServiceImpl.prototype = Object.create(sample.Service.stubClass.prototype); |
| 137 | 138 |
| 138 ServiceImpl.prototype.frobinate = function(foo, baz, port) { | 139 ServiceImpl.prototype.frobinate = function(foo, baz, port) { |
| 139 checkFoo(foo); | 140 checkFoo(foo); |
| 140 expect(baz).toBe(sample.Service.BazOptions.EXTRA); | 141 expect(baz).toBe(sample.Service.BazOptions.EXTRA); |
| 141 expect(port).toBe(10); | 142 expect(core.isHandle(port)).toBeTruthy(); |
| 142 global.result = "PASS"; | 143 global.result = "PASS"; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 function SimpleMessageReceiver() { | 146 function SimpleMessageReceiver() { |
| 146 } | 147 } |
| 147 | 148 |
| 148 SimpleMessageReceiver.prototype.accept = function(message) { | 149 SimpleMessageReceiver.prototype.accept = function(message) { |
| 149 if (dumpMessageAsHex) { | 150 if (dumpMessageAsHex) { |
| 150 var uint8Array = new Uint8Array(message.buffer.arrayBuffer); | 151 var uint8Array = new Uint8Array(message.buffer.arrayBuffer); |
| 151 console.log(hexdump.dumpArray(uint8Array)); | 152 console.log(hexdump.dumpArray(uint8Array)); |
| 152 } | 153 } |
| 153 // Imagine some IPC happened here. | 154 // Imagine some IPC happened here. |
| 154 var serviceImpl = new ServiceImpl(); | 155 var serviceImpl = new ServiceImpl(); |
| 155 serviceImpl.accept(message); | 156 serviceImpl.accept(message); |
| 156 }; | 157 }; |
| 157 | 158 |
| 158 var serviceProxy = new sample.Service.proxyClass; | 159 var serviceProxy = new sample.Service.proxyClass; |
| 159 serviceProxy.receiver_ = new SimpleMessageReceiver; | 160 serviceProxy.receiver_ = new SimpleMessageReceiver; |
| 160 | 161 |
| 161 checkDefaultValues(); | 162 checkDefaultValues(); |
| 162 | 163 |
| 163 var foo = makeFoo(); | 164 var foo = makeFoo(); |
| 164 checkFoo(foo); | 165 checkFoo(foo); |
| 165 | 166 |
| 166 var port = 10; | 167 var pipe = core.createMessagePipe(); |
| 167 serviceProxy.frobinate(foo, sample.Service.BazOptions.EXTRA, port); | 168 serviceProxy.frobinate(foo, sample.Service.BazOptions.EXTRA, pipe.handle0); |
| 169 expect(core.close(pipe.handle0)).toBe(core.RESULT_OK); |
| 170 expect(core.close(pipe.handle1)).toBe(core.RESULT_OK); |
| 168 }); | 171 }); |
| OLD | NEW |