<?xml version="1.0"?>

<!-- Work done for Netscape.  Public domain. -->

<?xml-stylesheet type="text/css" href="../base.css" ?>
<?xml-stylesheet type="text/css" href="../basexml.css" ?>
<!--DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd"-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<title>DOM Test Suite: Interface Node (extended interfaces)</title>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="copyright" href="http://dbaron.org/legal.html" />

<!--XXX Should this work in XHTML: ?? - It doesn't -->

<link rel="stylesheet" type="text/css" href="../base.css" />
<script type="text/javascript" src="../base.js" />

<!-- XXX we're getting no response to the HTML dom, only Core -->

<script type="text/javascript"><![CDATA[

function runPTest () {

	if ( ! ( canOutputWarn() &&  existsWarn("document") && existsWarn("document.getElementsByTagName"))) {
		return;
		}

	ulistE = document.getElementsByTagName("ul").item(0);
	firstE = document.getElementsByTagName("li").item(0);
	secondE = document.getElementsByTagName("li").item(1);
	thirdE = document.getElementsByTagName("li").item(2);
	fourthE = document.getElementsByTagName("li").item(3);

	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		secondA = secondE.getAttributeNode("class");
	}
	thirdT = thirdE.firstChild;
	fourthC = fourthE.firstChild;

	scriptE = document.getElementsByTagName("script").item(1);
		// second script element in document

	// I don't work with these yet:
	scriptCDATA = scriptE.firstChild;

	outTaggedText("header", "Testing nodeName:");
	shouldBe("ulistE.nodeName",'"ul"');
	shouldNotBe("ulistE.nodeName",'"li"');
	shouldBe("firstE.nodeName",'"li"');
	shouldBe("secondE.nodeName",'"li"');
	shouldBe("thirdE.nodeName",'"li"');
	shouldBe("fourthE.nodeName",'"li"');
	shouldNotBe("fourthE.nodeName",'""');

	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		shouldBe("secondA.nodeName",'"class"');
	}
	shouldBe("thirdT.nodeName",'"#text"');
	shouldBe("fourthC.nodeName",'"#comment"');
	shouldBe("document.nodeName",'"#document"');
	if ( notNullWarn("document.doctype") ) { // for Mozilla
		shouldBe("document.doctype.nodeName",'"html"');
	}
	shouldNotBe("thirdT.nodeName",'""');
	shouldNotBe("fourthC.nodeName",'""');

	outTaggedText("header", "Testing nodeValue:");

	shouldBe("ulistE.nodeValue","null");
	shouldBe("firstE.nodeValue","null");
	shouldBe("secondE.nodeValue","null");
	shouldBe("thirdE.nodeValue","null");
	shouldBe("fourthE.nodeValue","null");
	shouldNotBe("thirdE.nodeValue",'"li"');

	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		shouldBe("secondA.nodeValue",'"afterfirst"');
	}
	shouldBe("thirdT.nodeValue",'"third text"');
	shouldNotBe("thirdT.nodeValue","null");
	shouldBe("fourthC.nodeValue",'" A comment "');
	shouldBe("document.nodeValue","null");
	shouldBe("document.doctype.nodeValue","null");

	outTaggedText("header", "Testing nodeType:");

	// shouldBe("firstE.nodeType","ELEMENT_NODE");
	shouldBe("firstE.nodeType","1");
	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		// shouldBe("secondA.nodeType","ATTRIBUTE_NODE");
		shouldBe("secondA.nodeType","2");
	}
	// shouldBe("thirdT.nodeType","TEXT_NODE");
	shouldBe("thirdT.nodeType","3");
	// shouldBe("fourthC.nodeType","COMMENT_NODE");
	shouldBe("fourthC.nodeType","8");
	shouldNotBe("fourthC.nodeType","7");
	shouldBe("document.nodeType", "9");
	shouldBe("document.doctype.nodeType", "10");

	outTaggedText("header", "Testing parentNode:");
	shouldBe("firstE.parentNode","ulistE");
	shouldBe("secondE.parentNode","ulistE");
	shouldNotBe("secondE.parentNode","null");
	shouldBe("thirdE.parentNode","ulistE");
	shouldBe("fourthE.parentNode","ulistE");
	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		shouldBe("secondA.parentNode","null");
		shouldNotBe("secondA.parentNode","secondE");
	}
	shouldBe("thirdT.parentNode","thirdE");
	shouldBe("fourthC.parentNode","fourthE");
	shouldBe("document.parentNode","null");
	shouldBe("document.doctype.parentNode","document");


	outTaggedText("header", "Testing firstChild:");

	shouldBe("ulistE.firstChild","firstE");
	shouldBe("thirdT.firstChild","null");

	// MORE TESTS HERE...

	outTaggedText("header", "Testing lastChild:");

	shouldBe("ulistE.lastChild","fourthE");
	shouldBe("thirdT.lastChild","null");

	// MORE TESTS HERE...

	outTaggedText("header", "Testing previousSibling:");

	shouldBe("firstE.previousSibling","null");
	shouldBe("secondE.previousSibling","firstE");
	// MORE TESTS HERE...

	outTaggedText("header", "Testing nextSibling:");

	shouldBe("fourthE.nextSibling","null");
	shouldBe("secondE.nextSibling","thirdE");
	// MORE TESTS HERE...

	outTaggedText("header", "Testing attributes:");
	shouldBe("thirdE.attributes.length","1");
	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		shouldBe("secondA.attributes","null");
	}
	shouldBe("thirdT.attributes","null");
	shouldBe("fourthC.attributes","null");
	shouldBe("document.attributes","null");
	shouldBe("document.doctype.attributes","null");

	outTaggedText("header", "Testing ownerDocument:");
	shouldBe("secondE.ownerDocument", "document");
	shouldBe("thirdE.ownerDocument", "fourthC.ownerDocument");

	if ( existsWarn("secondE.getAttributeNode") ) { // for MSIE5
		shouldNotBe("secondA.ownerDocument.documentElement","null");
	}

	if ( existsWarn("thirdT.ownerDocument") ) { // for MSIE5
		shouldBe("thirdT.ownerDocument.ownerDocument","null");
	}
	shouldBe("document.doctype.ownerDocument","document");

	outTaggedText("header", "Testing hasChildNodes():");

	shouldBe("thirdT.hasChildNodes()","false");
	shouldBe("firstE.hasChildNodes()","true");

	outTaggedText("header", "Finished passive tests.");

}

