Chromium Code Reviews| Index: mojo/public/js/bindings/validation_unittests.js |
| diff --git a/mojo/public/js/bindings/validation_unittests.js b/mojo/public/js/bindings/validation_unittests.js |
| index 2f0bf9daec13a7d3af8450f7897f1b93e2f8d52e..c4e6723bdbfa7acf3bbce442890bed29341d3774 100644 |
| --- a/mojo/public/js/bindings/validation_unittests.js |
| +++ b/mojo/public/js/bindings/validation_unittests.js |
| @@ -9,10 +9,26 @@ define([ |
| "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom", |
| "mojo/public/js/bindings/buffer", |
| "mojo/public/js/bindings/codec", |
| + "mojo/public/js/bindings/connection", |
| + "mojo/public/js/bindings/connector", |
| + "mojo/public/js/bindings/core", |
| "mojo/public/js/bindings/tests/validation_test_input_parser", |
| + "mojo/public/js/bindings/router", |
| "mojo/public/js/bindings/validator", |
| - ], function( |
| - console, file, expect, testInterface, buffer, codec, parser, validator) { |
| +], function(console, |
| + file, |
| + expect, |
| + testInterface, |
| + buffer, |
| + codec, |
| + connection, |
| + connector, |
| + core, |
| + parser, |
| + router, |
| + validator) { |
| + |
| + var noError = validator.validationError.NONE; |
| function checkTestMessageParser() { |
| function TestMessageParserFailure(message, input) { |
| @@ -196,11 +212,18 @@ define([ |
| return contents.trim(); |
| } |
| + function checkValidationResult(testFile, err) { |
| + var actualResult = (err === noError) ? "PASS" : err; |
|
yzshen1
2014/09/15 07:08:40
wrong indent.
hansmuller
2014/09/15 16:25:26
Done.
|
| + var expectedResult = readTestExpected(testFile); |
| + if (actualResult != expectedResult) |
| + console.log("[Test message validation failed: " + testFile + " ]"); |
| + expect(actualResult).toEqual(expectedResult); |
| + } |
| + |
| function testMessageValidation(key, filters) { |
| var testFiles = getMessageTestFiles(key); |
| expect(testFiles.length).toBeGreaterThan(0); |
| - var noError = validator.validationError.NONE; |
| for (var i = 0; i < testFiles.length; i++) { |
| // TODO(hansmuller): Temporarily skipping array pointer overflow tests. |
| if (testFiles[i].indexOf("overflow") != -1) { |
| @@ -217,11 +240,7 @@ define([ |
| for (var j = 0; err === noError && j < filters.length; ++j) |
| err = filters[j](messageValidator); |
| - var actualResult = (err === noError) ? "PASS" : err; |
| - var expectedResult = readTestExpected(testFiles[i]); |
| - if (actualResult != expectedResult) |
| - console.log("[Test message validation failed: " + testFiles[i] + " ]"); |
| - expect(actualResult).toEqual(expectedResult); |
| + checkValidationResult(testFiles[i], err); |
| } |
| } |
| @@ -235,14 +254,83 @@ define([ |
| testInterface.ConformanceTestInterfaceStub.prototype.validator]); |
| } |
| - function testIntegrationMessageValidation() { |
| - testMessageValidation("integration_", [ |
| - testInterface.IntegrationTestInterface1Stub.prototype.validator, |
| - testInterface.IntegrationTestInterface2Proxy.prototype.validator]); |
| + function doTestIntegratedMessageValidation() { |
| + var testFiles = getMessageTestFiles("integration_"); |
| + expect(testFiles.length).toBeGreaterThan(0); |
| + |
| + for (var i = 0; i < testFiles.length; i++) { |
| + // TODO(hansmuller): Temporarily skipping array pointer overflow tests. |
| + if (testFiles[i].indexOf("overflow") != -1) { |
| + console.log("[Skipping " + testFiles[i] + "]"); |
| + continue; |
| + } |
| + |
| + var testMessage = readTestMessage(testFiles[i]); |
| + var handles = new Array(testMessage.handleCount); |
| + var testMessagePipe = new core.createMessagePipe(); |
| + expect(testMessagePipe.result).toBe(core.RESULT_OK); |
| + |
| + var writeMessageValue = core.writeMessage( |
| + testMessagePipe.handle0, |
| + new Uint8Array(testMessage.buffer.arrayBuffer), |
| + new Array(testMessage.handleCount), |
| + core.WRITE_MESSAGE_FLAG_NONE); |
| + expect(writeMessageValue).toBe(core.RESULT_OK); |
| + |
| + var testConnection = new connection.Connection( |
| + testMessagePipe.handle1, |
| + testInterface.IntegrationTestInterface1Stub, |
| + testInterface.IntegrationTestInterface2Proxy); |
| + |
| + var validationError = noError; |
| + testConnection.router_.validationErrorHandler = function(err) { |
| + validationError = err; |
|
yzshen1
2014/09/15 07:08:40
nit: wrong indent.
hansmuller
2014/09/15 16:25:25
Done.
|
| + } |
| + |
| + testConnection.router_.connector_.deliverMessage(); |
| + checkValidationResult(testFiles[i], validationError); |
| + |
| + testConnection.close(); |
| + expect(core.close(testMessagePipe.handle0)).toBe(core.RESULT_OK); |
| + } |
| + } |
| + |
| + function testIntegratedMessageValidation() { |
| + // Temporarily modify the Connector and Router classes: |
| + // - Enable delivering a message without an async wait. |
| + // - Defeat validated message handling. |
| + // - Delegate invalid message handling. |
| + try { |
| + var waitToReadMore = connector.Connector.prototype.waitToReadMore_; |
|
yzshen1
2014/09/15 07:08:40
[optional, something that may worth considering]
I
hansmuller
2014/09/15 16:25:26
I agree and I have to admit that what I had been d
yzshen1
2014/09/15 17:32:19
I like your new approach!
|
| + connector.Connector.prototype.waitToReadMore_ = function() { }; |
| + connector.Connector.prototype.deliverMessage = function() { |
| + this.readMore_(core.RESULT_OK); |
| + } |
| + |
| + var handleValidIncomingMessage = |
| + router.Router.prototype.handleValidIncomingMessage_; |
| + router.Router.prototype.handleValidIncomingMessage_ = function() { }; |
| + |
| + var handleInvalidIncomingMessage = |
| + router.Router.prototype.handleValidIncomingMessage_; |
| + router.Router.prototype.handleInvalidIncomingMessage_ = |
| + function(message, error) { |
| + this.validationErrorHandler(error); |
| + }; |
| + |
| + doTestIntegratedMessageValidation(); |
| + |
| + } finally { |
| + connector.Connector.prototype.waitToReadMore_ = waitToReadMore; |
| + router.Router.prototype.handleValidIncomingMessage_ = |
| + handleValidIncomingMessage; |
| + router.Router.prototype.handleinValidIncomingMessage_ = |
| + handleInvalidIncomingMessage; |
| + } |
| } |
| expect(checkTestMessageParser()).toBeNull(); |
| testConformanceMessageValidation(); |
| - testIntegrationMessageValidation(); |
| + testIntegratedMessageValidation(); |
| this.result = "PASS"; |
| }); |