Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Side by Side Diff: third_party/WebKit/LayoutTests/mojo/validation.html

Issue 2745293005: Moving mojo/validation test into LayoutTests (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/mojo/resources/validation_test_input_parser.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="../resources/mojo-helpers.js"></script>
5 <script src="resources/validation_test_input_parser.js"></script>
6 <script>
7 'use strict';
8
9 setup({ explicit_done: true });
10
11 define([//"file",
12 "mojo/public/interfaces/bindings/tests/validation_test_interfaces.mojom",
13 "mojo/public/js/bindings",
14 "mojo/public/js/buffer",
15 "mojo/public/js/codec",
16 "mojo/public/js/core",
17 "mojo/resources/validation_test_input_parser",
18 "mojo/public/js/validator",
19 ], function(//file,
20 testInterface,
21 bindings,
22 buffer,
23 codec,
24 core,
25 parser,
26 validator) {
27
28 var noError = validator.validationError.NONE;
29
30 function checkData(data, expectedData, input) {
31 assert_equals(data.byteLength, expectedData.byteLength,
32 "message length (" + data.byteLength + ") doesn't match " +
33 "expected length: " + expectedData.byteLength + " for " + input);
34
35 for (var i = 0; i < data.byteLength; i++) {
36 assert_equals(data.getUint8(i), expectedData.getUint8(i),
37 'message data mismatch at byte offset ' + i + "for" + input);
38 }
39 }
40
41 test(() => {
42 var input = '[f]+.3e9 [d]-10.03';
43 var msg = parser.parseTestMessage(input);
44 var expectedData = new buffer.Buffer(12);
45 expectedData.setFloat32(0, +.3e9);
46 expectedData.setFloat64(4, -10.03);
47 checkData(msg.buffer, expectedData, input);
48 }, 'message parser: float items');
49
50 test(() => {
51 var input = '[u1]0x10// hello world !! \n\r \t [u2]65535 \n' +
52 '[u4]65536 [u8]0xFFFFFFFFFFFFF 0 0Xff';
53 var msg = parser.parseTestMessage(input);
54 var expectedData = new buffer.Buffer(17);
55 expectedData.setUint8(0, 0x10);
56 expectedData.setUint16(1, 65535);
57 expectedData.setUint32(3, 65536);
58 expectedData.setUint64(7, 0xFFFFFFFFFFFFF);
59 expectedData.setUint8(15, 0);
60 expectedData.setUint8(16, 0xff);
61 checkData(msg.buffer, expectedData, input);
62 }, 'message parser: unsigned integer items');
63
64 test(() => {
65 var input = '[s8]-0x800 [s1]-128\t[s2]+0 [s4]-40';
66 var msg = parser.parseTestMessage(input);
67 var expectedData = new buffer.Buffer(15);
68 expectedData.setInt64(0, -0x800);
69 expectedData.setInt8(8, -128);
70 expectedData.setInt16(9, 0);
71 expectedData.setInt32(11, -40);
72 checkData(msg.buffer, expectedData, input);
73 }, 'message parser: signed integer items');
74
75 test(() => {
76 var input = '[b]00001011 [b]10000000 // hello world\n [b]00000000';
77 var msg = parser.parseTestMessage(input);
78 var expectedData = new buffer.Buffer(3);
79 expectedData.setUint8(0, 11);
80 expectedData.setUint8(1, 128);
81 expectedData.setUint8(2, 0);
82 checkData(msg.buffer, expectedData, input);
83 }, 'message parser: byte items');
84
85 test(() => {
86 var input = '[dist4]foo 0 [dist8]bar 0 [anchr]foo [anchr]bar';
87 var msg = parser.parseTestMessage(input);
88 var expectedData = new buffer.Buffer(14);
89 expectedData.setUint32(0, 14);
90 expectedData.setUint8(4, 0);
91 expectedData.setUint64(5, 9);
92 expectedData.setUint8(13, 0);
93 checkData(msg.buffer, expectedData, input);
94 }, 'message parser: anchors');
95
96 test(() => {
97 var input = '// This message has handles! \n[handles]50 [u8]2';
98 var msg = parser.parseTestMessage(input);
99 var expectedData = new buffer.Buffer(8);
100 expectedData.setUint64(0, 2);
101
102 assert_equals(msg.handleCount, 50,
103 'wrong handle count (' + msg.handleConut + ') for ' + input);
104 checkData(msg.buffer, expectedData, input);
105 }, 'message parser: handles');
106
107 test(() => {
108 var msg = parser.parseTestMessage('');
109 assert_equals(msg.buffer.byteLength, 0, 'expected empty message for ');
110 }, 'message parser: empty input');
111
112 test(() => {
113 var input = ' \t // hello world \n\r \t// the answer is 42 ';
114 var msg = parser.parseTestMessage(input);
115 assert_equals(msg.buffer.byteLength, 0, 'expected empty message for ' + inpu t);
116 }, 'message parser: blank input');
117
118 test(() => {
119 function parserShouldFail(input) {
120 assert_throws(new parser.InputError(), function() {
121 parser.parseTestMessage(input);
122 });
123 }
124
125 ['/ hello world',
126 '[u1]x',
127 '[u2]-1000',
128 '[u1]0x100',
129 '[s2]-0x8001',
130 '[b]1',
131 '[b]1111111k',
132 '[dist4]unmatched',
133 '[anchr]hello [dist8]hello',
134 '[dist4]a [dist4]a [anchr]a',
135 // '[dist4]a [anchr]a [dist4]a [anchr]a',
136 '0 [handles]50'
137 ].forEach(parserShouldFail);
138 }, 'message parser: invalid input');
139
140 function getMessageTestFiles(prefix) {
141 var sourceRoot = file.getSourceRootDirectory();
damargulis 2017/03/14 18:55:21 Since I am moving the location of this test, I no
jbroman 2017/03/14 21:22:15 During layout tests, it is possible to fetch a fil
142 assert_not_equals(sourceRoot, null);
143
144 var testDir = sourceRoot +
145 "/mojo/public/interfaces/bindings/tests/data/validation/";
146 var testFiles = file.getFilesInDirectory(testDir);
147 assert_not_equals(testFiles, null);
148 assert_greater_than(testFiles.length, 0);
149
150 // The matching ".data" pathnames with the extension removed.
151 return testFiles.filter(function(s) {
152 return s.substr(-5) == ".data" && s.indexOf(prefix) == 0;
153 }).map(function(s) {
154 return testDir + s.slice(0, -5);
155 });
156 }
157
158 function readTestMessage(filename) {
159 var contents = file.readFileToString(filename + ".data");
160 assert_not_equals(contents, null);
161 return parser.parseTestMessage(contents);
162 }
163
164 function readTestExpected(filename) {
165 var contents = file.readFileToString(filename + ".expected");
166 assert_not_equals(contents, null);
167 return contents.trim();
168 }
169
170 function checkValidationResult(testFile, err) {
171 var actualResult = (err === noError) ? "PASS" : err;
172 var expectedResult = readTestExpected(testFile);
173 assert_equals(actionResult, expectedResult,
174 "[Test message validation failed: " + testFile + " ]");
175 }
176
177 function testMessageValidation(prefix, filters) {
178 var testFiles = getMessageTestFiles(prefix);
179 expect(testFiles.length).toBeGreaterThan(0);
180
181 for (var i = 0; i < testFiles.length; i++) {
182 // TODO(hansmuller) Temporarily skipping array pointer overflow tests
183 // because JS numbers are limited to 53 bits.
184 // TODO(rudominer): Temporarily skipping 'no-such-method',
185 // 'invalid_request_flags', and 'invalid_response_flags' until additional
186 // logic in *RequestValidator and *ResponseValidator is ported from
187 // cpp to js.
188 // TODO(crbug/640298): Implement max recursion depth for JS.
189 // TODO(crbug/628104): Support struct map keys for JS.
190 if (testFiles[i].indexOf("overflow") != -1 ||
191 testFiles[i].indexOf("conformance_mthd19") != -1 ||
192 testFiles[i].indexOf("conformance_mthd20") != -1 ||
193 testFiles[i].indexOf("no_such_method") != -1 ||
194 testFiles[i].indexOf("invalid_request_flags") != -1 ||
195 testFiles[i].indexOf("invalid_response_flags") != -1) {
196 console.log("[Skipping " + testFiles[i] + "]");
197 continue;
198 }
199
200 var testMessage = readTestMessage(testFiles[i]);
201 var handles = new Array(testMessage.handleCount);
202 var message = new codec.Message(testMessage.buffer, handles);
203 var messageValidator = new validator.Validator(message);
204
205 var err = messageValidator.validateMessageHeader();
206 for (var j = 0; err === noError && j < filters.length; ++j)
207 err = filters[j](messageValidator);
208
209 checkValidationResult(testFiles[i], err);
210 }
211 }
212
213 test(() => {
214 testMessageValidation("conformance_", [
215 testInterface.ConformanceTestInterface.validateRequest]);
216 }, 'conformance message validation');
217
218 test(() => {
219 testMessageValidation("boundscheck_", [
220 testInterface.BoundsCheckTestInterface.validateRequest]);
221 }, 'bounds check message validation');
222
223 test(() => {
224 testMessageValidation("resp_conformance_", [
225 testInterface.ConformanceTestInterface.validateResponse]);
226 }, 'response conformance message validation');
227
228 test(() => {
229 testMessageValidation("resp_boundscheck_", [
230 testInterface.BoundsCheckTestInterface.validateResponse]);
231 }, 'response bounds check message validation');
232
233 function testIntegratedMessageValidation(testFilesPattern, endpoint) {
234 var testFiles = getMessageTestFiles(testFilesPattern);
235 assert_greater_than(testFiles.length, 0);
236
237 var testMessagePipe = core.createMessagePipe();
238 assert_equals(testMessagePipe.result, core.RESULT_OK);
239
240 endpoint.bind(testMessagePipe.handle1);
241 var testingController = endpoint.enableTestingMode();
242
243 var validationError;
244 testingController.setInvalidIncomingMessageHandler(function(error) {
245 validationError = error;
246 });
247
248 for (var i = 0; i < testFiles.length; i++) {
249 validationError = noError;
250 var testMessage = readTestMessage(testFiles[i]);
251 var handles = new Array(testMessage.handleCount);
252
253 var writeMessageValue = core.writeMessage(
254 testMessagePipe.handle0,
255 new Uint8Array(testMessage.buffer.arrayBuffer),
256 new Array(testMessage.handleCount),
257 core.WRITE_MESSAGE_FLAG_NONE);
258 assert_equals(writeMessageValue, core.RESULT_OK);
259
260 testingController.waitForNextMessage();
261 checkValidationResult(testFiles[i], validationError);
262 }
263
264 assert_equals(core.close(testMessagePipe.handle0), core.RESULT_OK);
265 }
266
267 test(() => {
268 testIntegratedMessageValidation(
269 "integration_msghdr",
270 new bindings.Binding(testInterface.IntegrationTestInterface, {}));
271 testIntegratedMessageValidation(
272 "integration_msghdr",
273 new testInterface.IntegrationTestInterfacePtr().ptr);
274 }, 'integrated message header validation');
275
276 test(() => {
277 testIntegratedMessageValidation(
278 "integration_intf_rqst",
279 new bindings.Binding(testInterface.IntegrationTestInterface, {}));
280 }, 'integrated request message validation');
281
282 test(() => {
283 testIntegratedMessageValidation(
284 "integration_intf_resp",
285 new testInterface.IntegrationTestInterfacePtr().ptr);
286 }, 'integrated response message validation');
287
288 done();
289 });
290
291 </script>
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/mojo/resources/validation_test_input_parser.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698