function makeElemText ( elemName, text ) {

	// utility function
	// create an Element with name elemName and contents text

	elem = document.createElement(elemName);

	elem.appendChild ( document.createTextNode(text) );

	return elem;

}

function testchildNodes() {
	outTaggedText("header", "Testing childNodes and NodeList interface:");

	ulistE = document.getElementsByTagName("ul").item(0);
	firstE = document.getElementsByTagName("li").item(0);
	secondE = document.getElementsByTagName("li").item(1);
	thirdE = document.getElementsByTagName("li").item(2);
	fourthE = document.getElementsByTagName("li").item(3);

	thirdT = thirdE.firstChild;

	outTaggedText("header", "Testing childNodes in a static situation:");

	shouldBe("ulistE.childNodes.length","4");
	shouldBe("ulistE.childNodes.item(0)","firstE");
	shouldBe("ulistE.childNodes.item(1)","secondE");
	shouldBe("ulistE.childNodes.item(2)","thirdE");
	shouldBe("ulistE.childNodes.item(3)","fourthE");
	shouldNotBe("ulistE.childNodes.item(2)","secondE");
	shouldNotBe("thirdT.childNodes","null");
	if ( notNullWarn("thirdT.childNodes") ) { // for Mozilla
		shouldBe("thirdT.childNodes.length","0");
	}

	outTaggedText("header", "Testing childNodes in a dynamic situation:");

	cn = ulistE.childNodes;
	outText("cn = ulistE.childNodes;");

	shouldBe("cn.length","4");

	outText("appending list item newnode, containing 'fifth text'.");

	newnode = makeElemText("LI", "fifth text");
	ulistE.appendChild( newnode );

	shouldBe("cn.length","5");
	shouldBe("ulistE.childNodes.item(3)","fourthE");
	shouldBe("ulistE.childNodes.item(4)","newnode");

	outText("Removing secondE from list.");
	ulistE.removeChild(secondE);

	shouldBe("cn.length","4");
	shouldBe("ulistE.childNodes.item(0)","firstE");
	shouldBe("ulistE.childNodes.item(1)","thirdE");

	outTaggedText("header", "Finished.");

}

function testinsertBefore() {
	outTaggedText("header", "Testing insertBefore...");

	ulistE = document.getElementsByTagName("ul").item(0);
	firstE = document.getElementsByTagName("li").item(0);
	secondE = document.getElementsByTagName("li").item(1);
	thirdE = document.getElementsByTagName("li").item(2);
	fourthE = document.getElementsByTagName("li").item(3);

	outText("Inserting list item '0.5 text' before list item 'first text'.");
	ulistE.insertBefore( makeElemText("LI", "0.5 text"), firstE);

	outText("Inserting list item '3.5 text' after list item 'fourth text.'");
	ulistE.insertBefore( makeElemText("LI", "3.5 text"), null);

	outText("Testing that inserted nodes are removed from the tree:");
	outText("  Creating a new node, inserting it, and moving it to its correct position");

	jumper = makeElemText("LI", "2.5 text");
	shouldBe("ulistE.insertBefore( jumper, secondE)", "jumper");
	shouldNotBe("thirdE", "jumper");
	ulistE.insertBefore( jumper, thirdE);

	outText("  Moving an existing node, to put fourth after 3.5");
	ulistE.insertBefore( fourthE, null );

	outText("The list should now read 0.5, first, second, 2.5, third, 3.5, fourth.")

	outTaggedText("header", "Test finished.");

}

