test_bug352728.html (3985B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=352728 5 --> 6 <head> 7 <title>Test for Bug 352728</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=352728">Mozilla Bug 352728</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script class="testbody" type="text/javascript"> 19 /** Test for Bug 352728 */ 20 21 function checkTypes(aNode, aNodeType, aTypeArray) 22 { 23 for (var i = 0; i < aTypeArray.length; ++i) { 24 ok(aNode instanceof aTypeArray[i], 25 `${aNodeType} type test ${i}: ${aNodeType} should be a ${aTypeArray[i]}`); 26 } 27 } 28 29 function testCharacterData(aNode, aText) 30 { 31 is(aNode.length, aText.length, "Text length should match"); 32 is(aNode.data, aText, "Text content should match"); 33 is(aNode.nodeValue, aText, "Check nodeValue"); 34 is(aNode.localName, undefined, "Check localName") 35 is(aNode.namespaceURI, undefined, "Check namespaceURI"); 36 } 37 38 function testComment(aText) 39 { 40 try { 41 var comment = document.createComment(aText); 42 var types = [ Comment, CharacterData, Node ]; 43 checkTypes(comment, "comment", types); 44 45 testCharacterData(comment, aText); 46 is(comment.nodeName, "#comment", "Check nodeName"); 47 is(comment.nodeType, Node.COMMENT_NODE, "Check nodeType"); 48 } catch (e) { 49 ok(0, "Correct functioning of comment stuff", "something broke: " + e); 50 } 51 } 52 53 function testCDATASection(aText, aShouldSucceed) 54 { 55 try { 56 var cdataSection = document.createCDATASection(aText); 57 ok(0, "Invalid CDATA section creation", 58 "Shouldn't create CDATA sections in HTML"); 59 } catch (e) { 60 is(e.name, "NotSupportedError", "Check exception"); 61 is(e.code, DOMException.NOT_SUPPORTED_ERR, "Check exception code"); 62 } 63 } 64 65 function testPI(aTarget, aData, aShouldSucceed, aReason) 66 { 67 try { 68 var pi = document.createProcessingInstruction(aTarget, aData); 69 var types = [ ProcessingInstruction, Node ]; 70 checkTypes(pi, "processing instruction", types); 71 72 is(pi.target, aTarget, "Check target"); 73 is(pi.data, aData, "Check data"); 74 is(pi.nodeName, aTarget, "Check nodeName"); 75 is(pi.nodeValue, aData, "Check nodeValue"); 76 is(pi.localName, undefined, "Check localName") 77 is(pi.namespaceURI, undefined, "Check namespaceURI"); 78 79 is(pi.nodeType, Node.PROCESSING_INSTRUCTION_NODE, "Check nodeType"); 80 81 if (!aShouldSucceed) { 82 ok(false, "Invalid processing instruction creation", aReason); 83 } 84 } catch (e) { 85 if (aShouldSucceed) { 86 ok(false, "Correct functioning of processing instruction stuff", 87 "something broke: " + e); 88 } else { 89 is(e.name, "InvalidCharacterError", "Check exception"); 90 is(e.code, DOMException.INVALID_CHARACTER_ERR, "Check exception code"); 91 } 92 } 93 } 94 95 testComment("Some text"); 96 testComment("Some text with a '-' in it"); 97 testComment("Some text with a '-' and a '-' and another '-'"); 98 testComment("Some text -- this should create a node!"); 99 testComment("<!-- This is an HTML comment -->"); 100 101 testCDATASection("Some text", true); 102 testCDATASection("Some text with a '?' in it", true); 103 testCDATASection("Some text with a '>' in it", true); 104 testCDATASection("Some text with a '?' and a '>' in it", true); 105 testCDATASection("Some text with a '? >' in it", true); 106 testCDATASection("Some text -- ?> this should be ok", true); 107 testCDATASection("Some text ]]> this should not create a node!", false); 108 109 testPI("foo", "bar", true); 110 testPI("foo:bar", "baz", true); 111 testPI("foo", "bar?", true); 112 testPI("foo", "bar>", true); 113 testPI("foo", "bar? >", true); 114 testPI("<aaa", "bar", false, "Target should not contain '<'"); 115 testPI("aaa>", "bar", false, "Target should not contain '>'"); 116 testPI("aa?", "bar", false, "Target should not contain '?'"); 117 testPI("foo", "bar?>", false, "Data should not contain '?>'"); 118 </script> 119 </pre> 120 </body> 121 </html>