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

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

Issue 377713004: Support packed arrays of booleans in Mojo messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified Decoder.prototype.decodeBoolArray() Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/sample_service.mojom » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/bindings/codec", 7 "mojo/public/js/bindings/codec",
8 "mojo/public/interfaces/bindings/tests/sample_service.mojom", 8 "mojo/public/interfaces/bindings/tests/sample_service.mojom",
9 ], function(expect, codec, sample) { 9 ], function(expect, codec, sample) {
10 testBar(); 10 testBar();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 foo.extra_bars[i].alpha = 1 * i; 80 foo.extra_bars[i].alpha = 1 * i;
81 foo.extra_bars[i].beta = 2 * i; 81 foo.extra_bars[i].beta = 2 * i;
82 foo.extra_bars[i].gamma = 3 * i; 82 foo.extra_bars[i].gamma = 3 * i;
83 } 83 }
84 foo.name = "I am a banana"; 84 foo.name = "I am a banana";
85 // This is supposed to be a handle, but we fake it with an integer. 85 // This is supposed to be a handle, but we fake it with an integer.
86 foo.source = 23423782; 86 foo.source = 23423782;
87 foo.array_of_array_of_bools = [ 87 foo.array_of_array_of_bools = [
88 [true], [false, true] 88 [true], [false, true]
89 ]; 89 ];
90 foo.array_of_bools = [
91 true, false, true, false, true, false, true, true
92 ];
93
90 94
91 var messageName = 31; 95 var messageName = 31;
92 var payloadSize = 280; 96 var payloadSize = 304;
93 97
94 var builder = new codec.MessageBuilder(messageName, payloadSize); 98 var builder = new codec.MessageBuilder(messageName, payloadSize);
95 builder.encodeStruct(sample.Foo, foo); 99 builder.encodeStruct(sample.Foo, foo);
96 100
97 var message = builder.finish(); 101 var message = builder.finish();
98 102
99 var expectedMemory = new Uint8Array([ 103 var expectedMemory = new Uint8Array([
100 /* 0: */ 16, 0, 0, 0, 2, 0, 0, 0, 104 /* 0: */ 16, 0, 0, 0, 2, 0, 0, 0,
101 /* 8: */ 31, 0, 0, 0, 0, 0, 0, 0, 105 /* 8: */ 31, 0, 0, 0, 0, 0, 0, 0,
102 /* 16: */ 88, 0, 0, 0, 14, 0, 0, 0, 106 /* 16: */ 96, 0, 0, 0, 15, 0, 0, 0,
103 /* 24: */ 0xD5, 0xB4, 0x12, 0x02, 0x93, 0x6E, 0x01, 0, 107 /* 24: */ 0xD5, 0xB4, 0x12, 0x02, 0x93, 0x6E, 0x01, 0,
104 /* 32: */ 5, 0, 0, 0, 0, 0, 0, 0, 108 /* 32: */ 5, 0, 0, 0, 0, 0, 0, 0,
105 /* 40: */ 64, 0, 0, 0, 0, 0, 0, 0, 109 /* 40: */ 72, 0, 0, 0, 0, 0, 0, 0,
106 ]); 110 ]);
107 // TODO(abarth): Test more of the message's raw memory. 111 // TODO(abarth): Test more of the message's raw memory.
108 var actualMemory = new Uint8Array(message.buffer.arrayBuffer, 112 var actualMemory = new Uint8Array(message.buffer.arrayBuffer,
109 0, expectedMemory.length); 113 0, expectedMemory.length);
110 expect(actualMemory).toEqual(expectedMemory); 114 expect(actualMemory).toEqual(expectedMemory);
111 115
112 var expectedHandles = [ 116 var expectedHandles = [
113 23423782, 117 23423782,
114 ]; 118 ];
115 119
(...skipping 12 matching lines...) Expand all
128 expect(foo2.a).toBe(foo.a & 1 ? true : false); 132 expect(foo2.a).toBe(foo.a & 1 ? true : false);
129 expect(foo2.b).toBe(foo.b & 1 ? true : false); 133 expect(foo2.b).toBe(foo.b & 1 ? true : false);
130 expect(foo2.c).toBe(foo.c & 1 ? true : false); 134 expect(foo2.c).toBe(foo.c & 1 ? true : false);
131 135
132 expect(foo2.bar).toEqual(foo.bar); 136 expect(foo2.bar).toEqual(foo.bar);
133 expect(foo2.data).toEqual(foo.data); 137 expect(foo2.data).toEqual(foo.data);
134 138
135 expect(foo2.extra_bars).toEqual(foo.extra_bars); 139 expect(foo2.extra_bars).toEqual(foo.extra_bars);
136 expect(foo2.name).toBe(foo.name); 140 expect(foo2.name).toBe(foo.name);
137 expect(foo2.source).toEqual(foo.source); 141 expect(foo2.source).toEqual(foo.source);
142
143 expect(foo2.array_of_bools).toEqual(foo.array_of_bools);
138 } 144 }
139 145
140 function testTypes() { 146 function testTypes() {
141 function encodeDecode(cls, input, expectedResult, encodedSize) { 147 function encodeDecode(cls, input, expectedResult, encodedSize) {
142 var messageName = 42; 148 var messageName = 42;
143 var payloadSize = encodedSize || cls.encodedSize; 149 var payloadSize = encodedSize || cls.encodedSize;
144 150
145 var builder = new codec.MessageBuilder(messageName, payloadSize); 151 var builder = new codec.MessageBuilder(messageName, payloadSize);
146 builder.encodeStruct(cls, input) 152 builder.encodeStruct(cls, input)
147 var message = builder.finish(); 153 var message = builder.finish();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 expect(actualMemory.length).toEqual(expectedMemory.length); 219 expect(actualMemory.length).toEqual(expectedMemory.length);
214 expect(actualMemory).toEqual(expectedMemory); 220 expect(actualMemory).toEqual(expectedMemory);
215 221
216 var reader = new codec.MessageReader(message); 222 var reader = new codec.MessageReader(message);
217 expect(reader.payloadSize).toBe(payloadSize); 223 expect(reader.payloadSize).toBe(payloadSize);
218 expect(reader.messageName).toBe(messageName); 224 expect(reader.messageName).toBe(messageName);
219 var str2 = reader.decoder.decodeStringPointer(); 225 var str2 = reader.decoder.decodeStringPointer();
220 expect(str2).toEqual(str); 226 expect(str2).toEqual(str);
221 } 227 }
222 }); 228 });
OLDNEW
« no previous file with comments | « no previous file | mojo/public/interfaces/bindings/tests/sample_service.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698