Merge "Added PixelBuffer for image loading and operations." into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / tests / animation.js
1
2 QUnit.module("Animation", {
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( "spline path", function( assert ) {
24
25   var done1 = assert.async();
26
27   threeSquares();
28   var col = {};
29   collectByName(col);
30   var actor = col.red;
31
32   var a = new dali.Animation(0);
33   var path = new dali.Path();
34
35   path.points = [
36     [-150, -50, 0],
37     [0.0, 70.0, 0.0],
38     [190.0, -150.0, 0.0]
39   ];
40
41   assert.ok(compareArrays(path.points, [
42     [-150, -50, 0],
43     [0.0, 70.0, 0.0],
44     [190.0, -150.0, 0.0]
45   ]));
46
47   dali.generateControlPoints(path, 0.35);
48
49   assert.ok(compareArrays(path.controlPoints, [
50     [-97.5, -8, 0],
51     [-66.94940948486328, 76.16658020019531, 0],
52     [101.31224060058594, 60.66832733154297, 0],
53     [123.5, -73, 0]
54   ]));
55
56   a.setDuration(0.1);
57   a.animatePath(actor, path, [1, 0, 0], dali.AlphaFunction.LINEAR, 0, 0.1);
58   a.play();
59
60
61   function checkPos() {
62     assert.ok(actor.position = path.points[2]);
63     clear();
64     actor.delete();
65     path.delete();
66     a.delete();
67     done1();
68   }
69
70   window.setTimeout(checkPos, 200);
71
72 });
73
74 QUnit.test( "linear", function( assert ) {
75
76   var done1 = assert.async();
77   var done2 = assert.async();
78   var done3 = assert.async();
79
80   threeSquares();
81   var col = {};
82   collectByName(col);
83   var actor = col.red;
84
85   var a = new dali.Animation(0);
86   a.setDuration(0.1);
87   a.animateTo(actor, "position", [20, 0, 0], dali.AlphaFunction.LINEAR, 0, 0.1);
88   a.play();
89
90   function checkAnimateBetween() {
91     assert.ok(actor.position = [0, 0, -30]);
92     clear();
93     a.delete();
94     actor.delete();
95     done3();
96   }
97
98   function checkAnimateBy() {
99     assert.ok(actor.position = [120, 100, 0]);
100     a.clear();
101     a.animateBetween(actor,
102                      "position", [ [ 0,  [10,20,30] ],
103                                    [ 1.0,[0, 0, -30] ] ],
104                      "linear",
105                      0,
106                      0.1,
107                      "linear");
108     a.play();
109     window.setTimeout(checkAnimateBetween, 200);
110     done2();
111   }
112
113   function checkAnimateTo() {
114     assert.ok(actor.position = [20, 0, 0]);
115     actor.position = [100, 100, 0];
116
117     a.clear(); // var a = new dali.Animation(0);
118     a.setDuration(0.1);
119     a.animateBy(actor, "position", [20, 0, 0], dali.AlphaFunction.LINEAR, 0, 0.1);
120     a.play();
121     window.setTimeout(checkAnimateBy, 200);
122     done1();
123   }
124
125   window.setTimeout(checkAnimateTo, 200);
126
127 });
128