content/base/test/test_bug469304.html

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 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=469304
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 469304</title>
michael@0 8 <script type="application/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=469304">Mozilla Bug 469304</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none">
michael@0 16
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script type="application/javascript">
michael@0 20
michael@0 21 /** Test for Bug 469304 **/
michael@0 22 function testGetAttribute() {
michael@0 23 var a1 = document.createAttribute("aa");
michael@0 24 a1.nodeValue = "lowercase";
michael@0 25 var a2 = document.createAttribute("AA");
michael@0 26 a2.nodeValue = "UPPERCASE";
michael@0 27 document.body.setAttributeNode(a1);
michael@0 28 document.body.setAttributeNode(a2);
michael@0 29 var log = document.getElementById("log");
michael@0 30 is(document.body.getAttribute('aa'), "UPPERCASE", "Wrong value (1)");
michael@0 31 is(document.body.getAttribute('AA'), "UPPERCASE", "Wrong value (2)");
michael@0 32
michael@0 33 var s = "";
michael@0 34 for (var i = 0; i < document.body.attributes.length; ++i) {
michael@0 35 s += document.body.attributes[i].nodeName + "=" +
michael@0 36 document.body.attributes[i].nodeValue;
michael@0 37 }
michael@0 38 is(s, "AA=UPPERCASE", "Wrong attribute!");
michael@0 39
michael@0 40 is(document.body.getAttributeNode("aa"), document.body.getAttributeNode("AA"),
michael@0 41 "Wrong node!");
michael@0 42
michael@0 43 document.body.getAttributeNode("AA").nodeValue = "FOO";
michael@0 44 is(document.body.getAttribute("AA"), "FOO", "Wrong value!");
michael@0 45
michael@0 46 document.body.removeAttributeNode(document.body.getAttributeNode("AA"));
michael@0 47 ok(!document.body.hasAttribute("AA"), "Should not have attribute!");
michael@0 48 ok(!document.body.getAttributeNode("AA"), "Should not have attribute node!");
michael@0 49 ok(!document.body.hasAttribute("aa"), "Should not have attribute!");
michael@0 50 ok(!document.body.getAttributeNode("aa"), "Should not have attribute node!");
michael@0 51
michael@0 52 is(a2.nodeValue, "FOO", "Wrong value!");
michael@0 53 a2.nodeValue = "UPPERCASE";
michael@0 54 is(a2.nodeValue, "UPPERCASE", "Wrong value!");
michael@0 55
michael@0 56 document.body.setAttributeNode(a2);
michael@0 57 is(document.body.getAttribute("AA"), "UPPERCASE", "wrong value!");
michael@0 58 ok(document.body.getAttributeNode("AA"), "Should have attribute node!");
michael@0 59 is(document.body.getAttribute("aa"), "UPPERCASE", "wrong value!");
michael@0 60 ok(document.body.getAttributeNode("aa"), "Should have attribute node!");
michael@0 61 }
michael@0 62 testGetAttribute();
michael@0 63
michael@0 64 // A bit modified testcases from WebKit.
michael@0 65 function testGetAttributeCaseInsensitive() {
michael@0 66 var div = document.createElement('div');
michael@0 67 div.setAttribute("mixedCaseAttrib", "x");
michael@0 68 // Do original case lookup, and lowercase lookup.
michael@0 69 return div.getAttribute("mixedcaseattrib");
michael@0 70 }
michael@0 71 is(testGetAttributeCaseInsensitive(), "x", "(1)");
michael@0 72
michael@0 73 function testGetAttributeNodeMixedCase() {
michael@0 74 var div = document.createElement('div');
michael@0 75 var a = div.ownerDocument.createAttribute("mixedCaseAttrib");
michael@0 76 a.nodeValue = "x";
michael@0 77 div.setAttributeNode(a);
michael@0 78 return div.getAttribute("mixedCaseAttrib");
michael@0 79 }
michael@0 80 is(testGetAttributeNodeMixedCase(), "x", "(2)");
michael@0 81
michael@0 82 function testGetAttributeNodeLowerCase(div) {
michael@0 83 var div = document.createElement('div');
michael@0 84 var a = div.ownerDocument.createAttribute("lowercaseattrib");
michael@0 85 a.nodeValue = "x";
michael@0 86 div.setAttributeNode(a);
michael@0 87 return div.getAttribute("lowerCaseAttrib");
michael@0 88 }
michael@0 89 is(testGetAttributeNodeLowerCase(), "x", "(3)");
michael@0 90
michael@0 91 function testSetAttributeNodeKeepsRef(div) {
michael@0 92 var div = document.createElement('div');
michael@0 93 var a = div.ownerDocument.createAttribute("attrib_name");
michael@0 94 a.nodeValue = "0";
michael@0 95 div.setAttributeNode(a);
michael@0 96 // Mutate the attribute node.
michael@0 97 a.nodeValue = "1";
michael@0 98 return div.getAttribute("attrib_name");
michael@0 99 }
michael@0 100 is(testSetAttributeNodeKeepsRef(), "1", "(4)");
michael@0 101
michael@0 102 function testAttribNodeNamePreservesCase() {
michael@0 103 var div = document.createElement('div');
michael@0 104 var a = div.ownerDocument.createAttribute("A");
michael@0 105 a.nodeValue = "x";
michael@0 106 div.setAttributeNode(a);
michael@0 107 var result = [ a.name, a.nodeName ];
michael@0 108 return result.join(",");
michael@0 109 }
michael@0 110 is(testAttribNodeNamePreservesCase(), "A,A", "(5)");
michael@0 111
michael@0 112 function testAttribNodeNamePreservesCaseGetNode() {
michael@0 113 var body = document.body;
michael@0 114 var a = body.ownerDocument.createAttribute("A");
michael@0 115 a.nodeValue = "x";
michael@0 116 body.setAttributeNode(a);
michael@0 117 a = document.body.getAttributeNode("A");
michael@0 118 if (!a)
michael@0 119 return "FAIL";
michael@0 120 var result = [ a.name, a.nodeName ];
michael@0 121 return result.join(",");
michael@0 122 }
michael@0 123 is(testAttribNodeNamePreservesCaseGetNode(), "A,A", "(6)");
michael@0 124
michael@0 125 function testAttribNodeNamePreservesCaseGetNode2() {
michael@0 126 var body = document.body;
michael@0 127 var a = body.ownerDocument.createAttribute("B");
michael@0 128 a.nodeValue = "x";
michael@0 129 body.setAttributeNode(a);
michael@0 130 a = document.body.getAttributeNode("B");
michael@0 131 if (!a)
michael@0 132 return "FAIL";
michael@0 133 // Now create node second time
michael@0 134 a = body.ownerDocument.createAttribute("B");
michael@0 135 a.nodeValue = "x";
michael@0 136 body.setAttributeNode(a);
michael@0 137 a = document.body.getAttributeNode("B");
michael@0 138 var result = [ a.name, a.nodeName ];
michael@0 139 return result.join(",");
michael@0 140 }
michael@0 141 is(testAttribNodeNamePreservesCaseGetNode2(), "B,B", "(7)");
michael@0 142
michael@0 143 function testAttribNodeNameGetMutate() {
michael@0 144 var body = document.body;
michael@0 145 var a = body.ownerDocument.createAttribute("c");
michael@0 146 a.nodeValue = "0";
michael@0 147 body.setAttributeNode(a);
michael@0 148 a = document.body.getAttributeNode("c");
michael@0 149 a.value = "1";
michael@0 150 a = document.body.getAttributeNode("c");
michael@0 151 return a.nodeValue;
michael@0 152 }
michael@0 153 is(testAttribNodeNameGetMutate(), "1", "(8)");
michael@0 154
michael@0 155 var node = document.createElement("div");
michael@0 156 var attrib = document.createAttribute("myAttrib");
michael@0 157 attrib.nodeValue = "XXX";
michael@0 158 node.setAttributeNode(attrib);
michael@0 159 // Note, this is different to what WebKit does
michael@0 160 is((new XMLSerializer).serializeToString(node),
michael@0 161 "<div xmlns=\"http://www.w3.org/1999/xhtml\" myattrib=\"XXX\"></div>", "(9)");
michael@0 162 is(node.getAttributeNode('myAttrib').name, "myAttrib", "(10)");
michael@0 163 is(node.getAttributeNode('myattrib').name, "myAttrib", "(11)");
michael@0 164 is(attrib.name, "myAttrib", "(12)");
michael@0 165
michael@0 166 var o = document.createElement("div");
michael@0 167 o.setAttribute("myAttrib","htmlattr");
michael@0 168 o.setAttributeNS("","myAttrib","123");
michael@0 169 is(o.getAttributeNodeNS("","myAttrib").nodeName, "myAttrib", "nodeName should be case-sensitive.");
michael@0 170 is(o.getAttributeNode("myAttrib").nodeName, "myattrib", "nodeName shouldn't be case-sensitive.");
michael@0 171 is(o.getAttributeNodeNS("","myAttrib").value, "123", "Should have got the case-sensitive attribute.");
michael@0 172 is(o.attributes.length, 2, "Should have two attributes.");
michael@0 173 o.setAttribute("myAttrib2", "htmlattr");
michael@0 174 o.setAttributeNS("", "myAttrib2", "123");
michael@0 175 is(o.attributes.length, 4, "Should have four attributes.");
michael@0 176 var an = o.attributes.removeNamedItem("myAttrib2");
michael@0 177 is(o.attributes.length, 3, "An attribute should have been removed.");
michael@0 178 is(an.value, "htmlattr", "The removed attribute should have been the case-insensitive attribute.");
michael@0 179 is(o.getAttribute("myAttrib2"), null, "Element shouldn't have case-insensitive attribute anymore.");
michael@0 180 var an2 = o.attributes.removeNamedItemNS("", "myAttrib2");
michael@0 181 is(an2.localName, "myAttrib2", "The removed attribute should be case-sensitive.");
michael@0 182 is(o.attributes.length, 2, "Element should have two attributes.");
michael@0 183
michael@0 184 </script>
michael@0 185 </pre>
michael@0 186 </body>
michael@0 187 </html>

mercurial