Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for ElementTraversal via SVG</title> |
michael@0 | 5 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | |
michael@0 | 10 | <p id="display"></p> |
michael@0 | 11 | <div id="content" style="display: none"></div> |
michael@0 | 12 | |
michael@0 | 13 | <iframe id="svg" src="w3element_traversal.svg"></iframe> |
michael@0 | 14 | |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script class="testbody" type="application/javascript"> |
michael@0 | 17 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 18 | |
michael@0 | 19 | function run() |
michael@0 | 20 | { |
michael@0 | 21 | var doc = $("svg").contentDocument; |
michael@0 | 22 | |
michael@0 | 23 | //et-namespace.svg |
michael@0 | 24 | var parentEl = doc.getElementById("parentEl_namespace"); |
michael@0 | 25 | var nChild = parentEl.firstElementChild; |
michael@0 | 26 | is(nChild && "dill", nChild.localName, "failed to get child with namespace") |
michael@0 | 27 | |
michael@0 | 28 | //et-previousElementSibling.svg |
michael@0 | 29 | var lec = doc.getElementById("last_element_child_pes"); |
michael@0 | 30 | var pes = lec.previousElementSibling; |
michael@0 | 31 | isnot(pes, null, "previousElementSibling is null"); |
michael@0 | 32 | is(pes.nodeType, 1, "previousElementSibling returned the wrong node type"); |
michael@0 | 33 | is(pes.getAttribute("id"), "middle_element_child_pes", "previousElementSibling returned the wrong child"); |
michael@0 | 34 | |
michael@0 | 35 | //et-sibling_null.svg |
michael@0 | 36 | var fec = doc.getElementById("first_element_child_sibnull"); |
michael@0 | 37 | var pes = fec.previousElementSibling; |
michael@0 | 38 | var nes = fec.nextElementSibling; |
michael@0 | 39 | is(pes, null, "previousElementSibling is not null"); |
michael@0 | 40 | is(nes, null, "nextElementSibling is not null"); |
michael@0 | 41 | |
michael@0 | 42 | //et-nextElementSibling.svg |
michael@0 | 43 | fec = doc.getElementById("first_element_child_nes"); |
michael@0 | 44 | var nes = fec.nextElementSibling; |
michael@0 | 45 | isnot(nes, null, "nextElementSibling returned NULL"); |
michael@0 | 46 | is(nes.nodeType, 1, "nextElementSibling returned wrong node type"); |
michael@0 | 47 | is(nes.getAttribute("id"), "last_element_child_nes", "nextElementSibling returned wrong node id"); |
michael@0 | 48 | |
michael@0 | 49 | //et-lastElementChild.svg |
michael@0 | 50 | var parentEl = doc.getElementById("parentEl_lec"); |
michael@0 | 51 | var lec = parentEl.lastElementChild; |
michael@0 | 52 | isnot(lec, null, "lastElementChild returned null"); |
michael@0 | 53 | is(lec.nodeType, 1, "lastElementChild returned wrong nodeType"); |
michael@0 | 54 | is(lec.getAttribute("id"), "last_element_child_lec", "lastElementChild returned wrong id"); |
michael@0 | 55 | |
michael@0 | 56 | //et-firstElementChild.svg |
michael@0 | 57 | var parentEl = doc.getElementById("parentEl_fec"); |
michael@0 | 58 | var fec = parentEl.firstElementChild; |
michael@0 | 59 | isnot(fec, null, "firstElementChild returned null"); |
michael@0 | 60 | is(fec.nodeType, 1, "firstElementChild returned wrong nodeType"); |
michael@0 | 61 | is(fec.getAttribute("id"), "first_element_child_fec", "firstElementChild returned wrong id"); |
michael@0 | 62 | |
michael@0 | 63 | //et-entity.svg |
michael@0 | 64 | var parentEl = doc.getElementById("parentEl_entity"); |
michael@0 | 65 | var fec = parentEl.firstElementChild; |
michael@0 | 66 | isnot(fec, null, "firstElementChild returned null"); |
michael@0 | 67 | is(fec.nodeType, 1, "firstElementChild returned wrong nodeType"); |
michael@0 | 68 | is(fec.getAttribute("id"), "first_element_child_entity", "firstElementChild returned wrong id"); |
michael@0 | 69 | |
michael@0 | 70 | //et-dynamic-remove.svg |
michael@0 | 71 | var parentEl = doc.getElementById("parentEl_dynremove"); |
michael@0 | 72 | var lec = parentEl.lastElementChild; |
michael@0 | 73 | parentEl.removeChild( lec ); |
michael@0 | 74 | is(parentEl.childElementCount && 1, parentEl.childElementCount, "failed to removeChild"); |
michael@0 | 75 | |
michael@0 | 76 | //et-dynamic-add.svg |
michael@0 | 77 | var parentEl = doc.getElementById("parentEl_dynadd"); |
michael@0 | 78 | var newChild = doc.createElementNS("http://www.w3.org/2000/svg", "tspan"); |
michael@0 | 79 | parentEl.appendChild( newChild ); |
michael@0 | 80 | is(parentEl.childElementCount && 2, parentEl.childElementCount, "failed to appendChild"); |
michael@0 | 81 | |
michael@0 | 82 | //et-childElement-null.svg |
michael@0 | 83 | var parentEl = doc.getElementById("parentEl_null"); |
michael@0 | 84 | var fec = parentEl.firstElementChild; |
michael@0 | 85 | var lec = parentEl.lastElementChild; |
michael@0 | 86 | is(fec, null, "expected null from firstElementChild"); |
michael@0 | 87 | is(lec, null, "expected null from lastElementChild"); |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | //et-childElementCount.svg |
michael@0 | 91 | var parentEl = doc.getElementById("parentEl_count"); |
michael@0 | 92 | is(parentEl.childElementCount && 3, parentEl.childElementCount, "got wrong childElementCount"); |
michael@0 | 93 | |
michael@0 | 94 | //et-childElementCount-nochild.svg |
michael@0 | 95 | var parentEl = doc.getElementById("parentEl_nochild"); |
michael@0 | 96 | is(0, parentEl.childElementCount, "got wrong childElementCount"); |
michael@0 | 97 | |
michael@0 | 98 | |
michael@0 | 99 | SimpleTest.finish(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | window.addEventListener("load", run, false); |
michael@0 | 103 | </script> |
michael@0 | 104 | </pre> |
michael@0 | 105 | </body> |
michael@0 | 106 | </html> |
michael@0 | 107 |