Add automated tests for MovieClip.getURL()-based FSCommand usage.
[gnash.git] / testsuite / misc-ming.all / hostcmd_htmltest.sh
blob2e455a2ff8d1a690d0c668c42e9b4cf74e786050
1 #!/bin/sh
4 # hostcmd_htmltest.sh - HTML-based non-predefined FSCommand invocation
5 # test runner generator
7 # Copyright (C) 2017 Free Software Foundation, Inc.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 # Original author: Nutchanon Wetchasit <Nutchanon.Wetchasit@gmail.com>
26 # The generated test runner checks Gnash (or proprietary player) for:
27 # * Support of FSCommand call via MovieClip.getURL() (bug #46944)
28 # <https://savannah.gnu.org/bugs/?46944>
30 # Usage:
31 # ./hostcmd_htmltest.sh <swfversion> <swf>
33 # The <swf> must be a valid URL name and must not contain '&',
34 # as this test generator does not escape SWF file name.
36 # Generated test runner's usage:
37 # Open the generated test HTML file under web browser with JavaScript and
38 # plug-ins enabled, wait few seconds for the test to run. Once finished,
39 # the result will be shown on browser screen, with "There should be NN
40 # tests run" as the last line.
42 # When testing with proprietary player, the test directory might need
43 # to be added as player's trusted location, or tests would fail due to
44 # sandbox violation. Alternative is putting the test directory
45 # on a web server and run the test online.
47 # Note:
48 # The generated test runner does not count checks run inside SWF file
49 # (because there aren't any).
52 # Check for generation parameters
53 while getopts "" name
55 case $name in
57 echo "Usage: $0 <swfversion> <swf>" >&2
58 exit 1;;
59 esac
60 done
61 shift $(($OPTIND - 1))
62 if [ "$#" -ne 2 ]
63 then
64 echo "Usage: $0 <swfversion> <swf>" >&2
65 exit 1
68 # Load generation parameters
69 swfversion=$1
70 shift
71 swf=$1
73 cat << EOF
74 <html>
75 <head>
76 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
77 <title>Host Communication FSCommand Test</title>
78 </head>
79 <body>
80 <div id="flashstate">
81 <noscript>
82 <strong>ERROR: JavaScript is not enabled, tests will not run</strong>
83 </noscript>
84 </div>
85 <object id="player" name="player" data="${swf}" width="320" height="240" type="application/x-shockwave-flash">
86 <param name="movie" value="${swf}">
87 <param name="AllowScriptAccess" value="always">
88 <div>
89 <strong>ERROR: SWF failed to load, tests will not run correctly</strong>
90 </div>
91 </object>
92 <script type="text/javascript">
93 <!--
94 var tested = 0;
95 var passed = 0;
96 var failed = 0;
97 var xpassed = 0;
98 var xfailed = 0;
100 function check(op, msg) {
101 var flashstatus;
102 var failureline;
104 flashstatus=document.getElementById("flashstate");
105 tested++;
106 if(op) {
107 passed++;
108 flashstatus.appendChild(document.createTextNode("PASSED: " + msg));
109 } else {
110 failed++;
111 failureline=document.createElement("strong");
112 failureline.appendChild(document.createTextNode("FAILED: " + msg));
113 flashstatus.appendChild(failureline);
115 flashstatus.appendChild(document.createElement("br"));
118 function check_equals(op1, op2, msg) {
119 var flashstatus;
120 var failureline;
122 flashstatus=document.getElementById("flashstate");
123 tested++;
124 if(op1 == op2) {
125 passed++;
126 flashstatus.appendChild(document.createTextNode("PASSED: " + msg));
127 } else {
128 failed++;
129 failureline=document.createElement("strong");
130 failureline.appendChild(document.createTextNode("FAILED: " + msg + " (\"" + op1 + "\" != \"" + op2 + "\")"));
131 flashstatus.appendChild(failureline);
133 flashstatus.appendChild(document.createElement("br"));
136 function xcheck_equals(op1, op2, msg) {
137 var flashstatus;
138 var successline;
140 flashstatus=document.getElementById("flashstate");
141 tested++;
142 if(op1 == op2) {
143 xpassed++;
144 successline=document.createElement("strong");
145 successline.appendChild(document.createTextNode("XPASSED: "+msg));
146 flashstatus.appendChild(successline);
147 } else {
148 xfailed++;
149 flashstatus.appendChild(document.createTextNode("XFAILED: " + msg + " (\"" + op1 + "\" != \"" + op2 + "\")"));
151 flashstatus.appendChild(document.createElement("br"));
154 function check_error(msg) {
155 var flashstatus;
156 var errorline;
158 flashstatus=document.getElementById("flashstate");
159 errorline=document.createElement("strong");
160 errorline.appendChild(document.createTextNode("ERROR: " + msg));
161 flashstatus.appendChild(errorline);
162 flashstatus.appendChild(document.createElement("br"));
165 function check_totals(total) {
166 check_equals(tested,total,"There should be "+total+" tests run");
169 function xcheck_totals(total) {
170 xcheck_equals(tested,total,"There should be "+total+" tests run");
173 var noname_call = 0;
174 var noarg_call = 0;
175 var stringarg_call = 0;
176 var weirdstringarg_call = 0;
177 var integerarg_call = 0;
178 var floatarg_call = 0;
179 var infinitearg_call = 0;
180 var neginfinitearg_call = 0;
181 var nanarg_call = 0;
182 var booleanarg_call = 0;
183 var nullarg_call = 0;
184 var undefinedarg_call = 0;
185 var arrayarg_call = 0;
186 var objectarg_call = 0;
187 var object_customstringarg_call = 0;
189 function player_DoFSCommand(cmd, arg) {
190 if("" == cmd) {
191 noname_call++;
192 if (noname_call == 1) {
193 check_equals(typeof(arg), "string", "MovieClip-based no-name FSCommand call with no parameter should pass string-type parameter");
194 check_equals(arg, "", "MovieClip-based no-name FSCommand call with no-parameter should pass an empty string parameter");
195 } else if(noname_call == 2) {
196 check_equals(typeof(arg), "string", "MovieClip-based no-name FSCommand call with string parameter should pass string-type parameter");
197 check_equals(arg, "This is a string for empty call", "MovieClip-based no-name FSCommand call with string parameter should pass a correct string parameter value");
198 } else {
199 check_error("Unknown no-name FSCommand issued: \"" + cmd + "\" parameter \"" + arg + "\"");
201 } else if("noarg" == cmd) {
202 noarg_call++;
203 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with no parameter should pass string-type parameter");
204 check_equals(arg, "", "MovieClip-based FSCommand call with no parameter should pass an empty string parameter value");
205 } else if("stringarg" == cmd) {
206 stringarg_call++;
207 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with string parameter should pass string-type parameter");
208 check_equals(arg, "This is a string", "MovieClip-based FSCommand call with string parameter should pass a correct string parameter value");
209 } else if("weirdstringarg" == cmd) {
210 // Currently, this FSCommand won't run under libgnashplugin,
211 // due to its internal parameter parsing issue.
213 weirdstringarg_call++;
214 xcheck_equals(typeof(arg),"string", "MovieClip-based FSCommand call with string parameter full of symbols should pass string-type parameter");
215 xcheck_equals(arg,"!@#\$%^&*()_+-={}|[]\\\\:\";\'<>?,./~\`", "Full-of-symbols string parameter value of MovieClip-based FSCommand call should be passed correctly");
216 } else if("integerarg" == cmd) {
217 integerarg_call++;
218 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with integer parameter should pass string-type parameter");
219 check_equals(arg, "9876", "MovieClip-based FSCommand call should pass a correct string representation of integer parameter value");
220 } else if("floatarg" == cmd) {
221 floatarg_call++;
222 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with floating point parameter should pass string-type parameter");
223 check_equals(arg, "9876.5432", "MovieClip-based FSCommand call should pass a correct string representation of floating point parameter value");
224 } else if("infinitearg" == cmd) {
225 infinitearg_call++;
226 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with infinity parameter should pass string-type parameter");
227 check_equals(arg, "Infinity", "MovieClip-based FSCommand call should pass a correct string representation of infinity parameter");
228 } else if("neginfinitearg" == cmd) {
229 neginfinitearg_call++;
230 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with negative infinity parameter should pass string-type parameter");
231 check_equals(arg, "-Infinity", "MovieClip-based FSCommand call should pass a correct string representation of negative infinity parameter value");
232 } else if("nanarg" == cmd) {
233 nanarg_call++;
234 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with not-a-number parameter should pass string-type parameter");
235 check_equals(arg, "NaN", "MovieClip-based FSCommand call should pass a correct string representation of not-a-number parameter value");
236 } else if("booleanarg" == cmd) {
237 booleanarg_call++;
238 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with boolean parameter should pass string-type parameter");
239 check_equals(arg, "true", "MovieClip-based FSCommand call should pass a correct string representation of boolean parameter value");
240 } else if("nullarg" == cmd) {
241 nullarg_call++;
242 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with null parameter should pass string-type parameter");
243 check_equals(arg, "null", "MovieClip-based FSCommand call should pass a correct string representation of null parameter");
244 } else if("undefinedarg" == cmd) {
245 undefinedarg_call++;
246 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with undefined parameter should pass string-type parameter");
247 xcheck_equals(arg, "", "MovieClip-based FSCommand call should pass an empty string as a representation of undefined parameter");
248 } else if("arrayarg" == cmd) {
249 arrayarg_call++;
250 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with array parameter should pass string-type parameter");
251 check_equals(arg, "The,quick,brown,fox,jumps,over,the,lazy,dog", "Array parameter value of MovieClip-based FSCommand call should be passed correctly as CSV string");
252 } else if("objectarg" == cmd) {
253 objectarg_call++;
254 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with object parameter should pass string-type parameter");
255 check_equals(arg, "[object Object]", "String representation of Object parameter of MovieClip-based FSCommand call should be correctly passed");
256 } else if("object_customstringarg" == cmd) {
257 object_customstringarg_call++;
258 check_equals(typeof(arg), "string", "MovieClip-based FSCommand call with object parameter bearing custom toString() should pass string-type parameter");
259 check_equals(arg, "This is a custom Object.toString()", "Custom string representation of object parameter of MovieClip-based FSCommand call should be correctly passed");
260 } else {
261 check_error("Unknown FSCommand issued: \"" + cmd + "\" parameter \"" + arg + "\"");
265 function verify_flash() {
266 check_equals(noname_call, 2, "No-name FSCommand should be called for 2 times");
267 check_equals(noarg_call, 1, "\"noarg\" FSCommand should be called for 1 time");
268 check_equals(stringarg_call, 1, "\"stringarg\" FSCommand should be called for 1 time");
269 xcheck_equals(weirdstringarg_call, 1, "\"weirdstringarg\" FSCommand should be called for 1 time");
270 check_equals(integerarg_call, 1, "\"integerarg\" FSCommand should be called for 1 time");
271 check_equals(floatarg_call, 1, "\"floatarg\" FSCommand should be called for 1 time");
272 check_equals(infinitearg_call, 1, "\"infinitearg\" FSCommand should be called for 1 time");
273 check_equals(neginfinitearg_call, 1, "\"neginfinitearg\" FSCommand should be called for 1 time");
274 check_equals(nanarg_call, 1, "\"nanarg\" FSCommand should be called for 1 time");
275 check_equals(booleanarg_call, 1, "\"booleanarg\" FSCommand should be called for 1 time");
276 check_equals(nullarg_call, 1, "\"nullarg\" FSCommand should be called for 1 time");
277 check_equals(undefinedarg_call, 1, "\"undefinedarg\" FSCommand should be called for 1 time");
278 check_equals(arrayarg_call, 1, "\"arrayarg\" FSCommand should be called for 1 time");
279 check_equals(objectarg_call, 1, "\"objectarg\" FSCommand should be called for 1 time");
280 check_equals(object_customstringarg_call, 1, "\"object_customstringarg\" FSCommand should be called for 1 time");
282 xcheck_totals(47);
285 setTimeout("verify_flash()",3000);
286 //-->
287 </script>
288 </body>
289 </html>