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
20 // Test case for NetConnection ActionScript class
21 // compile this test case with Ming makeswf, and then
22 // execute it like this gnash -1 -r 0 -v out.swf
25 rcsid
="NetConnection.as";
28 #if OUTPUT_VERSION
< 6
30 check_equals
(NetConnection, undefined);
33 #else // OUTPUT_VERSION >= 6
35 check
(NetConnection.prototype
.hasOwnProperty
("call"));
36 check
(NetConnection.prototype
.hasOwnProperty
("connect"));
37 check
(NetConnection.prototype
.hasOwnProperty
("addHeader"));
38 check
(NetConnection.prototype
.hasOwnProperty
("close"));
40 check
(!NetConnection.prototype
.hasOwnProperty
("isConnected"));
41 check
(!NetConnection.prototype
.hasOwnProperty
("uri"));
43 check_equals
(typeof(NetConnection), 'function');
44 check_equals
(typeof(NetConnection.prototype
), 'object');
45 check_equals
(typeof(NetConnection.prototype
.isConnected
), 'undefined');
46 check_equals
(typeof(NetConnection.prototype
.connect
), 'function');
48 var tmp
= new NetConnection;
49 check_equals
(typeof(tmp
), 'object');
50 check_equals
(tmp
.__proto__
, NetConnection.prototype
);
51 check
(tmp
instanceof NetConnection);
52 check_equals
(typeof(tmp
.isConnected
), 'boolean');
53 check_equals
(typeof(tmp
.uri
), 'undefined');
54 check_equals
(tmp
.uri
, undefined);
55 check_equals
(tmp
.isConnected
, false);
57 tmp
.isConnected
= true;
58 check_equals
(tmp
.isConnected
, false);
61 check_equals
(tmp
.isConnected
, false);
64 // Provided this connection is allowed, the player creates a connection.
65 // Because the Adobe player has a different sandbox method from Gnash,
66 // we can't test this connection *and* the blacklisted one.
68 // Starting this connection also causes different results later.
70 // test the NetConnection::connect method
71 if ( ! tmp
.connect
("rtmp://www.mediacollege.com/flash/media-player/testclip-4sec.flv") )
73 // FIXME: this would fail in the reference player too...
74 xfail
("NetConnection::connect() didn't initialize correctly");
78 pass
("NetConnection::connect() initialized correctly");
83 tmp
.onStatus
= function(info
) {
86 statuses
.push
(info
.code
);
92 statuses
= new Array();
94 check_equals
(ret
, undefined);
95 check_equals
(tmp
.isConnected
, false);
96 check_equals
(result
, "");
97 check_equals
(level
, "");
98 check_equals
(statuses
.toString
(), "");
100 statuses
= new Array();
101 ret
= tmp
.connect
("");
102 check_equals
(ret
, false);
103 check_equals
(tmp
.isConnected
, false);
104 check_equals
(result
, "NetConnection.Connect.Failed");
105 check_equals
(level
, "error");
106 check_equals
(typeof(tmp
.uri
), "string");
107 check_equals
(tmp
.uri
, "");
108 check_equals
(statuses
.toString
(), "NetConnection.Connect.Failed");
110 ret
= tmp
.connect
("null");
111 check_equals
(ret
, false);
112 check_equals
(tmp
.isConnected
, false);
113 check_equals
(result
, "NetConnection.Connect.Failed");
114 check_equals
(level
, "error");
115 check_equals
(typeof(tmp
.uri
), "string");
116 check_equals
(tmp
.uri
, "null");
118 ret
= tmp
.connect
(null, "another argument");
119 check_equals
(ret
, true);
120 check_equals
(tmp
.isConnected
, true);
121 check_equals
(result
, "NetConnection.Connect.Success");
122 check_equals
(level
, "status");
123 check_equals
(typeof(tmp
.uri
), "string");
124 check_equals
(tmp
.uri
, "null");
128 check_equals
(tmp
.uri
, "null");
131 statuses
= new Array();
132 ret
= tmp
.connect
(1);
133 check_equals
(ret
, false);
134 check_equals
(tmp
.isConnected
, false);
135 check_equals
(result
, "NetConnection.Connect.Failed");
136 check_equals
(level
, "error");
137 check_equals
(typeof(tmp
.uri
), "string");
138 check_equals
(tmp
.uri
, "1");
139 check_equals
(statuses
.toString
(),
140 "NetConnection.Connect.Closed,NetConnection.Connect.Failed");
142 statuses
= new Array();
143 ret
= tmp
.connect
("string");
144 check_equals
(ret
, false);
145 check_equals
(tmp
.isConnected
, false);
146 check_equals
(result
, "NetConnection.Connect.Failed");
147 check_equals
(level
, "error");
148 check_equals
(typeof(tmp
.uri
), "string");
149 check_equals
(tmp
.uri
, "string");
150 check_equals
(statuses
.toString
(),
151 "NetConnection.Connect.Failed");
153 ret
= tmp
.connect
(undefined);
155 #if OUTPUT_VERSION
> 6
156 check_equals
(ret
, true);
157 check_equals
(tmp
.isConnected
, true);
158 check_equals
(result
, "NetConnection.Connect.Success");
159 check_equals
(level
, "status");
160 check_equals
(typeof(tmp
.uri
), "string");
161 check_equals
(tmp
.uri
, "undefined");
163 check_equals
(ret
, false);
164 check_equals
(tmp
.isConnected
, false);
165 check_equals
(result
, "NetConnection.Connect.Failed");
166 check_equals
(level
, "error");
167 check_equals
(typeof(tmp
.uri
), "string");
168 check_equals
(tmp
.uri
, "");
171 statuses
= new Array;
172 ret
= tmp
.connect
(null);
173 check_equals
(ret
, true);
174 check_equals
(tmp
.isConnected
, true);
175 check_equals
(result
, "NetConnection.Connect.Success");
176 check_equals
(level
, "status");
178 // This depends on whether isConnected() was true or not.
179 #if OUTPUT_VERSION
> 6
180 check_equals
(statuses
.toString
(),
181 "NetConnection.Connect.Closed,NetConnection.Connect.Success");
183 check_equals
(statuses
.toString
(),
184 "NetConnection.Connect.Success");
186 // The pp and Gnash sandboxes behave differently. The pp rejects any
187 // network connection from filesystem-loaded SWFs unless the SWF location
188 // is added to the player configuration file. This server is blacklisted
189 // in the testsuite gnashrc file, so Gnash should refuse to load this too.
190 // The test should work on both players for a SWF loaded from anywhere but
191 // www.blacklistedserver.org (domain still available, in case anyone wants to
192 // mess up the test).
193 ret
= tmp
.connect
("http://www.blacklistedserver.org");
194 check_equals
(ret
, false);
195 check_equals
(tmp
.isConnected
, false);
196 check_equals
(result
, "NetConnection.Connect.Failed");
197 check_equals
(level
, "error");
200 // Close() doesn't reset uri if no connection is made. It does seem to
201 // reset it if a connection is genuinely closed.
203 check_equals
(tmp
.uri
, "http://www.blacklistedserver.org");
207 statuses
= new Array;
208 // No Call onStatus event when not connected.
210 check_equals
(ret
, undefined);
211 check_equals
(statuses
.length
, 0);
213 // No Call onStatus event when connected with null.
216 check_equals
(ret
, undefined);
217 check_equals
(statuses
.length
, 1);
218 check_equals
(result
, "NetConnection.Connect.Success");
219 check_equals
(typeof(tmp
.uri
), 'string');
220 check_equals
(tmp
.uri
, 'null');
222 // Check onStatus object.
224 nc
= new NetConnection;
225 nc
.onStatus
= function(info
) {
230 nc
.onStatus
= undefined;
231 check_equals
(infoObj
.code
, "NetConnection.Connect.Failed");
233 // It is a full object
234 check
(infoObj
instanceof Object);
235 check_equals
(infoObj
.toString
(), "[object Object]");
237 // Check whether the original object is modified on a new connect attempt.
239 check_equals
(infoObj
.code
, "NetConnection.Connect.Failed");
246 nc
.onStatus
= function(info
) {
249 statuses
.push
(info
.code
);
253 check
(nc
.isConnected
);
256 check_equals
(typeof(ret
), "undefined");
257 check_equals
(ret
, undefined);
258 check_equals
(result
, "");
259 check_equals
(level
, "");
262 check_equals
(typeof(ret
), "undefined");
263 check_equals
(ret
, undefined);
264 check_equals
(result
, "");
265 check_equals
(level
, "");
267 ret
= nc
.call
("string");
268 check_equals
(typeof(ret
), "undefined");
269 check_equals
(ret
, undefined);
270 check_equals
(result
, "");
271 check_equals
(level
, "");
273 // NetConnection close
275 statuses
= new Array;
276 check
(nc
.isConnected
);
278 check_equals
(nc
.isConnected
, false);
279 check_equals
(typeof(ret
), "undefined");
280 check_equals
(ret
, undefined);
281 check_equals
(result
, "NetConnection.Connect.Closed");
282 check_equals
(level
, "status");
285 check_equals
(nc
.isConnected
, false);
286 check_equals
(typeof(ret
), "undefined");
287 check_equals
(ret
, undefined);
288 check_equals
(result
, "NetConnection.Connect.Closed");
289 check_equals
(level
, "status");
292 check_equals
(statuses
.toString
(), "NetConnection.Connect.Closed");
295 check_equals
(nc
.isConnected
, false);
296 check_equals
(typeof(ret
), "undefined");
297 check_equals
(ret
, undefined);
298 check_equals
(result
, "NetConnection.Connect.Failed");
299 check_equals
(level
, "error");
301 check_equals
(nc
.isConnected
, false);
302 check_equals
(typeof(ret
), "undefined");
303 check_equals
(ret
, undefined);
304 check_equals
(result
, "NetConnection.Connect.Failed");
305 check_equals
(level
, "error");
311 #endif
// OUTPUT_VERSION >= 7