Thu, 15 Jan 2015 21:03:48 +0100
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=444722 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for the ElementTraversal spec</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="http://dev.w3.org/2006/webapi/ElementTraversal/publish/ElementTraversal.html">ElementTraversal</a> |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | <span>span</span><div>div</div> |
michael@0 | 15 | <!--comment goes here--> |
michael@0 | 16 | <p id="p1">p1</p> |
michael@0 | 17 | text here |
michael@0 | 18 | <p id="p2">p2</p> |
michael@0 | 19 | <span>a<span>b</span>c<span>d</span>e</span> |
michael@0 | 20 | </div> |
michael@0 | 21 | <pre id="test"> |
michael@0 | 22 | <script class="testbody" type="text/javascript"> |
michael@0 | 23 | |
michael@0 | 24 | var c = document.getElementById('content'); |
michael@0 | 25 | var cc = c.children; |
michael@0 | 26 | |
michael@0 | 27 | var contents = ["span", "div", "p1", "p2", "abcde"]; |
michael@0 | 28 | function testContent() { |
michael@0 | 29 | for(i = 0, e = c.firstElementChild; e; e = e.nextElementSibling, i++) { |
michael@0 | 30 | is(e.textContent, contents[i], "wrong element contents"); |
michael@0 | 31 | is(e, c.children[i], "wrong element"); |
michael@0 | 32 | is(e, c.children.item(i), "wrong element"); |
michael@0 | 33 | } |
michael@0 | 34 | is(i, contents.length, "wrong number of element siblings"); |
michael@0 | 35 | is(i, c.childElementCount, "wrong number of child elements"); |
michael@0 | 36 | is(i, c.children.length, "wrong number of child elements"); |
michael@0 | 37 | |
michael@0 | 38 | // Nuke all elements to retest the child list. |
michael@0 | 39 | c.innerHTML = c.innerHTML; |
michael@0 | 40 | |
michael@0 | 41 | for(i--, e = c.lastElementChild; e; e = e.previousElementSibling, i--) { |
michael@0 | 42 | is(e.textContent, contents[i], "g element contents"); |
michael@0 | 43 | is(e, c.children[i], "wrong element"); |
michael@0 | 44 | is(e, c.children.item(i), "wrong element"); |
michael@0 | 45 | } |
michael@0 | 46 | is(i, -1, "wrong number of element siblings"); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | testContent(); |
michael@0 | 50 | |
michael@0 | 51 | is(cc.length, 5, "wrong number of child elements"); |
michael@0 | 52 | is(c.childElementCount, 5, "wrong number of child elements"); |
michael@0 | 53 | |
michael@0 | 54 | var p1 = document.getElementById('p1'); |
michael@0 | 55 | var p2 = document.getElementById('p2'); |
michael@0 | 56 | is(p1.nextElementSibling, p2, "wrong sibling"); |
michael@0 | 57 | is(p2.previousElementSibling, p1, "wrong sibling"); |
michael@0 | 58 | |
michael@0 | 59 | u = document.createElement('u'); |
michael@0 | 60 | u.textContent = 'u'; |
michael@0 | 61 | c.insertBefore(u, p2); |
michael@0 | 62 | is(cc.length, 6, "wrong number of child elements"); |
michael@0 | 63 | is(c.childElementCount, 6, "wrong number of child elements"); |
michael@0 | 64 | is(p1.nextElementSibling, u, "wrong sibling"); |
michael@0 | 65 | is(p2.previousElementSibling, u, "wrong sibling"); |
michael@0 | 66 | |
michael@0 | 67 | contents.splice(3, 0, "u"); |
michael@0 | 68 | testContent(); |
michael@0 | 69 | |
michael@0 | 70 | var p1 = document.getElementById('p1'); |
michael@0 | 71 | var p2 = document.getElementById('p2'); |
michael@0 | 72 | c.removeChild(p1); |
michael@0 | 73 | c.removeChild(p2); |
michael@0 | 74 | is(cc.length, 4, "wrong number of child elements"); |
michael@0 | 75 | is(c.childElementCount, 4, "wrong number of child elements"); |
michael@0 | 76 | |
michael@0 | 77 | contents.splice(2, 1); |
michael@0 | 78 | contents.splice(3, 1); |
michael@0 | 79 | testContent(); |
michael@0 | 80 | |
michael@0 | 81 | tw = document.createTreeWalker(document.documentElement, |
michael@0 | 82 | NodeFilter.SHOW_ELEMENT, |
michael@0 | 83 | null); |
michael@0 | 84 | e = document.documentElement; |
michael@0 | 85 | |
michael@0 | 86 | elemsTested = 0; |
michael@0 | 87 | done = false; |
michael@0 | 88 | while(!done) { |
michael@0 | 89 | is(tw.currentNode, e, "wrong element:" + tw.currentNode + " != " + e); |
michael@0 | 90 | elemsTested++; |
michael@0 | 91 | |
michael@0 | 92 | if(tw.firstChild()) { |
michael@0 | 93 | e = e.firstElementChild; |
michael@0 | 94 | } |
michael@0 | 95 | else { |
michael@0 | 96 | while (!tw.nextSibling()) { |
michael@0 | 97 | if (!tw.parentNode()) { |
michael@0 | 98 | done = true; |
michael@0 | 99 | break; |
michael@0 | 100 | } |
michael@0 | 101 | e = e.parentNode; |
michael@0 | 102 | } |
michael@0 | 103 | e = e.nextElementSibling; |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | is(elemsTested, document.getElementsByTagName("*").length, |
michael@0 | 107 | "wrong number of elements"); |
michael@0 | 108 | </script> |
michael@0 | 109 | </pre> |
michael@0 | 110 | </body> |
michael@0 | 111 | </html> |