OLD | NEW |
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 ], function(expect, | 9 ], function(expect, |
10 rect, | 10 rect, |
11 testStructs) { | 11 testStructs) { |
12 | 12 |
13 function testConstructors() { | 13 function testConstructors() { |
14 var r = new rect.Rect(); | 14 var r = new rect.Rect(); |
15 expect(r).toEqual(new rect.Rect({x:0, y:0, width:0, height:0})); | 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})); | 16 expect(r).toEqual(new rect.Rect({foo:100, bar:200})); |
17 | 17 |
18 r.x = 10; | 18 r.x = 10; |
19 r.y = 20; | 19 r.y = 20; |
20 r.width = 30; | 20 r.width = 30; |
21 r.height = 40; | 21 r.height = 40; |
22 var rp = new testStructs.RectPair({first: r, second: r}); | 22 var rp = new testStructs.RectPair({first: r, second: r}); |
23 expect(rp.first).toEqual(r); | 23 expect(rp.first).toEqual(r); |
24 expect(rp.second).toEqual(r); | 24 expect(rp.second).toEqual(r); |
25 | 25 |
26 expect(new testStructs.RectPair({second: r}).first).toBeNull(); | 26 expect(new testStructs.RectPair({second: r}).first).toBeNull(); |
27 | 27 |
28 var nr = new testStructs.NamedRegion(); | 28 var nr = new testStructs.NamedRegion(); |
29 // TODO(hansmuller): nr.name should be null, see crbug.com/417039. | 29 expect(nr.name).toBeNull(); |
30 expect(nr.name).toBe(""); | |
31 expect(nr.rects).toBeNull(); | 30 expect(nr.rects).toBeNull(); |
32 expect(nr).toEqual(new testStructs.NamedRegion({})); | 31 expect(nr).toEqual(new testStructs.NamedRegion({})); |
33 | 32 |
34 nr.name = "foo"; | 33 nr.name = "foo"; |
35 nr.rects = [r, r, r]; | 34 nr.rects = [r, r, r]; |
36 expect(nr).toEqual(new testStructs.NamedRegion({ | 35 expect(nr).toEqual(new testStructs.NamedRegion({ |
37 name: "foo", | 36 name: "foo", |
38 rects: [r, r, r], | 37 rects: [r, r, r], |
39 })); | 38 })); |
40 | 39 |
41 var e = new testStructs.EmptyStruct(); | 40 var e = new testStructs.EmptyStruct(); |
42 expect(e).toEqual(new testStructs.EmptyStruct({foo:123})); | 41 expect(e).toEqual(new testStructs.EmptyStruct({foo:123})); |
43 } | 42 } |
44 | 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 |
45 testConstructors(); | 75 testConstructors(); |
| 76 testNoDefaultFieldValues(); |
| 77 testDefaultFieldValues(); |
46 this.result = "PASS"; | 78 this.result = "PASS"; |
47 }); | 79 }); |
OLD | NEW |