| 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/buffer", | 10 "mojo/public/js/buffer", |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 testEmptyInput(); | 173 testEmptyInput(); |
| 174 testBlankInput(); | 174 testBlankInput(); |
| 175 testHandles(); | 175 testHandles(); |
| 176 testAnchors(); | 176 testAnchors(); |
| 177 } catch (e) { | 177 } catch (e) { |
| 178 return e.toString(); | 178 return e.toString(); |
| 179 } | 179 } |
| 180 return null; | 180 return null; |
| 181 } | 181 } |
| 182 | 182 |
| 183 function getMessageTestFiles(key) { | 183 function getMessageTestFiles(prefix) { |
| 184 var sourceRoot = file.getSourceRootDirectory(); | 184 var sourceRoot = file.getSourceRootDirectory(); |
| 185 expect(sourceRoot).not.toBeNull(); | 185 expect(sourceRoot).not.toBeNull(); |
| 186 | 186 |
| 187 var testDir = sourceRoot + | 187 var testDir = sourceRoot + |
| 188 "/mojo/public/interfaces/bindings/tests/data/validation/"; | 188 "/mojo/public/interfaces/bindings/tests/data/validation/"; |
| 189 var testFiles = file.getFilesInDirectory(testDir); | 189 var testFiles = file.getFilesInDirectory(testDir); |
| 190 expect(testFiles).not.toBeNull(); | 190 expect(testFiles).not.toBeNull(); |
| 191 expect(testFiles.length).toBeGreaterThan(0); | 191 expect(testFiles.length).toBeGreaterThan(0); |
| 192 | 192 |
| 193 // The matching ".data" pathnames with the extension removed. | 193 // The matching ".data" pathnames with the extension removed. |
| 194 return testFiles.filter(function(s) { | 194 return testFiles.filter(function(s) { |
| 195 return s.substr(-5) == ".data"; | 195 return s.substr(-5) == ".data" && s.indexOf(prefix) == 0; |
| 196 }).map(function(s) { | 196 }).map(function(s) { |
| 197 return testDir + s.slice(0, -5); | 197 return testDir + s.slice(0, -5); |
| 198 }).filter(function(s) { | |
| 199 return s.indexOf(key) != -1; | |
| 200 }); | 198 }); |
| 201 } | 199 } |
| 202 | 200 |
| 203 function readTestMessage(filename) { | 201 function readTestMessage(filename) { |
| 204 var contents = file.readFileToString(filename + ".data"); | 202 var contents = file.readFileToString(filename + ".data"); |
| 205 expect(contents).not.toBeNull(); | 203 expect(contents).not.toBeNull(); |
| 206 return parser.parseTestMessage(contents); | 204 return parser.parseTestMessage(contents); |
| 207 } | 205 } |
| 208 | 206 |
| 209 function readTestExpected(filename) { | 207 function readTestExpected(filename) { |
| 210 var contents = file.readFileToString(filename + ".expected"); | 208 var contents = file.readFileToString(filename + ".expected"); |
| 211 expect(contents).not.toBeNull(); | 209 expect(contents).not.toBeNull(); |
| 212 return contents.trim(); | 210 return contents.trim(); |
| 213 } | 211 } |
| 214 | 212 |
| 215 function checkValidationResult(testFile, err) { | 213 function checkValidationResult(testFile, err) { |
| 216 var actualResult = (err === noError) ? "PASS" : err; | 214 var actualResult = (err === noError) ? "PASS" : err; |
| 217 var expectedResult = readTestExpected(testFile); | 215 var expectedResult = readTestExpected(testFile); |
| 218 if (actualResult != expectedResult) | 216 if (actualResult != expectedResult) |
| 219 console.log("[Test message validation failed: " + testFile + " ]"); | 217 console.log("[Test message validation failed: " + testFile + " ]"); |
| 220 expect(actualResult).toEqual(expectedResult); | 218 expect(actualResult).toEqual(expectedResult); |
| 221 } | 219 } |
| 222 | 220 |
| 223 function testMessageValidation(key, filters) { | 221 function testMessageValidation(prefix, filters) { |
| 224 var testFiles = getMessageTestFiles(key); | 222 var testFiles = getMessageTestFiles(prefix); |
| 225 expect(testFiles.length).toBeGreaterThan(0); | 223 expect(testFiles.length).toBeGreaterThan(0); |
| 226 | 224 |
| 227 for (var i = 0; i < testFiles.length; i++) { | 225 for (var i = 0; i < testFiles.length; i++) { |
| 228 // TODO(hansmuller) Temporarily skipping array pointer overflow tests | 226 // TODO(hansmuller) Temporarily skipping array pointer overflow tests |
| 229 // because JS numbers are limited to 53 bits. | 227 // because JS numbers are limited to 53 bits. |
| 230 // TODO(yzshen) Skipping struct versioning tests (tests with "mthd11" | 228 // TODO(yzshen) Skipping struct versioning tests (tests with "mthd11" |
| 231 // in the name) because the feature is not supported in JS yet. | 229 // in the name) because the feature is not supported in JS yet. |
| 232 // TODO(rudominer): Temporarily skipping 'no-such-method', | 230 // TODO(rudominer): Temporarily skipping 'no-such-method', |
| 233 // 'invalid_request_flags', and 'invalid_response_flags' until additional | 231 // 'invalid_request_flags', and 'invalid_response_flags' until additional |
| 234 // logic in *RequestValidator and *ResponseValidator is ported from | 232 // logic in *RequestValidator and *ResponseValidator is ported from |
| (...skipping 18 matching lines...) Expand all Loading... |
| 253 | 251 |
| 254 checkValidationResult(testFiles[i], err); | 252 checkValidationResult(testFiles[i], err); |
| 255 } | 253 } |
| 256 } | 254 } |
| 257 | 255 |
| 258 function testConformanceMessageValidation() { | 256 function testConformanceMessageValidation() { |
| 259 testMessageValidation("conformance_", [ | 257 testMessageValidation("conformance_", [ |
| 260 testInterface.ConformanceTestInterface.validateRequest]); | 258 testInterface.ConformanceTestInterface.validateRequest]); |
| 261 } | 259 } |
| 262 | 260 |
| 263 function testIntegratedMessageValidation(testFilesPattern) { | 261 function testBoundsCheckMessageValidation() { |
| 262 testMessageValidation("boundscheck_", [ |
| 263 testInterface.BoundsCheckTestInterface.validateRequest]); |
| 264 } |
| 265 |
| 266 function testResponseConformanceMessageValidation() { |
| 267 testMessageValidation("resp_conformance_", [ |
| 268 testInterface.ConformanceTestInterface.validateResponse]); |
| 269 } |
| 270 |
| 271 function testResponseBoundsCheckMessageValidation() { |
| 272 testMessageValidation("resp_boundscheck_", [ |
| 273 testInterface.BoundsCheckTestInterface.validateResponse]); |
| 274 } |
| 275 |
| 276 function testIntegratedMessageValidation(testFilesPattern, |
| 277 localFactory, |
| 278 remoteFactory) { |
| 264 var testFiles = getMessageTestFiles(testFilesPattern); | 279 var testFiles = getMessageTestFiles(testFilesPattern); |
| 265 expect(testFiles.length).toBeGreaterThan(0); | 280 expect(testFiles.length).toBeGreaterThan(0); |
| 266 | 281 |
| 282 var testMessagePipe = new core.createMessagePipe(); |
| 283 expect(testMessagePipe.result).toBe(core.RESULT_OK); |
| 284 var testConnection = new connection.TestConnection( |
| 285 testMessagePipe.handle1, localFactory, remoteFactory); |
| 286 |
| 267 for (var i = 0; i < testFiles.length; i++) { | 287 for (var i = 0; i < testFiles.length; i++) { |
| 268 var testMessage = readTestMessage(testFiles[i]); | 288 var testMessage = readTestMessage(testFiles[i]); |
| 269 var handles = new Array(testMessage.handleCount); | 289 var handles = new Array(testMessage.handleCount); |
| 270 var testMessagePipe = new core.createMessagePipe(); | |
| 271 expect(testMessagePipe.result).toBe(core.RESULT_OK); | |
| 272 | 290 |
| 273 var writeMessageValue = core.writeMessage( | 291 var writeMessageValue = core.writeMessage( |
| 274 testMessagePipe.handle0, | 292 testMessagePipe.handle0, |
| 275 new Uint8Array(testMessage.buffer.arrayBuffer), | 293 new Uint8Array(testMessage.buffer.arrayBuffer), |
| 276 new Array(testMessage.handleCount), | 294 new Array(testMessage.handleCount), |
| 277 core.WRITE_MESSAGE_FLAG_NONE); | 295 core.WRITE_MESSAGE_FLAG_NONE); |
| 278 expect(writeMessageValue).toBe(core.RESULT_OK); | 296 expect(writeMessageValue).toBe(core.RESULT_OK); |
| 279 | 297 |
| 280 var testConnection = new connection.TestConnection( | |
| 281 testMessagePipe.handle1, | |
| 282 testInterface.IntegrationTestInterface.stubClass, | |
| 283 testInterface.IntegrationTestInterface.proxyClass); | |
| 284 | |
| 285 var validationError = noError; | 298 var validationError = noError; |
| 286 testConnection.router_.validationErrorHandler = function(err) { | 299 testConnection.router_.validationErrorHandler = function(err) { |
| 287 validationError = err; | 300 validationError = err; |
| 288 } | 301 } |
| 289 | 302 |
| 290 testConnection.router_.connector_.deliverMessage(); | 303 testConnection.router_.connector_.waitForNextMessage(); |
| 291 checkValidationResult(testFiles[i], validationError); | 304 checkValidationResult(testFiles[i], validationError); |
| 305 } |
| 292 | 306 |
| 293 testConnection.close(); | 307 testConnection.close(); |
| 294 expect(core.close(testMessagePipe.handle0)).toBe(core.RESULT_OK); | 308 expect(core.close(testMessagePipe.handle0)).toBe(core.RESULT_OK); |
| 295 } | |
| 296 } | 309 } |
| 297 | 310 |
| 298 function testIntegratedMessageHeaderValidation() { | 311 function testIntegratedMessageHeaderValidation() { |
| 299 testIntegratedMessageValidation("integration_msghdr"); | 312 testIntegratedMessageValidation( |
| 313 "integration_msghdr", |
| 314 testInterface.IntegrationTestInterface.stubClass, |
| 315 undefined); |
| 316 testIntegratedMessageValidation( |
| 317 "integration_msghdr", |
| 318 undefined, |
| 319 testInterface.IntegrationTestInterface.proxyClass); |
| 300 } | 320 } |
| 301 | 321 |
| 302 function testIntegratedRequestMessageValidation() { | 322 function testIntegratedRequestMessageValidation() { |
| 303 testIntegratedMessageValidation("integration_intf_rqst"); | 323 testIntegratedMessageValidation( |
| 324 "integration_intf_rqst", |
| 325 testInterface.IntegrationTestInterface.stubClass, |
| 326 undefined); |
| 304 } | 327 } |
| 305 | 328 |
| 306 function testIntegratedResponseMessageValidation() { | 329 function testIntegratedResponseMessageValidation() { |
| 307 testIntegratedMessageValidation("integration_intf_resp"); | 330 testIntegratedMessageValidation( |
| 331 "integration_intf_resp", |
| 332 undefined, |
| 333 testInterface.IntegrationTestInterface.proxyClass); |
| 308 } | 334 } |
| 309 | 335 |
| 310 expect(checkTestMessageParser()).toBeNull(); | 336 expect(checkTestMessageParser()).toBeNull(); |
| 311 testConformanceMessageValidation(); | 337 testConformanceMessageValidation(); |
| 338 testBoundsCheckMessageValidation(); |
| 339 testResponseConformanceMessageValidation(); |
| 340 testResponseBoundsCheckMessageValidation(); |
| 312 testIntegratedMessageHeaderValidation(); | 341 testIntegratedMessageHeaderValidation(); |
| 313 testIntegratedResponseMessageValidation(); | 342 testIntegratedResponseMessageValidation(); |
| 314 testIntegratedRequestMessageValidation(); | 343 testIntegratedRequestMessageValidation(); |
| 344 |
| 315 this.result = "PASS"; | 345 this.result = "PASS"; |
| 316 }); | 346 }); |
| OLD | NEW |