content/base/test/test_bug352728.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <!--
michael@0 3 https://bugzilla.mozilla.org/show_bug.cgi?id=352728
michael@0 4 -->
michael@0 5 <head>
michael@0 6 <title>Test for Bug 352728</title>
michael@0 7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 8 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 9 </head>
michael@0 10 <body>
michael@0 11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a>
michael@0 12 <p id="display"></p>
michael@0 13 <div id="content" style="display: none">
michael@0 14
michael@0 15 </div>
michael@0 16 <pre id="test">
michael@0 17 <!-- First make sure that a script consisting of multiple CDATA sections is
michael@0 18 even supported -->
michael@0 19 <script class="testbody" type="text/javascript">
michael@0 20 var cdataTest1 = false;
michael@0 21 var cdataTest2 = false;
michael@0 22 var cdataTest3 = false;
michael@0 23 </script>
michael@0 24
michael@0 25 <script class="testbody" type="text/javascript">
michael@0 26 <![CDATA[
michael@0 27 cdataTest1 = true;
michael@0 28 ]]>
michael@0 29 cdataTest2 = true;
michael@0 30 <![CDATA[
michael@0 31 cdataTest3 = true;
michael@0 32 ]]>
michael@0 33 </script>
michael@0 34
michael@0 35 <script class="testbody" type="text/javascript">
michael@0 36 is(cdataTest1, true, "Check first CDATA section");
michael@0 37 is(cdataTest2, true, "Check in between CDATA sections");
michael@0 38 is(cdataTest3, true, "Check second CDATA section");
michael@0 39 </script>
michael@0 40
michael@0 41 <script class="testbody" type="text/javascript">
michael@0 42 <![CDATA[
michael@0 43
michael@0 44 /** Test for Bug 352728 **/
michael@0 45 function checkTypes(aNode, aNodeType, aTypeArray)
michael@0 46 {
michael@0 47 for (var i = 0; i < aTypeArray.length; ++i) {
michael@0 48 ok(aNode instanceof aTypeArray[i], aNodeType + " type test " + i,
michael@0 49 aNodeType + " should be a " + aTypeArray[i]);
michael@0 50 }
michael@0 51 }
michael@0 52
michael@0 53 function checkInterfaces(aNode, aNodeType, aInterfaceArray)
michael@0 54 {
michael@0 55 for (var i = 0; i < aInterfaceArray.length; ++i) {
michael@0 56 ok(aNode instanceof SpecialPowers.Ci[aInterfaceArray[i]],
michael@0 57 aNodeType + " interface test " + i,
michael@0 58 aNodeType + " should be a " + aInterfaceArray[i]);
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 function testCharacterData(aNode, aText)
michael@0 63 {
michael@0 64 is(aNode.length, aText.length, "Text length should match");
michael@0 65 is(aNode.data, aText, "Text content should match");
michael@0 66 is(aNode.nodeValue, aText, "Check nodeValue");
michael@0 67 is(aNode.localName, null, "Check localName")
michael@0 68 is(aNode.namespaceURI, null, "Check namespaceURI");
michael@0 69 }
michael@0 70
michael@0 71 function testComment(aText)
michael@0 72 {
michael@0 73 try {
michael@0 74 var comment = document.createComment(aText);
michael@0 75 var types = [ Comment, CharacterData, Node ];
michael@0 76 checkTypes(comment, "comment", types);
michael@0 77
michael@0 78 var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode",
michael@0 79 "nsIDOMEventTarget" ];
michael@0 80 checkInterfaces(comment, "comment", interfaces);
michael@0 81
michael@0 82 testCharacterData(comment, aText);
michael@0 83 is(comment.nodeName, "#comment", "Check nodeName");
michael@0 84 is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType");
michael@0 85 } catch (e) {
michael@0 86 ok(0, "Correct functioning of comment stuff", "something broke: " + e);
michael@0 87 }
michael@0 88 }
michael@0 89
michael@0 90 function testCDATASection(aText, aShouldSucceed)
michael@0 91 {
michael@0 92 try {
michael@0 93 var cdataSection = document.createCDATASection(aText);
michael@0 94 var types = [ CDATASection, CharacterData, Node ];
michael@0 95 checkTypes(cdataSection, "CDATA section", types);
michael@0 96
michael@0 97 var interfaces = [ "nsIDOMCDATASection", "nsIDOMCharacterData",
michael@0 98 "nsIDOMNode", "nsIDOMEventTarget" ];
michael@0 99 checkInterfaces(cdataSection, "CDATA section", interfaces);
michael@0 100
michael@0 101 testCharacterData(cdataSection, aText);
michael@0 102 is(cdataSection.nodeName, "#cdata-section", "Check nodeName");
michael@0 103 is(cdataSection.nodeType, Node.CDATA_SECTION_NODE, "Check nodeType");
michael@0 104
michael@0 105 if (!aShouldSucceed) {
michael@0 106 ok(0, "Invalid CDATA section creation",
michael@0 107 ]]>
michael@0 108 "Shouldn't create CDATA section with embedded \"]]&gt;\"");
michael@0 109 <![CDATA[
michael@0 110 }
michael@0 111 } catch (e) {
michael@0 112 if (aShouldSucceed) {
michael@0 113 ok(0, "Correct functioning of CDATA section stuff",
michael@0 114 "something broke: " + e);
michael@0 115 } else {
michael@0 116 is(e.name, "InvalidCharacterError", "Check exception");
michael@0 117 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
michael@0 118 }
michael@0 119 }
michael@0 120 }
michael@0 121
michael@0 122 function testPI(aTarget, aData, aShouldSucceed, aReason)
michael@0 123 {
michael@0 124 try {
michael@0 125 var pi = document.createProcessingInstruction(aTarget, aData);
michael@0 126 var types = [ ProcessingInstruction, Node ];
michael@0 127 checkTypes(pi, "processing instruction", types);
michael@0 128
michael@0 129 var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode",
michael@0 130 "nsIDOMEventTarget" ];
michael@0 131 checkInterfaces(pi, "processing instruction", interfaces);
michael@0 132
michael@0 133 is(pi.target, aTarget, "Check target");
michael@0 134 is(pi.data, aData, "Check data");
michael@0 135 is(pi.nodeName, aTarget, "Check nodeName");
michael@0 136 is(pi.nodeValue, aData, "Check nodeValue");
michael@0 137 is(pi.localName, null, "Check localName")
michael@0 138 is(pi.namespaceURI, null, "Check namespaceURI");
michael@0 139
michael@0 140 is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType");
michael@0 141
michael@0 142 if (!aShouldSucceed) {
michael@0 143 ok(0, "Invalid processing instruction creation", aReason);
michael@0 144 }
michael@0 145 } catch (e) {
michael@0 146 if (aShouldSucceed) {
michael@0 147 ok(0, "Correct functioning of processing instruction stuff",
michael@0 148 "something broke: " + e);
michael@0 149 } else {
michael@0 150 is(e.name, "InvalidCharacterError", "Check exception");
michael@0 151 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code");
michael@0 152 }
michael@0 153 }
michael@0 154 }
michael@0 155
michael@0 156 testComment("Some text");
michael@0 157 testComment("Some text with a '-' in it");
michael@0 158 testComment("Some text with a '-' and a '-' and another '-'");
michael@0 159 testComment("Some text -- this should create a node!");
michael@0 160 testComment("<!-- This is an HTML comment -->");
michael@0 161
michael@0 162 testCDATASection("Some text", true);
michael@0 163 testCDATASection("Some text with a '?' in it", true);
michael@0 164 testCDATASection("Some text with a '>' in it", true);
michael@0 165 testCDATASection("Some text with a '?' and a '>' in it", true);
michael@0 166 testCDATASection("Some text with a '? >' in it", true);
michael@0 167 testCDATASection("Some text -- ?> this should be ok", true);
michael@0 168 ]]>
michael@0 169 testCDATASection("Some text ]]&gt; this should not create a node!", false);
michael@0 170
michael@0 171 <![CDATA[
michael@0 172
michael@0 173 testPI("foo", "bar", true);
michael@0 174 testPI("foo:bar", "baz", true);
michael@0 175 testPI("foo", "bar?", true);
michael@0 176 testPI("foo", "bar>", true);
michael@0 177 testPI("foo", "bar? >", true);
michael@0 178 testPI("<aaa", "bar", false, "Target should not contain '<'");
michael@0 179 testPI("aaa>", "bar", false, "Target should not contain '>'");
michael@0 180 testPI("aa?", "bar", false, "Target should not contain '?'");
michael@0 181 testPI("foo", "bar?>", false, "Data should not contain '?>'");
michael@0 182 ]]>
michael@0 183 </script>
michael@0 184 </pre>
michael@0 185 </body>
michael@0 186 </html>
michael@0 187

mercurial