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([ | 5 define([ |
6 "gin/test/expect", | 6 "gin/test/expect", |
7 "mojo/public/js/codec", | 7 "mojo/public/js/codec", |
8 "mojo/public/interfaces/bindings/tests/rect.mojom", | 8 "mojo/public/interfaces/bindings/tests/rect.mojom", |
9 "mojo/public/interfaces/bindings/tests/sample_service.mojom", | 9 "mojo/public/interfaces/bindings/tests/sample_service.mojom", |
10 "mojo/public/interfaces/bindings/tests/test_structs.mojom", | 10 "mojo/public/interfaces/bindings/tests/test_structs.mojom", |
11 ], function(expect, codec, rect, sample, structs) { | 11 ], function(expect, codec, rect, sample, structs) { |
12 testBar(); | 12 testBar(); |
13 testFoo(); | 13 testFoo(); |
14 testNamedRegion(); | 14 testNamedRegion(); |
15 testTypes(); | 15 testTypes(); |
16 testAlign(); | 16 testAlign(); |
17 testUtf8(); | 17 testUtf8(); |
18 testArrayPointerValidation(); | 18 testTypedPointerValidation(); |
19 this.result = "PASS"; | 19 this.result = "PASS"; |
20 | 20 |
21 function testBar() { | 21 function testBar() { |
22 var bar = new sample.Bar(); | 22 var bar = new sample.Bar(); |
23 bar.alpha = 1; | 23 bar.alpha = 1; |
24 bar.beta = 2; | 24 bar.beta = 2; |
25 bar.gamma = 3; | 25 bar.gamma = 3; |
26 bar.type = 0x08070605; | 26 bar.type = 0x08070605; |
27 bar.extraProperty = "banana"; | 27 bar.extraProperty = "banana"; |
28 | 28 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 expect(actualMemory.length).toEqual(expectedMemory.length); | 250 expect(actualMemory.length).toEqual(expectedMemory.length); |
251 expect(actualMemory).toEqual(expectedMemory); | 251 expect(actualMemory).toEqual(expectedMemory); |
252 | 252 |
253 var reader = new codec.MessageReader(message); | 253 var reader = new codec.MessageReader(message); |
254 expect(reader.payloadSize).toBe(payloadSize); | 254 expect(reader.payloadSize).toBe(payloadSize); |
255 expect(reader.messageName).toBe(messageName); | 255 expect(reader.messageName).toBe(messageName); |
256 var str2 = reader.decoder.decodeStringPointer(); | 256 var str2 = reader.decoder.decodeStringPointer(); |
257 expect(str2).toEqual(str); | 257 expect(str2).toEqual(str); |
258 } | 258 } |
259 | 259 |
260 function testArrayPointerValidation() { | 260 function testTypedPointerValidation() { |
| 261 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); |
261 function DummyClass() {}; | 262 function DummyClass() {}; |
262 var builder = new codec.MessageBuilder(42, 24); | 263 var testCases = [ |
263 var encoder = builder.createEncoder(8); | 264 // method, args, invalid examples, valid examples |
264 expect(function() { | 265 [encoder.encodeArrayPointer, [DummyClass], [75], [[], null, undefined]], |
265 // Pass something that is not an array it should throw. | 266 [encoder.encodeStringPointer, [], [75, new String("foo")], |
266 encoder.encodeArrayPointer(DummyClass, 75); | 267 ["", "bar", null, undefined]], |
267 }).toThrow(); | 268 [encoder.encodeMapPointer, [DummyClass, DummyClass], [75], |
| 269 [new Map(), null, undefined]], |
| 270 ]; |
268 | 271 |
269 // An empty array or null should do nothing and be fine. | 272 testCases.forEach(function(test) { |
270 encoder.encodeArrayPointer(DummyClass, []); | 273 var method = test[0]; |
271 encoder.encodeArrayPointer(DummyClass, null); | 274 var baseArgs = test[1]; |
| 275 var invalidExamples = test[2]; |
| 276 var validExamples = test[3]; |
| 277 |
| 278 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); |
| 279 invalidExamples.forEach(function(invalid) { |
| 280 expect(function() { |
| 281 method.apply(encoder, baseArgs.concat(invalid)); |
| 282 }).toThrow(); |
| 283 }); |
| 284 |
| 285 validExamples.forEach(function(valid) { |
| 286 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); |
| 287 method.apply(encoder, baseArgs.concat(valid)); |
| 288 }); |
| 289 }); |
272 } | 290 } |
273 }); | 291 }); |
OLD | NEW |