2 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Test case for MovieClipLoader ActionScript class
22 // compile this test case with Ming makeswf, and then
23 // execute it like this gnash -1 -r 0 -v out.swf
26 rcsid
="MovieClipLoader.as";
31 // MovieClipLoader was added in player7
32 #if OUTPUT_VERSION
>= 7
34 check_equals
(typeOf
(MovieClipLoader
), 'function');
35 check_equals
(typeOf
(MovieClipLoader
.prototype
), 'object');
36 check
(MovieClipLoader
.prototype
.hasOwnProperty
('loadClip'));
37 check
(MovieClipLoader
.prototype
.hasOwnProperty
('unloadClip'));
38 check
(MovieClipLoader
.prototype
.hasOwnProperty
('getProgress'));
39 check
(MovieClipLoader
.prototype
.hasOwnProperty
('addListener'));
40 check
(MovieClipLoader
.prototype
.hasOwnProperty
('removeListener'));
41 check
(MovieClipLoader
.prototype
.hasOwnProperty
('broadcastMessage'));
42 check_equals
(typeOf
(MovieClipLoader
._listeners
), 'undefined');
44 var mcl
= new MovieClipLoader
();
45 check_equals
(typeOf
(mcl
), 'object');
46 check
(mcl instanceOf MovieClipLoader
);
48 check_equals
(typeOf
(mcl
.loadClip
), 'function');
49 check
(!mcl
.hasOwnProperty
('loadClip'));
51 check_equals
(typeOf
(mcl
.unloadClip
), 'function');
52 check
(!mcl
.hasOwnProperty
('unloadClip'));
54 ret
= mcl
.unloadClip
();
55 check_equals
(ret
, undefined);
57 check_equals
(typeOf
(mcl
.getProgress
), 'function');
58 check
(!mcl
.hasOwnProperty
('getProgress'));
60 check_equals
(typeOf
(mcl
.addListener
), 'function');
61 check
(!mcl
.hasOwnProperty
('addListener'));
63 check_equals
(typeOf
(mcl
.removeListener
), 'function');
64 check
(!mcl
.hasOwnProperty
('removeListener'));
66 check_equals
(typeOf
(mcl
.broadcastMessage
), 'function');
67 check
(!mcl
.hasOwnProperty
('broadcastMessage'));
69 check_equals
(typeOf
(mcl
._listeners
), 'object');
70 check
(mcl
.hasOwnProperty
('_listeners'));
71 check_equals
(mcl
._listeners
.length
, 1);
72 check_equals
(mcl
._listeners
[0], mcl
);
74 MovieClipLoader
.prototype
.bm
= MovieClipLoader
.prototype
.broadcastMessage
;
75 MovieClipLoader
.prototype
.broadcastMessage
= function(arg1
, arg2
, arg3
, arg4
)
77 //note("Broadcasting "+arg1);
78 //this.bm(arg1, arg2, arg3, arg4);
79 this.bm
.apply
(this, arguments);
82 // Test simple loadClip calls
84 lmc
= _root
.createEmptyMovieClip
("lmc", 2000);
85 mldr
= new MovieClipLoader
();
88 ret
= mldr
.loadClip
("h", lmc
);
89 check_equals
(ret
, true);
92 ret
= mldr
.loadClip
(9, lmc
);
93 check_equals
(ret
, false);
96 ret
= mldr
.loadClip
("h", lmc
);
97 check_equals
(ret
, true);
100 ret
= mldr
.loadClip
(true, lmc
);
101 check_equals
(ret
, false);
103 ret
= mldr
.loadClip
(false, lmc
);
104 check_equals
(ret
, false);
107 ret
= mldr
.loadClip
(null, lmc
);
108 check_equals
(ret
, false);
110 // String again (just to check it doesn't depend on previous calls).
111 ret
= mldr
.loadClip
("h", lmc
);
112 check_equals
(ret
, true);
115 ret
= mldr
.loadClip
(undefined, lmc
);
116 check_equals
(ret
, false);
119 ret
= mldr
.loadClip
([], lmc
);
120 check_equals
(ret
, false);
125 ret
= mldr
.loadClip
(o
, lmc
);
126 check_equals
(ret
, false);
128 // Object with toString
129 o
.toString
= function() { return "url"; };
130 ret
= mldr
.loadClip
(o
, lmc
);
131 check_equals
(ret
, false);
133 // Object with valueOf
134 o
.valueOf
= function() { return "url"; };
135 ret
= mldr
.loadClip
(o
, lmc
);
136 check_equals
(ret
, false);
139 //---------------------------------------------------------
140 // Test loadClip and events
141 //---------------------------------------------------------
143 // TODO: test even handlers (actionscript.all framework
144 // not enough for this)
146 // Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load.
147 // MovieClipLoader.onLoadError
149 // Invoked when a call to MovieClipLoader.loadClip() has successfully begun to download a file.
150 // MovieClipLoader.onLoadStart
152 // Invoked every time the loading content is written to disk during the loading process.
153 // MovieClipLoader.onLoadProgress
155 // Invoked when a file loaded with MovieClipLoader.loadClip() has completely downloaded.
156 // MovieClipLoader.onLoadComplete
158 // Invoked when the actions on the first frame of the loaded clip have been executed.
159 // MovieClipLoader.onLoadInit
161 //---------------------------------------------------------
163 dumpObj
= function(o
, lvl
)
165 if ( typeof(lvl
) == 'undefined' ) lvl
=0;
168 note
(lvl
+' - '+i
+': '+o
[i
]+' ('+typeof(o
[i
])+')');
169 if ( typeof(o
[i
]) == 'object' ) dumpObj
(o
[i
], lvl
+1);
174 createEmptyMovieClip
("loadtarget", 10);
180 resetState
= function()
185 onLoadProgressCalls
:0,
186 onLoadCompleteCalls
:0,
190 totalProgressCalls
=0;
192 nextTestOrEnd
= function()
194 //note("nextTestOrEnd");
195 if ( state
.nextFunction
== undefined )
197 // we don't know how many times onLoadProgress will be called
198 // so we have that handler increment a totalProgressCalls and
199 // we use that value to figure out how many tests to expect to
200 // be run (6 tests each onLoadProgress call).
201 // Note that if we miss to call onLoadProgress at all we'd catch
202 // the bug from supposedly subsequent callbacks, which check for
203 // a local flag set by the onLoadProgress handler.
205 var testsPerProgressCallback
= 15;
206 progCallbackTests
= totalProgressCalls
*testsPerProgressCallback
;
207 note
("Number of onLoadProgress runs: "+totalProgressCalls
+" - tests: "+progCallbackTests
);
208 if ( expected
.failtotals
) {
209 // this is failing due to vars.txt not being loaded
211 xcheck_totals
(expected
.totals
+ progCallbackTests
);
213 check_totals
(expected
.totals
+ progCallbackTests
);
219 state
.nextFunction
();
223 mcl
.onLoadError
= function(target
, msg
, n
)
225 check_equals
(arguments.length
, 3);
226 check_equals
(target
, expected
.target
);
227 note
("onLoadError called ("+msg
+")");
229 //dumpObj(arguments);
232 mcl
.onLoadStart
= function(target
)
234 check_equals
(arguments.length
, 1);
235 // a bug in Gnash made softrefs always convert
236 // to the empty string when not pointing to
237 // their original target...
238 check
(target
+"" != "");
239 check_equals
(target
, expected
.target
);
240 state
.onLoadStartCalls
++;
241 note
("onLoadStart("+target
+", "+target
._url
+") called");
242 //note("onLoadStart called with "+arguments.length+" args:"); dumpObj(arguments);
245 mcl
.onLoadProgress
= function(target
, bytesLoaded
, bytesTotal
)
247 //note("onLoadProgress("+target+", "+target._url+") called");
249 check_equals
(arguments.length
, 3);
250 check_equals
(target
, expected
.target
);
251 check_equals
(state
.onLoadStartCalls
, 1);
252 check_equals
(typeof(bytesLoaded
), 'number')
253 check_equals
(typeof(bytesTotal
), 'number')
254 check
(bytesTotal
<= bytesTotal
);
256 check_equals
(this, mcl
);
258 var tmp
= this.getProgress
();
259 check_equals
(typeof(tmp
), 'undefined');
261 var prog
= this.getProgress
(target
);
262 check_equals
(typeof(prog
), 'object');
263 check_equals
(prog
.__proto__
, undefined);
264 check_equals
(prog
.bytesLoaded
, bytesLoaded
);
265 check_equals
(prog
.bytesTotal
, bytesTotal
);
266 var progcopy
= {}; var progcount
=0;
267 for (var i
in prog
) { progcopy
[i
] = prog
[i
]; progcount
++; }
268 check_equals
(progcount
, 2);
269 check_equals
(progcopy
.bytesLoaded
, bytesLoaded
);
270 check_equals
(progcopy
.bytesTotal
, bytesTotal
);
272 ++state
.onLoadProgressCalls
;
273 ++totalProgressCalls
;
274 //note("onLoadProgress called with "+arguments.length+" args:"); dumpObj(arguments);
277 mcl
.onLoadComplete
= function(target
, n
)
279 note
("onLoadComplete("+target
+", "+target
._url
+") called");
280 check_equals
(arguments.length
, 2);
281 check_equals
(target
, expected
.target
);
282 check_equals
(state
.onLoadStartCalls
, 1);
283 check
(state
.onLoadProgressCalls
> 0);
284 check_equals
(typeof(n
), 'number'); // what is this ?
285 state
.onLoadCompleteCalls
++;
287 note
("onLoadComplete second arg is "+n
+" ("+typeof(n
)+")");
290 mcl
.onLoadInit
= function(target
)
292 note
("onLoadInit("+target
+", "+target
._url
+") called");
293 check_equals
(arguments.length
, 1);
294 check_equals
(target
, expected
.target
);
295 check_equals
(state
.onLoadStartCalls
, 1);
296 check
(state
.onLoadProgressCalls
> 0);
297 check_equals
(state
.onLoadCompleteCalls
, 1);
298 state
.onLoadInitCalls
++;
300 check_equals
(this, mcl
);
302 // At onLoadInit time the _url parameter is the url of
303 // old target with appended url of new target (?)
304 // So we test if it ends with it instead
305 var indexOfGreenJpeg
= target
._url
.indexOf
('green.jpg');
306 var isGreenJpeg
= ( (target
._url
.length
- indexOfGreenJpeg
) == 9 );
309 //trace("It's the jpeg go !");
312 note
("_lockroot: "+_lockroot
);
313 note
("---- Target's root is "+_root
);
314 check_equals
(_root
, _level0
);
316 check_equals
(_root
, _level0
.loadtarget
);
317 note
("---- After setting _lockroot to true, target's root is "+_root
);
319 check_equals
(_root
, _level0
);
320 note
("---- After setting _lockroot to false, target's root is "+_root
);
322 // NOTE: these two tests show the bug preventing
323 // YouTube active_sharing.swf movie from working
324 check_equals
(target
._width
, 170);
325 check_equals
(target
._height
, 170);
328 //note("target.var1: "+target.var1);
329 //note("onLoadInit called with "+arguments.length+" args:"); dumpObj(arguments);
333 check
( ! mcl
.loadClip
() );
334 check
( ! mcl
.loadClip
( MEDIA
(vars
.txt
) ) );
336 check
( ! mcl
.loadClip
( MEDIA
(vars
.txt
), 'unexistent' ) );
341 state
.nextFunction
= test2
;
342 expected
.target
= _root
.loadtarget
;
343 check
( mcl
.loadClip
( MEDIA
(unexistent
), 'loadtarget' ) );
349 state
.nextFunction
= test3
;
350 expected
.target
= _root
.loadtarget
;
351 check
( mcl
.loadClip
( MEDIA
(vars
.txt
), 'loadtarget' ) );
356 // getProgress can be called using *any* target
357 // and will return the target's actual size
358 var prog
= mcl
.getProgress
(_level0
);
359 check_equals
(typeof(prog
), 'object');
360 check_equals
(prog
.__proto__
, undefined);
361 check_equals
(prog
.bytesLoaded
, prog
.bytesTotal
);
362 check_equals
(prog
.bytesTotal
, _level0
.getBytesTotal
());
365 state
.nextFunction
= undefined;
366 expected
.target
= _root
.loadtarget
;
368 // set expected.totals when willing to end the test
369 // we don't know how many times onLoadProgress will be called
370 // so we only count the tests we can determine.
371 // The onLoadInit function will do the rest, by checking the actual
372 // number of times onLoadProgress was called and add to our expected
373 // count (appropriately multiplied to count *every* test in the
376 // subtract the number of progress callback runs reported when playing from the totals to get the correct number
377 // BUT MAKE SURE nextTestOrEnd CONTAINS THE CORRECT testsPerProgressCallback INFO !!
379 expected
.totals
= 85;
380 // gnash doesn't call onLoadInit if the data at the url is not an SWF or JPG
381 // (or whatever else can become a movie_instance), while the PP does.
382 // So in this testcase, the attempt to load vars.txt is invalid for Gnash
383 // (triggers onLoadError)
384 // TODO: fix gnash to be compatible and find out if there's anything
385 // actually dont for loadVariable-like data
387 expected
.failtotals
= true;
392 loadtarget
._alpha
= 20;
393 check
( mcl
.loadClip
( MEDIA
(green
.jpg
), 'loadtarget' ) );
400 #else // OUTPUT_VERSION < 7