| 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", |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 testTypedPointerValidation() { | 260 function testTypedPointerValidation() { |
| 261 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); | 261 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); |
| 262 function DummyClass() {}; | 262 function DummyClass() {}; |
| 263 var testCases = [ | 263 var testCases = [ |
| 264 // method, args, invalid examples, valid examples | 264 // method, args, invalid examples, valid examples |
| 265 [encoder.encodeArrayPointer, [DummyClass], [75], | 265 [encoder.encodeArrayPointer, [DummyClass], [75], |
| 266 [[], null, undefined, new Uint8Array([])]]], | 266 [[], null, undefined, new Uint8Array([])]], |
| 267 [encoder.encodeStringPointer, [], [75, new String("foo")], | 267 [encoder.encodeStringPointer, [], [75, new String("foo")], |
| 268 ["", "bar", null, undefined]], | 268 ["", "bar", null, undefined]], |
| 269 [encoder.encodeMapPointer, [DummyClass, DummyClass], [75], | 269 [encoder.encodeMapPointer, [DummyClass, DummyClass], [75], |
| 270 [new Map(), null, undefined]], | 270 [new Map(), null, undefined]], |
| 271 ]; | 271 ]; |
| 272 | 272 |
| 273 testCases.forEach(function(test) { | 273 testCases.forEach(function(test) { |
| 274 var method = test[0]; | 274 var method = test[0]; |
| 275 var baseArgs = test[1]; | 275 var baseArgs = test[1]; |
| 276 var invalidExamples = test[2]; | 276 var invalidExamples = test[2]; |
| 277 var validExamples = test[3]; | 277 var validExamples = test[3]; |
| 278 | 278 |
| 279 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); | 279 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); |
| 280 invalidExamples.forEach(function(invalid) { | 280 invalidExamples.forEach(function(invalid) { |
| 281 expect(function() { | 281 expect(function() { |
| 282 method.apply(encoder, baseArgs.concat(invalid)); | 282 method.apply(encoder, baseArgs.concat(invalid)); |
| 283 }).toThrow(); | 283 }).toThrow(); |
| 284 }); | 284 }); |
| 285 | 285 |
| 286 validExamples.forEach(function(valid) { | 286 validExamples.forEach(function(valid) { |
| 287 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); | 287 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8); |
| 288 method.apply(encoder, baseArgs.concat(valid)); | 288 method.apply(encoder, baseArgs.concat(valid)); |
| 289 }); | 289 }); |
| 290 }); | 290 }); |
| 291 } | 291 } |
| 292 }); | 292 }); |
| OLD | NEW |