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 3 // found in the LICENSE file. 4 5 define([ 6 "gin/test/expect", 7 "mojo/public/interfaces/bindings/tests/rect.mojom", 8 "mojo/public/interfaces/bindings/tests/test_structs.mojom" 9 ], function(expect, 10 rect, 11 testStructs) { 12 13 function testConstructors() { 14 var r = new rect.Rect(); 15 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})); 17 18 r.x = 10; 19 r.y = 20; 20 r.width = 30; 21 r.height = 40; 22 var rp = new testStructs.RectPair({first: r, second: r}); 23 expect(rp.first).toEqual(r); 24 expect(rp.second).toEqual(r); 25 26 expect(new testStructs.RectPair({second: r}).first).toBeNull(); 27 28 var nr = new testStructs.NamedRegion(); 29 expect(nr.name).toBeNull(); 30 expect(nr.rects).toBeNull(); 31 expect(nr).toEqual(new testStructs.NamedRegion({})); 32 33 nr.name = "foo"; 34 nr.rects = [r, r, r]; 35 expect(nr).toEqual(new testStructs.NamedRegion({ 36 name: "foo", 37 rects: [r, r, r], 38 })); 39 40 var e = new testStructs.EmptyStruct(); 41 expect(e).toEqual(new testStructs.EmptyStruct({foo:123})); 42 } 43 44 function testNoDefaultFieldValues() { 45 var s = new testStructs.NoDefaultFieldValues(); 46 expect(s.f0).toEqual(false); 47 48 // f1 - f10, number type fields 49 for (var i = 1; i <= 10; i++) 50 expect(s["f" + i]).toEqual(0); 51 52 // f11,12 strings, f13-22 handles, f23-f26 arrays, f27,28 structs 53 for (var i = 11; i <= 28; i++) 54 expect(s["f" + i]).toBeNull(); 55 } 56 57 function testDefaultFieldValues() { 58 var s = new testStructs.DefaultFieldValues(); 59 expect(s.f0).toEqual(true); 60 61 // f1 - f12, number type fields 62 for (var i = 1; i <= 12; i++) 63 expect(s["f" + i]).toEqual(100); 64 65 // f13,14 "foo" 66 for (var i = 13; i <= 14; i++) 67 expect(s["f" + i]).toEqual("foo"); 68 69 // f15,16 a default instance of Rect 70 var r = new rect.Rect(); 71 expect(s.f15).toEqual(r); 72 expect(s.f16).toEqual(r); 73 } 74 75 testConstructors(); 76 testNoDefaultFieldValues(); 77 testDefaultFieldValues(); 78 this.result = "PASS"; 79 });