Chromium Code Reviews| 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 "file", | 6 "file", |
| 7 "gin/test/expect", | 7 "gin/test/expect", |
| 8 "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom", | 8 "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom", |
| 9 "mojo/public/js/bindings/buffer", | 9 "mojo/public/js/bindings/buffer", |
| 10 "mojo/public/js/bindings/codec", | 10 "mojo/public/js/bindings/codec", |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 testEmptyInput(); | 155 testEmptyInput(); |
| 156 testBlankInput(); | 156 testBlankInput(); |
| 157 testHandles(); | 157 testHandles(); |
| 158 testAnchors(); | 158 testAnchors(); |
| 159 } catch (e) { | 159 } catch (e) { |
| 160 return e.toString(); | 160 return e.toString(); |
| 161 } | 161 } |
| 162 return null; | 162 return null; |
| 163 } | 163 } |
| 164 | 164 |
| 165 function getMessageTestFiles() { | 165 function getMessageTestFiles(key) { |
| 166 var sourceRoot = file.getSourceRootDirectory(); | 166 var sourceRoot = file.getSourceRootDirectory(); |
| 167 expect(sourceRoot).not.toBeNull(); | 167 expect(sourceRoot).not.toBeNull(); |
| 168 | 168 |
| 169 var testDir = sourceRoot + | 169 var testDir = sourceRoot + |
| 170 "/mojo/public/interfaces/bindings/tests/data/validation/"; | 170 "/mojo/public/interfaces/bindings/tests/data/validation/"; |
| 171 var testFiles = file.getFilesInDirectory(testDir); | 171 var testFiles = file.getFilesInDirectory(testDir); |
| 172 expect(testFiles).not.toBeNull(); | 172 expect(testFiles).not.toBeNull(); |
| 173 expect(testFiles.length).toBeGreaterThan(0); | 173 expect(testFiles.length).toBeGreaterThan(0); |
| 174 | 174 |
| 175 // The ".data" pathnames with the extension removed. | 175 // The matching ".data" pathnames with the extension removed. |
| 176 var testPathNames = testFiles.filter(function(s) { | 176 return testFiles.filter(function(s) { |
| 177 return s.substr(-5) == ".data"; | 177 return s.substr(-5) == ".data"; |
| 178 }).map(function(s) { | 178 }).map(function(s) { |
| 179 return testDir + s.slice(0, -5); | 179 return testDir + s.slice(0, -5); |
| 180 }); | 180 }).filter(function(s) { |
| 181 | 181 return s.indexOf(key) != -1; |
| 182 // For now, just checking the message header tests. | 182 }); |
| 183 return testPathNames.filter(function(s) { | |
| 184 return s.indexOf("_msghdr_") != -1; | |
| 185 }); | |
| 186 } | 183 } |
| 187 | 184 |
| 188 function readTestMessage(filename) { | 185 function readTestMessage(filename) { |
| 189 var contents = file.readFileToString(filename + ".data"); | 186 var contents = file.readFileToString(filename + ".data"); |
| 190 expect(contents).not.toBeNull(); | 187 expect(contents).not.toBeNull(); |
| 191 return parser.parseTestMessage(contents); | 188 return parser.parseTestMessage(contents); |
| 192 } | 189 } |
| 193 | 190 |
| 194 function readTestExpected(filename) { | 191 function readTestExpected(filename) { |
| 195 var contents = file.readFileToString(filename + ".expected"); | 192 var contents = file.readFileToString(filename + ".expected"); |
| 196 expect(contents).not.toBeNull(); | 193 expect(contents).not.toBeNull(); |
| 197 return contents.trim(); | 194 return contents.trim(); |
| 198 } | 195 } |
| 199 | 196 |
| 200 function testValidateMessageHeader() { | 197 function testMessageValidation(key, filters) { |
| 201 var testFiles = getMessageTestFiles(); | 198 var testFiles = getMessageTestFiles(key); |
| 202 expect(testFiles.length).toBeGreaterThan(0); | 199 expect(testFiles.length).toBeGreaterThan(0); |
| 203 | 200 |
| 201 var noError = validator.validationError.NONE; | |
| 204 for (var i = 0; i < testFiles.length; i++) { | 202 for (var i = 0; i < testFiles.length; i++) { |
| 203 // TODO(hansmuller): Temporarily skipping array pointer overflow tests. | |
| 204 if (testFiles[i].indexOf("overflow") != -1) | |
|
yzshen1
2014/08/14 00:06:32
It may be nice to output a warning with the file n
hansmuller
2014/08/14 00:57:57
Good point, I've done that.
| |
| 205 continue; | |
| 206 | |
| 205 var testMessage = readTestMessage(testFiles[i]); | 207 var testMessage = readTestMessage(testFiles[i]); |
| 206 // TODO(hansmuller): add the message handles. | 208 var handles = new Array(testMessage.handleCount); |
| 207 var message = new codec.Message(testMessage.buffer); | 209 var message = new codec.Message(testMessage.buffer, handles); |
|
yzshen1
2014/08/14 00:06:32
extra space after =
hansmuller
2014/08/14 00:57:57
Done.
| |
| 208 var actualResult = new validator.Validator(message).validateMessage(); | 210 var messageValidator = new validator.Validator(message); |
| 211 | |
| 212 var err = messageValidator.validateMessageHeader(); | |
|
yzshen1
2014/08/14 00:06:32
Something to think about:
It seems a little incons
hansmuller
2014/08/14 00:57:56
Acknowledged.
| |
| 213 for (var j = 0; err === noError && j < filters.length; ++j) | |
| 214 err = filters[j](messageValidator); | |
| 215 | |
| 216 var actualResult = (err === noError) ? "PASS" : err; | |
| 209 var expectedResult = readTestExpected(testFiles[i]); | 217 var expectedResult = readTestExpected(testFiles[i]); |
| 210 expect(actualResult).toEqual(expectedResult); | 218 expect(actualResult).toEqual(expectedResult); |
|
yzshen1
2014/08/14 00:06:32
It seems nice if we print out the file name on fai
hansmuller
2014/08/14 00:57:57
I agree. The simple JS expect framework doesn't ap
| |
| 211 } | 219 } |
| 212 } | 220 } |
| 213 | 221 |
| 214 testValidateMessageHeader(); | 222 function testConformanceMessageValidation() { |
| 223 testMessageValidation("conformance_", [ | |
| 224 testInterface.validateConformanceTestInterfaceRequest, | |
| 225 testInterface.validateConformanceTestInterfaceResponse | |
|
yzshen1
2014/08/14 00:06:32
All the conformance test cases are for Conformance
hansmuller
2014/08/14 00:57:56
Done.
| |
| 226 ]); | |
| 227 } | |
| 228 | |
| 229 function testIntegrationMessageValidation() { | |
| 230 testMessageValidation("integration_", [ | |
|
yzshen1
2014/08/14 00:06:32
The goal of the integration tests is to make sure
| |
| 231 testInterface.validateIntegrationTestInterface1Request, | |
|
yzshen1
2014/08/14 00:06:32
The tests are designed for a message pipe endpoint
hansmuller
2014/08/14 00:57:57
I hadn't completely understood the scope of messag
| |
| 232 testInterface.validateIntegrationTestInterface1Response, | |
| 233 testInterface.validateIntegrationTestInterface2Request, | |
| 234 testInterface.validateIntegrationTestInterface2Response | |
| 235 ]); | |
| 236 } | |
| 237 | |
| 238 testConformanceMessageValidation(); | |
| 239 testIntegrationMessageValidation(); | |
| 215 expect(checkTestMessageParser()).toBeNull(); | 240 expect(checkTestMessageParser()).toBeNull(); |
| 216 this.result = "PASS"; | 241 this.result = "PASS"; |
| 217 }); | 242 }); |
| OLD | NEW |