1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug352728.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=352728 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 352728</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + 1.19 +</div> 1.20 +<pre id="test"> 1.21 +<script class="testbody" type="text/javascript"> 1.22 +/** Test for Bug 352728 **/ 1.23 + 1.24 +function checkTypes(aNode, aNodeType, aTypeArray) 1.25 +{ 1.26 + for (var i = 0; i < aTypeArray.length; ++i) { 1.27 + ok(aNode instanceof aTypeArray[i], aNodeType + " type test " + i, 1.28 + aNodeType + " should be a " + aTypeArray[i]); 1.29 + } 1.30 +} 1.31 + 1.32 +function checkInterfaces(aNode, aNodeType, aInterfaceArray) 1.33 +{ 1.34 + for (var i = 0; i < aInterfaceArray.length; ++i) { 1.35 + ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]], 1.36 + aNodeType + " interface test " + i, 1.37 + aNodeType + " should be a " + aInterfaceArray[i]); 1.38 + } 1.39 +} 1.40 + 1.41 +function testCharacterData(aNode, aText) 1.42 +{ 1.43 + is(aNode.length, aText.length, "Text length should match"); 1.44 + is(aNode.data, aText, "Text content should match"); 1.45 + is(aNode.nodeValue, aText, "Check nodeValue"); 1.46 + is(aNode.localName, null, "Check localName") 1.47 + is(aNode.namespaceURI, null, "Check namespaceURI"); 1.48 +} 1.49 + 1.50 +function testComment(aText) 1.51 +{ 1.52 + try { 1.53 + var comment = document.createComment(aText); 1.54 + var types = [ Comment, CharacterData, Node ]; 1.55 + checkTypes(comment, "comment", types); 1.56 + 1.57 + var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode", 1.58 + "nsIDOMEventTarget" ]; 1.59 + checkInterfaces(comment, "comment", interfaces); 1.60 + 1.61 + testCharacterData(comment, aText); 1.62 + is(comment.nodeName, "#comment", "Check nodeName"); 1.63 + is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType"); 1.64 + } catch (e) { 1.65 + ok(0, "Correct functioning of comment stuff", "something broke: " + e); 1.66 + } 1.67 +} 1.68 + 1.69 +function testCDATASection(aText, aShouldSucceed) 1.70 +{ 1.71 + try { 1.72 + var cdataSection = document.createCDATASection(aText); 1.73 + ok(0, "Invalid CDATA section creation", 1.74 + "Shouldn't create CDATA sections in HTML"); 1.75 + } catch (e) { 1.76 + is(e.name, "NotSupportedError", "Check exception"); 1.77 + is(e.code, DOMException.NOT_SUPPORTED_ERR, "Check exception code"); 1.78 + } 1.79 +} 1.80 + 1.81 +function testPI(aTarget, aData, aShouldSucceed, aReason) 1.82 +{ 1.83 + try { 1.84 + var pi = document.createProcessingInstruction(aTarget, aData); 1.85 + var types = [ ProcessingInstruction, Node ]; 1.86 + checkTypes(pi, "processing instruction", types); 1.87 + 1.88 + var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode", 1.89 + "nsIDOMEventTarget" ]; 1.90 + checkInterfaces(pi, "processing instruction", interfaces); 1.91 + 1.92 + is(pi.target, aTarget, "Check target"); 1.93 + is(pi.data, aData, "Check data"); 1.94 + is(pi.nodeName, aTarget, "Check nodeName"); 1.95 + is(pi.nodeValue, aData, "Check nodeValue"); 1.96 + is(pi.localName, null, "Check localName") 1.97 + is(pi.namespaceURI, null, "Check namespaceURI"); 1.98 + 1.99 + is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType"); 1.100 + 1.101 + if (!aShouldSucceed) { 1.102 + ok(false, "Invalid processing instruction creation", aReason); 1.103 + } 1.104 + } catch (e) { 1.105 + if (aShouldSucceed) { 1.106 + ok(false, "Correct functioning of processing instruction stuff", 1.107 + "something broke: " + e); 1.108 + } else { 1.109 + is(e.name, "InvalidCharacterError", "Check exception"); 1.110 + is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); 1.111 + } 1.112 + } 1.113 +} 1.114 + 1.115 +testComment("Some text"); 1.116 +testComment("Some text with a '-' in it"); 1.117 +testComment("Some text with a '-' and a '-' and another '-'"); 1.118 +testComment("Some text -- this should create a node!"); 1.119 +testComment("<!-- This is an HTML comment -->"); 1.120 + 1.121 +testCDATASection("Some text", true); 1.122 +testCDATASection("Some text with a '?' in it", true); 1.123 +testCDATASection("Some text with a '>' in it", true); 1.124 +testCDATASection("Some text with a '?' and a '>' in it", true); 1.125 +testCDATASection("Some text with a '? >' in it", true); 1.126 +testCDATASection("Some text -- ?> this should be ok", true); 1.127 +testCDATASection("Some text ]]> this should not create a node!", false); 1.128 + 1.129 +testPI("foo", "bar", true); 1.130 +testPI("foo:bar", "baz", true); 1.131 +testPI("foo", "bar?", true); 1.132 +testPI("foo", "bar>", true); 1.133 +testPI("foo", "bar? >", true); 1.134 +testPI("<aaa", "bar", false, "Target should not contain '<'"); 1.135 +testPI("aaa>", "bar", false, "Target should not contain '>'"); 1.136 +testPI("aa?", "bar", false, "Target should not contain '?'"); 1.137 +testPI("foo", "bar?>", false, "Data should not contain '?>'"); 1.138 +</script> 1.139 +</pre> 1.140 +</body> 1.141 +</html> 1.142 +