<?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 DocumentFragment</title>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="stylesheet" type="text/css" href="../base.css" />
<script type="text/javascript" src="../base.js" />
<script type="text/javascript"><![CDATA[

function testAttributes() {
	if (!( canOutputWarn() &&  existsWarn("document") && existsWarn("document.getElementsByTagName") && existsWarn("document.createDocumentFragment") )) {
		return;
	}
	dfrag = document.createDocumentFragment();

	UList = document.getElementsByTagName("ul").item(0);
	firstLI = document.getElementsByTagName("li").item(0);
	secondLI = document.getElementsByTagName("li").item(1);
	thirdLI = document.getElementsByTagName("li").item(2);
	fourthLI = document.getElementsByTagName("li").item(3);
	shouldBe("UList.getAttribute('id')", '"ulist"');
	shouldBe("firstLI.getAttribute('id')", '"first"');
	shouldBe("secondLI.getAttribute('id')", '"second"');
	shouldBe("thirdLI.getAttribute('id')", '"third"');
	shouldBe("fourthLI.getAttribute('id')", '"fourth"');

	dfrag.appendChild(firstLI);
	dfrag.appendChild(secondLI);
	dfrag.appendChild(thirdLI);
	dfrag.appendChild(fourthLI);

	shouldBe("UList.childNodes.length", "0");// tested more in testAppendChild()

	shouldBe("dfrag.nodeName", "'#document-fragment'");
	shouldBe("dfrag.nodeValue", "null");
	shouldBe("dfrag.nodeType", "11");
	shouldBe("dfrag.parentNode", "null");
	shouldBe("dfrag.childNodes.length", "4");
	shouldBe("dfrag.childNodes.item(2)", "thirdLI");
	shouldBe("dfrag.firstChild", "firstLI");
	shouldBe("dfrag.lastChild", "fourthLI");
	shouldBe("dfrag.previousSibling", "null");
	shouldBe("dfrag.nextSibling", "null");
	shouldBe("dfrag.attributes", "null");
	shouldBe("dfrag.ownerDocument", "document");

	outTaggedText("header", "Done testing attributes.");

}

function testAppendChild() {
	if (!( canOutputWarn() &&  existsWarn("document") && existsWarn("document.getElementsByTagName") && existsWarn("document.createDocumentFragment") )) {
		return;
	}
	
	dfrag = document.createDocumentFragment();

	UList = document.getElementsByTagName("ul").item(0);
	firstLI = document.getElementsByTagName("li").item(0);
	secondLI = document.getElementsByTagName("li").item(1);
	thirdLI = document.getElementsByTagName("li").item(2);
	fourthLI = document.getElementsByTagName("li").item(3);
	shouldBe("UList.getAttribute('id')", '"ulist"');
	shouldBe("firstLI.getAttribute('id')", '"first"');
	shouldBe("secondLI.getAttribute('id')", '"second"');
	shouldBe("thirdLI.getAttribute('id')", '"third"');
	shouldBe("fourthLI.getAttribute('id')", '"fourth"');

	dfrag.appendChild(thirdLI);
	dfrag.appendChild(fourthLI);

	shouldBe("UList.childNodes.length", "2");
	shouldBe("UList.childNodes.item(0)", "firstLI");
	shouldBe("UList.childNodes.item(1)", "secondLI");
	shouldBe("dfrag.childNodes.length", "2");
	shouldBe("dfrag.childNodes.item(0)", "thirdLI");
	shouldBe("dfrag.childNodes.item(1)", "fourthLI");

	thirdrep = dfrag.replaceChild(firstLI, thirdLI);

	shouldBe("thirdrep", "thirdLI");

	shouldBe("UList.childNodes.length", "1");
	shouldBe("UList.childNodes.item(0)", "secondLI");
	shouldBe("dfrag.childNodes.length", "2");
	shouldBe("dfrag.childNodes.item(0)", "firstLI");
	shouldBe("dfrag.childNodes.item(1)", "fourthLI");

	UList.appendChild(thirdrep);

	shouldBe("UList.childNodes.length", "2");
	shouldBe("UList.childNodes.item(0)", "secondLI");
	shouldBe("UList.childNodes.item(1)", "thirdLI");
	shouldBe("UList.childNodes.item(1)", "thirdrep");
	shouldBe("dfrag.childNodes.length", "2");
	shouldBe("dfrag.childNodes.item(0)", "firstLI");
	shouldBe("dfrag.childNodes.item(1)", "fourthLI");

	UList.appendChild(dfrag);

	shouldBe("UList.childNodes.length", "4");
	shouldBe("UList.childNodes.item(0)", "secondLI");
	shouldBe("UList.childNodes.item(1)", "thirdLI");
	shouldBe("UList.childNodes.item(2)", "firstLI");
	shouldBe("UList.childNodes.item(3)", "fourthLI");
	shouldBe("dfrag.childNodes.length", "0");

	outTaggedText("header", "Tests of appendChild() finished.");
	
}

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

	dfrag = document.createDocumentFragment();

	UList = document.getElementsByTagName("ul").item(0);
	firstLI = document.getElementsByTagName("li").item(0);
	secondLI = document.getElementsByTagName("li").item(1);
	thirdLI = document.getElementsByTagName("li").item(2);
	fourthLI = document.getElementsByTagName("li").item(3);
	shouldBe("UList.getAttribute('id')", '"ulist"');
	shouldBe("firstLI.getAttribute('id')", '"first"');
	shouldBe("secondLI.getAttribute('id')", '"second"');
	shouldBe("thirdLI.getAttribute('id')", '"third"');
	shouldBe("fourthLI.getAttribute('id')", '"fourth"');

	dfrag.insertBefore(firstLI, null);
	dfrag.insertBefore(thirdLI, null);
	dfrag.insertBefore(secondLI, thirdLI);

	shouldBe("UList.childNodes.length", "1");
	shouldBe("UList.childNodes.item(0)", "fourthLI");
	shouldBe("dfrag.childNodes.length", "3");
	shouldBe("dfrag.childNodes.item(0)", "firstLI");
	shouldBe("dfrag.childNodes.item(1)", "secondLI");
	shouldBe("dfrag.childNodes.item(2)", "thirdLI");

	UList.insertBefore(dfrag, fourthLI);

	shouldBe("UList.childNodes.length", "4");
	shouldBe("UList.childNodes.item(0)", "firstLI");
	shouldBe("UList.childNodes.item(1)", "secondLI");
	shouldBe("UList.childNodes.item(2)", "thirdLI");
	shouldBe("UList.childNodes.item(3)", "fourthLI");
	shouldBe("dfrag.childNodes.length", "0");

	outTaggedText("header", "Tests of insertBefore() finished.");
}

]]></script>
</head>
<body>
<h1>DOM Test Suite: Interface <a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID-B63ED1A3">DocumentFragment</a></h1>

<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>


<div>
	<input type="button" onclick="testAttributes()" value="test attributes"/>
	<input type="button" onclick="testAppendChild()" value="test appendChild()"/>
	<input type="button" onclick="testInsertBefore()" value="test insertBefore()"/>
</div>

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

<ul id="ulist"><li id="first">first item</li><li id="second">second item</li><li id="third">third item</li><li id="fourth">fourth item</li></ul>
</div>

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

</div>

<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>
