<?xml version="1.0"?>
<?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: exceptions</title>
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="copyright" href="http://dbaron.org/legal.html" />
<link rel="stylesheet" type="text/css" href="../base.css" />
<script type="text/javascript" src="../base.js" />
<script type="text/javascript"><![CDATA[

function testX() {
	INDEX_SIZE_ERR = 1;
	DOMSTRING_SIZE_ERR = 2;
	HIERARCHY_REQUEST_ERR = 3;
	WRONG_DOCUMENT_ERR = 4;
	INVALID_CHARACTER_ERR = 5;
	NO_DATA_ALLOWED_ERR = 6;
	NO_MODIFICATION_ALLOWED_ERR = 7;
	NOT_FOUND_ERR = 8;
	NOT_SUPPORTED_ERR = 9;
	INUSE_ATTRIBUTE_ERR = 10;


	outTaggedText("header","Testing exception throwing in Document interface:");
	shouldThrow('document.createElement(" blah")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createProcessingInstruction("xml stylesheet", "href=\\\"../base.css\\\" type=\\\"text/css\\\"")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createProcessingInstruction("2style", "notmuch")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createProcessingInstruction("st,yle", "notmuch")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createProcessingInstruction("xml-stylesheet", "containing?>is bad")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createAttribute(" blah")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createEntityReference("bad entity name")', "INVALID_CHARACTER_ERR");
	shouldThrow('document.createEntityReference("bad;entity;name")', "INVALID_CHARACTER_ERR");


	// Interface Node
	outTaggedText("header","Testing exception throwing in Node interface:");
	helem = document.getElementsByTagName("h1").item(0);
	tn = helem.firstChild;
	pelem = document.createElement("p");
	newattr = document.createAttribute("class");

	dfrag = document.createDocumentFragment();
	dfrag.appendChild(document.createElement("div"));
	dfrag.firstChild.appendChild(document.createElement("div"));
	dfrag.firstChild.firstChild.appendChild(document.createElement("div"));
	pinfrag = document.createElement("p");
	pinfrag.appendChild(document.createTextNode("Paragraph nested in a document fragment."));
	dfrag.firstChild.firstChild.firstChild.appendChild(pinfrag);

	// insertBefore()
	outTaggedText("header","Testing exception throwing in Node::insertBefore():");
	shouldThrow("tn.insertBefore(pelem,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("document.insertBefore(pelem,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.insertBefore(newattr,tn)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.insertBefore(newattr,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.insertBefore(dfrag,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.insertBefore(dfrag,pinfrag.firstChild)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.insertBefore(document,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.insertBefore(document,pinfrag.firstChild)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.insertBefore(document,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.insertBefore(document,helem.firstChild)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.insertBefore(helem.parentNode,tn)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.insertBefore(pelem,helem.nextSibling)", "NOT_FOUND_ERR");

	// replaceChild()

	outTaggedText("header","Testing exception throwing in Node::replaceChild():");
	shouldThrow("tn.replaceChild(pelem,null)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.replaceChild(newattr,tn)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.replaceChild(dfrag,pinfrag.firstChild)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.replaceChild(document,pinfrag.firstChild)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.replaceChild(document,helem.firstChild)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.replaceChild(helem.parentNode,tn)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.replaceChild(pelem,helem.nextSibling)", "NOT_FOUND_ERR");
	shouldThrow("helem.replaceChild(pelem,document)", "NOT_FOUND_ERR");

	// removeChild
	outTaggedText("header","Testing exception throwing in Node::removeChild():");
	shouldThrow("helem.removeChild(document)", "NOT_FOUND_ERR");
	shouldThrow("helem.removeChild(helem.nextSibling)", "NOT_FOUND_ERR");
	shouldThrow("helem.removeChild(helem.parentNode)", "NOT_FOUND_ERR");

	outTaggedText("header","Testing exception throwing in Node::appendChild():");
	shouldThrow("tn.appendChild(pelem)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.appendChild(newattr)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.appendChild(dfrag)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("pinfrag.appendChild(document)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.appendChild(document)", "HIERARCHY_REQUEST_ERR");
	shouldThrow("helem.appendChild(helem.parentNode)", "HIERARCHY_REQUEST_ERR");

	// Interface NamedNodeMap
	outTaggedText("header","Testing exception throwing in NamedNodeMap interface:");
	hattrib = document.getElementsByTagName("h1").item(0).attributes;
	divattrib = document.getElementsByTagName("div").item(1).attributes;
	divid = divattrib.getNamedItem("id");
	shouldBe("divid.name", "'id'");
	shouldBe("divid.value", "'output'");
	shouldBe("divid.specified", "true");
	shouldThrow("hattrib.setNamedItem(divid)", "INUSE_ATTRIBUTE_ERR");
	shouldThrow("hattrib.removeNamedItem('class')", "NOT_FOUND_ERR");
	shouldThrow("divattrib.removeNamedItem('class')", "NOT_FOUND_ERR");


	// Interface Text
	outTaggedText("header","Testing exception throwing in Text interface:");
	tn = document.getElementsByTagName("h1").item(0).firstChild;
	shouldBe("tn.data", "'DOM Test Suite: exceptions'");
	shouldBe("tn.length", "26");
	shouldThrow("tn.substringData(-1,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(-1,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(27,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(27,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(-30,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(-30,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(537,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.substringData(537,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(-1,'text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(-1,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(27,'text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(27,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(-30,'text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(-30,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(537,'text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.insertData(537,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(-1,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(-1,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(27,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(27,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(-748,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(-748,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(378,5)", "INDEX_SIZE_ERR");
	shouldThrow("tn.deleteData(378,0)", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-1,5,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-1,0,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(27,5,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(27,0,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-38,5,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-38,0,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(176,5,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(176,0,'')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-1,5,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-1,0,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(27,5,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(27,0,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-72,5,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(-72,0,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(375,5,'lots of text and lots of text')", "INDEX_SIZE_ERR");
	shouldThrow("tn.replaceData(375,0,'lots of text and lots of text')", "INDEX_SIZE_ERR");

	// Interface Element
	outTaggedText("header","Testing exception throwing in Element interface:");
	helem = document.getElementsByTagName("h1").item(0);
	shouldThrow("helem.setAttribute('an attribute', 'a value')", "INVALID_CHARACTER_ERR");
	shouldThrow("helem.setAttribute('attribute ', 'a value')", "INVALID_CHARACTER_ERR");
	divid = document.getElementsByTagName("div").item(1).attributes.getNamedItem("id");
	shouldBe("divid.name", "'id'");
	shouldBe("divid.value", "'output'");
	shouldBe("divid.specified", "true");
	shouldThrow("helem.removeAttributeNode(divid)", "NOT_FOUND_ERR");
	shouldThrow("helem.setAttributeNode(divid)", "INUSE_ATTRIBUTE_ERR");
	shouldThrow("helem.removeAttributeNode(divid)", "NOT_FOUND_ERR");


	// Interface Text
	outTaggedText("header","Testing exception throwing in Text interface:");
	helem = document.getElementsByTagName("h1").item(0);
	tn = helem.firstChild;
	shouldBe("tn.data", "'DOM Test Suite: exceptions'");
	shouldBe("tn.length", "26");
	shouldThrow("tn.splitText(-1)", "INDEX_SIZE_ERR");
	shouldThrow("tn.splitText(27)", "INDEX_SIZE_ERR");
	shouldThrow("tn.splitText(-30)", "INDEX_SIZE_ERR");
	shouldThrow("tn.splitText(537)", "INDEX_SIZE_ERR");

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

}

]]></script>
</head>
<body>
<h1>DOM Test Suite: exceptions</h1>

<p>

	This test page uses the <code>try</code> and <code>catch</code>
	exception handling in ECMAScript Edition 3 (3d edition of
	ECMA-262), which is still not final as of October 1999.  It is
	therefore separate from all the other test pages.

</p>

<p>

	This page does not test WRONG_DOCUMENT_ERR,
	NO_MODIFICATION_ALLOWED_ERR, or DOMSTRING_SIZE_ERR anywhere in
	the DOM Level 1 Core.  It tests all other exceptions mentioned
	in the DOM Level 1 Core (nowhere near exhaustively, though).
	The tests for NamedNodeMap exceptions do not test anything with
	attributes where specified==false.

</p>

<div>
	<input type="button" onclick="testX()" value="test exceptions" />
</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>
