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", |
| 7 "mojo/public/bindings/js/test/hexdump", |
6 "gtest", | 8 "gtest", |
7 // TODO(abarth): We shouldn't need to depend on codec, but there seems to | 9 // TODO(abarth): We shouldn't need to depend on codec, but there seems to |
8 // be a bug in the module loading system whereby this test doesn't run if | 10 // be a bug in the module loading system whereby this test doesn't run if |
9 // we don't import codec here. | 11 // we don't import codec here. |
10 "mojo/public/bindings/js/codec", | 12 "mojo/public/bindings/js/codec", |
11 "mojo/public/bindings/sample/mojom/sample_service" | 13 "mojo/public/bindings/sample/mojom/sample_service" |
12 ], function(gtest, codec, sample) { | 14 ], function(console, hexdump, gtest, codec, sample) { |
13 | 15 |
14 var global = this; | 16 var global = this; |
15 | 17 |
| 18 // Set this variable to true to print the binary message in hex. |
| 19 var dumpMessageAsHex = false; |
| 20 |
16 function makeFoo() { | 21 function makeFoo() { |
17 var bar = new sample.Bar(); | 22 var bar = new sample.Bar(); |
18 bar.alpha = 20; | 23 bar.alpha = 20; |
19 bar.beta = 40; | 24 bar.beta = 40; |
20 bar.gamma = 60; | 25 bar.gamma = 60; |
21 | 26 |
22 var extra_bars = new Array(3); | 27 var extra_bars = new Array(3); |
23 for (var i = 0; i < extra_bars.length; ++i) { | 28 for (var i = 0; i < extra_bars.length; ++i) { |
24 var base = i * 100; | 29 var base = i * 100; |
25 extra_bars[i] = new sample.Bar(); | 30 extra_bars[i] = new sample.Bar(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 checkFoo(foo); | 105 checkFoo(foo); |
101 gtest.expectTrue(baz, "baz is " + baz); | 106 gtest.expectTrue(baz, "baz is " + baz); |
102 gtest.expectEqual(port, 10, "port is " + port); | 107 gtest.expectEqual(port, 10, "port is " + port); |
103 global.result = "PASS"; | 108 global.result = "PASS"; |
104 }; | 109 }; |
105 | 110 |
106 function SimpleMessageReceiver() { | 111 function SimpleMessageReceiver() { |
107 } | 112 } |
108 | 113 |
109 SimpleMessageReceiver.prototype.accept = function(message) { | 114 SimpleMessageReceiver.prototype.accept = function(message) { |
| 115 if (dumpMessageAsHex) |
| 116 console.log(hexdump.dumpArray(message.memory)); |
110 // Imagine some IPC happened here. | 117 // Imagine some IPC happened here. |
111 var serviceImpl = new ServiceImpl(); | 118 var serviceImpl = new ServiceImpl(); |
112 serviceImpl.accept(message); | 119 serviceImpl.accept(message); |
113 }; | 120 }; |
114 | 121 |
115 var receiver = new SimpleMessageReceiver(); | 122 var receiver = new SimpleMessageReceiver(); |
116 var serviceProxy = new sample.ServiceProxy(receiver); | 123 var serviceProxy = new sample.ServiceProxy(receiver); |
117 | 124 |
118 var foo = makeFoo(); | 125 var foo = makeFoo(); |
119 checkFoo(foo); | 126 checkFoo(foo); |
120 | 127 |
121 var port = 10; | 128 var port = 10; |
122 serviceProxy.frobinate(foo, true, port); | 129 serviceProxy.frobinate(foo, true, port); |
123 }); | 130 }); |
OLD | NEW |