| 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 "console", | 6 "console", |
| 7 "file", | 7 "file", |
| 8 "gin/test/expect", | 8 "gin/test/expect", |
| 9 "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom", | 9 "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom", |
| 10 "mojo/public/js/bindings", |
| 10 "mojo/public/js/buffer", | 11 "mojo/public/js/buffer", |
| 11 "mojo/public/js/codec", | 12 "mojo/public/js/codec", |
| 12 "mojo/public/js/connection", | |
| 13 "mojo/public/js/connector", | |
| 14 "mojo/public/js/core", | 13 "mojo/public/js/core", |
| 15 "mojo/public/js/test/validation_test_input_parser", | 14 "mojo/public/js/test/validation_test_input_parser", |
| 16 "mojo/public/js/router", | |
| 17 "mojo/public/js/validator", | 15 "mojo/public/js/validator", |
| 18 ], function(console, | 16 ], function(console, |
| 19 file, | 17 file, |
| 20 expect, | 18 expect, |
| 21 testInterface, | 19 testInterface, |
| 20 bindings, |
| 22 buffer, | 21 buffer, |
| 23 codec, | 22 codec, |
| 24 connection, | |
| 25 connector, | |
| 26 core, | 23 core, |
| 27 parser, | 24 parser, |
| 28 router, | |
| 29 validator) { | 25 validator) { |
| 30 | 26 |
| 31 var noError = validator.validationError.NONE; | 27 var noError = validator.validationError.NONE; |
| 32 | 28 |
| 33 function checkTestMessageParser() { | 29 function checkTestMessageParser() { |
| 34 function TestMessageParserFailure(message, input) { | 30 function TestMessageParserFailure(message, input) { |
| 35 this.message = message; | 31 this.message = message; |
| 36 this.input = input; | 32 this.input = input; |
| 37 } | 33 } |
| 38 | 34 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 function testResponseConformanceMessageValidation() { | 263 function testResponseConformanceMessageValidation() { |
| 268 testMessageValidation("resp_conformance_", [ | 264 testMessageValidation("resp_conformance_", [ |
| 269 testInterface.ConformanceTestInterface.validateResponse]); | 265 testInterface.ConformanceTestInterface.validateResponse]); |
| 270 } | 266 } |
| 271 | 267 |
| 272 function testResponseBoundsCheckMessageValidation() { | 268 function testResponseBoundsCheckMessageValidation() { |
| 273 testMessageValidation("resp_boundscheck_", [ | 269 testMessageValidation("resp_boundscheck_", [ |
| 274 testInterface.BoundsCheckTestInterface.validateResponse]); | 270 testInterface.BoundsCheckTestInterface.validateResponse]); |
| 275 } | 271 } |
| 276 | 272 |
| 277 function testIntegratedMessageValidation(testFilesPattern, | 273 function testIntegratedMessageValidation(testFilesPattern, endpoint) { |
| 278 localFactory, | |
| 279 remoteFactory) { | |
| 280 var testFiles = getMessageTestFiles(testFilesPattern); | 274 var testFiles = getMessageTestFiles(testFilesPattern); |
| 281 expect(testFiles.length).toBeGreaterThan(0); | 275 expect(testFiles.length).toBeGreaterThan(0); |
| 282 | 276 |
| 283 var testMessagePipe = core.createMessagePipe(); | 277 var testMessagePipe = core.createMessagePipe(); |
| 284 expect(testMessagePipe.result).toBe(core.RESULT_OK); | 278 expect(testMessagePipe.result).toBe(core.RESULT_OK); |
| 285 var testConnection = new connection.TestConnection( | 279 |
| 286 testMessagePipe.handle1, localFactory, remoteFactory); | 280 endpoint.bind(testMessagePipe.handle1); |
| 281 var testingController = endpoint.enableTestingMode(); |
| 282 |
| 283 var validationError; |
| 284 testingController.setInvalidIncomingMessageHandler(function(error) { |
| 285 validationError = error; |
| 286 }); |
| 287 | 287 |
| 288 for (var i = 0; i < testFiles.length; i++) { | 288 for (var i = 0; i < testFiles.length; i++) { |
| 289 validationError = noError; |
| 289 var testMessage = readTestMessage(testFiles[i]); | 290 var testMessage = readTestMessage(testFiles[i]); |
| 290 var handles = new Array(testMessage.handleCount); | 291 var handles = new Array(testMessage.handleCount); |
| 291 | 292 |
| 292 var writeMessageValue = core.writeMessage( | 293 var writeMessageValue = core.writeMessage( |
| 293 testMessagePipe.handle0, | 294 testMessagePipe.handle0, |
| 294 new Uint8Array(testMessage.buffer.arrayBuffer), | 295 new Uint8Array(testMessage.buffer.arrayBuffer), |
| 295 new Array(testMessage.handleCount), | 296 new Array(testMessage.handleCount), |
| 296 core.WRITE_MESSAGE_FLAG_NONE); | 297 core.WRITE_MESSAGE_FLAG_NONE); |
| 297 expect(writeMessageValue).toBe(core.RESULT_OK); | 298 expect(writeMessageValue).toBe(core.RESULT_OK); |
| 298 | 299 |
| 299 var validationError = noError; | 300 testingController.waitForNextMessage(); |
| 300 testConnection.router_.validationErrorHandler = function(err) { | |
| 301 validationError = err; | |
| 302 }; | |
| 303 | |
| 304 testConnection.router_.connector_.waitForNextMessage(); | |
| 305 checkValidationResult(testFiles[i], validationError); | 301 checkValidationResult(testFiles[i], validationError); |
| 306 } | 302 } |
| 307 | 303 |
| 308 testConnection.close(); | |
| 309 expect(core.close(testMessagePipe.handle0)).toBe(core.RESULT_OK); | 304 expect(core.close(testMessagePipe.handle0)).toBe(core.RESULT_OK); |
| 310 } | 305 } |
| 311 | 306 |
| 312 function testIntegratedMessageHeaderValidation() { | 307 function testIntegratedMessageHeaderValidation() { |
| 313 testIntegratedMessageValidation( | 308 testIntegratedMessageValidation( |
| 314 "integration_msghdr", | 309 "integration_msghdr", |
| 315 testInterface.IntegrationTestInterface.stubClass, | 310 new bindings.Binding(testInterface.IntegrationTestInterface, {})); |
| 316 undefined); | |
| 317 testIntegratedMessageValidation( | 311 testIntegratedMessageValidation( |
| 318 "integration_msghdr", | 312 "integration_msghdr", |
| 319 undefined, | 313 new testInterface.IntegrationTestInterfacePtr().ptr); |
| 320 testInterface.IntegrationTestInterface.proxyClass); | |
| 321 } | 314 } |
| 322 | 315 |
| 323 function testIntegratedRequestMessageValidation() { | 316 function testIntegratedRequestMessageValidation() { |
| 324 testIntegratedMessageValidation( | 317 testIntegratedMessageValidation( |
| 325 "integration_intf_rqst", | 318 "integration_intf_rqst", |
| 326 testInterface.IntegrationTestInterface.stubClass, | 319 new bindings.Binding(testInterface.IntegrationTestInterface, {})); |
| 327 undefined); | |
| 328 } | 320 } |
| 329 | 321 |
| 330 function testIntegratedResponseMessageValidation() { | 322 function testIntegratedResponseMessageValidation() { |
| 331 testIntegratedMessageValidation( | 323 testIntegratedMessageValidation( |
| 332 "integration_intf_resp", | 324 "integration_intf_resp", |
| 333 undefined, | 325 new testInterface.IntegrationTestInterfacePtr().ptr); |
| 334 testInterface.IntegrationTestInterface.proxyClass); | |
| 335 } | 326 } |
| 336 | 327 |
| 337 expect(checkTestMessageParser()).toBeNull(); | 328 expect(checkTestMessageParser()).toBeNull(); |
| 338 testConformanceMessageValidation(); | 329 testConformanceMessageValidation(); |
| 339 testBoundsCheckMessageValidation(); | 330 testBoundsCheckMessageValidation(); |
| 340 testResponseConformanceMessageValidation(); | 331 testResponseConformanceMessageValidation(); |
| 341 testResponseBoundsCheckMessageValidation(); | 332 testResponseBoundsCheckMessageValidation(); |
| 342 testIntegratedMessageHeaderValidation(); | 333 testIntegratedMessageHeaderValidation(); |
| 343 testIntegratedResponseMessageValidation(); | 334 testIntegratedResponseMessageValidation(); |
| 344 testIntegratedRequestMessageValidation(); | 335 testIntegratedRequestMessageValidation(); |
| 345 | 336 |
| 346 this.result = "PASS"; | 337 this.result = "PASS"; |
| 347 }); | 338 }); |
| OLD | NEW |