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