function testrraChild() {
	ulistE = document.getElementsByTagName("ul").item(0);
	firstE = document.getElementsByTagName("li").item(0);
	secondE = document.getElementsByTagName("li").item(1);
	thirdE = document.getElementsByTagName("li").item(2);
	fourthE = document.getElementsByTagName("li").item(3);

	outTaggedText("header", "Testing replaceChild...");

	fir = ulistE.replaceChild( makeElemText("LI", "primero"), firstE);
	shouldBe("fir.parentNode","null");

	outTaggedText("header", "Testing removeChild...");

	sec = ulistE.removeChild( secondE);

	outTaggedText("header", "Testing appendChild...");

	ulistE.appendChild( thirdE );
	ulistE.appendChild( fir );
	ulistE.appendChild( sec );
	ulistE.appendChild( makeElemText("LI", "final") );

	outText("The list should now be:  primero, fourth text, third text, first text, second text, final.");

	outTaggedText("header", "Test finished.");

}

function testcloneNode() {

	outTaggedText("header", "Testing cloneNode...");

	ulistE = document.getElementsByTagName("ul").item(0);
	firstE = document.getElementsByTagName("li").item(0);
	secondE = document.getElementsByTagName("li").item(1);
	thirdE = document.getElementsByTagName("li").item(2);
	fourthE = document.getElementsByTagName("li").item(3);

	thirdT = thirdE.firstChild;

	// create a list with "second", "third", "third"
	newlist = ulistE.cloneNode(false);
	newlist.appendChild(secondE.cloneNode(true));
	newfirst = firstE.cloneNode(false);
	newfirst.appendChild(thirdT.cloneNode(false));
	newlist.appendChild(newfirst);
	newfirst = firstE.cloneNode(false);
	newfirst.appendChild(thirdT.cloneNode(true));
	newlist.appendChild(newfirst);

	firstE.appendChild(newlist);

	thirdE.appendChild(ulistE.cloneNode(true));

	outText("You should now see that the first two list items have sublists.");
	outText("The 'first' item should have a child list that says");
	outText("'second', 'third', 'third', and the 'third' item should have a");
	outText("child list that is a duplicate of the whole list, including the");
	outText("additions to the 'first' item, but not the additions to itself.");

	outTaggedText("header", "Finished.");

	}

]]></script>
<style type="text/css"><![CDATA[
.afterfirst { color: black; background: yellow; }
]]></style>
</head>
<body>
<h1>DOM Test Suite:  Interface <a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1950641247">Node</a></h1>

<h2>Instructions</h2>

<p>
	This test does not test all node types, only the ones easily used in
	HTML, except for documentFragment, which will be tested separately.
	It therefore doesn't test node
	insertion or appending with documentFragments.
</p>

<p>
	It also does not test
	the defined constants in the definition of Node, since they aren't in
	the javascript binding. (correct???)
</p>

<p>
	This test tests that <code>childNodes</code> is
	a dynamic list of the child nodes. See
	<a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-1590626202">section 1.1.1</a>
	of the DOM spec for more information on this.
</p>

<p>
	These tests should all be run separately.  You will need to reload
	the page between them.  They're just all in one page for my
	convenience.
</p>

<p>
	<input type="button" onclick="runPTest()" value="Run Passive Tests" />
	<input type="button" onclick="testchildNodes()" value="test childNodes and NodeList interface" />
	<input type="button" onclick="testinsertBefore()" value="test insertBefore" />
	<input type="button" onclick="testrraChild()" value="test replaceChild(), removeChild(), and appendChild()" />
	<input type="button" onclick="testcloneNode()" value="test cloneNode" />
</p>

<div id="testarea">
<h2>Testing Area</h2>

<ul id="ulist"><li id="first">first text</li><li id="second" class="afterfirst">second text</li><li id="third">third text</li><li id="fourth"><!-- A comment -->fourth text</li></ul>

</div>

<div id="output">
<h2>Output:</h2>

</div>

<p>
	Bugzilla:
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6033">6033</a>,
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6046">6046</a>,
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6052">6052</a>,
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6069">6069</a>,
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6071">6071</a>,
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6073">6073</a>,
	<a href="http://bugzilla.mozilla.org/show_bug.cgi?id=6152">6152</a>.
</p>

<hr title="Beginning of Footer" />
<p>(Back to
<a href="../">DOM Testing Information</a>,
<a href="../../../">David Baron</a>)</p>
<p><a href="/" title="David Baron's Homepage">LDB</a>,
<a rev="made" href="mailto:dbaron@fas.harvard.edu" title="Send e-mail to David Baron">dbaron@fas.harvard.edu</a></p>

</body></html>
