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

Side by Side Diff: mojo/public/js/codec_unittests.js

Issue 795593004: Update mojo sdk to rev cc531b32182099a5a034a99daff35ed5d38a61c8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More workarounds for MSVC Created 5 years, 11 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 | « mojo/public/js/codec.js ('k') | mojo/public/js/connection.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "gin/test/expect", 6 "gin/test/expect",
7 "mojo/public/js/codec", 7 "mojo/public/js/codec",
8 "mojo/public/interfaces/bindings/tests/rect.mojom", 8 "mojo/public/interfaces/bindings/tests/rect.mojom",
9 "mojo/public/interfaces/bindings/tests/sample_service.mojom", 9 "mojo/public/interfaces/bindings/tests/sample_service.mojom",
10 "mojo/public/interfaces/bindings/tests/test_structs.mojom", 10 "mojo/public/interfaces/bindings/tests/test_structs.mojom",
11 ], function(expect, codec, rect, sample, structs) { 11 ], function(expect, codec, rect, sample, structs) {
12 testBar(); 12 testBar();
13 testFoo(); 13 testFoo();
14 testNamedRegion(); 14 testNamedRegion();
15 testTypes(); 15 testTypes();
16 testAlign(); 16 testAlign();
17 testUtf8(); 17 testUtf8();
18 testTypedPointerValidation();
18 this.result = "PASS"; 19 this.result = "PASS";
19 20
20 function testBar() { 21 function testBar() {
21 var bar = new sample.Bar(); 22 var bar = new sample.Bar();
22 bar.alpha = 1; 23 bar.alpha = 1;
23 bar.beta = 2; 24 bar.beta = 2;
24 bar.gamma = 3; 25 bar.gamma = 3;
25 bar.type = 0x08070605; 26 bar.type = 0x08070605;
26 bar.extraProperty = "banana"; 27 bar.extraProperty = "banana";
27 28
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 var actualMemory = new Uint8Array(message.buffer.arrayBuffer); 249 var actualMemory = new Uint8Array(message.buffer.arrayBuffer);
249 expect(actualMemory.length).toEqual(expectedMemory.length); 250 expect(actualMemory.length).toEqual(expectedMemory.length);
250 expect(actualMemory).toEqual(expectedMemory); 251 expect(actualMemory).toEqual(expectedMemory);
251 252
252 var reader = new codec.MessageReader(message); 253 var reader = new codec.MessageReader(message);
253 expect(reader.payloadSize).toBe(payloadSize); 254 expect(reader.payloadSize).toBe(payloadSize);
254 expect(reader.messageName).toBe(messageName); 255 expect(reader.messageName).toBe(messageName);
255 var str2 = reader.decoder.decodeStringPointer(); 256 var str2 = reader.decoder.decodeStringPointer();
256 expect(str2).toEqual(str); 257 expect(str2).toEqual(str);
257 } 258 }
259
260 function testTypedPointerValidation() {
261 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8);
262 function DummyClass() {};
263 var testCases = [
264 // method, args, invalid examples, valid examples
265 [encoder.encodeArrayPointer, [DummyClass], [75],
266 [[], null, undefined, new Uint8Array([])]],
267 [encoder.encodeStringPointer, [], [75, new String("foo")],
268 ["", "bar", null, undefined]],
269 [encoder.encodeMapPointer, [DummyClass, DummyClass], [75],
270 [new Map(), null, undefined]],
271 ];
272
273 testCases.forEach(function(test) {
274 var method = test[0];
275 var baseArgs = test[1];
276 var invalidExamples = test[2];
277 var validExamples = test[3];
278
279 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8);
280 invalidExamples.forEach(function(invalid) {
281 expect(function() {
282 method.apply(encoder, baseArgs.concat(invalid));
283 }).toThrow();
284 });
285
286 validExamples.forEach(function(valid) {
287 var encoder = new codec.MessageBuilder(42, 24).createEncoder(8);
288 method.apply(encoder, baseArgs.concat(valid));
289 });
290 });
291 }
258 }); 292 });
OLDNEW
« no previous file with comments | « mojo/public/js/codec.js ('k') | mojo/public/js/connection.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698