test_bug276037-1.html (3337B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=276037 5 --> 6 <head> 7 <title>Test for Bug 276037</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=276037">Mozilla Bug 276037</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 276037 */ 20 function countElements (node, namespaceURI, localName) { 21 var count = 0; 22 for (var i = 0; i < node.childNodes.length; i++) { 23 var child = node.childNodes[i]; 24 if (child.nodeType == Node.ELEMENT_NODE && child.localName == localName && 25 child.namespaceURI == namespaceURI) { 26 count++; 27 } 28 if (child.hasChildNodes()) { 29 count += countElements(child, namespaceURI, localName); 30 } 31 } 32 return count; 33 } 34 35 function checkElements(namespaceURI, localName) { 36 var elementsNS = document.getElementsByTagNameNS(namespaceURI, localName); 37 var elements = document.getElementsByTagName(localName); 38 var elementCount = countElements(document, namespaceURI, localName); 39 const gEBTN = 'document.getElementsByTagName(\'' + localName + '\').length: ' + elements.length; 40 const gEBTNNS = '; document.getElementsByTagNameNS(\'' + namespaceURI + '\', \'' + localName + '\').length: ' + elementsNS.length; 41 42 text1 = gEBTN + '; element count: ' + elementCount; 43 text2 = gEBTNNS + '; element count: ' + elementCount; 44 45 is(elements.length, elementCount, text1); 46 is(elementsNS.length, elementCount, text2); 47 is(global.gEBTN[namespaceURI][localName].length, elementCount, text1); 48 is(global.gEBTNNS[namespaceURI][localName].length, elementCount, text2); 49 } 50 51 const xhtmlNS = 'http://www.w3.org/1999/xhtml'; 52 53 function checkSpansAndScripts () { 54 checkElements(xhtmlNS, 'span'); 55 checkElements(xhtmlNS, 'script'); 56 } 57 58 SimpleTest.waitForExplicitFinish(); 59 addLoadEvent(function() { checkSpansAndScripts() }); 60 addLoadEvent(SimpleTest.finish); 61 62 // Init our global lists 63 var global = {}; 64 global.gEBTN = {}; 65 global.gEBTN[xhtmlNS] = {}; 66 global.gEBTNNS = {}; 67 global.gEBTNNS[xhtmlNS] = {}; 68 69 global.gEBTN[xhtmlNS].span = document.getElementsByTagName("span"); 70 global.gEBTNNS[xhtmlNS].span = document.getElementsByTagNameNS(xhtmlNS, "span"); 71 global.gEBTN[xhtmlNS].script = document.getElementsByTagName("script"); 72 global.gEBTNNS[xhtmlNS].script = document.getElementsByTagNameNS(xhtmlNS, "script"); 73 </script> 74 <p><span>Static text in span.</span></p> 75 <script type="text/javascript"> 76 checkSpansAndScripts(); 77 </script> 78 <p><span>Static text in span.</span></p> 79 <script type="text/javascript"> 80 checkSpansAndScripts(); 81 </script> 82 <p><span>Static text in span.</span></p> 83 <script type="text/javascript"> 84 checkSpansAndScripts(); 85 </script> 86 <p><span>Static text in span.</span></p> 87 <script type="text/javascript"> 88 checkSpansAndScripts(); 89 </script> 90 <p><span>Static text in span.</span></p> 91 <script type="text/javascript"> 92 checkSpansAndScripts(); 93 </script> 94 <p><span>Static text in span.</span></p> 95 <script type="text/javascript"> 96 checkSpansAndScripts(); 97 </script> 98 <p><span>Static text in span.</span></p> 99 <script type="text/javascript"> 100 checkSpansAndScripts(); 101 </script> 102 </pre> 103 </body> 104 </html>