| OLD | NEW |
| (Empty) |
| 1 description( | |
| 2 "Test modification of contents of a range" | |
| 3 ); | |
| 4 | |
| 5 var r; | |
| 6 | |
| 7 // TEST 1: Initial values | |
| 8 debug('<span>Start test 1</span>'); | |
| 9 var r = document.createRange(); | |
| 10 shouldBe("r.startOffset", "0"); | |
| 11 shouldBe("r.endOffset", "0"); | |
| 12 shouldBe("r.startContainer", "document"); | |
| 13 shouldBe("r.endContainer", "document"); | |
| 14 shouldBeTrue("r.collapsed"); | |
| 15 shouldBe("r.commonAncestorContainer", "document"); | |
| 16 | |
| 17 // TEST 2: Insert a comment into the document | |
| 18 debug('<span>Start test 2</span>'); | |
| 19 r.insertNode(document.createComment("test comment")); | |
| 20 shouldBe("r.startOffset", "0"); | |
| 21 shouldBe("r.endOffset", "1"); | |
| 22 shouldBe("r.startContainer", "document"); | |
| 23 shouldBe("r.endContainer", "document"); | |
| 24 shouldBeFalse("r.collapsed"); | |
| 25 shouldBe("r.commonAncestorContainer", "document"); | |
| 26 | |
| 27 // TEST 3: Remove the comment again | |
| 28 debug('<span>Start test 3</span>'); | |
| 29 r.deleteContents(); | |
| 30 shouldBe("r.startOffset", "0"); | |
| 31 shouldBe("r.endOffset", "0"); | |
| 32 shouldBe("r.startContainer", "document"); | |
| 33 shouldBe("r.endContainer", "document"); | |
| 34 shouldBeTrue("r.collapsed"); | |
| 35 shouldBe("r.commonAncestorContainer", "document"); | |
| 36 | |
| 37 // TEST 4: Insert a document fragment | |
| 38 debug('<span>Start test 4</span>'); | |
| 39 var f = document.createDocumentFragment(); | |
| 40 var c = document.getElementById("description"); | |
| 41 r.setStart(c, 0); | |
| 42 f.appendChild(document.createTextNode("test text node")); | |
| 43 f.appendChild(document.createComment("another text comment")); | |
| 44 f.appendChild(document.createTextNode("another test text node")); | |
| 45 r.insertNode(f); | |
| 46 shouldBe("r.startOffset", "0"); | |
| 47 shouldBe("r.endOffset", "3"); | |
| 48 shouldBe("r.startContainer", "c"); | |
| 49 shouldBe("r.endContainer", "c"); | |
| 50 shouldBeFalse("r.collapsed"); | |
| 51 shouldBe("r.commonAncestorContainer", "c"); | |
| 52 | |
| 53 // TEST 5: Remove the fragment again | |
| 54 debug('<span>Start test 5</span>'); | |
| 55 r.deleteContents(); | |
| 56 shouldBe("r.startOffset", "0"); | |
| 57 shouldBe("r.endOffset", "0"); | |
| 58 shouldBe("r.startContainer", "c"); | |
| 59 shouldBe("r.endContainer", "c"); | |
| 60 shouldBeTrue("r.collapsed"); | |
| 61 shouldBe("r.commonAncestorContainer", "c"); | |
| 62 | |
| 63 // TEST 6: Insert an empty document fragment | |
| 64 debug('<span>Start test 6</span>'); | |
| 65 f = document.createDocumentFragment(); | |
| 66 r.insertNode(f); | |
| 67 shouldBe("r.startOffset", "0"); | |
| 68 shouldBe("r.endOffset", "0"); | |
| 69 shouldBe("r.startContainer", "c"); | |
| 70 shouldBe("r.endContainer", "c"); | |
| 71 shouldBeTrue("r.collapsed"); | |
| 72 shouldBe("r.commonAncestorContainer", "c"); | |
| 73 | |
| 74 // TEST 7: Insert a div | |
| 75 debug('<span>Start test 7</span>'); | |
| 76 var d = document.createElement("div"); | |
| 77 d.appendChild(document.createTextNode("test text node")); | |
| 78 d.appendChild(document.createComment("another text comment")); | |
| 79 d.appendChild(document.createTextNode("another test text node")); | |
| 80 r.insertNode(d); | |
| 81 shouldBe("r.startOffset", "0"); | |
| 82 shouldBe("r.endOffset", "1"); | |
| 83 shouldBe("r.startContainer", "c"); | |
| 84 shouldBe("r.endContainer", "c"); | |
| 85 shouldBeFalse("r.collapsed"); | |
| 86 shouldBe("r.commonAncestorContainer", "c"); | |
| 87 | |
| 88 // TEST 8: Remove the div | |
| 89 debug('<span>Start test 8</span>'); | |
| 90 r.deleteContents(); | |
| 91 shouldBe("r.startOffset", "0"); | |
| 92 shouldBe("r.endOffset", "0"); | |
| 93 shouldBe("r.startContainer", "c"); | |
| 94 shouldBe("r.endContainer", "c"); | |
| 95 shouldBeTrue("r.collapsed"); | |
| 96 shouldBe("r.commonAncestorContainer", "c"); | |
| OLD | NEW |