1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug469304.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,187 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=469304 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 469304</title> 1.11 + <script type="application/javascript" src="/MochiKit/MochiKit.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=469304">Mozilla Bug 469304</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="display: none"> 1.19 + 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript"> 1.23 + 1.24 +/** Test for Bug 469304 **/ 1.25 +function testGetAttribute() { 1.26 + var a1 = document.createAttribute("aa"); 1.27 + a1.nodeValue = "lowercase"; 1.28 + var a2 = document.createAttribute("AA"); 1.29 + a2.nodeValue = "UPPERCASE"; 1.30 + document.body.setAttributeNode(a1); 1.31 + document.body.setAttributeNode(a2); 1.32 + var log = document.getElementById("log"); 1.33 + is(document.body.getAttribute('aa'), "UPPERCASE", "Wrong value (1)"); 1.34 + is(document.body.getAttribute('AA'), "UPPERCASE", "Wrong value (2)"); 1.35 + 1.36 + var s = ""; 1.37 + for (var i = 0; i < document.body.attributes.length; ++i) { 1.38 + s += document.body.attributes[i].nodeName + "=" + 1.39 + document.body.attributes[i].nodeValue; 1.40 + } 1.41 + is(s, "AA=UPPERCASE", "Wrong attribute!"); 1.42 + 1.43 + is(document.body.getAttributeNode("aa"), document.body.getAttributeNode("AA"), 1.44 + "Wrong node!"); 1.45 + 1.46 + document.body.getAttributeNode("AA").nodeValue = "FOO"; 1.47 + is(document.body.getAttribute("AA"), "FOO", "Wrong value!"); 1.48 + 1.49 + document.body.removeAttributeNode(document.body.getAttributeNode("AA")); 1.50 + ok(!document.body.hasAttribute("AA"), "Should not have attribute!"); 1.51 + ok(!document.body.getAttributeNode("AA"), "Should not have attribute node!"); 1.52 + ok(!document.body.hasAttribute("aa"), "Should not have attribute!"); 1.53 + ok(!document.body.getAttributeNode("aa"), "Should not have attribute node!"); 1.54 + 1.55 + is(a2.nodeValue, "FOO", "Wrong value!"); 1.56 + a2.nodeValue = "UPPERCASE"; 1.57 + is(a2.nodeValue, "UPPERCASE", "Wrong value!"); 1.58 + 1.59 + document.body.setAttributeNode(a2); 1.60 + is(document.body.getAttribute("AA"), "UPPERCASE", "wrong value!"); 1.61 + ok(document.body.getAttributeNode("AA"), "Should have attribute node!"); 1.62 + is(document.body.getAttribute("aa"), "UPPERCASE", "wrong value!"); 1.63 + ok(document.body.getAttributeNode("aa"), "Should have attribute node!"); 1.64 +} 1.65 +testGetAttribute(); 1.66 + 1.67 +// A bit modified testcases from WebKit. 1.68 +function testGetAttributeCaseInsensitive() { 1.69 + var div = document.createElement('div'); 1.70 + div.setAttribute("mixedCaseAttrib", "x"); 1.71 + // Do original case lookup, and lowercase lookup. 1.72 + return div.getAttribute("mixedcaseattrib"); 1.73 +} 1.74 +is(testGetAttributeCaseInsensitive(), "x", "(1)"); 1.75 + 1.76 +function testGetAttributeNodeMixedCase() { 1.77 + var div = document.createElement('div'); 1.78 + var a = div.ownerDocument.createAttribute("mixedCaseAttrib"); 1.79 + a.nodeValue = "x"; 1.80 + div.setAttributeNode(a); 1.81 + return div.getAttribute("mixedCaseAttrib"); 1.82 +} 1.83 +is(testGetAttributeNodeMixedCase(), "x", "(2)"); 1.84 + 1.85 +function testGetAttributeNodeLowerCase(div) { 1.86 + var div = document.createElement('div'); 1.87 + var a = div.ownerDocument.createAttribute("lowercaseattrib"); 1.88 + a.nodeValue = "x"; 1.89 + div.setAttributeNode(a); 1.90 + return div.getAttribute("lowerCaseAttrib"); 1.91 +} 1.92 +is(testGetAttributeNodeLowerCase(), "x", "(3)"); 1.93 + 1.94 +function testSetAttributeNodeKeepsRef(div) { 1.95 + var div = document.createElement('div'); 1.96 + var a = div.ownerDocument.createAttribute("attrib_name"); 1.97 + a.nodeValue = "0"; 1.98 + div.setAttributeNode(a); 1.99 + // Mutate the attribute node. 1.100 + a.nodeValue = "1"; 1.101 + return div.getAttribute("attrib_name"); 1.102 +} 1.103 +is(testSetAttributeNodeKeepsRef(), "1", "(4)"); 1.104 + 1.105 +function testAttribNodeNamePreservesCase() { 1.106 + var div = document.createElement('div'); 1.107 + var a = div.ownerDocument.createAttribute("A"); 1.108 + a.nodeValue = "x"; 1.109 + div.setAttributeNode(a); 1.110 + var result = [ a.name, a.nodeName ]; 1.111 + return result.join(","); 1.112 +} 1.113 +is(testAttribNodeNamePreservesCase(), "A,A", "(5)"); 1.114 + 1.115 +function testAttribNodeNamePreservesCaseGetNode() { 1.116 + var body = document.body; 1.117 + var a = body.ownerDocument.createAttribute("A"); 1.118 + a.nodeValue = "x"; 1.119 + body.setAttributeNode(a); 1.120 + a = document.body.getAttributeNode("A"); 1.121 + if (!a) 1.122 + return "FAIL"; 1.123 + var result = [ a.name, a.nodeName ]; 1.124 + return result.join(","); 1.125 +} 1.126 +is(testAttribNodeNamePreservesCaseGetNode(), "A,A", "(6)"); 1.127 + 1.128 +function testAttribNodeNamePreservesCaseGetNode2() { 1.129 + var body = document.body; 1.130 + var a = body.ownerDocument.createAttribute("B"); 1.131 + a.nodeValue = "x"; 1.132 + body.setAttributeNode(a); 1.133 + a = document.body.getAttributeNode("B"); 1.134 + if (!a) 1.135 + return "FAIL"; 1.136 + // Now create node second time 1.137 + a = body.ownerDocument.createAttribute("B"); 1.138 + a.nodeValue = "x"; 1.139 + body.setAttributeNode(a); 1.140 + a = document.body.getAttributeNode("B"); 1.141 + var result = [ a.name, a.nodeName ]; 1.142 + return result.join(","); 1.143 +} 1.144 +is(testAttribNodeNamePreservesCaseGetNode2(), "B,B", "(7)"); 1.145 + 1.146 +function testAttribNodeNameGetMutate() { 1.147 + var body = document.body; 1.148 + var a = body.ownerDocument.createAttribute("c"); 1.149 + a.nodeValue = "0"; 1.150 + body.setAttributeNode(a); 1.151 + a = document.body.getAttributeNode("c"); 1.152 + a.value = "1"; 1.153 + a = document.body.getAttributeNode("c"); 1.154 + return a.nodeValue; 1.155 +} 1.156 +is(testAttribNodeNameGetMutate(), "1", "(8)"); 1.157 + 1.158 +var node = document.createElement("div"); 1.159 +var attrib = document.createAttribute("myAttrib"); 1.160 +attrib.nodeValue = "XXX"; 1.161 +node.setAttributeNode(attrib); 1.162 +// Note, this is different to what WebKit does 1.163 +is((new XMLSerializer).serializeToString(node), 1.164 + "<div xmlns=\"http://www.w3.org/1999/xhtml\" myattrib=\"XXX\"></div>", "(9)"); 1.165 +is(node.getAttributeNode('myAttrib').name, "myAttrib", "(10)"); 1.166 +is(node.getAttributeNode('myattrib').name, "myAttrib", "(11)"); 1.167 +is(attrib.name, "myAttrib", "(12)"); 1.168 + 1.169 +var o = document.createElement("div"); 1.170 +o.setAttribute("myAttrib","htmlattr"); 1.171 +o.setAttributeNS("","myAttrib","123"); 1.172 +is(o.getAttributeNodeNS("","myAttrib").nodeName, "myAttrib", "nodeName should be case-sensitive."); 1.173 +is(o.getAttributeNode("myAttrib").nodeName, "myattrib", "nodeName shouldn't be case-sensitive."); 1.174 +is(o.getAttributeNodeNS("","myAttrib").value, "123", "Should have got the case-sensitive attribute."); 1.175 +is(o.attributes.length, 2, "Should have two attributes."); 1.176 +o.setAttribute("myAttrib2", "htmlattr"); 1.177 +o.setAttributeNS("", "myAttrib2", "123"); 1.178 +is(o.attributes.length, 4, "Should have four attributes."); 1.179 +var an = o.attributes.removeNamedItem("myAttrib2"); 1.180 +is(o.attributes.length, 3, "An attribute should have been removed."); 1.181 +is(an.value, "htmlattr", "The removed attribute should have been the case-insensitive attribute."); 1.182 +is(o.getAttribute("myAttrib2"), null, "Element shouldn't have case-insensitive attribute anymore."); 1.183 +var an2 = o.attributes.removeNamedItemNS("", "myAttrib2"); 1.184 +is(an2.localName, "myAttrib2", "The removed attribute should be case-sensitive."); 1.185 +is(o.attributes.length, 2, "Element should have two attributes."); 1.186 + 1.187 +</script> 1.188 +</pre> 1.189 +</body> 1.190 +</html>