content/base/test/test_bug352728.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug352728.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,187 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<!--
     1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=352728
     1.7 +-->
     1.8 +<head>
     1.9 +  <title>Test for Bug 352728</title>
    1.10 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
    1.11 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.12 +</head>
    1.13 +<body>
    1.14 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a>
    1.15 +<p id="display"></p>
    1.16 +<div id="content" style="display: none">
    1.17 +  
    1.18 +</div>
    1.19 +<pre id="test">
    1.20 +<!-- First make sure that a script consisting of multiple CDATA sections is
    1.21 +     even supported -->
    1.22 +<script class="testbody" type="text/javascript">
    1.23 +  var cdataTest1 = false;
    1.24 +  var cdataTest2 = false;
    1.25 +  var cdataTest3 = false;
    1.26 +</script>
    1.27 +
    1.28 +<script class="testbody" type="text/javascript">
    1.29 +<![CDATA[
    1.30 +  cdataTest1 = true;
    1.31 +]]>
    1.32 +  cdataTest2 = true;
    1.33 +<![CDATA[
    1.34 +  cdataTest3 = true;
    1.35 +]]>
    1.36 +</script>
    1.37 +
    1.38 +<script class="testbody" type="text/javascript">
    1.39 +  is(cdataTest1, true, "Check first CDATA section");
    1.40 +  is(cdataTest2, true, "Check in between CDATA sections");
    1.41 +  is(cdataTest3, true, "Check second CDATA section");
    1.42 +</script>
    1.43 +
    1.44 +<script class="testbody" type="text/javascript">
    1.45 +<![CDATA[
    1.46 +
    1.47 +/** Test for Bug 352728 **/
    1.48 +function checkTypes(aNode, aNodeType, aTypeArray)
    1.49 +{
    1.50 +  for (var i = 0; i < aTypeArray.length; ++i) {
    1.51 +    ok(aNode instanceof aTypeArray[i], aNodeType + " type test " + i,
    1.52 +       aNodeType + " should be a " + aTypeArray[i]);
    1.53 +  }
    1.54 +}
    1.55 +
    1.56 +function checkInterfaces(aNode, aNodeType, aInterfaceArray)
    1.57 +{
    1.58 +  for (var i = 0; i < aInterfaceArray.length; ++i) {
    1.59 +    ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]],
    1.60 +       aNodeType + " interface test " + i,
    1.61 +       aNodeType + " should be a " + aInterfaceArray[i]);
    1.62 +  }
    1.63 +}
    1.64 +
    1.65 +function testCharacterData(aNode, aText)
    1.66 +{
    1.67 +  is(aNode.length, aText.length, "Text length should match");
    1.68 +  is(aNode.data, aText, "Text content should match");
    1.69 +  is(aNode.nodeValue, aText, "Check nodeValue");
    1.70 +  is(aNode.localName, null, "Check localName")
    1.71 +  is(aNode.namespaceURI, null, "Check namespaceURI");
    1.72 +}
    1.73 +
    1.74 +function testComment(aText)
    1.75 +{
    1.76 +  try {
    1.77 +    var comment = document.createComment(aText);
    1.78 +    var types = [ Comment, CharacterData, Node ];
    1.79 +    checkTypes(comment, "comment", types);
    1.80 +
    1.81 +    var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode",
    1.82 +                       "nsIDOMEventTarget" ];
    1.83 +    checkInterfaces(comment, "comment", interfaces);
    1.84 +
    1.85 +    testCharacterData(comment, aText);
    1.86 +    is(comment.nodeName, "#comment", "Check nodeName");
    1.87 +    is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
    1.88 +  } catch (e) {
    1.89 +    ok(0, "Correct functioning of comment stuff", "something broke: " + e);
    1.90 +  }
    1.91 +}
    1.92 +
    1.93 +function testCDATASection(aText, aShouldSucceed)
    1.94 +{
    1.95 +  try {
    1.96 +    var cdataSection = document.createCDATASection(aText);
    1.97 +    var types = [ CDATASection, CharacterData, Node ];
    1.98 +    checkTypes(cdataSection, "CDATA section", types);
    1.99 +
   1.100 +    var interfaces = [ "nsIDOMCDATASection", "nsIDOMCharacterData",
   1.101 +                       "nsIDOMNode", "nsIDOMEventTarget" ];
   1.102 +    checkInterfaces(cdataSection, "CDATA section", interfaces);
   1.103 +
   1.104 +    testCharacterData(cdataSection, aText);
   1.105 +    is(cdataSection.nodeName, "#cdata-section", "Check nodeName");
   1.106 +    is(cdataSection.nodeType, Node.CDATA_SECTION_NODE, "Check nodeType");
   1.107 +
   1.108 +    if (!aShouldSucceed) {
   1.109 +      ok(0, "Invalid CDATA section creation",
   1.110 +]]>
   1.111 +         "Shouldn't create CDATA section with embedded \"]]&gt;\"");
   1.112 +<![CDATA[
   1.113 +    }
   1.114 +  } catch (e) {
   1.115 +    if (aShouldSucceed) {
   1.116 +      ok(0, "Correct functioning of CDATA section stuff",
   1.117 +         "something broke: " + e);
   1.118 +    } else {
   1.119 +      is(e.name, "InvalidCharacterError", "Check exception");
   1.120 +      is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
   1.121 +    }
   1.122 +  }
   1.123 +}
   1.124 +
   1.125 +function testPI(aTarget, aData, aShouldSucceed, aReason)
   1.126 +{
   1.127 +  try {
   1.128 +    var pi = document.createProcessingInstruction(aTarget, aData);
   1.129 +    var types = [ ProcessingInstruction, Node ];
   1.130 +    checkTypes(pi, "processing instruction", types);
   1.131 +
   1.132 +    var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode",
   1.133 +                       "nsIDOMEventTarget" ];
   1.134 +    checkInterfaces(pi, "processing instruction", interfaces);
   1.135 +
   1.136 +    is(pi.target, aTarget, "Check target");
   1.137 +    is(pi.data, aData, "Check data");
   1.138 +    is(pi.nodeName, aTarget, "Check nodeName");
   1.139 +    is(pi.nodeValue, aData, "Check nodeValue");
   1.140 +    is(pi.localName, null, "Check localName")
   1.141 +    is(pi.namespaceURI, null, "Check namespaceURI");
   1.142 +    
   1.143 +    is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType");
   1.144 +
   1.145 +    if (!aShouldSucceed) {
   1.146 +      ok(0, "Invalid processing instruction creation", aReason);
   1.147 +    }
   1.148 +  } catch (e) {
   1.149 +    if (aShouldSucceed) {
   1.150 +      ok(0, "Correct functioning of processing instruction stuff",
   1.151 +         "something broke: " + e);
   1.152 +    } else {
   1.153 +      is(e.name, "InvalidCharacterError", "Check exception");
   1.154 +      is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
   1.155 +    }
   1.156 +  }
   1.157 +}
   1.158 +
   1.159 +testComment("Some text");
   1.160 +testComment("Some text with a '-' in it");
   1.161 +testComment("Some text with a '-' and a '-' and another '-'");
   1.162 +testComment("Some text -- this should create a node!");
   1.163 +testComment("<!-- This is an HTML comment -->");
   1.164 +
   1.165 +testCDATASection("Some text", true);
   1.166 +testCDATASection("Some text with a '?' in it", true);
   1.167 +testCDATASection("Some text with a '>' in it", true);
   1.168 +testCDATASection("Some text with a '?' and a '>' in it", true);
   1.169 +testCDATASection("Some text with a '? >' in it", true);
   1.170 +testCDATASection("Some text -- ?> this should be ok", true);
   1.171 +]]>
   1.172 +testCDATASection("Some text ]]&gt; this should not create a node!", false);
   1.173 +
   1.174 +<![CDATA[
   1.175 +
   1.176 +testPI("foo", "bar", true);
   1.177 +testPI("foo:bar", "baz", true);
   1.178 +testPI("foo", "bar?", true);
   1.179 +testPI("foo", "bar>", true);
   1.180 +testPI("foo", "bar? >", true);
   1.181 +testPI("<aaa", "bar", false, "Target should not contain '<'");
   1.182 +testPI("aaa>", "bar", false, "Target should not contain '>'");
   1.183 +testPI("aa?", "bar", false, "Target should not contain '?'");
   1.184 +testPI("foo", "bar?>", false, "Data should not contain '?>'");
   1.185 +]]>
   1.186 +</script>
   1.187 +</pre>
   1.188 +</body>
   1.189 +</html>
   1.190 +

mercurial