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

Side by Side Diff: mojo/public/js/bindings/struct_unittests.js

Issue 654843005: Mojo JS Bindings: add support for associative arrays (Mojo map type) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/interfaces/bindings/tests/rect.mojom", 7 "mojo/public/interfaces/bindings/tests/rect.mojom",
8 "mojo/public/interfaces/bindings/tests/test_structs.mojom" 8 "mojo/public/interfaces/bindings/tests/test_structs.mojom",
9 "mojo/public/js/bindings/codec",
9 ], function(expect, 10 ], function(expect,
10 rect, 11 rect,
11 testStructs) { 12 testStructs,
13 codec) {
12 14
13 function testConstructors() { 15 function testConstructors() {
14 var r = new rect.Rect(); 16 var r = new rect.Rect();
15 expect(r).toEqual(new rect.Rect({x:0, y:0, width:0, height:0})); 17 expect(r).toEqual(new rect.Rect({x:0, y:0, width:0, height:0}));
16 expect(r).toEqual(new rect.Rect({foo:100, bar:200})); 18 expect(r).toEqual(new rect.Rect({foo:100, bar:200}));
17 19
18 r.x = 10; 20 r.x = 10;
19 r.y = 20; 21 r.y = 20;
20 r.width = 30; 22 r.width = 30;
21 r.height = 40; 23 r.height = 40;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 var s = new testStructs.ScopedConstants(); 88 var s = new testStructs.ScopedConstants();
87 expect(s.f0).toEqual(0); 89 expect(s.f0).toEqual(0);
88 expect(s.f1).toEqual(1); 90 expect(s.f1).toEqual(1);
89 expect(s.f2).toEqual(10); 91 expect(s.f2).toEqual(10);
90 expect(s.f3).toEqual(10); 92 expect(s.f3).toEqual(10);
91 expect(s.f4).toEqual(11); 93 expect(s.f4).toEqual(11);
92 expect(s.f5).toEqual(10); 94 expect(s.f5).toEqual(10);
93 expect(s.f6).toEqual(10); 95 expect(s.f6).toEqual(10);
94 } 96 }
95 97
98 function structEncodeDecode(struct) {
99 var structClass = struct.constructor;
100 var builder = new codec.MessageBuilder(1234, structClass.encodedSize);
101 builder.encodeStruct(structClass, struct);
102 var reader = new codec.MessageReader(builder.finish());
103 return reader.decodeStruct(structClass);
104 }
105
106 function testMapFields() {
107 var mapFieldsStruct = new testStructs.MapFields({
108 f0: new Map([[true, false], [false, true]]), // map<bool, bool>
109 f1: new Map([[0, 0], [1, 127], [-1, -128]]), // map<int8, int8>
110 f2: new Map([[0, 0], [1, 127], [2, 255]]), // map<uint8, uint8>
111 f3: new Map([[0, 0], [1, 32767], [2, -32768]]), // map<int16, int16>
112 f4: new Map([[0, 0], [1, 32768], [2, 0xFFFF]]), // map<uint16, uint16>
113 f5: new Map([[0, 0], [1, 32767], [2, -32768]]), // map<int32, int32>
114 f6: new Map([[0, 0], [1, 32768], [2, 0xFFFF]]), // map<uint32, uint32>
115 f7: new Map([[1000.5, -50000], [100.5, 5000]]), // map<float, float>
116 f8: new Map([[-100.5, -50000], [0, 50000000]]), // map<double, double>
117 f9: new Map([["one", "two"], ["free", "four"]]), // map<string, string>
118 });
119 var decodedStruct = structEncodeDecode(mapFieldsStruct);
120 expect(decodedStruct.f0).toEqual(mapFieldsStruct.f0);
121 expect(decodedStruct.f1).toEqual(mapFieldsStruct.f1);
122 expect(decodedStruct.f2).toEqual(mapFieldsStruct.f2);
123 expect(decodedStruct.f3).toEqual(mapFieldsStruct.f3);
124 expect(decodedStruct.f4).toEqual(mapFieldsStruct.f4);
125 expect(decodedStruct.f5).toEqual(mapFieldsStruct.f5);
126 expect(decodedStruct.f6).toEqual(mapFieldsStruct.f6);
127 expect(decodedStruct.f7).toEqual(mapFieldsStruct.f7);
128 expect(decodedStruct.f8).toEqual(mapFieldsStruct.f8);
129 expect(decodedStruct.f9).toEqual(mapFieldsStruct.f9);
130 }
131
96 testConstructors(); 132 testConstructors();
97 testNoDefaultFieldValues(); 133 testNoDefaultFieldValues();
98 testDefaultFieldValues(); 134 testDefaultFieldValues();
99 testScopedConstants(); 135 testScopedConstants();
136 testMapFields();
100 this.result = "PASS"; 137 this.result = "PASS";
101 }); 138 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698