| OLD | NEW |
| (Empty) |
| 1 description( | |
| 2 "This test checks mutation of the DOM and how it affects Ranges." | |
| 3 ); | |
| 4 | |
| 5 var a; | |
| 6 var b; | |
| 7 var c; | |
| 8 var d; | |
| 9 var e; | |
| 10 var paragraph; | |
| 11 var section; | |
| 12 var text; | |
| 13 var text1; | |
| 14 var text2; | |
| 15 var text3; | |
| 16 | |
| 17 function name(node) | |
| 18 { | |
| 19 if (node == a) | |
| 20 return "a"; | |
| 21 if (node == b) | |
| 22 return "b"; | |
| 23 if (node == c) | |
| 24 return "c"; | |
| 25 if (node == d) | |
| 26 return "d"; | |
| 27 if (node == e) | |
| 28 return "e"; | |
| 29 if (node == paragraph) | |
| 30 return "paragraph"; | |
| 31 if (node == section) | |
| 32 return "section"; | |
| 33 if (node == text) | |
| 34 return "text"; | |
| 35 if (node == text1) | |
| 36 return "text1"; | |
| 37 if (node == text2) | |
| 38 return "text2"; | |
| 39 if (node == text3) | |
| 40 return "text3"; | |
| 41 return "???"; | |
| 42 } | |
| 43 | |
| 44 function description(range) | |
| 45 { | |
| 46 return name(range.startContainer) + "," + range.startOffset + " -> " + name(
range.endContainer) + "," + range.endOffset + ": " + range.toString(); | |
| 47 } | |
| 48 | |
| 49 function makeRange(sc, so, ec, eo) | |
| 50 { | |
| 51 var newRange = document.createRange(); | |
| 52 newRange.setStart(sc, so); | |
| 53 newRange.setEnd(ec, eo); | |
| 54 return newRange; | |
| 55 } | |
| 56 | |
| 57 function setUp1() | |
| 58 { | |
| 59 paragraph = document.createElement("p"); | |
| 60 text = document.createTextNode("Abcd efgh XY blah ijkl"); | |
| 61 paragraph.appendChild(text); | |
| 62 range = makeRange(text, 11, text, 19); | |
| 63 } | |
| 64 | |
| 65 function createTestElement(name) | |
| 66 { | |
| 67 var element = document.createElement("em"); | |
| 68 var text = document.createTextNode(name); | |
| 69 element.appendChild(text); | |
| 70 return element; | |
| 71 } | |
| 72 | |
| 73 function setUp2() | |
| 74 { | |
| 75 paragraph = document.createElement("p"); | |
| 76 a = createTestElement("a"); | |
| 77 b = createTestElement("b"); | |
| 78 c = createTestElement("c"); | |
| 79 d = createTestElement("d"); | |
| 80 e = createTestElement("e"); | |
| 81 | |
| 82 paragraph.appendChild(a); | |
| 83 paragraph.appendChild(b); | |
| 84 paragraph.appendChild(c); | |
| 85 paragraph.appendChild(d); | |
| 86 range = makeRange(paragraph, 1, paragraph, 3); | |
| 87 } | |
| 88 | |
| 89 function setUp3() | |
| 90 { | |
| 91 paragraph = document.createElement("p"); | |
| 92 a = document.createTextNode("ax"); | |
| 93 b = document.createTextNode("by"); | |
| 94 | |
| 95 paragraph.appendChild(a); | |
| 96 paragraph.appendChild(b); | |
| 97 | |
| 98 range = makeRange(a, 1, b, 1); | |
| 99 } | |
| 100 | |
| 101 function setUp4() | |
| 102 { | |
| 103 paragraph = document.createElement("p"); | |
| 104 a = document.createTextNode("abcd"); | |
| 105 | |
| 106 paragraph.appendChild(a); | |
| 107 | |
| 108 range = makeRange(a, 1, a, 3); | |
| 109 } | |
| 110 | |
| 111 function setUp5() | |
| 112 { | |
| 113 section = document.createElement("div"); | |
| 114 paragraph = document.createElement("p"); | |
| 115 a = document.createTextNode("abcde"); | |
| 116 | |
| 117 section.appendChild(paragraph); | |
| 118 paragraph.appendChild(a); | |
| 119 | |
| 120 range = makeRange(a, 2, section, 1); | |
| 121 } | |
| 122 | |
| 123 // First, tests from the DOM Level 2 specification. | |
| 124 | |
| 125 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 1. | |
| 126 setUp1(); | |
| 127 text.insertData(10, "inserted text"); | |
| 128 shouldBe('description(range)', '"text,24 -> text,32: Y blah i"'); | |
| 129 | |
| 130 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 2. | |
| 131 // Firefox does not match the DOM Level 2 specification on this one. | |
| 132 setUp1(); | |
| 133 text.insertData(11, "inserted text"); | |
| 134 shouldBe('description(range)', '"text,11 -> text,32: inserted textY blah i"'); | |
| 135 | |
| 136 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 3. | |
| 137 setUp1(); | |
| 138 text.insertData(12, "inserted text"); | |
| 139 shouldBe('description(range)', '"text,11 -> text,32: Yinserted text blah i"'); | |
| 140 | |
| 141 // DOM Level 2 Traversal Range, 2.12.1. Insertions, example 4. | |
| 142 setUp1(); | |
| 143 text.insertData(17, "inserted text"); | |
| 144 shouldBe('description(range)', '"text,11 -> text,32: Y blahinserted text i"'); | |
| 145 | |
| 146 // Similar test at the range end. | |
| 147 setUp1(); | |
| 148 text.insertData(18, "inserted text"); | |
| 149 shouldBe('description(range)', '"text,11 -> text,32: Y blah inserted texti"'); | |
| 150 | |
| 151 // Similar test at the range end. | |
| 152 setUp1(); | |
| 153 text.insertData(19, "inserted text"); | |
| 154 shouldBe('description(range)', '"text,11 -> text,19: Y blah i"'); | |
| 155 | |
| 156 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 1. | |
| 157 paragraph = document.createElement("p"); | |
| 158 text = document.createTextNode("Abcd efgh The Range ijkl"); | |
| 159 paragraph.appendChild(text); | |
| 160 range = makeRange(text, 11, text, 21); | |
| 161 text.deleteData(5, 8); | |
| 162 shouldBe('description(range)', '"text,5 -> text,13: Range i"'); | |
| 163 | |
| 164 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 2. | |
| 165 paragraph = document.createElement("p"); | |
| 166 text = document.createTextNode("Abcd efgh The Range ijkl"); | |
| 167 paragraph.appendChild(text); | |
| 168 range = makeRange(text, 11, text, 21); | |
| 169 text.deleteData(5, 17); | |
| 170 shouldBe('description(range)', '"text,5 -> text,5: "'); | |
| 171 | |
| 172 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 3. | |
| 173 // Firefox does not match the DOM Level 2 specification on this one. | |
| 174 // Or maybe I wrote the test wrong? | |
| 175 paragraph = document.createElement("p"); | |
| 176 text1 = document.createTextNode("ABCD efgh The "); | |
| 177 paragraph.appendChild(text1); | |
| 178 em = document.createElement("em"); | |
| 179 paragraph.appendChild(em); | |
| 180 text2 = document.createTextNode("Range"); | |
| 181 em.appendChild(text2); | |
| 182 text3 = document.createTextNode(" ijkl"); | |
| 183 paragraph.appendChild(text3); | |
| 184 range = makeRange(text1, 11, text2, 5); | |
| 185 makeRange(text1, 5, text2, 1).deleteContents(); | |
| 186 shouldBe('description(range)', '"text1,5 -> text2,4: ange"'); | |
| 187 | |
| 188 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 4. | |
| 189 paragraph = document.createElement("p"); | |
| 190 text = document.createTextNode("Abcd efgh The Range ijkl"); | |
| 191 paragraph.appendChild(text); | |
| 192 range = makeRange(text, 11, text, 21); | |
| 193 text.deleteData(5, 6); | |
| 194 shouldBe('description(range)', '"text,5 -> text,15: he Range i"'); | |
| 195 | |
| 196 // DOM Level 2 Traversal Range, 2.12.2. Deletions, example 5. | |
| 197 paragraph = document.createElement("p"); | |
| 198 text1 = document.createTextNode("Abcd "); | |
| 199 paragraph.appendChild(text1); | |
| 200 em = document.createElement("em"); | |
| 201 paragraph.appendChild(em); | |
| 202 text2 = document.createTextNode("efgh The Range ij"); | |
| 203 em.appendChild(text2); | |
| 204 text3 = document.createTextNode("kl"); | |
| 205 paragraph.appendChild(text3); | |
| 206 range = makeRange(text2, 6, text2, 16); | |
| 207 makeRange(paragraph, 1, paragraph, 2).deleteContents(); | |
| 208 shouldBe('paragraph.childNodes.length', '2'); | |
| 209 shouldBe('text1.length', '5'); | |
| 210 shouldBe('description(range)', '"paragraph,1 -> paragraph,1: "'); | |
| 211 paragraph.normalize(); | |
| 212 shouldBe('paragraph.childNodes.length', '1'); | |
| 213 shouldBe('text1.length', '7'); | |
| 214 shouldBe('description(range)', '"text1,5 -> text1,5: "'); | |
| 215 | |
| 216 // Inserting a node in the start container, before the range start offset. | |
| 217 setUp2(); | |
| 218 paragraph.insertBefore(e, a); | |
| 219 shouldBe('description(range)', '"paragraph,2 -> paragraph,4: bc"'); | |
| 220 | |
| 221 // Inserting a node in the start container, at the range start offset. | |
| 222 setUp2(); | |
| 223 paragraph.insertBefore(e, b); | |
| 224 shouldBe('description(range)', '"paragraph,1 -> paragraph,4: ebc"'); | |
| 225 | |
| 226 // Inserting a node in the start container, between start and end. | |
| 227 setUp2(); | |
| 228 paragraph.insertBefore(e, c); | |
| 229 shouldBe('description(range)', '"paragraph,1 -> paragraph,4: bec"'); | |
| 230 | |
| 231 // Inserting a node in the end container, at the range end offset. | |
| 232 setUp2(); | |
| 233 paragraph.insertBefore(e, d); | |
| 234 shouldBe('description(range)', '"paragraph,1 -> paragraph,3: bc"'); | |
| 235 | |
| 236 // Inserting a node in the end container, after the range end offset. | |
| 237 setUp2(); | |
| 238 paragraph.appendChild(e); | |
| 239 shouldBe('description(range)', '"paragraph,1 -> paragraph,3: bc"'); | |
| 240 | |
| 241 // Removing the start container of a range. | |
| 242 setUp2(); | |
| 243 range = makeRange(b, 0, d, 1); | |
| 244 paragraph.removeChild(b); | |
| 245 shouldBe('description(range)', '"paragraph,1 -> d,1: cd"'); | |
| 246 setUp2(); | |
| 247 range = makeRange(b, 1, d, 0); | |
| 248 paragraph.removeChild(b); | |
| 249 shouldBe('description(range)', '"paragraph,1 -> d,0: c"'); | |
| 250 | |
| 251 // Removing the end container of a range. | |
| 252 setUp2(); | |
| 253 range = makeRange(b, 0, d, 1); | |
| 254 paragraph.removeChild(d); | |
| 255 shouldBe('description(range)', '"b,0 -> paragraph,3: bc"'); | |
| 256 setUp2(); | |
| 257 range = makeRange(b, 1, d, 0); | |
| 258 paragraph.removeChild(d); | |
| 259 shouldBe('description(range)', '"b,1 -> paragraph,3: c"'); | |
| 260 | |
| 261 // Calling normalize with a range that has an endpoint in a text node that gets
merged into another. | |
| 262 // Firefox does not do what the DOM Level 2 specification seems to call for on t
his one. | |
| 263 setUp3(); | |
| 264 paragraph.normalize(); | |
| 265 shouldBe('description(range)', '"a,1 -> a,3: xb"'); | |
| 266 | |
| 267 // Calling splitText when a range has an endpoint on in the piece that gets made
into a new text node. | |
| 268 // Firefox does not do what the DOM Level 2 specification seems to call for on t
his one. | |
| 269 setUp4(); | |
| 270 b = a.splitText(1); | |
| 271 shouldBe('description(range)', '"a,1 -> b,2: bc"'); | |
| 272 setUp4(); | |
| 273 b = a.splitText(2); | |
| 274 shouldBe('description(range)', '"a,1 -> b,1: bc"'); | |
| 275 setUp4(); | |
| 276 b = a.splitText(3); | |
| 277 shouldBe('description(range)', '"a,1 -> a,3: bc"'); | |
| 278 | |
| 279 // Range test in Acid3. | |
| 280 setUp5(); | |
| 281 shouldBe('description(range)', '"a,2 -> section,1: cde"'); | |
| 282 section.removeChild(paragraph); | |
| 283 shouldBe('description(range)', '"section,0 -> section,0: "'); | |
| 284 | |
| 285 // Children in a range being removed, but by DOM mutation (not CharacterData mut
ation). | |
| 286 // Test CharacterData.replaceData cases? | |
| 287 // Test Element.innerHTML cases (setting it)? | |
| 288 // Test Element.innerText cases (setting it)? | |
| 289 // Test Element.outerHTML cases (setting it)? | |
| 290 // Test Element.outerText cases (setting it)? | |
| 291 // Test Node.replaceChild cases? | |
| 292 // Test cases where Node.insertBefore/appendChild has a side effect of deleting
the node from a range. | |
| 293 // Test Range.deleteContents cases? | |
| 294 // Test Range.extractContents cases? | |
| 295 // Test Range.surroundContents cases? | |
| 296 // Test Text.replaceWholeText cases? | |
| OLD | NEW |