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> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=421765 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Text.wholeText tests</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="https://bugzilla.mozilla.org/show_bug.cgi?id=421765">Mozilla Bug 421765</a> |
michael@0 | 13 | <p id="display"></p> |
michael@0 | 14 | <div id="content" style="display: none"></div> |
michael@0 | 15 | |
michael@0 | 16 | <iframe id="xmlDocument" src="wholeTexty-helper.xml"></iframe> |
michael@0 | 17 | |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script class="testbody" type="text/javascript"> |
michael@0 | 20 | |
michael@0 | 21 | /** Test for Bug 421765 **/ |
michael@0 | 22 | |
michael@0 | 23 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 24 | |
michael@0 | 25 | var xmlDoc; |
michael@0 | 26 | |
michael@0 | 27 | function text(t) { return document.createTextNode(t); } |
michael@0 | 28 | function element() { return document.createElement("div"); } |
michael@0 | 29 | function cdata(t) |
michael@0 | 30 | { |
michael@0 | 31 | xmlDoc = $("xmlDocument").contentDocument; |
michael@0 | 32 | // document.createCDATASection isn't implemented; clone for the win |
michael@0 | 33 | var node = xmlDoc.documentElement.firstChild.cloneNode(false); |
michael@0 | 34 | is(node.nodeType, Node.CDATA_SECTION_NODE, |
michael@0 | 35 | "er, why isn't this a CDATA section node?"); |
michael@0 | 36 | node.data = t; |
michael@0 | 37 | return node; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | |
michael@0 | 41 | function firstTests() |
michael@0 | 42 | { |
michael@0 | 43 | var outer = element(); |
michael@0 | 44 | var first = text("first"); |
michael@0 | 45 | var second = element(); |
michael@0 | 46 | second.appendChild(text("element contents")); |
michael@0 | 47 | outer.appendChild(first); |
michael@0 | 48 | outer.appendChild(second); |
michael@0 | 49 | |
michael@0 | 50 | is(first.wholeText, "first", "wrong wholeText for first"); |
michael@0 | 51 | |
michael@0 | 52 | var insertedText = text("-continued"); |
michael@0 | 53 | outer.insertBefore(insertedText, second); |
michael@0 | 54 | |
michael@0 | 55 | is(first.wholeText, "first-continued", |
michael@0 | 56 | "wrong wholeText for first after insertedText insertion"); |
michael@0 | 57 | is(insertedText.wholeText, "first-continued", |
michael@0 | 58 | "wrong wholeText for insertedText after insertedText insertion"); |
michael@0 | 59 | |
michael@0 | 60 | var cdataNode = cdata("zero-") |
michael@0 | 61 | outer.insertBefore(cdataNode, first); |
michael@0 | 62 | |
michael@0 | 63 | is(first.wholeText, "zero-first-continued", |
michael@0 | 64 | "wrong wholeText for first after cdataNode insertion"); |
michael@0 | 65 | is(cdataNode.wholeText, "zero-first-continued", |
michael@0 | 66 | "wrong wholeText for cdataNode after cdataNode insertion"); |
michael@0 | 67 | is(insertedText.wholeText, "zero-first-continued", |
michael@0 | 68 | "wrong wholeText for insertedText after cdataNode insertion"); |
michael@0 | 69 | |
michael@0 | 70 | outer.insertBefore(element(), first); |
michael@0 | 71 | |
michael@0 | 72 | is(first.wholeText, "first-continued", |
michael@0 | 73 | "wrong wholeText for first after element insertion"); |
michael@0 | 74 | is(cdataNode.wholeText, "zero-", |
michael@0 | 75 | "wrong wholeText for cdataNode after element insertion"); |
michael@0 | 76 | is(insertedText.wholeText, "first-continued", |
michael@0 | 77 | "wrong wholeText for insertedText after element insertion"); |
michael@0 | 78 | |
michael@0 | 79 | var cdataNode2 = cdata("-interrupted"); |
michael@0 | 80 | outer.insertBefore(cdataNode2, insertedText); |
michael@0 | 81 | |
michael@0 | 82 | is(first.wholeText, "first-interrupted-continued", |
michael@0 | 83 | "wrong wholeText for first after cdataNode2 insertion"); |
michael@0 | 84 | is(cdataNode2.wholeText, "first-interrupted-continued", |
michael@0 | 85 | "wrong wholeText for cdataNode2 after cdataNode2 insertion"); |
michael@0 | 86 | is(insertedText.wholeText, "first-interrupted-continued", |
michael@0 | 87 | "wrong wholeText for insertedText after cdataNode2 insertion"); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function middleTests() |
michael@0 | 91 | { |
michael@0 | 92 | var outer = element(); |
michael@0 | 93 | var first = element(); |
michael@0 | 94 | var last = element(); |
michael@0 | 95 | var middle = text("middle"); |
michael@0 | 96 | first.appendChild(text("first element contents")); |
michael@0 | 97 | last.appendChild(text("last element contents")); |
michael@0 | 98 | outer.appendChild(first); |
michael@0 | 99 | outer.appendChild(middle); |
michael@0 | 100 | outer.appendChild(last); |
michael@0 | 101 | |
michael@0 | 102 | is(middle.wholeText, "middle", "wrong wholeText for middle"); |
michael@0 | 103 | |
michael@0 | 104 | var beforeMiddle = text("before-"); |
michael@0 | 105 | outer.insertBefore(beforeMiddle, middle); |
michael@0 | 106 | |
michael@0 | 107 | is(middle.wholeText, "before-middle", |
michael@0 | 108 | "wrong wholeText for middle after beforeMiddle insertion"); |
michael@0 | 109 | is(beforeMiddle.wholeText, "before-middle", |
michael@0 | 110 | "wrong wholeText for beforeMiddle after beforeMiddle insertion"); |
michael@0 | 111 | |
michael@0 | 112 | var midElement = element(); |
michael@0 | 113 | midElement.appendChild(text("middle element")); |
michael@0 | 114 | outer.insertBefore(midElement, middle); |
michael@0 | 115 | |
michael@0 | 116 | is(middle.wholeText, "middle", |
michael@0 | 117 | "wrong wholeText for middle after midElement insertion"); |
michael@0 | 118 | is(beforeMiddle.wholeText, "before-", |
michael@0 | 119 | "wrong wholeText for beforeMiddle after midElement insertion"); |
michael@0 | 120 | |
michael@0 | 121 | var cdataNode = cdata("after"); |
michael@0 | 122 | outer.insertBefore(cdataNode, midElement); |
michael@0 | 123 | |
michael@0 | 124 | is(cdataNode.wholeText, "before-after", |
michael@0 | 125 | "wrong wholeText for cdataNode after cdataNode insertion"); |
michael@0 | 126 | is(beforeMiddle.wholeText, "before-after", |
michael@0 | 127 | "wrong wholeText for beforeMiddle after cdataNode insertion"); |
michael@0 | 128 | is(middle.wholeText, "middle", |
michael@0 | 129 | "wrong wholeText for middle after cdataNode insertion"); |
michael@0 | 130 | |
michael@0 | 131 | var cdataNode2 = cdata("before-"); |
michael@0 | 132 | outer.insertBefore(cdataNode2, middle); |
michael@0 | 133 | |
michael@0 | 134 | is(cdataNode.wholeText, "before-after", |
michael@0 | 135 | "wrong wholeText for cdataNode after cdataNode2 insertion"); |
michael@0 | 136 | is(beforeMiddle.wholeText, "before-after", |
michael@0 | 137 | "wrong wholeText for beforeMiddle after cdataNode2 insertion"); |
michael@0 | 138 | is(cdataNode2.wholeText, "before-middle", |
michael@0 | 139 | "wrong wholeText for middle after cdataNode2 insertion"); |
michael@0 | 140 | is(middle.wholeText, "before-middle", |
michael@0 | 141 | "wrong wholeText for middle after cdataNode2 insertion"); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | function lastTests() |
michael@0 | 145 | { |
michael@0 | 146 | var outer = element(); |
michael@0 | 147 | var first = element(); |
michael@0 | 148 | var second = text("second"); |
michael@0 | 149 | first.appendChild(text("element contents")); |
michael@0 | 150 | outer.appendChild(first); |
michael@0 | 151 | outer.appendChild(second); |
michael@0 | 152 | |
michael@0 | 153 | is(second.wholeText, "second", "wrong wholeText for second"); |
michael@0 | 154 | |
michael@0 | 155 | var insertedText = text("before-"); |
michael@0 | 156 | outer.insertBefore(insertedText, second); |
michael@0 | 157 | |
michael@0 | 158 | is(second.wholeText, "before-second", |
michael@0 | 159 | "wrong wholeText for second after insertedText insertion"); |
michael@0 | 160 | is(insertedText.wholeText, "before-second", |
michael@0 | 161 | "wrong wholeText for insertedText after insertedText insertion"); |
michael@0 | 162 | |
michael@0 | 163 | var cdataNode = cdata("zero-") |
michael@0 | 164 | outer.insertBefore(cdataNode, insertedText); |
michael@0 | 165 | |
michael@0 | 166 | is(cdataNode.wholeText, "zero-before-second", |
michael@0 | 167 | "wrong wholeText for cdataNode after cdataNode insertion"); |
michael@0 | 168 | is(second.wholeText, "zero-before-second", |
michael@0 | 169 | "wrong wholeText for second after cdataNode insertion"); |
michael@0 | 170 | is(insertedText.wholeText, "zero-before-second", |
michael@0 | 171 | "wrong wholeText for insertedText after cdataNode insertion"); |
michael@0 | 172 | |
michael@0 | 173 | outer.insertBefore(element(), second); |
michael@0 | 174 | |
michael@0 | 175 | is(second.wholeText, "second", |
michael@0 | 176 | "wrong wholeText for second after element insertion"); |
michael@0 | 177 | is(cdataNode.wholeText, "zero-before-", |
michael@0 | 178 | "wrong wholeText for cdataNode after element insertion"); |
michael@0 | 179 | is(insertedText.wholeText, "zero-before-", |
michael@0 | 180 | "wrong wholeText for insertedText after element insertion"); |
michael@0 | 181 | |
michael@0 | 182 | var cdataNode2 = cdata("interrupted-"); |
michael@0 | 183 | outer.insertBefore(cdataNode2, insertedText); |
michael@0 | 184 | |
michael@0 | 185 | is(second.wholeText, "second", |
michael@0 | 186 | "wrong wholeText for second after cdataNode2 insertion"); |
michael@0 | 187 | is(cdataNode2.wholeText, "zero-interrupted-before-", |
michael@0 | 188 | "wrong wholeText for cdataNode2 after cdataNode2 insertion"); |
michael@0 | 189 | is(insertedText.wholeText, "zero-interrupted-before-", |
michael@0 | 190 | "wrong wholeText for insertedText after cdataNode2 insertion"); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | function noParentTests() |
michael@0 | 194 | { |
michael@0 | 195 | var textNode = text("foobar"); |
michael@0 | 196 | is(textNode.wholeText, textNode.data, |
michael@0 | 197 | "orphaned textNode should have wholeText == data"); |
michael@0 | 198 | is(textNode.wholeText, "foobar", |
michael@0 | 199 | "orphaned textNode should have wholeText == 'foobar'"); |
michael@0 | 200 | |
michael@0 | 201 | var cdataSection = cdata("baz"); |
michael@0 | 202 | is(cdataSection.wholeText, cdataSection.data, |
michael@0 | 203 | "orphaned cdatasection should have wholeText == data"); |
michael@0 | 204 | is(cdataSection.wholeText, "baz", |
michael@0 | 205 | "orphaned cdatasection should have wholeText == data"); |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | function tests() |
michael@0 | 209 | { |
michael@0 | 210 | try |
michael@0 | 211 | { |
michael@0 | 212 | firstTests(); |
michael@0 | 213 | middleTests(); |
michael@0 | 214 | lastTests(); |
michael@0 | 215 | noParentTests(); |
michael@0 | 216 | } |
michael@0 | 217 | catch (e) |
michael@0 | 218 | { |
michael@0 | 219 | ok(false, "error thrown: " + e); |
michael@0 | 220 | } |
michael@0 | 221 | finally |
michael@0 | 222 | { |
michael@0 | 223 | SimpleTest.finish(); |
michael@0 | 224 | } |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | window.addEventListener("load", tests, false); |
michael@0 | 228 | </script> |
michael@0 | 229 | </pre> |
michael@0 | 230 | </body> |
michael@0 | 231 | </html> |
michael@0 | 232 |