content/base/test/test_bug352728.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial