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 XML 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
="$Id: XML.as,v 1.57 2008/04/08 10:09:21 strk Exp $";
27 //#include "dejagnu.as"
30 #if OUTPUT_VERSION
< 6
31 Object.prototype
.hasOwnProperty
= ASnative
(101, 5);
34 var existtests
= true;
38 check
(! XML.prototype
.hasOwnProperty
("appendChild") );
39 check
(! XML.prototype
.hasOwnProperty
("cloneNode") );
40 check
(! XML.prototype
.hasOwnProperty
("hasChildNodes") );
41 check
(! XML.prototype
.hasOwnProperty
("insertBefore") );
42 check
(! XML.prototype
.hasOwnProperty
("removeNode") );
43 check
(! XML.prototype
.hasOwnProperty
("cloneNode") );
44 check
(! XML.prototype
.hasOwnProperty
("toString") );
45 check
(! XML.prototype
.hasOwnProperty
("length") );
46 check
(! XML.prototype
.hasOwnProperty
("status"));
47 check
(! XML.prototype
.hasOwnProperty
("loaded"));
48 check
(! XML.prototype
.hasOwnProperty
("attributes"));
49 check
(! XML.prototype
.hasOwnProperty
("nodeValue"));
50 check
(XML.prototype
.hasOwnProperty
("onData"));
51 check
(XML.prototype
.hasOwnProperty
("onLoad")); // it seems it wouldn't do anything anyway, would it ?
52 check
(XML.prototype
.hasOwnProperty
("createElement") );
53 check
(XML.prototype
.hasOwnProperty
("addRequestHeader") );
54 check
(XML.prototype
.hasOwnProperty
("createTextNode") );
55 check
(XML.prototype
.hasOwnProperty
("getBytesLoaded") );
56 check
(XML.prototype
.hasOwnProperty
("getBytesTotal") );
57 check
(!XML.prototype
.hasOwnProperty
("_bytesTotal") );
58 check
(!XML.prototype
.hasOwnProperty
("_bytesLoaded") );
59 check
(XML.prototype
.hasOwnProperty
("load") );
60 check
(XML.prototype
.hasOwnProperty
("parseXML") );
61 check
(XML.prototype
.hasOwnProperty
("send") );
62 check
(XML.prototype
.hasOwnProperty
("sendAndLoad") );
64 check
(!XML.prototype
.hasOwnProperty
("docTypeDecl") );
65 check
(!XML.prototype
.hasOwnProperty
("xmlDecl") );
66 // ignoreWhite is undefined by default, but is used when set to true
67 check
(!XML.prototype
.hasOwnProperty
("ignoreWhite") );
69 check
(!XML.hasOwnProperty
("createElement") );
70 check
(!XML.hasOwnProperty
("addRequestHeader") );
71 check
(!XML.hasOwnProperty
("createTextNode") );
72 check
(!XML.hasOwnProperty
("getBytesLoaded") );
73 check
(!XML.hasOwnProperty
("getBytesTotal") );
74 check
(!XML.hasOwnProperty
("load") );
75 check
(!XML.hasOwnProperty
("parseXML") );
76 check
(!XML.hasOwnProperty
("send") );
77 check
(!XML.hasOwnProperty
("sendAndLoad") );
78 check
(!XML.hasOwnProperty
("nodeValue"));
79 check
(!XML.hasOwnProperty
("_customHeaders"));
80 check
(!XML.hasOwnProperty
("docTypeDecl") );
81 check
(!XML.hasOwnProperty
("xmlDecl") );
83 check
(XMLNode.prototype
.hasOwnProperty
("appendChild") );
84 check
(XMLNode.prototype
.hasOwnProperty
("cloneNode") );
85 check
(XMLNode.prototype
.hasOwnProperty
("hasChildNodes") );
86 check
(XMLNode.prototype
.hasOwnProperty
("insertBefore") );
87 check
(XMLNode.prototype
.hasOwnProperty
("removeNode") );
88 check
(XMLNode.prototype
.hasOwnProperty
("toString") );
89 check
(XMLNode.prototype
.hasOwnProperty
("cloneNode") );
90 check
(XMLNode.prototype
.hasOwnProperty
("attributes") );
91 check
(XMLNode.prototype
.hasOwnProperty
("parentNode") );
92 check
(XMLNode.prototype
.hasOwnProperty
("nodeValue"));
93 check
(! XMLNode.prototype
.hasOwnProperty
("onData") );
94 check
(! XMLNode.prototype
.hasOwnProperty
("length") );
95 check
(! XMLNode.prototype
.hasOwnProperty
("createElement") );
96 check
(! XMLNode.prototype
.hasOwnProperty
("addRequestHeader") );
97 check
(! XMLNode.prototype
.hasOwnProperty
("createTextNode") );
98 check
(! XMLNode.prototype
.hasOwnProperty
("getBytesLoaded") );
99 check
(! XMLNode.prototype
.hasOwnProperty
("getBytesTotal") );
100 check
(! XMLNode.prototype
.hasOwnProperty
("load") );
101 check
(! XMLNode.prototype
.hasOwnProperty
("parseXML") );
102 check
(! XMLNode.prototype
.hasOwnProperty
("send") );
103 check
(! XMLNode.prototype
.hasOwnProperty
("sendAndLoad") );
104 check
(! XMLNode.prototype
.hasOwnProperty
("status"));
105 check
(! XMLNode.prototype
.hasOwnProperty
("loaded"));
107 check
(! XMLNode.hasOwnProperty
("appendChild") );
108 check
(! XMLNode.hasOwnProperty
("cloneNode") );
109 check
(! XMLNode.hasOwnProperty
("hasChildNodes") );
110 check
(! XMLNode.hasOwnProperty
("insertBefore") );
111 check
(! XMLNode.hasOwnProperty
("removeNode") );
112 check
(! XMLNode.hasOwnProperty
("toString") );
113 check
(! XMLNode.hasOwnProperty
("cloneNode") );
114 check
(! XMLNode.hasOwnProperty
("nodeValue"));
116 check
(XML.prototype
instanceof XMLNode);
121 // These properties are added to the prototype here.
122 check
(!tmp
.hasOwnProperty
("docTypeDecl") );
123 check
(!tmp
.hasOwnProperty
("xmlDecl") );
124 check
(XML.prototype
.hasOwnProperty
("docTypeDecl") );
125 check
(XML.prototype
.hasOwnProperty
("xmlDecl") );
126 check
(XML.prototype
.hasOwnProperty
("contentType") );
127 check
(XML.prototype
.hasOwnProperty
("ignoreWhite") );
129 #if OUTPUT_VERSION
>= 6
130 check
( ! tmp
.hasOwnProperty
("nodeValue") );
133 check
(tmp
instanceof XML);
134 check
(tmp
instanceof XMLNode);
136 check_equals
(typeof(tmp
.length
), 'undefined');
137 check
(! tmp
.hasOwnProperty
("length"));
139 check_equals
(typeof(tmp
.status
), 'number');
140 check
(! tmp
.hasOwnProperty
("status"));
141 check
(tmp
.__proto__
.hasOwnProperty
('status') );
145 // These are added on construction
146 check
(tmp
.__proto__
.hasOwnProperty
("status"));
147 check
(tmp
.__proto__
.hasOwnProperty
("loaded"));
150 check
(!tmp
.__proto__
.hasOwnProperty
("toString"));
151 check
(!tmp
.hasOwnProperty
("toString"));
153 /// Setting status always results in a number.
154 check_equals
(tmp
.status
, 0);
156 check_equals
(tmp
.status
, -1);
158 check_equals
(tmp
.status
, 1000);
161 check_equals
(typeof(tmp
.status
), 'number');
162 check_equals
(tmp
.status
, -2147483648.0); // 0xFFFFFFFF
164 check_equals
(tmp
.status
, 7);
166 returnFour
= function() { return 4; };
167 o
.toString
= returnFour
;
169 check_equals
(typeof(tmp
.status
), 'number');
170 check_equals
(tmp
.status
, -2147483648.0); // 0xFFFFFFFF
172 o
.valueOf
= function() { return 5; };
174 check_equals
(typeof(tmp
.status
), 'number');
175 check_equals
(tmp
.status
, 5);
178 check_equals
(typeof(tmp
.status
), 'number');
179 check_equals
(tmp
.status
, -2147483648.0); // 0xFFFFFFFF
181 tmp
.status
= -100000;
182 check_equals
(tmp
.status
, -100000);
184 check_equals
(typeof(tmp
.loaded
), 'undefined');
185 check
(! tmp
.hasOwnProperty
("loaded"));
188 check_equals
(typeof(tmp
.loaded
), 'boolean');
191 check_equals
(typeof(tmp
.loaded
), 'boolean');
193 check
(! tmp
.hasOwnProperty
("loaded"));
194 check
(tmp
.__proto__
.hasOwnProperty
("loaded"));
197 check_equals
(tmp
.loaded
, true);
198 check_equals
(tmp
.__proto__
.loaded
, undefined);
200 // test the XML constuctor
202 pass
("XML::XML() constructor");
211 // test the XML::addrequestheader method
212 if (tmp
.addRequestHeader
) {
213 pass
("XML::addRequestHeader() exists");
215 fail
("XML::addRequestHeader() doesn't exist");
217 // test the XML::appendchild method
218 if (tmp
.appendChild
) {
219 pass
("XML::appendChild() exists");
221 fail
("XML::appendChild() doesn't exist");
223 // test the XML::clonenode method
225 pass
("XML::cloneNode() exists");
227 fail
("XML::cloneNode() doesn't exist");
229 // test the XML::createelement method
230 if (tmp
.createElement
) {
231 pass
("XML::createElement() exists");
233 fail
("XML::createElement() doesn't exist");
235 // test the XML::createtextnode method
236 if (tmp
.createTextNode
) {
237 pass
("XML::createTextNode() exists");
239 fail
("XML::createTextNode() doesn't exist");
241 // test the XML::getbytesloaded method
242 if (tmp
.getBytesLoaded
) {
243 pass
("XML::getBytesLoaded() exists");
245 fail
("XML::getBytesLoaded() doesn't exist");
247 // test the XML::getbytestotal method
248 if (tmp
.getBytesTotal
) {
249 pass
("XML::getBytesTotal() exists");
251 fail
("XML::getBytesTotal() doesn't exist");
253 // test the XML::haschildnodes method
254 if (tmp
.hasChildNodes
) {
255 pass
("XML::hasChildNodes() exists");
257 fail
("XML::hasChildNodes() doesn't exist");
259 // test the XML::insertbefore method
260 if (tmp
.insertBefore
) {
261 pass
("XML::insertBefore() exists");
263 fail
("XML::insertBefore() doesn't exist");
265 // test the XML::load method
267 pass
("XML::load() exists");
269 fail
("XML::load() doesn't exist");
271 // This doesn't seem to exist in the real player
272 // test the XML::loaded method
274 unresolved
("XML::loaded() exists, it shouldn't!");
276 unresolved
("XML::loaded() doesn't exist yet");
279 //test the XML::parse method
281 pass
("XML::parseXML() exists");
283 fail
("XML::parseXML() doesn't exist");
285 // test the XML::removenode method
286 if (tmp
.removeNode
) {
287 pass
("XML::removeNode() exists");
289 fail
("XML::removeNode() doesn't exist");
291 // test the XML::send method
293 pass
("XML::send() exists");
295 fail
("XML::send() doesn't exist");
297 // test the XML::sendandload method
298 if (tmp
.sendAndLoad
) {
299 pass
("XML::sendAndLoad() exists");
301 fail
("XML::sendAndLoad() doesn't exist");
303 // test the XML::tostring method
305 pass
("XML::toString() exists");
307 fail
("XML::toString() doesn't exist");
310 } // end of existtests
311 /////////////////////////////////////////////////////
318 // if (tmp.load("testin.xml")) {
319 // pass("XML::load() works");
321 // fail("XML::load() doesn't work");
325 // Use escaped " instead of ' so that it matches xml_out (comments and CDATA tags stripped).
326 var xml_in
= "<TOPNODE tna1=\"tna1val\" tna2=\"tna2val\" tna3=\"tna3val\"><SUBNODE1 sna1=\"sna1val\" sna2=\"sna2val\"><SUBSUBNODE1 ssna1=\"ssna1val\" ssna2=\"ssna2val\"><!-- comment should be ignored-->sub sub1 node data 1</SUBSUBNODE1><SUBSUBNODE2><!--comment: cdata with illegal characters --><![CDATA[sub /\sub1 <br>\"node data 2\"]]></SUBSUBNODE2></SUBNODE1><SUBNODE2><SUBSUBNODE1>sub sub2 node data 1</SUBSUBNODE1><SUBSUBNODE2>sub sub2 node data 2</SUBSUBNODE2></SUBNODE2></TOPNODE>";
327 // with comments stripped out.
328 var xml_out
= '<TOPNODE tna1="tna1val" tna2="tna2val" tna3="tna3val"><SUBNODE1 sna1="sna1val" sna2="sna2val"><SUBSUBNODE1 ssna1="ssna1val" ssna2="ssna2val">sub sub1 node data 1</SUBSUBNODE1><SUBSUBNODE2>sub /sub1 <br>"node data 2"</SUBSUBNODE2></SUBNODE1><SUBNODE2><SUBSUBNODE1>sub sub2 node data 1</SUBSUBNODE1><SUBSUBNODE2>sub sub2 node data 2</SUBSUBNODE2></SUBNODE2></TOPNODE>';
329 //var xml_out = "<TOPNODE tna1=\"tna1val\" tna2=\"tna2val\" tna3=\"tna3val\"><SUBNODE1 sna1=\"sna1val\" sna2=\"sna2val\"><SUBSUBNODE1 ssna1=\"ssna1val\" ssna2=\"ssna2val\">sub sub1 node data 1</SUBSUBNODE1><SUBSUBNODE2>sub /\sub1 \<br\>\"node data 2\"</SUBSUBNODE2></SUBNODE1><SUBNODE2><SUBSUBNODE1>sub sub2 node data 1</SUBSUBNODE1><SUBSUBNODE2>sub sub2 node data 2</SUBSUBNODE2></SUBNODE2></TOPNODE>";
332 tmp
.checkParsed
= function ()
334 //note("tmp.checkParsed called");
336 // Since we didn't *load* the XML, but we
337 // just *parsed* it, expect getBytesLoaded
338 // and getBytesTotal to return undefined
339 check_equals
(this.getBytesLoaded
(), undefined);
340 check_equals
(this.getBytesTotal
(), undefined);
342 check
(this.hasChildNodes
());
343 check_equals
(typeof(this.nodeName
), 'null');
344 check_equals
(typeof(this.nodeValue
), 'null');
345 check
(this.childNodes
instanceof Array);
346 check_equals
(this.firstChild
, this.lastChild
);
347 check
(this.firstChild
instanceof XMLNode);
348 check_equals
(typeof(this.length
), 'undefined');
349 check_equals
(typeof(this.childNodes
.length
), 'number');
350 check_equals
(this.childNodes
.length
, 1);
351 check_equals
(this.childNodes
[0], this.firstChild
);
352 check_equals
(this.childNodes
[0], this.lastChild
);
354 check
(this.childNodes
.hasOwnProperty
('length'));
355 check
(this.childNodes
[0] === this.firstChild
);
356 check
(this.childNodes
[0] === this.lastChild
);
358 // childNodes is a read-only property !
360 check
(this.childNodes
instanceof Array);
362 with (this.firstChild
)
364 check_equals
(nodeName
, 'TOPNODE');
365 check_equals
(typeof(nodeValue
), 'null');
366 check_equals
(typeof(nextSibling
), 'null');
367 check_equals
(typeof(previousSibling
), 'null');
370 check_equals
(typeof(attributes
), 'object');
371 check_equals
(attributes
.tna1
, 'tna1val');
372 check_equals
(attributes
.tna2
, 'tna2val');
373 // Check attributes enumerability
375 for (var i
in attributes
) attrcopy
[i
] = attributes
[i
];
376 check_equals
(attrcopy
.tna1
, 'tna1val');
377 check_equals
(attrcopy
.tna2
, 'tna2val');
380 // Check that nodeValue is overridable
382 check_equals
(typeof(nodeValue
), 'string');
383 check_equals
(nodeValue
, '4');
385 check_equals
(nodeType
, 1); // element
386 check_equals
(childNodes
.length
, 2);
390 check_equals
(nodeName
, 'SUBNODE1');
391 check_equals
(typeof(nodeValue
), 'null');
393 check_equals
(typeof(nextSibling
), 'object');
394 check_equals
(nextSibling
.nodeName
, 'SUBNODE2');
395 check_equals
(typeof(previousSibling
), 'null');
397 check_equals
(typeof(attributes
), 'object');
398 check_equals
(attributes
.sna1
, 'sna1val');
399 check_equals
(attributes
.sna2
, 'sna2val');
401 check_equals
(nodeType
, 1); // element
402 check_equals
(childNodes
.length
, 2);
405 check_equals
(nodeName
, 'SUBSUBNODE1');
406 check_equals
(typeof(nodeValue
), 'null');
407 check_equals
(nodeType
, 1); // element
408 check_equals
(typeof(nextSibling
), 'object');
409 check_equals
(nextSibling
.nodeName
, 'SUBSUBNODE2');
410 check_equals
(typeof(previousSibling
), 'null');
411 check_equals
(typeof(attributes
), 'object');
412 check_equals
(attributes
.ssna1
, 'ssna1val');
413 check_equals
(attributes
.ssna2
, 'ssna2val');
414 check_equals
(childNodes
.length
, 1);
417 check_equals
(typeof(nodeName
), 'null')
418 check_equals
(nodeValue
, 'sub sub1 node data 1')
419 check_equals
(nodeType
, 3); // text
424 check_equals
(nodeName
, 'SUBSUBNODE2');
425 check_equals
(typeof(nodeValue
), 'null');
426 check_equals
(nodeType
, 1); // element
427 check_equals
(typeof(nextSibling
), 'null');
428 check_equals
(typeof(previousSibling
), 'object');
429 check_equals
(previousSibling
.nodeName
, 'SUBSUBNODE1');
430 check_equals
(childNodes
.length
, 1);
433 check_equals
(typeof(nodeName
), 'null')
434 check_equals
(nodeValue
, 'sub /\sub1 <br>"node data 2"')
435 check_equals
(nodeType
, 3); // text
442 check_equals
(nodeName
, 'SUBNODE2');
443 check_equals
(typeof(nodeValue
), 'null');
444 check_equals
(nodeType
, 1); // element
446 check_equals
(typeof(nextSibling
), 'null');
447 check_equals
(typeof(previousSibling
), 'object');
448 check_equals
(previousSibling
.nodeName
, 'SUBNODE1');
450 check_equals
(childNodes
.length
, 2);
453 check_equals
(nodeName
, 'SUBSUBNODE1');
454 check_equals
(typeof(nodeValue
), 'null');
455 check_equals
(nodeType
, 1); // element
456 check_equals
(childNodes
.length
, 1);
459 check_equals
(typeof(nodeName
), 'null')
460 check_equals
(nodeValue
, 'sub sub2 node data 1')
461 check_equals
(nodeType
, 3); // text
466 check_equals
(nodeName
, 'SUBSUBNODE2');
467 check_equals
(typeof(nodeValue
), 'null');
468 check_equals
(nodeType
, 1); // element
469 check_equals
(childNodes
.length
, 1);
472 check_equals
(typeof(nodeName
), 'null')
473 check_equals
(nodeValue
, 'sub sub2 node data 2')
474 check_equals
(nodeType
, 3); // text
479 check_equals
(this.firstChild
.nodeValue
, '4');
482 check_equals
( typeof(tmp
.parseXML
), 'function');
483 check
(tmp
.childNodes instanceOf
Array);
484 check_equals
(tmp
.childNodes
.length
, 0);
486 // parseXML doesn't return anything
487 ret
= tmp
.parseXML
(xml_in
);
488 check_equals
(typeof(ret
), 'undefined');
490 tmp
.checkParsed
(); // onLoad won't be called
491 //note("Parsed XML: "+tmp.toString());
494 check_equals
(tmp
.toString
(), xml_out
);
496 //------------------------------------------------
498 //------------------------------------------------
499 xml1
= new XML("<X1T><X1C1></X1C1><X1C2></X1C2></X1T>");
500 xml2
= new XML("<X2T><X2C1></X2C1><X2C2></X2C2></X2T>");
501 check_equals
(xml1
.childNodes
.length
, 1);
502 check_equals
(xml1
.firstChild
.childNodes
.length
, 2);
503 check_equals
(xml2
.childNodes
.length
, 1);
504 check_equals
(xml2
.firstChild
.childNodes
.length
, 2);
506 // Now move X1C1 to X2T
507 movingchild
= xml2
.firstChild
.lastChild
;
509 check_equals
(movingchild
.parentNode
, xml2
.firstChild
);
510 check
(movingchild
.parentNode
!= xml1
.firstChild
);
511 xml1
.firstChild
.appendChild
(movingchild
);
512 check_equals
(movingchild
.parentNode
, xml1
.firstChild
);
513 check
(movingchild
.parentNode
!= xml2
.firstChild
);
515 check_equals
(xml1
.firstChild
.childNodes
.length
, 3);
516 check_equals
(xml1
.firstChild
.childNodes
[0].nodeName
, "X1C1");
517 check_equals
(xml1
.firstChild
.childNodes
[1].nodeName
, "X1C2");
518 check_equals
(xml1
.firstChild
.childNodes
[2].nodeName
, "X2C2");
520 check_equals
(xml2
.firstChild
.childNodes
.length
, 1); // firstChild has been moved
521 check_equals
(xml2
.firstChild
.childNodes
[0].nodeName
, "X2C1");
523 // Now insert X2C1 from xml2 before X1C2 in xml1
524 xml1
.firstChild
.insertBefore
(
525 xml2
.firstChild
.lastChild
, // what to insert
526 xml1
.firstChild
.childNodes
[1] // before what to insert it
528 check_equals
(xml1
.firstChild
.childNodes
.length
, 4);
529 check_equals
(xml1
.firstChild
.childNodes
[0].nodeName
, "X1C1");
530 check_equals
(xml1
.firstChild
.childNodes
[1].nodeName
, "X2C1");
531 check_equals
(xml1
.firstChild
.childNodes
[2].nodeName
, "X1C2");
532 check_equals
(xml1
.firstChild
.childNodes
[3].nodeName
, "X2C2");
534 // XMLNode.removeNode
535 check_equals
(xml2
.firstChild
.childNodes
.length
, 0); // lastChild has been moved
536 xml2
.firstChild
.removeNode
();
537 check_equals
(xml2
.childNodes
.length
, 0); // it's only child has been dropped
539 x1c1_node
= xml1
.firstChild
.childNodes
[0];
540 x2c1_node
= xml1
.firstChild
.childNodes
[1];
541 check_equals
(x1c1_node
.nodeName
, "X1C1");
542 check_equals
(x1c1_node
.nextSibling
, x2c1_node
);
543 check_equals
(x2c1_node
.nodeName
, "X2C1");
544 check_equals
(x2c1_node
.previousSibling
, x1c1_node
);
545 xml1
.firstChild
.removeNode
(); // removeNode removes all childrens !!
546 check_equals
(xml1
.childNodes
.length
, 0);
547 // so these become orphaned (no parent)
548 check_equals
(x1c1_node
.nodeName
, "X1C1");
549 check_equals
(x1c1_node
.nextSibling
(), null);
550 check_equals
(x2c1_node
.nodeName
, "X2C1");
551 check_equals
(x2c1_node
.previousSibling
(), null);
553 xml1
.appendChild
(x1c1_node
);
554 xml1
.appendChild
(x2c1_node
);
555 check_equals
(x1c1_node
.nextSibling
, x2c1_node
);
556 check_equals
(x2c1_node
.previousSibling
, x1c1_node
);
558 check_equals
(xml1
.childNodes
.length
, 2);
559 x1c1_node
.appendChild
(x2c1_node
);
560 check_equals
(xml1
.childNodes
.length
, 1);
561 check_equals
(xml1
.firstChild
.lastChild
.nodeName
, 'X2C1');
563 src_node
= xml1
.firstChild
;
564 cln_node
= src_node
.cloneNode
(); // ! deep
565 deepcln_node
= src_node
.cloneNode
(true); // deep
567 check_equals
(src_node
.childNodes
.length
, 1);
568 check_equals
(cln_node
.childNodes
.length
, 0); // non-deep clone doesn't clone childs !
569 check_equals
(deepcln_node
.childNodes
.length
, 1);
571 check_equals
(src_node
.firstChild
.nodeName
, 'X2C1');
572 check_equals
(deepcln_node
.firstChild
.nodeName
, 'X2C1');
573 src_node
.firstChild
.nodeName
= 'X2C1_modified';
574 check_equals
(src_node
.firstChild
.nodeName
, 'X2C1_modified');
575 check_equals
(deepcln_node
.firstChild
.nodeName
, 'X2C1');
577 check_equals
(deepcln_node
.parentNode
, null);
578 deepcln_node
.parentNode
= src_node
;
579 check_equals
(deepcln_node
.parentNode
, null);
582 xml1
= new XML("<X1T><X1C1><X1C1C1></X1C1C1></X1C1><X1C2></X1C2></X1T>");
583 check_equals
(xml1
.firstChild
.childNodes
.length
, 2);
584 fc
= xml1
.firstChild
.firstChild
;
585 check_equals
(fc
.nodeName
, 'X1C1');
586 check_equals
(fc
.childNodes
.length
, 1);
587 check_equals
(fc
.parentNode
, xml1
.firstChild
);
588 fc
.removeNode
(); // removes xml1.firstChild.firstChil (X1C1)
589 check_equals
(xml1
.firstChild
.childNodes
.length
, 1);
590 check_equals
(fc
.parentNode
, null);
591 check_equals
(fc
.nodeName
, 'X1C1');
592 check_equals
(fc
.childNodes
.length
, 1); // childs of the removed child are still alive !
593 check_equals
(fc
.childNodes
[0].parentNode
, fc
); // and still point to the removed child !
595 //------------------------------------------------
597 //------------------------------------------------
600 check
(myXML
!= undefined);
601 check
(myXML
.createElement
);
603 // file.puts("function: dodo()");
604 // create three XML nodes using createElement()
605 var element1
= myXML
.createElement
("element1");
606 check
(element1
.nodeName
== "element1");
608 var element2
= myXML
.createElement
("element2");
609 check_equals
(element2
.nodeName
, "element2");
611 var element3
= myXML
.createElement
("element3");
612 check_equals
(element3
.nodeName
, "element3");
614 check
(myXML
.createTextNode
);
616 // create two XML text nodes using createTextNode()
617 var textNode1
= myXML
.createTextNode
("textNode1 String value");
618 check
(textNode1
.nodeValue
== "textNode1 String value");
620 var textNode2
= myXML
.createTextNode
("textNode2 String value");
621 check
(textNode2
.nodeValue
== "textNode2 String value");
623 // place the new nodes into the XML tree
624 check
(!element2
.hasChildNodes
());
625 ret
= element2
.appendChild
(textNode1
);
626 check_equals
(typeof(ret
), 'undefined');
627 check
(element2
.hasChildNodes
());
629 check_equals
(element2
.nodeValue
, null);
630 check_equals
(typeof(element2
.lastChild
), 'object');
631 check_equals
(element2
.lastChild
.nodeValue
, "textNode1 String value");
632 element2
.lastChild
= 4;
633 check_equals
(typeof(element2
.lastChild
), 'object');
635 element3
.appendChild
(textNode2
);
636 check_equals
(element3
.nodeValue
, null);
637 check_equals
(typeof(element3
.lastChild
), 'object');
638 check_equals
(element3
.lastChild
.nodeValue
, "textNode2 String value");
640 // place the new nodes into the XML tree
641 doc
.appendChild
(element1
);
642 //check(doc.firstChild.nodeName == "element1");
644 element1
.appendChild
(element2
);
645 check
(element1
.hasChildNodes
());
646 // trace(element1.nodeName);
647 // trace(element1.firstChild.nodeName);
648 check
(element1
.firstChild
.nodeName
== "element2");
650 element2
.appendChild
(element3
);
651 check
(element2
.hasChildNodes
());
653 trace
(doc
.toString
());
655 // // trace(myXML.toString());
657 // newnode = myXML.cloneNode(false);
659 // //trace(myXML.nodeName);
660 // //trace(newnode.nodeValue);
662 // //trace("Child1" + _global.child1);
663 // //trace("Child2" + _global.child2);
665 // // This won't work as onLoad is not called unless you
666 // // actually *load* the XML, we're using parseXML that
667 // // does *not* trigger loading (see also getBytesLoaded
668 // // and getBytesTotal) and does *not* trigger onLoad
669 // // event to execute.
671 // if ((_global.child1 == "sub sub1 node data 1")
672 // && (global.child2 == "sub sub1 node data 2")) {
673 // pass("XML::onLoad works");
675 // fail("XML::onLoad doesn't work");
680 // Test sendAndLoad return;
681 // Any object can be passed as second argument.
685 check
(!r
.hasOwnProperty
("loaded"));
686 check_equals
(x
.sendAndLoad
("some server name", r
), true);
687 check
(r
.hasOwnProperty
("loaded"));
690 check
(!r
.hasOwnProperty
("loaded"));
691 check_equals
(x
.sendAndLoad
("some server name", r
), true);
692 check
(!r
.hasOwnProperty
("loaded"));
693 check_equals
(typeof(r
.loaded
), "boolean");
694 check_equals
(r
.loaded
, false);
696 #if OUTPUT_VERSION
> 5
697 // No LoadVars in SWF 5.
699 check
(!r
.hasOwnProperty
("loaded"));
700 check_equals
(x
.sendAndLoad
("some server name", r
), true);
701 check
(r
.hasOwnProperty
("loaded"));
702 check_equals
(typeof(r
.loaded
), "boolean");
703 check_equals
(r
.loaded
, false);
707 check
(!r
.hasOwnProperty
("loaded"));
708 check_equals
(x
.sendAndLoad
("some server name", r
), true);
709 check
(r
.hasOwnProperty
("loaded"));
710 check_equals
(typeof(r
.loaded
), "boolean");
711 check_equals
(r
.loaded
, false);
713 check_equals
(r
.toString
(), t
.toString
());
714 check
(r instanceOf
Date);
717 check
(!r
.hasOwnProperty
("loaded"));
718 check_equals
(x
.sendAndLoad
("some server name", r
), false);
719 check
(!r
.hasOwnProperty
("loaded"));
720 check_equals
(typeof(r
.loaded
), "undefined");
721 check_equals
(r
.loaded
, undefined);
724 check
(!r
.hasOwnProperty
("loaded"));
725 check_equals
(x
.sendAndLoad
("some server name", r
), false);
726 check
(!r
.hasOwnProperty
("loaded"));
727 check_equals
(typeof(r
.loaded
), "undefined");
728 check_equals
(r
.loaded
, undefined);
731 check
(!r
.hasOwnProperty
("loaded"));
732 check_equals
(x
.sendAndLoad
("some server name", r
), true);
733 check
(r
.hasOwnProperty
("loaded"));
734 check_equals
(typeof(r
.loaded
), "boolean");
735 check_equals
(r
.loaded
, false);
738 /// Test addRequestHeaders
740 #if OUTPUT_VERSION
> 5
742 check
(!x
.hasOwnProperty
("_customHeaders"));
744 x
.addRequestHeader
("header1", "value1");
745 check
(x
.hasOwnProperty
("_customHeaders"));
746 check
(x
._customHeaders instanceOf
Array);
747 check_equals
(x
._customHeaders
.toString
(), "header1,value1");
749 x
.addRequestHeader
("header2", "value2");
750 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2");
752 x
.addRequestHeader
(["header3", "value3", "header4", "value4"]);
753 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,value4");
755 x
._customHeaders
.pop
();
756 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4");
758 x
._customHeaders
[8] = "value4";
759 #if OUTPUT_VERSION
< 7
760 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,,value4");
762 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,undefined,value4");
765 x
._customHeaders
[7] = "shoved in";
767 x
.addRequestHeader
("header5", "value5");
768 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,shoved in,value4,header5,value5");
770 x
.addRequestHeader
("GET", "should not be sent");
771 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,shoved in,value4,header5,value5,GET,should not be sent");
773 x
.addRequestHeader
("Public", "should not be sent");
774 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,shoved in,value4,header5,value5,GET,should not be sent,Public,should not be sent");
776 /// Shouldn't change _customHeaders
777 x
.contentType
="Odd Content Type";
778 check_equals
(x
._customHeaders
.toString
(), "header1,value1,header2,value2,header3,value3,header4,shoved in,value4,header5,value5,GET,should not be sent,Public,should not be sent");
780 x
._customHeaders
= 3;
781 check_equals
(x
._customHeaders
.toString
(), "3");
783 x
.addRequestHeader
("header0", "value0");
784 check_equals
(x
._customHeaders
.toString
(), "3");
787 // Only strings work.
789 check
(!x
.hasOwnProperty
("_customHeaders"));
790 x
.addRequestHeader
(3);
791 check
(x
.hasOwnProperty
("_customHeaders"));
792 check_equals
(x
._customHeaders
.toString
(), "");
795 check
(!x
.hasOwnProperty
("_customHeaders"));
796 x
.addRequestHeader
();
797 check
(x
.hasOwnProperty
("_customHeaders"));
798 check_equals
(x
._customHeaders
.toString
(), "");
802 x
.addRequestHeader
(3, 5);
803 check_equals
(x
._customHeaders
.toString
(), "");
805 x
.addRequestHeader
(new Date, new Object);
806 check_equals
(x
._customHeaders
.toString
(), "");
808 x
.addRequestHeader
("string", 6);
809 check_equals
(x
._customHeaders
.toString
(), "");
811 x
.addRequestHeader
("string", "string");
812 check_equals
(x
._customHeaders
.toString
(), "string,string");
816 //--------------------------------------------------------------------
817 // Test loading an XML locally
818 //--------------------------------------------------------------------
822 check_equals
(typeof(myxml
.onData
), 'function');
823 #if OUTPUT_VERSION
> 5
824 check
(myxml
.onData
!= XML.prototype
.parseXML
);
827 check
(!myxml
.hasOwnProperty
('onLoad'));
829 myxml
.onLoadCalls
= 0;
831 myxml
.onLoad
= function(success
)
833 //note("myxml.onLoad("+success+") called");
835 check_equals
(typeof(myxml
.status
), 'number');
836 check_equals
(typeof(myxml
.loaded
), 'boolean');
837 #if OUTPUT_VERSION
>= 6
838 check
(! myxml
.hasOwnProperty
('status'));
839 check
(! myxml
.hasOwnProperty
('loaded'));
840 #endif
// OUTPUT_VERSION >= 6
844 note
("No success loading gnash.xml");
845 check_equals
(myxml
.status
, 0);
846 check
(! myxml
.loaded
);
849 note
("gnash.xml successfully loaded");
850 note
("myxml status is "+myxml
.status
);
851 check_equals
(myxml
.status
, 0);
854 // Check 'loaded' and 'status' to be "overridable"
856 var loaded_backup
= myxml
.loaded
;
857 myxml
.loaded
= 'a string';
858 check_equals
(typeof(myxml
.loaded
), 'boolean');
859 myxml
.loaded
= ! loaded_backup
;
860 check
(myxml
.loaded
!= loaded_backup
);
861 myxml
.loaded
= loaded_backup
;
863 var status_backup
= myxml
.status
;
864 myxml
.status
= 'a string';
865 check_equals
(typeof(myxml
.status
), 'number');
866 check
(myxml
.status
!= status_backup
);
867 //note("myxml.status is == "+myxml.status+" after being set to 'a string'");
868 myxml
.status
= status_backup
;
871 //note("myxml.toString(): "+myxml.toString());
872 check_equals
(typeof(myxml
.attributes
), 'object');
873 check
(! myxml
.attributes
instanceof Object);
874 check_equals
(typeof(myxml
.attributes
.__proto__
), 'undefined');
876 check
(myxml
.hasChildNodes
());
877 check_equals
(myxml
.nodeName
, null);
879 topnode
= myxml
.firstChild
;
880 #if OUTPUT_VERSION
== 5
881 xcheck_equals
(topnode
.nodeName
, null);
882 xcheck_equals
(topnode
.attributes
.attr1
, undefined);
884 check_equals
(topnode
.nodeName
, 'XML');
885 check_equals
(topnode
.attributes
.attr1
, 'attr1 value');
888 // XML, comment, NULL
889 if ( typeof(myxml
.lastChildNodesCount
) == 'undefined' )
891 myxml
.lastChildNodesCount
= myxml
.childNodes
.length
;
895 check_equals
(myxml
.childNodes
.length
, myxml
.lastChildNodesCount
);
897 #if OUTPUT_VERSION
== 5
898 xcheck_equals
(myxml
.childNodes
.length
, 4); // gnash fails discarding the comment and the ending blanks
900 check_equals
(myxml
.childNodes
.length
, 3); // gnash fails discarding the comment and the ending blanks
905 //note("onLoad called "+this.onLoadCalls+" times");
906 #if OUTPUT_VERSION
< 8
907 if ( this.onLoadCalls
== 2 )
909 if ( this.onLoadCalls
== 1 )
912 #if OUTPUT_VERSION
< 6
915 # if OUTPUT_VERSION
< 8
926 check_equals
(typeof(myxml
.status
), 'number');
927 #if OUTPUT_VERSION
< 7
928 check_equals
(typeof(myxml
.STATUS
), 'number');
929 #else // OUTPUT_VERSION >= 7
930 check_equals
(typeof(myxml
.STATUS
), 'undefined');
931 #endif
// OUTPUT_VERSION >= 7
933 check_equals
(typeof(myxml
.__proto__
.status
), 'undefined');
934 check_equals
(typeof(myxml
.loaded
), 'undefined');
935 check_equals
(typeof(myxml
._bytesLoaded
), 'undefined');
936 check_equals
(typeof(myxml
._bytesTotal
), 'undefined');
938 check
(!myxml
.hasOwnProperty
('status'));
939 check
(!myxml
.hasOwnProperty
('loaded'));
940 check
(!myxml
.hasOwnProperty
('_bytesLoaded'));
941 check
(!myxml
.hasOwnProperty
('_bytesTotal'));
943 ret
= myxml
.load
( MEDIA
(gnash
.xml
) );
945 check
(myxml
.hasOwnProperty
('_bytesLoaded'));
946 check
(myxml
.hasOwnProperty
('_bytesTotal'));
948 check_equals
(typeof(myxml
.loaded
), 'boolean');
949 #if OUTPUT_VERSION
< 7
950 check_equals
(typeof(myxml
.LOADED
), 'boolean');
951 #else // OUTPUT_VERSION >= 7
952 check_equals
(typeof(myxml
.LOADED
), 'undefined');
953 #endif
// OUTPUT_VERSION >= 7
954 check
(! myxml
.loaded
); // is really loaded in a background thread
956 check_equals
(myxml
.loaded
, false ); // is really loaded in a background thread
957 //note("myxml.loaded = "+myxml.loaded);
958 //note("myxml.load() returned "+ret);
960 // Load again, to verify new parsing doesn't get appended to the old
961 ret
= myxml
.load
( MEDIA
(gnash
.xml
) );
963 //------------------------------------------------
964 // Test XML.ignoreWhite
965 //------------------------------------------------
968 xmlin
= "<X1T> <X1C1> </X1C1> <X1C2>\n</X1C2> </X1T>";
969 xmlin2
= "<X0><X1/></X0>";
970 xmlin2_out
= "<X0><X1 /></X0>";
971 xmlin_stripwhite
= "<X1T><X1C1 /><X1C2 /></X1T>";
973 myxml2
.ignoreWhite
= false;
974 myxml2
.parseXML
(xmlin
);
975 check_equals
(myxml2
.childNodes
.length
, 1);
976 check_equals
(myxml2
.toString
(), xmlin
);
977 myxml2
.parseXML
(xmlin2
); // parsing twice doesn't append !
978 check_equals
(myxml2
.childNodes
.length
, 1);
979 check_equals
(myxml2
.toString
(), xmlin2_out
);
981 myxml2
.ignoreWhite
= true;
982 myxml2
.parseXML
(xmlin
);
983 check_equals
(myxml2
.toString
(), xmlin_stripwhite
);
985 myxml2
.ignoreWhite
= true;
986 myxml2
.parseXML
("<X1> </X1>");
987 check_equals
(myxml2
.childNodes
.length
, 1);
988 check
(!myxml2
.childNodes
[0].hasChildNodes
());
989 check_equals
(myxml2
.toString
(), "<X1 />");
991 myxml2
.ignoreWhite
= false;
992 myxml2
.parseXML
("<X1> </X1>");
993 check_equals
(myxml2
.childNodes
.length
, 1);
994 check
(myxml2
.childNodes
[0].hasChildNodes
());
995 check_equals
(myxml2
.childNodes
[0].childNodes
[0].nodeType
, 3); // text node
996 check_equals
(myxml2
.childNodes
[0].childNodes
[0].nodeValue
, ' '); // text node
997 check_equals
(myxml2
.toString
(), "<X1> </X1>");
999 myxml2
.ignoreWhite
= true;
1000 myxml2
.parseXML
("<X1>\n</X1>");
1001 check_equals
(myxml2
.childNodes
.length
, 1);
1002 check
(!myxml2
.childNodes
[0].hasChildNodes
());
1003 check_equals
(myxml2
.toString
(), "<X1 />");
1005 myxml2
.ignoreWhite
= true;
1006 myxml2
.parseXML
("<X1> t </X1>");
1007 check_equals
(myxml2
.toString
(), "<X1> t </X1>");
1009 /// Check various malformed XMLs
1011 h
= new XML("<open>");
1012 check_equals
(h
.toString
(), "<open />");
1014 h
= new XML("<open></close>");
1015 check_equals
(h
.toString
(), "<open />");
1017 h
= new XML("<open><open2></open>");
1018 check_equals
(h
.toString
(), "<open><open2 /></open>");
1020 h
= new XML("<open att='");
1021 check_equals
(h
.toString
(), "");
1023 h
= new XML("<open att r='kk'");
1024 check_equals
(h
.toString
(), "");
1026 h
= new XML("<open>& ' \"<");
1027 check_equals
(h
.toString
(), "<open>& ' "</open>");
1029 // A non-breaking space (honest).
1030 h
= new XML("<open> </open>");
1031 check_equals
(h
.toString
(), "<open> </open>");
1033 h
= new XML("</open><open>node with \"</open>");
1034 check_equals
(h
.toString
(), "");
1036 h
= new XML("<open/><open><!-- lkjsdcölkj<hello>");
1037 check_equals
(h
.toString
(), "<open /><open />");
1039 h
= new XML("<open><![CDATA[jlkjdc</open>");
1040 check_equals
(h
.toString
(), "<open />");
1042 // Check DOCTYPE and xml declarations.
1044 check_equals
(h
.docTypeDecl
, undefined);
1045 check_equals
(h
.xmlDecl
, undefined);
1047 h
= new XML("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><tag></tag>");
1048 check_equals
(h
.toString
(), "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'><tag />");
1049 check_equals
(h
.docTypeDecl
, "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>");
1051 h
= new XML("<!DOcTyPE text><tag></tag>");
1052 check_equals
(h
.toString
(), "<!DOcTyPE text><tag />");
1053 check_equals
(h
.docTypeDecl
, "<!DOcTyPE text>");
1055 h
= new XML("<?xml declaration goes here?><tag>content</tag>");
1056 check_equals
(h
.toString
(), "<?xml declaration goes here?><tag>content</tag>");
1057 check_equals
(h
.xmlDecl
, "<?xml declaration goes here?>");
1059 h
= new XML("<?xMl declaration goes here?><tag>content</tag>");
1060 check_equals
(h
.toString
(), "<?xMl declaration goes here?><tag>content</tag>");
1061 check_equals
(h
.xmlDecl
, "<?xMl declaration goes here?>");
1064 h
= new XML("<!doctype d><?xMl declaration goes here?><tag>content</tag>");
1065 check_equals
(h
.toString
(), "<?xMl declaration goes here?><!doctype d><tag>content</tag>");
1066 check_equals
(h
.xmlDecl
, "<?xMl declaration goes here?>");
1067 check_equals
(h
.docTypeDecl
, "<!doctype d>");
1070 h
= new XML("<tag></tag><!doctype d><?xMl declaration goes here?><tag>content</tag>");
1071 check_equals
(h
.toString
(), "<?xMl declaration goes here?><!doctype d><tag /><tag>content</tag>");
1073 // Check multiple declarations
1074 h
= new XML("<tag></tag><!doctype d><?xMl decl?><!dOcType new><?XMl new?>");
1075 check_equals
(h
.toString
(), "<?xMl decl?><?XMl new?><!dOcType new><tag />");
1076 check_equals
(h
.xmlDecl
, "<?xMl decl?><?XMl new?>");
1079 check_equals
(typeof(h
.xmlDecl
), "string");
1080 check_equals
(h
.xmlDecl
, "7");
1081 check_equals
(h
.toString
(), "7<!dOcType new><tag />");
1084 check_equals
(typeof(h
.docTypeDecl
), "string");
1085 check_equals
(h
.docTypeDecl
, "98");
1086 check_equals
(h
.toString
(), "798<tag />");
1088 #if OUTPUT_VERSION
> 5
1090 /// Check special characters
1091 r
= new XML("1: å 2: ä 3: Ё 4: ई 5: ä");
1092 xcheck_equals
(r
.toString
(), "1: å 2: ä 3: Ё 4: ई 5: ä");
1094 r
= new XML("1: åe2; 2: Le9; 3: &#ee229; 4: &#fee; 5: a");
1095 xcheck_equals
(r
.toString
(), "1: å 2: L 3: &#ee229; 4: &#fee; 5: a");