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