194889f430090e7dc0169a9b22c2be9c7454c655
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / tests / properties.js
1
2 QUnit.module("Properties", {
3     setup : function() {
4         QUnit.stop();
5         var that = this;
6         this.cb = function(e) {
7           QUnit.ok(true, "Scene loaded");
8           var iframe = document.getElementById('daliframe');
9           that.doc =  iframe.contentDocument || iframe.contentWindow.document;
10           that.doc.Module.postDaliWrapperRun = function() {
11             dali = that.doc.Module;
12             QUnit.start();
13           };
14         };
15         loadDocument("dali-page.html"+window.location.search, this.cb);
16     },
17     teardown : function() {
18         var v = document.getElementById("daliframe");
19         v.removeEventListener("load", this.cb, true);
20     }
21 });
22
23 QUnit.test( "dotted property access", function( assert ) {
24
25   var actor = new dali.Actor();
26
27   assert.ok( "" === actor.name );
28   assert.ok( compareArrays(actor.position, [0, 0, 0]) );
29   assert.ok( compareArrays(actor.parentOrigin, [0, 0, 0.5]) );
30
31 });
32
33 QUnit.test( "hierarchy", function( assert ) {
34
35   var actor = new dali.Actor();
36   actor.parentOrigin = [0.5, 0.5, 0.5];
37   actor.anchorPoint = [0.5, 0.5, 0.5];
38   actor.text = "actor";
39   actor.name = actor.text;
40   actor.size = [100, 100, 1];
41   actor.position = [0, 0, 10];
42   dali.stage.add(actor);
43
44   var hello = new dali.Actor();
45   hello.text = "hello";
46   hello.name = hello.text;
47   actor.add(hello);
48
49   var hellochild = new dali.Actor();
50   hellochild.text = "hello-child";
51   hellochild.name = hellochild.text;
52   hello.add(hellochild);
53
54   var hellochild2 = new dali.Actor();
55   hellochild2.text = "hello-child2";
56   hellochild2.name = hellochild2.text;
57   hello.add(hellochild2);
58
59   var hellochildchild = new dali.Actor();
60   hellochildchild.text = "hello-child-child1";
61   hellochildchild.name = "hello-child-child1";
62   hellochildchild.name = hellochildchild.text;
63   hellochild.add(hellochildchild);
64
65
66   var depthfirst = actor.findAllChildren();
67
68   assert.ok(actor.getChildCount() === 1);
69
70   var directChildren = actor.directChildren();
71
72   assert.ok(directChildren.length === 1);
73   assert.ok(directChildren[0].getId() === hello.getId());
74
75   actor.position = [100, 100, 0];
76
77   var root = dali.stage.getRootLayer(); //rootRotationActor;
78
79   actor.remove(hello);
80   assert.ok(actor.getChildCount() === 0);
81
82   actor.add(hello);
83   assert.ok(actor.getChildCount() === 1);
84
85   var rootLayerCount = root.getChildCount();
86   dali.stage.remove(actor); // check these don't assert
87   assert.ok(root.getChildCount() === rootLayerCount - 1);
88
89   dali.stage.add(actor);
90   assert.ok(root.getChildCount() === rootLayerCount);
91
92   assert.ok(root.findChildByName("none") === null);
93
94 });
95
96 QUnit.test( "register property", function( assert ) {
97   var s = dali.stage;
98   var root = s.getRootLayer(); //rootRotationActor;
99
100   var another = new dali.Actor();
101   another.parentOrigin = [0.5, 0.5, 0.5];
102   another.anchorPoint = [0.5, 0.5, 0.5];
103   another.text = "peppa";
104   another.name = another.text;
105   another.size = [100, 100, 1];
106   another.position = [-50, 100, 0];
107   root.add(another);
108
109   var c = root.getChildAt(root.getChildCount() - 1);
110   //var n = c.getChildCount();
111   var p = c.getParent();
112   assert.ok(p.getId() == root.getId());
113
114   var matrix = c.worldMatrix;
115
116   assert.ok(matrix.length === 16);
117
118 });
119
120 QUnit.test( "get/set", function( assert ) {
121   var s = dali.stage;
122   threeSquares();
123   var col = {};
124   collectByName(col);
125   var actor = col.red;
126   var p = actor.position;
127   actor.position = [1, 1, 1];
128   assert.ok(compareArrays(actor.position, [1, 1, 1]));
129   actor.position = [3, 3, 3];
130   assert.ok(compareArrays(actor.position, [3, 3, 3]));
131   actor.position = p;
132 });