Update with current status
[gnash.git] / testsuite / misc-ming.all / DragDropTest.as
blob6ed02e6877712241ec6a78e978518949edf16fd5
1 //
2 // Build with:
3 // makeswf -o DrawingApi.swf ../Dejagnu.swf DrawingApi.as
4 // Run with:
5 // firefox DrawingApi.swf
6 // Or:
7 // gnash DrawingApi.swf
8 //
9 //
12 #define info _root.note
13 #define note _root.note
14 #define fail_check _root.fail
15 #define pass_check _root.pass
16 #define xfail_check _root.xfail
17 #define xpass_check _root.xpass
19 #ifdef LOADED_VERSION
20 #define SUPPRESS_RCSID_DUMP
21 #endif
23 #include "../actionscript.all/check.as"
24 #include "../actionscript.all/utils.as"
26 printBounds = function(b)
28 return ''+Math.round(b.xMin*100)/100+','+Math.round(b.yMin*100)/100+' '+Math.round(b.xMax*100)/100+','+Math.round(b.yMax*100)/100;
31 // Draw a circle with given center and radius
32 // Uses 8 curves to approximate the circle
33 drawCircle = function (where, x, y, rad)
35 var ctl = Math.sin(24*Math.PI/180)*rad;
36 var cos = Math.cos(45*Math.PI/180)*rad;
37 var sin = Math.sin(45*Math.PI/180)*rad;
39 with (where)
41 moveTo(x, y-rad);
42 curveTo(x+ctl, y-rad, x+cos, y-sin);
43 curveTo(x+rad, y-ctl, x+rad, y);
44 curveTo(x+rad, y+ctl, x+cos, y+sin);
45 curveTo(x+ctl, y+rad, x, y+rad);
46 curveTo(x-ctl, y+rad, x-cos, y+sin);
47 curveTo(x-rad, y+ctl, x-rad, y);
48 curveTo(x-rad, y-ctl, x-cos, y-sin);
49 curveTo(x-ctl, y-rad, x, y-rad);
53 dragOverHandler = function()
55 check_equals(this, _root.target10);
56 note(this+'.onDragOver called with args: '+dumpObject(arguments));
58 dragOutHandler = function()
60 check_equals(this, _root.target10);
61 note(this+'.onDragOver called with args: '+dumpObject(arguments));
64 createTextField("tf", 0, 0, 100, 20, 5004);
65 tf.text = "Hello";
67 createEmptyMovieClip("target10", 10);
68 with (target10)
70 lineStyle(4, 0);
71 beginFill(0xFF0000, 100);
72 drawCircle(target10, 50, 50, 20);
73 #if 1
74 target10.onDragOver = dragOverHandler;
75 target10.onDragOut = dragOutHandler;
76 #else
77 target10.onDragOver = function()
79 check_equals(this, _root.target10);
80 note("(onDragOver): draggable dragged over "+this._droptarget);
82 target10.onDragOut = function()
84 check_equals(this, _root.target10);
85 note("(onDragOut): draggable dragged out of "+this._droptarget);
87 #endif
88 #ifdef LOADED_VERSION
89 _x = 100;
90 #endif
93 createEmptyMovieClip("target20", 20);
94 with (target20)
96 lineStyle(4, 0);
97 beginFill(0x00FF00, 100);
98 drawCircle(target20, 100, 50, 20);
99 #if 1
100 target20.onDragOver = dragOverHandler;
101 target20.onDragOut = dragOutHandler;
102 #else
103 target20.onDragOver = function()
105 check_equals(this, _root.target20);
106 note("(onDragOver): draggable dragged over "+this._droptarget);
108 target20.onDragOut = function()
110 check_equals(this, _root.target20);
111 note("(onDragOut): draggable dragged out of "+this._droptarget);
113 #endif
115 #ifdef LOADED_VERSION
116 _x = 100;
117 #endif
120 createEmptyMovieClip("target100", 100);
121 with (target100)
123 lineStyle(4, 0);
124 beginFill(0x0000FF, 50);
125 drawCircle(target100, 70, 100, 20);
126 #if 1
127 target100.onDragOver = dragOverHandler;
128 target100.onDragOut = dragOutHandler;
129 #else
130 target100.onDragOver = function()
132 check_equals(this, _root.target100);
133 note("(onDragOver): draggable dragged over "+this._droptarget);
135 target100.onDragOut = function()
137 check_equals(this, _root.target100);
138 note("(onDragOut): draggable dragged out of "+this._droptarget);
140 #endif
142 #ifdef LOADED_VERSION
143 _x = 100;
144 #endif
147 #ifndef LOADED_VERSION
149 loadMovie("DragDropTestLoaded.swf", "_level50");
151 createEmptyMovieClip("loadedTarget", 30);
152 loadedTarget.loadMovie("DragDropTestLoaded.swf");
153 loadedTarget._x = 100;
155 createEmptyMovieClip("draggable50", 50);
156 with (draggable50)
158 lineStyle(1, 0);
159 beginFill(0x00FFFF, 50);
160 drawCircle(draggable50, 0, 0, 10);
161 draggable50.startDrag(true, 0, 0, 500, 120);
162 #if 1
163 draggable50.onDragOver = dragOverHandler;
164 draggable50.onDragOut = dragOutHandler;
165 #else
166 draggable50.onDragOver = function()
168 check_equals(this, _root.draggable50);
169 note("(onDragOver): draggable dragged over "+this._droptarget);
171 draggable50.onDragOut = function()
173 check_equals(this, _root.draggable50);
174 note("(onDragOut): draggable dragged out of "+this._droptarget);
176 #endif
178 draggable50.lastDropTarget = undefined;
179 draggable50.onEnterFrame = function()
181 //check_equals(this, _root.draggable50);
182 if ( this._droptarget != this.lastDropTarget )
184 if ( this._droptarget != "" )
186 // reduces space on the textfield..
187 //note(" -> draggable over "+this._droptarget);
189 this.lastDropTarget = this._droptarget;
194 Dejagnu._y = 100;
196 note("- This test is for drag&drop operations. Follow the instructions - ");
198 test1 = function()
200 note("1. Click OUTSIDE of any drawing.");
201 _root.onMouseDown = function()
203 check_equals(_root.draggable50._droptarget, "");
204 check_equals(eval(_root.draggable50._droptarget), undefined);
205 test2();
209 test2 = function()
211 note("2. Click on the FIRST RED circle.");
212 _root.onMouseDown = function()
214 check_equals(_root.draggable50._droptarget, "/target10");
215 check_equals(eval(_root.draggable50._droptarget), _level0.target10);
216 test3();
220 test3 = function()
222 note("3. Click on the FIRST GREEN circle.");
223 _root.onMouseDown = function()
225 check_equals(_root.draggable50._droptarget, "/target20");
226 check_equals(eval(_root.draggable50._droptarget), _level0.target20);
227 test4();
231 test4 = function()
233 note("4. Click on the FIRST BLUE circle.");
234 _root.onMouseDown = function()
236 check_equals(_root.draggable50._droptarget, "/target100");
237 check_equals(eval(_root.draggable50._droptarget), _level0.target100);
238 test5();
242 test5 = function()
244 note("5. Click on the SECOND RED circle.");
245 _root.onMouseDown = function()
247 check_equals(_root.draggable50._droptarget, "_level50/target10");
248 check_equals(eval(_root.draggable50._droptarget), _level50.target10);
249 test6();
253 test6 = function()
255 note("6. Click on the SECOND GREEN circle.");
256 _root.onMouseDown = function()
258 check_equals(_root.draggable50._droptarget, "_level50/target20");
259 check_equals(eval(_root.draggable50._droptarget), _level50.target20);
260 test7();
264 test7 = function()
266 note("7. Click on the SECOND BLUE circle.");
267 _root.onMouseDown = function()
269 check_equals(_root.draggable50._droptarget, "_level50/target100");
270 check_equals(eval(_root.draggable50._droptarget), _level50.target100);
271 test8();
275 test8 = function()
277 note("8. Click on the THIRD RED circle.");
278 _root.onMouseDown = function()
280 check_equals(_root.draggable50._droptarget, "/loadedTarget/target10");
281 check_equals(eval(_root.draggable50._droptarget), _level0.loadedTarget.target10);
282 test9();
286 test9 = function()
288 note("9. Click on the THIRD GREEN circle.");
289 _root.onMouseDown = function()
291 check_equals(_root.draggable50._droptarget, "/loadedTarget/target20");
292 check_equals(eval(_root.draggable50._droptarget), _level0.loadedTarget.target20);
293 test10();
297 test10 = function()
299 note("10. Click on the THIRD BLUE circle.");
300 _root.onMouseDown = function()
302 check_equals(_root.draggable50._droptarget, "/loadedTarget/target100");
303 check_equals(eval(_root.draggable50._droptarget), _level0.loadedTarget.target100);
305 // move the draggable over the first green square
306 _root.draggable50._x = _root.draggable50._y = 50;
308 test11();
312 // Check that startDrag works for a textfield.
313 // The textfield should no longer be at 0, 100.
314 test11 = function()
316 note("11. Click on the SECOND GREEN circle.");
318 // Deliberately set target to null and then
319 // call stopDrag (old version) to make sure it still works.
320 asm { push null settargetexpr };
321 stopDrag();
323 check_equals(_root.tf._x, 0);
324 check_equals(_root.tf._y, 100);
326 tf.startDrag = MovieClip.prototype.startDrag;
327 tf.startDrag(true);
328 _root.onMouseDown = function()
330 check_equals(_root.draggable50._droptarget, "/loadedTarget/target100");
331 check(_root.tf._x != 0);
332 check(_root.tf._y != 100);
333 test12();
337 test12 = function()
339 note("12. Click ANYWHERE OUT of the THIRD BLUE circle (on another circle makes a better test)");
340 _root.onMouseDown = function()
342 check_equals(_root.draggable50._droptarget, "/loadedTarget/target100");
343 endOfTest(); // TODO: test that moving the draggable out of any drawing changes _droptarget to the empty string
348 endOfTest = function()
350 _root.ENDOFTEST = true;
351 note("END OF TEST");
352 check_totals(26);
353 _root.onMouseDown = undefined;
356 test1(); // start the test
359 #endif // ndef LOADED_VERSION
361 stop();